Java Code Examples for java.awt.geom.Ellipse2D#Float

The following examples show how to use java.awt.geom.Ellipse2D#Float . These examples are extracted from open source projects. 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
/**
 * Draw pie
 *
 * @param aPoint Start point
 * @param width Width
 * @param height Height
 * @param startAngle Start angle
 * @param sweepAngle Sweep angle
 * @param aPGB Polygon break
 * @param wedgeWidth Wedge width
 * @param g Graphics2D
 */
public static void drawPie(PointF aPoint, float width, float height, float startAngle,
        float sweepAngle, PolygonBreak aPGB, float wedgeWidth, Graphics2D g) {
    Color aColor = aPGB.getColor();
    Arc2D.Float arc2D = new Arc2D.Float(aPoint.X, aPoint.Y, width, height, startAngle, sweepAngle, Arc2D.PIE);
    Area area1 = new Area(arc2D);
    Ellipse2D e2 = new Ellipse2D.Float(aPoint.X + wedgeWidth, aPoint.Y + wedgeWidth, width - wedgeWidth * 2,
            height - wedgeWidth * 2);
    Area area2 = new Area(e2);
    area1.subtract(area2);
    if (aPGB.isDrawFill()) {
        g.setColor(aColor);
        g.fill(area1);
    }
    if (aPGB.isDrawOutline()) {
        g.setColor(aPGB.getOutlineColor());
        g.setStroke(new BasicStroke(aPGB.getOutlineSize()));
        g.draw(area1);
    }
}
 
Example 2
/**
 * Builds an ellipse shape.
 * 
 * @return the ellipse or null if its size is not specified
 */
protected Shape buildEllipse()
{
	Ellipse2D ellipse = null;
	Dimension2D size = getSize();
	if (size != null)
	{
		Point offset = getOffset(size);
		ellipse = 
			new Ellipse2D.Float(
				-offset.getX(), 
				-offset.getY(), 
				(float)size.getWidth(), 
				(float)size.getHeight()
				);
	}
	return ellipse;
}
 
Example 3
boolean reflect(Discrete p, boolean scatter) {
	float dt = model.getTimeStep();
	float predictedX = p.getRx() + p.getVx() * dt;
	float predictedY = p.getRy() + p.getVy() * dt;
	if (p instanceof Particle) {
		float dt2 = 0.5f * dt * dt;
		predictedX += ((Particle) p).ax * dt2;
		predictedY += ((Particle) p).ay * dt2;
	}
	Shape shape = getShape();
	boolean predictedToBeInShape = true; // optimization flag: if the predicted position is not within this part, skip the costly reflection calculation
	if (p instanceof Photon)
		predictedToBeInShape = shape.contains(predictedX, predictedY);
	if (shape instanceof Rectangle2D.Float) {
		if (predictedToBeInShape)
			return reflect((Rectangle2D.Float) shape, p, predictedX, predictedY, scatter);
	} else if (shape instanceof Polygon2D) {
		if (predictedToBeInShape)
			return reflect((Polygon2D) shape, p, predictedX, predictedY, scatter);
	} else if (shape instanceof Blob2D) {
		if (predictedToBeInShape)
			return reflect((Blob2D) shape, p, predictedX, predictedY, scatter);
	} else if (shape instanceof Ellipse2D.Float) {
		if (predictedToBeInShape)
			return reflect((Ellipse2D.Float) shape, p, predictedX, predictedY, scatter);
	} else if (shape instanceof Annulus) {
		if (predictedToBeInShape)
			return reflect((Annulus) shape, p, predictedX, predictedY, scatter);
	} else if (shape instanceof EllipticalAnnulus) {
		if (predictedToBeInShape)
			return reflect((EllipticalAnnulus) shape, p, predictedX, predictedY, scatter);
	}
	return false;
}
 
Example 4
Source Project: consulo   File: LabelIcon.java    License: Apache License 2.0 5 votes vote down vote up
public void paintTag(Graphics2D g2, float scale, float x, float y) {
  Path2D.Float path = new Path2D.Float();
  path.moveTo(x + 1 * scale, y + 2 * scale);
  path.lineTo(x + 3 * scale, y + 2 * scale);
  path.lineTo(x + 6 * scale, y + 5 * scale);
  path.lineTo(x + 4 * scale, y + 7 * scale);
  path.lineTo(x + 1 * scale, y + 4 * scale);
  path.lineTo(x + 1 * scale, y + 2 * scale);
  path.closePath();
  Ellipse2D hole = new Ellipse2D.Float(x + 2 * scale, y + 3 * scale, scale, scale);
  Area area = new Area(path);
  area.subtract(new Area(hole));
  g2.fill(area);
}
 
Example 5
Source Project: pumpernickel   File: CloseIcon.java    License: MIT License 5 votes vote down vote up
protected void paintBorder(Graphics2D g, int x, int y) {
	Ellipse2D border = new Ellipse2D.Float(x, y, size - 1, size - 1);
	// draw the border
	g.setStroke(new BasicStroke(1));
	g.setPaint(new GradientPaint(0, 0, borderTop, 0, size, borderBottom));
	g.draw(border);
}
 
Example 6
Source Project: pumpernickel   File: AlphaCompositeDemo.java    License: MIT License 5 votes vote down vote up
private BufferedImage createShapeSample(int destAlphaValue,
		int srcAlphaValue) {
	BufferedImage bi = new BufferedImage(getWidth(), getHeight(),
			BufferedImage.TYPE_INT_ARGB);
	Graphics2D g = bi.createGraphics();
	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
	g.setComposite(AlphaComposite.Clear);
	g.fillRect(0, 0, getWidth(), getHeight());
	g.setComposite(AlphaComposite.SrcOver);

	Ellipse2D destShape = new Ellipse2D.Float(25, 0, 100, 100);
	Ellipse2D srcShape = new Ellipse2D.Float(75, 0, 100, 100);

	Paint destPaint = new GradientPaint(0, 0, new Color(255, 100, 100,
			0), 0, 200, new Color(255, 100, 100, destAlphaValue));
	g.setPaint(destPaint);
	g.fill(destShape);

	Paint srcPaint = new GradientPaint(0, 200, new Color(100, 100, 255,
			0), 0, 0, new Color(100, 100, 255, srcAlphaValue));
	g.setComposite(getComposite());
	g.setPaint(srcPaint);
	g.fill(srcShape);

	g.setComposite(AlphaComposite.SrcOver);
	g.setColor(Color.black);
	drawString(g, "DST", 85 - 30, 50);
	drawString(g, "SRC", 115 + 30, 50);

	return bi;
}
 
Example 7
@Override
public Shape getRegiao() {
    if (Regiao == null) {
        Regiao = new Ellipse2D.Float(getLeft(), getTop(), getWidth(), getHeight());
    }
    return Regiao;
}
 
Example 8
Source Project: pumpernickel   File: JFancyBox.java    License: MIT License 5 votes vote down vote up
public void paintIcon(Component c, Graphics g0, int x, int y) {
	Graphics2D g = (Graphics2D) g0.create();
	g.translate(x, y);
	g.scale(scaleFactor, scaleFactor);
	g.translate(shadowInset, shadowInset);

	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
	g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
			RenderingHints.VALUE_STROKE_PURE);
	g.setColor(new Color(0, 0, 0, 20));
	Ellipse2D e = new Ellipse2D.Float(2, 2, 20, 20);
	AffineTransform tx = g.getTransform();
	for (int a = 0; a < shadowInset; a++) {
		g.setStroke(new BasicStroke(2f + 1.5f * a));
		g.translate(0, .5f);
		g.draw(e);
	}
	g.setTransform(tx);
	g.setColor(backgroundColor);
	g.fill(e);
	g.setColor(borderColor);
	g.setStroke(new BasicStroke(1.9f));
	g.draw(e);
	g.setStroke(new BasicStroke(2.5f));
	int k = 9;
	g.setColor(xColor);
	g.drawLine(k, k, 24 - k, 24 - k);
	g.drawLine(24 - k, k, k, 24 - k);
	g.dispose();
}
 
Example 9
Source Project: jaamsim   File: RoundToggleButton.java    License: Apache License 2.0 5 votes vote down vote up
private void initShape() {
	if (!getBounds().equals(base)) {
		Dimension s = getPreferredSize();
		base = getBounds();
		shape = new Ellipse2D.Float(0, 0, s.width - 1, s.height - 1);
	}
}
 
Example 10
private double calcOverlap(ImageObject imgObj) {

    int inOverlap = 0;
    int allCell = 0;

    Rectangle boundings = imgObj.getBoundings();

    Ellipse2D ellipse = new Ellipse2D.Float(boundings.x, boundings.y, boundings.width,
        boundings.height);

    for (int y = boundings.y; y < boundings.y + boundings.getHeight(); ++y) {
      for (int x = boundings.x; x < boundings.x + boundings.getWidth(); ++x) {
        boolean isCell = imgObj.getColorFromGlobalCoordinates(x, y) != Color.WHITE.getRGB();
        boolean isOnEllipse = ellipse.contains(new Point(x, y));

        if (isCell && isOnEllipse) {
          ++inOverlap;
        }

        if (isCell || isOnEllipse) {
          ++allCell;
        }
      }
    }

    return (float) inOverlap / (float) allCell;
  }
 
Example 11
private void paintUnexploredTerrain(Graphics worldPanelGraphics, WorldPanel worldPanel, int circleRadius, int circleLeft, int circleTop) {
	float circleDiameter = circleRadius * 2.0f;
	Shape circle = new Ellipse2D.Float(circleLeft, circleTop, circleDiameter, circleDiameter);
	Area worldPanelRectangle = new Area(new Rectangle(worldPanel.getWorldViewWidth(), worldPanel.getWorldViewHeight()));
	worldPanelRectangle.subtract(new Area(circle));
       
	worldPanelGraphics.setColor(Color.BLACK);
	((Graphics2D)worldPanelGraphics).fill(worldPanelRectangle);
}
 
Example 12
Source Project: pumpernickel   File: AngleSliderUI.java    License: MIT License 4 votes vote down vote up
@Override
public void paint(Graphics g0, JComponent c) {
	Graphics2D g = (Graphics2D) g0.create();
	JSlider slider = (JSlider) c;
	if (slider.isOpaque()) {
		g.setColor(slider.getBackground());
		g.fillRect(0, 0, slider.getWidth(), slider.getHeight());
	}

	if (slider.isEnabled() == false) {
		g.setComposite(
				AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f));
	}

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

	// paint a circular shadow
	/*
	 * g.translate(2,2); g.setColor(new Color(0,0,0,20)); g.fill(new
	 * Ellipse2D
	 * .Double(dial.getX()-2,dial.getY()-2,dial.getWidth()+4,dial.getHeight
	 * ()+4)); g.setColor(new Color(0,0,0,40)); g.fill(new
	 * Ellipse2D.Double(dial
	 * .getX()-1,dial.getY()-1,dial.getWidth()+2,dial.getHeight()+2));
	 * g.setColor(new Color(0,0,0,80)); g.fill(new
	 * Ellipse2D.Double(dial.getX
	 * ()-0,dial.getY()-0,dial.getWidth()+0,dial.getHeight()+0));
	 * g.translate(-2,-2);
	 */

	Data data = getData(slider);
	if (slider.hasFocus()) {
		PlafPaintUtils.paintFocus(g, data.dial, 3);
	}

	// g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
	// RenderingHints.VALUE_ANTIALIAS_OFF);

	Shape oldClip = g.getClip();
	g.clip(data.dial);
	int d = data.mousePressed ? -50 : 0;
	for (int a = 0; a < 5; a++) {
		float f = (a) / 4f;
		g.setColor(tweenColor(new Color(150 + d, 150 + d, 150 + d),
				new Color(212 + d, 212 + d, 212 + d), f));
		g.translate(0, a);
		g.fill(data.dial);
		g.translate(0, -a);
	}
	g.setClip(oldClip);

	g.setColor(border);
	g.draw(data.dial);

	float angle = (float) (slider.getValue() - slider.getMinimum())
			/ (((float) (slider.getMaximum() - slider.getMinimum())));
	angle = angle * (float) (2 * Math.PI);

	float centerX = (float) data.dial.getCenterX();
	float centerY = (float) data.dial.getCenterY();
	float radius = (float) Math.min(centerX - data.dial.getX(),
			centerY - data.dial.getY()) - 6;
	float x = (float) (centerX + radius * Math.cos(angle));
	float y = (float) (centerY + radius * Math.sin(angle));
	Ellipse2D knob = new Ellipse2D.Float(x - 2, y - 2, 4, 4);
	if (slider.hasFocus()) {
		g.setColor(Color.gray);
		g.fill(knob);
		g.setColor(Color.darkGray);
		g.draw(knob);
	} else {
		g.setColor(new Color(180, 180, 180));
		g.fill(knob);
		g.setColor(border);
		g.draw(knob);
	}

	g.dispose();
}
 
Example 13
@Override
public Shape getShape() {
    return new Ellipse2D.Float(0, 0, 100, 100);
}
 
Example 14
@Override
public Shape getShape(float width,float height,boolean leftEdge,boolean rightEdge,boolean sharpEdgesHint) {
	Ellipse2D e = new Ellipse2D.Float(-width/2f, -height/2f, width, height);
	return e;
}
 
Example 15
Source Project: pumpernickel   File: CurvedPolylineCreationUI.java    License: MIT License 4 votes vote down vote up
@Override
protected void paintControls(Graphics2D g0, ShapeCreationPanel scp) {
	AffineTransform tx = scp.getTransform();
	Graphics2D g = (Graphics2D) g0.create();
	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
	g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
			RenderingHints.VALUE_STROKE_PURE);
	g.setStroke(new BasicStroke(1, BasicStroke.CAP_ROUND,
			BasicStroke.JOIN_ROUND));
	float r = (float) (scp.getHandleSize()) / 2f;
	Selection selection = scp.getSelectionModel().getSelection();
	Selection indication = scp.getSelectionModel().getIndication();
	Shape[] shapes = scp.getDataModel().getShapes();
	float[] coords = new float[6];
	Ellipse2D ellipse = new Ellipse2D.Float();
	for (int shapeIndex = 0; shapeIndex < shapes.length; shapeIndex++) {
		if (scp.getHandlesActive().supports(scp, shapeIndex)) {
			PathIterator iter = shapes[shapeIndex].getPathIterator(tx);
			int nodeCtr = -1;
			while (!iter.isDone()) {
				int k = iter.currentSegment(coords);
				float x, y;
				if (k == PathIterator.SEG_MOVETO
						|| k == PathIterator.SEG_LINETO) {
					x = coords[0];
					y = coords[1];
					nodeCtr++;
				} else if (k == PathIterator.SEG_QUADTO) {
					x = coords[2];
					y = coords[3];
					nodeCtr++;
				} else if (k == PathIterator.SEG_CUBICTO) {
					x = coords[4];
					y = coords[5];
					nodeCtr++;
				} else if (k == PathIterator.SEG_CLOSE) {
					x = -1;
					y = -1;
				} else {
					throw new RuntimeException("unexpected segment type: "
							+ k);
				}
				g.setColor(Color.white);
				if (selection != null
						&& selection.getShapeIndex() == shapeIndex
						&& selection.getNodeIndex() == nodeCtr) {
					g.setColor(Color.darkGray);
				} else if (indication != null
						&& indication.getShapeIndex() == shapeIndex
						&& indication.getNodeIndex() == nodeCtr) {
					g.setColor(Color.gray);
				}
				ellipse.setFrame(x - r, y - r, 2 * r, 2 * r);
				g.fill(ellipse);
				g.setColor(Color.black);
				g.draw(ellipse);

				iter.next();
			}
		}
	}
	g.dispose();
}
 
Example 16
public Shape[] getAffectedAreaShapes() {
    return new Shape[]{
            new Ellipse2D.Float(icentreX - radius, icentreY - radius, 2 * radius, 2 * radius)
    };
}
 
Example 17
Source Project: pumpernickel   File: CircleTransition2D.java    License: MIT License 4 votes vote down vote up
@Override
public Shape getShape() {
	return new Ellipse2D.Float(0, 0, 100, 100);
}
 
Example 18
public DebugDrawJ2D(TestPanelJ2D argTestPanel, boolean yFlip) {
  panel = argTestPanel;
  this.yFlip = yFlip;
  stroke = new BasicStroke(0);
  circle = new Ellipse2D.Float(-1, -1, 2, 2);
}
 
Example 19
MovingEllipse(Ellipse2D.Float ellipse) {
	this.ellipse = ellipse;
}
 
Example 20
Source Project: consulo   File: mxEllipseShape.java    License: Apache License 2.0 4 votes vote down vote up
/**
 *
 */
public Shape createShape(mxGraphics2DCanvas canvas, mxCellState state) {
  Rectangle temp = state.getRectangle();

  return new Ellipse2D.Float(temp.x, temp.y, temp.width, temp.height);
}