Example usage for java.awt.geom Rectangle2D getY

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

Introduction

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

Prototype

public abstract double getY();

Source Link

Document

Returns the Y 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  w w . ja  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);/*  ww w.  ja  v  a 2s .  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:Clip.java

/**
 * Indicates if this Clip intersects the given rectangle expanded
 * by the additional margin pace.//from  w ww  . j  a  va 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.mwc.cmap.grideditor.chart.DataPointsDragTracker.java

public void chartMouseMoved(final ChartMouseEvent event) {
    if (!myDragSubject.isEmpty()) {
        myChartPanel.forgetZoomPoints();

        // Rectangle clientArea = myChartPanel.getClientArea();
        // int screenX = event.getTrigger().getX() - clientArea.x;
        // int screenY = event.getTrigger().getY() - clientArea.y;

        // [IM] don't bother with sorting out the client area offset
        // - we've stopped using it in the FixedChartComposite calling method
        final int screenX = event.getTrigger().getX();
        final int screenY = event.getTrigger().getY();

        // deliberately switch axes for following line, now that we've switched
        // the axes to put time
        // down the LH side.
        final Point2D point2d = new Point2D.Double(screenY, screenX);
        final XYPlot xyplot = myChartPanel.getChart().getXYPlot();
        final ChartRenderingInfo renderingInfo = myChartPanel.getChartRenderingInfo();
        Rectangle2D dataArea = renderingInfo.getPlotInfo().getDataArea();

        // WORKAROUND: when the grid graph gets really wide, the labels on the
        // y-axis get stretched.
        // but, the dataArea value doesn't reflect this.
        // So, get the width values from the getScreenDataArea method - which
        // does reflect the scaling applied to the y axis.
        // - and all works well now.
        final Rectangle dataArea2 = myChartPanel.getScreenDataArea();
        dataArea = new Rectangle2D.Double(dataArea2.x, dataArea.getY(), dataArea2.width, dataArea.getHeight());

        final ValueAxis domainAxis = xyplot.getDomainAxis();
        final RectangleEdge domainEdge = xyplot.getDomainAxisEdge();
        final ValueAxis valueAxis = xyplot.getRangeAxis();
        final RectangleEdge valueEdge = xyplot.getRangeAxisEdge();
        double domainX = domainAxis.java2DToValue(point2d.getX(), dataArea, domainEdge);
        final double domainY = valueAxis.java2DToValue(point2d.getY(), dataArea, valueEdge);

        if (myAllowVerticalMovesOnly) {
            domainX = myDragSubject.getDraggedItem().getXValue();
        }//from  www .  j a va 2s  .  c  om

        if (!myDragSubject.isEmpty())
            myDragSubject.setProposedValues(domainX, domainY);
        myChartPanel.redrawCanvas();
    }
}

From source file:ucar.unidata.idv.control.chart.TrackSegment.java

/**
 * Draws the wayPoint./*from   www .  j  a v  a  2 s  .  c o  m*/
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  an optional info object that will be populated with
 *              entity information.
 */
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis,
        int rendererIndex, PlotRenderingInfo info) {
    super.setGraphicsState(g2);

    if (!getPlotWrapper().okToDraw(this)) {
        return;
    }
    WayPoint leftWayPoint = getLeft();
    WayPoint rightWayPoint = getRight();
    g2.setStroke(new BasicStroke());
    int x1 = leftWayPoint.getXFromValue(dataArea, domainAxis);
    int x2 = rightWayPoint.getXFromValue(dataArea, domainAxis);
    int top = (int) (dataArea.getY());
    int bottom = (int) (dataArea.getY() + dataArea.getHeight());
    FontMetrics fm = g2.getFontMetrics();
    int width = fm.stringWidth(getName());
    int height = fm.getAscent() + fm.getDescent();
    if (getSelected()) {
        g2.setColor(Color.red);
    } else {
        g2.setColor(Color.black);
    }
    //      int y = bottom-3;
    y = top - 2;
    int textLeft = x1 + (x2 - x1) / 2 - width / 2;
    g2.drawString(getName(), textLeft, y);
    g2.setStroke(new BasicStroke(2.0f));
    g2.drawLine(x1, top + 1, x2, top + 1);
    g2.setStroke(new BasicStroke(1.0f));
    g2.setColor(Color.gray);
    g2.drawLine(x1, top, x1, bottom - WayPoint.ANNOTATION_WIDTH);
    g2.drawLine(x2, top, x2, bottom - WayPoint.ANNOTATION_WIDTH);
}

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

/**
 * Returns the frame surrounding the specified view rectangle.
 * /*w  w  w .j  a  va2s .  c om*/
 * @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:WeatherWizard.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Dimension size = getSize();//from w ww . j av  a 2 s.co 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.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java

/**
 * Get the border shape for the given label shape
 * @param labelShape//from   w w w  .  ja  v  a 2  s  .  c  om
 *          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:org.pentaho.reporting.engine.classic.extensions.modules.sbarcodes.BarcodeWrapper.java

public void draw(final Graphics2D g2, final Rectangle2D bounds) {
    final Graphics2D gr2 = (Graphics2D) g2.create();
    try {/*from w  w  w .j a  v  a2s .c o m*/
        gr2.clip(bounds);
        if (scale) {
            final Dimension size = barcode.getPreferredSize();
            final double horzScale = bounds.getWidth() / size.getWidth();
            final double vertScale = bounds.getHeight() / size.getHeight();
            if (keepAspectRatio) {
                final double scale = Math.min(horzScale, vertScale);
                gr2.scale(scale, scale);
            } else {
                gr2.scale(horzScale, vertScale);
            }
        }
        barcode.draw(gr2, (int) bounds.getX(), (int) bounds.getY());
    } catch (OutputException e) {
        logger.error("Unable to draw barcode element", e);
    } finally {
        gr2.dispose();
    }

}

From source file:org.pentaho.plugin.jfreereport.reportcharts.JFreeChartReportDrawable.java

public void draw(final Graphics2D graphics2D, final Rectangle2D bounds) {
    this.bounds = (Rectangle2D) bounds.clone();
    if (chartRenderingInfo != null) {
        this.chartRenderingInfo.clear();
    }/*from w  w w  . j av  a  2 s.  co  m*/
    final Graphics2D g2 = (Graphics2D) graphics2D.create();
    this.chart.draw(g2, bounds, chartRenderingInfo);
    g2.dispose();

    if (chartRenderingInfo == null || debugRendering == false) {
        return;
    }

    graphics2D.setColor(Color.RED);
    final Rectangle2D dataArea = getDataAreaOffset();
    final EntityCollection entityCollection = chartRenderingInfo.getEntityCollection();
    for (int i = 0; i < entityCollection.getEntityCount(); i++) {
        final ChartEntity chartEntity = entityCollection.getEntity(i);
        if (chartEntity instanceof XYItemEntity || chartEntity instanceof CategoryItemEntity
                || chartEntity instanceof PieSectionEntity) {
            final Area a = new Area(chartEntity.getArea());
            if (buggyDrawArea) {
                a.transform(AffineTransform.getTranslateInstance(dataArea.getX(), dataArea.getY()));
            }
            a.intersect(new Area(dataArea));
            graphics2D.draw(a);
        } else {
            graphics2D.draw(chartEntity.getArea());
        }
    }
}