Example usage for java.awt.geom Area transform

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

Introduction

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

Prototype

AffineTransform transform

To view the source code for java.awt.geom Area transform.

Click Source Link

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);/*from  w  w  w. ja v a 2  s  .  c  o m*/

    a1.transform(new AffineTransform());

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

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

}

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  2  s .c o 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()));
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.JFreeChartReportDrawable.java

public void draw(final Graphics2D graphics2D, final Rectangle2D bounds) {
    this.bounds = (Rectangle2D) bounds.clone();
    if (chartRenderingInfo != null) {
        this.chartRenderingInfo.clear();
    }//w w w .  j a  va 2  s  .  co m
    final Graphics2D g2 = (Graphics2D) graphics2D.create();
    this.chart.draw(g2, bounds, chartRenderingInfo);
    g2.dispose();

    if (chartRenderingInfo == null || debugRendering == false) {
        return;
    }

    graphics2D.setColor(Color.RED);
    final Rectangle2D dataArea = getDataAreaOffset();
    final EntityCollection entityCollection = chartRenderingInfo.getEntityCollection();
    for (int i = 0; i < entityCollection.getEntityCount(); i++) {
        final ChartEntity chartEntity = entityCollection.getEntity(i);
        if (chartEntity instanceof XYItemEntity || chartEntity instanceof CategoryItemEntity
                || chartEntity instanceof PieSectionEntity) {
            final Area a = new Area(chartEntity.getArea());
            if (buggyDrawArea) {
                a.transform(AffineTransform.getTranslateInstance(dataArea.getX(), dataArea.getY()));
            }
            a.intersect(new Area(dataArea));
            graphics2D.draw(a);
        } else {
            graphics2D.draw(chartEntity.getArea());
        }
    }
}

From source file:com.t3.model.LightSource.java

private Area getArea(Token token, Zone zone, Direction position, Area area) {
    Grid grid = zone.getGrid();//from  w ww. j  av  a 2s  .c o  m
    Rectangle footprintBounds = token.getFootprint(grid).getBounds(grid,
            grid.convert(new ZonePoint(token.getX(), token.getY())));

    int tx = 0;
    int ty = 0;
    switch (position) {
    case NW:
        tx -= footprintBounds.width / 2;
        ty -= footprintBounds.height / 2;
        break;
    case N:
        ty -= footprintBounds.height / 2;
        break;
    case NE:
        tx += footprintBounds.width / 2;
        ty -= footprintBounds.height / 2;
        break;
    case W:
        tx -= footprintBounds.width / 2;
        break;
    case CENTER:
        break;
    case E:
        tx += footprintBounds.width / 2;
        break;
    case SW:
        tx -= footprintBounds.width / 2;
        ty += footprintBounds.height / 2;
        break;
    case S:
        ty += footprintBounds.height / 2;
        break;
    case SE:
        tx += footprintBounds.width / 2;
        ty += footprintBounds.height / 2;
        break;
    }
    area.transform(AffineTransform.getTranslateInstance(tx, ty));
    return area;
}