Search in sources :

Example 1 with YPoint

use of y.geom.YPoint in project binnavi by google.

the class ZyNodeRealizer method scalePortCoordinates.

protected void scalePortCoordinates(final Node node, final double wOld, final double wNew, final double hOld, final double hNew) {
    final Graph2D graph = (Graph2D) node.getGraph();
    final double wScaling = wOld > 0 ? wNew / wOld : 1.0d;
    final double hScaling = hOld > 0 ? hNew / hOld : 1.0d;
    for (Edge e = node.firstOutEdge(); e != null; e = e.nextOutEdge()) {
        final EdgeRealizer er = graph.getRealizer(e);
        final Port port = er.getSourcePort();
        final double px = port.getOffsetX() * wScaling;
        final double py = port.getOffsetY() * hScaling;
        port.setOffsets(px, py);
        graph.setSourcePointRel(e, new YPoint(px, py));
    }
    for (Edge e = node.firstInEdge(); e != null; e = e.nextInEdge()) {
        final EdgeRealizer er = graph.getRealizer(e);
        final Port port = er.getTargetPort();
        final double px = port.getOffsetX() * wScaling;
        final double py = port.getOffsetY() * hScaling;
        port.setOffsets(px, py);
        graph.setTargetPointRel(e, new YPoint(px, py));
    }
}
Also used : Port(y.view.Port) EdgeRealizer(y.view.EdgeRealizer) Edge(y.base.Edge) YPoint(y.geom.YPoint) Graph2D(y.view.Graph2D)

Example 2 with YPoint

use of y.geom.YPoint in project binnavi by google.

the class YHelpers method openFolder.

/**
   * Opens a folder node.
   * 
   * @param graph The graph the folder node belongs to.
   * @param folderNode The folder node to be opened.
   */
public static void openFolder(final Graph2D graph, final Node folderNode) {
    Preconditions.checkNotNull(graph, "Error: Graph argument can not be null");
    Preconditions.checkNotNull(folderNode, "Error: Folder node argument can not be null");
    final HierarchyManager hierarchy = graph.getHierarchyManager();
    final double w = graph.getWidth(folderNode);
    final double h = graph.getHeight(folderNode);
    final NodeList folderNodes = new NodeList();
    folderNodes.add(folderNode);
    graph.firePreEvent();
    for (final NodeCursor nc = folderNodes.nodes(); nc.ok(); nc.next()) {
        // get original location of folder node
        final Graph2D innerGraph = (Graph2D) hierarchy.getInnerGraph(nc.node());
        final YPoint folderP = graph.getLocation(nc.node());
        final NodeList innerNodes = new NodeList(innerGraph.nodes());
        hierarchy.openFolder(nc.node());
        // get new location of group node
        final Rectangle2D.Double gBox = graph.getRealizer(nc.node()).getBoundingBox();
        // move grouped nodes to former location of folder node
        LayoutTool.moveSubgraph(graph, innerNodes.nodes(), folderP.x - gBox.x, folderP.y - gBox.y);
    }
    graph.firePostEvent();
    graph.unselectAll();
    for (final NodeCursor nc = folderNodes.nodes(); nc.ok(); nc.next()) {
        graph.setSelected(nc.node(), true);
    }
    // to the node
    if ((w != graph.getWidth(folderNode)) || (h != graph.getHeight(folderNode))) {
        for (final EdgeCursor ec = folderNode.outEdges(); ec.ok(); ec.next()) {
            graph.setSourcePointRel(ec.edge(), YPoint.ORIGIN);
        }
        for (final EdgeCursor ec = folderNode.inEdges(); ec.ok(); ec.next()) {
            graph.setTargetPointRel(ec.edge(), YPoint.ORIGIN);
        }
    }
    graph.updateViews();
}
Also used : HierarchyManager(y.view.hierarchy.HierarchyManager) EdgeCursor(y.base.EdgeCursor) NodeList(y.base.NodeList) Rectangle2D(java.awt.geom.Rectangle2D) NodeCursor(y.base.NodeCursor) YPoint(y.geom.YPoint) Graph2D(y.view.Graph2D)

Example 3 with YPoint

use of y.geom.YPoint in project binnavi by google.

the class ZyGraphEdge method getPaths.

public ArrayList<Pair<Double, Double>> getPaths() {
    final int points = getRealizer(m_edge).pointCount();
    final ArrayList<Pair<Double, Double>> pointsList = new ArrayList<>();
    for (int i = 0; i < points; i++) {
        final YPoint point = getRealizer(m_edge).getPoint(i);
        pointsList.add(new Pair<Double, Double>(point.x, point.y));
    }
    return pointsList;
}
Also used : ArrayList(java.util.ArrayList) YPoint(y.geom.YPoint) YPoint(y.geom.YPoint) Pair(com.google.security.zynamics.zylib.general.Pair)

Aggregations

YPoint (y.geom.YPoint)3 Graph2D (y.view.Graph2D)2 Pair (com.google.security.zynamics.zylib.general.Pair)1 Rectangle2D (java.awt.geom.Rectangle2D)1 ArrayList (java.util.ArrayList)1 Edge (y.base.Edge)1 EdgeCursor (y.base.EdgeCursor)1 NodeCursor (y.base.NodeCursor)1 NodeList (y.base.NodeList)1 EdgeRealizer (y.view.EdgeRealizer)1 Port (y.view.Port)1 HierarchyManager (y.view.hierarchy.HierarchyManager)1