下面列出了java.awt.geom.Ellipse2D#Double ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void paintEllipse(Point center, double major, double minor, double orientation)
{
gr.setColor(fillColor);
gr.setStroke(new BasicStroke(1));
double width = major * transform.getScaleX();
double height = minor * -transform.getScaleY();
Point2D.Double dst = new Point2D.Double();
transform.transform(new Point2D.Double(center.getX(), center.getY()), dst);
if (!FloatUtils.isEqual(orientation, 0.0))
{
gr.rotate(-orientation, dst.getX(), dst.getY());
}
Ellipse2D.Double ellipse = new Ellipse2D.Double(dst.getX() - (width / 2), dst.getY() - (height / 2), width, height);
gr.fill(ellipse);
// rotate back
if (!FloatUtils.isEqual(orientation, 0.0))
{
gr.rotate(orientation, dst.getX(), dst.getY());
}
}
/**
* 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));
}
}
}
static Shape createShapePixel(AmodeusComponent amodeusComponent, Tensor hull) {
if (Tensors.isEmpty(hull))
return new Ellipse2D.Double(0, 0, 0, 0);
Path2D path2d = new Path2D.Double();
boolean init = false;
for (Tensor vector : hull)
if (!init) {
init = true;
path2d.moveTo( //
vector.Get(0).number().doubleValue(), //
vector.Get(1).number().doubleValue());
} else
path2d.lineTo( //
vector.Get(0).number().doubleValue(), //
vector.Get(1).number().doubleValue());
path2d.closePath();
return path2d;
}
/**
* 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);
}
@Override
public void renderLine (Graphics2D g,
boolean showPoints,
double pointWidth)
{
Rectangle clip = g.getClipBounds();
if ((clip == null) || clip.intersects(getBounds())) {
checkLine();
if (startPoint != null) {
g.draw(getLine());
// Then the absolute defining points?
if (showPoints) {
double r = pointWidth / 2; // Point radius
Ellipse2D ellipse = new Ellipse2D.Double();
for (Point2D p : new Point2D[]{startPoint, stopPoint}) {
ellipse.setFrame(p.getX() - r, p.getY() - r, 2 * r, 2 * r);
g.fill(ellipse);
}
}
}
}
}
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);
}
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
private Area buildPrimitive() {
Rectangle2D.Double body = new Rectangle2D.Double( 6, 0, 30, 12 ); // location and size
Ellipse2D.Double head = new Ellipse2D.Double( 0, 0, 12, 12 );
Ellipse2D.Double tail = new Ellipse2D.Double( 30, 0, 12, 12 );
Area tick = new Area(body);
tick.add( new Area( head ) );
tick.add( new Area( tail ) );
return tick;
}
/**
* Draws two ellipses to represent overlapping outliers.
*
* @param point the location.
* @param boxWidth the box width.
* @param oRadius the radius.
* @param g2 the graphics device.
*/
protected void drawMultipleEllipse(Point2D point, double boxWidth,
double oRadius, Graphics2D g2) {
Ellipse2D.Double dot1 = new Ellipse2D.Double(point.getX()
- (boxWidth / 2) + oRadius, point.getY(), oRadius, oRadius);
Ellipse2D.Double dot2 = new Ellipse2D.Double(point.getX()
+ (boxWidth / 2), point.getY(), oRadius, oRadius);
g2.draw(dot1);
g2.draw(dot2);
}
/**
* Calculates the location of the waferedge.
*
* @param plotArea the plot area.
*
* @return The wafer edge.
*/
protected Ellipse2D getWaferEdge(Rectangle2D plotArea) {
Ellipse2D edge = new Ellipse2D.Double();
double diameter = plotArea.getWidth();
double upperLeftX = plotArea.getX();
double upperLeftY = plotArea.getY();
//get major dimension
if (plotArea.getWidth() != plotArea.getHeight()) {
double major, minor;
if (plotArea.getWidth() > plotArea.getHeight()) {
major = plotArea.getWidth();
minor = plotArea.getHeight();
}
else {
major = plotArea.getHeight();
minor = plotArea.getWidth();
}
//ellipse diameter is the minor dimension
diameter = minor;
//set upperLeft point
if (plotArea.getWidth() == minor) { // x is minor
upperLeftY = plotArea.getY() + (major - minor) / 2;
}
else { // y is minor
upperLeftX = plotArea.getX() + (major - minor) / 2;
}
}
edge.setFrame(upperLeftX, upperLeftY, diameter, diameter);
return edge;
}
public BufferedImage createYellowOffImage(final int WIDTH, final int HEIGHT) {
final GraphicsConfiguration GFX_CONF = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
if (WIDTH <= 0 || HEIGHT <= 0) {
return GFX_CONF.createCompatibleImage(1, 1, java.awt.Transparency.TRANSLUCENT);
}
final BufferedImage IMAGE = GFX_CONF.createCompatibleImage(WIDTH, HEIGHT, Transparency.TRANSLUCENT);
final Graphics2D G2 = IMAGE.createGraphics();
G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
G2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
final int IMAGE_WIDTH = IMAGE.getWidth();
final int IMAGE_HEIGHT = IMAGE.getHeight();
final Ellipse2D LIGHT_OFF = new Ellipse2D.Double(0.17346938775510204 * IMAGE_WIDTH, 0.38489208633093525 * IMAGE_HEIGHT, 0.6530612244897959 * IMAGE_WIDTH, 0.2302158273381295 * IMAGE_HEIGHT);
G2.setPaint(new RadialGradientPaint(new Point2D.Double(0.5 * IMAGE_WIDTH, 0.5 * IMAGE_HEIGHT), (0.32653061224489793f * IMAGE_WIDTH), new float[]{0.0f, 1.0f}, new Color[]{new Color(1f, 1f, 0f, 0.2470588235f), new Color(1f, 1f, 0f, 0.0470588235f)}));
G2.fill(LIGHT_OFF);
final Ellipse2D INNER_SHADOW = new Ellipse2D.Double(0.17346938775510204 * IMAGE_WIDTH, 0.38489208633093525 * IMAGE_HEIGHT, 0.6530612244897959 * IMAGE_WIDTH, 0.2302158273381295 * IMAGE_HEIGHT);
G2.setPaint(new RadialGradientPaint(new Point2D.Double(0.5 * IMAGE_WIDTH, 0.5 * IMAGE_HEIGHT), (0.32653061224489793f * IMAGE_WIDTH), new float[]{0.0f, 0.55f, 0.5501f, 0.78f, 0.79f, 1.0f}, new Color[]{new Color(0.0039215686f, 0.0039215686f, 0.0039215686f, 0f), new Color(0f, 0f, 0f, 0f), new Color(0f, 0f, 0f, 0f), new Color(0f, 0f, 0f, 0.1215686275f), new Color(0f, 0f, 0f, 0.1294117647f), new Color(0f, 0f, 0f, 0.4980392157f)}));
G2.fill(INNER_SHADOW);
final TexturePaint HATCH_PAINT = new TexturePaint(HATCH_TEXTURE, new java.awt.Rectangle(0, 0, 2, 2));
G2.setPaint(HATCH_PAINT);
G2.fill(INNER_SHADOW);
G2.dispose();
return IMAGE;
}
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
JMenuItem b = (JMenuItem) c;
ButtonModel bm = b.getModel();
g.translate(x, y);
boolean isSelected = bm.isSelected();
boolean isEnabled = bm.isEnabled();
boolean isPressed = bm.isPressed();
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
// drawing background section
if (!isEnabled) {
g2.setColor(Colors.RADIOBUTTON_BORDER_DISABLED);
} else {
if (isPressed) {
g2.setColor(Colors.RADIOBUTTON_BORDER_FOCUS);
} else {
g2.setColor(Colors.RADIOBUTTON_BORDER);
}
}
g2.setStroke(RADIO_STROKE);
Shape circle = new Ellipse2D.Double(0, 0, 9, 9);
g2.draw(circle);
// drawing sphere
if (isSelected) {
if (isEnabled) {
g2.setColor(Colors.RADIOBUTTON_CHECKED);
} else {
g2.setColor(Colors.RADIOBUTTON_CHECKED_DISABLED);
}
circle = new Ellipse2D.Double(3, 3, 4, 4);
g2.fill(circle);
}
g.translate(-x, -y);
}
protected Outline getHeadDecoration(Graphics2D graphics, LineDecoration deco, BasicStroke stroke) {
if (deco == null || stroke == null) {
return null;
}
DecorationSize headLength = deco.getHeadLength();
if (headLength == null) {
headLength = DecorationSize.MEDIUM;
}
DecorationSize headWidth = deco.getHeadWidth();
if (headWidth == null) {
headWidth = DecorationSize.MEDIUM;
}
double lineWidth = Math.max(2.5, stroke.getLineWidth());
Rectangle2D anchor = getAnchor(graphics, getShape());
double x1 = anchor.getX(), y1 = anchor.getY();
double alpha = Math.atan(anchor.getHeight() / anchor.getWidth());
AffineTransform at = new AffineTransform();
java.awt.Shape headShape = null;
Path p = null;
Rectangle2D bounds;
final double scaleY = Math.pow(DECO_SIZE_POW, headWidth.ordinal()+1.);
final double scaleX = Math.pow(DECO_SIZE_POW, headLength.ordinal()+1.);
DecorationShape headShapeEnum = deco.getHeadShape();
if (headShapeEnum == null) {
return null;
}
switch (headShapeEnum) {
case OVAL:
p = new Path();
headShape = new Ellipse2D.Double(0, 0, lineWidth * scaleX, lineWidth * scaleY);
bounds = headShape.getBounds2D();
at.translate(x1 - bounds.getWidth() / 2, y1 - bounds.getHeight() / 2);
at.rotate(alpha, bounds.getX() + bounds.getWidth() / 2, bounds.getY() + bounds.getHeight() / 2);
break;
case STEALTH:
case ARROW:
p = new Path(false, true);
Path2D.Double arrow = new Path2D.Double();
arrow.moveTo((lineWidth * scaleX), (-lineWidth * scaleY / 2));
arrow.lineTo(0, 0);
arrow.lineTo((lineWidth * scaleX), (lineWidth * scaleY / 2));
headShape = arrow;
at.translate(x1, y1);
at.rotate(alpha);
break;
case TRIANGLE:
p = new Path();
Path2D.Double triangle = new Path2D.Double();
triangle.moveTo((lineWidth * scaleX), (-lineWidth * scaleY / 2));
triangle.lineTo(0, 0);
triangle.lineTo((lineWidth * scaleX), (lineWidth * scaleY / 2));
triangle.closePath();
headShape = triangle;
at.translate(x1, y1);
at.rotate(alpha);
break;
default:
break;
}
if (headShape != null) {
headShape = at.createTransformedShape(headShape);
}
return headShape == null ? null : new Outline(headShape, p);
}
public ShapeDrawable makePoint(double x, double y, double radius) {
double size = radius*2;
return new ShapeDrawable(new Ellipse2D.Double(x - radius, y - radius, size, size));
}
public static void strokeCircle(Graphics2D g, int x, int y, int r) {
Ellipse2D circle = new Ellipse2D.Double(x - r, y - r, 2 * r, 2 * r);
g.draw(circle);
}
private Ellipse2D getDraggableArea(Point2D control) {
Ellipse2D outer = new Ellipse2D.Double(xPositionToPixel(control.getX()) - CONTROL_POINT_SIZE / 2.0,
yPositionToPixel(control.getY()) - CONTROL_POINT_SIZE / 2.0,
CONTROL_POINT_SIZE, CONTROL_POINT_SIZE);
return outer;
}
/**
* Creates an interactive ellipse.
*
* @param x
* @param y
* @param w
* @param h
* @return InteractiveShape
*/
public static InteractiveShape createEllipse(double x, double y, double w, double h) {
Shape shape = new Ellipse2D.Double(-w/2, -h/2, w, h);
InteractiveShape is = new InteractiveShape(shape, x, y);
is.width = w;
is.height = h;
return is;
}
/**
* �R���X�g���N�^
*
* @param x �X�|�b�g���C�g���S��X���W
* @param y �X�|�b�g���C�g���S��Y���W
* @param radius �X�|�b�g���C�g�̔��a
*/
public Spotlight(int x, int y, int radius) {
this.spot = new Ellipse2D.Double(x - radius, y - radius, radius * 2,
radius * 2);
}