Package com.sun.demo
Class ElementTreePanel.ElementTreeModel
java.lang.Object
javax.swing.tree.DefaultTreeModel
com.sun.demo.ElementTreePanel.ElementTreeModel
- All Implemented Interfaces:
Serializable,TreeModel
- Enclosing class:
- ElementTreePanel
ElementTreeModel is an implementation of TreeModel to handle displaying
the Elements from a Document. AbstractDocument.AbstractElement is
the default implementation used by the swing text package to implement
Element, and it implements TreeNode. This makes it trivial to create
a DefaultTreeModel rooted at a particular Element from the Document.
Unfortunately each Document can have more than one root Element.
Implying that to display all the root elements as a child of another
root a fake node has be created. This class creates a fake node as
the root with the children being the root elements of the Document
(getRootElements).
This subclasses DefaultTreeModel. The majority of the TreeModel methods have been subclassed, primarily to special case the root.
- See Also:
-
Field Summary
FieldsFields inherited from class javax.swing.tree.DefaultTreeModel
asksAllowsChildren, listenerList, root -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the child of parent at index index in the parent's child array.intgetChildCount(Object parent) Returns the number of children of parent.intgetIndexOfChild(Object parent, Object child) Returns the index of child in parent.protected TreeNode[]getPathToRoot(TreeNode aNode, int depth) Returns the path to a particluar node.booleanReturns true if node is a leaf.voidnodeChanged(TreeNode node) Invoke this method after you've changed how node is to be represented in the tree.Methods inherited from class javax.swing.tree.DefaultTreeModel
addTreeModelListener, asksAllowsChildren, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeStructureChanged, getListeners, getPathToRoot, getRoot, getTreeModelListeners, insertNodeInto, nodesChanged, nodeStructureChanged, nodesWereInserted, nodesWereRemoved, reload, reload, removeNodeFromParent, removeTreeModelListener, setAsksAllowsChildren, setRoot, valueForPathChanged
-
Field Details
-
rootElements
-
-
Constructor Details
-
ElementTreeModel
-
-
Method Details
-
getChild
Returns the child of parent at index index in the parent's child array. parent must be a node previously obtained from this data source. This should not return null if index is a valid index for parent (that is index >= 0 && index < getChildCount(parent)).- Specified by:
getChildin interfaceTreeModel- Overrides:
getChildin classDefaultTreeModel- Parameters:
parent- a node in the tree, obtained from this data source- Returns:
- the child of parent at index index
-
getChildCount
Returns the number of children of parent. Returns 0 if the node is a leaf or if it has no children. parent must be a node previously obtained from this data source.- Specified by:
getChildCountin interfaceTreeModel- Overrides:
getChildCountin classDefaultTreeModel- Parameters:
parent- a node in the tree, obtained from this data source- Returns:
- the number of children of the node parent
-
isLeaf
Returns true if node is a leaf. It is possible for this method to return false even if node has no children. A directory in a filesystem, for example, may contain no files; the node representing the directory is not a leaf, but it also has no children.- Specified by:
isLeafin interfaceTreeModel- Overrides:
isLeafin classDefaultTreeModel- Parameters:
node- a node in the tree, obtained from this data source- Returns:
- true if node is a leaf
-
getIndexOfChild
Returns the index of child in parent.- Specified by:
getIndexOfChildin interfaceTreeModel- Overrides:
getIndexOfChildin classDefaultTreeModel
-
nodeChanged
Invoke this method after you've changed how node is to be represented in the tree.- Overrides:
nodeChangedin classDefaultTreeModel
-
getPathToRoot
Returns the path to a particluar node. This is recursive.- Overrides:
getPathToRootin classDefaultTreeModel
-