List of usage examples for java.awt.geom Ellipse2D getHeight
public abstract double getHeight();
From source file:Main.java
/** * Serialises a <code>Shape</code> object. * * @param shape the shape object (<code>null</code> permitted). * @param stream the output stream (<code>null</code> not permitted). * * @throws IOException if there is an I/O error. */// w w w. j av a2 s. c o m public static void writeShape(final Shape shape, final ObjectOutputStream stream) throws IOException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } if (shape != null) { stream.writeBoolean(false); if (shape instanceof Line2D) { final Line2D line = (Line2D) shape; stream.writeObject(Line2D.class); stream.writeDouble(line.getX1()); stream.writeDouble(line.getY1()); stream.writeDouble(line.getX2()); stream.writeDouble(line.getY2()); } else if (shape instanceof Rectangle2D) { final Rectangle2D rectangle = (Rectangle2D) shape; stream.writeObject(Rectangle2D.class); stream.writeDouble(rectangle.getX()); stream.writeDouble(rectangle.getY()); stream.writeDouble(rectangle.getWidth()); stream.writeDouble(rectangle.getHeight()); } else if (shape instanceof Ellipse2D) { final Ellipse2D ellipse = (Ellipse2D) shape; stream.writeObject(Ellipse2D.class); stream.writeDouble(ellipse.getX()); stream.writeDouble(ellipse.getY()); stream.writeDouble(ellipse.getWidth()); stream.writeDouble(ellipse.getHeight()); } else if (shape instanceof Arc2D) { final Arc2D arc = (Arc2D) shape; stream.writeObject(Arc2D.class); stream.writeDouble(arc.getX()); stream.writeDouble(arc.getY()); stream.writeDouble(arc.getWidth()); stream.writeDouble(arc.getHeight()); stream.writeDouble(arc.getAngleStart()); stream.writeDouble(arc.getAngleExtent()); stream.writeInt(arc.getArcType()); } else if (shape instanceof GeneralPath) { stream.writeObject(GeneralPath.class); final PathIterator pi = shape.getPathIterator(null); final float[] args = new float[6]; stream.writeBoolean(pi.isDone()); while (!pi.isDone()) { final int type = pi.currentSegment(args); stream.writeInt(type); // TODO: could write this to only stream the values // required for the segment type for (int i = 0; i < 6; i++) { stream.writeFloat(args[i]); } stream.writeInt(pi.getWindingRule()); pi.next(); stream.writeBoolean(pi.isDone()); } } else { stream.writeObject(shape.getClass()); stream.writeObject(shape); } } else { stream.writeBoolean(true); } }
From source file:org.pentaho.plugin.jfreereport.reportcharts.JFreeChartReportDrawable.java
private AbstractImageMapEntry createMapEntry(final Shape area, final Rectangle2D dataArea) { if (buggyDrawArea) { if (area instanceof Ellipse2D) { final Ellipse2D ellipse2D = (Ellipse2D) area; if (ellipse2D.getWidth() == ellipse2D.getHeight()) { return new CircleImageMapEntry((float) (ellipse2D.getCenterX() + dataArea.getX()), (float) (ellipse2D.getCenterY() + dataArea.getY()), (float) (ellipse2D.getWidth() / 2)); }/*w w w . j a va 2s .c om*/ } else if (area instanceof Rectangle2D) { final Rectangle2D rect = (Rectangle2D) area; return (new RectangleImageMapEntry((float) (rect.getX() + dataArea.getX()), (float) (rect.getY() + dataArea.getY()), (float) (rect.getX() + rect.getWidth()), (float) (rect.getY() + rect.getHeight()))); } } else { if (area instanceof Ellipse2D) { final Ellipse2D ellipse2D = (Ellipse2D) area; if (ellipse2D.getWidth() == ellipse2D.getHeight()) { return new CircleImageMapEntry((float) (ellipse2D.getCenterX()), (float) (ellipse2D.getCenterY()), (float) (ellipse2D.getWidth() / 2)); } } else if (area instanceof Rectangle2D) { final Rectangle2D rect = (Rectangle2D) area; return (new RectangleImageMapEntry((float) (rect.getX()), (float) (rect.getY()), (float) (rect.getX() + rect.getWidth()), (float) (rect.getY() + rect.getHeight()))); } } final Area a = new Area(area); if (buggyDrawArea) { a.transform(AffineTransform.getTranslateInstance(dataArea.getX(), dataArea.getY())); } if (dataArea.isEmpty() == false) { a.intersect(new Area(dataArea)); } final PathIterator pathIterator = a.getPathIterator(null, 2); final FloatList floats = new FloatList(100); final float[] coords = new float[6]; while (pathIterator.isDone() == false) { final int retval = pathIterator.currentSegment(coords); if (retval == PathIterator.SEG_MOVETO || retval == PathIterator.SEG_LINETO) { floats.add(coords[0]); floats.add(coords[1]); } pathIterator.next(); } if (floats.size() == 0) { return null; } return (new PolygonImageMapEntry(floats.toArray())); }
From source file:be.ugent.maf.cellmissy.gui.controller.load.generic.DragAndDropController.java
/** * Highlight the imaged well for which we are importing data. * * @param selectedWellGui// ww w. j av a 2 s.co m */ private void highlightImagedWell(WellGui selectedWellGui) { List<Ellipse2D> ellipsi = selectedWellGui.getEllipsi(); List<WellHasImagingType> wellHasImagingTypeList = selectedWellGui.getWell().getWellHasImagingTypeList(); ImagedPlatePanel imagedPlatePanel = genericImagedPlateController.getImagedPlatePanel(); List<ImagingType> uniqueImagingTypes = imagedPlatePanel.getUniqueImagingTypes(wellHasImagingTypeList); // if size is one, only one imaging type was processed: do not add eny ellipsi if (uniqueImagingTypes.size() != 1) { if (ellipsi.size() < uniqueImagingTypes.size()) { int lastIndex = uniqueImagingTypes.size() - 2; Ellipse2D lastEllipse = ellipsi.get(lastIndex); // calculate factors for new ellipse double size = lastEllipse.getHeight(); double newSize = (size / uniqueImagingTypes.size()); double newTopLeftX = lastEllipse.getCenterX() - (newSize / 2); double newTopLeftY = lastEllipse.getCenterY() - (newSize / 2); if (newSize != size) { Ellipse2D ellipseToAdd = new Ellipse2D.Double(newTopLeftX, newTopLeftY, newSize, newSize); // add the new Ellipse2D to the ellipsi List ellipsi.add(ellipseToAdd); } } } imagedPlatePanel.repaint(); }
From source file:org.apache.fop.afp.AFPGraphics2D.java
/** * Handle the Batik drawing event/*from ww w. j ava2 s.c o m*/ * * @param shape * the shape to draw * @param fill * true if the shape is to be drawn filled */ private void doDrawing(Shape shape, boolean fill) { if (!fill) { graphicsObj.newSegment(); } graphicsObj.setColor(gc.getColor()); applyPaint(gc.getPaint(), fill); if (fill) { graphicsObj.beginArea(); } else { applyStroke(gc.getStroke()); } AffineTransform trans = gc.getTransform(); PathIterator iter = shape.getPathIterator(trans); if (shape instanceof Line2D) { double[] dstPts = new double[6]; iter.currentSegment(dstPts); int[] coords = new int[4]; coords[X1] = (int) Math.round(dstPts[X]); coords[Y1] = (int) Math.round(dstPts[Y]); iter.next(); iter.currentSegment(dstPts); coords[X2] = (int) Math.round(dstPts[X]); coords[Y2] = (int) Math.round(dstPts[Y]); graphicsObj.addLine(coords); } else if (shape instanceof Rectangle2D) { double[] dstPts = new double[6]; iter.currentSegment(dstPts); int[] coords = new int[4]; coords[X2] = (int) Math.round(dstPts[X]); coords[Y2] = (int) Math.round(dstPts[Y]); iter.next(); iter.next(); iter.currentSegment(dstPts); coords[X1] = (int) Math.round(dstPts[X]); coords[Y1] = (int) Math.round(dstPts[Y]); graphicsObj.addBox(coords); } else if (shape instanceof Ellipse2D) { double[] dstPts = new double[6]; Ellipse2D elip = (Ellipse2D) shape; double scale = trans.getScaleX(); double radiusWidth = elip.getWidth() / 2; double radiusHeight = elip.getHeight() / 2; graphicsObj.setArcParams((int) Math.round(radiusWidth * scale), (int) Math.round(radiusHeight * scale), 0, 0); double[] srcPts = new double[] { elip.getCenterX(), elip.getCenterY() }; trans.transform(srcPts, 0, dstPts, 0, 1); final int mh = 1; final int mhr = 0; graphicsObj.addFullArc((int) Math.round(dstPts[X]), (int) Math.round(dstPts[Y]), mh, mhr); } else { processPathIterator(iter); } if (fill) { graphicsObj.endArea(); } }