KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > action > layout > graph > TreeLayout


1 package prefuse.action.layout.graph;
2
3 import prefuse.action.layout.Layout;
4 import prefuse.data.Graph;
5 import prefuse.data.Tree;
6 import prefuse.data.tuple.TupleSet;
7 import prefuse.visual.NodeItem;
8
9 /**
10  * Abstract base class providing convenience methods for tree layout algorithms.
11  *
12  * @version 1.0
13  * @author <a HREF="http://jheer.org">jeffrey heer</a>
14  */

15 public abstract class TreeLayout extends Layout {
16
17     protected NodeItem m_root;
18
19     /**
20      * Create a new TreeLayout.
21      */

22     public TreeLayout() {
23         super();
24     }
25
26     /**
27      * Create a new TreeLayout.
28      * @param group the data group to layout. This must resolve to a graph
29      * instance, otherwise an exception will result when subclasses attempt
30      * to retrieve the layout root.
31      */

32     public TreeLayout(String JavaDoc group) {
33         super(group);
34     }
35     
36     // ------------------------------------------------------------------------
37

38     /**
39      * Explicitly set the node to use as the layout root.
40      * @param root the node to use as the root. A null value is legal, and
41      * indicates that the root of the spanning tree of the backing graph will
42      * be used as the layout root. If the node is not a member of this layout's
43      * data group, an exception will be thrown.
44      * @throws IllegalArgumentException if the provided root is not a member of
45      * this layout's data group.
46      */

47     public void setLayoutRoot(NodeItem root) {
48         if ( !root.isInGroup(m_group) )
49             throw new IllegalArgumentException JavaDoc("Input node is not a member "
50                     + "of this layout's data group");
51         m_root = root;
52     }
53     
54     /**
55      * Return the NodeItem to use as the root for this tree layout.
56      * @return the root node to use for this tree layout.
57      * @throws IllegalStateException if the action's data group does not
58      * resolve to a {@link prefuse.data.Graph} instance.
59      */

60     public NodeItem getLayoutRoot() {
61         if ( m_root != null )
62             return m_root;
63         
64         TupleSet ts = m_vis.getGroup(m_group);
65         if ( ts instanceof Graph ) {
66             Tree tree = ((Graph)ts).getSpanningTree();
67             return (NodeItem)tree.getRoot();
68         } else {
69             throw new IllegalStateException JavaDoc("This action's data group does" +
70                     "not resolve to a Graph instance.");
71         }
72     }
73
74 } // end of abstract class TreeLayout
75
Popular Tags