Java Code Examples for java.awt.Graphics2D#drawPolygon()

The following examples show how to use java.awt.Graphics2D#drawPolygon() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DebugDrawJ2D.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void drawPolygon(Vec2[] vertices, int vertexCount, Color3f color) {
  Color s = cpool.getColor(color.x, color.y, color.z, 1f);
  Graphics2D g = getGraphics();
  saveState(g);
  int[] xInts = xIntsPool.get(vertexCount);
  int[] yInts = yIntsPool.get(vertexCount);
  for (int i = 0; i < vertexCount; i++) {
    getWorldToScreenToOut(vertices[i], temp);
    xInts[i] = (int) temp.x;
    yInts[i] = (int) temp.y;
  }
  g.setStroke(stroke);
  g.setColor(s);
  g.drawPolygon(xInts, yInts, vertexCount);
  restoreState(g);
}
 
Example 2
Source File: SeaZoneOutlineDrawable.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void draw(
    final Rectangle bounds,
    final GameData data,
    final Graphics2D graphics,
    final MapData mapData) {
  final Territory territory = data.getMap().getTerritory(territoryName);
  final List<Polygon> polys = mapData.getPolygons(territory);
  graphics.setColor(Color.BLACK);
  for (final Polygon polygon : polys) {
    if (!polygon.intersects(bounds) && !polygon.contains(bounds)) {
      continue;
    }

    graphics.drawPolygon(Util.translatePolygon(polygon, -bounds.x, -bounds.y));
  }
}
 
Example 3
Source File: TerritoryDrawable.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
protected static void draw(
    final Rectangle bounds,
    final Graphics2D graphics,
    final MapData mapData,
    final Territory territory,
    final Paint territoryPaint) {
  final List<Polygon> polygons = mapData.getPolygons(territory);
  for (final Polygon polygon : polygons) {
    if (!polygon.intersects(bounds) && !polygon.contains(bounds)) {
      continue;
    }

    final Polygon translatedPolygon = Util.translatePolygon(polygon, -bounds.x, -bounds.y);
    graphics.setPaint(territoryPaint);
    graphics.fillPolygon(translatedPolygon);
    graphics.setColor(Color.BLACK);
    graphics.drawPolygon(translatedPolygon);
  }
}
 
Example 4
Source File: ErrorIcon.java    From settlers-remake with MIT License 6 votes vote down vote up
@Override
public void paintIcon(Component c, Graphics g1, int x, int y) {
	Graphics2D g = (Graphics2D) g1;
	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
	g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
			RenderingHints.VALUE_INTERPOLATION_BILINEAR);

	g.setColor(Color.RED);
	g.setStroke(new BasicStroke(5));

	Polygon p = new Polygon();
	p.addPoint(5, size - 5);
	p.addPoint(size - 5, size - 5);
	p.addPoint(size / 2, 5);
	p.addPoint(5, size - 5);

	g.drawPolygon(p);

	g.drawLine(size / 2, 30, size / 2, size - 40);
	g.drawLine(size / 2, size - 22, size / 2, size - 20);
}
 
Example 5
Source File: Polygon.java    From pdfxtk with Apache License 2.0 6 votes vote down vote up
public void paintObject(Graphics2D g, double scale) {
     if (style != null) {
style.setStyle(g);
     }
     Style[] styles = context.flagger.getStyles(element);
     for (int i = 0; i < styles.length; i++) {
styles[i].setStyle(g);
     }

     int[][] p = getPoints(scale);

     if ((style != null) && style.isFilled()) {
g.fillPolygon(p[0], p[1], p[0].length);
     } else {
g.drawPolygon(p[0], p[1], p[0].length);
     }
   }
 
Example 6
Source File: AbstractTile.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
void draw(Graphics2D _g2, int _index) {
  if(levelZ!=null) {
    drawColorCoded(_g2, _index);
    return;
  }
  int sides = corners[_index].length;
  // Allow the panel to adjust color according to depth
  if(getRealStyle().isDrawingFill()) { // First fill the inside
    _g2.setPaint(getDrawingPanel3D().projectColor(getRealStyle().getFillColor(), objects[_index].getDistance()));
    _g2.fillPolygon(a[_index], b[_index], sides);
  }
  if(getRealStyle().isDrawingLines()) {
    _g2.setStroke(getRealStyle().getLineStroke());
    _g2.setColor(getDrawingPanel3D().projectColor(getRealStyle().getLineColor(), objects[_index].getDistance()));
    _g2.drawPolygon(a[_index], b[_index], sides);
  }
}
 
Example 7
Source File: Test8004821.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void test(final Graphics2D g, final int[] arr) {
    g.drawPolygon(arr, arr, arr.length);
    g.drawPolygon(new Polygon(arr, arr, arr.length));
    g.fillPolygon(arr, arr, arr.length);
    g.fillPolygon(new Polygon(arr, arr, arr.length));
    g.drawPolyline(arr, arr, arr.length);
}
 
Example 8
Source File: TileManager.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
private void drawForCreate(
    final Territory selected,
    final GameData data,
    final MapData mapData,
    final Rectangle bounds,
    final Graphics2D graphics,
    final boolean drawOutline) {
  final List<IDrawable> drawables =
      getTiles(bounds).stream()
          .map(Tile::getDrawables)
          .flatMap(Collection::stream)
          .sorted()
          .collect(Collectors.toList());
  for (final IDrawable drawer : drawables) {
    if (drawer.getLevel().ordinal() >= IDrawable.DrawLevel.UNITS_LEVEL.ordinal()) {
      break;
    }
    if (drawer.getLevel() == IDrawable.DrawLevel.TERRITORY_TEXT_LEVEL) {
      continue;
    }
    drawer.draw(bounds, data, graphics, mapData);
  }
  if (!drawOutline) {
    final Color c = selected.isWater() ? Color.RED : Color.BLACK;
    final TerritoryOverLayDrawable told =
        new TerritoryOverLayDrawable(c, selected.getName(), 100, Operation.FILL);
    told.draw(bounds, data, graphics, mapData);
  }
  graphics.setStroke(new BasicStroke(10));
  graphics.setColor(Color.RED);
  for (final Polygon polygon : mapData.getPolygons(selected)) {
    graphics.drawPolygon(Util.translatePolygon(polygon, -bounds.x, -bounds.y));
  }
}
 
Example 9
Source File: Test8004821.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void test(final Graphics2D g, final int[] arr) {
    g.drawPolygon(arr, arr, arr.length);
    g.drawPolygon(new Polygon(arr, arr, arr.length));
    g.fillPolygon(arr, arr, arr.length);
    g.fillPolygon(new Polygon(arr, arr, arr.length));
    g.drawPolyline(arr, arr, arr.length);
}
 
Example 10
Source File: Test8004821.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void test(final Graphics2D g, final int[] arr) {
    g.drawPolygon(arr, arr, arr.length);
    g.drawPolygon(new Polygon(arr, arr, arr.length));
    g.fillPolygon(arr, arr, arr.length);
    g.fillPolygon(new Polygon(arr, arr, arr.length));
    g.drawPolyline(arr, arr, arr.length);
}
 
Example 11
Source File: Test8004821.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void test(final Graphics2D g, final int[] arr) {
    g.drawPolygon(arr, arr, arr.length);
    g.drawPolygon(new Polygon(arr, arr, arr.length));
    g.fillPolygon(arr, arr, arr.length);
    g.fillPolygon(new Polygon(arr, arr, arr.length));
    g.drawPolyline(arr, arr, arr.length);
}
 
Example 12
Source File: CursorMarker.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private static int drawMark(final Graphics2D gc, final int y, final CursorMarker mark, final Rectangle bounds)
{
	final Rectangle metrics = GraphicsUtils.measureText(gc, mark.label);
	final int dir = (mark.x + ARROW + metrics.width + BORDER <= bounds.width) ? 1 : -1;
	final int[] outline_x = new int[]
    {
        mark.x,
        mark.x + dir * ARROW,
        mark.x + dir *(ARROW + metrics.width + BORDER),
        mark.x + dir *(ARROW + metrics.width + BORDER),
        mark.x + dir * ARROW,
    };
    final int[] outline_y = new int[]
    {
        mark.y,
        y - metrics.height/2 - BORDER,
        y - metrics.height/2 - BORDER,
        y + metrics.height/2 + BORDER,
        y + metrics.height/2 + BORDER,
    };

    final Color orig_fill = gc.getColor();

    gc.setColor(gc.getBackground());
    gc.fillPolygon(outline_x, outline_y, 5);

    gc.setColor(mark.rgb);
    gc.drawPolygon(outline_x, outline_y, 5);
    if (dir > 0)
        gc.drawString(mark.label, mark.x + ARROW, y - metrics.height/2 + metrics.y);
    else
        gc.drawString(mark.label, mark.x - ARROW - metrics.width, y - metrics.height/2 + metrics.y);

    gc.setColor(orig_fill);

    return metrics.height;
}
 
Example 13
Source File: Test8004821.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void test(final Graphics2D g, final int[] arr) {
    g.drawPolygon(arr, arr, arr.length);
    g.drawPolygon(new Polygon(arr, arr, arr.length));
    g.fillPolygon(arr, arr, arr.length);
    g.fillPolygon(new Polygon(arr, arr, arr.length));
    g.drawPolyline(arr, arr, arr.length);
}
 
Example 14
Source File: VGDLSprite.java    From GVGAI_GYM with Apache License 2.0 5 votes vote down vote up
/**
 * In case this sprite is oriented and has an arrow to draw, it draws it.
 * @param g graphics device to draw in.
 */
public void _drawOriented(Graphics2D g, Rectangle r)
{
    Color arrowColor = new Color(color.getRed(), 255-color.getGreen(), color.getBlue());
    Polygon p = Utils.triPoints(r, orientation);

    // Rotation information

    if(shrinkfactor != 1)
    {
        r.width *= shrinkfactor;
        r.height *= shrinkfactor;
        r.x += (rect.width-r.width)/2;
        r.y += (rect.height-r.height)/2;
    }

    int w = image.getWidth(null);
    int h = image.getHeight(null);
    float scale = (float)r.width/w; //assume all sprites are quadratic.

    AffineTransform trans = new AffineTransform();
    trans.translate(r.x, r.y);
    trans.scale(scale,scale);
    trans.rotate(rotation,w/2.0,h/2.0);
    // Uncomment this line to have only one sprite
    //g.drawImage(image, trans, null);

    /* Code added by Carlos*/
    g.drawImage(image, trans, null);
    /* End of code added by carlos*/

    // We only draw the arrow if the directional sprites are null
    if (draw_arrow) {
        g.setColor(arrowColor);
        g.drawPolygon(p);
        g.fillPolygon(p);
    }

}
 
Example 15
Source File: TelekineticRoom.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void renderLocalPoint(Graphics2D graphics, LocalPoint local)
{
	if (local != null)
	{
		Polygon canvasTilePoly = Perspective.getCanvasTilePoly(client, local);
		if (canvasTilePoly != null)
		{
			graphics.drawPolygon(canvasTilePoly);
		}
	}
}
 
Example 16
Source File: Test8004821.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void test(final Graphics2D g, final int[] arr) {
    g.drawPolygon(arr, arr, arr.length);
    g.drawPolygon(new Polygon(arr, arr, arr.length));
    g.fillPolygon(arr, arr, arr.length);
    g.fillPolygon(new Polygon(arr, arr, arr.length));
    g.drawPolyline(arr, arr, arr.length);
}
 
Example 17
Source File: TelekineticRoom.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private void renderLocalPoint(Graphics2D graphics, LocalPoint local)
{
	if (local != null)
	{
		Polygon canvasTilePoly = Perspective.getCanvasTilePoly(client, local);
		if (canvasTilePoly != null)
		{
			graphics.drawPolygon(canvasTilePoly);
		}
	}
}
 
Example 18
Source File: TelekineticRoom.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void under(Graphics2D graphics2D)
{
	if (inside() && maze != null && guardian != null)
	{
		if (destination != null)
		{
			graphics2D.setColor(Color.ORANGE);
			renderLocalPoint(graphics2D, destination);
		}
		if (!moves.isEmpty())
		{
			if (moves.peek() == getPosition())
			{
				graphics2D.setColor(Color.GREEN);
			}
			else
			{
				graphics2D.setColor(Color.RED);
			}

			Polygon tile = Perspective.getCanvasTilePoly(client, guardian.getLocalLocation());
			if (tile != null)
			{
				graphics2D.drawPolygon(tile);
			}

			WorldPoint optimal = optimal();

			if (optimal != null)
			{
				client.setHintArrow(optimal);
				renderWorldPoint(graphics2D, optimal);
			}
		}
	}
}
 
Example 19
Source File: ImageDrawLines.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
public cfData execute( cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException{
	cfImageData im	= getImage( _session, argStruct );
	
	cfData	xa	= getNamedParam(argStruct, "xarray", null );
	if ( xa == null || xa.getDataType() != cfData.CFARRAYDATA )
		throwException(_session, "please specify the xarray and make sure it is an array");
	
	cfData	ya	= getNamedParam(argStruct, "yarray", null );
	if ( ya == null || ya.getDataType() != cfData.CFARRAYDATA )
		throwException(_session, "please specify the yarray and make sure it is an array");
	
	cfArrayData xarray = (cfArrayData)xa;
	cfArrayData yarray = (cfArrayData)ya;
	
	if ( xarray.size() != yarray.size() )
		throwException(_session, "the xarray is not the same size as the yarray");
	
	int x[]	= new int[xarray.size()];
	int y[]	= new int[yarray.size()];
	
	for ( int q=0; q < xarray.size(); q++ ){
		x[q]	= xarray.getData(q+1).getInt();
	}
	
	for ( int q=0; q < yarray.size(); q++ ){
		y[q]	= yarray.getData(q+1).getInt();
	}
	
	boolean bPolygon	= getNamedBooleanParam(argStruct, "isploygon", false );
	
	Graphics2D g2 = im.createGraphics();
	
	if ( bPolygon ){
		boolean bFilled	= getNamedBooleanParam(argStruct, "filled", false );
		
		if ( bFilled ){
			g2.fillPolygon(x, y, x.length);
		}else{
			g2.drawPolygon(x, y, x.length);
		}
		
	}else{
		g2.drawPolyline(x, y, x.length );
	}
	
	im.dispose(g2);
	
	return cfBooleanData.TRUE;
}
 
Example 20
Source File: Draw.java    From MeteoInfo with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static void drawPoint_Simple_Up(PointF aP, PointBreak aPB, Graphics2D g) {
    AffineTransform tempTrans = g.getTransform();
    if (aPB.getAngle() != 0) {
        //AffineTransform myTrans = new AffineTransform();
        AffineTransform myTrans = (AffineTransform) tempTrans.clone();
        myTrans.translate(aP.X, aP.Y);
        //myTrans.translate(tempTrans.getTranslateX() + aP.X, tempTrans.getTranslateY() + aP.Y);
        myTrans.rotate(aPB.getAngle() * Math.PI / 180);
        g.setTransform(myTrans);
        aP.X = 0;
        aP.Y = 0;
    }

    int[] xPoints;
    int[] yPoints;
    float aSize = aPB.getSize();
    boolean drawFill = aPB.isDrawFill();
    boolean drawOutline = aPB.isDrawOutline();
    Color color = aPB.getColor();
    Color outlineColor = aPB.getOutlineColor();
    float outlineSize = aPB.getOutlineSize();

    GeneralPath path = new GeneralPath();

    switch (aPB.getStyle()) {
        case Circle:
            aP.X = aP.X - aSize / 2;
            aP.Y = aP.Y - aSize;

            if (drawFill) {
                g.setColor(color);
                g.fillOval((int) aP.X, (int) aP.Y, (int) aSize, (int) aSize);
            }
            if (drawOutline) {
                g.setColor(outlineColor);
                g.setStroke(new BasicStroke(outlineSize));
                g.drawOval((int) aP.X, (int) aP.Y, (int) aSize, (int) aSize);
            }
            break;
        case Square:
            aP.X = aP.X - aSize / 2;
            aP.Y = aP.Y - aSize;

            if (drawFill) {
                g.setColor(color);
                g.fillRect((int) aP.X, (int) aP.Y, (int) aSize, (int) aSize);
            }
            if (drawOutline) {
                g.setColor(outlineColor);
                g.setStroke(new BasicStroke(outlineSize));
                g.drawRect((int) aP.X, (int) aP.Y, (int) aSize, (int) aSize);
            }
            break;
        case Diamond:
            xPoints = new int[4];
            yPoints = new int[4];
            xPoints[0] = (int) (aP.X - aSize / 2);
            yPoints[0] = (int) aP.Y;
            xPoints[1] = (int) aP.X;
            yPoints[1] = (int) (aP.Y - aSize / 2);
            xPoints[2] = (int) (aP.X + aSize / 2);
            yPoints[2] = (int) aP.Y;
            xPoints[3] = (int) aP.X;
            yPoints[3] = (int) (aP.Y + aSize / 2);
            if (drawFill) {
                g.setColor(color);
                g.fillPolygon(xPoints, yPoints, xPoints.length);
            }
            if (drawOutline) {
                g.setColor(outlineColor);
                g.setStroke(new BasicStroke(outlineSize));
                g.drawPolygon(xPoints, yPoints, xPoints.length);
            }
        case UpTriangle:
            xPoints = new int[3];
            yPoints = new int[3];
            xPoints[0] = (int) aP.X;
            yPoints[0] = (int) (aP.Y - aSize * 3 / 4);
            xPoints[1] = (int) (aP.X + aSize / 4 * Math.sqrt(3));
            yPoints[1] = (int) (aP.Y);
            xPoints[2] = (int) (aP.X - aSize / 4 * Math.sqrt(3));
            yPoints[2] = (int) (aP.Y);
            if (drawFill) {
                g.setColor(color);
                g.fillPolygon(xPoints, yPoints, xPoints.length);
            }
            if (drawOutline) {
                g.setColor(outlineColor);
                g.setStroke(new BasicStroke(outlineSize));
                g.drawPolygon(xPoints, yPoints, xPoints.length);
            }
            break;
    }

    if (aPB.getAngle() != 0) {
        g.setTransform(tempTrans);
    }
}