Example usage for java.awt.geom Rectangle2D getX

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

Introduction

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

Prototype

public abstract double getX();

Source Link

Document

Returns the X coordinate of the upper-left corner of the framing rectangle in double precision.

Usage

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

/**
 * A handler for the export to PDF option in the context menu.
 *//*from   w  ww.j a v  a 2s.  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);*/
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.parser.simple.readhandlers.LineReadHandler.java

private void createLineElementFromBounds(final float x1, final float y1, final float x2, final float y2,
        final Stroke stroke, final String name, final Color c, final Rectangle2D bounds) {
    if (x1 == x2) {
        // assume that we have a vertical line
        final VerticalLineElementFactory elementFactory = new VerticalLineElementFactory();
        elementFactory.setName(name);//from   w  w  w. j  av a  2  s .com
        elementFactory.setColor(c);
        elementFactory.setStroke(stroke);
        elementFactory.setX(new Float(bounds.getX()));
        elementFactory.setY(new Float(bounds.getY()));
        elementFactory.setMinimumWidth(new Float(bounds.getWidth()));
        elementFactory.setMinimumHeight(new Float(bounds.getHeight()));
        elementFactory.setScale(Boolean.TRUE);
        elementFactory.setKeepAspectRatio(Boolean.FALSE);
        elementFactory.setShouldDraw(Boolean.TRUE);
        element = elementFactory.createElement();
    } else if (y1 == y2) {
        // assume that we have a horizontal line
        final HorizontalLineElementFactory elementFactory = new HorizontalLineElementFactory();
        elementFactory.setName(name);
        elementFactory.setColor(c);
        elementFactory.setStroke(stroke);
        elementFactory.setX(new Float(bounds.getX()));
        elementFactory.setY(new Float(bounds.getY()));
        elementFactory.setMinimumWidth(new Float(bounds.getWidth()));
        elementFactory.setMinimumHeight(new Float(bounds.getHeight()));
        elementFactory.setScale(Boolean.TRUE);
        elementFactory.setKeepAspectRatio(Boolean.FALSE);
        elementFactory.setShouldDraw(Boolean.TRUE);
        element = elementFactory.createElement();
    } else {
        // here comes the magic - we transform the line into the absolute space;
        // this should preserve the general appearance. Heck, and if not, then
        // it is part of the users reponsibility to resolve that. Magic does not
        // solve all problems, you know.
        final Line2D line = new Line2D.Float(Math.abs(x1), Math.abs(y1), Math.abs(x2), Math.abs(y2));
        final Rectangle2D shapeBounds = line.getBounds2D();
        final Shape transformedShape = ShapeTransform.translateShape(line, -shapeBounds.getX(),
                -shapeBounds.getY());
        // and use that shape with the user's bounds to create the element.
        final ContentElementFactory elementFactory = new ContentElementFactory();
        elementFactory.setName(name);
        elementFactory.setColor(c);
        elementFactory.setStroke(stroke);
        elementFactory.setX(new Float(shapeBounds.getX()));
        elementFactory.setY(new Float(shapeBounds.getY()));
        elementFactory.setMinimumWidth(new Float(shapeBounds.getWidth()));
        elementFactory.setMinimumHeight(new Float(shapeBounds.getHeight()));
        elementFactory.setContent(transformedShape);
        elementFactory.setScale(Boolean.TRUE);
        elementFactory.setKeepAspectRatio(Boolean.FALSE);
        elementFactory.setShouldDraw(Boolean.TRUE);
        element = elementFactory.createElement();
    }
}

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

/**
 * @param rectMM bounding box in milimeters
 * @see #getSubimage(double, double, double, double, int)
 * @return//from w w  w .j  a v a 2 s.  c  om
 */
public SubImage getSubimage(Rectangle2D rectMM, int imageType) {

    Rectangle rect = this.toPixels(rectMM);
    if (logger.isDebugEnabled()) {
        logger.debug("Subimage " + rectMM + " mm " + rect + " px.");
    }
    PagePoint upperLeft = new PagePoint(this, rectMM.getX(), rectMM.getY());

    Point reference = upperLeft.getPixelsPoint();

    BufferedImage originalImage = getImage();
    Rectangle originalRect = new Rectangle(originalImage.getWidth(), originalImage.getHeight());
    // copy what is available from image
    Rectangle available = rect.intersection(originalRect);

    BufferedImage originalSubImage = originalImage.getSubimage(available.x, available.y, available.width,
            available.height);

    //rotate image
    SubImage subimage = new SubImage(rect.width, rect.height, imageType);
    subimage.setReference(reference);
    subimage.setBoundingBox(rect);
    subimage.setCapturedBoundingBox(available);

    Graphics2D g = subimage.createGraphics();
    g.drawImage(originalSubImage, available.x - rect.x, available.y - rect.y, null);

    return subimage;
}

From source file:Clip.java

/**
 * Indicates if this Clip intersects the given rectangle expanded
 * by the additional margin pace.//from  ww  w  . j  a v  a  2  s.co m
 * @param r the rectangle to test for intersect
 * @param margin additional margin "bleed" to include in the intersection
 * @return true if the clip intersects the expanded region, false otherwise
 */
public boolean intersects(Rectangle2D r, double margin) {
    double tw = clip[6] - clip[0];
    double th = clip[7] - clip[1];
    double rw = r.getWidth();
    double rh = r.getHeight();
    if (rw < 0 || rh < 0 || tw < 0 || th < 0) {
        return false;
    }
    double tx = clip[0];
    double ty = clip[1];
    double rx = r.getX() - margin;
    double ry = r.getY() - margin;
    rw += rx + 2 * margin;
    rh += ry + 2 * margin;
    tw += tx;
    th += ty;
    //      overflow || intersect
    return ((rw < rx || rw > tx) && (rh < ry || rh > ty) && (tw < tx || tw > rx) && (th < ty || th > ry));
}

From source file:org.jfree.experimental.chart.plot.dial.DialPlot.java

/**
 * Returns the frame surrounding the specified view rectangle.
 * /*from w  w  w.  j av  a  2  s.  c o m*/
 * @param view  the view rectangle (<code>null</code> not permitted).
 */
private Rectangle2D viewToFrame(Rectangle2D view) {
    double width = view.getWidth() / this.viewW;
    double height = view.getHeight() / this.viewH;
    double x = view.getX() - (width * this.viewX);
    double y = view.getY() - (height * this.viewY);
    return new Rectangle2D.Double(x, y, width, height);
}

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

/**
 * Get the border shape for the given label shape
 * @param labelShape/*  ww  w  . j a  v a 2s.c o  m*/
 *          the label shape that we're going to draw a border around
 * @return
 *          the border shape
 */
private Shape getLabelBorder(Shape labelShape) {
    Rectangle2D labelBounds = labelShape.getBounds2D();

    return new RoundRectangle2D.Double(labelBounds.getX() - LABEL_BORDER_ROUNDING_ARC_SIZE,
            labelBounds.getY() - LABEL_BORDER_ROUNDING_ARC_SIZE,
            labelBounds.getWidth() + (LABEL_BORDER_ROUNDING_ARC_SIZE * 2),
            labelBounds.getHeight() + (LABEL_BORDER_ROUNDING_ARC_SIZE * 2), LABEL_BORDER_ROUNDING_ARC_SIZE,
            LABEL_BORDER_ROUNDING_ARC_SIZE);
}

From source file:WeatherWizard.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Dimension size = getSize();/*www . j  av  a 2  s  .c  o m*/
    Composite origComposite;

    setupWeatherReport();

    origComposite = g2.getComposite();
    if (alpha0 != null)
        g2.setComposite(alpha0);
    g2.drawImage(img0, 0, 0, size.width, size.height, 0, 0, img0.getWidth(null), img0.getHeight(null), null);
    if (img1 != null) {
        if (alpha1 != null)
            g2.setComposite(alpha1);
        g2.drawImage(img1, 0, 0, size.width, size.height, 0, 0, img1.getWidth(null), img1.getHeight(null),
                null);
    }
    g2.setComposite(origComposite);

    // Freezing, Cold, Cool, Warm, Hot,
    // Blue, Green, Yellow, Orange, Red
    Font font = new Font("Serif", Font.PLAIN, 36);
    g.setFont(font);

    String tempString = feels + " " + temperature + "F";
    FontRenderContext frc = ((Graphics2D) g).getFontRenderContext();
    Rectangle2D boundsTemp = font.getStringBounds(tempString, frc);
    Rectangle2D boundsCond = font.getStringBounds(condStr, frc);
    int wText = Math.max((int) boundsTemp.getWidth(), (int) boundsCond.getWidth());
    int hText = (int) boundsTemp.getHeight() + (int) boundsCond.getHeight();
    int rX = (size.width - wText) / 2;
    int rY = (size.height - hText) / 2;

    g.setColor(Color.LIGHT_GRAY);
    g2.fillRect(rX, rY, wText, hText);

    g.setColor(textColor);
    int xTextTemp = rX - (int) boundsTemp.getX();
    int yTextTemp = rY - (int) boundsTemp.getY();
    g.drawString(tempString, xTextTemp, yTextTemp);

    int xTextCond = rX - (int) boundsCond.getX();
    int yTextCond = rY - (int) boundsCond.getY() + (int) boundsTemp.getHeight();
    g.drawString(condStr, xTextCond, yTextCond);

}

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

    //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);
}

From source file:org.fhcrc.cpl.viewer.mrm.utilities.MRMerMouseListener.java

public void mouseReleased(MouseEvent e) {
    try {//  w  ww.j av  a2  s  .  c  o  m
        if ((e.isShiftDown() || e.getButton() == MouseEvent.BUTTON3) || shifted) {
            //            Rectangle2D scaledDataArea = _chartPanel.getScreenDataArea(
            //                    (int) this.coElutionStart.getX(), (int) this.coElutionStart.getY());
            JFreeChart jfc = _cp.getChart();
            XYPlot p = jfc.getXYPlot();
            CenterZoomNumberAxis czna = (CenterZoomNumberAxis) p.getDomainAxis();
            Rectangle2D screenDataArea = _cp.getScreenDataArea(e.getX(), e.getY());
            Rectangle2D plotboundaries = _cp.getChartRenderingInfo().getPlotInfo().getPlotArea();

            double leftmostOnAxis = czna.getLowerBound();
            double rightmostOnAxis = czna.getUpperBound();
            double leftmostOnRange = this.coElutionRegion.getX();
            double rightmostOnRange = this.coElutionRegion.getX() + this.coElutionRegion.getWidth();
            double leftmostonscreen = screenDataArea.getX();
            double rightmostonscreen = leftmostonscreen + screenDataArea.getWidth();
            double slope = (rightmostOnAxis - leftmostOnAxis) / (rightmostonscreen - leftmostonscreen);
            double transformedLeftRange = (slope * (leftmostOnRange - leftmostonscreen)) + leftmostOnAxis;
            double transformedRightRange = (slope * (rightmostOnRange - leftmostonscreen)) + leftmostOnAxis;
            shifted = false;
            MRMDialog ultimateParent = (MRMDialog) MRMAncestor();
            if (ultimateParent != null) {
                MRMTransition transition = ultimateParent.transitionOnPlot;
                MRMTransition mrmt = transition;
                if (mrmt != null) {
                    int row = mrmt.getTableRow();
                    _ptm.data[row][MRMDialog.peaksData.CoStart.colno] = new Float(0f);
                    _ptm.data[row][MRMDialog.peaksData.CoEnd.colno] = new Float(10000000f);
                    _ptm.setValueAt(new Float(transformedRightRange), row, MRMDialog.peaksData.CoEnd.colno);
                    _ptm.setValueAt(new Float(transformedLeftRange), row, MRMDialog.peaksData.CoStart.colno);
                }
            }
            Graphics2D g2 = (Graphics2D) _cp.getGraphics();
            if (this.coElutionRegion != null)
                drawCoElutionRegion(g2);
            this.coElutionRegion = null;
            this.coElutionStart = null;
        } else {
            _cp.mouseReleased(e);
        }
    } catch (Exception ee) {
    }
}

From source file:figs.treeVisualization.gui.PhyloDateAxis.java

/**
 * Translates the data value to the display coordinates (Java 2D User Space)
 * of the chart.//w  ww.j  a v  a  2  s . co  m
 *
 * @param value  the date to be plotted.
 * @param area  the rectangle (in Java2D space) where the data is to be 
 *              plotted.
 * @param edge  the axis location.
 *
 * @return The coordinate corresponding to the supplied data value.
 * 
 * Original method is in <code>org.jfree.chart.axis.DateAxis</code>
 */
@Override
public double valueToJava2D(double value, Rectangle2D area, RectangleEdge edge) {

    Timeline timeline = this.getTimeline();
    value = timeline.toTimelineValue((long) value);

    DateRange range = (DateRange) getRange();
    double axisMin = timeline.toTimelineValue(range.getLowerDate());
    double axisMax = timeline.toTimelineValue(range.getUpperDate());
    double result = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        double minX = area.getX();
        double maxX = area.getMaxX();
        if (isInverted()) {
            result = maxX + ((value - axisMin) / (axisMax - axisMin)) * (minX - maxX);
        } else {
            result = minX + ((value - axisMin) / (axisMax - axisMin)) * (maxX - minX);
        }
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        //double minY = area.getMinY();
        //double maxY = area.getMaxY();
        double minY = area.getY();
        double maxY = area.getHeight();
        if (isInverted()) {
            result = minY + (((value - axisMin) / (axisMax - axisMin)) * (maxY - minY));
        } else {
            result = maxY - (((value - axisMin) / (axisMax - axisMin)) * (maxY - minY));
        }
    }
    return result;

}