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);
}
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();
}
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);
}
}
}
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();
}
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);
}
Aggregations