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:peakml.util.jfreechart.LognAxis.java

@Override
public double java2DToValue(double java2DValue, Rectangle2D plotArea, RectangleEdge edge) {
    Range range = getRange();/*from w w  w.  jav a 2s  . c om*/
    double axisMin = log(range.getLowerBound());
    double axisMax = log(range.getUpperBound());

    double min = 0.0, max = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        min = plotArea.getX();
        max = plotArea.getMaxX();
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        min = plotArea.getMaxY();
        max = plotArea.getMinY();
    }

    if (isInverted())
        return pow(axisMax - ((java2DValue - min) / (max - min)) * (axisMax - axisMin));
    else
        return pow(axisMin + ((java2DValue - min) / (max - min)) * (axisMax - axisMin));
}

From source file:Clip.java

/**
 * Set the clip contents, and set the status to valid and in use.
 * @param r the clip contents to copy//from  www  . j a  v a2  s  .c  o  m
 */
public void setClip(Rectangle2D r) {
    setClip(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}

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

/**
 * Returns the shape for the window for this dial.  Some dial layers will
 * request that their drawing be clipped within this window.
 *
 * @param frame  the reference frame (<code>null</code> not permitted).
 *
 * @return The shape of the dial's window.
 *//*from  w ww.  j ava 2  s .c om*/
public Shape getWindow(Rectangle2D frame) {
    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius);
    return new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(), f.getHeight());
}

From source file:gda.plots.BlockWrapper.java

/**
 * JFreeChart will actually call this from its drawTitle method expecting the Block to draw itself at this point.
 * Our JComponent will already have been drawn as a consequence of being a simple child of the ChartPanel (which
 * extends JPanel). However we can use the information passed to the Block here to get the JComponents bounds set
 * correctly.//  w w  w .ja  v  a2 s .  c  o  m
 * 
 * @param g2
 *            the Graphics2D into which to draw (not used here)
 * @param area
 *            the Rectangle2D into which the object should draw itself)
 * @param params
 *            some parameters not yet understood
 * @return an Object else null
 */
@Override
public Object draw(Graphics2D g2, Rectangle2D area, Object params) {
    logger.debug("BW area is " + area);
    logger.debug("BW params is " + params);
    logger.debug("BW g2 is " + g2);
    logger.debug("BW g2.transform is " + g2.getTransform());
    jc.setBounds((int) Math.round(area.getX()), (int) Math.round(area.getY()),
            (int) Math.round(area.getWidth()), (int) Math.round(area.getHeight()));

    return null;
}

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

/**
 * Draws the background to the specified graphics device.  If the dial
 * frame specifies a window, the clipping region will already have been 
 * set to this window before this method is called.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param plot  the plot (ignored here).
 * @param frame  the dial frame (ignored here).
 * @param view  the view rectangle (<code>null</code> not permitted). 
 *///from w ww .j  ava2 s .com
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    g2.setPaint(this.fillPaint);

    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius);
    Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(), f.getHeight());
    g2.fill(e);
    g2.setPaint(this.outlinePaint);
    g2.setStroke(this.outlineStroke);
    g2.draw(e);

}

From source file:org.nuxeo.pdf.service.PDFTransformationServiceImpl.java

public Point2D computeTranslationVector(double pageWidth, double watermarkWidth, double pageHeight,
        double watermarkHeight, WatermarkProperties properties) {
    double xTranslation;
    double yTranslation;
    double xRotationOffset = 0;
    double yRotationOffset = 0;

    if (properties.getTextRotation() != 0) {
        Rectangle2D rectangle2D = new Rectangle2D.Double(0, -watermarkHeight, watermarkWidth, watermarkHeight);
        AffineTransform at = AffineTransform.getRotateInstance(-Math.toRadians(properties.getTextRotation()), 0,
                0);// w w  w . j a  va 2  s  .  co m
        Shape shape = at.createTransformedShape(rectangle2D);
        Rectangle2D rotated = shape.getBounds2D();

        watermarkWidth = rotated.getWidth();
        if (!properties.isInvertX() || properties.isRelativeCoordinates()) {
            xRotationOffset = -rotated.getX();
        } else {
            xRotationOffset = rotated.getX();
        }

        watermarkHeight = rotated.getHeight();
        if (!properties.isInvertY() || properties.isRelativeCoordinates()) {
            yRotationOffset = rotated.getY() + rotated.getHeight();
        } else {
            yRotationOffset = -(rotated.getY() + rotated.getHeight());
        }

    }

    if (properties.isRelativeCoordinates()) {
        xTranslation = (pageWidth - watermarkWidth) * properties.getxPosition() + xRotationOffset;
        yTranslation = (pageHeight - watermarkHeight) * properties.getyPosition() + yRotationOffset;
    } else {
        xTranslation = properties.getxPosition() + xRotationOffset;
        yTranslation = properties.getyPosition() + yRotationOffset;
        if (properties.isInvertX())
            xTranslation = pageWidth - watermarkWidth - xTranslation;
        if (properties.isInvertY())
            yTranslation = pageHeight - watermarkHeight - yTranslation;
    }
    return new Point2D.Double(xTranslation, yTranslation);
}

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

/**
 * Draws the frame.  This method is called by the {@link DialPlot} class,
 * you shouldn't need to call it directly.
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the plot (<code>null</code> not permitted).
 * @param frame  the frame (<code>null</code> not permitted).
 * @param view  the view (<code>null</code> not permitted).
 *///from  w w w . j a va 2 s  . co m
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    Shape window = getWindow(frame);

    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius + 0.02, this.radius + 0.02);
    Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(), f.getHeight());

    Area area = new Area(e);
    Area area2 = new Area(window);
    area.subtract(area2);
    g2.setPaint(this.backgroundPaint);
    g2.fill(area);

    g2.setStroke(this.stroke);
    g2.setPaint(this.foregroundPaint);
    g2.draw(window);
    g2.draw(e);
}

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

public void mouseClicked(MouseEvent e) {
    if (e.getSource() instanceof ChartPanel && ((e.getButton() == MouseEvent.BUTTON2)
            || (e.getButton() == MouseEvent.BUTTON1) && ((e.getModifiers() & InputEvent.CTRL_MASK) != 0))) {
        CenterZoomNumberAxis czna = (CenterZoomNumberAxis) _cp.getChart().getXYPlot().getDomainAxis();
        NumberAxis range = (NumberAxis) _cp.getChart().getXYPlot().getRangeAxis();
        Rectangle2D screenDataArea = _cp.getScreenDataArea(e.getX(), e.getY());
        double y1 = czna.getLowerBound();
        double y2 = czna.getUpperBound();
        double x1 = screenDataArea.getX();
        double x2 = x1 + screenDataArea.getWidth();
        double transformedx = (((y2 - y1) / (x2 - x1)) * (e.getX() - x1)) + y1;
        MRMDialog mrmd = (MRMDialog) MRMAncestor();
        PeaksTableModel model = (PeaksTableModel) mrmd.peaksTable.getModel();
        MRMTransition mrt = mrmd.transitionOnPlot;
        mrt.setCalcXatMaxYAllDaughters(transformedx);
        mrt.setCalcMaxYAllDaughters(/*from   ww w  .j  a v  a2s  . c o m*/
                range.getLowerBound() + 0.95 * (range.getUpperBound() - range.getLowerBound()));
        model.setValueAt(new Float(mrt.getCalcXatMaxYAllDaughters()), mrt.getTableRow(),
                MRMDialog.peaksData.MidTime.colno);
        for (MRMDaughter d : mrt.getDaughters().values()) {
            model.setValueAt(new Float(mrt.getCalcXatMaxYAllDaughters()), d.getElutionDataTableRow(),
                    MRMDialog.peaksData.MidTime.colno);
        }
        mrmd.updateChartsAndFields(false);
    }
    if ((e.isShiftDown() || e.getButton() == MouseEvent.BUTTON3) || shifted) {
        _cp.mouseClicked(e);
    } else {
        _cp.mouseClicked(e);
    }
}

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

/**
 * @param x//from   w w  w .  j av a 2s .co 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:org.fhcrc.cpl.toolbox.gui.chart.ChartMouseAndMotionListener.java

/**
 * Transform a mouse X value into a value in the units of the X axis of the chart.
 * Note: if there were multiple subplots, this would need to take a MouseEvent to determine which one
 * Note: bounds the raw value by the boundaries of the chart.  No using values off the ends, even if you're zoomed
 * @param rawValue/* w w  w .ja  v  a2s.c om*/
 * @return
 */
protected double transformMouseXValue(double rawValue) {
    Rectangle2D screenDataArea = _chartPanel.getScreenDataArea();
    double boundedValue = Math.min(screenDataArea.getMaxX(), Math.max(screenDataArea.getMinX(), rawValue));

    double leftmostOnAxis = domainAxis.getLowerBound();
    double rightmostOnAxis = domainAxis.getUpperBound();
    double leftmostonscreen = screenDataArea.getX();
    double rightmostonscreen = leftmostonscreen + screenDataArea.getWidth();
    double slope = (rightmostOnAxis - leftmostOnAxis) / (rightmostonscreen - leftmostonscreen);
    return ((slope * (boundedValue - leftmostonscreen)) + leftmostOnAxis);
}