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

The following examples show how to use java.awt.Graphics#fillArc() . 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: GraphViewer.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * This method is called by Swing to draw this component.
 */
@Override
public void paintComponent(final Graphics gr) {
    super.paintComponent(gr);
    Graphics2D g2 = (Graphics2D) gr;
    AffineTransform oldAF = (AffineTransform) (g2.getTransform().clone());
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.scale(scale, scale);
    Object sel = (selected != null ? selected : highlight);
    GraphNode c = null;
    if (sel instanceof GraphNode && ((GraphNode) sel).shape() == null) {
        c = (GraphNode) sel;
        sel = c.ins.get(0);
    }
    graph.draw(new Artist(g2), scale, sel, true);
    if (c != null) {
        gr.setColor(((GraphEdge) sel).color());
        gr.fillArc(c.x() - 5 - graph.getLeft(), c.y() - 5 - graph.getTop(), 10, 10, 0, 360);
    }
    g2.setTransform(oldAF);
}
 
Example 2
Source File: ImagePanel.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void drawDecoration(Graphics g, int index, boolean selected) {
    if (selected)
        g.setColor(SELECTED_ANNOTATION_COLOR);
    else
        g.setColor(ANNOTATION_COLOR);
    g.fillRect(x, y, width - 1, height - 1);
    g.setColor(Color.RED);
    g.fillArc(x - 8, y - 8, 16, 16, 0, 359);
    g.setColor(Color.WHITE);
    Font f = g.getFont().deriveFont(Font.BOLD, 9);
    g.setFont(f);
    g.drawString(index + 1 + "", x - 4, y + 4);
}
 
Example 3
Source File: OrbitCanvas.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draw Planets' Body
 */
private void drawPlanetBody(Graphics og, Xyz planetPos, String strName) {
	Xyz xyz = planetPos.Rotate(this.mtxRotate);
	Point point = getDrawPoint(xyz);
	og.setColor(colorPlanet);
	og.fillArc(point.x - 2, point.y - 2, 5, 5, 0, 360);
	if (bPlanetName) {
		og.setColor(colorPlanetName);
		og.drawString(strName, point.x + 5, point.y);
	}
}
 
Example 4
Source File: RotaryController.java    From jsyn with Apache License 2.0 5 votes vote down vote up
private void drawArcIndicator(Graphics g, int x, int y, int radius, double angle) {
    final double DEGREES_PER_RADIAN = 180.0 / Math.PI;
    final int minAngleDegrees = (int) (minAngle * DEGREES_PER_RADIAN);
    final int maxAngleDegrees = (int) (maxAngle * DEGREES_PER_RADIAN);

    int zeroAngleDegrees = (int) (fractionToAngle(baseValue) * DEGREES_PER_RADIAN);

    double arrowSize = radius * 0.95;
    int arcX = x - radius;
    int arcY = y - radius;
    int arcAngle = (int) (angle * DEGREES_PER_RADIAN);
    int arrowX = (int) (arrowSize * Math.cos(angle));
    int arrowY = (int) (arrowSize * Math.sin(angle));

    g.setColor(knobColor.darker().darker());
    g.fillArc(arcX, arcY, 2 * radius, 2 * radius, minAngleDegrees, maxAngleDegrees
            - minAngleDegrees);
    g.setColor(Color.ORANGE);
    g.fillArc(arcX, arcY, 2 * radius, 2 * radius, zeroAngleDegrees, arcAngle - zeroAngleDegrees);

    // fill in middle
    int arcWidth = radius / 4;
    int diameter = ((radius - arcWidth) * 2);
    g.setColor(knobColor);
    g.fillOval(arcWidth + x - radius, arcWidth + y - radius, diameter, diameter);

    g.setColor(lineColor);
    g.drawLine(x, y, x + arrowX, y - arrowY);

}
 
Example 5
Source File: RotaryController.java    From jsyn with Apache License 2.0 5 votes vote down vote up
private void drawArcIndicator(Graphics g, int x, int y, int radius, double angle) {
    final double DEGREES_PER_RADIAN = 180.0 / Math.PI;
    final int minAngleDegrees = (int) (minAngle * DEGREES_PER_RADIAN);
    final int maxAngleDegrees = (int) (maxAngle * DEGREES_PER_RADIAN);

    int zeroAngleDegrees = (int) (fractionToAngle(baseValue) * DEGREES_PER_RADIAN);

    double arrowSize = radius * 0.95;
    int arcX = x - radius;
    int arcY = y - radius;
    int arcAngle = (int) (angle * DEGREES_PER_RADIAN);
    int arrowX = (int) (arrowSize * Math.cos(angle));
    int arrowY = (int) (arrowSize * Math.sin(angle));

    g.setColor(knobColor.darker().darker());
    g.fillArc(arcX, arcY, 2 * radius, 2 * radius, minAngleDegrees, maxAngleDegrees
            - minAngleDegrees);
    g.setColor(Color.ORANGE);
    g.fillArc(arcX, arcY, 2 * radius, 2 * radius, zeroAngleDegrees, arcAngle - zeroAngleDegrees);

    // fill in middle
    int arcWidth = radius / 4;
    int diameter = ((radius - arcWidth) * 2);
    g.setColor(knobColor);
    g.fillOval(arcWidth + x - radius, arcWidth + y - radius, diameter, diameter);

    g.setColor(lineColor);
    g.drawLine(x, y, x + arrowX, y - arrowY);

}
 
Example 6
Source File: Circles.java    From marvinproject with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void process
(
	MarvinImage a_imageIn, 
	MarvinImage a_imageOut,
	MarvinAttributes a_attributesOut,
	MarvinImageMask a_mask, 
	boolean a_previewMode
)
{
	double l_intensity;

	circleWidth = (Integer)attributes.get("circleWidth");
	shift = (Integer)attributes.get("shift");
	circlesDistance = (Integer)attributes.get("circlesDistance");

	Graphics l_graphics = a_imageOut.getBufferedImage().getGraphics();

	// Gray
	MarvinImagePlugin l_filter = new GrayScale();
	l_filter.load();
	l_filter.process(a_imageIn, a_imageIn, a_attributesOut, a_mask, a_previewMode);
	
	performanceMeter.enableProgressBar("Halftone - Circles" , (a_imageIn.getHeight()/(circleWidth+circlesDistance))*(a_imageIn.getWidth()/(circleWidth+circlesDistance)));
	
	boolean[][] l_arrMask = a_mask.getMask();
	
	int l_dif=0;
	for (int y = 0; y < a_imageIn.getHeight(); y+=circleWidth+circlesDistance) {
		for (int x = 0+l_dif; x < a_imageIn.getWidth(); x+=circleWidth+circlesDistance) {
			if(l_arrMask != null && !l_arrMask[x][y]){
				continue;
			}
			l_intensity = getSquareIntensity(x,y,a_imageIn);
			l_intensity+=1.0/circleWidth;
			l_graphics.setColor(Color.white);
			l_graphics.fillRect(x,y,circleWidth+circlesDistance,circleWidth+circlesDistance);
			l_graphics.setColor(Color.black);
			l_graphics.fillArc((int)(x+(circleWidth-(l_intensity*circleWidth))/2), (int)(y+(circleWidth-(l_intensity*circleWidth))/2), (int)(l_intensity*(circleWidth)), (int)(l_intensity*(circleWidth)),1,360);
		}
		l_dif = (l_dif+shift)%circleWidth;
		performanceMeter.stepsFinished((a_imageIn.getWidth()/(circleWidth+circlesDistance)));
	}
	a_imageOut.updateColorArray();
	performanceMeter.finish();
}
 
Example 7
Source File: ComparisonView.java    From javamoney-examples with Apache License 2.0 4 votes vote down vote up
/**
 * This method renders the view specific data to its canvas.
 *
 * @param graphics The graphics context to render to.
 */
@Override
public
void
paint(Graphics graphics)
{
  super.paint(graphics);

  double total = getTotals()[MONTH_EXPENSE] + getTotals()[MONTH_INCOME];
  int height = 174;
  int width = height;
  int xCoord = 200;
  int yCoord = 15;

  if(total != 0.0)
  {
    int arc = (int)(360 * (getTotals()[MONTH_EXPENSE] / total));

    // Fill the pie as income, and then paint the expenses.
    graphics.setClip(new Arc2D.Double(xCoord, yCoord, width, height, 0, 360, Arc2D.PIE));
    graphics.drawImage(INCOME, xCoord, yCoord, null);

    graphics.setClip(new Arc2D.Double(xCoord, yCoord, width, height, 0, arc, Arc2D.PIE));
    graphics.drawImage(EXPENSE, xCoord, yCoord, null);
  }
  else
  {
    String str = getProperty("no_data");
    int strWidth = getFontMetrics(getFont()).stringWidth(str);

    // Clear previous paints.
    graphics.setColor(getBackground());
    graphics.fillArc(xCoord, yCoord, width, height, 0, 360);

    graphics.setClip(new Arc2D.Double(xCoord, yCoord, width, height, 0, 360, Arc2D.PIE));
    graphics.drawImage(NO_DATA, xCoord, yCoord, null);

    // Center the text.
    xCoord += width / 2 - (strWidth / 2);
    yCoord += height / 2;

    graphics.setColor(Color.BLACK);
    graphics.drawString(str, xCoord, yCoord);
  }
}
 
Example 8
Source File: CategoryTotalPieChartPanel.java    From javamoney-examples with Apache License 2.0 4 votes vote down vote up
/**
 * This method renders the category total data to its canvas.
 *
 * @param graphics The graphics context to render to.
 */
@Override
public
void
paint(Graphics graphics)
{
  super.paint(graphics);

  int height = 175;
  int width = height;
  int xCoord = (getBounds().width / 2) - (width / 2);
  int yCoord = 10;

  if(getCategoryTotal() != null)
  {
    int arc = (int)(360 * getCategoryTotal().getPercent());

    // Fill the pie as other, and then paint the percentage.
    if(arc < 360)
    {
      graphics.setClip(new Arc2D.Double(xCoord, yCoord, width, height, 0, 360, Arc2D.PIE));
      graphics.drawImage(OTHER, xCoord, yCoord, null);
    }

    graphics.setClip(new Arc2D.Double(xCoord, yCoord, width, height, 0, arc, Arc2D.PIE));
    graphics.drawImage(SELECTED, xCoord, yCoord, null);
  }
  else
  {
    String str = getProperty("select");
    int strWidth = getFontMetrics(getFont()).stringWidth(str);

    // Clear previous paints.
    graphics.setColor(getBackground());
    graphics.fillArc(xCoord, yCoord, width, height, 0, 360);

    graphics.setClip(new Arc2D.Double(xCoord, yCoord, width, height, 0, 360, Arc2D.PIE));
    graphics.drawImage(NO_DATA, xCoord, yCoord, null);

    // Center the text.
    xCoord += width / 2 - (strWidth / 2);
    yCoord += height / 2;

    graphics.setColor(Color.BLACK);
    graphics.drawString(str, xCoord, yCoord);
  }
}