List of usage examples for java.awt.geom GeneralPath setWindingRule
public final void setWindingRule(int rule)
From source file:Main.java
/** * Reads a <code>Shape</code> object that has been serialised by the * {@link #writeShape(Shape, ObjectOutputStream)} method. * * @param stream the input stream (<code>null</code> not permitted). * * @return The shape object (possibly <code>null</code>). * * @throws IOException if there is an I/O problem. * @throws ClassNotFoundException if there is a problem loading a class. *//*from w w w . j a v a2 s. co m*/ public static Shape readShape(final ObjectInputStream stream) throws IOException, ClassNotFoundException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } Shape result = null; final boolean isNull = stream.readBoolean(); if (!isNull) { final Class c = (Class) stream.readObject(); if (c.equals(Line2D.class)) { final double x1 = stream.readDouble(); final double y1 = stream.readDouble(); final double x2 = stream.readDouble(); final double y2 = stream.readDouble(); result = new Line2D.Double(x1, y1, x2, y2); } else if (c.equals(Rectangle2D.class)) { final double x = stream.readDouble(); final double y = stream.readDouble(); final double w = stream.readDouble(); final double h = stream.readDouble(); result = new Rectangle2D.Double(x, y, w, h); } else if (c.equals(Ellipse2D.class)) { final double x = stream.readDouble(); final double y = stream.readDouble(); final double w = stream.readDouble(); final double h = stream.readDouble(); result = new Ellipse2D.Double(x, y, w, h); } else if (c.equals(Arc2D.class)) { final double x = stream.readDouble(); final double y = stream.readDouble(); final double w = stream.readDouble(); final double h = stream.readDouble(); final double as = stream.readDouble(); // Angle Start final double ae = stream.readDouble(); // Angle Extent final int at = stream.readInt(); // Arc type result = new Arc2D.Double(x, y, w, h, as, ae, at); } else if (c.equals(GeneralPath.class)) { final GeneralPath gp = new GeneralPath(); final float[] args = new float[6]; boolean hasNext = stream.readBoolean(); while (!hasNext) { final int type = stream.readInt(); for (int i = 0; i < 6; i++) { args[i] = stream.readFloat(); } switch (type) { case PathIterator.SEG_MOVETO: gp.moveTo(args[0], args[1]); break; case PathIterator.SEG_LINETO: gp.lineTo(args[0], args[1]); break; case PathIterator.SEG_CUBICTO: gp.curveTo(args[0], args[1], args[2], args[3], args[4], args[5]); break; case PathIterator.SEG_QUADTO: gp.quadTo(args[0], args[1], args[2], args[3]); break; case PathIterator.SEG_CLOSE: gp.closePath(); break; default: throw new RuntimeException("JFreeChart - No path exists"); } gp.setWindingRule(stream.readInt()); hasNext = stream.readBoolean(); } result = gp; } else { result = (Shape) stream.readObject(); } } return result; }
From source file:org.apache.pdfbox.pdfviewer.PageDrawer.java
/** * Set the clipping Path.// ww w. ja v a 2 s . co m * * @param windingRule The winding rule this path will use. * */ public void setClippingPath(int windingRule) { PDGraphicsState graphicsState = getGraphicsState(); GeneralPath clippingPath = (GeneralPath) getLinePath().clone(); clippingPath.setWindingRule(windingRule); // If there is already set a clipping path, we have to intersect the new with the existing one if (graphicsState.getCurrentClippingPath() != null) { Area currentArea = new Area(getGraphicsState().getCurrentClippingPath()); Area newArea = new Area(clippingPath); currentArea.intersect(newArea); graphicsState.setCurrentClippingPath(currentArea); } else { graphicsState.setCurrentClippingPath(clippingPath); } getLinePath().reset(); }