Example usage for java.awt Rectangle isEmpty

List of usage examples for java.awt Rectangle isEmpty

Introduction

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

Prototype

public boolean isEmpty() 

Source Link

Usage

From source file:Main.java

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

    Rectangle r = new Rectangle(10, 10);

    g2.fill(r);//from   ww  w. j av a 2 s  .  c  om
    System.out.println(r.isEmpty());
}

From source file:Main.java

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

    Rectangle r = new Rectangle(new Dimension(10, 10));

    g2.fill(r);//from   w ww .  j  ava  2  s.  c  om
    System.out.println(r.isEmpty());
}

From source file:Main.java

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

    Rectangle r = new Rectangle(new Point(10, 10));

    r.setSize(30, 30);/*from  w ww. j a  v a 2  s .  c  om*/

    g2.fill(r);

    System.out.println(r.isEmpty());
}

From source file:Main.java

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

    Rectangle r = new Rectangle();

    r.setLocation(new Point(20, 20));
    r.setSize(new Dimension(10, 10));

    g2.fill(r);/* ww  w .j a v  a  2  s . c  om*/
    System.out.println(r.isEmpty());

}

From source file:at.knowcenter.wag.egov.egiz.pdf.PDFPage.java

/**
 * Registers a rectangle that bounds the path currently being drawn.
 * // w w  w .  j  av  a  2s.  c  o m
 * @param bounds
 *            A rectangle depicting the bounds (coordinates originating from
 *            bottom left).
 * @author Datentechnik Innovation GmbH
 */
public void registerPathBounds(Rectangle bounds) {
    if (!bounds.isEmpty()) {
        logger.debug("Registering path bounds: " + bounds);

        // vertical start of rectangle (counting from top of page)
        float upperBoundYPositionFromTop;

        // vertical end of rectangle (counting from top of page)
        // this depicts the current end of path-related page content
        float lowerBoundYPositionFromTop;

        PDRectangle boundaryBox = this.getCurrentPage().findCropBox();

        if (boundaryBox == null) {
            boundaryBox = this.getCurrentPage().findMediaBox();
        }

        float pageHeight;

        switch (this.getCurrentPage().findRotation()) {
        case 90: // CW
            pageHeight = boundaryBox.getWidth();
            upperBoundYPositionFromTop = (float) bounds.getMinX();
            lowerBoundYPositionFromTop = (float) bounds.getMaxX();
            break;
        case 180:
            pageHeight = boundaryBox.getHeight();
            upperBoundYPositionFromTop = (float) bounds.getMinY();
            lowerBoundYPositionFromTop = (float) bounds.getMaxY();
            break;
        case 270: // CCW
            pageHeight = boundaryBox.getWidth();
            upperBoundYPositionFromTop = pageHeight - (float) bounds.getMaxX();
            lowerBoundYPositionFromTop = pageHeight - (float) bounds.getMinX();
            break;
        default:
            pageHeight = boundaryBox.getHeight();
            upperBoundYPositionFromTop = pageHeight - (float) bounds.getMaxY();
            lowerBoundYPositionFromTop = pageHeight - (float) bounds.getMinY();
            break;
        }

        // new maximum ?
        if (lowerBoundYPositionFromTop > maxPathRelatedYPositionFromTop) {
            // Is the rectangle (at least partly) located above the footer
            // line?
            // (effective page height := page height - footer line)
            if (upperBoundYPositionFromTop <= effectivePageHeight) {
                // yes: update current end of path-related page content
                maxPathRelatedYPositionFromTop = lowerBoundYPositionFromTop;
                logger.trace("New max path related y position (from top): " + maxPathRelatedYPositionFromTop);
            } else {
                // no: rectangle is fully located below the footer line ->
                // ignore
                logger.trace("Ignoring path bound below the footer line.");
            }
        }
    }
}

From source file:at.knowcenter.wag.egov.egiz.pdfbox2.pdf.PDFPage.java

/**
 * Registers a rectangle that bounds the path currently being drawn.
 * /*from   ww  w  . j a v a 2  s  . com*/
 * @param bounds
 *            A rectangle depicting the bounds (coordinates originating from
 *            bottom left).
 * @author Datentechnik Innovation GmbH
 */
public void registerPathBounds(Rectangle bounds) {
    if (!bounds.isEmpty()) {
        logger.debug("Registering path bounds: " + bounds);

        // vertical start of rectangle (counting from top of page)
        float upperBoundYPositionFromTop;

        // vertical end of rectangle (counting from top of page)
        // this depicts the current end of path-related page content
        float lowerBoundYPositionFromTop;

        PDRectangle boundaryBox = this.getCurrentPage().getCropBox();

        if (boundaryBox == null) {
            boundaryBox = this.getCurrentPage().getMediaBox();
        }

        float pageHeight;

        switch (this.getCurrentPage().getRotation()) {
        case 90: // CW
            pageHeight = boundaryBox.getWidth();
            upperBoundYPositionFromTop = (float) bounds.getMinX();
            lowerBoundYPositionFromTop = (float) bounds.getMaxX();
            break;
        case 180:
            pageHeight = boundaryBox.getHeight();
            upperBoundYPositionFromTop = (float) bounds.getMinY();
            lowerBoundYPositionFromTop = (float) bounds.getMaxY();
            break;
        case 270: // CCW
            pageHeight = boundaryBox.getWidth();
            upperBoundYPositionFromTop = pageHeight - (float) bounds.getMaxX();
            lowerBoundYPositionFromTop = pageHeight - (float) bounds.getMinX();
            break;
        default:
            pageHeight = boundaryBox.getHeight();
            upperBoundYPositionFromTop = pageHeight - (float) bounds.getMaxY();
            lowerBoundYPositionFromTop = pageHeight - (float) bounds.getMinY();
            break;
        }

        // new maximum ?
        if (lowerBoundYPositionFromTop > maxPathRelatedYPositionFromTop) {
            // Is the rectangle (at least partly) located above the footer
            // line?
            // (effective page height := page height - footer line)
            if (upperBoundYPositionFromTop <= effectivePageHeight) {
                // yes: update current end of path-related page content
                maxPathRelatedYPositionFromTop = lowerBoundYPositionFromTop;
                logger.trace("New max path related y position (from top): " + maxPathRelatedYPositionFromTop);
            } else {
                // no: rectangle is fully located below the footer line ->
                // ignore
                logger.trace("Ignoring path bound below the footer line.");
            }
        }
    }
}

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  ww w  .j  ava2 s.  c o m*/
    }

    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: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;// w ww.  j av  a 2s.c om
    }

    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.esa.nest.dat.views.polarview.PolarCanvas.java

private static void paintComponents(Container c, Graphics g) {
    if (!c.isShowing())
        return;/*  w ww . j  a v a2  s .co  m*/

    final int ncomponents = c.getComponentCount();
    final Rectangle clip = g.getClipBounds();

    int i = ncomponents - 1;
    while (i >= 0) {
        final Component component[] = c.getComponents();
        final Component comp = component[i];
        if (comp == null || !comp.isVisible())
            continue;
        final Rectangle bounds = comp.getBounds();
        Rectangle cr;
        if (clip == null)
            cr = new Rectangle(bounds);
        else
            cr = bounds.intersection(clip);
        if (cr.isEmpty())
            continue;

        final Graphics cg = g.create();
        cg.setClip(cr);
        cg.translate(bounds.x, bounds.y);
        try {
            comp.paint(cg);
        } catch (Throwable e) {
            //
        }

        cg.dispose();
        i--;
    }
}

From source file:org.esa.s2tbx.dataio.jp2.internal.JP2TileOpImage.java

private void computeRectIndirect(WritableRaster dest, Rectangle destRect) {
    try {/* w  ww  .  j av a2s.  c om*/
        Path tile = decompressTile(tileIndex, getLevel());
        RenderedImage readTileImage = null;
        if (tile != null) {
            try (ImageReader imageReader = new ImageReader(tile)) {
                final DataBuffer dataBuffer = dest.getDataBuffer();
                int tileWidth = this.getTileWidth();
                int tileHeight = this.getTileHeight();
                final int fileTileX = destRect.x / tileLayout.tileWidth;
                final int fileTileY = destRect.y / tileLayout.tileHeight;
                int fileTileOriginX = destRect.x - fileTileX * tileLayout.tileWidth;
                int fileTileOriginY = destRect.y - fileTileY * tileLayout.tileHeight;
                Rectangle fileTileRect = tileDims.get(tile);
                if (fileTileRect == null) {
                    fileTileRect = new Rectangle(0, 0, imageReader.getImageWidth(),
                            imageReader.getImageHeight());
                    tileDims.put(tile, fileTileRect);
                }
                if (fileTileOriginX == 0 && tileLayout.tileWidth == tileWidth && fileTileOriginY == 0
                        && tileLayout.tileHeight == tileHeight
                        && tileWidth * tileHeight == dataBuffer.getSize()) {
                    readTileImage = imageReader.read();
                } else {
                    final Rectangle tileRect = new Rectangle(fileTileOriginX, fileTileOriginY, tileWidth,
                            tileHeight);
                    final Rectangle intersection = fileTileRect.intersection(tileRect);
                    if (!intersection.isEmpty()) {
                        readTileImage = imageReader.read(intersection);
                    }
                }
                if (readTileImage != null) {
                    Raster readBandRaster = readTileImage.getData().createChild(0, 0, readTileImage.getWidth(),
                            readTileImage.getHeight(), 0, 0, new int[] { bandIndex });
                    dest.setDataElements(dest.getMinX(), dest.getMinY(), readBandRaster);
                }
            } catch (IOException e) {
                logger.severe(e.getMessage());
            }
        }
    } catch (IOException e) {
        logger.severe(e.getMessage());
    }
}