Where to Find Up-to-date yFiles Information

This page is from the outdated yFiles for Java 2.13 documentation. You can find the most up-to-date documentation for all yFiles products on the yFiles documentation overview page.

Please see the following links for more information about the yFiles product family of diagramming programming libraries and corresponding yFiles products for modern web apps, for cross-platform Java(FX) applications, and for applications for the Microsoft .NET environment.

More about the yFiles product family Close X

User Interaction

Group nodes and folder nodes introduce new user interaction aspects with grouped graphs. These aspects are reflected by view mode and Action implementations in package y.view.

The view modes listed in Table 7.3, “View modes associated with class EditMode with group node-specific behavior” provide specific group node-related functionality.

Table 7.3. View modes associated with class EditMode with group node-specific behavior

Classname Description
CreateEdgeMode 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.
HotSpotMode Auto bounds-constrained group node resizing policies are taken special care of.
MoveSelectionMode 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. Furthermore, during re-parenting gestures, possible target group nodes can optionally be highlighted using a customizable adornment.
SelectionBoxMode A group node's selection state is only changed when it is entirely contained in the selection box.

In addition, class Graph2DViewActions provides many predefined Action implementations to handle group nodes and folder nodes.

Table 7.4. Predefined group node/folder node-related Action implementations from class Graph2DViewActions

Classname Description
Graph2DViewActions.CloseGroupsAction Closes selected group nodes. Each group node is converted into a folder node, the contained nodes are removed from the graph that contains the group node and added to the folder node's inner graph instead.
Graph2DViewActions.OpenFoldersAction Opens selected folder nodes. Each folder node is converted into a group node, all nodes from the folder node's inner graph are removed from it and added to the graph that contains the folder node instead.
Graph2DViewActions.GroupSelectionAction A selected subgraph is put into a newly created group node.
Graph2DViewActions.FoldSelectionAction A selected subgraph is removed from the containing graph and added to the new inner graph of a newly created folder node instead.
Graph2DViewActions.UngroupSelectionAction A selected subgraph is taken out of its directly containing group node.
Graph2DViewActions.UnfoldSelectionAction A selected subgraph is removed from the inner graph of a folder node and added to the graph containing the folder node instead.

Graph2DViewActions also facilitates creation of new Action implementations.

Tutorial Demo Code

The class fragment that is presented in Example 7.5, “Toggling a GroupNodeRealizer's state” briefly shows how a view mode could use the group node/folder node-related Action implementations to change the state of a GroupNodeRealizer-rendered node in response to a mouse click on the node's state icon.

Example 7.5. 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 grouped graph.
        hm = HierarchyManager.getInstance(view.getGraph2D());
        
        if (hm.isFolderNode(v)) {
          // Invokes a customized OpenFolders Action implementation.
          createOpenFoldersAction(v).openFolders(view);
        }
        else {
          // Invokes a customized CloseGroups Action implementation.
          createCloseGroupsAction(v).closeGroups(view);
        }
      }
    }
  }
}

The tutorial demo applications HierarchyDemo.java and GroupingDemo.java present further examples of how to use the Action implementations. Creation of new actions is shown in GroupNavigationDemo.java.