Package ptolemy.vergil.tree
Class EntityTreeModel
- java.lang.Object
-
- ptolemy.vergil.tree.EntityTreeModel
-
- All Implemented Interfaces:
javax.swing.tree.TreeModel
- Direct Known Subclasses:
ClassAndEntityTreeModel,CompositeTreeModel
public class EntityTreeModel extends java.lang.Object implements javax.swing.tree.TreeModelA tree model for Ptolemy II objects. This class makes it easy to view ptolemy models in a JTree, which renders the hierarchy. This base class handles only composite entities and their contained entities. It does not include entities that are class definitions. Derived classes represent more (or less) of the Ptolemy II model.- Since:
- Ptolemy II 1.0
- Version:
- $Id$
- Author:
- Steve Neuendorffer and Edward A. Lee, Contributor: Jianwu Wang
- Pt.AcceptedRating:
- Red (johnr)
- Pt.ProposedRating:
- Red (eal)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classEntityTreeModel.TreeUpdateListenerA ChangeListener that updates the Tree.
-
Constructor Summary
Constructors Constructor Description EntityTreeModel(NamedObj root)Create a new tree model with the specified root.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTreeModelListener(javax.swing.event.TreeModelListener listener)Add a listener to this model.java.lang.ObjectgetChild(java.lang.Object parent, int index)Get the child of the given parent at the given index.intgetChildCount(java.lang.Object parent)Return the number of children of the given parent, which in this base class is the number of contained entities.intgetIndexOfChild(java.lang.Object parent, java.lang.Object child)Return the index of the given child within the given parent.java.lang.ObjectgetRoot()Get the root of this tree model.booleanisLeaf(java.lang.Object object)Return true if the object is a leaf node.voidremoveTreeModelListener(javax.swing.event.TreeModelListener listener)Remove the specified listener.voidsetRoot(NamedObj root)Set the object that this treemodel looks at.voidvalueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)Notify listeners that the object at the given path has changed.
-
-
-
Field Detail
-
_root
protected NamedObj _root
The root of the tree.
-
-
Constructor Detail
-
EntityTreeModel
public EntityTreeModel(NamedObj root)
Create a new tree model with the specified root. Normally the root is an instance of CompositeEntity, but other root objects might be used by derived classes.- Parameters:
root- The root of the tree.
-
-
Method Detail
-
addTreeModelListener
public void addTreeModelListener(javax.swing.event.TreeModelListener listener)
Add a listener to this model.- Specified by:
addTreeModelListenerin interfacejavax.swing.tree.TreeModel- Parameters:
listener- The listener to add.- See Also:
removeTreeModelListener(TreeModelListener)
-
getChild
public java.lang.Object getChild(java.lang.Object parent, int index)Get the child of the given parent at the given index. If the child does not exist, then return null. In this base class, a child is a contained entity.- Specified by:
getChildin interfacejavax.swing.tree.TreeModel- Parameters:
parent- A node in the tree.index- The index of the desired child.- Returns:
- A node, or null if there is no such child.
-
getChildCount
public int getChildCount(java.lang.Object parent)
Return the number of children of the given parent, which in this base class is the number of contained entities.- Specified by:
getChildCountin interfacejavax.swing.tree.TreeModel- Parameters:
parent- A parent node.- Returns:
- The number of contained entities.
-
getIndexOfChild
public int getIndexOfChild(java.lang.Object parent, java.lang.Object child)Return the index of the given child within the given parent. If the parent is not contained in the child or is not an instance of CompositeEntity return -1.- Specified by:
getIndexOfChildin interfacejavax.swing.tree.TreeModel- Parameters:
parent- The parent, which is usually a CompositeEntity.child- The child.- Returns:
- The index of the specified child.
-
getRoot
public java.lang.Object getRoot()
Get the root of this tree model.- Specified by:
getRootin interfacejavax.swing.tree.TreeModel- Returns:
- A NamedObj, usually an Entity.
- See Also:
setRoot(NamedObj)
-
isLeaf
public boolean isLeaf(java.lang.Object object)
Return true if the object is a leaf node. In this base class, an object is a leaf node if it is not an instance of CompositeEntity.- Specified by:
isLeafin interfacejavax.swing.tree.TreeModel- Parameters:
object- The object in question.- Returns:
- True if the node has no children.
-
setRoot
public void setRoot(NamedObj root)
Set the object that this treemodel looks at.- Parameters:
root- The root NamedObj. BasicGraphFrame.dispose() calls this method and passes null as the value of root.- See Also:
getRoot()
-
removeTreeModelListener
public void removeTreeModelListener(javax.swing.event.TreeModelListener listener)
Remove the specified listener.- Specified by:
removeTreeModelListenerin interfacejavax.swing.tree.TreeModel- Parameters:
listener- The listener to remove.- See Also:
addTreeModelListener(TreeModelListener)
-
valueForPathChanged
public void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)Notify listeners that the object at the given path has changed.- Specified by:
valueForPathChangedin interfacejavax.swing.tree.TreeModel- Parameters:
path- The path of the node that has changed.newValue- The new value of the node.
-
-