javax.swing.tree
public class DefaultTreeModel extends Object implements Serializable, TreeModel
Modifier and Type | Field and Description |
---|---|
protected boolean |
asksAllowsChildren
asksAllowsChildren
|
protected EventListenerList |
listenerList
listenerList
|
protected TreeNode |
root
root
|
Constructor and Description |
---|
DefaultTreeModel(TreeNode root)
Constructor DefaultTreeModel where any node can have children.
|
DefaultTreeModel(TreeNode aRoot,
boolean asksAllowsChildren)
Create the DefaultTreeModel that may check if the nodes can have
children or not.
|
Modifier and Type | Method and Description |
---|---|
void |
addTreeModelListener(TreeModelListener listener)
Registers a listere to the model.
|
boolean |
asksAllowsChildren()
asksAllowsChildren
|
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
|
<T extends EventListener> |
getListeners(Class<T> listenerType)
Returns the registered listeners of a given type.
|
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 |
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 |
nodeStructureChanged(TreeNode node)
Invoke this method if you've totally changed the children of node and
its childrens children.
|
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.
|
protected EventListenerList listenerList
protected boolean asksAllowsChildren
public DefaultTreeModel(TreeNode root)
root
- the tree root.public DefaultTreeModel(TreeNode aRoot, boolean asksAllowsChildren)
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.public boolean asksAllowsChildren()
public void setAsksAllowsChildren(boolean value)
value
- TODOpublic int getIndexOfChild(Object parent, Object child)
getIndexOfChild
in interface TreeModel
parent
- TODOchild
- TODOpublic int getChildCount(Object node)
getChildCount
in interface TreeModel
node
- TODOpublic boolean isLeaf(Object node)
asksAllowsChildren
is true, then this checks if the TreeNode
allows children, otherwise it returns the TreeNode's leaf
property.isLeaf
in interface TreeModel
node
- the node to checktrue
if the node is a leaf node,
false
otherwiseClassCastException
- if the specified node is not a
TreeNode
instanceTreeNode.getAllowsChildren()
,
TreeNode.isLeaf()
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)
.
public void reload(TreeNode node)
node
- - the tree node, from which the tree nodes have changed
(inclusive). If you do not know this node, call reload()
instead.public void valueForPathChanged(TreePath path, Object newValue)
valueForPathChanged
in interface TreeModel
path
- - path to the node that the user has alterednewValue
- - the new value from the TreeCellEditorpublic void insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int index)
newChild
- is the node to add to the parent's childrenparent
- is the parent of the newChildindex
- is the index of the newChildpublic void removeNodeFromParent(MutableTreeNode node)
node
- to be removedpublic void nodeChanged(TreeNode node)
node
- that was changedpublic void nodesWereInserted(TreeNode parent, int[] childIndices)
parent
- that had a child added tochildIndices
- of the children addedpublic void nodesWereRemoved(TreeNode parent, int[] childIndices, Object[] removedChildren)
parent
- that had a child added tochildIndices
- of the children addedremovedChildren
- are all the children removed from parent.public void nodesChanged(TreeNode node, int[] childIndices)
node
- that is the parent of the children that changed in a tree.childIndices
- are the child nodes that changed.public void nodeStructureChanged(TreeNode node)
node
- that had its children and grandchildren changed.public TreeNode[] getPathToRoot(TreeNode node)
node
- - the TreeNode to get the path forprotected TreeNode[] getPathToRoot(TreeNode node, int depth)
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 arraypublic void addTreeModelListener(TreeModelListener listener)
addTreeModelListener
in interface TreeModel
listener
- the listener to addpublic void removeTreeModelListener(TreeModelListener listener)
removeTreeModelListener
in interface TreeModel
listener
- the listener to removepublic TreeModelListener[] getTreeModelListeners()
TreeModelListener
listeners.protected void fireTreeNodesChanged(Object source, Object[] path, int[] childIndices, Object[] children)
source
- the node being changedpath
- the path to the root nodechildIndices
- the indices of the changed elementschildren
- the changed elementsprotected void fireTreeNodesInserted(Object source, Object[] path, int[] childIndices, Object[] children)
source
- the node where new nodes got insertedpath
- the path to the root nodechildIndices
- the indices of the new elementschildren
- the new elementsprotected void fireTreeNodesRemoved(Object source, Object[] path, int[] childIndices, Object[] children)
source
- the node where nodes got removed-path
- the path to the root nodechildIndices
- the indices of the removed elementschildren
- the removed elementsprotected void fireTreeStructureChanged(Object source, Object[] path, int[] childIndices, Object[] children)
source
- the node where the model has changedpath
- the path to the root nodechildIndices
- the indices of the affected elementschildren
- the affected elementspublic <T extends EventListener> T[] getListeners(Class<T> listenerType)
listenerType
- the listener type to return