Example usage for java.awt.geom Point2D getY

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

Introduction

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

Prototype

public abstract double getY();

Source Link

Document

Returns the Y coordinate of this Point2D in double precision.

Usage

From source file:org.jcurl.core.base.CurveTransformedTest.java

/**
 * Test the transformation from a Rock Coordinates (rc) System at wc(3,3.5)
 * with positive y axis along wc(2,4.2) into World Coordinates (wc). Uses a
 * Point rc(5,1.3) = wc(8,2.5)./*from   w w w  .ja v a2 s .c  om*/
 */
public void testAffineTransformRotateShift() {
    final Point2D p0_wc = new Point2D.Double(3, 3.5);
    final Rock v0_wc = new RockDouble(2, 4.2, 0.3);
    final double v = v0_wc.distance(0, 0);
    final double[] d = { v0_wc.getY(), -v0_wc.getX(), v0_wc.getX(), v0_wc.getY(), 0, 0 };
    final AffineTransform at = new AffineTransform(d);
    at.scale(1 / v, 1 / v);
    assertEquals(AffineTransform.TYPE_GENERAL_ROTATION + AffineTransform.TYPE_UNIFORM_SCALE, at.getType());
    assertEquals(1.0, at.getDeterminant());
    assertEquals(0.9028605188239303, at.getScaleX());
    assertEquals(at.getScaleX(), at.getScaleY());
    assertEquals(0.42993358039234775, at.getShearX());
    assertEquals(-at.getShearX(), at.getShearY());
    assertEquals(0, at.getTranslateX());
    assertEquals(0, at.getTranslateY());
    Point2D p = null;
    p = at.transform(new Point2D.Double(5, 1.3), null);
    assertEquals("Point2D.Double[5.073216248629703, -0.9759492274906292]", p.toString());

    at.preConcatenate(AffineTransform.getTranslateInstance(p0_wc.getX(), p0_wc.getY()));
    assertEquals(AffineTransform.TYPE_GENERAL_ROTATION + AffineTransform.TYPE_TRANSLATION
            + AffineTransform.TYPE_UNIFORM_SCALE, at.getType());
    assertEquals(1.0, at.getDeterminant());
    assertEquals(0.9028605188239303, at.getScaleX());
    assertEquals(at.getScaleX(), at.getScaleY());
    assertEquals(0.42993358039234775, at.getShearX());
    assertEquals(-at.getShearX(), at.getShearY());
    assertEquals(p0_wc.getX(), at.getTranslateX());
    assertEquals(p0_wc.getY(), at.getTranslateY());

    p = at.transform(new Point2D.Double(5, 1.3), null);
    assertEquals("Point2D.Double[8.073216248629702, 2.524050772509371]", p.toString());
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.SpectraPanel.java

public Peak findPeakAt(Point2D p) {

    if (theDocument.getNoScans() > 0) {
        Point2D dp = screenToDataCoords(p);
        double mz_toll = screenToDataX(3.);
        double int_toll = screenToDataY(3.);
        return findNearestPeak(dp.getX(), dp.getY(), mz_toll, int_toll);
    }/*from   w  w  w . j a  va2 s  .  com*/
    return null;
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

private void xorConnection(AnnotationObject selection, Point start_point, Point end_point) {

    Graphics g = getGraphics();//  ww w.jav a2s .  c om
    g.setXORMode(Color.white);
    g.setColor(Color.gray);

    Rectangle rect = rectangles_complete.get(selection);
    Point2D peak = dataToScreenCoords(selection.getPeakPoint());

    // select anchor
    Point2D anchor = computeAnchor(rect, end_point, peak);

    // draw connection
    g.drawLine((int) anchor.getX(), (int) anchor.getY(), (int) end_point.getX(), (int) end_point.getY());
    g.drawLine((int) end_point.getX(), (int) end_point.getY(), (int) peak.getX(), (int) peak.getY());
}

From source file:lu.lippmann.cdb.graph.GraphViewImpl.java

public void rescaleSatelliteView() {
    //MutableTransformer masterViewTransformer   =  vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW);
    //MutableTransformer masterLayoutTransformer = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT);
    MutableTransformer slaveViewTransformer = vv2.getRenderContext().getMultiLayerTransformer()
            .getTransformer(Layer.VIEW);
    MutableTransformer slaveLayoutTransformer = vv2.getRenderContext().getMultiLayerTransformer()
            .getTransformer(Layer.LAYOUT);

    final Layout<CNode, CEdge> layout = vv.getGraphLayout();
    double minX = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, minY = Integer.MAX_VALUE,
            maxY = Integer.MIN_VALUE;
    final Graph<CNode, CEdge> graph = layout.getGraph();

    double w = 0, h = 0;
    for (final CNode n : graph.getVertices()) {
        final Point2D point = layout.transform(n); //center of the node
        if (point.getX() < minX) {
            minX = point.getX();//  ww  w  . j a  va  2  s .  c  o m
            w = ShapeFactory.createShape(n.getShape()).getBounds().getWidth() / 2;
        }
        if (point.getX() > maxX) {
            maxX = point.getX();
        }
        if (point.getY() < minY) {
            minY = point.getY();
            h = ShapeFactory.createShape(n.getShape()).getBounds().getHeight() / 2;
        }
        if (point.getY() > maxY) {
            maxY = point.getY();
        }
    }

    final double graphWidth = (maxX - minX) + 2 * w;///slaveViewTransformer.getScale(); 
    final double graphHeight = (maxY - minY) + 2 * h;///slaveViewTransformer.getScale();
    final double slaveWidth = vv2.getBounds().getWidth() / slaveViewTransformer.getScale();
    final double slaveHeight = vv2.getBounds().getHeight() / slaveViewTransformer.getScale();

    final double scale1 = (slaveWidth / graphWidth);
    final double scale2 = (slaveHeight / graphHeight);
    final float scale = (float) (Math.min(scale1, scale2)); //to avoid round error 
    if (scale < slaveLayoutTransformer.getScale()) {
        slaveLayoutTransformer.setToIdentity();
        final Point2D graphCenter = GraphUtil.getCenter(
                new HashSet<CNode>(vv.getGraphLayout().getGraph().getVertices()),
                vv.getModel().getGraphLayout());
        //System.out.println("Scaling from center : " + graphCenter +"->" + slaveViewTransformer.transform(graphCenter));
        slaveLayoutTransformer.scale(scale, scale, slaveViewTransformer.transform(graphCenter));
        //System.out.println("Graph center : " + graphCenter);
        //slaveLayoutTransformer.setTranslate(slaveWidth/2-graphCenter.getX()/2,slaveHeight/2-graphCenter.getY()/2);
    } else {
        final double tx = slaveLayoutTransformer.getTranslateX();
        final double ty = slaveLayoutTransformer.getTranslateY();
        if (minX < tx) {
            slaveLayoutTransformer.translate(-minX - tx + w, 0);
        } else if (slaveWidth < maxX) {
            slaveLayoutTransformer.translate(slaveWidth - maxX - tx - w, 0);
        }
        if (minY < ty) {
            slaveLayoutTransformer.translate(0, -minY - ty + h);
        } else if (slaveHeight < maxY) {
            slaveLayoutTransformer.translate(0, slaveHeight - maxY - ty - h);
        }
    }

}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

public AnnotationObject getConnectionAtPoint(Point2D p) {
    for (Map.Entry<AnnotationObject, Polygon> e : connections.entrySet()) {
        if (e.getValue().intersects(p.getX() - 3, p.getY() - 3, 6., 6.))
            return e.getKey();
    }/* ww  w . j  a v a 2  s  . c  om*/
    return null;
}

From source file:edu.dlnu.liuwenpeng.render.BarRenderer.java

/**    
* Draws an item label.  This method is overridden so that the bar can be    
* used to calculate the label anchor point.    
*    //from   w ww .j  a v  a  2 s .  c om
* @param g2  the graphics device.    
* @param data  the dataset.    
* @param row  the row.    
* @param column  the column.    
* @param plot  the plot.    
* @param generator  the label generator.    
* @param bar  the bar.    
* @param negative  a flag indicating a negative value.    
*/
protected void drawItemLabel(Graphics2D g2, CategoryDataset data, int row, int column, CategoryPlot plot,
        CategoryItemLabelGenerator generator, Rectangle2D bar, boolean negative) {

    String label = generator.generateLabel(data, row, column);
    if (label == null) {
        return; // nothing to do    
    }

    Font labelFont = getItemLabelFont(row, column);
    g2.setFont(labelFont);
    Paint paint = getItemLabelPaint(row, column);
    g2.setPaint(paint);

    // find out where to place the label...    
    ItemLabelPosition position = null;
    if (!negative) {
        position = getPositiveItemLabelPosition(row, column);
    } else {
        position = getNegativeItemLabelPosition(row, column);
    }

    // work out the label anchor point...    
    Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation());

    if (isInternalAnchor(position.getItemLabelAnchor())) {
        Shape bounds = TextUtilities.calculateRotatedStringBounds(label, g2, (float) anchorPoint.getX(),
                (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());

        if (bounds != null) {
            if (!bar.contains(bounds.getBounds2D())) {
                if (!negative) {
                    position = getPositiveItemLabelPositionFallback();
                } else {
                    position = getNegativeItemLabelPositionFallback();
                }
                if (position != null) {
                    anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar,
                            plot.getOrientation());
                }
            }
        }

    }

    if (position != null) {
        TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(), position.getRotationAnchor());
    }
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

public Point2D screenToDataCoords(Point2D p) {

    double x = thePlot.getDomainAxis().java2DToValue(p.getX(), data_area, thePlot.getDomainAxisEdge());
    double y = thePlot.getRangeAxis().java2DToValue(p.getY(), data_area, thePlot.getRangeAxisEdge());
    return new Point2D.Double(x, y);
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

public Point2D dataToScreenCoords(Point2D p) {

    double x = thePlot.getDomainAxis().valueToJava2D(p.getX(), data_area, thePlot.getDomainAxisEdge());
    double y = thePlot.getRangeAxis().valueToJava2D(p.getY(), data_area, thePlot.getRangeAxisEdge());
    return new Point2D.Double(x, y);
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

protected void computeConnections() {

    connections = new HashMap<AnnotationObject, Polygon>();
    connections_cp = new HashMap<AnnotationObject, Point2D>();

    for (AnnotationObject a : theDocument.getAnnotations()) {
        Rectangle rect = rectangles_complete.get(a);
        Point2D cp = dataToScreenCoords(theDocument.getControlPoint(a));
        Point2D peak = dataToScreenCoords(a.getPeakPoint());

        // select anchor
        Point2D anchor = computeAnchor(rect, cp, peak);
        boolean add_cp = (peak.getY() > bottom(rect));

        if (anchor.distance(peak) > 10) {
            // create shape
            Polygon connection = new Polygon();
            connection.addPoint((int) anchor.getX(), (int) anchor.getY());
            if (add_cp)
                connection.addPoint((int) cp.getX(), (int) cp.getY());
            connection.addPoint((int) peak.getX(), (int) peak.getY());
            if (add_cp)
                connection.addPoint((int) cp.getX(), (int) cp.getY());

            // save
            connections.put(a, connection);
            if (add_cp)
                connections_cp.put(a, cp);
        }//from   ww w. j a  va 2 s  . c o m
    }
}

From source file:dk.dma.epd.common.prototype.notification.MsiNmNotification.java

/**
 * Returns if the MSI-NM is close the the new route
 *
 * NB: This code was from the old MsiLayer. Should be optimized!
 *
 * @param route the new route/*ww w.  j  a va  2 s.c  o  m*/
 * @param mousePosition the mouse position
 * @param projection the projection
 * @return if the MSI-NM is close the the new route
 */
public boolean nearNewRoute(Route route, Position mousePosition, Projection projection) {

    double visibilityFromNewWaypoint = EPD.getInstance().getSettings().getEnavSettings()
            .getMsiVisibilityFromNewWaypoint();

    // Check if MSI messages should be visible on route.
    boolean visibleOnRoute = false;

    // Go through each waypoint of the route to check if the MSI message should be visible.
    for (int i = 0; !visibleOnRoute && i < route.getWaypoints().size(); i++) {

        RouteWaypoint rWaypoint = route.getWaypoints().get(i);
        Point2D pointA = null;
        Point2D pointB = null;
        Point2D pnt;

        // If the waypoint is not the last placed waypoint compare it to the next in line.
        // Else compare it to the mouse location.
        if (rWaypoint == route.getWaypoints().getLast()) {
            pointA = projection.forward(rWaypoint.getPos().getLatitude(), rWaypoint.getPos().getLongitude());
            pointB = projection.forward(mousePosition.getLatitude(), mousePosition.getLongitude());
        } else if (rWaypoint != route.getWaypoints().getLast()) {
            RouteWaypoint nWaypoint = route.getWaypoints().get(i + 1);
            pointA = projection.forward(rWaypoint.getPos().getLatitude(), rWaypoint.getPos().getLongitude());
            pointB = projection.forward(nWaypoint.getPos().getLatitude(), nWaypoint.getPos().getLongitude());
        }

        // The slope of the line.
        double slope = Math.round(((pointB.getY() - pointA.getY()) / (pointB.getX() - pointA.getX()))
                * visibilityFromNewWaypoint);

        // If the value of slope is more than the value of visibilityFromNewWaypoint,
        // change the slop reverse the x and y axis.
        if (Math.abs(slope) > visibilityFromNewWaypoint) {
            double dy = Math.abs(pointB.getY() - pointA.getY());
            slope = Math.round(((pointB.getX() - pointA.getX()) / (pointB.getY() - pointA.getY()))
                    * visibilityFromNewWaypoint);
            for (int j = 0; j * visibilityFromNewWaypoint < dy; j++) {
                pnt = pointA;

                // The first point should be placed a point where the mouse was clicked.
                if (j == 0) {
                    visibleOnRoute = setMessageVisible(visibilityFromNewWaypoint, visibleOnRoute, projection,
                            pnt);
                    continue;
                }

                //Mouse placed on the right side of the last placed waypoint.
                if (pointA.getX() <= pointB.getX()) {

                    if (slope > 0) {
                        pnt.setLocation(pointA.getX() + slope, pointA.getY() + visibilityFromNewWaypoint);
                    } else if (slope < 0) {
                        double posSlope = Math.abs(slope);
                        pnt.setLocation(pointA.getX() + posSlope, pointA.getY() - visibilityFromNewWaypoint);
                    }

                    // mouse placed on the left side.
                } else if (pointA.getX() > pointB.getX()) {

                    if (slope > 0) {
                        pnt.setLocation(pointA.getX() - slope, pointA.getY() - visibilityFromNewWaypoint);
                    } else if (slope < 0) {
                        double posSlope = Math.abs(slope);
                        pnt.setLocation(pointA.getX() - posSlope, pointA.getY() + visibilityFromNewWaypoint);
                    }
                }

                // Handles placing of point on a vertical line.
                if (pointA.getY() < pointB.getY() && slope == 0) {
                    pnt.setLocation(pointA.getX(), pointA.getY() + visibilityFromNewWaypoint);
                } else if (pointA.getY() > pointB.getY() && slope == 0) {
                    pnt.setLocation(pointA.getX(), pointA.getY() - visibilityFromNewWaypoint);
                }

                visibleOnRoute = setMessageVisible(visibilityFromNewWaypoint, visibleOnRoute, projection, pnt);
            }
        } else {
            double dx = Math.abs(pointB.getX() - pointA.getX());
            for (int j = 0; j * visibilityFromNewWaypoint < dx; j++) {
                pnt = pointA;

                if (j == 0) {
                    visibleOnRoute = setMessageVisible(visibilityFromNewWaypoint, visibleOnRoute, projection,
                            pnt);
                    continue;
                }

                // Mouse placed on the right side of the last placed waypoint.
                if (pointA.getX() <= pointB.getX()) {

                    if (slope > 0) {
                        pnt.setLocation(pointA.getX() + visibilityFromNewWaypoint, pointA.getY() + slope);
                    } else if (slope < 0) {
                        double posSlope = Math.abs(slope);
                        pnt.setLocation(pointA.getX() + visibilityFromNewWaypoint, pointA.getY() - posSlope);
                    }

                    // Mouse placed on the left side of the last placed waypoint.
                } else if (pointA.getX() > pointB.getX()) {

                    if (slope > 0) {
                        pnt.setLocation(pointA.getX() - visibilityFromNewWaypoint, pointA.getY() - slope);
                    } else if (slope < 0) {
                        double posSlope = Math.abs(slope);
                        pnt.setLocation(pointA.getX() - visibilityFromNewWaypoint, pointA.getY() + posSlope);
                    }
                }

                if (pointA.getX() < pointB.getX() && slope == 0) {
                    pnt.setLocation(pointA.getX() + visibilityFromNewWaypoint, pointA.getY());
                } else if (pointA.getX() > pointB.getX() && slope == 0) {
                    pnt.setLocation(pointA.getX() - visibilityFromNewWaypoint, pointA.getY());
                }

                visibleOnRoute = setMessageVisible(visibilityFromNewWaypoint, visibleOnRoute, projection, pnt);
            }
        }
    }

    return visibleOnRoute;
}