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

The following examples show how to use java.awt.Graphics#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: MiniMap.java    From megamek with GNU General Public License v2.0 6 votes vote down vote up
private void paintCoord(Graphics g, int x, int y, boolean border) {
    int baseX = (x * (hexSide[zoom] + hexSideBySin30[zoom])) + leftMargin;
    int baseY = (((2 * y) + 1 + (x % 2)) * hexSideByCos30[zoom]) + topMargin;
    int[] xPoints = new int[6];
    int[] yPoints = new int[6];
    xPoints[0] = baseX;
    yPoints[0] = baseY;
    xPoints[1] = baseX + hexSideBySin30[zoom];
    yPoints[1] = baseY + hexSideByCos30[zoom];
    xPoints[2] = xPoints[1] + hexSide[zoom];
    yPoints[2] = yPoints[1];
    xPoints[3] = xPoints[2] + hexSideBySin30[zoom];
    yPoints[3] = baseY;
    xPoints[4] = xPoints[2];
    yPoints[4] = baseY - hexSideByCos30[zoom];
    xPoints[5] = xPoints[1];
    yPoints[5] = yPoints[4];
    g.fillPolygon(xPoints, yPoints, 6);
    if (border) {
        Color oldColor = g.getColor();
        g.setColor(oldColor.darker());
        g.drawPolygon(xPoints, yPoints, 6);
        g.setColor(oldColor);
    }
}
 
Example 2
Source File: Plexers.java    From Logisim with GNU General Public License v3.0 6 votes vote down vote up
static void drawTrapezoid(Graphics g, Bounds bds, Direction facing, int facingLean) {
	int wid = bds.getWidth();
	int ht = bds.getHeight();
	int x0 = bds.getX();
	int x1 = x0 + wid;
	int y0 = bds.getY();
	int y1 = y0 + ht;
	int[] xp = { x0, x1, x1, x0 };
	int[] yp = { y0, y0, y1, y1 };
	if (facing == Direction.WEST) {
		yp[0] += facingLean;
		yp[3] -= facingLean;
	} else if (facing == Direction.NORTH) {
		xp[0] += facingLean;
		xp[1] -= facingLean;
	} else if (facing == Direction.SOUTH) {
		xp[2] -= facingLean;
		xp[3] += facingLean;
	} else {
		yp[1] += facingLean;
		yp[2] -= facingLean;
	}
	GraphicsUtil.switchToWidth(g, 2);
	g.drawPolygon(xp, yp, 4);
}
 
Example 3
Source File: DStarLiteNode.java    From The-Kraken-Pathfinding with MIT License 6 votes vote down vote up
@Override
public void print(Graphics g, Display f)
{
	if(heuristiqueOrientation != null)
	{
		double n = 40;
		XY_RW point1 = new XY_RW(n, 0), point2 = new XY_RW(-n / 2, n / 2), point3 = new XY_RW(-n / 2, -n / 2);
		point1.rotate(heuristiqueOrientation).plus(node.position);
		point2.rotate(heuristiqueOrientation).plus(node.position);
		point3.rotate(heuristiqueOrientation).plus(node.position);
		int[] X = { f.XtoWindow((int) point1.getX()), f.XtoWindow((int) point2.getX()), f.XtoWindow((int) point3.getX()) };
		int[] Y = { f.YtoWindow((int) point1.getY()), f.YtoWindow((int) point2.getY()), f.YtoWindow((int) point3.getY()) };

		g.drawPolygon(X, Y, 3);
	}
}
 
Example 4
Source File: MovementSprite.java    From megamek with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void drawOnto(Graphics g, int x, int y, ImageObserver observer) {
    // don't draw anything if the unit has no velocity

    if (vel == 0) {
        return;
    }

    Polygon drawPoly = new Polygon(movePoly.xpoints, movePoly.ypoints,
            movePoly.npoints);
    drawPoly.translate(x, y);

    g.setColor(moveColor);
    g.fillPolygon(drawPoly);
    g.setColor(Color.gray.darker());
    g.drawPolygon(drawPoly);

}
 
Example 5
Source File: CursorSprite.java    From megamek with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void prepare() {
    // create image for buffer
    Image tempImage = new BufferedImage(bounds.width, bounds.height,
            BufferedImage.TYPE_INT_ARGB);
    Graphics graph = tempImage.getGraphics();
    
    if (GUIPreferences.getInstance().getAntiAliasing()) {
        ((Graphics2D) graph).setRenderingHint(
                RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
    }

    // fill with key color
    graph.setColor(new Color(0,0,0,0));
    graph.fillRect(0, 0, bounds.width, bounds.height);
    // draw attack poly
    graph.setColor(color);
    graph.drawPolygon(BoardView1.hexPoly);

    // create final image
    image = bv.getScaledImage(bv.createImage(tempImage.getSource()), false);
    
    graph.dispose();
    tempImage.flush();
}
 
Example 6
Source File: PMSimplePolygonArea.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
public void drawInto(Graphics g) {
    if ((g == null) || (!visible))
        return;
    Color oldColor = g.getColor();
    g.setColor(this.backColor);
    g.fillPolygon(areaShape);
    if (selected && highlight) {
        g.setColor(highlightBorderColor);
    } else {
        g.setColor(this.normalBorderColor);
    }
    g.drawPolygon(this.areaShape);
    g.setColor(oldColor);
}
 
Example 7
Source File: RenderTests.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    RenderTests.Context rctx = (RenderTests.Context) ctx;
    // subtract 1 to account for the fact that lines are drawn to
    // and including the final coordinate...
    int size = rctx.size - 1;
    int x = rctx.initX;
    int y = rctx.initY;
    int hexaX[] = new int[6];
    int hexaY[] = new int[6];
    Graphics g = rctx.graphics;
    g.translate(rctx.orgX, rctx.orgY);
    Color rCArray[] = rctx.colorlist;
    int ci = rctx.colorindex;
    do {
        hexaX[0] = x;
        hexaX[1] = hexaX[5] = x+size/4;
        hexaX[2] = hexaX[4] = x+size-size/4;
        hexaX[3] = x+size;
        hexaY[1] = hexaY[2] = y;
        hexaY[0] = hexaY[3] = y+size/2;
        hexaY[4] = hexaY[5] = y+size;

        if (rCArray != null) {
            g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        g.drawPolygon(hexaX, hexaY, 6);
        if ((x -= 3) < 0) x += rctx.maxX;
        if ((y -= 1) < 0) y += rctx.maxY;
    } while (--numReps > 0);
    rctx.colorindex = ci;
    g.translate(-rctx.orgX, -rctx.orgY);
}
 
Example 8
Source File: EquilateralTriangleMarker.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
public void paint(Graphics g, int width) {
  if(background != null)
    g.setColor(background);
  if(opaque && !open)
    g.fillPolygon(p);    
  if(foreground != null)
    g.setColor(foreground);
  if(open)
    g.drawPolyline(p.xpoints, p.ypoints, p.npoints);
  else
    g.drawPolygon(p);
}
 
Example 9
Source File: MenuScroller.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
  Dimension size = c.getSize();
  Graphics g2 = g.create(size.width / 2 - 5, size.height / 2 - 5, 10, 10);
  g2.setColor(UIManager.getColor("MenuItem.disabledForeground"));
  g2.drawPolygon(xPoints, yPoints, 3);
  if (c.isEnabled()) {
    g2.setColor(UIManager.getColor("MenuItem.foreground"));
    g2.fillPolygon(xPoints, yPoints, 3);
  }
  g2.dispose();
}
 
Example 10
Source File: FilterBar.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void paint(Graphics g)
{
	Color b;
	Color f;
	if (entered)
	{
		b = UIManager.getColor("controlDkShadow");
		f = Color.BLACK;
	}
	else
	{
		b = UIManager.getColor("control");
		f = UIManager.getColor("controlDkShadow");
	}
	g.setColor(b);
	g.fillRect(0, 0, getWidth(), getHeight());
	int center = getWidth() / 2;
	int[] xs = {center, center - 3, center + 3};
	int[] ys;
	if (open)
	{
		ys = YUP;

	}
	else
	{
		ys = YDOWN;
	}
	g.setColor(f);
	g.drawPolygon(xs, ys, 3);
	g.fillPolygon(xs, ys, 3);
}
 
Example 11
Source File: RenderTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    RenderTests.Context rctx = (RenderTests.Context) ctx;
    // subtract 1 to account for the fact that lines are drawn to
    // and including the final coordinate...
    int size = rctx.size - 1;
    int x = rctx.initX;
    int y = rctx.initY;
    int hexaX[] = new int[6];
    int hexaY[] = new int[6];
    Graphics g = rctx.graphics;
    g.translate(rctx.orgX, rctx.orgY);
    Color rCArray[] = rctx.colorlist;
    int ci = rctx.colorindex;
    do {
        hexaX[0] = x;
        hexaX[1] = hexaX[5] = x+size/4;
        hexaX[2] = hexaX[4] = x+size-size/4;
        hexaX[3] = x+size;
        hexaY[1] = hexaY[2] = y;
        hexaY[0] = hexaY[3] = y+size/2;
        hexaY[4] = hexaY[5] = y+size;

        if (rCArray != null) {
            g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        g.drawPolygon(hexaX, hexaY, 6);
        if ((x -= 3) < 0) x += rctx.maxX;
        if ((y -= 1) < 0) y += rctx.maxY;
    } while (--numReps > 0);
    rctx.colorindex = ci;
    g.translate(-rctx.orgX, -rctx.orgY);
}
 
Example 12
Source File: FilterBar.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void paint(Graphics g)
{
	Color b;
	Color f;
	if (entered)
	{
		b = UIManager.getColor("controlDkShadow");
		f = Color.BLACK;
	}
	else
	{
		b = UIManager.getColor("control");
		f = UIManager.getColor("controlDkShadow");
	}
	g.setColor(b);
	g.fillRect(0, 0, getWidth(), getHeight());
	int center = getWidth() / 2;
	int[] xs = {center, center - 3, center + 3};
	int[] ys;
	if (open)
	{
		ys = YUP;

	}
	else
	{
		ys = YDOWN;
	}
	g.setColor(f);
	g.drawPolygon(xs, ys, 3);
	g.fillPolygon(xs, ys, 3);
}
 
Example 13
Source File: RectangularObstacle.java    From The-Kraken-Pathfinding with MIT License 5 votes vote down vote up
@Override
public void print(Graphics g, Display f)
{
	int[] X = new int[4];
	X[0] = (int) coinBasDroiteRotate.getX();
	X[1] = (int) coinHautDroiteRotate.getX();
	X[2] = (int) coinHautGaucheRotate.getX();
	X[3] = (int) coinBasGaucheRotate.getX();

	int[] Y = new int[4];
	Y[0] = (int) coinBasDroiteRotate.getY();
	Y[1] = (int) coinHautDroiteRotate.getY();
	Y[2] = (int) coinHautGaucheRotate.getY();
	Y[3] = (int) coinBasGaucheRotate.getY();

	for(int i = 0; i < 4; i++)
	{
		X[i] = f.XtoWindow(X[i]);
		Y[i] = f.YtoWindow(Y[i]);
	}
	g.drawPolygon(X, Y, 4);
	
	Color c = g.getColor();
	Color cTransparent = new Color(c.getRed(), c.getGreen(), c.getBlue(), 30);
	g.setColor(cTransparent);
	
	g.fillPolygon(X, Y, 4);
	g.setColor(c);
}
 
Example 14
Source File: RenderTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    RenderTests.Context rctx = (RenderTests.Context) ctx;
    // subtract 1 to account for the fact that lines are drawn to
    // and including the final coordinate...
    int size = rctx.size - 1;
    int x = rctx.initX;
    int y = rctx.initY;
    int hexaX[] = new int[6];
    int hexaY[] = new int[6];
    Graphics g = rctx.graphics;
    g.translate(rctx.orgX, rctx.orgY);
    Color rCArray[] = rctx.colorlist;
    int ci = rctx.colorindex;
    do {
        hexaX[0] = x;
        hexaX[1] = hexaX[5] = x+size/4;
        hexaX[2] = hexaX[4] = x+size-size/4;
        hexaX[3] = x+size;
        hexaY[1] = hexaY[2] = y;
        hexaY[0] = hexaY[3] = y+size/2;
        hexaY[4] = hexaY[5] = y+size;

        if (rCArray != null) {
            g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        g.drawPolygon(hexaX, hexaY, 6);
        if ((x -= 3) < 0) x += rctx.maxX;
        if ((y -= 1) < 0) y += rctx.maxY;
    } while (--numReps > 0);
    rctx.colorindex = ci;
    g.translate(-rctx.orgX, -rctx.orgY);
}
 
Example 15
Source File: RenderTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    RenderTests.Context rctx = (RenderTests.Context) ctx;
    // subtract 1 to account for the fact that lines are drawn to
    // and including the final coordinate...
    int size = rctx.size - 1;
    int x = rctx.initX;
    int y = rctx.initY;
    int hexaX[] = new int[6];
    int hexaY[] = new int[6];
    Graphics g = rctx.graphics;
    g.translate(rctx.orgX, rctx.orgY);
    Color rCArray[] = rctx.colorlist;
    int ci = rctx.colorindex;
    do {
        hexaX[0] = x;
        hexaX[1] = hexaX[5] = x+size/4;
        hexaX[2] = hexaX[4] = x+size-size/4;
        hexaX[3] = x+size;
        hexaY[1] = hexaY[2] = y;
        hexaY[0] = hexaY[3] = y+size/2;
        hexaY[4] = hexaY[5] = y+size;

        if (rCArray != null) {
            g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        g.drawPolygon(hexaX, hexaY, 6);
        if ((x -= 3) < 0) x += rctx.maxX;
        if ((y -= 1) < 0) y += rctx.maxY;
    } while (--numReps > 0);
    rctx.colorindex = ci;
    g.translate(-rctx.orgX, -rctx.orgY);
}
 
Example 16
Source File: RenderTests.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    RenderTests.Context rctx = (RenderTests.Context) ctx;
    // subtract 1 to account for the fact that lines are drawn to
    // and including the final coordinate...
    int size = rctx.size - 1;
    int x = rctx.initX;
    int y = rctx.initY;
    int hexaX[] = new int[6];
    int hexaY[] = new int[6];
    Graphics g = rctx.graphics;
    g.translate(rctx.orgX, rctx.orgY);
    Color rCArray[] = rctx.colorlist;
    int ci = rctx.colorindex;
    do {
        hexaX[0] = x;
        hexaX[1] = hexaX[5] = x+size/4;
        hexaX[2] = hexaX[4] = x+size-size/4;
        hexaX[3] = x+size;
        hexaY[1] = hexaY[2] = y;
        hexaY[0] = hexaY[3] = y+size/2;
        hexaY[4] = hexaY[5] = y+size;

        if (rCArray != null) {
            g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        g.drawPolygon(hexaX, hexaY, 6);
        if ((x -= 3) < 0) x += rctx.maxX;
        if ((y -= 1) < 0) y += rctx.maxY;
    } while (--numReps > 0);
    rctx.colorindex = ci;
    g.translate(-rctx.orgX, -rctx.orgY);
}
 
Example 17
Source File: Mosaic.java    From marvinproject with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void trianglesMosaic(int width, boolean border, Graphics graphics, MarvinImage image){
	Color l_colorT1;
	Color l_colorT2;
	int t=-1;
	boolean l_aux=true;

	if
	(
		((image.getWidth()/width)%2 == 0 && image.getWidth()%width==0) ||
		((image.getWidth()/width)%2 == 1 && image.getWidth()%width!=0)
	)
	{
		l_aux=false;
	}
	
	for (int y = 0; y < image.getHeight(); y+=width) {
		for (int x = 0; x < image.getWidth(); x+=width) {
			if(t ==-1)
			{
				l_colorT1 = getTriangleColor(x,y,0, image);
				l_colorT2 = getTriangleColor(x,y,1, image);

				graphics.setColor(l_colorT1);
				graphics.fillPolygon(new int[]{x,x+width,x}, new int[]{y,y,y+width},3);
				if(border){
					graphics.setColor(Color.black);
					graphics.drawPolygon(new int[]{x,x+width,x}, new int[]{y,y,y+width},3);
				}


				graphics.setColor(l_colorT2);
				graphics.fillPolygon(new int[]{x+width,x+width,x}, new int[]{y,y+width,y+width},3);
				if(border){
					graphics.setColor(Color.black);
					graphics.drawPolygon(new int[]{x+width,x+width,x}, new int[]{y,y+width,y+width},3);
				}
			}
			else{
				l_colorT1 = getTriangleColor(x,y,2, image);
				l_colorT2 = getTriangleColor(x,y,3, image);


				graphics.setColor(l_colorT1);
				graphics.fillPolygon(new int[]{x,x+width,x+width}, new int[]{y,y,y+width},3);
				if(border){
					graphics.setColor(Color.black);
					graphics.drawPolygon(new int[]{x,x+width,x+width}, new int[]{y,y,y+width},3);
				}	



				graphics.setColor(l_colorT2);
				graphics.fillPolygon(new int[]{x, x+width,x}, new int[]{y,y+width,y+width},3);
				if(border){
					graphics.setColor(Color.black);
					graphics.drawPolygon(new int[]{x, x+width,x}, new int[]{y,y+width,y+width},3);
				}
			}
			performanceMeter.stepsFinished(image.getWidth());	
			t*=-1;
		}
		if(l_aux){
			t*=-1;
		}
	}
}
 
Example 18
Source File: MiniMap.java    From megamek with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draw a line to represent an attack
 */
private void paintAttack(Graphics g, AttackAction attack) {
    Entity source = m_game.getEntity(attack.getEntityId());
    Targetable target = m_game.getTarget(attack.getTargetType(),
            attack.getTargetId());
    // sanity check...
    if ((null == source) || (null == target)) {
        return;
    }

    if (attack.getTargetType() == Targetable.TYPE_INARC_POD) {
        // iNarc pods don't have a position, so lets scrap this idea, shall
        // we?
        return;
    }
    if (attack instanceof WeaponAttackAction) {
        WeaponAttackAction waa = (WeaponAttackAction) attack;
        if ((attack.getTargetType() == Targetable.TYPE_HEX_ARTILLERY)
                && (waa.getEntity(m_game).getOwner().getId() != m_client
                        .getLocalPlayer().getId())) {
            return;
        }
    }
    Color oldColor = g.getColor();

    int[] xPoints = new int[4];
    int[] yPoints = new int[4];

    xPoints[0] = ((source.getPosition().getX() * (hexSide[zoom] + hexSideBySin30[zoom]))
            + leftMargin + ((int) 1.5 * hexSide[zoom])) - 2;
    yPoints[0] = (((2 * source.getPosition().getY()) + 1 + (source
            .getPosition().getX() % 2)) * hexSideByCos30[zoom]) + topMargin;
    xPoints[1] = ((target.getPosition().getX() * (hexSide[zoom] + hexSideBySin30[zoom]))
            + leftMargin + ((int) 1.5 * hexSide[zoom])) - 2;
    yPoints[1] = (((2 * target.getPosition().getY()) + 1 + (target
            .getPosition().getX() % 2)) * hexSideByCos30[zoom]) + topMargin;
    xPoints[2] = xPoints[1] + 2;
    xPoints[3] = xPoints[0] + 2;
    if (((source.getPosition().getX() > target.getPosition().getX()) && (source
            .getPosition().getY() < target.getPosition().getY()))
            || ((source.getPosition().getX() < target.getPosition().getX()) && (source
                    .getPosition().getY() > target.getPosition().getY()))) {
        yPoints[3] = yPoints[0] + 2;
        yPoints[2] = yPoints[1] + 2;
    } else {
        yPoints[3] = yPoints[0] - 2;
        yPoints[2] = yPoints[1] - 2;
    }
    g.setColor(PlayerColors.getColor(source.getOwner().getColorIndex()));
    g.fillPolygon(xPoints, yPoints, 4);
    g.setColor(Color.black);
    g.drawPolygon(xPoints, yPoints, 4);

    // if this is mutual fire, draw a half-and-half line
    for (Enumeration<EntityAction> iter = m_game.getActions(); iter
            .hasMoreElements();) {
        EntityAction action = iter.nextElement();
        if (action instanceof AttackAction) {
            AttackAction otherAttack = (AttackAction) action;
            if ((attack.getEntityId() == otherAttack.getTargetId())
                    && (otherAttack.getEntityId() == attack.getTargetId())) {
                // attackTarget _must_ be an entity since it's shooting back
                // (?)
                Entity attackTarget = m_game.getEntity(otherAttack
                        .getEntityId());
                g.setColor(PlayerColors.getColor(attackTarget.getOwner()
                        .getColorIndex()));

                xPoints[0] = xPoints[3];
                yPoints[0] = yPoints[3];
                xPoints[1] = xPoints[2];
                yPoints[1] = yPoints[2];
                xPoints[2] = xPoints[1] + 2;
                xPoints[3] = xPoints[0] + 2;
                if (((source.getPosition().getX() > target.getPosition()
                        .getX()) && (source.getPosition().getY() < target
                        .getPosition().getY()))
                        || ((source.getPosition().getX() < target
                                .getPosition().getX()) && (source
                                .getPosition().getY() > target
                                .getPosition().getY()))) {
                    yPoints[3] = yPoints[0] + 2;
                    yPoints[2] = yPoints[1] + 2;
                } else {
                    yPoints[3] = yPoints[0] - 2;
                    yPoints[2] = yPoints[1] - 2;
                }
                g.fillPolygon(xPoints, yPoints, 4);
                g.setColor(Color.black);
                g.drawPolygon(xPoints, yPoints, 4);
                break;
            }
        }
    }

    g.setColor(oldColor);
}
 
Example 19
Source File: BasicSection.java    From libreveris with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean render (Graphics g,
                       boolean drawBorders)
{
    Rectangle clip = g.getClipBounds();
    Rectangle rect = getBounds();
    Color oldColor = g.getColor();

    if (clip.intersects(rect)) {
        // Default section color
        Color color = isVertical() ? Colors.GRID_VERTICAL
                : Colors.GRID_HORIZONTAL;

        // Use color defined for section glyph shape, if any
        Glyph glyph = getGlyph();

        if (glyph != null) {
            Shape shape = glyph.getShape();

            if (shape != null) {
                color = shape.getColor();
            }
        }

        g.setColor(color);

        // Fill polygon with proper color
        Polygon polygon = getPolygon();
        g.fillPolygon(polygon.xpoints, polygon.ypoints, polygon.npoints);

        // Draw polygon borders if so desired
        if (drawBorders) {
            g.setColor(Color.black);
            g.drawPolygon(
                    polygon.xpoints,
                    polygon.ypoints,
                    polygon.npoints);
        }

        g.setColor(oldColor);

        return true;
    } else {
        return false;
    }
}
 
Example 20
Source File: TileImageReconstructor.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
private void createMap() {
  textOptionPane.show();
  final GraphicsConfiguration localGraphicSystem =
      GraphicsEnvironment.getLocalGraphicsEnvironment()
          .getDefaultScreenDevice()
          .getDefaultConfiguration();
  final BufferedImage mapImage =
      localGraphicSystem.createCompatibleImage(sizeX, sizeY, Transparency.TRANSLUCENT);
  final Graphics graphics = mapImage.getGraphics();
  for (int x = 0; x * TILE_SIZE < sizeX; x++) {
    for (int y = 0; y * TILE_SIZE < sizeY; y++) {
      final String tileName = x + "_" + y + ".png";
      final File tileFile = new File(baseTileLocation, tileName);
      if (!tileFile.exists()) {
        continue;
      }
      final Image tile = Toolkit.getDefaultToolkit().createImage(tileFile.getPath());
      Util.ensureImageLoaded(tile);
      final Rectangle tileBounds =
          new Rectangle(
              x * TILE_SIZE,
              y * TILE_SIZE,
              Math.min((x * TILE_SIZE) + TILE_SIZE, sizeX),
              Math.min((y * TILE_SIZE) + TILE_SIZE, sizeY));
      graphics.drawImage(
          tile,
          tileBounds.x,
          tileBounds.y,
          tileBounds.x + tileBounds.width,
          tileBounds.y + tileBounds.height,
          0,
          0,
          tileBounds.width,
          tileBounds.height,
          null);
      textOptionPane.appendNewLine("Drew " + tileName);
    }
  }
  if (polygons != null && !polygons.isEmpty()) {
    graphics.setColor(Color.black);
    textOptionPane.appendNewLine("Drawing Polygons");
    for (final Entry<String, List<Polygon>> entry : polygons.entrySet()) {
      for (final Polygon poly : entry.getValue()) {
        graphics.drawPolygon(poly.xpoints, poly.ypoints, poly.npoints);
      }
    }
  }
  textOptionPane.appendNewLine("Saving as " + imageSaveLocation + " ... ");
  try {
    ImageIO.write(mapImage, "png", new File(imageSaveLocation));
  } catch (final IOException e) {
    log.log(Level.SEVERE, "Failed to save image: " + imageSaveLocation, e);
  }
  textOptionPane.appendNewLine("Wrote " + imageSaveLocation);
  textOptionPane.appendNewLine("\r\nAll Finished!");
  textOptionPane.countDown();
  textOptionPane.dispose();
  JOptionPane.showMessageDialog(null, new JLabel("All Finished"));
}