Forums

Full Version: customizing the root item in the RadialGraphView demo
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This demo adds an extension of the RadialTreeLayout to the original RadialGraphView demo, which enables the user to set the root item explicitely.

Inspired by

http://sourceforge.net/forum/forum.php?t..._id=343013



Please communicate in the source forge forum if you encounter any problems, this layout extension wasn't tested very well. Please let me also know, if the same
result can be accomplished with the standard setLayoutRoot() method of the TreeLayout.


The extended RadialTreeLayout:

Code:
public class RadialTreeLayoutCustomRootItem extends RadialTreeLayout {
  private NodeItem nextRootItem = null;

  public RadialTreeLayoutCustomRootItem(String group,NodeItem firstRootItem) {
    super(group);
    setNextRootItem(firstRootItem);
  }
    
  public void setNextRootItem(NodeItem nextRootItem) {
     this.nextRootItem = nextRootItem;
  }

  public NodeItem getLayoutRoot() {
    if ( m_root != null )
      return m_root;
            
   TupleSet ts = m_vis.getGroup(m_group);
   if ( ts instanceof Graph ) {
     if (nextRootItem != null) {                                    // <--- the extension
       ((Graph)ts).getSpanningTree(nextRootItem);
       NodeItem ret = nextRootItem;
       nextRootItem = null;
       return ret;
     } else {                                                       // <--- regular case
       Tree tree = ((Graph)ts).getSpanningTree();
       return (NodeItem)tree.getRoot();
     }
   } else {
   throw new IllegalStateException("This action's data group does" +
                        "not resolve to a Graph instance.");
  }
}
}
Reference URL's