Example usage for java.awt.geom Rectangle2D getBounds2D

List of usage examples for java.awt.geom Rectangle2D getBounds2D

Introduction

In this page you can find the example usage for java.awt.geom Rectangle2D getBounds2D.

Prototype

public Rectangle2D getBounds2D() 

Source Link

Usage

From source file:ShapeTransform.java

/**
 * Clips the given shape to the given bounds. If the shape is a Line2D, manual
 * clipping is performed, as the built in Area does not handle lines.
 * /*from ww  w.  j av  a2 s. com*/
 * @param s
 *          the shape to be clipped
 * @param bounds
 *          the bounds to which the shape should be clipped
 * @return the clipped shape.
 */
public static Shape performCliping(final Shape s, final Rectangle2D bounds) {
    if (s instanceof Line2D) {
        final Line2D line = (Line2D) s;
        final Point2D[] clipped = getClipped(line.getX1(), line.getY1(), line.getX2(), line.getY2(), -DELTA,
                DELTA + bounds.getWidth(), -DELTA, DELTA + bounds.getHeight());
        if (clipped == null) {
            return new GeneralPath();
        }
        return new Line2D.Float(clipped[0], clipped[1]);
    }

    final Rectangle2D boundsCorrected = bounds.getBounds2D();
    boundsCorrected.setRect(-DELTA, -DELTA, DELTA + boundsCorrected.getWidth(),
            DELTA + boundsCorrected.getHeight());
    final Area a = new Area(boundsCorrected);
    if (a.isEmpty()) {
        // don't clip ... Area does not like lines
        // operations with lines always result in an empty Bounds:(0,0,0,0) area
        return new GeneralPath();
    }

    final Area clipArea = new Area(s);
    a.intersect(clipArea);
    return a;

}

From source file:org.gumtree.vis.awt.JChartPanel.java

private Line2D convertDomainAxisMarker(Line2D marker) {
    Line2D newLine = (Line2D) marker.clone();
    Rectangle2D imageArea = getScreenDataArea();
    double maxY = imageArea.getBounds2D().getMaxY();
    if (maxY == 0) {
        isShapeValid = false;/*from  w w w  . j ava2  s . c  om*/
    }
    newLine.setLine(marker.getX1(),
            ChartMaskingUtilities.translateScreenY(maxY - marker.getY1(), imageArea, getChart(), 0),
            marker.getX2(),
            ChartMaskingUtilities.translateScreenY(maxY - marker.getY2(), imageArea, getChart(), 0));
    return newLine;
}

From source file:org.gumtree.vis.awt.JChartPanel.java

private Line2D convertRangeAxisMarker(Line2D marker) {
    Line2D newLine = (Line2D) marker.clone();
    Rectangle2D imageArea = getScreenDataArea();
    double minX = imageArea.getBounds2D().getMinX();
    if (imageArea.getBounds2D().getMaxX() == 0) {
        isShapeValid = false;//  w  w w  .j av  a2 s. c o m
    }
    newLine.setLine(ChartMaskingUtilities.translateScreenX(minX + marker.getX1(), imageArea, getChart()),
            marker.getY1(),
            ChartMaskingUtilities.translateScreenX(minX + marker.getX2(), imageArea, getChart()),
            marker.getY2());
    return newLine;
}

From source file:org.esa.snap.graphbuilder.gpf.ui.worldmap.NestWorldMapPane.java

public void zoomToProduct(Product product) {
    final GeoPos[][] selGeoBoundaries = dataModel.getSelectedGeoBoundaries();
    if ((product == null || product.getSceneGeoCoding() == null) && selGeoBoundaries.length == 0) {
        return;/*from   w  w w. ja  v a  2s  .c  o m*/
    }

    //NESTMOD
    final GeneralPath[] generalPaths;
    if (product != null && product.getSceneGeoCoding() != null) {
        generalPaths = getGeoBoundaryPaths(product);
    } else {
        final ArrayList<GeneralPath> pathList = assemblePathList(selGeoBoundaries[0]);
        generalPaths = pathList.toArray(new GeneralPath[pathList.size()]);
    }

    Rectangle2D modelArea = new Rectangle2D.Double();
    final Viewport viewport = layerCanvas.getViewport();
    for (GeneralPath generalPath : generalPaths) {
        final Rectangle2D rectangle2D = generalPath.getBounds2D();
        if (modelArea.isEmpty()) {
            if (!viewport.isModelYAxisDown()) {
                modelArea.setFrame(rectangle2D.getX(), rectangle2D.getMaxY(), rectangle2D.getWidth(),
                        rectangle2D.getHeight());
            }
            modelArea = rectangle2D;
        } else {
            modelArea.add(rectangle2D);
        }
    }
    Rectangle2D modelBounds = modelArea.getBounds2D();
    modelBounds.setFrame(modelBounds.getX() - 2, modelBounds.getY() - 2, modelBounds.getWidth() + 4,
            modelBounds.getHeight() + 4);

    modelBounds = cropToMaxModelBounds(modelBounds);

    viewport.zoom(modelBounds);
}