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.algorithms.layout.FRLayout2.java

protected void calcRepulsion(V v1) {
    Point2D fvd1 = frVertexData.get(v1);
    if (fvd1 == null)
        return;//from   ww w . j a v  a2s.  c  o m
    fvd1.setLocation(0, 0);
    boolean v1_locked = isLocked(v1);

    try {
        for (V v2 : getGraph().getVertices()) {

            boolean v2_locked = isLocked(v2);
            if (v1_locked && v2_locked)
                continue;
            if (v1 != v2) {
                Point2D p1 = transform(v1);
                Point2D p2 = transform(v2);
                if (p1 == null || p2 == null)
                    continue;
                double xDelta = p1.getX() - p2.getX();
                double yDelta = p1.getY() - p2.getY();

                double deltaLength = Math.max(EPSILON, p1.distanceSq(p2));

                double force = (repulsion_constant * repulsion_constant);// / deltaLength;

                double forceOverDeltaLength = force / deltaLength;

                assert Double.isNaN(
                        force) == false : "Unexpected mathematical result in FRLayout:calcPositions [repulsion]";

                if (v2_locked) {
                    // double the offset for v1, as v2 will not be moving in
                    // the opposite direction
                    fvd1.setLocation(fvd1.getX() + 2 * xDelta * forceOverDeltaLength,
                            fvd1.getY() + 2 * yDelta * forceOverDeltaLength);
                } else {
                    fvd1.setLocation(fvd1.getX() + xDelta * forceOverDeltaLength,
                            fvd1.getY() + yDelta * forceOverDeltaLength);
                }
            }
        }
    } catch (ConcurrentModificationException cme) {
        calcRepulsion(v1);
    }
}

From source file:Visualizer.SpringLayoutWeighted.java

protected void relaxEdges() {
    try {//w  w w.j  a v  a2  s .  c o  m
        for (Functionality.Edge e : getGraph().getEdges()) {
            Pair<Functionality.Node> endpoints = getGraph().getEndpoints(e);
            Functionality.Node v1 = endpoints.getFirst();
            Functionality.Node v2 = endpoints.getSecond();

            Point2D p1 = transform(v1);
            Point2D p2 = transform(v2);
            if (p1 == null || p2 == null)
                continue;
            double vx = p1.getX() - p2.getX();
            double vy = p1.getY() - p2.getY();
            double len = Math.sqrt(vx * vx + vy * vy);

            double desiredLen = lengthFunction.transform(e);

            // round from zero, if needed [zero would be Bad.].
            len = (len == 0) ? .0001 : len;

            double f = force_multiplier * (desiredLen - len) / len;

            if (DataModule.displayedGraph.edgeIsDotted(v1, v2)) {
                f = f / 2.5;
            }

            if (DataModule.displayedGraph.edgeIsNormal(v1, v2)) {
                f = f / 1.7;
            }

            f = f * Math.pow(stretch, (getGraph().degree(v1) + getGraph().degree(v2) - 2));

            // the actual movement distance 'dx' is the force multiplied by the
            // distance to go.
            double dx = f * vx;
            double dy = f * vy;
            SpringVertexData v1D, v2D;
            v1D = springVertexData.get(v1);
            v2D = springVertexData.get(v2);

            v1D.edgedx += dx;
            v1D.edgedy += dy;
            v2D.edgedx += -dx;
            v2D.edgedy += -dy;
        }
    } catch (ConcurrentModificationException cme) {
        relaxEdges();
    }
}

From source file:Visualizer.FRWeightedLayout.java

protected void calcRepulsion(Functionality.Node v1) {
    FRVertexData fvd1 = getFRData(v1);/*from  w  ww. j  a v a 2  s .c o m*/
    if (fvd1 == null)
        return;
    fvd1.setLocation(0, 0);

    try {
        for (Functionality.Node v2 : getGraph().getVertices()) {

            //                if (isLocked(v2)) continue;
            if (v1 != v2) {
                Point2D p1 = transform(v1);
                Point2D p2 = transform(v2);
                if (p1 == null || p2 == null)
                    continue;
                double xDelta = p1.getX() - p2.getX();
                double yDelta = p1.getY() - p2.getY();

                double deltaLength = Math.max(EPSILON, Math.sqrt((xDelta * xDelta) + (yDelta * yDelta)));

                double force = (repulsion_constant * repulsion_constant) / deltaLength;

                if (Double.isNaN(force)) {
                    throw new RuntimeException(
                            "Unexpected mathematical result in FRWeightedLayout:calcPositions [repulsion]");
                }

                fvd1.offset((xDelta / deltaLength) * force, (yDelta / deltaLength) * force);
            }
        }
    } catch (ConcurrentModificationException cme) {
        calcRepulsion(v1);
    }
}

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

/**
 * Returns the location of the vertex.  The location is specified first
 * by the sublayouts, and then by the base layout if no sublayouts operate
 * on this vertex.//from   w  w w.j a v a  2  s . c o m
 * @return the location of the vertex
 * @see org.apache.commons.collections15.Transformer#transform(java.lang.Object)
 */
public Point2D transform(V v) {
    boolean wasInSublayout = false;
    for (Layout<V, E> layout : layouts.keySet()) {
        if (layout.getGraph().getVertices().contains(v)) {
            wasInSublayout = true;
            Point2D center = layouts.get(layout);
            // transform by the layout itself, but offset to the
            // center of the sublayout
            Dimension d = layout.getSize();
            AffineTransform at = AffineTransform.getTranslateInstance(center.getX() - d.width / 2,
                    center.getY() - d.height / 2);
            return at.transform(layout.transform(v), null);
        }
    }
    if (wasInSublayout == false) {
        return delegate.transform(v);
    }
    return null;

}

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

/**
 * @param v//from w  ww . j  ava 2  s .c o m
 * @param location
 * @see edu.uci.ics.jung.algorithms.layout.Layout#setLocation(java.lang.Object, java.awt.geom.Point2D)
 */
public void setLocation(V v, Point2D location) {
    boolean wasInSublayout = false;
    for (Layout<V, E> layout : layouts.keySet()) {
        if (layout.getGraph().getVertices().contains(v)) {
            Point2D center = layouts.get(layout);
            // transform by the layout itself, but offset to the
            // center of the sublayout
            Dimension d = layout.getSize();

            AffineTransform at = AffineTransform.getTranslateInstance(-center.getX() + d.width / 2,
                    -center.getY() + d.height / 2);
            Point2D localLocation = at.transform(location, null);
            layout.setLocation(v, localLocation);
            wasInSublayout = true;
        }
    }
    if (wasInSublayout == false && getGraph().getVertices().contains(v)) {
        delegate.setLocation(v, location);
    }
}

From source file:Visualizer.SpringLayoutWeighted.java

protected void calculateRepulsion() {
    try {//from   ww w .  j  a  va 2 s. c o  m
        for (Functionality.Node v : getGraph().getVertices()) {
            if (isLocked(v))
                continue;

            SpringVertexData svd = springVertexData.get(v);
            if (svd == null)
                continue;
            double dx = 0, dy = 0;

            for (Functionality.Node v2 : getGraph().getVertices()) {
                if (v == v2)
                    continue;
                Point2D p = transform(v);
                Point2D p2 = transform(v2);
                if (p == null || p2 == null)
                    continue;
                double vx = p.getX() - p2.getX();
                double vy = p.getY() - p2.getY();
                double distanceSq = p.distanceSq(p2);
                if (distanceSq == 0) {
                    dx += Math.random();
                    dy += Math.random();
                } else if (distanceSq < repulsion_range_sq) {
                    double factor = 1;
                    dx += factor * vx / distanceSq;
                    dy += factor * vy / distanceSq;
                }
            }
            double dlen = dx * dx + dy * dy;
            if (dlen > 0) {
                dlen = Math.sqrt(dlen) / 2;
                svd.repulsiondx += dx / dlen;
                svd.repulsiondy += dy / dlen;
            }
        }
    } catch (ConcurrentModificationException cme) {
        calculateRepulsion();
    }
}

From source file:util.ModSpringLayout.java

protected void relaxEdges() {
    try {//from   w  ww .  j  a  v a 2  s . co  m
        for (E e : getGraph().getEdges()) {
            Pair<V> endpoints = getGraph().getEndpoints(e);
            V v1 = endpoints.getFirst();
            V v2 = endpoints.getSecond();

            Point2D p1 = transform(v1);
            Point2D p2 = transform(v2);
            if (p1 == null || p2 == null) {
                continue;
            }
            double vx = p1.getX() - p2.getX();
            double vy = p1.getY() - p2.getY();
            double len = Math.sqrt(vx * vx + vy * vy);

            double desiredLen = lengthFunction.transform(e);

            // round from zero, if needed [zero would be Bad.].
            len = (len == 0) ? .0001 : len;

            double f = force_multiplier * (desiredLen - len) / len;

            f = f * Math.pow(stretch, (getGraph().degree(v1) + getGraph().degree(v2) - 2));

            // the actual movement distance 'dx' is the force multiplied by the
            // distance to go.
            double dx = f * vx;
            double dy = f * vy;
            SpringVertexData v1D, v2D;
            v1D = springVertexData.get(v1);
            v2D = springVertexData.get(v2);

            v1D.edgedx += dx;
            v1D.edgedy += dy;
            v2D.edgedx += -dx;
            v2D.edgedy += -dy;
        }
    } catch (ConcurrentModificationException cme) {
        relaxEdges();
    }
}

From source file:org.apache.fontbox.cff.CharStringRenderer.java

private void rrcurveTo(Number dx1, Number dy1, Number dx2, Number dy2, Number dx3, Number dy3) {
    Point2D point = path.getCurrentPoint();
    float x1 = (float) point.getX() + dx1.floatValue();
    float y1 = (float) point.getY() + dy1.floatValue();
    float x2 = x1 + dx2.floatValue();
    float y2 = y1 + dy2.floatValue();
    float x3 = x2 + dx3.floatValue();
    float y3 = y2 + dy3.floatValue();
    path.curveTo(x1, y1, x2, y2, x3, y3);
}

From source file:vnreal.gui.control.MyEditingPopupGraphMousePlugin.java

@SuppressWarnings("unchecked")
@Override/*from  ww  w .j a v a  2  s . c  om*/
protected void createGeneralMenuEntries(final Point point, final N graph, final LayerViewer<V, E> vv) {
    JMenuItem mi;
    // creating a node
    mi = new JMenuItem("Create node");
    final int layer = vv.getLayer().getLayer();
    mi.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // adding an resource/demand
            boolean addConstraint = true;
            V node = vertexFactory.create();
            Point2D p2 = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(point);
            node.setCoordinateX(p2.getX());
            node.setCoordinateY(p2.getY());

            while (addConstraint) {
                new AddConstraintDialog(node, layer, GUI.getInstance(), new Dimension(300, 150));
                // if a resource/demand has been added
                if (node.get().size() > 0) {
                    addConstraint = false;
                    @SuppressWarnings("rawtypes")
                    Network net = ToolKit.getScenario().getNetworkStack().getLayer(layer);
                    if ((net instanceof SubstrateNetwork
                            && ((SubstrateNetwork) net).addVertex((SubstrateNode) node))
                            || (net instanceof VirtualNetwork
                                    && ((VirtualNetwork) net).addVertex((VirtualNode) node))) {
                        vv.updateUI();
                    } else {
                        throw new AssertionError("Adding Node failed.");
                    }
                } else {
                    String cons = (layer == 0 ? "Resource" : "Demand");

                    int option = JOptionPane.showConfirmDialog(GUI.getInstance(),
                            "A " + cons + " must be added for the node to be created!", "Create Node",
                            JOptionPane.OK_CANCEL_OPTION);
                    if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
                        addConstraint = false;
                    }
                }
            }
        }
    });
    popup.add(mi);

    popup.addSeparator();

    @SuppressWarnings("rawtypes")
    final MyGraphPanel pnl = GUI.getInstance().getGraphPanel();
    if (pnl.getMaximized() == null) {
        mi = new JMenuItem("Maximize");
        mi.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                pnl.setMaximized(vv);
            }
        });
    } else {
        mi = new JMenuItem("Restore");
        mi.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                pnl.setMaximized(null);
            }
        });
    }
    popup.add(mi);

    if (pnl.getMaximized() != null) {
        mi = new JMenuItem("Hide");
        mi.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                vv.getParent().setVisible(false);
            }
        });
        popup.add(mi);
    }

    popup.addSeparator();

    // Copied from MuLaNEO
    mi = new JMenuItem("Export layer to SVG");
    mi.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int layer = vv.getLayer().getLayer();
            MyFileChooser fc = new MyFileChooser("Export layer " + layer + " to SVG", MyFileChooserType.MISC,
                    false);
            fc.addChoosableFileFilter(FileFilters.svgFilter);
            fc.setSelectedFile(new File("export-layer-" + layer + ".svg"));

            if (fc.showSaveDialog(GUI.getInstance()) == JFileChooser.APPROVE_OPTION)
                new SVGExporter().export(vv, fc.getSelectedFile());
        }
    });
    popup.add(mi);
}

From source file:org.bigwiv.blastgraph.gui.graphvisualization.EWLayout.java

protected void calcRepulsion(V v1) {
    VertexData fvd1 = getData(v1);// w w  w .ja  v  a  2  s .  co m
    if (fvd1 == null)
        return;
    fvd1.setLocation(0, 0);

    try {
        for (V v2 : getGraph().getVertices()) {

            // if (isLocked(v2)) continue;
            if (v1 != v2) {
                Point2D p1 = transform(v1);
                Point2D p2 = transform(v2);
                if (p1 == null || p2 == null)
                    continue;
                double xDelta = p1.getX() - p2.getX();
                double yDelta = p1.getY() - p2.getY();

                double deltaLength = Math.max(EPSILON, Math.sqrt((xDelta * xDelta) + (yDelta * yDelta)));

                double force = (repulsion_constant * repulsion_constant) / deltaLength;

                if (Double.isNaN(force)) {
                    throw new RuntimeException(
                            "Unexpected mathematical result in FRLayout:calcPositions [repulsion]");
                }

                fvd1.offset((xDelta / deltaLength) * force, (yDelta / deltaLength) * force);
            }
        }
    } catch (ConcurrentModificationException cme) {
        calcRepulsion(v1);
    }
}