Overview | Package | Class | Tree | Deprecated | Index | Help Java Platform
1.1.7
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class com.sun.java.swing.tree.DefaultTreeModel

java.lang.Object
  |
  +--com.sun.java.swing.tree.DefaultTreeModel

public class DefaultTreeModel
extends java.lang.Object
implements java.io.Serializable, TreeModel
A simple tree data model that uses TreeNodes.

Warning: serialized objects of this class will not be compatible with future swing releases. The current serialization support is appropriate for short term storage or RMI between Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.

See Also:
Serialized Form

Field Summary
boolean asksAllowsChildren
          Determines how the isLeaf determines if a node is a leaf node.
EventListenerList listenerList
          Listeners.
TreeNode root
          Root of the tree.
 
Constructor Summary
DefaultTreeModel(TreeNode root)
           
DefaultTreeModel(TreeNode root, boolean asksAllowsChildren)
           
 
Method Summary
void addTreeModelListener(TreeModelListener l)
           
boolean asksAllowsChildren()
          Tells how leaf nodes are determined.
void fireTreeNodesChanged(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
           
void fireTreeNodesInserted(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
           
void fireTreeNodesRemoved(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
           
void fireTreeStructureChanged(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
           
int getChildCount(java.lang.Object parent)
           
java.lang.Object getChild(java.lang.Object parent, int index)
           
int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
           
TreeNode[] getPathToRoot(TreeNode aNode)
          Builds the parents of node up to and including the root node, where the original node is the last element in the returned array.
TreeNode[] getPathToRoot(TreeNode aNode, int depth)
          Builds the parents of node up to and including the root node, where the original node is the last element in the returned array.
java.lang.Object getRoot()
           
void insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int index)
          Invoked this to insert newChild at location index in parents children.
boolean isLeaf(java.lang.Object node)
          Returns whether the specified node is a leaf node.
void nodeChanged(TreeNode node)
          Invoke this method after you've changed how node is to be represented in the tree.
void nodesChanged(TreeNode node, int[] childIndices)
          Invoke this method after you've changed how the children identified by childIndicies are to be represented in the tree.
void nodeStructureChanged(TreeNode node)
          Invoke this method if you've totally changed the children of node and its childrens children...
void nodesWereInserted(TreeNode node, int[] childIndices)
          Invoke this method after you've inserted some TreeNodes into node. childIndices should be the index of the new elements and must be sorted in ascending order.
void nodesWereRemoved(TreeNode node, int[] childIndices, java.lang.Object[] removedChildren)
          Invoke this method after you've removed some TreeNodes from node. childIndices should be the index of the removed elements and must be sorted in ascending order.
void reload()
          Invoke this method if you've modified the TreeNodes upon which this model depends.
void reload(TreeNode node)
          Invoke this method if you've modified the TreeNodes upon which this model depends.
void removeNodeFromParent(MutableTreeNode node)
          Message this to remove node from its parent.
void removeTreeModelListener(TreeModelListener l)
           
void setAsksAllowsChildren(boolean newValue)
          Sets whether or not to test leafness by asking getAllowsChildren() or isLeaf() to the TreeNodes.
void valueForPathChanged(TreePath path, java.lang.Object newValue)
          This sets the user object of the TreeNode identified by path and posts a node changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Field Detail

root

protected TreeNode root
Root of the tree.

listenerList

protected EventListenerList listenerList
Listeners.

asksAllowsChildren

protected boolean asksAllowsChildren
Determines how the isLeaf determines if a node is a leaf node. If true, a node is a leaf node if it does not allow children. (If it allows children, it is not a leaf node, even if no children are present.) If this value is false, then any node which has no children is a leaf node.
See Also:
getAllowsChildren, isLeaf, setAsksAllowsChildren
Constructor Detail

DefaultTreeModel

public DefaultTreeModel(TreeNode root)

DefaultTreeModel

public DefaultTreeModel(TreeNode root,
                        boolean asksAllowsChildren)
Method Detail

setAsksAllowsChildren

public void setAsksAllowsChildren(boolean newValue)
Sets whether or not to test leafness by asking getAllowsChildren() or isLeaf() to the TreeNodes. If newvalue is true, getAllowsChildren() is messaged, otherwise isLeaf() is messaged.

asksAllowsChildren

public boolean asksAllowsChildren()
Tells how leaf nodes are determined.
Returns:
true if only nodes which do not allow children are leaf nodes, false if nodes which have no children (even if allowed) are leaf nodes
See Also:
asksAllowsChildren

getRoot

public java.lang.Object getRoot()
Description copied from interface:
Returns the root of the tree. Returns null only if the tree has no nodes.
Specified by:
getRoot in interface TreeModel

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
Description copied from interface:
Returns the index of child in parent.
Specified by:
getIndexOfChild in interface TreeModel

getChild

public java.lang.Object getChild(java.lang.Object parent,
                       int index)
Description copied from interface:
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.
Specified by:
getChild in interface TreeModel

getChildCount

public int getChildCount(java.lang.Object parent)
Description copied from interface:
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:
getChildCount in interface TreeModel

isLeaf

public boolean isLeaf(java.lang.Object node)
Returns whether the specified node is a leaf node. The way the test is performed depends on the askAllowsChildren setting.
Specified by:
isLeaf in interface TreeModel
Parameters:
node - the node to check
Returns:
true if the node is a leaf node
See Also:
asksAllowsChildren, isLeaf

reload

public void reload()
Invoke this method if you've modified the TreeNodes upon which this model depends. The model will notify all of its listeners that the model has changed.

valueForPathChanged

public void valueForPathChanged(TreePath path,
                                java.lang.Object newValue)
This sets the user object of the TreeNode identified by path and posts a node changed. If you use custom user objects in the TreeModel you're going to need to subclass this and set the user object of the changed node to something meaningful.
Specified by:
valueForPathChanged in interface TreeModel

insertNodeInto

public void insertNodeInto(MutableTreeNode newChild,
                           MutableTreeNode parent,
                           int index)
Invoked this to insert newChild at location index in parents children. This will then message nodesWereInserted to create the appropriate event. This is the preferred way to add children as it will create the appropriate event.

removeNodeFromParent

public void removeNodeFromParent(MutableTreeNode node)
Message this to remove node from its parent. This will message nodesWereRemoved to create the appropriate event. This is the preferred way to remove a node as it handles the event creation for you.

nodeChanged

public void nodeChanged(TreeNode node)
Invoke this method after you've changed how node is to be represented in the tree.

reload

public void reload(TreeNode node)
Invoke this method if you've modified the TreeNodes upon which this model depends. The model will notify all of its listeners that the model has changed below the node node (PENDING).

nodesWereInserted

public void nodesWereInserted(TreeNode node,
                              int[] childIndices)
Invoke this method after you've inserted some TreeNodes into node. childIndices should be the index of the new elements and must be sorted in ascending order.

nodesWereRemoved

public void nodesWereRemoved(TreeNode node,
                             int[] childIndices,
                             java.lang.Object[] removedChildren)
Invoke this method after you've removed some TreeNodes from node. childIndices should be the index of the removed elements and must be sorted in ascending order. And removedChildren should be the array of the children objects that were removed.

nodesChanged

public void nodesChanged(TreeNode node,
                         int[] childIndices)
Invoke this method after you've changed how the children identified by childIndicies are to be represented in the tree.

nodeStructureChanged

public void nodeStructureChanged(TreeNode node)
Invoke this method if you've totally changed the children of node and its childrens children... This will post a treeStructureChanged event.

getPathToRoot

public TreeNode[] getPathToRoot(TreeNode aNode)
Builds the parents of node up to and including the root node, where the original node is the last element in the returned array. The length of the returned array gives the node's depth in the tree.
Parameters:
aNode - the TreeNode to get the path for
an - array of TreeNodes giving the path from the root to the specified node.

getPathToRoot

protected TreeNode[] getPathToRoot(TreeNode aNode,
                                   int depth)
Builds the parents of node up to and including the root node, where the original node is the last element in the returned array. The length of the returned array gives the node's depth in the tree.
Parameters:
aNode - the TreeNode to get the path for
depth - an int giving the number of steps already taken towards the root (on recursive calls), used to size the returned array
Returns:
an array of TreeNodes giving the path from the root to the specified node

addTreeModelListener

public void addTreeModelListener(TreeModelListener l)
Description copied from interface:
Adds a listener for the TreeModelEvent posted after the tree changes.
Specified by:
addTreeModelListener in interface TreeModel

removeTreeModelListener

public void removeTreeModelListener(TreeModelListener l)
Description copied from interface:
Removes a listener previously added with addTreeModelListener().
Specified by:
removeTreeModelListener in interface TreeModel

fireTreeNodesChanged

protected void fireTreeNodesChanged(java.lang.Object source,
                                    java.lang.Object[] path,
                                    int[] childIndices,
                                    java.lang.Object[] children)

fireTreeNodesInserted

protected void fireTreeNodesInserted(java.lang.Object source,
                                     java.lang.Object[] path,
                                     int[] childIndices,
                                     java.lang.Object[] children)

fireTreeNodesRemoved

protected void fireTreeNodesRemoved(java.lang.Object source,
                                    java.lang.Object[] path,
                                    int[] childIndices,
                                    java.lang.Object[] children)

fireTreeStructureChanged

protected void fireTreeStructureChanged(java.lang.Object source,
                                        java.lang.Object[] path,
                                        int[] childIndices,
                                        java.lang.Object[] children)

Overview | Package | Class | Tree | Deprecated | Index | Help Java Platform
1.1.7
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Submit a bug or feature
Submit comments/suggestions about javadoc
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.