com.objectwave.utility
Class TreeCollection

java.lang.Object
  |
  +--com.objectwave.utility.TreeCollection
All Implemented Interfaces:
java.io.Serializable, javax.swing.tree.TreeModel

public class TreeCollection
extends java.lang.Object
implements java.io.Serializable, javax.swing.tree.TreeModel

This class differs from the jfc tree implementation in that you never worry about TreeNode objects. You just use this as you would any old collection. This class should probably change from using Vectors to contain elements using link lists. This would provide flexibility in what comparison operator to use.

See Also:
Serialized Form

Constructor Summary
TreeCollection()
           
 
Method Summary
 void add(java.lang.Object key)
          Adds new elements to the root of the tree.
 void addTreeModelListener(javax.swing.event.TreeModelListener l)
          Implement TreeModel
 boolean contains(java.lang.Object key)
          Does the object exist in this collection.
 java.util.Enumeration elements()
          Return an enumeration of the entire contents of collection.
protected  void fireInsertedEvent(javax.swing.event.TreeModelEvent e)
           
protected  void fireTreeNodesChanged(javax.swing.event.TreeModelEvent e)
          e.path() returns the path the parent of the changed node(s).
 java.util.Enumeration get(java.lang.Object key)
          Returns the children at the specified key.
 java.lang.Object getChild(java.lang.Object parent, int index)
           
 int getChildCount(java.lang.Object parent)
           
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
           
 java.lang.Object getParent(java.lang.Object key)
           
 java.lang.Object getRoot()
           
 TreeCollection getSubTree(java.lang.Object key)
           
 boolean isEmpty()
           
 boolean isEmpty(java.lang.Object key)
          Do we have any children at the node.
 boolean isLeaf(java.lang.Object node)
           
static void main(java.lang.String[] args)
           
 java.lang.Object[] pathTo(java.lang.Object key)
          Path to the parent of key.
 void prune(java.lang.Object key)
          Remove the object 'key' and all children of key.
 void put(java.lang.Object key, java.lang.Object node)
          Puts the new elment after the existing element.
 void refreshPath(javax.swing.tree.TreePath path)
           
 void remove(java.lang.Object key)
          Remove the object 'key' and promote all of it's children to have the same parent that 'key' had.
 void removeTreeModelListener(javax.swing.event.TreeModelListener l)
           
 void replace(java.lang.Object key, java.lang.Object with)
           
 void setName(java.lang.String val)
           
 int size()
           
 int size(java.lang.Object key)
          Deprecated. Get the child count at the object.
 java.lang.String toString()
          What is the name of 'this' object.
 void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TreeCollection

public TreeCollection()
Method Detail

add

public void add(java.lang.Object key)
Adds new elements to the root of the tree. If the element is already in the tree, it is moved to the root of the tree.


addTreeModelListener

public void addTreeModelListener(javax.swing.event.TreeModelListener l)
Implement TreeModel

Specified by:
addTreeModelListener in interface javax.swing.tree.TreeModel

contains

public boolean contains(java.lang.Object key)
Does the object exist in this collection.


elements

public java.util.Enumeration elements()
Return an enumeration of the entire contents of collection.


fireInsertedEvent

protected void fireInsertedEvent(javax.swing.event.TreeModelEvent e)

fireTreeNodesChanged

protected void fireTreeNodesChanged(javax.swing.event.TreeModelEvent e)
e.path() returns the path the parent of the changed node(s). e.childIndices() returns the index(es) of the changed node(s).


get

public java.util.Enumeration get(java.lang.Object key)
Returns the children at the specified key.


getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)
Specified by:
getChild in interface javax.swing.tree.TreeModel

getChildCount

public int getChildCount(java.lang.Object parent)
Specified by:
getChildCount in interface javax.swing.tree.TreeModel

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
Specified by:
getIndexOfChild in interface javax.swing.tree.TreeModel
Parameters:
parent - If null, look at root values.
Returns:
int Index of the child. -1 if child not found at parent.

getParent

public java.lang.Object getParent(java.lang.Object key)

getRoot

public java.lang.Object getRoot()
Specified by:
getRoot in interface javax.swing.tree.TreeModel

getSubTree

public TreeCollection getSubTree(java.lang.Object key)

isEmpty

public boolean isEmpty()

isEmpty

public boolean isEmpty(java.lang.Object key)
Do we have any children at the node.


isLeaf

public boolean isLeaf(java.lang.Object node)
Specified by:
isLeaf in interface javax.swing.tree.TreeModel

main

public static void main(java.lang.String[] args)

pathTo

public java.lang.Object[] pathTo(java.lang.Object key)
Path to the parent of key. At minimum this will contain the root node.


prune

public void prune(java.lang.Object key)
Remove the object 'key' and all children of key.


put

public void put(java.lang.Object key,
                java.lang.Object node)
Puts the new elment after the existing element. If the existing element is not in the tree it is just added at the root level. If the new elment is already in the tree, it and it's children are moved to the new elements child.


refreshPath

public void refreshPath(javax.swing.tree.TreePath path)

remove

public void remove(java.lang.Object key)
Remove the object 'key' and promote all of it's children to have the same parent that 'key' had.


removeTreeModelListener

public void removeTreeModelListener(javax.swing.event.TreeModelListener l)
Specified by:
removeTreeModelListener in interface javax.swing.tree.TreeModel

replace

public void replace(java.lang.Object key,
                    java.lang.Object with)

setName

public void setName(java.lang.String val)

size

public int size()

size

public int size(java.lang.Object key)
Deprecated. Get the child count at the object.


toString

public java.lang.String toString()
What is the name of 'this' object.

Overrides:
toString in class java.lang.Object

valueForPathChanged

public void valueForPathChanged(javax.swing.tree.TreePath path,
                                java.lang.Object newValue)
Specified by:
valueForPathChanged in interface javax.swing.tree.TreeModel