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:org.apache.joshua.ui.tree_visualizer.DerivationTreeTransformer.java

public Point2D transform(Node n) {
    double x, y;/* w w  w.java2 s . c  o m*/
    Point2D t = treeLayout.transform(n);
    if (n.isSource) {
        x = /* treeLayout.transform(root).getX() + */(t.getX() - treeLayout.transform(sourceRoot).getX()
                + treeLayout.transform(root).getX());
        y = Y_DIST * (distanceToLeaf(n) + 1);
    } else {
        x = t.getX();
        y = Y_DIST * (-1) * distanceToLeaf(n);
    }
    if (isAnchored) {
        x += anchorPoint.getX();
        y += anchorPoint.getY();
    }
    return new Point2D.Double(x, y + Y_DIST * (1 + distanceToLeaf(root)));
}

From source file:org.apache.geode.geospatial.client.Roads.java

private Coordinate convert(Point2D point2D) {
    return new Coordinate(point2D.getX(), point2D.getY());
}

From source file:edu.uci.ics.jung.visualization.decorators.GradientEdgePaintTransformer.java

public Paint transform(E e) {
    Layout<V, E> layout = vv.getGraphLayout();
    Pair<V> p = layout.getGraph().getEndpoints(e);
    V b = p.getFirst();/*from www .ja v  a  2  s  . c  om*/
    V f = p.getSecond();
    Point2D pb = transformer.transform(layout.transform(b));
    Point2D pf = transformer.transform(layout.transform(f));
    float xB = (float) pb.getX();
    float yB = (float) pb.getY();
    float xF = (float) pf.getX();
    float yF = (float) pf.getY();
    if ((layout.getGraph().getEdgeType(e)) == EdgeType.UNDIRECTED) {
        xF = (xF + xB) / 2;
        yF = (yF + yB) / 2;
    }
    if (selfLoop.evaluate(Context.<Graph<V, E>, E>getInstance(layout.getGraph(), e))) {
        yF += 50;
        xF += 50;
    }

    return new GradientPaint(xB, yB, getColor1(e), xF, yF, getColor2(e), true);
}

From source file:inflor.core.gates.ui.PolygonGateAdapter.java

@Override
public void mouseMoved(MouseEvent e) {
    if (anchorSegment != null) {
        panel.removeTemporaryAnnotation(anchorSegment);
    }//from w ww. j av a 2  s  . c  o  m
    if (anchorPoint != null) {
        Point2D p = ChartUtils.getPlotCoordinates(e, panel);
        anchorSegment = new XYLineAnnotation(anchorPoint.getX(), anchorPoint.getY(), p.getX(), p.getY());
        panel.addTemporaryAnnotation(anchorSegment);
    }
}

From source file:inflor.core.gates.ui.RectangleGateAnnotation.java

@Override
public boolean matchesVertex(Point2D v, double xHandleSize, double yHandleSize) {
    double xMin = (v.getX() - xHandleSize);
    double xMax = (v.getX() + xHandleSize);
    double yMin = (v.getY() - yHandleSize);
    double yMax = (v.getY() + yHandleSize);
    boolean xMatches = false;
    boolean yMatches = false;
    if ((xMin <= x0 && x0 <= xMax) || (xMin <= x1 && x1 <= xMax)) {
        xMatches = true;//  www  . j a v a  2 s  . co  m
    }
    if ((yMin <= y0 && y0 <= yMax) || (yMin <= y1 && y1 <= yMax)) {
        yMatches = true;
    }
    if (xMatches && yMatches) {
        return true;
    }
    return false;
}

From source file:ca.ubc.cs.ferret.cg.VertexLabelAsShapeRenderer.java

/**
 * Labels the specified vertex with the specified label.  
 * Uses the font specified by this instance's 
 * <code>VertexFontFunction</code>.  (If the font is unspecified, the existing
 * font for the graphics context is used.)  If vertex label centering
 * is active, the label is centered on the position of the vertex; otherwise
  * the label is offset slightly.// w  w  w  .  j a  v  a  2  s . c om
  */
public void labelVertex(RenderContext<V, E> rc, Layout<V, E> layout, V v, String label) {
    Graph<V, E> graph = layout.getGraph();
    if (rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V>getInstance(graph, v)) == false) {
        return;
    }
    GraphicsDecorator g = rc.getGraphicsContext();
    Component component = prepareRenderer(rc, rc.getVertexLabelRenderer(), label,
            rc.getPickedVertexState().isPicked(v), v);
    Dimension d = component.getPreferredSize();

    int h_offset = -d.width / 2;
    int v_offset = -d.height / 2;

    Point2D p = layout.transform(v);
    p = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p);

    int x = (int) p.getX();
    int y = (int) p.getY();

    g.draw(component, rc.getRendererPane(), x + h_offset, y + v_offset, d.width, d.height, true);

    Dimension size = component.getPreferredSize();
    Rectangle bounds = new Rectangle(-size.width / 2 - 2, -size.height / 2 - 2, size.width + 4, size.height);
    shapes.put(v, bounds);
}

From source file:be.ugent.maf.cellmissy.analysis.singlecell.processing.impl.EnclosingBallCalculatorImpl.java

@Override
public List<EnclosingBall> findEnclosingBalls(double[] firstDimension, double[] secondDimension,
        KDTree<Point2D> tree, double eps) {

    // an empty list of enclosing balls
    List<EnclosingBall> enclosingBalls = new ArrayList<>();
    // first ball: always add it to the list
    Point2D m_0 = new Point2D.Double(firstDimension[0], secondDimension[0]);
    Ellipse2D ball = new Ellipse2D.Double();
    ball.setFrameFromCenter(m_0.getX(), m_0.getY(), m_0.getX() + eps, m_0.getY() + eps);
    // make a new enclosing ball object
    EnclosingBall enclosingBall = new EnclosingBall(ball, eps);
    enclosingBall.getEnclosingPoints().add(m_0);
    enclosingBalls.add(enclosingBall);/*from   w w w.  j  av  a  2  s  . com*/

    // now start counting from 1
    for (int i = 1; i < firstDimension.length; i++) {
        Point2D m_i = new Point2D.Double(firstDimension[i], secondDimension[i]);
        // try to get the points close to the current point:
        // i.e. points m_i such that ||m_i - m_t|| 2 <= radius 
        try {
            List<Point2D> nearestPoints = tree.nearestEuclidean(new double[] { m_i.getX(), m_i.getY() }, eps);
            for (Point2D nearest : nearestPoints) {
                EnclosingBall whichBallContainsPoint = whichBallContainsPoint(enclosingBalls, nearest);
                if (whichBallContainsPoint != null) {
                    if (!whichBallContainsPoint.getEnclosingPoints().contains(m_i)) {
                        whichBallContainsPoint.getEnclosingPoints().add(m_i);
                    }
                } else {
                    ball = new Ellipse2D.Double();
                    ball.setFrameFromCenter(nearest.getX(), nearest.getY(), nearest.getX() + eps,
                            nearest.getY() + eps);
                    enclosingBall = new EnclosingBall(ball, eps);
                    enclosingBall.getEnclosingPoints().add(nearest);
                    if (!enclosingBalls.contains(enclosingBall)) {
                        enclosingBalls.add(enclosingBall);
                    }
                }
            }
        } catch (KeySizeException ex) {
            Logger.getLogger(EnclosingBallCalculatorImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return enclosingBalls;
}

From source file:edu.uci.ics.jung.visualization.control.LabelEditingGraphMousePlugin.java

/**
 * For primary modifiers (default, MouseButton1):
 * pick a single Vertex or Edge that/*from w  ww  .  j  a va 2 s  .  c  o m*/
  * is under the mouse pointer. If no Vertex or edge is under
  * the pointer, unselect all picked Vertices and edges, and
  * set up to draw a rectangle for multiple selection
  * of contained Vertices.
  * For additional selection (default Shift+MouseButton1):
  * Add to the selection, a single Vertex or Edge that is
  * under the mouse pointer. If a previously picked Vertex
  * or Edge is under the pointer, it is un-picked.
  * If no vertex or Edge is under the pointer, set up
  * to draw a multiple selection rectangle (as above)
  * but do not unpick previously picked elements.
 * 
 * @param e the event
 */
@SuppressWarnings("unchecked")
public void mouseClicked(MouseEvent e) {
    if (e.getModifiers() == modifiers && e.getClickCount() == 2) {
        VisualizationViewer<V, E> vv = (VisualizationViewer) e.getSource();
        GraphElementAccessor<V, E> pickSupport = vv.getPickSupport();
        if (pickSupport != null) {
            Transformer<V, String> vs = vv.getRenderContext().getVertexLabelTransformer();
            if (vs instanceof MapTransformer) {
                Map<V, String> map = ((MapTransformer) vs).getMap();
                Layout<V, E> layout = vv.getGraphLayout();
                // p is the screen point for the mouse event
                Point2D p = e.getPoint();

                V vertex = pickSupport.getVertex(layout, p.getX(), p.getY());
                if (vertex != null) {
                    String newLabel = vs.transform(vertex);
                    newLabel = JOptionPane.showInputDialog("New Vertex Label for " + vertex);
                    if (newLabel != null) {
                        map.put(vertex, newLabel);
                        vv.repaint();
                    }
                    return;
                }
            }
            Transformer<E, String> es = vv.getRenderContext().getEdgeLabelTransformer();
            if (es instanceof MapTransformer) {
                Map<E, String> map = ((MapTransformer) es).getMap();
                Layout<V, E> layout = vv.getGraphLayout();
                // p is the screen point for the mouse event
                Point2D p = e.getPoint();
                // take away the view transform
                Point2D ip = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.VIEW, p);
                E edge = pickSupport.getEdge(layout, ip.getX(), ip.getY());
                if (edge != null) {
                    String newLabel = JOptionPane.showInputDialog("New Edge Label for " + edge);
                    if (newLabel != null) {
                        map.put(edge, newLabel);
                        vv.repaint();
                    }
                    return;
                }
            }
        }
        e.consume();
    }
}

From source file:algorithms.MedianDivergenceComputer.java

private void deriveMedianColormapToJNDRatio() {
    int len = points.size() / 2;
    ratios = new double[len];
    Iterator<Point2D> ptIt = points.iterator();

    int i = 0;/*w w  w  .  j  av a 2 s . c om*/
    while (i < len && ptIt.hasNext()) {
        Point2D p1 = ptIt.next();
        Point2D p2 = ptIt.next();

        double dist = p1.distance(p2);

        Color colorA = colormap.getColor(p1.getX(), p1.getY());
        Color colorB = colormap.getColor(p2.getX(), p2.getY());

        // color distance
        double cdist = colorDiff(colorA, colorB);

        // filter zero divisions, as long as the value distance is small
        // DON'T protect colormaps that contain duplicate colors
        if (cdist == 0 && dist < 0.05)
            continue;
        double ratio = cdist / dist;
        ratios[i] = ratio;
        i++;
    }
    Arrays.sort(ratios);
}

From source file:inflor.core.gates.ui.RectangleGateAnnotation.java

@Override
public XYGateAnnotation updateVertex(Point2D v, double dx, double dy, double xHandleSize, double yHandleSize) {
    double xMin = (v.getX() - xHandleSize);
    double xMax = (v.getX() + xHandleSize);
    double yMin = (v.getY() - yHandleSize);
    double yMax = (v.getY() + yHandleSize);

    if ((xMin <= x0 && x0 <= xMax)) {
        x0 = x0 + dx;/*from   w ww.  ja v a 2  s.  c o  m*/
    }
    if ((xMin <= x1 && x1 <= xMax)) {
        x1 = x1 + dx;
    }
    if ((yMin <= y0 && y0 <= yMax)) {
        y0 = y0 + dy;
    }
    if ((yMin <= y1 && y1 <= yMax)) {
        y1 = y1 + dy;
    }

    return new RectangleGateAnnotation(subsetName, domainAxisName, rangeAxisName, x0, y0, x1, y1,
            LookAndFeel.SELECTED_STROKE, LookAndFeel.SELECTED_GATE_COLOR);
}