Example usage for java.awt.geom Point2D getX

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

Introduction

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

Prototype

public abstract double getX();

Source Link

Document

Returns the X coordinate of this Point2D in double precision.

Usage

From source file:com.t_oster.visicut.misc.Helper.java

/**
* Compute the rotation angle of an affine transformation.
* Counter-clockwise rotation is considered positive.
*
* method taken from http://javagraphics.blogspot.com/
*
* @return rotation angle in radians (beween -pi and pi),
*  or NaN if the transformation is bogus.
*//*from w  w  w  . j  a  va  2 s  .c  o  m*/
public static double getRotationAngle(AffineTransform transform) {
    transform = (AffineTransform) transform.clone();
    // Eliminate any post-translation
    transform.preConcatenate(
            AffineTransform.getTranslateInstance(-transform.getTranslateX(), -transform.getTranslateY()));
    Point2D p1 = new Point2D.Double(1, 0);
    p1 = transform.transform(p1, p1);
    return Math.atan2(p1.getY(), p1.getX());
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

public static Abstract2DMask translateChartRectangle(Abstract2DMask mask, Rectangle2D imageArea,
        JFreeChart chart) {//  w  ww . j a  va 2 s.c  o m
    Rectangle2D bound = mask.getRectangleFrame();
    Point2D start = new Point2D.Double(bound.getMinX(), bound.getMinY());
    Point2D end = new Point2D.Double(bound.getMaxX(), bound.getMaxY());
    Point2D screenStart = translateChartPoint(start, imageArea, chart);
    Point2D screenEnd = translateChartPoint(end, imageArea, chart);
    Abstract2DMask imageMask = mask.clone();
    imageMask.setRectangleFrame(new Rectangle2D.Double(Math.min(screenStart.getX(), screenEnd.getX()),
            Math.min(screenStart.getY(), screenEnd.getY()), Math.abs(screenStart.getX() - screenEnd.getX()),
            Math.abs(screenStart.getY() - screenEnd.getY())));
    return imageMask;
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

public static Point2D translateChartPoint(Point2D point, Rectangle2D imageArea, JFreeChart chart) {
    XYPlot plot = chart.getXYPlot();/*from w  w w . j  a  v  a  2s .co  m*/
    double x, y;

    ValueAxis domainAxis = plot.getDomainAxis();
    ValueAxis rangeAxis = plot.getRangeAxis();

    x = domainAxis.valueToJava2D(point.getX(), imageArea, RectangleEdge.BOTTOM);
    y = rangeAxis.valueToJava2D(point.getY(), imageArea, RectangleEdge.LEFT);

    return new Point2D.Double(x, y);
}

From source file:com.t_oster.visicut.misc.Helper.java

/**
 * Returns an AffineTransform, which transformes src to dest
 * and constists of a scale and translate component
 * @param src/*from w ww  . j  a  va2  s  .c o m*/
 * @param dest
 * @return
 */
public static AffineTransform getTransform(Rectangle2D src, Rectangle2D dest) {
    AffineTransform scale = AffineTransform.getScaleInstance(dest.getWidth() / src.getWidth(),
            dest.getHeight() / src.getHeight());
    Point2D scaled = scale.transform(new Point.Double(src.getX(), src.getY()), null);
    AffineTransform result = AffineTransform.getTranslateInstance(dest.getX() - scaled.getX(),
            dest.getY() - scaled.getY());
    result.concatenate(scale);
    return result;
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

private static void drawMaskName(Graphics2D g2, AbstractMask mask, Rectangle2D imageArea, double fontSizeRate) {
    if (mask.getName() == null) {
        return;/* w  ww  .  ja v  a  2s .  c  o  m*/
    }
    Point2D fontLocation = mask.getTitleLocation(imageArea);
    g2.setPaint(Color.black);
    Font currentFont = g2.getFont();
    g2.setFont(currentFont.deriveFont((float) (maskNameFont.getSize() * fontSizeRate)).deriveFont(Font.ITALIC));
    g2.drawString(mask.getName(), (int) fontLocation.getX(), (int) fontLocation.getY());
    g2.setFont(currentFont);
}

From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java

/**
 * Translates screen (pixel) values to plot values
 * //from  w  w  w  .  j a v a2 s. com
 * @param myChart
 * @return width in data space for x and y
 */
public static Point2D screenValueToPlotValue(ChartViewer myChart, int val) {
    Point2D p = mouseXYToPlotXY(myChart, 0, 0);
    Point2D p2 = mouseXYToPlotXY(myChart, val, val);
    // inverted y
    return new Point2D.Double(p2.getX() - p.getX(), p.getY() - p2.getY());
}

From source file:net.sf.mzmine.chartbasics.ChartLogics.java

/**
 * Translates screen (pixel) values to plot values
 * /* www  . jav a  2s . c  o  m*/
 * @param myChart
 * @return width in data space for x and y
 * @throws Exception
 */
public static Point2D screenValueToPlotValue(ChartPanel myChart, int val) throws Exception {
    Point2D p = mouseXYToPlotXY(myChart, 0, 0);
    Point2D p2 = mouseXYToPlotXY(myChart, val, val);
    // inverted y
    return new Point2D.Double(p2.getX() - p.getX(), p.getY() - p2.getY());
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

public static Shape translateChartShape(Shape shape, Rectangle2D imageArea, JFreeChart chart) {
    if (shape instanceof Line2D) {
        Line2D line = (Line2D) shape;
        double length = line.getP1().distance(line.getP2());
        if (length == 0) {
            Point2D point = line.getP1();
            Point2D newPoint = ChartMaskingUtilities.translateChartPoint(point, imageArea, chart);
            Shape oShape = ShapeUtilities.createDiagonalCross(5f, 0.2f);
            //             Shape oShape = ShapeUtilities.createRegularCross(3f, 0.5f);
            Shape newShape = ShapeUtilities.createTranslatedShape(oShape, newPoint.getX(), newPoint.getY());
            return newShape;
        } else if (length < 1e-6) {
            if (line.getP1().getX() == line.getP2().getX()) {
                double newX = ChartMaskingUtilities.translateChartPoint(line.getP1(), imageArea, chart).getX();
                Line2D newLine = new Line2D.Double(newX, imageArea.getMinY(), newX, imageArea.getMaxY());
                return newLine;
            } else {
                double newY = ChartMaskingUtilities.translateChartPoint(line.getP1(), imageArea, chart).getY();
                Line2D newLine = new Line2D.Double(imageArea.getMinX(), newY, imageArea.getMaxX(), newY);
                return newLine;
            }//from   www  . ja va 2s .  c o  m
        }
        Line2D newShape = (Line2D) line.clone();
        Point2D newP1 = translateChartPoint(line.getP1(), imageArea, chart);
        Point2D newP2 = translateChartPoint(line.getP2(), imageArea, chart);
        newShape.setLine(newP1, newP2);
        return newShape;
    } else if (shape instanceof RectangularShape) {
        RectangularShape rect = (RectangularShape) shape;
        RectangularShape newShape = (RectangularShape) rect.clone();
        Rectangle2D bound = rect.getBounds2D();
        Point2D start = new Point2D.Double(bound.getMinX(), bound.getMinY());
        Point2D end = new Point2D.Double(bound.getMaxX(), bound.getMaxY());
        Point2D screenStart = translateChartPoint(start, imageArea, chart);
        Point2D screenEnd = translateChartPoint(end, imageArea, chart);
        newShape.setFrame(new Rectangle2D.Double(Math.min(screenStart.getX(), screenEnd.getX()),
                Math.min(screenStart.getY(), screenEnd.getY()), Math.abs(screenStart.getX() - screenEnd.getX()),
                Math.abs(screenStart.getY() - screenEnd.getY())));
        return newShape;
    } else {
        return shape;
    }
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

public static Point2D translateChartPoint(Point2D point, Rectangle2D imageArea, JFreeChart chart,
        int rangeAxisIndex) {
    XYPlot plot = chart.getXYPlot();//  w w w.  ja  v  a2  s  .c o m
    double x, y;

    ValueAxis domainAxis = plot.getDomainAxis();
    ValueAxis rangeAxis;
    if (rangeAxisIndex < 0 || rangeAxisIndex >= plot.getRangeAxisCount()) {
        rangeAxis = plot.getRangeAxis();
    } else {
        rangeAxis = plot.getRangeAxis(rangeAxisIndex);
    }
    x = domainAxis.valueToJava2D(point.getX(), imageArea, RectangleEdge.BOTTOM);
    y = rangeAxis.valueToJava2D(point.getY(), imageArea, RectangleEdge.LEFT);

    return new Point2D.Double(x, y);
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

public static void drawText(Graphics2D g2, Rectangle2D imageArea,
        LinkedHashMap<Rectangle2D, String> textContentMap, JFreeChart chart) {
    if (textContentMap == null || textContentMap.size() == 0) {
        return;//from   w  w w. ja  v a 2s. c  o m
    }
    //      for (Entry<Rectangle2D, String> textEntry : textMap.entrySet()) {
    //         Rectangle2D rect = textEntry.getKey();
    //         String text = textEntry.getValue();
    //         drawText(g2, imageArea, rect, text, chart);
    //      }
    Color oldColor = g2.getColor();
    g2.setColor(Color.BLACK);
    for (Entry<Rectangle2D, String> entry : textContentMap.entrySet()) {
        Rectangle2D rect = entry.getKey();
        Point2D screenPoint = ChartMaskingUtilities
                .translateChartPoint(new Point2D.Double(rect.getX(), rect.getY()), imageArea, chart);
        String text = entry.getValue();
        if (text == null) {
            continue;
        }
        String[] lines = text.split("\n");
        g2.setColor(Color.BLACK);
        for (int i = 0; i < lines.length; i++) {
            g2.drawString(lines[i], (int) screenPoint.getX() + 3, (int) screenPoint.getY() - 3 + i * 15);
        }
        //         if (rect == selectedTextWrapper) {
        //            FontMetrics fm = g2.getFontMetrics();
        //            int maxWidth = 0;
        //            int maxHeight = 0;
        //            for (int i = 0; i < lines.length; i++) {
        //               int lineWidth = fm.stringWidth(lines[i]);
        //               if (lineWidth > maxWidth) {
        //                  maxWidth = lineWidth;
        //               }
        //            }
        //            maxHeight = 15 * lines.length;
        //            if (maxWidth < 100) {
        //               maxWidth = 100;
        //            }
        //            Rectangle2D inputBox = new Rectangle2D.Double(screenPoint.getX(), screenPoint.getY() - 15, maxWidth + 8, maxHeight);
        //              Color fillColor = new Color(250, 250, 50, 30);
        //              g2.setPaint(fillColor);
        //              g2.fill(inputBox);
        //            g2.setColor(Color.ORANGE);
        //            g2.drawRect((int) screenPoint.getX(), (int) screenPoint.getY() - 15, maxWidth + 8, maxHeight);
        //
        //         }
        //         g2.drawString(text == null ? "" : text, (int) screenPoint.getX() + 3, (int) screenPoint.getY() - 3);
    }
    g2.setColor(oldColor);
}