Example usage for java.awt.geom Area getPathIterator

List of usage examples for java.awt.geom Area getPathIterator

Introduction

In this page you can find the example usage for java.awt.geom Area getPathIterator.

Prototype

public PathIterator getPathIterator(AffineTransform at, double flatness) 

Source Link

Document

Creates a PathIterator for the flattened outline of this Area object.

Usage

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Ellipse2D e1 = new Ellipse2D.Double(20.0, 20.0, 80.0, 70.0);
    Ellipse2D e2 = new Ellipse2D.Double(20.0, 70.0, 40.0, 40.0);

    Area a1 = new Area(e1);
    Area a2 = new Area(e2);

    a1.subtract(a2);// w ww  .  j ava 2  s  . co m

    g2.setColor(Color.orange);
    g2.fill(a1);

    g2.setColor(Color.black);
    g2.drawString("subtract", 20, 140);

    System.out.println(a1.getPathIterator(new AffineTransform(), 0.5).getWindingRule());
}

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 av  a2 s . co m*/
        } 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()));
}