javax.swing.tree
Class DefaultTreeModel
- Serializable, TreeModel
DefaultTreeModel
void | addTreeModelListener(TreeModelListener listener) - Registers a listere to the model.
|
boolean | asksAllowsChildren() - asksAllowsChildren
|
| extends EventListener> T[] getListeners(Class listenerType) - Returns the registered listeners of a given type.
|
protected void | fireTreeNodesChanged(Object source, Object[] path, int[] childIndices, Object[] children) - Notifies all listeners that have registered interest for notification
on this event type.
|
protected void | fireTreeNodesInserted(Object source, Object[] path, int[] childIndices, Object[] children) - fireTreeNodesInserted
|
protected void | fireTreeNodesRemoved(Object source, Object[] path, int[] childIndices, Object[] children) - fireTreeNodesRemoved
|
protected void | fireTreeStructureChanged(Object source, Object[] path, int[] childIndices, Object[] children) - fireTreeStructureChanged
|
Object | getChild(Object node, int idx) - getChild
|
int | getChildCount(Object node) - getChildCount
|
int | getIndexOfChild(Object parent, Object child) - getIndexOfChild
|
TreeNode[] | getPathToRoot(TreeNode node) - Builds the parents of node up to and including the root node, where
the original node is the last element in the returned array.
|
protected TreeNode[] | getPathToRoot(TreeNode node, 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.
|
Object | getRoot() - getRoot
|
TreeModelListener[] | getTreeModelListeners() - Returns all registered
TreeModelListener listeners.
|
void | insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int index) - Invoked this to insert newChild at location index in parents children.
|
boolean | isLeaf(Object node) - Returns if the specified node is a leaf or not.
|
void | nodeChanged(TreeNode node) - Invoke this method after you've changed how node is 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 | nodesChanged(TreeNode node, int[] childIndices) - Invoke this method after you've changed how the children identified by
childIndices are to be represented in the tree.
|
void | nodesWereInserted(TreeNode parent, 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 parent, int[] childIndices, Object[] removedChildren) - Invoke this method after you've removed some TreeNodes from node.
|
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 listener) - Removes a listener from the model.
|
void | setAsksAllowsChildren(boolean value) - setAsksAllowsChildren
|
void | setRoot(TreeNode root) - setRoot
|
void | valueForPathChanged(TreePath path, Object newValue) - Messaged when the user has altered the value for the item
identified by path to newValue.
|
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
DefaultTreeModel
public DefaultTreeModel(TreeNode aRoot,
boolean asksAllowsChildren)
Create the DefaultTreeModel that may check if the nodes can have
children or not.
aRoot
- the tree root.asksAllowsChildren
- if true, each node is asked if it can have
children. If false, the model does not care about this, supposing, that
any node can have children.
extends EventListener> T[] getListeners
public extends EventListener> T[] getListeners(Class listenerType)
Returns the registered listeners of a given type.
listenerType
- the listener type to return
fireTreeNodesChanged
protected void fireTreeNodesChanged(Object source,
Object[] path,
int[] childIndices,
Object[] children)
Notifies all listeners that have registered interest for notification
on this event type. The event instance is lazily created using the parameters
passed into the fire method.
source
- the node being changedpath
- the path to the root nodechildIndices
- the indices of the changed elementschildren
- the changed elements
fireTreeNodesInserted
protected void fireTreeNodesInserted(Object source,
Object[] path,
int[] childIndices,
Object[] children)
fireTreeNodesInserted
source
- the node where new nodes got insertedpath
- the path to the root nodechildIndices
- the indices of the new elementschildren
- the new elements
fireTreeNodesRemoved
protected void fireTreeNodesRemoved(Object source,
Object[] path,
int[] childIndices,
Object[] children)
fireTreeNodesRemoved
source
- the node where nodes got removed-path
- the path to the root nodechildIndices
- the indices of the removed elementschildren
- the removed elements
fireTreeStructureChanged
protected void fireTreeStructureChanged(Object source,
Object[] path,
int[] childIndices,
Object[] children)
fireTreeStructureChanged
source
- the node where the model has changedpath
- the path to the root nodechildIndices
- the indices of the affected elementschildren
- the affected elements
getPathToRoot
public TreeNode[] getPathToRoot(TreeNode node)
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.
node
- - the TreeNode to get the path for
- TreeNode[] - the path from node to the root
getPathToRoot
protected TreeNode[] getPathToRoot(TreeNode node,
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.
node
- - the TreeNode to get the path fordepth
- - an int giving the number of steps already taken
towards the root (on recursive calls), used to size the returned array
- an array of TreeNodes giving the path from the root to the
specified node
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.
newChild
- is the node to add to the parent's childrenparent
- is the parent of the newChildindex
- is the index of the newChild
isLeaf
public boolean isLeaf(Object node)
Returns if the specified node is a leaf or not. When
asksAllowsChildren
is true, then this checks if the TreeNode
allows children, otherwise it returns the TreeNode's
leaf
property.
- isLeaf in interface TreeModel
- boolean
true
if the node is a leaf node,
false
otherwise
nodeChanged
public void nodeChanged(TreeNode node)
Invoke this method after you've changed how node is 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.
node
- that had its children and grandchildren changed.
nodesChanged
public void nodesChanged(TreeNode node,
int[] childIndices)
Invoke this method after you've changed how the children identified by
childIndices are to be represented in the tree.
node
- that is the parent of the children that changed in a tree.childIndices
- are the child nodes that changed.
nodesWereInserted
public void nodesWereInserted(TreeNode parent,
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.
parent
- that had a child added tochildIndices
- of the children added
nodesWereRemoved
public void nodesWereRemoved(TreeNode parent,
int[] childIndices,
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.
parent
- that had a child added tochildIndices
- of the children addedremovedChildren
- are all the children removed from parent.
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. It will fire the events, necessary to update the layout caches and
repaint the tree. The tree will
not be properly refreshed if you
call the JTree.repaint instead.
This method will refresh the information about whole tree from the root. If
only part of the tree should be refreshed, it is more effective to call
reload(TreeNode)
.
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. It will fire the events, necessary to update the layout caches and
repaint the tree. The tree will not be properly refreshed if you
call the JTree.repaint instead.
node
- - the tree node, from which the tree nodes have changed
(inclusive). If you do not know this node, call reload()
instead.
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.
valueForPathChanged
public void valueForPathChanged(TreePath path,
Object newValue)
Messaged when the user has altered the value for the item
identified by path to newValue. If newValue signifies a truly new
value the model should post a treeNodesChanged event.
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.
- valueForPathChanged in interface TreeModel
path
- - path to the node that the user has alterednewValue
- - the new value from the TreeCellEditor
DefaultTreeModel.java --
Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.