Example usage for java.awt Graphics drawPolygon

List of usage examples for java.awt Graphics drawPolygon

Introduction

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

Prototype

public void drawPolygon(Polygon p) 

Source Link

Document

Draws the outline of a polygon defined by the specified Polygon object.

Usage

From source file:Main.java

public void paint(Graphics g) {
    g.setColor(isActive ? ACTIVE_COLOR : INACTIVE_COLOR);
    g.drawPolygon(polygon);
}

From source file:UndoDrawing.java

protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawPolygon(polygon);
}

From source file:DrawPolyPanel.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Polygon p = new Polygon();
    for (int i = 0; i < 5; i++)
        p.addPoint((int) (100 + 50 * Math.cos(i * 2 * Math.PI / 5)),
                (int) (100 + 50 * Math.sin(i * 2 * Math.PI / 5)));

    g.drawPolygon(p);

    Polygon s = new Polygon();
    for (int i = 0; i < 360; i++) {
        double t = i / 360.0;
        s.addPoint((int) (150 + 50 * t * Math.cos(8 * t * Math.PI)),
                (int) (150 + 50 * t * Math.sin(8 * t * Math.PI)));
    }/*from   www  . j a v a2 s.  co m*/
    g.drawPolygon(s);
}

From source file:PagingTester.java

public void paintIcon(Component c, Graphics g, int x, int y) {
    g.setColor(Color.black);/*from w w w.  jav  a  2s  .  co  m*/
    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:MessagePopup.java

public void paintIcon(Component c, Graphics g, int x, int y) {
    g.setColor(color);/* w  w  w . j  a va  2 s  .c o m*/
    g.translate(x, y);
    if (selected) {
        g.fillPolygon(poly);
    } else {
        g.drawPolygon(poly);
    }
    g.translate(-x, -y);
}

From source file:CheckBoxSample.java

public void paintIcon(Component component, Graphics g, int x, int y) {
    boolean selected = false;
    g.setColor(color);//  w ww  .  ja v  a  2 s  .  com
    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: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.  ja  v a2s  . 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];/*ww  w  .ja va  2 s.c om*/
    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);
}

From source file:com.actelion.research.table.view.JVisualization.java

protected void drawSelectionOutline(Graphics g) {
    g.setColor(VisualizationColor.cSelectedColor);
    if (mRectangleSelecting)
        g.drawRect((mMouseX1 < mMouseX2) ? mMouseX1 : mMouseX2, (mMouseY1 < mMouseY2) ? mMouseY1 : mMouseY2,
                Math.abs(mMouseX2 - mMouseX1), Math.abs(mMouseY2 - mMouseY1));

    if (mLassoSelecting)
        g.drawPolygon(mLassoRegion);
}

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 .  ja  va 2  s . c  o m
            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);

}