Example usage for java.awt Rectangle add

List of usage examples for java.awt Rectangle add

Introduction

In this page you can find the example usage for java.awt Rectangle add.

Prototype

public void add(Rectangle r) 

Source Link

Document

Adds a Rectangle to this Rectangle .

Usage

From source file:Main.java

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

    Rectangle r = new Rectangle(10, 10, 50, 40);

    r.add(new Rectangle(40, 40, 100, 100));

    g2.fill(r);//from   w w  w  .j  av  a2  s. com

}

From source file:Main.java

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

    Rectangle r = new Rectangle(10, 10, 50, 40);

    r.add(new Point(40, 40));

    g2.fill(r);/*from  w w w  . ja v a  2 s .  co m*/

}

From source file:org.esa.s2tbx.dataio.s2.l1b.L1bSceneDescription.java

/**
 * Returns the scene description, or null if no scene description can be created (no tile of
 * no tile layout)//from  www . jav a  2 s. c  o m
 *
 * @param header            the {@link L1bMetadata} object containing the tile list
 * @param productResolution the product resolution for which we want the scene description
 * @return the scene description of {@code null}
 */
public static L1bSceneDescription create(L1bMetadata header, S2SpatialResolution productResolution) {
    L1bSceneDescription sceneDescription = null;

    List<S2Metadata.Tile> tileList = header.getTileList();
    // initialise with default CRS
    CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84;
    Envelope2D[] tileEnvelopes = new Envelope2D[tileList.size()];
    TileInfo[] tileInfos = new TileInfo[tileList.size()];
    Envelope2D sceneEnvelope = null;

    if (!tileList.isEmpty()) {

        Map<String, Integer> detectorsTopPositionMap = computeTopPositions(tileList, productResolution);

        for (int i = 0; i < tileList.size(); i++) {
            L1bMetadata.Tile tile = tileList.get(i);

            L1bMetadata.TileGeometry selectedGeometry = tile.getTileGeometry(productResolution);

            // Envelope2D envelope = new Envelope2D(selectedGeometry.envelope);

            Envelope2D envelope;

            // data is referenced through 1 based indexes
            // since position si computed for 10m, we need multiply by a ratio if product resolution is not 10m

            int ratio = productResolution.resolution / S2SpatialResolution.R10M.resolution;
            String detectorId = tile.getDetectorId();
            int topPosition = detectorsTopPositionMap.get(detectorId);
            int yOffset = (selectedGeometry.getPosition() - topPosition) / ratio;
            double yWidth = yOffset * selectedGeometry.getyDim();

            int xOffset = 0;

            envelope = new Envelope2D(crs, xOffset,
                    yWidth + selectedGeometry.getNumRows() * selectedGeometry.getyDim(),
                    selectedGeometry.getNumCols() * selectedGeometry.getxDim(),
                    -selectedGeometry.getNumRows() * selectedGeometry.getyDim());

            tileEnvelopes[i] = envelope;

            if (sceneEnvelope == null) {
                sceneEnvelope = new Envelope2D(crs, envelope);
            } else {
                sceneEnvelope.add(envelope);
            }
            tileInfos[i] = new TileInfo(i, tile.getId(), new Rectangle());
        }

        // get back to upperLeft info in scene
        double imageX = sceneEnvelope.getX();
        double imageY = sceneEnvelope.getY() + sceneEnvelope.getHeight();
        Rectangle sceneBounds = null;
        for (int i = 0; i < tileEnvelopes.length; i++) {
            L1bMetadata.Tile tile = tileList.get(i);
            L1bMetadata.TileGeometry selectedGeometry = tile.getTileGeometry(productResolution);
            Envelope2D tileEnvelope = tileEnvelopes[i];

            // upperLeft again
            double tileX = tileEnvelope.getX();
            double tileY = tileEnvelope.getY() + tileEnvelope.getHeight();

            Rectangle rectangle = new Rectangle((int) ((tileX - imageX) / selectedGeometry.getxDim()),
                    (int) ((imageY - tileY) / -selectedGeometry.getyDim()), selectedGeometry.getNumCols(),
                    selectedGeometry.getNumRows());
            if (sceneBounds == null) {
                sceneBounds = new Rectangle(rectangle);
            } else {
                sceneBounds.add(rectangle);
            }
            tileInfos[i] = new TileInfo(i, tile.getId(), rectangle);
        }

        sceneDescription = new L1bSceneDescription(tileInfos, sceneEnvelope, sceneBounds);
    }

    return sceneDescription;
}

From source file:eu.esdihumboldt.hale.ui.views.styledmap.tool.InstanceTool.java

/**
 * @see AbstractMapTool#click(MouseEvent, GeoPosition)
 *//*w w w  . j a va  2 s  .com*/
@Override
public void click(MouseEvent me, GeoPosition pos) {
    if (me.getClickCount() == 2) {
        mapKit.setCenterPosition(pos);
        mapKit.setZoom(mapKit.getMainMap().getZoom() - 1);
    } else if (me.getClickCount() == 1) {
        if (me.isAltDown() && getPositions().size() < 1) {
            // add pos
            addPosition(pos);
        } else if (getPositions().size() == 1) {
            // finish box selection
            // action & reset
            addPosition(pos);

            // action
            try {
                List<Point2D> points = getPoints();
                Rectangle rect = new Rectangle((int) points.get(0).getX(), (int) points.get(0).getY(), 0, 0);
                rect.add(points.get(1));

                updateSelection(rect, me.isControlDown() || me.isMetaDown(), true);
            } catch (IllegalGeoPositionException e) {
                log.error("Error calculating selection box", e); //$NON-NLS-1$
            }

            reset();
        } else {
            // click selection
            reset();

            updateSelection(me.getPoint(), me.isControlDown() || me.isMetaDown(), true);
        }
    }
}

From source file:org.uva.itast.blended.omr.pages.PageImage.java

/**
 * Convert box from Milimeters to Pixels relative to the PageImage in the preferred resolution
 * in case of alignment rotation the returned Rectangle is the minimum bounding box that contains
 * the original corners transformed./*from   ww  w. j  a  v a 2 s.  c  o  m*/
 * @param box in milimeters related to actual page
 * @return minimum bounding box in pixels related to image representation
 */
public Rectangle toPixels(Rectangle2D box) {

    Point p1 = toPixels(box.getX(), box.getY());
    Point p2 = toPixels(box.getMaxX(), box.getMaxY());
    Rectangle bboxPx = new Rectangle(p1);
    bboxPx.add(p2);
    return bboxPx;

}

From source file:com.tag.FramePreferences.java

public final Rectangle getGraphicsBounds() {
    GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Rectangle r = null;
    for (GraphicsDevice device : environment.getScreenDevices()) {
        GraphicsConfiguration config = device.getDefaultConfiguration();
        if (r == null) {
            r = config.getBounds();/*from ww w  . j a  v a2  s.  co  m*/
        } else {
            r.add(config.getBounds());
        }
    }
    return r;
}

From source file:VASSAL.counters.Labeler.java

public Rectangle boundingBox() {
    final Rectangle r = piece.boundingBox();
    r.add(new Rectangle(getLabelPosition(), imagePainter.getImageSize()));
    return r;/*w  w  w  . j a v  a  2 s. c  o m*/
}