Search in sources :

Example 1 with NodeList

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

the class ZyGroupNodeRealizer method moveContent.

private void moveContent(final double dx, final double dy) {
    final Graph2D graph = (Graph2D) m_userData.getNode().getNode().getGraph();
    final HierarchyManager hm = graph.getHierarchyManager();
    // Find the children contained in the given group node.
    final NodeList childNodes = new NodeList();
    addChildren(hm, getNode(), childNodes);
    // Move the children.
    moveNodes(graph, childNodes.nodes(), dx, dy);
}
Also used : HierarchyManager(y.view.hierarchy.HierarchyManager) NodeList(y.base.NodeList) Graph2D(y.view.Graph2D)

Example 2 with NodeList

use of y.base.NodeList 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 NodeList

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

the class CGraphSelector method selectPath.

/**
   * Function which handles the selection of nodes in a path finding scenario. The function performs
   * four BFS runs: BFS 1 searches for all successors of the start nodes. BFS 2 searches for all
   * predecessors of the end nodes. BFS 2 searches for all predecessors of the start nodes. BFS 4
   * searches for all successors of the end nodes.
   * 
   * These four BFS runs are used in two sets: Set 1 is intersect of nodes reached through (BFS 1,
   * BFS 2). Set 2 is intersect of nodes reached through (BFS 3, BFS 4).
   * 
   * Therefore Set 1 represents all nodes on paths if the set of start nodes contains parents of the
   * newly selected node and Set 2 represents all nodes on paths if the set of start nodes contains
   * child nodes of the newly selected node.
   * 
   * 
   * @param graph The graph in which the selection takes place.
   * @param alreadySelectedNodes The List of nodes already selected.
   * @param newlySelectedNode The node which is newly selected.
   */
@SuppressWarnings("unchecked")
public static <NodeType extends ZyGraphNode<?>> void selectPath(final AbstractZyGraph<NodeType, ?> graph, final ArrayList<NodeType> alreadySelectedNodes, final NodeType newlySelectedNode) {
    final Function<NodeType, Node> function = new Function<NodeType, Node>() {

        @Override
        public Node apply(final NodeType input) {
            return input.getNode();
        }
    };
    final Collection<Node> foo = Collections2.transform(alreadySelectedNodes, function);
    final NodeList startNodes = new NodeList(foo.iterator());
    final NodeList endNodes = new NodeList(newlySelectedNode.getNode());
    final Set<Node> startSuccSet = new HashSet<Node>();
    final NodeList[] nodeListsStartSucc = Bfs.getLayers(graph.getGraph(), startNodes, Bfs.DIRECTION_SUCCESSOR, graph.getGraph().createNodeMap(), 0);
    for (final NodeList nodeList : nodeListsStartSucc) {
        startSuccSet.addAll(nodeList);
    }
    final Set<Node> endPredSet = new HashSet<Node>();
    final NodeList[] nodeListsEndPred = Bfs.getLayers(graph.getGraph(), endNodes, Bfs.DIRECTION_PREDECESSOR, graph.getGraph().createNodeMap(), 0);
    for (final NodeList nodeList : nodeListsEndPred) {
        endPredSet.addAll(nodeList);
    }
    final SetView<Node> startBeforeEndSetView = Sets.intersection(startSuccSet, endPredSet);
    if (!startBeforeEndSetView.isEmpty()) {
        for (final Node node : startBeforeEndSetView) {
            graph.getGraph().setSelected(node, true);
        }
    }
    final Set<Node> startPredSet = new HashSet<Node>();
    final NodeList[] nodeListsStartPred = Bfs.getLayers(graph.getGraph(), startNodes, Bfs.DIRECTION_PREDECESSOR, graph.getGraph().createNodeMap(), 0);
    for (final NodeList nodeList : nodeListsStartPred) {
        startPredSet.addAll(nodeList);
    }
    final Set<Node> endSuccSet = new HashSet<Node>();
    final NodeList[] nodeListsEndSucc = Bfs.getLayers(graph.getGraph(), endNodes, Bfs.DIRECTION_SUCCESSOR, graph.getGraph().createNodeMap(), 0);
    for (final NodeList nodeList : nodeListsEndSucc) {
        endSuccSet.addAll(nodeList);
    }
    final SetView<Node> endBeforeStartSetView = Sets.intersection(startPredSet, endSuccSet);
    if (!endBeforeStartSetView.isEmpty()) {
        for (final Node node : endBeforeStartSetView) {
            graph.getGraph().setSelected(node, true);
        }
    }
}
Also used : Function(com.google.common.base.Function) ZyGraphNode(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.nodes.ZyGraphNode) Node(y.base.Node) NodeList(y.base.NodeList) HashSet(java.util.HashSet)

Example 4 with NodeList

use of y.base.NodeList 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)

Example 5 with NodeList

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

the class GroupHelpers method extractFolder.

public static void extractFolder(final Graph2D graph, final Node folderNode) {
    final Graph innerGraph = graph.getHierarchyManager().getInnerGraph(folderNode);
    final NodeList subNodes = new NodeList(innerGraph.nodes());
    graph.getHierarchyManager().unfoldSubgraph(innerGraph, subNodes);
}
Also used : Graph(y.base.Graph) NodeList(y.base.NodeList)

Aggregations

NodeList (y.base.NodeList)6 EdgeCursor (y.base.EdgeCursor)3 NodeCursor (y.base.NodeCursor)3 HierarchyManager (y.view.hierarchy.HierarchyManager)3 ZyGraphNode (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.nodes.ZyGraphNode)2 Node (y.base.Node)2 Graph2D (y.view.Graph2D)2 Function (com.google.common.base.Function)1 ZyProximityNode (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.proximity.ZyProximityNode)1 Rectangle2D (java.awt.geom.Rectangle2D)1 HashSet (java.util.HashSet)1 Edge (y.base.Edge)1 Graph (y.base.Graph)1 YPoint (y.geom.YPoint)1