RARS - Bank of Useful Information



 

Animated 2D Cone Tree Display

A2DCT is a set of Java classes written by Andy Colebourne which will display an Animated 2D Cone Tree.

An Animated 2D  Cone Tree is displayed in a series of cone (or star) shapes where the children on any node are displayed in a cone round the parent.

We can display a large tree on one screen using this type of display but at the expense of node information. For a very large tree, the information ‘lower’ down the tree tends to become hidden behind nodes ‘higher’ in the tree. The initial display contains the root node at the centre of the display. Left clicking on any node will result in that node being placed at the centre of the display. Successively doing this results in the lower nodes becoming more visible and the higher ones less visible.

The flow of the tree is determined by following nodes in a clockwise direction round the parent. When starting at the root, the first is that located at the North West subordinate node. When starting at a subordinate node, the first is that located, in a clockwise direction, from the line joining the subordinate node to its parent.

The display can be enhanced by using a tree node which extends ACNode and overrides the ACNode methods.

The initial display contains no node information as this clutters up the panel. As the mouse pointer moves over a node, the node name is displayed. Right clicking on a node causes a pop-up menu to be displayed giving the user the option to hold the node name or release a name currently being held.

Further node manipulation can be made by using a pop-up menu which is activated by right clicking on a space containing no node:

As a user clicks on nodes and changes the presentation of the tree, the route taken is displayed at the top of the panel. Choosing Back from the pop-up menu causes the display to go back one on this route. The route is updated to reflect this change. Selecting GoTo Root from the pop-up menu causes the display to go back to the first node in the route. The route is updated to reflect this change. Hold All Names causes names to be displayed on all tree nodes. For a large tree this is a pointless exercise as the tree becomes cluttered with black lettering. However, to view nodes low down in the tree, this becomes a useful feature. Release all names is the reverse of Hold All Names. The Cone tree contains a lot of information in a small space. It is not easy to locate a node we want in this display. When selected, the ‘Find node with…’ menu item presents a user with a small window for the user to type in a search string, or comparator.
  If the user types in a string and presses OK, the nodes containing the string are located and highlighted with circles.

Source

 
 Source Module Description 
ACNode class to represent an A2D node - extends DefaultMutableTreeNode
ACTreeTest Main  test harness class - creates new Frame1
Frame1 Main frame to test tree - contains menu items for creating random trees - extends JFrame
TreePanel Panel used to display the tree defined by ACNodes - extends JPanel

ACTreeTest and Frame1 are harness classes merely to demonstrate the functionality of ACNode and TreePanel.
ACNode and TreePanel can be incorporated in any program which requires an Animated 2D Cone Tree alternative to a JTree.

Example of creating an A2D Cone Tree.

The tree has already been created at this point in the variable gtmd.
The coding below shows how to display said tree on a JTabbedPane using the A2D Cone Tree classes produced by Andy Colebourne.

        // create new A2D Cone Tree Display from tree.
        // GuruEnquiryListItem extends ACNode.
        GuruEnquiryListItem x = gtmd.getRootNode ();
        TreePanel treep = new TreePanel ( x );

        // create a new tab, add tree display to it and make it selected
        resultsTP.addTab ( (title + "*"), treep );
        int tabIndex = (resultsTP.getTabCount ()) - 1;
        resultsTP.setSelectedIndex ( tabIndex );
 

To try out the program

1. Download source into a directory.
2. Compile all 4 java files in that directory -> javac *.java
3. Run test harness -> java ACTreeTest

To incorporate the tree into your java program, follow your nose!

Top