Search in sources :

Example 1 with ZyGraphNode

use of com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.nodes.ZyGraphNode 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 2 with ZyGraphNode

use of com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.nodes.ZyGraphNode in project binnavi by google.

the class ProximityNodeCreator method createProximityNode.

/**
 * Creates a proximity browsing node.
 *
 * @param graph The graph where the proximity node is added to.
 * @param attachedNode The graph node the proximity node is attached to.
 * @param degree The edge degree of the attached node (this is the number shown in the proximity
 *        node).
 * @param isIncoming True, to signal that the proximity node is incoming. False, if it is
 *        outcoming.
 *
 * @param <NodeType> Raw node type of the real (e.g. not proximity nodes) nodes in the graph.
 *
 * @return The created proximity node.
 */
public static <NodeType extends IViewNode<?>> ZyProximityNode<?> createProximityNode(final Graph2D graph, final ZyGraphNode<?> attachedNode, final int degree, final boolean isIncoming) {
    Preconditions.checkNotNull(graph, "Graph argument can not be null");
    Preconditions.checkNotNull(attachedNode, "Target node argument can not be null");
    final ZyLabelContent labelcontent = new ZyLabelContent(null);
    labelcontent.addLineContent(new ZyLineContent(String.valueOf(degree), new Font("New Courier", Font.PLAIN, 12), null));
    final ZyProximityNodeRealizer<NodeType> r = new ZyProximityNodeRealizer<NodeType>(labelcontent);
    final Node node = graph.createNode(r);
    @SuppressWarnings("unchecked") final ZyProximityNode<NodeType> infoNode = new ZyProximityNode<NodeType>(node, r, (ZyGraphNode<NodeType>) attachedNode, isIncoming);
    final ZyNodeData<ZyProximityNode<NodeType>> data = new ZyNodeData<ZyProximityNode<NodeType>>(infoNode);
    r.setUserData(data);
    return infoNode;
}
Also used : ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent) ZyNodeData(com.google.security.zynamics.zylib.gui.zygraph.nodes.ZyNodeData) ZyGraphNode(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.nodes.ZyGraphNode) IViewNode(com.google.security.zynamics.zylib.gui.zygraph.nodes.IViewNode) Node(y.base.Node) ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent) ZyProximityNodeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyProximityNodeRealizer) Font(java.awt.Font)

Aggregations

ZyGraphNode (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.nodes.ZyGraphNode)2 Node (y.base.Node)2 Function (com.google.common.base.Function)1 IViewNode (com.google.security.zynamics.zylib.gui.zygraph.nodes.IViewNode)1 ZyNodeData (com.google.security.zynamics.zylib.gui.zygraph.nodes.ZyNodeData)1 ZyLabelContent (com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent)1 ZyLineContent (com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent)1 ZyProximityNodeRealizer (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyProximityNodeRealizer)1 Font (java.awt.Font)1 HashSet (java.util.HashSet)1 NodeList (y.base.NodeList)1