Class HierarchyJTree
is an
implementation of a view that displays the nodes of a hierarchically organized
graph in a tree-like fashion.
The presentation resembles a directory structure with normal nodes being
leaves, group nodes being opened directories, and folder nodes being closed
ones.
HierarchyJTree uses the first node label as the descriptive text to be displayed. Node labels that render HTML code result in rendered HTML in the tree-like view, too, since HierarchyJTree utilizes a DefaultTreeCellRenderer object for this task.
Figure 7.6, “Graph view provided by HierarchyJTree” shows a HierarchyJTree placed in the lower left corner inside an application's window.
Class HierarchyJTree's presentation of the selection state indication is at any time synchronized with the selection state as present in the hierarchically organized graph.
Using the services of class
DefaultNodeChangePropagator
HierarchyJTree also gets notified whenever a group node is changed to a folder
node or vice-versa.
Such modifications to the graph hierarchy result in a label change of the
respective node in the tree-like view.
Class
HierarchyTreeTransferHandler
can be used to add drag-and-drop functionality to a HierarchyJTree.
It is a proper javax.swing.TransferHandler that enables
changing the tree-like representation of a hierarchically organized graph by
means of simple mouse drag gestures.
Each such change is directly converted to an actual change of the graph
hierarchy itself.
Example 7.4, “Enabling drag-and-drop for a HierarchyJTree” shows how to enable the drag-and-drop gesture on the content of the HierarchyJTree. The HierarchyManager that is associated with the hierarchically organized graph is given to HierarchyTreeTransferHandler at creation time.
Example 7.4. Enabling drag-and-drop for a HierarchyJTree
// 'hierarchyManager' is of type y.view.hierarchy.HierarchyManager. HierarchyJTree tree = new HierarchyJTree(hierarchyManager); tree.setDragEnabled(true); // The given HierarchyManager is responsible for the hierarchically organized // graph that is presented in the HierarchyJTree. tree.setTransferHandler(new HierarchyTreeTransferHandler(hierarchyManager));
|
Copyright ©2004-2008, yWorks GmbH. All rights reserved. |