Search in sources :

Example 1 with NodeCursor

use of y.base.NodeCursor 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 2 with NodeCursor

use of y.base.NodeCursor in project binnavi by google.

the class YHelpers method closeGroup.

/**
   * Closes a group node.
   * 
   * @param graph The graph the group node belongs to.
   * @param groupNode The group node to be closed.
   */
public static void closeGroup(final Graph2D graph, final Node groupNode) {
    Preconditions.checkNotNull(graph, "Error: Graph argument can not be null");
    Preconditions.checkNotNull(groupNode, "Error: Group node argument can not be null");
    final HierarchyManager hierarchy = graph.getHierarchyManager();
    final double w = graph.getWidth(groupNode);
    final double h = graph.getHeight(groupNode);
    final NodeList groupNodes = new NodeList();
    groupNodes.add(groupNode);
    graph.firePreEvent();
    for (final NodeCursor nc = groupNodes.nodes(); nc.ok(); nc.next()) {
        hierarchy.closeGroup(nc.node());
    }
    graph.firePostEvent();
    // to the node
    if ((w != graph.getWidth(groupNode)) || (h != graph.getHeight(groupNode))) {
        for (final EdgeCursor ec = groupNode.outEdges(); ec.ok(); ec.next()) {
            graph.setSourcePointRel(ec.edge(), YPoint.ORIGIN);
        }
        for (final EdgeCursor ec = groupNode.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) NodeCursor(y.base.NodeCursor)

Example 3 with NodeCursor

use of y.base.NodeCursor in project binnavi by google.

the class ZyGraphDefaultRenderer method bringNodeToFront.

public void bringNodeToFront(final Node node) {
    final Graph2D g = (Graph2D) node.getGraph();
    final NodeRealizer r = g.getRealizer(node);
    if (r.isSelected()) {
        // This does not work properly! Why? NH
        for (final NodeCursor nc = g.selectedNodes(); nc.ok(); nc.next()) {
            m_nodesInDrawingOrder.remove(nc.node());
            m_nodesInDrawingOrder.add(nc.node());
        }
    } else {
        // This seems to work correctly.
        m_nodesInDrawingOrder.remove(node);
        m_nodesInDrawingOrder.add(node);
    }
}
Also used : ZyGroupNodeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyGroupNodeRealizer) NodeRealizer(y.view.NodeRealizer) NodeCursor(y.base.NodeCursor) Graph2D(y.view.Graph2D)

Example 4 with NodeCursor

use of y.base.NodeCursor in project binnavi by google.

the class CSelectionMode method selectionBoxAction.

@Override
protected void selectionBoxAction(final Rectangle rect, final boolean shiftMode) {
    m_graph.getGraph().firePreEvent();
    final NodeList selectedNodes = new NodeList();
    for (final NodeCursor node = m_graph.getGraph().nodes(); node.ok(); node.next()) {
        final NodeType zyNode = m_graph.getNode(node.node());
        if ((zyNode == null) || (zyNode instanceof ZyProximityNode<?>)) {
            continue;
        }
        if (belongsToSelection(node.node(), rect)) {
            selectedNodes.add(node.node());
        }
    }
    if (((getLastDragEvent().getModifiersEx() & InputEvent.CTRL_DOWN_MASK) == 0) && ((getLastDragEvent().getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) == 0)) {
        m_graph.getGraph().unselectAll();
    }
    for (final Object nodeObject : selectedNodes) {
        final Node node = (Node) nodeObject;
        m_graph.getGraph().setSelected(node, true);
    }
    for (final EdgeCursor ec = m_graph.getGraph().selectedEdges(); ec.ok(); ec.next()) {
        final Edge e = ec.edge();
        final Node src = e.source();
        final Node dst = e.target();
        if (!m_graph.getGraph().getRealizer(src).isSelected() && !m_graph.getGraph().getRealizer(dst).isSelected()) {
            m_graph.getGraph().getRealizer(e).setSelected(false);
        }
    }
    m_graph.getGraph().firePostEvent();
    m_graph.getGraph().updateViews();
}
Also used : EdgeCursor(y.base.EdgeCursor) NodeList(y.base.NodeList) ZyGraphNode(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.nodes.ZyGraphNode) Node(y.base.Node) ZyProximityNode(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.proximity.ZyProximityNode) NodeCursor(y.base.NodeCursor) Edge(y.base.Edge) ZyProximityNode(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.proximity.ZyProximityNode)

Aggregations

NodeCursor (y.base.NodeCursor)4 EdgeCursor (y.base.EdgeCursor)3 NodeList (y.base.NodeList)3 Graph2D (y.view.Graph2D)2 HierarchyManager (y.view.hierarchy.HierarchyManager)2 ZyGraphNode (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.nodes.ZyGraphNode)1 ZyProximityNode (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.proximity.ZyProximityNode)1 ZyGroupNodeRealizer (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyGroupNodeRealizer)1 Rectangle2D (java.awt.geom.Rectangle2D)1 Edge (y.base.Edge)1 Node (y.base.Node)1 YPoint (y.geom.YPoint)1 NodeRealizer (y.view.NodeRealizer)1