Java Code Examples for java.awt.Graphics2D.fillOval()

The following are Jave code examples for showing how to use fillOval() of the java.awt.Graphics2D class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: UpdatePopupMenu.java   View Source Code Vote up 6 votes
private Image createSystemTrayIconImage() {
    final BufferedImage trayImage = new BufferedImage(
            imageSize,
            imageSize,
            BufferedImage.TYPE_INT_ARGB);

    final Graphics2D imageGraphics = (Graphics2D) trayImage.getGraphics();

    imageGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);

    imageGraphics.setColor(new Color(255, 255, 255, 0));
    imageGraphics.fillRect(0, 0, trayImage.getWidth(),
            trayImage.getHeight());

    imageGraphics.setColor(Color.green);

    int imageWidth = trayImage.getWidth() - 2 * imageInset;
    int imageHeight = trayImage.getHeight() - 2 * imageInset;

    imageGraphics.fillOval(imageInset, imageInset, imageWidth, imageHeight);
    imageGraphics.setColor(Color.darkGray);
    imageGraphics.drawOval(imageInset, imageInset, imageWidth, imageHeight);

    return trayImage;
}
 
Example 2
Project: openjdk-jdk10   File: TSFrame.java   View Source Code Vote up 6 votes
private static void render(Graphics g, int w, int h, boolean useNonOpaque) {
    if (useNonOpaque) {
        Graphics2D g2d = (Graphics2D)g;
        GradientPaint p =
            new GradientPaint(0.0f, 0.0f,
                              new Color(rnd.nextInt(0xffffff)),
                              w, h,
                              new Color(rnd.nextInt(0xff),
                                        rnd.nextInt(0xff),
                                        rnd.nextInt(0xff), 0),
                              true);
        g2d.setPaint(p);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.fillOval(0, 0, w, h);
    } else {
        g.setColor(new Color(rnd.nextInt(0xffffff)));
        g.fillRect(0, 0, w, h);
    }
}
 
Example 3
Project: java-course   File: CircleWorker.java   View Source Code Vote up 6 votes
/**
 * {@inheritDoc}
 */
@Override
public void processRequest(RequestContext context) {
    final int size = 200;
    BufferedImage bim = new BufferedImage(size, size,
            BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D g2d = bim.createGraphics();
    g2d.setColor(Color.WHITE);
    g2d.fillRect(0, 0, size, size);
    g2d.setColor(Color.RED);
    g2d.fillOval(0, 0, size, size);
    g2d.dispose();

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        ImageIO.write(bim, "png", bos);
        context.setMimeType("image/png");
        context.write(bos.toByteArray());
    } catch (IOException e) {
        System.out.println("Server ERROR: " + e.getMessage());
    }

}
 
Example 4
Project: jmt   File: Convex2DGraph.java   View Source Code Vote up 6 votes
/**
 * It draw a temporary point when a point is moved in another place
 * 
 * @param g
 *            The graphic object
 * @param p
 *            The position of the point
 * @param c
 *            The color of the point
 * @param size
 *            The size of the point
 */
public void drawShadowPoint(Graphics2D g, Point p, Color c, int size) {
	g.setColor(c);

	int fontSize = 7 + getPointSize();
	Font f = new Font("Arial", Font.PLAIN, fontSize);
	g.setFont(f);
	double x = Math.max(p.getX(), GRAPH_LEFT_MARGIN);
	double y = Math.min(p.getY(), getHeight() - GRAPH_BOTTOM_MARGIN);

	g.drawString("(" + FORMAT_3_DEC.format(getTrueX(x)) + ", "
			+ FORMAT_3_DEC.format(getTrueY(y)) + ")",
			(int) (x - (fontSize * 3)), (int) y - 5 - getPointSize());

	g.drawOval((int) x - (((size / 2))), (int) y - (((size / 2))), size,
			size);

	g.setColor(Color.GRAY);
	Composite oldComp = g.getComposite();
	Composite alphaComp = AlphaComposite.getInstance(
			AlphaComposite.SRC_OVER, 0.3f);
	g.setComposite(alphaComp);
	g.fillOval((int) x - (((size / 2))), (int) y - (((size / 2))), size,
			size);
	g.setComposite(oldComp);
}
 
Example 5
Project: jmt   File: PainterConvex2D.java   View Source Code Vote up 6 votes
/**
 * It draw a temporary point when a point is moved in another place
 * @param g The graphic object
 * @param p The position of the point
 * @param c The color of the point
 * @param size The size of the point
 */
public void drawShadowPoint(Graphics2D g, Point p, Color c, int size) {
	g.setColor(c);

	int fontSize = 7 + pointSize;
	Font f = new Font("Arial", Font.PLAIN, fontSize);
	g.setFont(f);
	double x = Math.max((p.getX() - tran_x) / scale, 0);
	double y = Math.max((-p.getY() + tran_y) / scale, 0);
	double X = (x * scale) + tran_x;
	double Y = -((y * scale) - tran_y);

	g.drawString("(" + format2Dec.format(x) + ", " + format2Dec.format(y) + ")", (int) (X - (fontSize * 3)), (int) Y - 5 - pointSize);

	g.drawOval((int) X - (((size / 2))), (int) Y - (((size / 2))), size, size);

	g.setColor(Color.GRAY);
	Composite oldComp = g.getComposite();
	Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
	g.setComposite(alphaComp);
	g.fillOval((int) X - (((size / 2))), (int) Y - (((size / 2))), size, size);
	g.setComposite(oldComp);

}
 
Example 6
Project: snake_classic   File: ButtonBack.java   View Source Code Vote up 6 votes
@Override
	protected void paintComponent(Graphics g) {
		// TODO Auto-generated method stub
//		super.paintComponent(g);
		graphics2d = (Graphics2D)g;
		if(getModel().isArmed()){
			graphics2d.setColor(Color.RED);
		}
		else{
			graphics2d.setColor(getBackground());
		}
		graphics2d.fillOval(0
				, 0,
				getSize().width-1,
				getSize().height-1);
		super.paintComponent(graphics2d);
		
	}
 
Example 7
Project: incubator-netbeans   File: ProfilerXYSelectionOverlay.java   View Source Code Vote up 5 votes
public void paint(Graphics g) {
    if (selectedValues.isEmpty()) return;

    Graphics2D g2 = (Graphics2D)g;
    g2.setRenderingHints(chart.getRenderingHints());

    Iterator<Point> it = selectedValues.iterator();
    boolean linePainted = false;

    while (it.hasNext()) {
        Point p = it.next();

        if (!linePainted) {
            g2.setPaint(evenPerfPaint);
            g2.setStroke(evenPerfStroke);
            g2.drawLine(p.x, 0, p.x, getHeight());
            g2.setPaint(oddPerfPaint);
            g2.setStroke(oddPerfStroke);
            g2.drawLine(p.x, 0, p.x, getHeight());

            g2.setPaint(markPaint);
            g2.setStroke(markStroke);

            linePainted = true;
        }

        g2.fillOval(p.x - selectionExtent + 1, p.y - selectionExtent + 1,
                    selectionExtent * 2 - 1, selectionExtent * 2 - 1);
    }

}
 
Example 8
Project: ramus   File: StartupPanel.java   View Source Code Vote up 5 votes
@Override
protected void paintComponent(Graphics g) {
    final float POINTS = 9;
    final float SIZE = 8;

    Graphics2D g2 = (Graphics2D) g.create();
    g2.setColor(Color.BLUE);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    long time = gTime;
    gTime += 1;
    time %= POINTS + 1;

    double angle = time / (POINTS + 1) * Math.PI * 2.0;

    double w = getWidth();
    double h = getHeight();

    for (int i = 0; i < POINTS; i++) {
        double x = Math.sin(angle);
        double y = -Math.cos(angle);

        angle += Math.PI * 2.0 / (POINTS + 1);

        float strength = 1f - (POINTS - i - 1) / POINTS;
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, strength));

        double mx = w / 2 + x * w * (SIZE - 2) / SIZE / 2.0;
        double my = h / 2 + y * h * (SIZE - 2) / SIZE / 2.0;

        g2.fillOval((int) (mx - w / SIZE / 2), (int) (my - h / SIZE / 2), (int) (w / SIZE), (int) (h / SIZE));
    }

    g2.dispose();
}
 
Example 9
Project: COE1186   File: TrackRenderWindow.java   View Source Code Vote up 5 votes
public void drawBeacons(Graphics2D g2d){

        for (int i = 0; i < blocks.size(); i++){
            if (blocks.get(i).getBeacon() != null){
                
                double[] x_coords = blocks.get(i).getXCoordinates();
                double[] y_coords = blocks.get(i).getYCoordinates();

                int x = (int)x_coords[x_coords.length/2]-1;
                int y = (int)y_coords[x_coords.length/2]-1;
                int w = 3;
                int h = 3;

                // Semi transparent glow layer 1
                g2d.setColor(new Color(0, 100, 255, 50));
                g2d.fillOval(x - 5, y - 5, w + 10, h + 10);

                // Semi transparent glow layer 2
                g2d.setColor(new Color(0, 100, 255, 30));
                g2d.fillOval(x - 12, y - 12, w + 24, h + 24);

                // Nice blue color :)
                g2d.setColor(new Color(0, 100, 255));
                g2d.fillOval(x, y, w, h);
            
            }
        }
    }
 
Example 10
Project: openjdk-jdk10   File: BMPCompressionTest.java   View Source Code Vote up 5 votes
private static BufferedImage createTestImage(int type)
  throws IOException {

    int w = 200;
    int h = 200;
    BufferedImage b = new BufferedImage(w, h, type);
    Graphics2D g = b.createGraphics();
    g.setColor(Color.white);
    g.fillRect(0,0, w, h);
    g.setColor(Color.black);
    g.fillOval(10, 10, w -20, h-20);

    return b;
}
 
Example 11
Project: Pet-Supply-Store   File: ImageCreator.java   View Source Code Vote up 5 votes
private static void makeOval(Graphics2D graphics, ImageSize maxSize, Random rand) {
	switchColor(graphics, rand);
	
	int x = rand.nextInt(maxSize.getWidth());
	int y = rand.nextInt(maxSize.getHeight());
	int width = rand.nextInt(maxSize.getWidth() - x) + 1;
	int height = rand.nextInt(maxSize.getHeight() - y) + 1;

	if (rand.nextBoolean()) {
		graphics.fillOval(x, y, width, height);
	}

	graphics.drawOval(x, y, width, height);
}
 
Example 12
Project: JuggleMasterPro   File: Body.java   View Source Code Vote up 5 votes
final public void drawHead(Graphics2D objPgraphics2D, float fltPframeSizeRatio, boolean bolPfill) {
	if (bolPfill) {
		objPgraphics2D.fillOval(Math.round((Constants.intS_GRAPHICS_CORRECTION_X + this.intGheadX - this.intGheadRadius - 2) * fltPframeSizeRatio),
								Math.round((this.intGheadY - this.intGheadRadius * 1.1F - 2) * fltPframeSizeRatio),
								Math.round((2 * this.intGheadRadius + 4) * fltPframeSizeRatio),
								Math.round((2 * this.intGheadRadius * 1.1F + 4) * fltPframeSizeRatio));
	} else {
		objPgraphics2D.drawOval(Math.round((Constants.intS_GRAPHICS_CORRECTION_X + this.intGheadX - this.intGheadRadius) * fltPframeSizeRatio),
								Math.round((this.intGheadY - this.intGheadRadius * 1.1F) * fltPframeSizeRatio),
								Math.round(2 * this.intGheadRadius * fltPframeSizeRatio),
								Math.round(2 * this.intGheadRadius * 1.1F * fltPframeSizeRatio));
	}
}
 
Example 13
Project: jmt   File: Convex2DGraph.java   View Source Code Vote up 4 votes
/**
 * It draws that explains the simbols on the graphic
 * 
 * @param g
 *            The graphic object
 */
public void summary(Graphics2D g) {
	int size = getPointSize() + 1;
	int x = getWidth() - 53 - (getPointSize() * 5);
	int y = 7 + size;
	int fontSize = 6 + Math.min(getPointSize() + 1, 9);
	Font f = new Font("Arial", Font.PLAIN, fontSize);
	g.setFont(f);

	// Potential Bottleneck
	g.setColor(Color.RED);
	g.fillOval(5 + (x) - ((size / 2)), (int) (y + (0.5) * fontSize)
			- ((Math.min(getPointSize() + 1, 9) / 2)),
			Math.min(getPointSize() + 1, 9),
			Math.min(getPointSize() + 1, 9));
	g.setColor(Color.BLACK);
	g.drawString("Potential", x + 11 + ((size / 2)), y);
	g.drawString("Bottleneck", x + 11 + ((size / 2)), y + fontSize);
	g.drawString("Stations", x + 11 + ((size / 2)), y + 2 * fontSize);

	// Masked-off
	g.setColor(Color.BLUE);
	g.fillOval(5 + (x) - ((size / 2)),
			-3 + y + (4) * fontSize - Math.min(getPointSize() + 1, 9),
			Math.min(getPointSize() + 1, 9),
			Math.min(getPointSize() + 1, 9));
	g.setColor(Color.BLACK);
	g.drawString("Masked-off", x + 11 + ((size / 2)), 3 + y + (3)
			* fontSize);
	g.drawString("Stations", x + 11 + ((size / 2)), 3 + y + (4) * fontSize);

	// Dominated
	g.setColor(new Color(15, 185, 100));
	g.fillOval(
			5 + (x) - ((size / 2)),
			6 + y + (((6 * fontSize) + (5 * fontSize)) / 2)
					- Math.min(getPointSize() + 1, 9),
			Math.min(getPointSize() + 1, 9),
			Math.min(getPointSize() + 1, 9));
	g.setColor(Color.BLACK);
	g.drawString("Dominated", x + 11 + ((size / 2)), 6 + y + (5) * fontSize);
	g.drawString("Stations", x + 11 + ((size / 2)), 6 + y + (6) * fontSize);

	// Masked off-Area
	g.drawString("Masked-off", x + 11 + ((size / 2)), 2 + y + (8)
			* fontSize);
	g.drawString("Area", x + 11 + ((size / 2)), 2 + y + (9) * fontSize);
	int xP1 = 4 + x - ((size / 2));
	int yP1 = 3 + y + (8) * fontSize + ((size / 2));
	int xP2 = 4 + x + size;
	int yP2 = 3 + (y + (8) * fontSize) - size;

	Polygon p = twoPointRectangle(xP1, yP1, xP2, yP2);

	g.setColor(Color.ORANGE);
	g.fill(p);
	g.setColor(Color.GRAY);
	g.draw(p);

	// Dominated Area
	g.setColor(Color.BLACK);
	g.drawString("Dominated", x + 11 + ((size / 2)), 3 + y + (10)
			* fontSize);
	g.drawString("Area", x + 11 + ((size / 2)), 3 + y + (11) * fontSize);
	xP1 = 4 + x - ((size / 2));
	yP1 = 4 + y + (10) * fontSize + ((size / 2));
	xP2 = 4 + x + size;
	yP2 = 4 + (y + (10) * fontSize) - size;

	p = twoPointRectangle(xP1, yP1, xP2, yP2);

	g.setColor(new Color(255, 250, 120));
	g.fill(p);
	g.setColor(Color.GRAY);
	g.draw(p);
}
 
Example 14
Project: jdk8u-jdk   File: MultiGradientTest.java   View Source Code Vote up 4 votes
public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D)g.create();

    int w = getWidth();
    int h = getHeight();
    g2d.setColor(Color.black);
    g2d.fillRect(0, 0, w, h);

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                         antialiasHint);
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
                         renderHint);

    g2d.transform(transform);
    g2d.setPaint(paint);

    switch (shapeType) {
    default:
    case RECT:
        g2d.fillRect(0, 0, w, h);
        break;

    case ELLIPSE:
        g2d.fillOval(0, 0, w, h);
        break;

    case MULTIPLE:
        g2d.fillRect(0, 0, w/2, h/2);
        g2d.fillOval(w/2, 0, w/2, h/2);
        g2d.drawOval(0, h/2, w/2, h/2);
        g2d.drawLine(0, h/2, w/2, h);
        g2d.drawLine(0, h, w/2, h/2);
        Polygon p = new Polygon();
        p.addPoint(w/2, h);
        p.addPoint(w, h);
        p.addPoint(3*w/4, h/2);
        g2d.fillPolygon(p);
        break;
    }

    switch (paintType) {
    default:
    case BASIC:
    case LINEAR:
        g2d.setColor(Color.white);
        g2d.fillRect(startX-1, startY-1, 2, 2);
        g2d.drawString("1", startX, startY + 12);
        g2d.fillRect(endX-1, endY-1, 2, 2);
        g2d.drawString("2", endX, endY + 12);
        break;

    case RADIAL:
        g2d.setColor(Color.white);
        g2d.fillRect(ctrX-1, ctrY-1, 2, 2);
        g2d.drawString("C", ctrX, ctrY + 12);
        g2d.fillRect(focusX-1, focusY-1, 2, 2);
        g2d.drawString("F", focusX, focusY + 12);
        break;
    }

    g2d.dispose();
}
 
Example 15
Project: SE2017-Team1   File: TestUtil.java   View Source Code Vote up 4 votes
public static void drawCond(
		Graphics2D g2d,
		int circleCondX, int circleCondY,
		int triangleCondX, int triangleCondY,
		int lineCondStartX, int lineCondEndX,
		char trianglePos, int addToLineX, int addToLineY) {
		
	g2d.setColor(Constants.CONDITION_RELATION_COLOR);
	
	// circle
	g2d.fillOval(circleCondX - Constants.DOT_SIZE / 2, circleCondY - Constants.DOT_SIZE /2, Constants.DOT_SIZE, Constants.DOT_SIZE);
	
	// triangle
	Point pCond1 = new Point(triangleCondX, triangleCondY);
	int pResp2X = 0;
	int pResp3X = 0;
	int pResp2Y = 0;
	int pResp3Y = 0;
	
	switch(trianglePos) {
	  	case 'U':
			pResp2X = pCond1.x - Constants.TRIANGLE_HEIGHT / 2;
			pResp3X = pCond1.x + Constants.TRIANGLE_HEIGHT / 2;
			pResp2Y = pCond1.y + Constants.TRIANGLE_HEIGHT;
			pResp3Y = pCond1.y + Constants.TRIANGLE_HEIGHT;
			break;
	  	case 'D':
			pResp2X = pCond1.x - Constants.TRIANGLE_HEIGHT / 2;
			pResp3X = pCond1.x + Constants.TRIANGLE_HEIGHT / 2;
			pResp2Y = pCond1.y - Constants.TRIANGLE_HEIGHT;
			pResp3Y = pCond1.y - Constants.TRIANGLE_HEIGHT;
			break;
		case 'L':
			pResp2X = pCond1.x + Constants.TRIANGLE_HEIGHT;
			pResp3X = pCond1.x + Constants.TRIANGLE_HEIGHT;
			pResp2Y = pCond1.y - Constants.TRIANGLE_HEIGHT / 2;
			pResp3Y = pCond1.y + Constants.TRIANGLE_HEIGHT / 2;
			break;
		case 'R':
	  		pResp2X = pCond1.x - Constants.TRIANGLE_HEIGHT;
	  		pResp3X = pCond1.x - Constants.TRIANGLE_HEIGHT;
	  		pResp2Y = pCond1.y - Constants.TRIANGLE_HEIGHT / 2;
	  		pResp3Y = pCond1.y + Constants.TRIANGLE_HEIGHT / 2;
	  		break;
	}
	  
	Point pCond2 = new Point(pResp2X, pResp2Y);
	Point pCond3 = new Point(pResp3X, pResp3Y);
	int[] xsCond = {pCond1.x, pCond2.x, pCond3.x};
	int[] ysCond = {pCond1.y, pCond2.y, pCond3.y};
	g2d.fillPolygon(xsCond, ysCond, 3);
	
	// line
    g2d.drawLine(circleCondX + addToLineX, circleCondY + addToLineY, lineCondStartX, lineCondEndX);
}
 
Example 16
Project: propan-jogl-examples   File: RadialMarkerApplication.java   View Source Code Vote up 4 votes
@Override
public void init(Graphics3D graphics) {
	
	//marker = TextureLoader.getInstance().loadTexture("/mark.png");
	
	BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
	Graphics2D g = image.createGraphics();
	
	g.setColor(Color.WHITE);
	g.fillRect(0, 0, 200, 200);
	
	g.setColor(Color.RED);
	g.fillOval(50, 50, 100, 100);
	
	g.setColor(Color.BLACK);
	
	int stroke = 8;
	
	g.setStroke(new BasicStroke(stroke));
	g.drawRect(stroke, stroke, 200-stroke*2, 200-stroke*2);
	
	marker = TextureLoader.getInstance().loadTexture(image);
}
 
Example 17
Project: freecol   File: MapViewer.java   View Source Code Vote up 4 votes
/**
 * Display a path.
 *
 * @param g The {@code Graphics2D} to display on.
 * @param path The {@code PathNode} to display.
 */
private void displayPath(Graphics2D g, PathNode path) {
    final Font font = FontLibrary.createFont(FontLibrary.FontType.NORMAL,
        FontLibrary.FontSize.TINY, lib.getScaleFactor());
    final boolean debug = FreeColDebugger
        .isInDebugMode(FreeColDebugger.DebugMode.PATHS);

    for (PathNode p = path; p != null; p = p.next) {
        Tile tile = p.getTile();
        if (tile == null) continue;
        Point point = calculateTilePosition(tile);
        if (point == null) continue;

        BufferedImage image = (p.isOnCarrier())
            ? ImageLibrary.getPathImage(ImageLibrary.PathType.NAVAL)
            : (activeUnit != null)
            ? ImageLibrary.getPathImage(activeUnit)
            : null;

        BufferedImage turns = (p.getTurns() <= 0) ? null
            : lib.getStringImage(g, Integer.toString(p.getTurns()),
                                  Color.WHITE, font);
        g.setColor((turns == null) ? Color.GREEN : Color.RED);

        if (debug) { // More detailed display
            if (activeUnit != null) {
                image = ImageLibrary.getPathNextTurnImage(activeUnit);
            }
            turns = lib.getStringImage(g, Integer.toString(p.getTurns())
                + "/" + Integer.toString(p.getMovesLeft()),
                Color.WHITE, font);
        }

        g.translate(point.x, point.y);
        if (image == null) {
            g.fillOval(halfWidth, halfHeight, 10, 10);
            g.setColor(Color.BLACK);
            g.drawOval(halfWidth, halfHeight, 10, 10);
        } else {
            tv.displayCenteredImage(g, image);
            if (turns != null) {
                tv.displayCenteredImage(g, turns);
            }
        }
        g.translate(-point.x, -point.y);
    }
}
 
Example 18
Project: chordatlas   File: ColPt.java   View Source Code Vote up 4 votes
@Override
public void paint( Graphics2D g, PanMouseAdaptor ma ) {
	g.setColor( color );
	g.fillOval( ma.toX( x )-2, ma.toY( y )-2, 4, 4 );
	
}
 
Example 19
Project: pacman-mas   File: Cell.java   View Source Code Vote up 4 votes
public void draw(Graphics2D canvas)
{
    int x = position.x,
        y = position.y;
            
    canvas.setColor(type.getColor());
    // TODO: Change some stuff to canvas.drawImage(...)
    
    switch (type)
    {
        case DOT:
            int xPos = Constant.BOARD_CELL_SIZE * x + (Constant.BOARD_CELL_SIZE / 4);
            int yPos = Constant.BOARD_CELL_SIZE * y + (Constant.BOARD_CELL_SIZE / 4);
            
            canvas.fillOval(
                yPos,
                xPos,
                Constant.BOARD_CELL_SIZE / 2, 
                Constant.BOARD_CELL_SIZE / 2   
            );
            
            break;
            
        case GHOST:
        case PACMAN:
        case POWERUP:
            canvas.fillOval(
                Constant.BOARD_CELL_SIZE * y,
                Constant.BOARD_CELL_SIZE * x, 
                Constant.BOARD_CELL_SIZE, 
                Constant.BOARD_CELL_SIZE    
            );
            
            break;
        default:
            canvas.fillRect(
                Constant.BOARD_CELL_SIZE * y,
                Constant.BOARD_CELL_SIZE * x, 
                Constant.BOARD_CELL_SIZE, 
                Constant.BOARD_CELL_SIZE
            );
    }
}
 
Example 20
Project: FreeCol   File: MapViewer.java   View Source Code Vote up 4 votes
/**
 * Display a path.
 *
 * @param g The {@code Graphics2D} to display on.
 * @param path The {@code PathNode} to display.
 */
private void displayPath(Graphics2D g, PathNode path) {
    final Font font = FontLibrary.createFont(FontLibrary.FontType.NORMAL,
        FontLibrary.FontSize.TINY, lib.getScaleFactor());
    final boolean debug = FreeColDebugger
        .isInDebugMode(FreeColDebugger.DebugMode.PATHS);

    for (PathNode p = path; p != null; p = p.next) {
        Tile tile = p.getTile();
        if (tile == null) continue;
        Point point = calculateTilePosition(tile);
        if (point == null) continue;

        BufferedImage image = (p.isOnCarrier())
            ? ImageLibrary.getPathImage(ImageLibrary.PathType.NAVAL)
            : (activeUnit != null)
            ? ImageLibrary.getPathImage(activeUnit)
            : null;

        BufferedImage turns = (p.getTurns() <= 0) ? null
            : lib.getStringImage(g, Integer.toString(p.getTurns()),
                                  Color.WHITE, font);
        g.setColor((turns == null) ? Color.GREEN : Color.RED);

        if (debug) { // More detailed display
            if (activeUnit != null) {
                image = ImageLibrary.getPathNextTurnImage(activeUnit);
            }
            turns = lib.getStringImage(g, Integer.toString(p.getTurns())
                + "/" + Integer.toString(p.getMovesLeft()),
                Color.WHITE, font);
        }

        g.translate(point.x, point.y);
        if (image == null) {
            g.fillOval(halfWidth, halfHeight, 10, 10);
            g.setColor(Color.BLACK);
            g.drawOval(halfWidth, halfHeight, 10, 10);
        } else {
            tv.displayCenteredImage(g, image);
            if (turns != null) {
                tv.displayCenteredImage(g, turns);
            }
        }
        g.translate(-point.x, -point.y);
    }
}