Example usage for java.awt Rectangle contains

List of usage examples for java.awt Rectangle contains

Introduction

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

Prototype

public boolean contains(Rectangle r) 

Source Link

Document

Checks whether or not this Rectangle entirely contains the specified Rectangle .

Usage

From source file:tilt.image.Blob.java

/**
 * Is this blob surrounded by a wide band of white?
 * @param wr the raster to search in//from  w w  w . ja v a  2s. co  m
 * @param hStandoff the amount of white horizontal standoff
 * @param vStandoff the amount of vertical white standoff
 * @return true if it is
 */
boolean hasWhiteStandoff(WritableRaster wr, int hStandoff, int vStandoff) {
    // 1. original blob bounds
    Rectangle inner = new Rectangle(topLeft().x, topLeft().y, getWidth(), getHeight());
    Rectangle outer = (Rectangle) inner.clone();
    // 2. outset rect by standoff
    if (outer.x >= hStandoff)
        outer.x -= hStandoff;
    else
        outer.x = 0;
    if (outer.y - vStandoff > 0)
        outer.y -= vStandoff;
    else
        outer.y = 0;
    if (outer.x + outer.width + hStandoff * 2 < wr.getWidth())
        outer.width += hStandoff * 2;
    else
        outer.width = wr.getWidth() - outer.x;
    if (outer.y + outer.height + vStandoff * 2 < wr.getHeight())
        outer.height += vStandoff * 2;
    else
        outer.height = wr.getHeight() - outer.y;
    // 3. test for black pixels in that area
    int[] iArray = new int[1];
    int maxY = outer.y + outer.height;
    int maxX = outer.x + outer.width;
    int nBlacks = 0;
    int maxRogues = opts.getInt(Options.Keys.maxRoguePixels);
    for (int y = outer.y; y < maxY; y++) {
        for (int x = outer.x; x < maxX; x++) {
            Point loc = new Point(x, y);
            if (!inner.contains(loc)) {
                wr.getPixel(x, y, iArray);
                if (iArray[0] == 0) {
                    if (nBlacks == maxRogues) {
                        return false;
                    } else
                        nBlacks++;
                }
            }
        }
    }
    return true;
}

From source file:de.tor.tribes.ui.panels.MinimapPanel.java

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    try {//ww  w  .j  a  v  a2s  . c  om
        Graphics2D g2d = (Graphics2D) g;
        g2d.clearRect(0, 0, getWidth(), getHeight());
        g2d.drawImage(mBuffer, 0, 0, null);

        if (iCurrentView == ID_MINIMAP) {
            g2d.setColor(Color.YELLOW);

            int mapWidth = rVisiblePart.width;
            int mapHeight = rVisiblePart.height;

            int w = (int) Math.rint(((double) getWidth() / mapWidth) * (double) iWidth);
            int h = (int) Math.rint(((double) getHeight() / mapHeight) * (double) iHeight);

            double posX = ((double) getWidth() / mapWidth * (double) (iX - rVisiblePart.x)) - w / 2;
            double posY = ((double) getHeight() / mapHeight * (double) (iY - rVisiblePart.y)) - h / 2;

            g2d.drawRect((int) Math.rint(posX), (int) Math.rint(posY), w, h);

            if (iCurrentCursor == ImageManager.CURSOR_SHOT) {
                if (rDrag != null) {
                    g2d.setColor(Color.ORANGE);
                    g2d.drawRect((int) rDrag.getMinX(), (int) rDrag.getMinY(),
                            (int) (rDrag.getWidth() - rDrag.getX()), (int) (rDrag.getHeight() - rDrag.getY()));
                }
            } else if (iCurrentCursor == ImageManager.CURSOR_ZOOM) {
                if (rDrag != null) {
                    g2d.setColor(Color.CYAN);
                    g2d.drawRect((int) rDrag.getX(), (int) rDrag.getY(),
                            (int) (rDrag.getWidth() - rDrag.getX()),
                            (int) ((rDrag.getWidth() - rDrag.getX()) * ((double) getHeight()) / getWidth()));
                }
            }
        }

        if (showControls) {
            //g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .2f));
            Rectangle r = minimapButtons.get(ID_MINIMAP);
            g2d.setColor(Color.WHITE);
            Point menuPos = r.getLocation();
            menuPos.translate(-2, -2);
            //draw border
            g2d.fillRect(menuPos.x, menuPos.y, 88, 30);
            g2d.setColor(Color.BLACK);
            //check if mouse is inside minimap button
            if (getMousePosition() != null && r.contains(getMousePosition())) {
                g2d.setColor(Color.YELLOW);
                g2d.fillRect(r.x, r.y, r.width, r.height);
                g2d.setColor(Color.BLACK);
            }
            g2d.drawImage(minimapIcons.get(ID_MINIMAP), r.x, r.y, null);
            g2d.drawRect(r.x, r.y, r.width, r.height);

            r = minimapButtons.get(ID_ALLY_CHART);
            //check if mouse is inside ally chart button
            if (getMousePosition() != null && r.contains(getMousePosition())) {
                g2d.setColor(Color.YELLOW);
                g2d.fillRect(r.x, r.y, r.width, r.height);
                g2d.setColor(Color.BLACK);
            }
            g2d.drawImage(minimapIcons.get(ID_ALLY_CHART), r.x, r.y, null);
            g2d.drawRect(r.x, r.y, r.width, r.height);

            r = minimapButtons.get(ID_TRIBE_CHART);
            //check if mouse is inside tribe chart button
            if (getMousePosition() != null && r.contains(getMousePosition())) {
                g2d.setColor(Color.YELLOW);
                g2d.fillRect(r.x, r.y, r.width, r.height);
                g2d.setColor(Color.BLACK);

            }
            g2d.drawImage(minimapIcons.get(ID_TRIBE_CHART), r.x, r.y, null);
            g2d.drawRect(r.x, r.y, r.width, r.height);
        }
        g2d.dispose();
    } catch (Exception e) {
        logger.error("Failed painting Minimap", e);
    }
}

From source file:pcgen.gui2.PCGenFrame.java

/**
 * This checks to make sure that the given rectangle will be visible
 * on the current graphics environment// w ww  .ja  va  2s  .c o m
 */
private boolean checkBounds(Rectangle rect) {
    if (rect.isEmpty()) {
        return false;
    }
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();

    for (GraphicsDevice device : env.getScreenDevices()) {
        Rectangle bounds = device.getDefaultConfiguration().getBounds();
        if (bounds.contains(rect) || bounds.intersects(rect)) {
            return true;
        }
    }
    return false;
}

From source file:edu.ku.brc.specify.ui.containers.ContainerTreePanel.java

/**
 * @param e/*  w w  w  . j a va  2s  .c  o m*/
 */
private void mousePressedOnTree(final MouseEvent e) {
    Point pnt = e.getLocationOnScreen();

    int i = 0;
    for (Rectangle r : treeRenderer.getHitRects()) {
        //System.out.println(pnt+" "+r+" "+r.contains(pnt));
        if (r.contains(pnt)) {
            DefaultMutableTreeNode node = getSelectedTreeNode();
            if (node != null) {
                if (node.getUserObject() instanceof Container) {
                    Container cn = (Container) node.getUserObject();
                    if (cn != null) {
                        if (!isViewMode) // Edit Mode
                        {
                            if (cn.getCollectionObject() != null) {
                                if (i == 0) {
                                    editColObj(cn.getCollectionObject());
                                } else {
                                    delColObj();
                                }
                            } else {
                                if (i == 0) {
                                    addColObjToContainer(true, true);
                                } else {
                                    addColObjToContainer(false, true);
                                }
                            }
                        } else if (cn.getCollectionObject() != null && i == 0) {
                            viewColObj();
                        }
                    }
                } else if (node.getUserObject() instanceof CollectionObject) {
                    if (isViewMode) {
                        if (i == 0) {
                            viewColObj();
                        }
                    } else {
                        if (i == 0) {
                            editColObj();
                        }
                    }
                }
            }
            break;
        }
        i++;
    }
}

From source file:org.esa.snap.rcp.statistics.ScatterPlotPanel.java

private void compute(final Mask selectedMask) {

    final RasterDataNode raster = getRaster();

    final AttributeDescriptor dataField = scatterPlotModel.dataField;
    if (raster == null || dataField == null) {
        return;//from  w  w  w . ja v  a2s  . c om
    }

    SwingWorker<ComputedData[], Object> swingWorker = new SwingWorker<ComputedData[], Object>() {

        @Override
        protected ComputedData[] doInBackground() throws Exception {
            SystemUtils.LOG.finest("start computing scatter plot data");

            final List<ComputedData> computedDataList = new ArrayList<>();

            final FeatureCollection<SimpleFeatureType, SimpleFeature> collection = scatterPlotModel.pointDataSource
                    .getFeatureCollection();
            final SimpleFeature[] features = collection.toArray(new SimpleFeature[collection.size()]);

            final int boxSize = scatterPlotModel.boxSize;

            final Rectangle sceneRect = new Rectangle(raster.getRasterWidth(), raster.getRasterHeight());

            final GeoCoding geoCoding = raster.getGeoCoding();
            final AffineTransform imageToModelTransform;
            imageToModelTransform = Product.findImageToModelTransform(geoCoding);
            for (SimpleFeature feature : features) {
                final Point point = (Point) feature.getDefaultGeometryProperty().getValue();
                Point2D modelPos = new Point2D.Float((float) point.getX(), (float) point.getY());
                final Point2D imagePos = imageToModelTransform.inverseTransform(modelPos, null);

                if (!sceneRect.contains(imagePos)) {
                    continue;
                }
                final float imagePosX = (float) imagePos.getX();
                final float imagePosY = (float) imagePos.getY();
                final Rectangle imageRect = sceneRect.intersection(new Rectangle(
                        ((int) imagePosX) - boxSize / 2, ((int) imagePosY) - boxSize / 2, boxSize, boxSize));
                if (imageRect.isEmpty()) {
                    continue;
                }
                final double[] rasterValues = new double[imageRect.width * imageRect.height];
                raster.readPixels(imageRect.x, imageRect.y, imageRect.width, imageRect.height, rasterValues);

                final int[] maskBuffer = new int[imageRect.width * imageRect.height];
                Arrays.fill(maskBuffer, 1);
                if (selectedMask != null) {
                    selectedMask.readPixels(imageRect.x, imageRect.y, imageRect.width, imageRect.height,
                            maskBuffer);
                }

                final int centerIndex = imageRect.width * (imageRect.height / 2) + (imageRect.width / 2);
                if (maskBuffer[centerIndex] == 0) {
                    continue;
                }

                double sum = 0;
                double sumSqr = 0;
                int n = 0;
                boolean valid = false;

                for (int y = 0; y < imageRect.height; y++) {
                    for (int x = 0; x < imageRect.width; x++) {
                        final int index = y * imageRect.height + x;
                        if (raster.isPixelValid(x + imageRect.x, y + imageRect.y) && maskBuffer[index] != 0) {
                            final double rasterValue = rasterValues[index];
                            sum += rasterValue;
                            sumSqr += rasterValue * rasterValue;
                            n++;
                            valid = true;
                        }
                    }
                }

                if (!valid) {
                    continue;
                }

                double rasterMean = sum / n;
                double rasterSigma = n > 1 ? Math.sqrt((sumSqr - (sum * sum) / n) / (n - 1)) : 0.0;

                String localName = dataField.getLocalName();
                Number attribute = (Number) feature.getAttribute(localName);

                final Collection<org.opengis.feature.Property> featureProperties = feature.getProperties();

                final float correlativeData = attribute.floatValue();
                final GeoPos geoPos = new GeoPos();
                if (geoCoding.canGetGeoPos()) {
                    final PixelPos pixelPos = new PixelPos(imagePosX, imagePosY);
                    geoCoding.getGeoPos(pixelPos, geoPos);
                } else {
                    geoPos.setInvalid();
                }
                computedDataList.add(
                        new ComputedData(imagePosX, imagePosY, (float) geoPos.getLat(), (float) geoPos.getLon(),
                                (float) rasterMean, (float) rasterSigma, correlativeData, featureProperties));
            }

            return computedDataList.toArray(new ComputedData[computedDataList.size()]);
        }

        @Override
        public void done() {
            try {
                final ValueAxis xAxis = getPlot().getDomainAxis();
                final ValueAxis yAxis = getPlot().getRangeAxis();

                xAxis.setAutoRange(false);
                yAxis.setAutoRange(false);

                scatterpointsDataset.removeAllSeries();
                acceptableDeviationDataset.removeAllSeries();
                regressionDataset.removeAllSeries();
                getPlot().removeAnnotation(r2Annotation);
                computedDatas = null;

                final ComputedData[] data = get();
                if (data.length == 0) {
                    return;
                }

                computedDatas = data;

                final XYIntervalSeries scatterValues = new XYIntervalSeries(getCorrelativeDataName());
                for (ComputedData computedData : computedDatas) {
                    final float rasterMean = computedData.rasterMean;
                    final float rasterSigma = computedData.rasterSigma;
                    final float correlativeData = computedData.correlativeData;
                    scatterValues.add(correlativeData, correlativeData, correlativeData, rasterMean,
                            rasterMean - rasterSigma, rasterMean + rasterSigma);
                }

                computingData = true;
                scatterpointsDataset.addSeries(scatterValues);

                xAxis.setAutoRange(true);
                yAxis.setAutoRange(true);

                xAxis.setAutoRange(false);
                yAxis.setAutoRange(false);

                xAutoRangeAxisRange = new Range(xAxis.getLowerBound(), xAxis.getUpperBound());
                yAutoRangeAxisRange = new Range(yAxis.getLowerBound(), yAxis.getUpperBound());

                if (xAxisRangeControl.isAutoMinMax()) {
                    xAxisRangeControl.adjustComponents(xAxis, 3);
                } else {
                    xAxisRangeControl.adjustAxis(xAxis, 3);
                }
                if (yAxisRangeControl.isAutoMinMax()) {
                    yAxisRangeControl.adjustComponents(yAxis, 3);
                } else {
                    yAxisRangeControl.adjustAxis(yAxis, 3);
                }

                computeRegressionAndAcceptableDeviationData();
                computingData = false;
            } catch (InterruptedException | CancellationException e) {
                SystemUtils.LOG.log(Level.WARNING, "Failed to compute correlative plot.", e);
                Dialogs.showMessage(CHART_TITLE,
                        "Failed to compute correlative plot.\n" + "Calculation canceled.",
                        JOptionPane.ERROR_MESSAGE, null);
            } catch (ExecutionException e) {
                SystemUtils.LOG.log(Level.WARNING, "Failed to compute correlative plot.", e);
                Dialogs.showMessage(CHART_TITLE, "Failed to compute correlative plot.\n"
                        + "An error occurred:\n" + e.getCause().getMessage(), JOptionPane.ERROR_MESSAGE, null);
            }
        }
    };
    swingWorker.execute();
}

From source file:pcgen.gui2.PCGenFrame.java

private void initSettings() {
    final UIPropertyContext frameContext = UIPropertyContext.createContext("PCGenFrame");

    Rectangle screenBounds = getGraphicsConfiguration().getBounds();

    setSize(1060, 725); //this is the default frame dimensions
    setLocationRelativeTo(null); //center the frame
    if (!screenBounds.contains(getBounds())) {
        setSize((5 * screenBounds.width) / 6, (5 * screenBounds.height) / 6);
        setLocationRelativeTo(null); //center the frame
    }//  w  w w  .  j  av  a  2 s . c  o m
    Rectangle frameBounds = getBounds();
    frameBounds.x = frameContext.initInt("bounds.x", frameBounds.x);
    frameBounds.y = frameContext.initInt("bounds.y", frameBounds.x);
    frameBounds.width = frameContext.initInt("bounds.width", frameBounds.width);
    frameBounds.height = frameContext.initInt("bounds.height", frameBounds.height);

    int extendedState = frameContext.initInt("extendedState", NORMAL);
    if (extendedState == ICONIFIED) {
        extendedState = NORMAL;
        frameContext.setInt("extendedState", NORMAL);
    }
    setExtendedState(extendedState);
    if (checkBounds(frameBounds)) {
        setBounds(frameBounds);
    }
    addPropertyChangeListener("extendedState", frameContext);
    addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            updateBounds();
        }

        @Override
        public void componentMoved(ComponentEvent e) {
            updateBounds();
        }

        private void updateBounds() {
            Rectangle bounds = getBounds();
            frameContext.setInt("bounds.x", bounds.x);
            frameContext.setInt("bounds.y", bounds.y);
            frameContext.setInt("bounds.width", bounds.width);
            frameContext.setInt("bounds.height", bounds.height);
        }

    });
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            PCGenUIManager.closePCGen();
        }

    });
}

From source file:org.esa.beam.visat.toolviews.stat.ScatterPlotPanel.java

private void compute(final Mask selectedMask) {

    final RasterDataNode raster = getRaster();

    final AttributeDescriptor dataField = scatterPlotModel.dataField;
    if (raster == null || dataField == null) {
        return;/*from  w  ww. jav a2 s  .c  o  m*/
    }

    SwingWorker<ComputedData[], Object> swingWorker = new SwingWorker<ComputedData[], Object>() {

        @Override
        protected ComputedData[] doInBackground() throws Exception {
            BeamLogManager.getSystemLogger().finest("start computing scatter plot data");

            final List<ComputedData> computedDataList = new ArrayList<>();

            final FeatureCollection<SimpleFeatureType, SimpleFeature> collection = scatterPlotModel.pointDataSource
                    .getFeatureCollection();
            final SimpleFeature[] features = collection.toArray(new SimpleFeature[collection.size()]);

            final int boxSize = scatterPlotModel.boxSize;

            final Rectangle sceneRect = new Rectangle(raster.getSceneRasterWidth(),
                    raster.getSceneRasterHeight());

            final GeoCoding geoCoding = raster.getGeoCoding();
            final AffineTransform imageToModelTransform;
            imageToModelTransform = ImageManager.getImageToModelTransform(geoCoding);
            for (SimpleFeature feature : features) {
                final Point point = (Point) feature.getDefaultGeometryProperty().getValue();
                Point2D modelPos = new Point2D.Float((float) point.getX(), (float) point.getY());
                final Point2D imagePos = imageToModelTransform.inverseTransform(modelPos, null);

                if (!sceneRect.contains(imagePos)) {
                    continue;
                }
                final float imagePosX = (float) imagePos.getX();
                final float imagePosY = (float) imagePos.getY();
                final Rectangle imageRect = sceneRect.intersection(new Rectangle(
                        ((int) imagePosX) - boxSize / 2, ((int) imagePosY) - boxSize / 2, boxSize, boxSize));
                if (imageRect.isEmpty()) {
                    continue;
                }
                final double[] rasterValues = new double[imageRect.width * imageRect.height];
                raster.readPixels(imageRect.x, imageRect.y, imageRect.width, imageRect.height, rasterValues);

                final int[] maskBuffer = new int[imageRect.width * imageRect.height];
                Arrays.fill(maskBuffer, 1);
                if (selectedMask != null) {
                    selectedMask.readPixels(imageRect.x, imageRect.y, imageRect.width, imageRect.height,
                            maskBuffer);
                }

                final int centerIndex = imageRect.width * (imageRect.height / 2) + (imageRect.width / 2);
                if (maskBuffer[centerIndex] == 0) {
                    continue;
                }

                double sum = 0;
                double sumSqr = 0;
                int n = 0;
                boolean valid = false;

                for (int y = 0; y < imageRect.height; y++) {
                    for (int x = 0; x < imageRect.width; x++) {
                        final int index = y * imageRect.height + x;
                        if (raster.isPixelValid(x + imageRect.x, y + imageRect.y) && maskBuffer[index] != 0) {
                            final double rasterValue = rasterValues[index];
                            sum += rasterValue;
                            sumSqr += rasterValue * rasterValue;
                            n++;
                            valid = true;
                        }
                    }
                }

                if (!valid) {
                    continue;
                }

                double rasterMean = sum / n;
                double rasterSigma = n > 1 ? Math.sqrt((sumSqr - (sum * sum) / n) / (n - 1)) : 0.0;

                String localName = dataField.getLocalName();
                Number attribute = (Number) feature.getAttribute(localName);

                final Collection<org.opengis.feature.Property> featureProperties = feature.getProperties();

                final float correlativeData = attribute.floatValue();
                final GeoPos geoPos = new GeoPos();
                if (geoCoding.canGetGeoPos()) {
                    final PixelPos pixelPos = new PixelPos(imagePosX, imagePosY);
                    geoCoding.getGeoPos(pixelPos, geoPos);
                } else {
                    geoPos.setInvalid();
                }
                computedDataList.add(new ComputedData(imagePosX, imagePosY, geoPos.getLat(), geoPos.getLon(),
                        (float) rasterMean, (float) rasterSigma, correlativeData, featureProperties));
            }

            return computedDataList.toArray(new ComputedData[computedDataList.size()]);
        }

        @Override
        public void done() {
            try {
                final ValueAxis xAxis = getPlot().getDomainAxis();
                final ValueAxis yAxis = getPlot().getRangeAxis();

                xAxis.setAutoRange(false);
                yAxis.setAutoRange(false);

                scatterpointsDataset.removeAllSeries();
                acceptableDeviationDataset.removeAllSeries();
                regressionDataset.removeAllSeries();
                getPlot().removeAnnotation(r2Annotation);
                computedDatas = null;

                final ComputedData[] data = get();
                if (data.length == 0) {
                    return;
                }

                computedDatas = data;

                final XYIntervalSeries scatterValues = new XYIntervalSeries(getCorrelativeDataName());
                for (ComputedData computedData : computedDatas) {
                    final float rasterMean = computedData.rasterMean;
                    final float rasterSigma = computedData.rasterSigma;
                    final float correlativeData = computedData.correlativeData;
                    scatterValues.add(correlativeData, correlativeData, correlativeData, rasterMean,
                            rasterMean - rasterSigma, rasterMean + rasterSigma);
                }

                computingData = true;
                scatterpointsDataset.addSeries(scatterValues);

                xAxis.setAutoRange(true);
                yAxis.setAutoRange(true);

                xAxis.setAutoRange(false);
                yAxis.setAutoRange(false);

                xAutoRangeAxisRange = new Range(xAxis.getLowerBound(), xAxis.getUpperBound());
                yAutoRangeAxisRange = new Range(yAxis.getLowerBound(), yAxis.getUpperBound());

                if (xAxisRangeControl.isAutoMinMax()) {
                    xAxisRangeControl.adjustComponents(xAxis, 3);
                } else {
                    xAxisRangeControl.adjustAxis(xAxis, 3);
                }
                if (yAxisRangeControl.isAutoMinMax()) {
                    yAxisRangeControl.adjustComponents(yAxis, 3);
                } else {
                    yAxisRangeControl.adjustAxis(yAxis, 3);
                }

                computeRegressionAndAcceptableDeviationData();
                computingData = false;
            } catch (InterruptedException | CancellationException e) {
                BeamLogManager.getSystemLogger().log(Level.WARNING, "Failed to compute correlative plot.", e);
                JOptionPane.showMessageDialog(getParentDialogContentPane(),
                        "Failed to compute correlative plot.\n" + "Calculation canceled.",
                        /*I18N*/
                        CHART_TITLE, /*I18N*/
                        JOptionPane.ERROR_MESSAGE);
            } catch (ExecutionException e) {
                BeamLogManager.getSystemLogger().log(Level.WARNING, "Failed to compute correlative plot.", e);
                JOptionPane.showMessageDialog(getParentDialogContentPane(),
                        "Failed to compute correlative plot.\n" + "An error occurred:\n"
                                + e.getCause().getMessage(),
                        CHART_TITLE, /*I18N*/
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    };
    swingWorker.execute();
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java

/**
 * Handles the mouse moved event. Displays the properties of the
 * the nodes the mouse is over.//from  w  w w . j  a  v  a2 s.c  o  m
 * 
 * @param e   The mouse event to handle.
 */
private void rollOver(MouseEvent e) {
    if (!model.getParentModel().isRollOver())
        return;
    JTree tree = treeDisplay;
    TreePath path = treeDisplay.getClosestPathForLocation(e.getX(), e.getY());
    Rectangle bounds = tree.getPathBounds(path);
    if (!bounds.contains(e.getPoint()))
        return;
    TreeImageDisplay node = (TreeImageDisplay) path.getLastPathComponent();
    Object uo = node.getUserObject();
    if (!(uo instanceof DataObject))
        return;
}

From source file:ded.ui.DiagramController.java

/** Find EntityControllers fully contained in a rectangle. */
public IdentityHashSet<EntityController> findEntityControllersInRectangle(Rectangle rect) {
    IdentityHashSet<EntityController> ret = new IdentityHashSet<EntityController>();
    for (Controller c : this.controllers) {
        if (c instanceof EntityController) {
            EntityController ec = (EntityController) c;
            if (rect.contains(ec.getRect())) {
                ret.add(ec);//from   www . ja v  a  2s .  c om
            }
        }
    }
    return ret;
}

From source file:org.geotools.gce.imagemosaic.RasterLayerResponse.java

/**
 * Once we reach this method it means that we have loaded all the images
 * which were intersecting the requested envelope. Next step is to create
 * the final mosaic image and cropping it to the exact requested envelope.
 * @param visitor /* w  w w . ja  v a2  s.  c o m*/
 * 
 * @return A {@link RenderedImage}}.
 */
private RenderedImage buildMosaic(final MosaicBuilder visitor) throws IOException {

    // build final layout and use it for cropping purposes
    final ImageLayout layout = new ImageLayout(rasterBounds.x, rasterBounds.y, rasterBounds.width,
            rasterBounds.height);

    //prepare hints
    final Dimension tileDimensions = request.getTileDimensions();
    if (tileDimensions != null) {
        layout.setTileHeight(tileDimensions.width).setTileWidth(tileDimensions.height);
    }
    final RenderingHints localHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout);
    if (hints != null && !hints.isEmpty()) {
        if (hints.containsKey(JAI.KEY_TILE_CACHE)) {
            final Object tc = hints.get(JAI.KEY_TILE_CACHE);
            if (tc != null && tc instanceof TileCache)
                localHints.add(new RenderingHints(JAI.KEY_TILE_CACHE, (TileCache) tc));
        }
        boolean addBorderExtender = true;
        if (hints != null && hints.containsKey(JAI.KEY_BORDER_EXTENDER)) {
            final Object extender = hints.get(JAI.KEY_BORDER_EXTENDER);
            if (extender != null && extender instanceof BorderExtender) {
                localHints.add(new RenderingHints(JAI.KEY_BORDER_EXTENDER, (BorderExtender) extender));
                addBorderExtender = false;
            }
        }
        if (addBorderExtender) {
            localHints.add(ImageUtilities.BORDER_EXTENDER_HINTS);
        }
        if (hints.containsKey(JAI.KEY_TILE_SCHEDULER)) {
            final Object ts = hints.get(JAI.KEY_TILE_SCHEDULER);
            if (ts != null && ts instanceof TileScheduler)
                localHints.add(new RenderingHints(JAI.KEY_TILE_SCHEDULER, (TileScheduler) ts));
        }
    }

    //
    // SPECIAL CASE
    // 1 single tile, we try not do a mosaic.
    final ROI[] sourceRoi = visitor.sourceRoi;
    if (visitor.granulesNumber == 1 && Utils.OPTIMIZE_CROP) {
        // the roi is exactly equal to the 
        final ROI roi = visitor.rois.get(0);
        Rectangle bounds = Utils.toRectangle(roi.getAsShape());
        if (bounds != null) {
            RenderedImage image = visitor.getSourcesAsArray()[0];
            Rectangle imageBounds = PlanarImage.wrapRenderedImage(image).getBounds();
            if (imageBounds.equals(bounds)) {

                // do we need to crop? (image is bigger than requested?)
                if (!rasterBounds.contains(imageBounds)) {
                    // we have to crop
                    XRectangle2D.intersect(imageBounds, rasterBounds, imageBounds);

                    if (imageBounds.isEmpty()) {
                        // return back a constant image
                        return null;
                    }
                    // crop
                    ImageWorker iw = new ImageWorker(image);
                    iw.setRenderingHints(localHints);
                    iw.crop(imageBounds.x, imageBounds.y, imageBounds.width, imageBounds.height);

                    image = iw.getRenderedImage();
                    imageBounds = PlanarImage.wrapRenderedImage(image).getBounds();
                }

                // and, do we need to add a border around the image?
                if (!imageBounds.contains(rasterBounds)) {
                    image = MosaicDescriptor.create(new RenderedImage[] { image },
                            request.isBlend() ? MosaicDescriptor.MOSAIC_TYPE_BLEND
                                    : MosaicDescriptor.MOSAIC_TYPE_OVERLAY,
                            (alphaIn || visitor.doInputTransparency) ? visitor.alphaChannels : null, sourceRoi,
                            visitor.sourceThreshold, backgroundValues, localHints);
                }

                return image;
            }
        }
    }

    // 
    // Final Merge
    // 
    // I can even do a stacking merge or a flat merge
    final RenderedImage mosaic = request.getMergeBehavior().process(visitor.getSourcesAsArray(),
            backgroundValues, visitor.sourceThreshold,
            (alphaIn || visitor.doInputTransparency) ? visitor.alphaChannels : null, sourceRoi,
            request.isBlend() ? MosaicDescriptor.MOSAIC_TYPE_BLEND : MosaicDescriptor.MOSAIC_TYPE_OVERLAY,
            localHints);

    if (setRoiProperty) {

        //Adding globalRoi to the output
        RenderedOp rop = (RenderedOp) mosaic;
        ROI globalRoi = null;
        ROI[] rois = sourceRoi;
        for (int i = 0; i < rois.length; i++) {
            if (globalRoi == null) {
                globalRoi = new ROIGeometry(((ROIGeometry) rois[i]).getAsGeometry());
            } else {
                globalRoi = globalRoi.add(rois[i]);
            }
        }
        rop.setProperty("ROI", globalRoi);
    }

    if (LOGGER.isLoggable(Level.FINE))
        LOGGER.fine("Mosaic created ");

    // create the coverage
    return mosaic;

}