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 15 public abstract class TreeLayout extends Layout { 16 17 protected NodeItem m_root; 18 19 22 public TreeLayout() { 23 super(); 24 } 25 26 32 public TreeLayout(String group) { 33 super(group); 34 } 35 36 38 47 public void setLayoutRoot(NodeItem root) { 48 if ( !root.isInGroup(m_group) ) 49 throw new IllegalArgumentException ("Input node is not a member " 50 + "of this layout's data group"); 51 m_root = root; 52 } 53 54 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 ("This action's data group does" + 70 "not resolve to a Graph instance."); 71 } 72 } 73 74 } | Popular Tags |