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:edu.uci.ics.jung.visualization.picking.ShapePickSupport.java

/**
 * Returns an edge whose shape intersects the 'pickArea' footprint of the passed
 * x,y, coordinates.// w  ww . j av a 2 s  . c o m
 */
public E getEdge(Layout<V, E> layout, double x, double y) {

    Point2D ip = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.VIEW,
            new Point2D.Double(x, y));
    x = ip.getX();
    y = ip.getY();

    // as a Line has no area, we can't always use edgeshape.contains(point) so we
    // make a small rectangular pickArea around the point and check if the
    // edgeshape.intersects(pickArea)
    Rectangle2D pickArea = new Rectangle2D.Float((float) x - pickSize / 2, (float) y - pickSize / 2, pickSize,
            pickSize);
    E closest = null;
    double minDistance = Double.MAX_VALUE;
    while (true) {
        try {
            for (E e : getFilteredEdges(layout)) {

                Shape edgeShape = getTransformedEdgeShape(layout, e);
                if (edgeShape == null)
                    continue;

                // because of the transform, the edgeShape is now a GeneralPath
                // see if this edge is the closest of any that intersect
                if (edgeShape.intersects(pickArea)) {
                    float cx = 0;
                    float cy = 0;
                    float[] f = new float[6];
                    PathIterator pi = new GeneralPath(edgeShape).getPathIterator(null);
                    if (pi.isDone() == false) {
                        pi.next();
                        pi.currentSegment(f);
                        cx = f[0];
                        cy = f[1];
                        if (pi.isDone() == false) {
                            pi.currentSegment(f);
                            cx = f[0];
                            cy = f[1];
                        }
                    }
                    float dx = (float) (cx - x);
                    float dy = (float) (cy - y);
                    float dist = dx * dx + dy * dy;
                    if (dist < minDistance) {
                        minDistance = dist;
                        closest = e;
                    }
                }
            }
            break;
        } catch (ConcurrentModificationException cme) {
        }
    }
    return closest;
}

From source file:lu.lippmann.cdb.graph.mouse.CadralEditingGraphMousePlugin.java

/**
 * {@inheritDoc}/*from ww  w  .  java2 s .c  o m*/
 */
@Override
public void mouseReleased(MouseEvent e) {
    //Don't create node or edge with right click !
    if (!e.isPopupTrigger()) {
        @SuppressWarnings("unchecked")
        final VisualizationViewer<CNode, CEdge> vv = (VisualizationViewer<CNode, CEdge>) e.getSource();

        final Point2D p = e.getPoint();
        final Layout<CNode, CEdge> layout = vv.getModel().getGraphLayout();
        final GraphWithOperations graph = (GraphWithOperations) layout.getGraph();

        final GraphElementAccessor<CNode, CEdge> pickSupport = vv.getPickSupport();

        if (pickSupport != null) {
            CNode vertex = pickSupport.getVertex(layout, p.getX(), p.getY());
            // if no vertex create one on the fly
            if (vertex == null) {
                final CNode newNode = vertexFactory.create();
                final Point2D newPos = vv.getRenderContext().getMultiLayerTransformer()
                        .inverseTransform(e.getPoint());
                graph.addVertex(newNode, new CPoint(newPos.getX(), newPos.getY()));
                layout.lock(newNode, false);
                vertex = newNode;
            } else {
                //reset to initial color if needed
                if (startVertex != null && !startVertex.equals(vertex)) {
                    if (pointedVertices.containsKey(vertex)) {
                        vertex.setColor(pointedVertices.get(vertex));
                    }
                }
                layout.lock(vertex, false);
            }
            // if the source & destination vertex are not the same : create edge
            if (vertex != null && startVertex != null) {
                if (!startVertex.equals(vertex)) {
                    transformEdgeShape(down, down);
                    transformArrowShape(down, e.getPoint());
                    graph.addEdge(edgeFactory.create(), startVertex, vertex, edgeIsDirected);
                }
            }
        }
        //Reset fields
        startVertex = null;
        down = null;
        edgeIsDirected = EdgeType.UNDIRECTED;
        vv.removePostRenderPaintable(edgePaintable);
        vv.removePostRenderPaintable(arrowPaintable);

        //clear color mapping map
        pointedVertices.clear();
        dragVertex = null;
        lastDragVertex = null;

        vv.repaint();
    }
}

From source file:edu.uci.ics.jung.algorithms.layout.SpringLayout.java

protected void moveNodes() {
    synchronized (getSize()) {
        try {//from w ww  . ja va  2s  . c o m
            for (V v : getGraph().getVertices()) {
                if (isLocked(v))
                    continue;
                SpringVertexData vd = springVertexData.get(v);
                if (vd == null)
                    continue;
                Point2D xyd = transform(v);

                vd.dx += vd.repulsiondx + vd.edgedx;
                vd.dy += vd.repulsiondy + vd.edgedy;

                // keeps nodes from moving any faster than 5 per time unit
                xyd.setLocation(xyd.getX() + Math.max(-5, Math.min(5, vd.dx)),
                        xyd.getY() + Math.max(-5, Math.min(5, vd.dy)));

                Dimension d = getSize();
                int width = d.width;
                int height = d.height;

                if (xyd.getX() < 0) {
                    xyd.setLocation(0, xyd.getY());
                } else if (xyd.getX() > width) {
                    xyd.setLocation(width, xyd.getY());
                }
                if (xyd.getY() < 0) {
                    xyd.setLocation(xyd.getX(), 0);
                } else if (xyd.getY() > height) {
                    xyd.setLocation(xyd.getX(), height);
                }

            }
        } catch (ConcurrentModificationException cme) {
            moveNodes();
        }
    }
}

From source file:com.sdk.connector.chart.TimeDomainRenderer.java

@Override
public void chartMouseClicked(ChartMouseEvent cme) {
    ChartEntity chartentity = cme.getEntity();
    //JOptionPane.showMessageDialog(null,chartentity.getClass(), "",JOptionPane.CANCEL_OPTION);

    if (cme.getEntity() instanceof PlotEntity) {
        if (chartentity != null) {
            Point2D p = chartPanel.translateScreenToJava2D(cme.getTrigger().getPoint());
            final Rectangle2D plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
            double chartX = plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge());
            double chartY = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge());

            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis((long) chartX);
            createAnnotation(formatter.format(calendar.getTime()), chartX, chartY);
        } else {/*from ww w.  ja va 2s  .c  o  m*/

        }
    }
}

From source file:org.jcurl.demo.tactics.old.MenuView.java

private void zoom(final Point2D center, final double ratio, final int dt) {
    if (getModel() == null)
        return;//from  w w w.  jav  a 2  s.  co  m
    final RectangularShape src = getModel().getZoom();
    if (log.isDebugEnabled())
        log.debug(src);
    final double w = src.getWidth() * ratio;
    final double h = src.getHeight() * ratio;
    final double cx, cy;
    if (center == null) {
        cx = src.getCenterX();
        cy = src.getCenterY();
    } else {
        cx = center.getX();
        cy = center.getY();
    }
    zoom(new Rectangle2D.Double(cx - w / 2, cy - h / 2, Math.abs(w), Math.abs(h)), dt);
}

From source file:jmeanshift.ChartProof.java

@Override
public void chartMouseClicked(ChartMouseEvent cme) {
    ChartEntity chartentity = cme.getEntity();
    if (chartentity != null) {
        Point2D p = chartPanel.translateScreenToJava2D(cme.getTrigger().getPoint());
        final Rectangle2D plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
        int i = (int) plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge());
        int j = (int) plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge());
        series.addOrUpdate(i, j);//w  ww. j av a2  s  .  c o  m
        data1.add((double) i);
        data2.add((double) j);
    } else {

    }

}

From source file:net.sf.fspdfs.chartthemes.spring.ScaledDialPointer.java

/**
 * Draws the pointer./*w  ww  .  jav a  2 s .c  o m*/
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    g2.setStroke(new BasicStroke(1.0f));
    Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame, this.getRadius(), this.getRadius());
    Rectangle2D widthRect = DialPlot.rectangleByRadius(frame, this.getWidthRadius(), this.getWidthRadius());
    double value = ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale);
    DialScale scale = plot.getScaleForDataset(this.getDatasetIndex());
    double angle = scale.valueToAngle(value);

    Arc2D arc1 = new Arc2D.Double(lengthRect, angle, 0, Arc2D.OPEN);
    Point2D pt1 = arc1.getEndPoint();
    Arc2D arc2 = new Arc2D.Double(widthRect, angle - 90.0, 180.0, Arc2D.OPEN);
    Point2D pt2 = arc2.getStartPoint();
    Point2D pt3 = arc2.getEndPoint();
    Arc2D arc3 = new Arc2D.Double(widthRect, angle - 180.0, 0.0, Arc2D.OPEN);
    Point2D pt4 = arc3.getStartPoint();

    GeneralPath gp = new GeneralPath();
    gp.moveTo((float) pt1.getX(), (float) pt1.getY());
    gp.lineTo((float) pt2.getX(), (float) pt2.getY());
    gp.lineTo((float) pt4.getX(), (float) pt4.getY());
    gp.lineTo((float) pt3.getX(), (float) pt3.getY());
    gp.closePath();
    g2.setPaint(this.fillPaint);
    g2.fill(gp);

    g2.setPaint(this.getOutlinePaint());
    Line2D line = new Line2D.Double(frame.getCenterX(), frame.getCenterY(), pt1.getX(), pt1.getY());
    //      g2.draw(line);

    line.setLine(pt2, pt3);
    g2.draw(line);

    line.setLine(pt3, pt1);
    g2.draw(line);

    line.setLine(pt2, pt1);
    g2.draw(line);

    line.setLine(pt2, pt4);
    g2.draw(line);

    line.setLine(pt3, pt4);
    g2.draw(line);
}

From source file:net.sf.jasperreports.chartthemes.spring.ScaledDialPointer.java

/**
 * Draws the pointer./*from  w  w w . ja  v  a  2 s  .  co m*/
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    g2.setStroke(new BasicStroke(1.0f));
    Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame, this.getRadius(), this.getRadius());
    Rectangle2D widthRect = DialPlot.rectangleByRadius(frame, this.getWidthRadius(), this.getWidthRadius());
    double value = ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale);
    DialScale scale = plot.getScaleForDataset(this.getDatasetIndex());
    double angle = scale.valueToAngle(value);

    Arc2D arc1 = new Arc2D.Double(lengthRect, angle, 0, Arc2D.OPEN);
    Point2D pt1 = arc1.getEndPoint();
    Arc2D arc2 = new Arc2D.Double(widthRect, angle - 90.0, 180.0, Arc2D.OPEN);
    Point2D pt2 = arc2.getStartPoint();
    Point2D pt3 = arc2.getEndPoint();
    Arc2D arc3 = new Arc2D.Double(widthRect, angle - 180.0, 0.0, Arc2D.OPEN);
    Point2D pt4 = arc3.getStartPoint();

    GeneralPath gp = new GeneralPath();
    gp.moveTo((float) pt1.getX(), (float) pt1.getY());
    gp.lineTo((float) pt2.getX(), (float) pt2.getY());
    gp.lineTo((float) pt4.getX(), (float) pt4.getY());
    gp.lineTo((float) pt3.getX(), (float) pt3.getY());
    gp.closePath();
    g2.setPaint(this.fillPaint);
    g2.fill(gp);

    g2.setPaint(this.getOutlinePaint());
    Line2D line = new Line2D.Double(frame.getCenterX(), frame.getCenterY(), pt1.getX(), pt1.getY());
    //      g2.draw(line);

    line.setLine(pt2, pt3);
    g2.draw(line);

    line.setLine(pt3, pt1);
    g2.draw(line);

    line.setLine(pt2, pt1);
    g2.draw(line);

    line.setLine(pt2, pt4);
    g2.draw(line);

    line.setLine(pt3, pt4);
    g2.draw(line);
}

From source file:org.jax.maanova.plot.MaanovaChartPanel.java

/**
 * Convert the given point in java2d coordinates to chart coordinates.
 * @param java2DPoint the point to convert
 * @return the converted point/*  ww  w . j  a v a 2  s. c  o m*/
 * @throws ClassCastException the plot isn't an XYPlot
 */
public Point2D toChartPoint(Point2D java2DPoint) throws ClassCastException {
    XYPlot plot = this.getChart().getXYPlot();
    Rectangle2D dataArea = this.chartRenderingInfo.getPlotInfo().getDataArea();

    double graphX = plot.getDomainAxis().java2DToValue(java2DPoint.getX(), dataArea, plot.getDomainAxisEdge());
    double graphY = plot.getRangeAxis().java2DToValue(java2DPoint.getY(), dataArea, plot.getRangeAxisEdge());

    return new Point2D.Double(graphX, graphY);
}

From source file:org.opensha.commons.data.function.EvenlyDiscretizedFunc.java

/**
 *
 * @return value of each point in the function in String format
 *///  w w  w .ja  va 2s  .c om
public String getMetadataString() {
    StringBuffer b = new StringBuffer();
    Iterator<Point2D> it2 = this.iterator();

    while (it2.hasNext()) {

        Point2D point = (Point2D) it2.next();
        double x = point.getX();
        double y = point.getY();
        b.append((float) x + "\t  " + (float) y + '\n');
    }
    return b.toString();
}