/** Trie Node class **/ import java.awt.*; import ciips.animation.*; import ciips.animation.tree.*; class TrieNode extends MultiNode { protected int diff_x=5; protected int diff_y=30; /** Construct an intermediate node - intermediate nodes have no data (weight = null) and null child pointers. The child pointers will be set to point to sub-trees **/ public TrieNode( int max_children, TrieNode sub_tree, int pos ) { this.max_children = max_children; weight = null; // Check that pos is reasonable if( (pos < -1) || (pos>=max_children) ) { throw new RuntimeException("TrieNode: illegal child position"); } child = new MultiNode[ max_children+1 ]; for( int i=0; i<(max_children+1); i++ ) { // child[i] = makeSentinel(); child[i] = null; } child[pos+1] = sub_tree; } /** Construct a leaf node - leaf nodes have data (weight != null) and null child pointers (which never change) **/ public TrieNode( RadixKey d, int n_child ) { this( n_child, null, -1 ); weight = d; } public int getRadixCount() { return child.length ; } /** Function to get the child node **/ public TrieNode getChild( int index ) { if( (index < -1) || (index>=max_children) ) { throw new RuntimeException("TrieNode:getChild - illegal child position"); } return (TrieNode)(child[index+1]); } /** function for setting the child node **/ public void setChild(TrieNode y, int index) { if( (index < -1) || (index>=max_children) ) { throw new RuntimeException("TrieNode:setChild - illegal child position"); } child[index+1] = y; } /** * This method draws the node on the corresponding graphical context * normally passed in from the drawing panel. **/ public void draw(Graphics g) { System.out.println("TrieNode:draw " + ((getData()== null)?"null data":getData()) ); if (getHighlight()){ g.setColor(Color.yellow); } else { if (getData() == null) g.setColor(Color.white); else g.setColor(Color.black); } g.fillRect(x, y, diameter.width, diameter.height); g.setColor(Color.black); g.drawRect(x, y, diameter.width, diameter.height); if ( getData() != null ) { g.setColor( labelColor ); rotate_label( g, getData(), x, y + (diameter.height * 2)); } System.out.println("MultiNode:draw " + getData() + " exit" ); } /* * This method rotates the value of a node * into a vertical line and draw the value */ public void rotate_label ( Graphics g, Object data, int x, int y ){ String s = data.toString(); int fontSize = 10; Font labelFont = new Font ( "Dialog", 0, fontSize ); g.setFont( labelFont ); for (int i=0 ; i