Example usage for java.awt Graphics fillPolygon

List of usage examples for java.awt Graphics fillPolygon

Introduction

In this page you can find the example usage for java.awt Graphics fillPolygon.

Prototype

public void fillPolygon(Polygon p) 

Source Link

Document

Fills the polygon defined by the specified Polygon object with the graphics context's current color.

Usage

From source file:org.kalypso.ogc.gml.map.widgets.advanced.utils.GeometryPainter.java

public static void drawPolygon(final IMapPanel mapPanel, final Graphics g, final Polygon polygon,
        final Color border, final Color fill) {
    final LineString ring = polygon.getExteriorRing();
    int[] x = new int[] {};
    int[] y = new int[] {};
    for (int i = 0; i < ring.getNumPoints(); i++) {

        try {/* www.  j av  a2s .  c  om*/
            final Point p = ring.getPointN(i);
            final GM_Point gmp = (GM_Point) JTSAdapter.wrap(p);

            final java.awt.Point awt = MapUtilities.retransform(mapPanel, gmp);
            x = ArrayUtils.add(x, awt.x);
            y = ArrayUtils.add(y, awt.y);
        } catch (final GM_Exception e) {
            KalypsoCorePlugin.getDefault().getLog().log(StatusUtilities.statusFromThrowable(e));
        }
    }

    Assert.isTrue(x.length == y.length);

    final java.awt.Polygon poly = new java.awt.Polygon(x, y, x.length);

    final Color original = g.getColor();

    g.setColor(fill);
    g.fillPolygon(poly);

    g.setColor(border);
    g.drawPolygon(poly);

    g.setColor(original);

}

From source file:MessagePopup.java

public void paintIcon(Component c, Graphics g, int x, int y) {
    g.setColor(color);/*from w  w  w  .  ja va2  s  . co m*/
    g.translate(x, y);
    if (selected) {
        g.fillPolygon(poly);
    } else {
        g.drawPolygon(poly);
    }
    g.translate(-x, -y);
}

From source file:Main.java

public void paint(Graphics g) {
    super.paintComponent(g);
    int radius = 40;
    int centerX = 50;
    int centerY = 100;

    Polygon p = new Polygon();
    centerX = 150;//  w w  w.  j  ava 2 s.c om
    for (int i = 0; i < 5; i++)
        p.addPoint((int) (centerX + radius * Math.cos(i * 2 * Math.PI / 5)),
                (int) (centerY + radius * Math.sin(i * 2 * Math.PI / 5)));

    g.fillPolygon(p);

}

From source file:RedBlueBox.java

public void paintComponent(Graphics g) {
    Insets insets = getInsets();//from w w  w  .  j  av a2  s  .c  om
    int endX = getWidth() - insets.right;
    int endY = getHeight() - insets.bottom;
    // get the top-left corner
    int x = insets.left;
    int y = insets.top;

    g.setColor(Color.RED);
    Polygon p = new Polygon();
    p.addPoint(x, y);
    p.addPoint(endX, y);
    p.addPoint(x, endY);
    g.fillPolygon(p);
    g.setColor(Color.BLUE);
    p.reset();
    p.addPoint(endX, y);
    p.addPoint(x, endY);
    p.addPoint(endX, endY);
    g.fillPolygon(p);
}

From source file:CheckBoxSample.java

public void paintIcon(Component component, Graphics g, int x, int y) {
    boolean selected = false;
    g.setColor(color);/*ww w. j  ava 2s. c  o  m*/
    g.translate(x, y);
    if (component instanceof AbstractButton) {
        AbstractButton abstractButton = (AbstractButton) component;
        selected = abstractButton.isSelected();
    }
    if (selected) {
        g.fillPolygon(polygon);
    } else {
        g.drawPolygon(polygon);
    }
    g.translate(-x, -y);
}

From source file:PagingTester.java

public void paintIcon(Component c, Graphics g, int x, int y) {
    g.setColor(Color.black);// w  w w.  j a v a2s  .  c om
    pagePolygon.translate(x, y);
    g.drawPolygon(pagePolygon);
    pagePolygon.translate(-x, -y);
    if (direction == UP) {
        arrowUpPolygon.translate(x, y);
        g.fillPolygon(arrowUpPolygon);
        arrowUpPolygon.translate(-x, -y);
    } else {
        arrowDownPolygon.translate(x, y);
        g.fillPolygon(arrowDownPolygon);
        arrowDownPolygon.translate(-x, -y);
    }
}

From source file:FillPolyPanel.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    int radius = 40;
    int centerX = 50;
    int centerY = 100;
    int angle = 30;

    int dx = (int) (radius * Math.cos(angle * Math.PI / 180));
    int dy = (int) (radius * Math.sin(angle * Math.PI / 180));

    g.fillArc(centerX - radius, centerY - radius, 2 * radius, 2 * radius, angle, 360 - 2 * angle);

    Polygon p = new Polygon();
    centerX = 150;//from w ww .  j  av a  2s .c  om
    for (int i = 0; i < 5; i++)
        p.addPoint((int) (centerX + radius * Math.cos(i * 2 * Math.PI / 5)),
                (int) (centerY + radius * Math.sin(i * 2 * Math.PI / 5)));

    g.fillPolygon(p);

    p = new Polygon();
    centerX = 250;
    for (int i = 0; i < 360; i++) {
        double t = i / 360.0;
        p.addPoint((int) (centerX + radius * t * Math.cos(8 * t * Math.PI)),
                (int) (centerY + radius * t * Math.sin(8 * t * Math.PI)));
    }
    g.fillPolygon(p);
}

From source file:Main.java

public void paintIcon(Component c, Graphics g, int x, int y) {
    g.setColor(color);//ww  w  .j  a  v  a  2  s.com
    Polygon p = new Polygon();
    if (state == State.NORMAL) {
        p.addPoint(x + (getIconWidth() / 2), y);
        p.addPoint(x, y + getIconHeight() - 1);
        p.addPoint(x + getIconWidth() - 1, y + getIconHeight() - 1);
    } else if (state == State.PRESSED) {

        p.addPoint(x, y);
        p.addPoint(x + getIconWidth() - 1, y);
        p.addPoint(x + (getIconWidth() / 2), y + getIconHeight() - 1);
    } else {
        p.addPoint(x, y);
        p.addPoint(x, y + getIconHeight() - 1);
        p.addPoint(x + getIconWidth() - 1, y + (getIconHeight() / 2));
    }
    g.fillPolygon(p);
}

From source file:oct.analysis.application.OCTSelection.java

protected void drawSelectButton(Graphics g, int imageOffsetX, int imageOffsetY) {
    Polygon buttonOutline = getSelectionButtonShape();
    buttonOutline.translate(imageOffsetX, imageOffsetY);
    g.setColor(Color.lightGray);//from www  .j av a  2 s  . c o m
    g.drawPolygon(buttonOutline);
    g.fillPolygon(buttonOutline);
    Polygon button = new Polygon();
    button.addPoint(imageOffsetX + xPositionOnOct - 5, imageOffsetY);
    button.addPoint(imageOffsetX + xPositionOnOct - 5, imageOffsetY + 15);
    button.addPoint(imageOffsetX + xPositionOnOct, imageOffsetY + 20);
    button.addPoint(imageOffsetX + xPositionOnOct + 5, imageOffsetY + 15);
    button.addPoint(imageOffsetX + xPositionOnOct + 5, imageOffsetY);
    g.setColor(Color.DARK_GRAY);
    g.drawPolygon(button);
}

From source file:rod_design_compute.ShowPanel.java

private void drawBlock(Rod rod, Point point, Graphics g) {
    int[] x = new int[4];
    int[] y = new int[4];
    int l = lengthBlock;
    double theta = rod.getAngle();

    x[0] = (int) ((2 * Math.cos(theta) + Math.sin(theta)) * l / 4);
    y[0] = (int) ((2 * Math.sin(theta) - Math.cos(theta)) * l / 4);
    x[1] = (int) ((2 * Math.cos(theta) - Math.sin(theta)) * l / 4);
    y[1] = (int) ((2 * Math.sin(theta) + Math.cos(theta)) * l / 4);
    x[2] = -x[0];//from  w  w w  .j  a va  2s  .c  o  m
    y[2] = -y[0];
    x[3] = -x[1];
    y[3] = -y[1];

    Polygon block = new Polygon();
    for (int i = 0; i < 4; i++) {
        x[i] = toScreenX(point.X) + x[i];
        y[i] = toScreenY(point.Y) - y[i];
        block.addPoint(x[i], y[i]);
    }

    g.setColor(Color.white);
    g.fillPolygon(block);
    g.setColor(Color.black);
    g.drawPolygon(block);
}