Group nodes and folder nodes introduce new user interaction aspects with hierarchically organized graphs. These aspects are reflected by appropriately enhanced view mode implementations.
The view modes that support both grouping and nesting can be activated by simply registering an instance of class HierarchyEditMode as shown in Example 7.5, “Registering an edit mode that provides support for graph hierarchies”.
Example 7.5. Registering an edit mode that provides support for graph hierarchies
public class GraphHierarchyDemo { protected Graph2DView view; protected HierarchyManager hm; protected EditMode editMode; public GraphHierarchyDemo() { view = new Graph2DView(); // Add support for grouping and nesting to the graph. hm = new HierarchyManager(view.getGraph2D()); // Register an augmented edit mode that provides support for graph // hierarchies. editMode = new HierarchyEditMode(); view.addViewMode(editMode); } }
Class HierarchyEditMode
takes the role of class EditMode in
hierarchically organized graphs.
It has associated a number of child modes that provide adequate editing
capabilities for graph hierarchies.
Figure 7.7, “Class HierarchyEditMode” shows class HierarchyEditMode's inheritence structure which is typical for the associated child modes, too. Each of the hierarchy view modes listed in Table 7.3, “Specialized view modes associated with class HierarchyEditMode” inherits from the corresponding view mode from package y.view that handles similar functionality in graphs without support for grouping or nesting.
Table 7.3. Specialized view modes associated with class HierarchyEditMode
| Classname | Description |
|---|---|
| HierarchyCreateEdgeMode |
Handles edge creation in hierarchically organized graphs. In particular, edge creation involving group nodes or their grouped nodes is taken special care of. The group node's border area is reserved for creation of edges connecting to the group node itself. This also implies that bend creation is not possible at a group node's border. |
| HierarchyHotSpotMode |
Handles node resizing in hierarchically organized graphs. In particular, auto bounds-constrained group node resizing policies are taken special care of. |
| HierarchyMoveSelectionMode |
Handles moving a collection of selected graph elements in hierarchically organized graphs. In particular, moving group nodes is taken special care of. Whenever a group node is moved, all its grouped nodes are moved, too. This mode does also provide support to add further nodes to a group node. |
| HierarchySelectionBoxMode |
Handles creating a rectangular box in the view and changes the selection state of graph elements contained in that box in hierarchically organized graphs. In particular, group node selection is taken special care of. A group node's selection state is only changed when it is entirely contained in the selection box. |
The class fragment that is presented in Example 7.6, “Toggling a GroupNodeRealizer's state” briefly shows how a view mode would change the state of a GroupNodeRealizer-rendered node in response to a mouse click on the node's state icon.
Example 7.6. Toggling a GroupNodeRealizer's state
public class ToggleOpenClosedStateViewMode extends ViewMode { HierarchyManager hm; public void mouseClicked(MouseEvent ev) { // Convert the mouse event's coordinates from view to world coordinates. double x = translateX(ev.getX()); double y = translateY(ev.getY()); // Retrieve the node that has been hit at the location. Node v = getHitInfo(ev).getHitNode(); // Test if the node is rendered by GroupNodeRealizer. GroupNodeRealizer gnr = getGroupNodeRealizer(v); if (gnr != null) { // Get the state label. NodeLabel stateLabel = gnr.getStateLabel(); // Test, if the mouse event occured on the state icon. if (stateLabel.getBox().contains(x, y)) { // Retrieve the HierarchyManager of the hierarchically organized graph. hm = HierarchyManager.getInstance(view.getGraph2D()); if (hm.isFolderNode(v)) { openFolder(v); // Invokes hm.openFolder(v) ultimately... } else { closeGroup(v); // Invokes hm.closeGroup(v) ultimately... } } } } }
HierarchyDemo.java provides further view mode implementations in the context of hierarchically organized graphs.
|
Copyright ©2004-2008, yWorks GmbH. All rights reserved. |