use of y.base.Node in project binnavi by google.
the class ZyGraphVerifier method verifyMap.
/**
* Verifies the map that maps between ynode objects and node objects. If the map has an incorrect
* format, the function throws an {@link IllegalArgumentException}.
*
* @param graph
*/
public static <NodeType> void verifyMap(final Graph2D graph, final HashMap<Node, NodeType> nodeMap) {
// Let's verify the node map.
//
// - The number of mappings must equal or less than the number of graphs in the node (each node
// must be mapped, but some nodes can be hidden in folder nodes)
// - No element of the key set/value set of the mapping must appear more than once
// - No key or value of the mapping must be null
Preconditions.checkArgument(graph.nodeCount() <= nodeMap.size(), "Error: Invalid node map (Graph contains " + graph.nodeCount() + " nodes while nodeMap contains " + nodeMap.size() + " nodes");
final HashSet<Node> visitedNodes = new HashSet<Node>();
final HashSet<NodeType> visitedNodes2 = new HashSet<NodeType>();
for (final Map.Entry<Node, NodeType> elem : nodeMap.entrySet()) {
final Node ynode = elem.getKey();
final NodeType node = elem.getValue();
Preconditions.checkArgument((ynode != null) && (node != null), "Error: Invalid node map");
// We can not check this because of nodes hidden in folder nodes
// if (!graph.contains(ynode))
Preconditions.checkArgument(!visitedNodes.contains(ynode), "Error: Invalid node map");
Preconditions.checkArgument(!visitedNodes2.contains(node), "Error: Invalid node map");
visitedNodes.add(ynode);
visitedNodes2.add(node);
}
}
use of y.base.Node 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.Node in project binnavi by google.
the class CMousePressedHandler method handleMousePressed.
public static IMouseStateChange handleMousePressed(final CStateFactory<?, ?> factory, final IMouseState defaultState, final AbstractZyGraph<?, ?> graph, final MouseEvent event) {
final double x = graph.getEditMode().translateX(event.getX());
final double y = graph.getEditMode().translateY(event.getY());
final HitInfo hitInfo = graph.getGraph().getHitInfo(x, y);
if (hitInfo.hasHitNodes()) {
final Node n = hitInfo.getHitNode();
if (SwingUtilities.isLeftMouseButton(event) && !event.isAltDown()) {
return new CStateChange(factory.createNodePressedLeftState(n, event), true);
} else if (SwingUtilities.isRightMouseButton(event)) {
return new CStateChange(factory.createNodePressedRightState(n, event), true);
} else if (SwingUtilities.isMiddleMouseButton(event) || (event.isAltDown() && SwingUtilities.isLeftMouseButton(event))) {
return new CStateChange(factory.createNodePressedMiddleState(n, event), false);
} else {
return new CStateChange(defaultState, true);
}
} else if (hitInfo.hasHitNodeLabels()) {
throw new IllegalStateException("yFiles Labels are not in use...");
} else if (hitInfo.hasHitEdges()) {
final Edge edge = hitInfo.getHitEdge();
if (SwingUtilities.isLeftMouseButton(event)) {
return new CStateChange(factory.createEdgePressedLeftState(edge, event), true);
} else if (SwingUtilities.isRightMouseButton(event)) {
return new CStateChange(factory.createEdgePressedRightState(edge, event), true);
} else {
return new CStateChange(defaultState, true);
}
} else if (hitInfo.hasHitEdgeLabels()) {
// {
return new CStateChange(defaultState, true);
// }
} else if (hitInfo.hasHitBends()) {
final Bend bend = hitInfo.getHitBend();
if (SwingUtilities.isLeftMouseButton(event)) {
return new CStateChange(factory.createBendPressedLeftState(bend, event), true);
} else {
return new CStateChange(defaultState, true);
}
} else if (hitInfo.hasHitPorts()) {
return new CStateChange(factory.createDefaultState(), true);
} else {
if (SwingUtilities.isLeftMouseButton(event)) {
return new CStateChange(factory.createBackgroundPressedLeftState(event), true);
} else if (SwingUtilities.isRightMouseButton(event)) {
return new CStateChange(factory.createBackgroundPressedRightState(event), true);
}
return new CStateChange(factory.createDefaultState(), true);
}
}
use of y.base.Node in project binnavi by google.
the class AbstractZyGraph method removeNode.
protected void removeNode(final NodeType node) {
if (node.getNode().getGraph() == null) {
m_graph.reInsertNode(node.getNode());
}
final HierarchyManager manager = m_graph.getHierarchyManager();
final Node n = node.getNode();
if (manager.isNormalNode(n)) {
m_graph.removeNode(node.getNode());
} else if (getGraph().getHierarchyManager().isFolderNode(node.getNode())) {
GroupHelpers.extractFolder(m_graph, node.getNode());
m_graph.removeNode(node.getNode());
} else if (getGraph().getHierarchyManager().isGroupNode(node.getNode())) {
GroupHelpers.extractGroup(m_graph, node.getNode());
m_graph.removeNode(node.getNode());
}
m_mappings.removeNode(node);
}
use of y.base.Node in project binnavi by google.
the class TypeDependenceGraph method determineDependentTypes.
/**
* Determines the set of base types that are (transitively) contained within baseType. A type A is
* said to be contained within B iff B has a member of type A, or if there exists a chain of
* nested types within B leading to at least one type that has a member of type A.
*
* @param baseType The type for which to determine the set of dependent types.
* @return The set of dependent types.
*/
public ImmutableSet<BaseType> determineDependentTypes(final BaseType baseType) {
Preconditions.checkNotNull(baseType, "Error: Base type can not be null.");
final Node typeNode = containedRelationMap.get(baseType);
final TypeSearch search = new TypeSearch(containedRelationMap.inverse());
search.start(containedRelation, typeNode);
return search.getDependentTypes();
}
Aggregations