Example usage for java.awt.geom Rectangle2D getWidth

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

Introduction

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

Prototype

public abstract double getWidth();

Source Link

Document

Returns the width of the framing rectangle in double precision.

Usage

From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java

/**
 * A recursive version of//w  w w .j av  a2s  .c  o m
 * {@link #calculateMaximalNodeDimension(VisualTreeNode, FontRenderContext)}
 * @param maximalNodeDimension
 *          the biggest width and height
 * @param treeLayout
 *          the tree layout
 * @param frc
 *          the {@link FontRenderContext}
 */
private void calculateMaximalNodeDimensionRecursive(Dimension2DDouble maximalNodeDimension,
        VisualTreeNode treeLayout, FontRenderContext frc) {
    Shape textShape = this.getLabelShape(treeLayout, frc);
    Shape borderShape = this.getLabelBorder(textShape);
    Rectangle2D borderBounds = borderShape.getBounds2D();

    if (borderBounds.getWidth() > maximalNodeDimension.getWidth()) {
        maximalNodeDimension.setWidth(borderBounds.getWidth());
    }

    if (borderBounds.getHeight() > maximalNodeDimension.getHeight()) {
        maximalNodeDimension.setHeight(borderBounds.getHeight());
    }

    for (VisualTreeNode childNode : treeLayout.getChildNodes()) {
        this.calculateMaximalNodeDimensionRecursive(maximalNodeDimension, childNode, frc);
    }
}

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

/**
 * @param x/* w ww.  jav  a  2  s .  c o  m*/
 * @param y
 * @param w
 * @param h
 * @return
 */
private SubImage getSubimageWithPartialRendering(Rectangle2D rect, int imageType) {
    double pageHeight = getPage().getHeight();
    // Area in pixels according to preferred resolution
    Point upperLeft = toPixels(rect.getX(), rect.getY());

    Rectangle imageBBox = this.toPixels(rect); // subImage Bounding Box in pixels      
    Rectangle2D pdfAreaBBox = toPDFUnits(imageBBox); // subImage Bounding Box in PDF units

    Rectangle imageSize = new Rectangle(imageBBox.width, imageBBox.height); // subImage Size in pixels

    Rectangle2D clippingArea = new Rectangle(); // area of interest in the PDF
    clippingArea.setFrame(pdfAreaBBox.getX(), pageHeight - pdfAreaBBox.getY() - pdfAreaBBox.getHeight(), //PDF-Page coordinate space counts from bottomleft
            pdfAreaBBox.getWidth(), pdfAreaBBox.getHeight());

    SubImage img_pdf = new SubImage(imageSize.width, imageSize.height, imageType);
    // se configura la imagen con las medidas necesarias

    Graphics2D g2 = img_pdf.createGraphics(); // se crea un objeto grfico en dos dimensiones
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); // prefer to get sharp edges

    PDFRenderer renderer = new PDFRenderer(getPage(), g2, imageSize, clippingArea, Color.RED); // se renderiza la imgen 
    try {
        getPage().waitForFinish();
    } catch (InterruptedException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    renderer.run();

    img_pdf.setReference(upperLeft);
    img_pdf.setBoundingBox(imageBBox);

    return img_pdf;
}

From source file:com.rapidminer.gui.plotter.charts.ChartPanelShiftController.java

@Override
public void mouseDragged(MouseEvent mouseEvent) {
    if (!mouseEvent.isControlDown()) {
        return;//from  w w  w .  j  av  a 2 s  . c o m
    }

    if (oldx > -1 && oldy > -1) {
        int xdif = mouseEvent.getX() - oldx;
        int ydif = mouseEvent.getY() - oldy;

        final Rectangle2D scaledDataArea = chartPanel.getScreenDataArea();

        ValueAxis[] domAxes = getPlotAxis(chartPanel.getChart(), !axesSwaped);
        if (domAxes != null) {
            double[] xDelta = new double[domAxes.length];
            for (int i = 0; i < domAxes.length; i++) {
                xDelta[i] = xdif * domAxes[i].getRange().getLength() / (scaledDataArea.getWidth());
            }
            for (int i = 0; i < domAxes.length; i++) {
                domAxes[i].setRange(domAxes[i].getLowerBound() - xDelta[i],
                        domAxes[i].getUpperBound() - xDelta[i]);
            }
        }

        ValueAxis[] rngAxes = getPlotAxis(chartPanel.getChart(), axesSwaped);
        if (rngAxes != null) {
            double[] yDelta = new double[rngAxes.length];
            for (int i = 0; i < rngAxes.length; i++) {
                yDelta[i] = ydif * rngAxes[i].getRange().getLength() / (scaledDataArea.getHeight());
            }
            if (!onlyXShift) {
                for (int i = 0; i < rngAxes.length; i++) {
                    rngAxes[i].setRange(rngAxes[i].getLowerBound() + yDelta[i],
                            rngAxes[i].getUpperBound() + yDelta[i]);
                }
            }
        }
    }

    oldx = mouseEvent.getX();
    oldy = mouseEvent.getY();
}

From source file:fr.amap.commons.javafx.chart.ChartViewer.java

/**
 * A handler for the export to JPEG option in the context menu.
 *//*from  ww w.java  2 s  .c  om*/
private void handleExportToJPEG() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export to JPEG");
    fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("JPEG", "jpg"));
    File file = fileChooser.showSaveDialog(stage);
    if (file != null) {
        try {
            CanvasPositionsAndSize canvasPositionAndSize = getCanvasPositionAndSize();

            BufferedImage image = new BufferedImage((int) canvasPositionAndSize.totalWidth,
                    (int) canvasPositionAndSize.totalHeight, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2 = image.createGraphics();

            int index = 0;
            for (ChartCanvas canvas : chartCanvasList) {

                Rectangle2D rectangle2D = canvasPositionAndSize.positionsAndSizes.get(index);

                ((Drawable) canvas.chart).draw(g2, new Rectangle((int) rectangle2D.getX(),
                        (int) rectangle2D.getY(), (int) rectangle2D.getWidth(), (int) rectangle2D.getHeight()));
                index++;
            }

            try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) {
                ImageIO.write(image, "jpg", out);
            }

            /*ExportUtils.writeAsJPEG(chartCanvasList.get(0).chart, (int)chartCanvasList.get(0).getWidth(),
                (int)chartCanvasList.get(0).getHeight(), file);*/
        } catch (IOException ex) {
            // FIXME: show a dialog with the error
        }
    }
}

From source file:fr.amap.commons.javafx.chart.ChartViewer.java

/**
 * A handler for the export to PNG option in the context menu.
 *//*from  w  w w  .  j  a v  a  2  s  .co  m*/
private void handleExportToPNG() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export to PNG");
    fileChooser.setSelectedExtensionFilter(
            new FileChooser.ExtensionFilter("Portable Network Graphics (PNG)", "png"));
    File file = fileChooser.showSaveDialog(stage);

    if (file != null) {
        try {

            CanvasPositionsAndSize canvasPositionAndSize = getCanvasPositionAndSize();

            BufferedImage image = new BufferedImage((int) canvasPositionAndSize.totalWidth,
                    (int) canvasPositionAndSize.totalHeight, BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2 = image.createGraphics();

            int index = 0;
            for (ChartCanvas canvas : chartCanvasList) {

                Rectangle2D rectangle2D = canvasPositionAndSize.positionsAndSizes.get(index);

                ((Drawable) canvas.chart).draw(g2, new Rectangle((int) rectangle2D.getX(),
                        (int) rectangle2D.getY(), (int) rectangle2D.getWidth(), (int) rectangle2D.getHeight()));
                index++;
            }

            try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) {
                ImageIO.write(image, "png", out);
            }

        } catch (IOException ex) {
            // FIXME: show a dialog with the error
        }
    }
}

From source file:com.bdaum.zoom.report.internal.jfree.custom.CylinderRenderer.java

/**
 * Draws a cylinder to represent one data item.
 *
 * @param g2  the graphics device./*from  w  ww. ja  v  a  2 s .c o m*/
 * @param state  the renderer state.
 * @param dataArea  the area for plotting the data.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // check the value we are plotting...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    double value = dataValue.doubleValue();

    Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(),
            dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());

    PlotOrientation orientation = plot.getOrientation();

    double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column);
    double[] barL0L1 = calculateBarL0L1(value);
    if (barL0L1 == null) {
        return; // the bar is not visible
    }

    RectangleEdge edge = plot.getRangeAxisEdge();
    float transL0 = (float) rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge);
    float transL1 = (float) rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge);
    float barL0 = Math.min(transL0, transL1);
    float barLength = Math.abs(transL1 - transL0);

    // draw the bar...
    GeneralPath bar = new GeneralPath();
    Shape top = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar.moveTo((float) (barL0 + getXOffset() / 2), (float) barW0);
        bar.lineTo((float) (barL0 + barLength + getXOffset() / 2), (float) barW0);
        Arc2D arc = new Arc2D.Double(barL0 + barLength, barW0, getXOffset(), state.getBarWidth(), 90, 180,
                Arc2D.OPEN);
        bar.append(arc, true);
        bar.lineTo((float) (barL0 + getXOffset() / 2), (float) (barW0 + state.getBarWidth()));
        arc = new Arc2D.Double(barL0, barW0, getXOffset(), state.getBarWidth(), 270, -180, Arc2D.OPEN);
        bar.append(arc, true);
        bar.closePath();
        top = new Ellipse2D.Double(barL0 + barLength, barW0, getXOffset(), state.getBarWidth());

    } else {
        bar.moveTo((float) barW0, (float) (barL0 - getYOffset() / 2));
        bar.lineTo((float) barW0, (float) (barL0 + barLength - getYOffset() / 2));
        Arc2D arc = new Arc2D.Double(barW0, (barL0 + barLength - getYOffset()), state.getBarWidth(),
                getYOffset(), 180, 180, Arc2D.OPEN);
        bar.append(arc, true);
        bar.lineTo((float) (barW0 + state.getBarWidth()), (float) (barL0 - getYOffset() / 2));
        arc = new Arc2D.Double(barW0, (barL0 - getYOffset()), state.getBarWidth(), getYOffset(), 0, -180,
                Arc2D.OPEN);
        bar.append(arc, true);
        bar.closePath();

        top = new Ellipse2D.Double(barW0, barL0 - getYOffset(), state.getBarWidth(), getYOffset());
    }
    Paint itemPaint = getItemPaint(row, column);
    if (getGradientPaintTransformer() != null && itemPaint instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) itemPaint;
        itemPaint = getGradientPaintTransformer().transform(gp, bar);
    }
    g2.setPaint(itemPaint);
    g2.fill(bar);

    if (itemPaint instanceof GradientPaint) {
        g2.setPaint(((GradientPaint) itemPaint).getColor2());
    } else {
        g2.setPaint(PaintAlpha.darker(itemPaint)); // bd
    }
    if (top != null) {
        g2.fill(top);
    }

    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemOutlineStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
        if (top != null) {
            g2.draw(top);
        }
    }

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar.getBounds2D(), (value < 0.0));
    }

    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            String tip = null;
            CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
            if (tipster != null) {
                tip = tipster.generateToolTip(dataset, row, column);
            }
            String url = null;
            if (getItemURLGenerator(row, column) != null) {
                url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
            }
            CategoryItemEntity entity = new CategoryItemEntity(bar.getBounds2D(), tip, url, dataset,
                    dataset.getRowKey(row), dataset.getColumnKey(column));
            entities.add(entity);
        }
    }

}

From source file:com.appnativa.rare.ui.chart.jfreechart.XYPlotEx.java

@Override
protected void fillBackground(Graphics2D g2, Rectangle2D area, PlotOrientation orientation) {
    Paint p = this.getBackgroundPaint();

    if (p == null) {
        return;/* w  w  w. ja  v a2s.  c om*/
    }

    iPainter painter = ChartHelper.getPainter(p);

    if (painter == null) {
        super.fillBackground(g2, area, orientation);

        return;
    }

    Composite originalComposite = g2.getComposite();

    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getBackgroundAlpha()));
    graphics = SwingGraphics.fromGraphics(g2, null, graphics);

    float x = UIScreen.snapToPosition(area.getX());
    float y = UIScreen.snapToPosition(area.getY());
    float w = UIScreen.snapToSize(area.getWidth());
    float h = UIScreen.snapToSize(area.getHeight());

    painter.paint(graphics, x, y, w, h, iPainter.UNKNOWN);
    g2.setComposite(originalComposite);
}

From source file:VASSAL.tools.image.svg.SVGRenderer.java

public BufferedImage render(double angle, double scale, Rectangle2D aoi) {
    // The renderer needs the bounds unscaled---scaling comes from the
    // width and height hints.
    AffineTransform px = AffineTransform.getRotateInstance(angle * DEGTORAD, defaultW / 2.0, defaultH / 2.0);
    r.setTransform(px);//from  ww w  .  jav a 2s.  co  m

    px = new AffineTransform(px);
    px.scale(scale, scale);

    final Rectangle2D rect = new Rectangle2D.Float(0, 0, defaultW, defaultH);

    r.addTranscodingHint(Rasterizer.KEY_WIDTH, (float) aoi.getWidth());
    r.addTranscodingHint(Rasterizer.KEY_HEIGHT, (float) aoi.getHeight());
    r.addTranscodingHint(Rasterizer.KEY_AOI, aoi);

    try {
        r.transcode(new TranscoderInput(doc), null);
        return r.getBufferedImage();
    }
    // FIXME: review error message
    catch (BridgeException e) {
        logger.error("", e);
    } catch (TranscoderException e) {
        logger.error("", e);
    }

    return null;
}

From source file:org.csa.rstb.dat.toolviews.HaAlphaPlotPanel.java

private ChartPanel createChartPanel(JFreeChart chart) {
    densityPlotDisplay = new ChartPanel(chart);

    MaskSelectionToolSupport maskSelectionToolSupport = new MaskSelectionToolSupport(this, densityPlotDisplay,
            "scatter_plot_area", "Mask generated from selected scatter plot area", Color.RED,
            PlotAreaSelectionTool.AreaType.ELLIPSE) {
        @Override/*from   ww w.  java  2  s .co m*/
        protected String createMaskExpression(PlotAreaSelectionTool.AreaType areaType, Shape shape) {
            Rectangle2D bounds = shape.getBounds2D();
            return createMaskExpression(bounds.getCenterX(), bounds.getCenterY(), 0.5 * bounds.getWidth(),
                    0.5 * bounds.getHeight());
        }

        protected String createMaskExpression(double x0, double y0, double dx, double dy) {
            return String.format("sqrt(sqr((%s - %s)/%s) + sqr((%s - %s)/%s)) < 1.0",
                    BandArithmetic.createExternalName(dataSourceConfig.xBand.getName()), x0, dx,
                    BandArithmetic.createExternalName(dataSourceConfig.yBand.getName()), y0, dy);
        }
    };

    densityPlotDisplay.getPopupMenu().addSeparator();
    densityPlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createMaskSelectionModeMenuItem());
    densityPlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createDeleteMaskMenuItem());
    densityPlotDisplay.getPopupMenu().addSeparator();
    densityPlotDisplay.getPopupMenu().add(createCopyDataToClipboardMenuItem());
    return densityPlotDisplay;
}

From source file:fr.amap.commons.javafx.chart.ChartViewer.java

/**
 * A handler for the export to PDF option in the context menu.
 *//* w  w  w  . ja va2s.c o m*/
private void handleExportToPDF() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setSelectedExtensionFilter(
            new FileChooser.ExtensionFilter("Portable Document Format (PDF)", "pdf"));
    fileChooser.setTitle("Export to PDF");
    File file = fileChooser.showSaveDialog(stage);
    if (file != null) {

        try {

            CanvasPositionsAndSize canvasPositionAndSize = getCanvasPositionAndSize();

            PDDocument doc = new PDDocument();

            PDPage page = new PDPage(new PDRectangle((float) canvasPositionAndSize.totalWidth,
                    (float) canvasPositionAndSize.totalHeight));
            doc.addPage(page);

            BufferedImage image = new BufferedImage((int) canvasPositionAndSize.totalWidth,
                    (int) canvasPositionAndSize.totalHeight, BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2 = image.createGraphics();

            int index = 0;
            for (ChartCanvas canvas : chartCanvasList) {

                Rectangle2D rectangle2D = canvasPositionAndSize.positionsAndSizes.get(index);

                ((Drawable) canvas.chart).draw(g2, new Rectangle((int) rectangle2D.getX(),
                        (int) rectangle2D.getY(), (int) rectangle2D.getWidth(), (int) rectangle2D.getHeight()));
                index++;
            }

            PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
            PDXObjectImage pdImage = new PDPixelMap(doc, image);
            contentStream.drawImage(pdImage, 0, 0);

            PDPageContentStream cos = new PDPageContentStream(doc, page);
            cos.drawXObject(pdImage, 0, 0, pdImage.getWidth(), pdImage.getHeight());
            cos.close();

            doc.save(file);

        } catch (IOException | COSVisitorException ex) {
            Logger.getLogger(ChartViewer.class.getName()).log(Level.SEVERE, null, ex);
        }
        /*ExportUtils.writeAsPDF(this.chart, (int)canvas.getWidth(),
        (int)canvas.getHeight(), file);*/

        /*ExportUtils.writeAsPDF(this.chart, (int)canvas.getWidth(),
                (int)canvas.getHeight(), file);*/
    }
}