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

The following examples show how to use java.awt.Graphics2D#fillOval() . 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: ClearIcon.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);

	Stroke oldStroke = g.getStroke();

	g.setColor(hover ? Color.GRAY : Color.LIGHT_GRAY);
	g.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
	g.fillOval(x + 2, y + 2, 18, 18);
	g.setColor(Color.WHITE);
	g.drawLine(x + 6, y + 6, x + 15, y + 15);
	g.drawLine(x + 15, y + 6, x + 6, y + 15);

	g.setStroke(oldStroke);
}
 
Example 2
Source File: TSFrame.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: TrackerTab.java    From jeveassets with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
	Graphics2D g2d = (Graphics2D) g;
	//Render settings
	//g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
	g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	//Border
	g2d.setColor(Color.BLACK);
	g2d.fillOval(x + 2, y + 2, getIconWidth() - 4, getIconHeight() - 4);

	//Background
	g2d.setColor(color);
	g2d.fillOval(x + 3, y + 3, getIconWidth() - 6, getIconHeight() - 6);
}
 
Example 4
Source File: BMPCompressionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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 5
Source File: AntiDragOverlay.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Dimension render(Graphics2D g)
{
	g.setColor(color);

	final net.runelite.api.Point mouseCanvasPosition = client.getMouseCanvasPosition();
	final Point mousePosition = new Point(mouseCanvasPosition.getX() - RADIUS, mouseCanvasPosition.getY() - RADIUS);
	final Rectangle bounds = new Rectangle(mousePosition.x, mousePosition.y, 2 * RADIUS, 2 * RADIUS);
	g.fillOval(bounds.x, bounds.y, bounds.width, bounds.height);

	return bounds.getSize();
}
 
Example 6
Source File: RangeSlider.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void paintBar(Graphics2D g) {
    List<String> list = getPaintingModel().getPositions();
    int barStartY = getBarStartY();

    g.setColor(BAR_COLOR);
    g.fillRect(getXPosition(0), barStartY + BAR_HEIGHT / 2 - BAR_THICKNESS / 2, getXPosition(list.size() - 1) - getXPosition(0), BAR_THICKNESS);

    int circleCenterY = barStartY + BAR_HEIGHT / 2;
    for (int i = 0; i < list.size(); i++) {
        int curX = getXPosition(i);
        g.setColor(getPaintingModel().getColors().get(i));
        g.fillOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE);
        g.setColor(Color.black);
        g.drawOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE);


        String curS = list.get(i);
        if (curS != null && curS.length() > 0) {
            int startX = getStartXPosition(i);
            int endX = getEndXPosition(i);
            FontMetrics metrics = g.getFontMetrics();
            Rectangle bounds = metrics.getStringBounds(curS, g).getBounds();
            if (bounds.width < endX - startX && bounds.height < barStartY) {
                g.setColor(Color.black);
                g.drawString(curS, startX + (endX - startX) / 2 - bounds.width / 2, barStartY / 2 + bounds.height / 2);
            }
        }
    }

}
 
Example 7
Source File: RangeSlider.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void paintBar(Graphics2D g) {
    List<String> list = getPaintingModel().getPositions();
    int barStartY = getBarStartY();

    g.setColor(BAR_COLOR);
    g.fillRect(getXPosition(0), barStartY + BAR_HEIGHT / 2 - BAR_THICKNESS / 2, getXPosition(list.size() - 1) - getXPosition(0), BAR_THICKNESS);

    int circleCenterY = barStartY + BAR_HEIGHT / 2;
    for (int i = 0; i < list.size(); i++) {
        int curX = getXPosition(i);
        g.setColor(getPaintingModel().getColors().get(i));
        g.fillOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE);
        g.setColor(Color.black);
        g.drawOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE);


        String curS = list.get(i);
        if (curS != null && curS.length() > 0) {
            int startX = getStartXPosition(i);
            int endX = getEndXPosition(i);
            FontMetrics metrics = g.getFontMetrics();
            Rectangle bounds = metrics.getStringBounds(curS, g).getBounds();
            if (bounds.width < endX - startX && bounds.height < barStartY) {
                g.setColor(Color.black);
                g.drawString(curS, startX + (endX - startX) / 2 - bounds.width / 2, barStartY / 2 + bounds.height / 2);
            }
        }
    }

}
 
Example 8
Source File: JTagsDialog.java    From jeveassets 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) {
	Graphics2D g2d = (Graphics2D) g;
	if (image != null) { //Selected
		//Render settings
		//g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
		g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

		//Border
		g2d.setColor(Color.BLACK);
		g2d.fillOval(x, y, getIconWidth() - 1, getIconHeight() - 1);

		//Background
		g2d.setColor(tagColor.getBackground());
		g2d.fillOval(x + 1, y + 1, getIconWidth() - 3, getIconHeight() - 3);

		//Image
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
		g.drawImage(image, x + 2, y + 2, null);
	} else { //Not selected
		//Render settings
		g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

		//Background
		g2d.setColor(tagColor.getBackground());
		g2d.fillRect(x, y, getIconWidth() - 1, getIconHeight() - 1);

		//Border
		g2d.setColor(Color.BLACK);
		g2d.drawRect(x, y, getIconWidth() - 1, getIconHeight() - 1);

		//Text
		g2d.setFont(new JLabel().getFont());
		g2d.setColor(tagColor.getForeground());
		g2d.drawString("a", x + 5, y + 11);
	}
}
 
Example 9
Source File: MtcnnUtil.java    From mtcnn-java with Apache License 2.0 5 votes vote down vote up
public static BufferedImage drawFaceAnnotations(BufferedImage originalImage, FaceAnnotation[] faceAnnotations) {

		Graphics2D g = originalImage.createGraphics();
		g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

		Stroke stroke = g.getStroke();
		Color color = g.getColor();
		g.setStroke(new BasicStroke(3));
		g.setColor(Color.YELLOW);

		int radius = 2;
		for (FaceAnnotation faceAnnotation : faceAnnotations) {
			FaceAnnotation.BoundingBox bbox = faceAnnotation.getBoundingBox();
			g.drawRect(bbox.getX(), bbox.getY(), bbox.getW(), bbox.getH());
			for (FaceAnnotation.Landmark lm : faceAnnotation.getLandmarks()) {
				g.fillOval(lm.getPosition().getX() - radius, lm.getPosition().getY() - radius,
						2 * radius, 2 * radius);
			}
		}

		g.setStroke(stroke);
		g.setColor(color);

		g.dispose();

		return originalImage;
	}
 
Example 10
Source File: RangeSlider.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void paintBar(Graphics2D g) {
    List<String> list = getPaintingModel().getPositions();
    int barStartY = getBarStartY();

    g.setColor(BAR_COLOR);
    g.fillRect(getXPosition(0), barStartY + BAR_HEIGHT / 2 - BAR_THICKNESS / 2, getXPosition(list.size() - 1) - getXPosition(0), BAR_THICKNESS);

    int circleCenterY = barStartY + BAR_HEIGHT / 2;
    for (int i = 0; i < list.size(); i++) {
        int curX = getXPosition(i);
        g.setColor(getPaintingModel().getColors().get(i));
        g.fillOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE);
        g.setColor(Color.black);
        g.drawOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE);


        String curS = list.get(i);
        if (curS != null && curS.length() > 0) {
            int startX = getStartXPosition(i);
            int endX = getEndXPosition(i);
            FontMetrics metrics = g.getFontMetrics();
            Rectangle bounds = metrics.getStringBounds(curS, g).getBounds();
            if (bounds.width < endX - startX && bounds.height < barStartY) {
                g.setColor(Color.black);
                g.drawString(curS, startX + (endX - startX) / 2 - bounds.width / 2, barStartY / 2 + bounds.height / 2);
            }
        }
    }

}
 
Example 11
Source File: ShapeIcon.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
protected void paint(Component c, Graphics2D g, int x, int y) {
	g.fillOval(x + 1, y + 1, 5, 5);
	g.fillOval(x + 2, y + 4, 5, 5);
	g.fillOval(x + 5, y + 7, 5, 5);
	g.fillOval(x + 3, y + 2, 5, 5);
	g.fillOval(x + 10, y + 7, 5, 5);
}
 
Example 12
Source File: PopupMenuLeakTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static Image createTrayIconImage() {
    /**
     * Create a small image of a red circle to use as the icon for the tray icon
     */
    int trayIconImageSize = 32;
    final BufferedImage trayImage = new BufferedImage(trayIconImageSize, trayIconImageSize, BufferedImage.TYPE_INT_ARGB);
    final Graphics2D trayImageGraphics = (Graphics2D) trayImage.getGraphics();

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

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

    trayImageGraphics.setColor(Color.red);

    int trayIconImageInset = 4;
    trayImageGraphics.fillOval(trayIconImageInset,
            trayIconImageInset,
            trayImage.getWidth() - 2 * trayIconImageInset,
            trayImage.getHeight() - 2 * trayIconImageInset);

    trayImageGraphics.setColor(Color.darkGray);

    trayImageGraphics.drawOval(trayIconImageInset,
            trayIconImageInset,
            trayImage.getWidth() - 2 * trayIconImageInset,
            trayImage.getHeight() - 2 * trayIconImageInset);

    return trayImage;
}
 
Example 13
Source File: XYSelectionOverlay.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
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 14
Source File: InterestPointOverlay.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void drawOverlays( final Graphics g )
{
	final Graphics2D graphics = ( Graphics2D ) g;
	final int t = viewer.getState().getCurrentTimepoint();
	final double[] lPos = new double[ 3 ];
	final double[] gPos = new double[ 3 ];
	final AffineTransform3D transform = new AffineTransform3D();

	for ( final InterestPointSource pointSource : interestPointSources )
	{
		pointSource.getLocalToGlobalTransform( t, transform );
		transform.preConcatenate( viewerTransform );

		for ( final RealLocalizable p : pointSource.getLocalCoordinates( t ) )
		{
			p.localize( lPos );
			transform.apply( lPos, gPos );
			final double size = getPointSize( gPos );
			final int x = ( int ) ( gPos[ 0 ] - 0.5 * size );
			final int y = ( int ) ( gPos[ 1 ] - 0.5 * size );
			final int w = ( int ) size;
			graphics.setColor( getColor( gPos ) );
			graphics.fillOval( x, y, w, w );
		}
	}
}
 
Example 15
Source File: BMPPluginTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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 16
Source File: ShapeIcon.java    From settlers-remake with MIT License 4 votes vote down vote up
@Override
protected void paint(Component c, Graphics2D g, int x, int y) {
	g.fillOval(x + 5, y + 5, 6, 6);
}
 
Example 17
Source File: ShapeIcon.java    From settlers-remake with MIT License 4 votes vote down vote up
@Override
protected void paint(Component c, Graphics2D g, int x, int y) {
	g.fillOval(x + 1, y + 1, 14, 14);
}
 
Example 18
Source File: FlatRadioButtonIcon.java    From FlatLaf with Apache License 2.0 4 votes vote down vote up
@Override
protected void paintBorder( Graphics2D g2 ) {
	g2.fillOval( 0, 0, 15, 15 );
}
 
Example 19
Source File: Cell.java    From JavaExercises with GNU General Public License v2.0 4 votes vote down vote up
public void paint(Graphics2D g) {           // object rendering
    g.setColor(color);
    g.fillOval(x * size, y * size,        // upper left corner
            size, size);                  // width and height
}
 
Example 20
Source File: CountResults.java    From lizzie with GNU General Public License v3.0 4 votes vote down vote up
public void paint(Graphics g) {
  Graphics2D g2 = (Graphics2D) g;
  Image image = Lizzie.config.theme.background();
  try {
    image = ImageIO.read(getClass().getResourceAsStream("/assets/countbackground.jpg"));
  } catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
  }
  int withtimes = (340 / image.getWidth(getOwner())) + 1;
  int highttimes = (260 / image.getHeight(getOwner())) + 1;

  for (int i = 0; i < highttimes; i++) {
    for (int j = 0; j < withtimes; j++) {
      g2.drawImage(image, image.getWidth(getOwner()) * j, image.getHeight(getOwner()) * i, null);
    }
  }
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g2.setColor(Color.BLACK);
  g2.setStroke(new BasicStroke(2f));
  g2.fillOval(30, 58, 20, 20);
  g2.setColor(Color.WHITE);
  g2.fillOval(170, 58, 20, 20);
  g2.setColor(Color.BLACK);
  g2.setFont(new Font(Lizzie.config.uiFontName, Font.BOLD, 25));
  if (allBlackCounts >= allWhiteCounts) {
    g2.setColor(Color.BLACK);
    g2.drawString(resourceBundle.getString("CountDialog.bigBlack"), 25, 50);
  } else {
    g2.setColor(Color.WHITE);
    g2.drawString(resourceBundle.getString("CountDialog.bigWhite"), 25, 50);
  }
  g2.setFont(new Font(Lizzie.config.uiFontName, Font.BOLD, 20));
  g2.drawString(
      resourceBundle.getString("CountDialog.onBoardLead")
          + Math.abs(allBlackCounts - allWhiteCounts)
          + resourceBundle.getString("CountDialog.points"),
      53,
      50);
  g2.setColor(Color.BLACK);
  g2.setFont(new Font(Lizzie.config.uiFontName, Font.BOLD, 17));
  g2.drawString(resourceBundle.getString("CountDialog.areaCount"), 95, 100);
  g2.drawString(resourceBundle.getString("CountDialog.eat"), 95, 130);
  g2.drawString(allBlackCounts + "", 32, 100);
  g2.drawString(blackEat + "", 32, 130);
  g2.setColor(Color.WHITE);
  g2.drawString(allWhiteCounts + "", 172, 100);
  g2.drawString(whiteEat + "", 172, 130);
  button.repaint();
  button2.repaint();
}