下面列出了怎么用java.awt.geom.Ellipse2D的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Creates a new plot.
*
* @param dataset the dataset (<code>null</code> permitted).
*/
public MultiplePiePlot(CategoryDataset dataset) {
super();
setDataset(dataset);
PiePlot piePlot = new PiePlot(null);
piePlot.setIgnoreNullValues(true);
this.pieChart = new JFreeChart(piePlot);
this.pieChart.removeLegend();
this.dataExtractOrder = TableOrder.BY_COLUMN;
this.pieChart.setBackgroundPaint(null);
TextTitle seriesTitle = new TextTitle("Series Title",
new Font("SansSerif", Font.BOLD, 12));
seriesTitle.setPosition(RectangleEdge.BOTTOM);
this.pieChart.setTitle(seriesTitle);
this.aggregatedItemsKey = "Other";
this.aggregatedItemsPaint = Color.lightGray;
this.sectionPaints = new HashMap();
this.legendItemShape = new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0);
}
public void drawCatchingEvent(int x, int y, int width, int height, Image image) {
// event circles
Ellipse2D outerCircle = new Ellipse2D.Double(x, y, width, height);
int innerCircleX = x + 3;
int innerCircleY = y + 3;
int innerCircleWidth = width - 6;
int innerCircleHeight = height - 6;
Ellipse2D innerCircle = new Ellipse2D.Double(innerCircleX, innerCircleY, innerCircleWidth, innerCircleHeight);
Paint originalPaint = g.getPaint();
g.setPaint(BOUNDARY_EVENT_COLOR);
g.fill(outerCircle);
g.setPaint(originalPaint);
g.draw(outerCircle);
g.draw(innerCircle);
g.drawImage(image, innerCircleX, innerCircleY, innerCircleWidth, innerCircleHeight, null);
}
public void runTest(Object ctx, int numReps) {
DrawEllipse2Ds.Context cctx = (DrawEllipse2Ds.Context) ctx;
int size = cctx.size;
int x = cctx.initX;
int y = cctx.initY;
Ellipse2D ellipse = cctx.ellipse;
Graphics2D g2d = (Graphics2D) cctx.graphics;
g2d.translate(cctx.orgX, cctx.orgY);
Color rCArray[] = cctx.colorlist;
int ci = cctx.colorindex;
do {
if (rCArray != null) {
g2d.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
}
ellipse.setFrame(x, y, size, size);
g2d.draw(ellipse);
if ((x -= 3) < 0) x += cctx.maxX;
if ((y -= 1) < 0) y += cctx.maxY;
} while (--numReps > 0);
cctx.colorindex = ci;
g2d.translate(-cctx.orgX, -cctx.orgY);
}
@Test
public void testLineCircleIntersections() {
// Arrange
Path2D line = new Path2D.Double(Path2D.WIND_NON_ZERO, 3);
line.moveTo(1, 10);
line.lineTo(20 - 1, 10);
line.lineTo(20 - 1 + SMALL_DELTA, 10 + SMALL_DELTA);
line.closePath();
Ellipse2D.Double circle = new Ellipse2D.Double(4, 8, 4, 4);
// Act
Area intersectionArea = new Area(line);
intersectionArea.intersect(new Area(circle));
// Assert
assertThat(intersectionArea.isEmpty()).isFalse();
Rectangle2D bounds2D = intersectionArea.getBounds2D();
assertThat(bounds2D.getX()).isCloseTo(4d, offset(PRECISION));
assertThat(bounds2D.getY()).isCloseTo(10d, offset(PRECISION));
assertThat(bounds2D.getX() + bounds2D.getWidth()).isCloseTo(8d, offset(PRECISION));
assertThat(bounds2D.getY() + bounds2D.getHeight()).isCloseTo(10d, offset(PRECISION));
}
public mxPoint paintMarker(mxGraphics2DCanvas canvas,
mxCellState state, String type, mxPoint pe, double nx,
double ny, double size, boolean source)
{
double cx = pe.getX() - nx / 2;
double cy = pe.getY() - ny / 2;
double a = size / 2;
Shape shape = new Ellipse2D.Double(cx - a, cy - a, size, size);
if (mxUtils.isTrue(state.getStyle(), (source) ? "startFill" : "endFill", true))
{
canvas.fillShape(shape);
}
canvas.getGraphics().draw(shape);
return new mxPoint(-nx / 2, -ny / 2);
}
/**
* Creates a new plot.
*
* @param dataset the dataset (<code>null</code> permitted).
*/
public MultiplePiePlot(CategoryDataset dataset) {
super();
setDataset(dataset);
PiePlot piePlot = new PiePlot(null);
piePlot.setIgnoreNullValues(true);
this.pieChart = new JFreeChart(piePlot);
this.pieChart.removeLegend();
this.dataExtractOrder = TableOrder.BY_COLUMN;
this.pieChart.setBackgroundPaint(null);
TextTitle seriesTitle = new TextTitle("Series Title",
new Font("Tahoma", Font.BOLD, 12));
seriesTitle.setPosition(RectangleEdge.BOTTOM);
this.pieChart.setTitle(seriesTitle);
this.aggregatedItemsKey = "Other";
this.aggregatedItemsPaint = Color.lightGray;
this.sectionPaints = new HashMap();
this.legendItemShape = new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0);
}
private boolean reflect(Ellipse2D.Float e, Discrete p, float predictedX, float predictedY, boolean scatter) {
float a = e.width * 0.5f;
float b = e.height * 0.5f;
float x = e.x + a;
float y = e.y + b;
int polygonize = 50;
float[] vx = new float[polygonize];
float[] vy = new float[polygonize];
float theta;
float delta = (float) (2 * Math.PI / polygonize);
for (int i = 0; i < polygonize; i++) {
theta = -delta * i;
vx[i] = (float) (x + a * Math.cos(theta));
vy[i] = (float) (y + b * Math.sin(theta));
}
Line2D.Float line = new Line2D.Float();
for (int i = 0; i < polygonize - 1; i++) {
line.setLine(vx[i], vy[i], vx[i + 1], vy[i + 1]);
if (reflectFromLine(p, line, predictedX, predictedY, scatter, true))
return true;
}
line.setLine(vx[polygonize - 1], vy[polygonize - 1], vx[0], vy[0]);
if (reflectFromLine(p, line, predictedX, predictedY, scatter, true))
return true;
return false;
}
/**
* Tests two shapes for equality. If both shapes are <code>null</code>,
* this method will return <code>true</code>.
* <p>
* In the current implementation, the following shapes are supported:
* <code>Ellipse2D</code>, <code>Line2D</code> and <code>Rectangle2D</code>
* (implicit).
*
* @param s1 the first shape (<code>null</code> permitted).
* @param s2 the second shape (<code>null</code> permitted).
*
* @return A boolean.
*/
public static boolean equal(Shape s1, Shape s2) {
if (s1 instanceof Line2D && s2 instanceof Line2D) {
return equal((Line2D) s1, (Line2D) s2);
}
else if (s1 instanceof Ellipse2D && s2 instanceof Ellipse2D) {
return equal((Ellipse2D) s1, (Ellipse2D) s2);
}
else if (s1 instanceof Arc2D && s2 instanceof Arc2D) {
return equal((Arc2D) s1, (Arc2D) s2);
}
else if (s1 instanceof Polygon && s2 instanceof Polygon) {
return equal((Polygon) s1, (Polygon) s2);
}
else if (s1 instanceof GeneralPath && s2 instanceof GeneralPath) {
return equal((GeneralPath) s1, (GeneralPath) s2);
}
else {
// this will handle Rectangle2D...
return ObjectUtilities.equal(s1, s2);
}
}
private Selection getSelection(MouseEvent evt)
throws NoninvertibleTransformException {
ShapeCreationPanel scp = (ShapeCreationPanel) evt.getComponent();
AffineTransform tx = scp.getTransform();
double r = scp.getHandleSize() / 2;
Point2D mouseLoc = new Point2D.Float(evt.getX(), evt.getY());
CurvedPolyline[] shapes = getMirror(scp);
for (int shapeIndex = 0; shapeIndex < shapes.length; shapeIndex++) {
if (scp.getHandlesActive().supports(scp, shapeIndex)) {
for (int b = shapes[shapeIndex].getPointCount() - 1; b >= 0; b--) {
Point2D p = tx.transform(
shapes[shapeIndex].getPoint(b), null);
Ellipse2D e = new Ellipse2D.Double(p.getX() - r,
p.getY() - r, 2 * r, 2 * r);
if (e.contains(mouseLoc))
return new Selection(shapeIndex, b, null);
}
}
}
return getSelectedShape(scp, evt.getPoint());
}
public void runTest(Object ctx, int numReps) {
FillEllipse2Ds.Context cctx = (FillEllipse2Ds.Context) ctx;
int size = cctx.size;
int x = cctx.initX;
int y = cctx.initY;
Ellipse2D ellipse = cctx.ellipse;
Graphics2D g2d = (Graphics2D) cctx.graphics;
g2d.translate(cctx.orgX, cctx.orgY);
Color rCArray[] = cctx.colorlist;
int ci = cctx.colorindex;
do {
if (rCArray != null) {
g2d.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
}
ellipse.setFrame(x, y, size, size);
g2d.fill(ellipse);
if ((x -= 3) < 0) x += cctx.maxX;
if ((y -= 1) < 0) y += cctx.maxY;
} while (--numReps > 0);
cctx.colorindex = ci;
g2d.translate(-cctx.orgX, -cctx.orgY);
}
public void runTest(Object ctx, int numReps) {
FillEllipse2Ds.Context cctx = (FillEllipse2Ds.Context) ctx;
int size = cctx.size;
int x = cctx.initX;
int y = cctx.initY;
Ellipse2D ellipse = cctx.ellipse;
Graphics2D g2d = (Graphics2D) cctx.graphics;
g2d.translate(cctx.orgX, cctx.orgY);
Color rCArray[] = cctx.colorlist;
int ci = cctx.colorindex;
do {
if (rCArray != null) {
g2d.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
}
ellipse.setFrame(x, y, size, size);
g2d.fill(ellipse);
if ((x -= 3) < 0) x += cctx.maxX;
if ((y -= 1) < 0) y += cctx.maxY;
} while (--numReps > 0);
cctx.colorindex = ci;
g2d.translate(-cctx.orgX, -cctx.orgY);
}
@Override
public void draw(DrawRequest r) {
Graphics2D g = r.getGraphics();
Shape shape = new Ellipse2D.Double(
-getSize() / 2 + getStrokeWidth() / 2,
-getSize() / 2 + getStrokeWidth() / 2,
getSize() - getStrokeWidth(),
getSize() - getStrokeWidth());
g.setColor(ColorUtils.colorise(getFillColor(), r.getDecoration().getBackground()));
g.fill(shape);
g.setColor(ColorUtils.colorise(getForegroundColor(), r.getDecoration().getColorisation()));
g.setStroke(new BasicStroke((float) getStrokeWidth()));
g.draw(shape);
drawToken(r);
drawErrorInLocalSpace(r);
drawDurationInLocalSpace(r);
drawLabelInLocalSpace(r);
drawNameInLocalSpace(r);
}
/**
* Draws the background to the specified graphics device. If the dial
* frame specifies a window, the clipping region will already have been
* set to this window before this method is called.
*
* @param g2 the graphics device (<code>null</code> not permitted).
* @param plot the plot (ignored here).
* @param frame the dial frame (ignored here).
* @param view the view rectangle (<code>null</code> not permitted).
*/
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
Rectangle2D view) {
g2.setPaint(this.fillPaint);
Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius,
this.radius);
Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(),
f.getHeight());
g2.fill(e);
g2.setPaint(this.outlinePaint);
g2.setStroke(this.outlineStroke);
g2.draw(e);
}
/**
* Draws the frame. This method is called by the {@link DialPlot} class,
* you shouldn't need to call it directly.
*
* @param g2 the graphics target (<code>null</code> not permitted).
* @param plot the plot (<code>null</code> not permitted).
* @param frame the frame (<code>null</code> not permitted).
* @param view the view (<code>null</code> not permitted).
*/
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
Rectangle2D view) {
Shape window = getWindow(frame);
Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius + 0.02,
this.radius + 0.02);
Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(),
f.getHeight());
Area area = new Area(e);
Area area2 = new Area(window);
area.subtract(area2);
g2.setPaint(this.backgroundPaint);
g2.fill(area);
g2.setStroke(this.stroke);
g2.setPaint(this.foregroundPaint);
g2.draw(window);
g2.draw(e);
}
/**
* Draws a bullet or text marker
*/
protected void drawListBullet(ListItemBox elem, Graphics2D g)
{
final VisualContext ctx = elem.getVisualContext();
float x = elem.getAbsoluteContentX() - 1.2f * ctx.getEm();
float y = elem.getAbsoluteContentY() + 0.5f * ctx.getEm();
float r = 0.4f * ctx.getEm();
if (elem.getStyleType() == CSSProperty.ListStyleType.CIRCLE)
g.draw(new Ellipse2D.Float(x, y, r, r));
else if (elem.getStyleType() == CSSProperty.ListStyleType.SQUARE)
g.fill(new Rectangle2D.Float(x, y, r, r));
else if (elem.getStyleType() == CSSProperty.ListStyleType.DISC)
g.fill(new Ellipse2D.Float(x, y, r, r));
else if (elem.getStyleType() != CSSProperty.ListStyleType.NONE)
drawListTextMarker(elem, g, elem.getMarkerText());
}
/**
* Draws Points on the Map.
*
* @param graphics The {@linkplain Graphics2D} Object being drawn on
* @param points The {@linkplain Point2D} array aka the "Joints" to be drawn
*/
private void drawJoints(final Graphics2D graphics, final Point2D[] points) {
final int jointsize = 10;
// If the points array is bigger than 1 the last joint should not be drawn (draw an arrow
// instead)
final Point2D[] newPoints =
points.length > 1 ? Arrays.copyOf(points, points.length - 1) : points;
for (final Point2D[] joints : routeCalculator.getAllPoints(newPoints)) {
for (final Point2D p : joints) {
final Ellipse2D circle =
new Ellipse2D.Double(jointsize / -2.0, jointsize / -2.0, jointsize, jointsize);
final AffineTransform ellipseTransform = getDrawingTransform();
ellipseTransform.translate(p.getX(), p.getY());
graphics.fill(ellipseTransform.createTransformedShape(circle));
}
}
}
public static Image makeImage(int size, Color color) {
// BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);
BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = image.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setPaint(color);
g2.fill(new Ellipse2D.Double(0d, 0d, size - 1d, size - 1d));
FontRenderContext frc = g2.getFontRenderContext();
Font font = g2.getFont().deriveFont(AffineTransform.getScaleInstance(.8, 1d));
Shape s = new TextLayout(Integer.toString(size), font, frc).getOutline(null);
g2.setPaint(Color.BLACK);
Rectangle r = s.getBounds();
double cx = size / 2d - r.getCenterX();
double cy = size / 2d - r.getCenterY();
AffineTransform toCenterAtf = AffineTransform.getTranslateInstance(cx, cy);
g2.fill(toCenterAtf.createTransformedShape(s));
g2.dispose();
return image;
}
public void drawNoneEndEvent(GraphicInfo graphicInfo, double scaleFactor) {
Paint originalPaint = g.getPaint();
Stroke originalStroke = g.getStroke();
g.setPaint(EVENT_COLOR);
Ellipse2D circle = new Ellipse2D.Double(graphicInfo.getX(), graphicInfo.getY(),
graphicInfo.getWidth(), graphicInfo.getHeight());
g.fill(circle);
g.setPaint(EVENT_BORDER_COLOR);
if (scaleFactor == 1.0) {
g.setStroke(END_EVENT_STROKE);
} else {
g.setStroke(new BasicStroke(2.0f));
}
g.draw(circle);
g.setStroke(originalStroke);
g.setPaint(originalPaint);
}
public static void main(String[] args) throws Exception {
BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setPaint(Color.WHITE);
g.fill(new Rectangle(image.getWidth(), image.getHeight()));
g.scale(.9, .9);
g.setPaint(Color.BLACK);
g.setStroke(new BasicStroke(0.5f));
g.draw(new Ellipse2D.Double(25, 25, 150, 150));
// To visually check it
//ImageIO.write(image, "PNG", new File(args[0]));
boolean nonWhitePixelFound = false;
for (int x = 100; x < 200; ++x) {
if (image.getRGB(x, 90) != Color.WHITE.getRGB()) {
nonWhitePixelFound = true;
break;
}
}
if (!nonWhitePixelFound) {
throw new RuntimeException("A circle is rendered like a 'C' shape.");
}
}
/**
* Tests two shapes for equality. If both shapes are <code>null</code>,
* this method will return <code>true</code>.
* <p>
* In the current implementation, the following shapes are supported:
* <code>Ellipse2D</code>, <code>Line2D</code> and <code>Rectangle2D</code>
* (implicit).
*
* @param s1 the first shape (<code>null</code> permitted).
* @param s2 the second shape (<code>null</code> permitted).
*
* @return A boolean.
*/
public static boolean equal(Shape s1, Shape s2) {
if (s1 instanceof Line2D && s2 instanceof Line2D) {
return equal((Line2D) s1, (Line2D) s2);
}
else if (s1 instanceof Ellipse2D && s2 instanceof Ellipse2D) {
return equal((Ellipse2D) s1, (Ellipse2D) s2);
}
else if (s1 instanceof Arc2D && s2 instanceof Arc2D) {
return equal((Arc2D) s1, (Arc2D) s2);
}
else if (s1 instanceof Polygon && s2 instanceof Polygon) {
return equal((Polygon) s1, (Polygon) s2);
}
else if (s1 instanceof GeneralPath && s2 instanceof GeneralPath) {
return equal((GeneralPath) s1, (GeneralPath) s2);
}
else {
// this will handle Rectangle2D...
return ObjectUtilities.equal(s1, s2);
}
}
/**
* Sets the parameters of this description object to match the supplied object.
*
* @param o
* the object (should be an instance of <code>Rectangle2D</code>).
* @throws ObjectFactoryException
* if the object is not an instance of <code>Rectangle2D</code>.
*/
public void setParameterFromObject( final Object o ) throws ObjectFactoryException {
if ( !( o instanceof Ellipse2D ) ) {
throw new ObjectFactoryException( "The given object is no java.awt.geom.Rectangle2D." );
}
final Ellipse2D rect = (Ellipse2D) o;
final float x = (float) rect.getX();
final float y = (float) rect.getY();
final float w = (float) rect.getWidth();
final float h = (float) rect.getHeight();
setParameter( "x", new Float( x ) );
setParameter( "y", new Float( y ) );
setParameter( "width", new Float( w ) );
setParameter( "height", new Float( h ) );
}
/**
* Creates a new <code>XYShapeRenderer</code> instance with default
* attributes.
*/
public XYShapeRenderer() {
this.paintScale = new LookupPaintScale();
this.useFillPaint = false;
this.drawOutlines = false;
this.useOutlinePaint = true;
this.guideLinesVisible = false;
this.guideLinePaint = Color.darkGray;
this.guideLineStroke = new BasicStroke();
setBaseShape(new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0));
setAutoPopulateSeriesShape(false);
}
@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;
}
/**
* Constructs a new renderer with the specified type of scaling.
*
* @param scaleType the type of scaling (must be one of:
* {@link #SCALE_ON_BOTH_AXES}, {@link #SCALE_ON_DOMAIN_AXIS},
* {@link #SCALE_ON_RANGE_AXIS}).
*/
public XYBubbleRenderer(int scaleType) {
super();
if (scaleType < 0 || scaleType > 2) {
throw new IllegalArgumentException("Invalid 'scaleType'.");
}
this.scaleType = scaleType;
setBaseLegendShape(new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0));
}
/**
* Draw the radial gridlines - the rings.
*
* @param g2 the drawing surface (<code>null</code> not permitted).
* @param plot the plot (<code>null</code> not permitted).
* @param radialAxis the radial axis (<code>null</code> not permitted).
* @param ticks the ticks (<code>null</code> not permitted).
* @param dataArea the data area.
*/
@Override
public void drawRadialGridLines(Graphics2D g2, PolarPlot plot,
ValueAxis radialAxis, List ticks, Rectangle2D dataArea) {
ParamChecks.nullNotPermitted(radialAxis, "radialAxis");
g2.setFont(radialAxis.getTickLabelFont());
g2.setPaint(plot.getRadiusGridlinePaint());
g2.setStroke(plot.getRadiusGridlineStroke());
double centerValue;
if (radialAxis.isInverted()) {
centerValue = radialAxis.getUpperBound();
} else {
centerValue = radialAxis.getLowerBound();
}
Point center = plot.translateToJava2D(0, centerValue, radialAxis, dataArea);
Iterator iterator = ticks.iterator();
while (iterator.hasNext()) {
NumberTick tick = (NumberTick) iterator.next();
double angleDegrees = plot.isCounterClockwise()
? plot.getAngleOffset() : -plot.getAngleOffset();
Point p = plot.translateToJava2D(angleDegrees,
tick.getNumber().doubleValue(), radialAxis, dataArea);
int r = p.x - center.x;
int upperLeftX = center.x - r;
int upperLeftY = center.y - r;
int d = 2 * r;
Ellipse2D ring = new Ellipse2D.Double(upperLeftX, upperLeftY, d, d);
g2.setPaint(plot.getRadiusGridlinePaint());
g2.draw(ring);
}
}
/**
* Adds an entity to the collection.
*
* @param entities the entity collection being populated.
* @param hotspot the entity area (if <code>null</code> a default will be
* used).
* @param dataset the dataset.
* @param row the series.
* @param column the item.
* @param selected is the item selected?
* @param entityX the entity's center x-coordinate in user space (only
* used if <code>area</code> is <code>null</code>).
* @param entityY the entity's center y-coordinate in user space (only
* used if <code>area</code> is <code>null</code>).
*
* @since 1.2.0
*/
protected void addEntity(EntityCollection entities, Shape hotspot,
CategoryDataset dataset, int row, int column, boolean selected,
double entityX, double entityY) {
if (!getItemCreateEntity(row, column, selected)) {
return;
}
Shape s = hotspot;
if (hotspot == null) {
double r = getDefaultEntityRadius();
double w = r * 2;
if (getPlot().getOrientation() == PlotOrientation.VERTICAL) {
s = new Ellipse2D.Double(entityX - r, entityY - r, w, w);
}
else {
s = new Ellipse2D.Double(entityY - r, entityX - r, w, w);
}
}
String tip = null;
CategoryToolTipGenerator generator = getToolTipGenerator(row, column,
selected);
if (generator != null) {
tip = generator.generateToolTip(dataset, row, column);
}
String url = null;
CategoryURLGenerator urlster = getURLGenerator(row, column, selected);
if (urlster != null) {
url = urlster.generateURL(dataset, row, column);
}
CategoryItemEntity entity = new CategoryItemEntity(s, tip, url,
dataset, dataset.getRowKey(row), dataset.getColumnKey(column));
entities.add(entity);
}
/**
* Returns a circle passing by the 3 given points.
*
* @param P1 the first point.
* @param P2 the second point.
* @param P3 the third point.
* @return a circle passing by the given points.
*/
public static Ellipse2D circle(final Point2D P1, final Point2D P2, final Point2D P3) {
final Point2D.Double center = ShapeUtilities.circleCentre(P1.getX(), P1.getY(),
P2.getX(), P2.getY(),
P3.getX(), P3.getY());
final double radius = center.distance(P2);
return new Ellipse2D.Double(center.x - radius,
center.y - radius,
2*radius, 2*radius);
}
/**
* Constructs a new compass plot.
*
* @param dataset the dataset for the plot (<code>null</code> permitted).
*/
public CompassPlot(ValueDataset dataset) {
super();
if (dataset != null) {
this.datasets[0] = dataset;
dataset.addChangeListener(this);
}
this.circle1 = new Ellipse2D.Double();
this.circle2 = new Ellipse2D.Double();
this.rect1 = new Rectangle2D.Double();
setSeriesNeedle(0);
}
private void shapedCbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shapedCbActionPerformed
if (testFrame != null) {
Shape s = null;
if (shapedCb.isSelected()) {
s = new Ellipse2D.Double(0, 0,
testFrame.getWidth(),
testFrame.getHeight());
}
testFrame.setShape(s);
}
}
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();
}