Class EntityTreeModel

  • All Implemented Interfaces:
    javax.swing.tree.TreeModel
    Direct Known Subclasses:
    ClassAndEntityTreeModel, CompositeTreeModel

    public class EntityTreeModel
    extends java.lang.Object
    implements javax.swing.tree.TreeModel
    A 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)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected NamedObj _root
      The root of 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
      void addTreeModelListener​(javax.swing.event.TreeModelListener listener)
      Add a listener to this model.
      java.lang.Object getChild​(java.lang.Object parent, int index)
      Get the child of the given parent at the given index.
      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.
      int getIndexOfChild​(java.lang.Object parent, java.lang.Object child)
      Return the index of the given child within the given parent.
      java.lang.Object getRoot()
      Get the root of this tree model.
      boolean isLeaf​(java.lang.Object object)
      Return true if the object is a leaf node.
      void removeTreeModelListener​(javax.swing.event.TreeModelListener listener)
      Remove the specified listener.
      void setRoot​(NamedObj root)
      Set the object that this treemodel looks at.
      void valueForPathChanged​(javax.swing.tree.TreePath path, java.lang.Object newValue)
      Notify listeners that the object at the given path has changed.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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:
        addTreeModelListener in interface javax.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:
        getChild in interface javax.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:
        getChildCount in interface javax.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:
        getIndexOfChild in interface javax.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:
        getRoot in interface javax.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:
        isLeaf in interface javax.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:
        removeTreeModelListener in interface javax.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:
        valueForPathChanged in interface javax.swing.tree.TreeModel
        Parameters:
        path - The path of the node that has changed.
        newValue - The new value of the node.