org.progeeks.graph.swing
Class OrientedForestModel

java.lang.Object
  extended by org.progeeks.util.swing.AbstractTreeModel
      extended by org.progeeks.graph.swing.OrientedForestModel
All Implemented Interfaces:
javax.swing.tree.TreeModel

public class OrientedForestModel
extends AbstractTreeModel

Wraps an OrientedForest implementation in an implementation of TreeModel. If the OrientedForest contains or is an ObservableGraph then it is listened to for tree changes. The children are automatically sorted and so must implement comparable that will work with their siblings. If not, then a Comparator must be provided to do the sorting.

Version:
$Revision: 1.6 $
Author:
Paul Speed

Nested Class Summary
protected  class OrientedForestModel.GraphObserver
           
 
Field Summary
static java.lang.String BASE_ROOT
          Constant returned as the root.
 
Constructor Summary
OrientedForestModel()
           
 
Method Summary
protected  void addRoot(java.lang.Object node)
          Adds a node as a root node, performing whatever caching and event firing that is necessary.
protected  void clearCache()
           
protected  void fireTreeNodesChanged(javax.swing.event.TreeModelEvent event)
           
protected  void fireTreeNodesInserted(javax.swing.event.TreeModelEvent event)
           
protected  void fireTreeNodesRemoved(javax.swing.event.TreeModelEvent event)
           
protected  void fireTreeStructureChanged(javax.swing.event.TreeModelEvent event)
           
 java.util.List getChildList(java.lang.Object parent)
          Returns a List of child nodes for the specified parent.
 java.util.Comparator getComparator()
          Returns the current comparator used to sort the children.
 com.phoenixst.plexus.OrientedForest getOrientedForest()
           
 java.lang.Object getRoot()
          Always returns the BASE_ROOT constant.
 javax.swing.tree.TreePath getTreePath(java.lang.Object node)
          Returns a TreePath for the specified node based on the parent child relationship defined by the RootedTree.
 boolean getUseEdgesAsChildren()
          Returns true to return Graph.Edge objects for the children instead of just the nodes.
protected  boolean hasChildren(java.lang.Object parent)
          Optimized method for returning whether or not a node has children without having to retrieve the whole child list and sort it.
 boolean isLeaf(java.lang.Object node)
          Returns true if the specified node is a leaf.
protected  java.lang.Object nodeFromChild(java.lang.Object child)
          Converts a node from a child edge if necessary.
protected  void removeRoot(java.lang.Object node)
          Removes a node as a root node, performing whatever caching and event firing that is necessary.
 void setComparator(java.util.Comparator comparator)
          Sets a comparator to use when sorting the tree nodes.
 void setOrientedForest(com.phoenixst.plexus.OrientedForest forest)
           
 void setUseEdgesAsChildren(boolean flag)
          Set to true to return Graph.Edge objects for the children instead of just the nodes.
 
Methods inherited from class org.progeeks.util.swing.AbstractTreeModel
addTreeModelListener, getChild, getChildCount, getIndexOfChild, getListeners, removeTreeModelListener, valueForPathChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BASE_ROOT

public static final java.lang.String BASE_ROOT
Constant returned as the root. Forest roots will be children of this one root node. JTree requires a single root.

See Also:
Constant Field Values
Constructor Detail

OrientedForestModel

public OrientedForestModel()
Method Detail

setOrientedForest

public void setOrientedForest(com.phoenixst.plexus.OrientedForest forest)

getOrientedForest

public com.phoenixst.plexus.OrientedForest getOrientedForest()

setComparator

public void setComparator(java.util.Comparator comparator)
Sets a comparator to use when sorting the tree nodes. If this is null then the children are expected to be Comparable.


getComparator

public java.util.Comparator getComparator()
Returns the current comparator used to sort the children.


setUseEdgesAsChildren

public void setUseEdgesAsChildren(boolean flag)
Set to true to return Graph.Edge objects for the children instead of just the nodes.


getUseEdgesAsChildren

public boolean getUseEdgesAsChildren()
Returns true to return Graph.Edge objects for the children instead of just the nodes.


nodeFromChild

protected java.lang.Object nodeFromChild(java.lang.Object child)
Converts a node from a child edge if necessary.


getTreePath

public javax.swing.tree.TreePath getTreePath(java.lang.Object node)
Returns a TreePath for the specified node based on the parent child relationship defined by the RootedTree.


getRoot

public java.lang.Object getRoot()
Always returns the BASE_ROOT constant.


getChildList

public java.util.List getChildList(java.lang.Object parent)
Description copied from class: AbstractTreeModel
Returns a List of child nodes for the specified parent. This is an optional operation and may throw UnsupportedOperationException.

Overrides:
getChildList in class AbstractTreeModel

hasChildren

protected boolean hasChildren(java.lang.Object parent)
Optimized method for returning whether or not a node has children without having to retrieve the whole child list and sort it.


isLeaf

public boolean isLeaf(java.lang.Object node)
Returns true if the specified node is a leaf.

Specified by:
isLeaf in interface javax.swing.tree.TreeModel
Overrides:
isLeaf in class AbstractTreeModel

clearCache

protected void clearCache()

addRoot

protected void addRoot(java.lang.Object node)
Adds a node as a root node, performing whatever caching and event firing that is necessary. This method will ignore nodes that are not forest roots.


removeRoot

protected void removeRoot(java.lang.Object node)
Removes a node as a root node, performing whatever caching and event firing that is necessary.


fireTreeNodesChanged

protected void fireTreeNodesChanged(javax.swing.event.TreeModelEvent event)
Overrides:
fireTreeNodesChanged in class AbstractTreeModel

fireTreeNodesInserted

protected void fireTreeNodesInserted(javax.swing.event.TreeModelEvent event)
Overrides:
fireTreeNodesInserted in class AbstractTreeModel

fireTreeNodesRemoved

protected void fireTreeNodesRemoved(javax.swing.event.TreeModelEvent event)
Overrides:
fireTreeNodesRemoved in class AbstractTreeModel

fireTreeStructureChanged

protected void fireTreeStructureChanged(javax.swing.event.TreeModelEvent event)
Overrides:
fireTreeStructureChanged in class AbstractTreeModel


Copyright © 2002-2003 Paul Speed. All Rights Reserved.