org.peace_tools.data
Class MSTTreeModel

java.lang.Object
  extended by org.peace_tools.data.MSTTreeModel
All Implemented Interfaces:
javax.swing.tree.TreeModel

public class MSTTreeModel
extends java.lang.Object
implements javax.swing.tree.TreeModel

A bridge class between a MST and a JTree. This class serves as a bridge between the in-memory representation of a MST (represented by a recursively defined MSTNode set of classes). This class enables reusing the data set hierarchy maintained by the MSTNode object to display it in a JTree.


Field Summary
private  ESTList estList
          The list of ESTs for which this MST was constructed.
private  MST mst
          The MST data file that provides all the necessary information for displaying the MST.
private  java.util.ArrayList<javax.swing.event.TreeModelListener> treeModelListeners
          The list of tree mode listeners that were added to this tree model.
private  MSTData wsEntry
          A handy reference to the workspace entry from which the data for this MST tree model was actually obtained.
 
Constructor Summary
MSTTreeModel(MST mst, ESTList estList, MSTData wsEntry)
          The default constructor.
 
Method Summary
 void addTreeModelListener(javax.swing.event.TreeModelListener tml)
          Adds a listener to be notified when the data associated with the data set changes.
protected  void fireTreeStructureChanged(java.lang.Object oldRoot)
          The only event raised by this model is TreeStructureChanged with the appropriate entry to be
 java.lang.Object getChild(java.lang.Object parent, int index)
          This method provides the actual child object to be displayed in a JTree under a given node.
 int getChildCount(java.lang.Object parent)
          This method provides the child count for a given node.
 ESTList getESTList()
          Obtain the list of ESTs for which this MST was generated.
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
          This method provides the zero-based logical index of a child node.
 MST getMST()
          Obtain the raw MST file data associated with this model.
 java.lang.Object getRoot()
          Obtain the root of the data set tree.
 MSTData getWsEntry()
          Obtain the actual workspace entry whose data is contained in this model.
 boolean isLeaf(java.lang.Object entry)
          Method to determine if a given entry is a leaf object.
 void removeTreeModelListener(javax.swing.event.TreeModelListener tml)
          Removes a listener from the list of listeners maintained by this class.
 void valueForPathChanged(javax.swing.tree.TreePath arg0, java.lang.Object arg1)
          This data model is meant to be used with a read-only type JTree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

wsEntry

private final MSTData wsEntry
A handy reference to the workspace entry from which the data for this MST tree model was actually obtained. This information can be used by "view" classes to create additional views as needed.


mst

private final MST mst
The MST data file that provides all the necessary information for displaying the MST. The value is set when this class is instantiated.


estList

private final ESTList estList
The list of ESTs for which this MST was constructed. The value is set when this class is instantiated. The EST information is used to display additional information about the nodes in the MST.


treeModelListeners

private java.util.ArrayList<javax.swing.event.TreeModelListener> treeModelListeners
The list of tree mode listeners that were added to this tree model. This list is used to notify listeners that the tree has changed.

Constructor Detail

MSTTreeModel

public MSTTreeModel(MST mst,
                    ESTList estList,
                    MSTData wsEntry)
The default constructor. The constructor merely saves the root node of the MST for displaying it in a JTree.

Parameters:
mst - The MST data structure that is used to generate information for this tree model.
estList - The list of ESTs for which this MST was constructed. The EST information is used to display additional EST information in the MST display.
wsEntry - The workspace entry corresponding to the clusters being adapted by this object.
Method Detail

getMST

public MST getMST()
Obtain the raw MST file data associated with this model.

Returns:
The raw MST file data associated with this model.

getESTList

public ESTList getESTList()
Obtain the list of ESTs for which this MST was generated.

Returns:
The list of ESTs corresponding to this MST.

addTreeModelListener

public void addTreeModelListener(javax.swing.event.TreeModelListener tml)
Adds a listener to be notified when the data associated with the data set changes.

Specified by:
addTreeModelListener in interface javax.swing.tree.TreeModel
Parameters:
tml - The listener to be added to the list of listeners to be notified when the data associated with the work space changes.

removeTreeModelListener

public void removeTreeModelListener(javax.swing.event.TreeModelListener tml)
Removes a listener from the list of listeners maintained by this class.

Specified by:
removeTreeModelListener in interface javax.swing.tree.TreeModel
Parameters:
tml - The listener to be removed from the list of listeners to receive updates.

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)
This method provides the actual child object to be displayed in a JTree under a given node.

Specified by:
getChild in interface javax.swing.tree.TreeModel
Parameters:
parent - The object whose child is to be returned.
index - The index of the child to be returned by this method.
See Also:
TreeModel.getChildCount(java.lang.Object)

getChildCount

public int getChildCount(java.lang.Object parent)
This method provides the child count for a given node. The child count is zero for leaf nodes.

Specified by:
getChildCount in interface javax.swing.tree.TreeModel
Parameters:
parent - The object whose child counts is to be determined.

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
This method provides the zero-based logical index of a child node. The child node must have been obtained through a prior call to the getChild() method in this class.

Specified by:
getIndexOfChild in interface javax.swing.tree.TreeModel
Parameters:
parent - The object whose child index is to be determined.
child - The child node whose index is to be determined.
Returns:
The index of the child node if found. If the child node was not found, then this method returns -1.
See Also:
TreeModel.getChildCount(java.lang.Object)

getRoot

public java.lang.Object getRoot()
Obtain the root of the data set tree.

Specified by:
getRoot in interface javax.swing.tree.TreeModel
Returns:
The root node of the MST that was set when this class was instantiated.

isLeaf

public boolean isLeaf(java.lang.Object entry)
Method to determine if a given entry is a leaf object. This method returns false, if the entry is a leaf node in the MST. In all other cases, it returns true.

Specified by:
isLeaf in interface javax.swing.tree.TreeModel
Returns:
This method returns true if the entry is to be treated as a leaf node.

valueForPathChanged

public void valueForPathChanged(javax.swing.tree.TreePath arg0,
                                java.lang.Object arg1)
This data model is meant to be used with a read-only type JTree. Consequently, this method (that is meant to change the value in the tree) is not implemented and must not be called.

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

fireTreeStructureChanged

protected void fireTreeStructureChanged(java.lang.Object oldRoot)
The only event raised by this model is TreeStructureChanged with the appropriate entry to be


getWsEntry

public MSTData getWsEntry()
Obtain the actual workspace entry whose data is contained in this model. A handy reference to the workspace entry from which the data for this MST tree model was actually obtained. This information can be used by "view" classes to create additional views as needed.

Returns:
The reference to the MSTData workspace entry whose data is "modeled" by this class.