beowulf.model.tree
Class AbstractBinaryTreeModel

java.lang.Object
  extended bybeowulf.model.tree.AbstractBinaryTreeModel
All Implemented Interfaces:
BinaryTreeModel, TreeModel
Direct Known Subclasses:
DefaultBinaryTree

public abstract class AbstractBinaryTreeModel
extends Object
implements BinaryTreeModel

This abstract class defines event handling procedures common to all of its implementors. This is simply another level of abstraction, and allows another class to provide all of the implementation details on the actual operation of the tree. Certain rules must be followed by its subclasses to ensure that events are delivered to the approrpriate listeners. These rules are largely limited to calling the appropriate fireXXXX method after the occurrance of a certain TreeModelEvent.

Version:
1.0, 11/15/2003
Author:
Andy Scukanec (ags at cs dot cornell dot edu)

Field Summary
protected  EventListenerList listenerList
          This list contains references to all interested listeners.
 
Constructor Summary
AbstractBinaryTreeModel()
           
 
Method Summary
abstract  void add(Object value)
          This method will create a new node with the given value, and add it to the tree.
 void addTreeModelListener(TreeModelListener l)
          This method adds a TreeModelListener as an interested listener of events to this Tree.
protected  void fireNodesChanged(Object source, BinaryTreeNode[] path)
          This method must be called by all subclasses after the value of a node has changed.
protected  void fireNodesInserted(Object source, BinaryTreeNode[] path)
          This method must be called by all subclasses after a node is added to the Tree.
protected  void fireNodesRemoved(Object source, BinaryTreeNode[] path)
          This method must be called by all subclasses after a node is removed from the Tree.
protected  void fireStructureChanged(Object source, BinaryTreeNode[] path)
          This method must be called by all subclasses after the structure of the tree has changed in some large way that will not fit into the simple classifications of the other fireXxx methods.
 EventListener[] getListeners(Class listenerType)
          Returns an array of all the objects currently registered as FooListeners upon this model.
 TreeModelListener[] getTreeListeners()
          Returns an array of all the tree listeners registered on this AbstractTreeModel.
abstract  void remove(Object value)
          Given a node's value, this method will find and remove that node from the tree.
 void removeTreeModelListener(TreeModelListener l)
          This method removes the TreeModelListener as an interested listener of events to this Tree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface beowulf.model.tree.BinaryTreeModel
elements, getMaxDepth, getNodeCount, toString
 
Methods inherited from interface javax.swing.tree.TreeModel
getChild, getChildCount, getIndexOfChild, getRoot, isLeaf, valueForPathChanged
 

Field Detail

listenerList

protected EventListenerList listenerList
This list contains references to all interested listeners.

Constructor Detail

AbstractBinaryTreeModel

public AbstractBinaryTreeModel()
Method Detail

addTreeModelListener

public void addTreeModelListener(TreeModelListener l)
This method adds a TreeModelListener as an interested listener of events to this Tree.

Specified by:
addTreeModelListener in interface TreeModel
Parameters:
l - The tree listener to add.

removeTreeModelListener

public void removeTreeModelListener(TreeModelListener l)
This method removes the TreeModelListener as an interested listener of events to this Tree.

Specified by:
removeTreeModelListener in interface TreeModel
Parameters:
l - The tree listener to remove.

fireNodesInserted

protected void fireNodesInserted(Object source,
                                 BinaryTreeNode[] path)
This method must be called by all subclasses after a node is added to the Tree.

Parameters:
source - The tree on which the event occurred.
path - The path to the node that was added.

fireNodesRemoved

protected void fireNodesRemoved(Object source,
                                BinaryTreeNode[] path)
This method must be called by all subclasses after a node is removed from the Tree.

Parameters:
source - The tree on which the event occurred.
path - The path to the node that was removed.

fireNodesChanged

protected void fireNodesChanged(Object source,
                                BinaryTreeNode[] path)
This method must be called by all subclasses after the value of a node has changed.

Parameters:
source - The tree on which the event occurred.
path - The path to the node whose value changed.

fireStructureChanged

protected void fireStructureChanged(Object source,
                                    BinaryTreeNode[] path)
This method must be called by all subclasses after the structure of the tree has changed in some large way that will not fit into the simple classifications of the other fireXxx methods.

Parameters:
source - The tree on which the event occurred.
path - The path to the root of the subtree whose structure changed.

getTreeListeners

public TreeModelListener[] getTreeListeners()
Returns an array of all the tree listeners registered on this AbstractTreeModel.

Returns:
all of this model's TreeListeners, or an empty array if no tree listeners are currently registered

getListeners

public EventListener[] getListeners(Class listenerType)
Returns an array of all the objects currently registered as FooListeners upon this model. FooListeners are registered using the addFooListener method.

You can specify the listenerType argument with a class literal, such as FooListener.class. For example, you can query a list model m for its list data listeners with the following code:

TreeListener[] gls =
 (TreeListener[])(m.getListeners(TreeListener.class));
If no such listeners exist, this method returns an empty array.

Parameters:
listenerType - the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
Returns:
an array of all objects registered as FooListeners on this model, or an empty array if no such listeners have been added
Throws:
ClassCastException - if listenerType doesn't specify a class or interface that implements java.util.EventListener

remove

public abstract void remove(Object value)
Given a node's value, this method will find and remove that node from the tree. If the value does not occur in the tree

Parameters:
value - The value of the node to be removed.

add

public abstract void add(Object value)
This method will create a new node with the given value, and add it to the tree.

Parameters:
value - The value of the new node.