Packageorg.aswing.tree
Classpublic class DefaultTreeModel
ImplementsTreeModel

A simple tree data model that uses TreeNodes.

See also

org.aswing.tree.DefaultMutableTreeNode


Public Methods
 MethodDefined by
  
DefaultTreeModel(root:TreeNode, asc:Boolean = false)
Creates a tree specifying whether any node can have children, or whether only certain nodes can have children.
DefaultTreeModel
  
Adds a listener for the TreeModelEvent posted after the tree changes.
DefaultTreeModel
  
Tells how leaf nodes are determined.
DefaultTreeModel
  
getChild(parent:Object, index:int):Object
Returns the child of parent at index index in the parent's child array.
DefaultTreeModel
  
getChildCount(parent:Object):int
Returns the number of children of parent.
DefaultTreeModel
  
getIndexOfChild(parent:Object, child:Object):int
Returns the index of child in parent.
DefaultTreeModel
  
getRoot():Object
Returns the root of the tree.
DefaultTreeModel
  
insertNodeInto(newChild:MutableTreeNode, parent:MutableTreeNode, index:int):void
Invoked this to insert newChild at location index in parents children.
DefaultTreeModel
  
isLeaf(node:Object):Boolean
Returns whether the specified node is a leaf node.
DefaultTreeModel
  
nodeChanged(node:TreeNode):void
Invoke this method after you've changed how node is to be represented in the tree.
DefaultTreeModel
  
nodesChanged(node:TreeNode, childIndices:Array):void
Invoke this method after you've changed how the children identified by childIndicies are to be represented in the tree.
DefaultTreeModel
  
Invoke this method if you've totally changed the children of node and its childrens children...
DefaultTreeModel
  
nodesWereInserted(node:TreeNode, childIndices:Array):void
Invoke this method after you've inserted some TreeNodes into node.
DefaultTreeModel
  
nodesWereRemoved(node:TreeNode, childIndices:Array, removedChildren:Array):void
Invoke this method after you've removed some TreeNodes from node.
DefaultTreeModel
  
reload(node:TreeNode = null):void
Invoke this method if you've modified the TreeNodes upon which this model depends.
DefaultTreeModel
  
Message this to remove node from its parent.
DefaultTreeModel
  
Removes a listener previously added with addTreeModelListener().
DefaultTreeModel
  
setAsksAllowsChildren(newValue:Boolean):void
Sets whether or not to test leafness by asking getAllowsChildren() or isLeaf() to the TreeNodes.
DefaultTreeModel
  
setRoot(root:TreeNode):void
Sets the root to root.
DefaultTreeModel
  
toString():String
DefaultTreeModel
  
valueForPathChanged(path:TreePath, newValue:Object):void
This sets the user object of the TreeNode identified by path and posts a node changed.
DefaultTreeModel
Constructor detail
DefaultTreeModel()constructor
public function DefaultTreeModel(root:TreeNode, asc:Boolean = false)

Creates a tree specifying whether any node can have children, or whether only certain nodes can have children.

Parameters
root:TreeNode — a TreeNode object that is the root of the tree
 
asc:Boolean (default = false) — (optional)a boolean, false if any node can have children, true if each node is asked to see if it can have children. Default is false.

See also

Method detail
addTreeModelListener()method
public function addTreeModelListener(l:TreeModelListener):void

Adds a listener for the TreeModelEvent posted after the tree changes.

Parameters
l:TreeModelListener — l the listener to add

See also

asksAllowsChildren()method 
public function asksAllowsChildren():Boolean

Tells how leaf nodes are determined.

Returns
Boolean — 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

getChild()method 
public function getChild(parent:Object, index:int):Object

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)).

Parameters
parent:Object — parent a node in the tree, obtained from this data source
 
index:int

Returns
Object — the child of parent at index index
getChildCount()method 
public function getChildCount(parent:Object):int

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.

Parameters
parent:Object — parent a node in the tree, obtained from this data source

Returns
int — the number of children of the node parent
getIndexOfChild()method 
public function getIndexOfChild(parent:Object, child:Object):int

Returns the index of child in parent. If either the parent or child is null, returns -1.

Parameters
parent:Object — a note in the tree, obtained from this data source
 
child:Object — the node we are interested in

Returns
int — the index of the child in the parent, or -1 if either the parent or the child is null
getRoot()method 
public function getRoot():Object

Returns the root of the tree. Returns null only if the tree has no nodes.

Returns
Object — the root of the tree
insertNodeInto()method 
public function insertNodeInto(newChild:MutableTreeNode, parent:MutableTreeNode, index:int):void

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.

Parameters
newChild:MutableTreeNode
 
parent:MutableTreeNode
 
index:int
isLeaf()method 
public function isLeaf(node:Object):Boolean

Returns whether the specified node is a leaf node. The way the test is performed depends on the askAllowsChildren setting.

Parameters
node:Object — the node to check

Returns
Boolean — true if the node is a leaf node

See also

nodeChanged()method 
public function nodeChanged(node:TreeNode):void

Invoke this method after you've changed how node is to be represented in the tree.

Parameters
node:TreeNode
nodesChanged()method 
public function nodesChanged(node:TreeNode, childIndices:Array):void

Invoke this method after you've changed how the children identified by childIndicies are to be represented in the tree.

Parameters
node:TreeNode
 
childIndices:Array
nodeStructureChanged()method 
public function nodeStructureChanged(node:TreeNode):void

Invoke this method if you've totally changed the children of node and its childrens children... This will post a treeStructureChanged event.

Parameters
node:TreeNode
nodesWereInserted()method 
public function nodesWereInserted(node:TreeNode, childIndices:Array):void

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.

Parameters
node:TreeNode
 
childIndices:Array
nodesWereRemoved()method 
public function nodesWereRemoved(node:TreeNode, childIndices:Array, removedChildren:Array):void

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.

Parameters
node:TreeNode
 
childIndices:Array
 
removedChildren:Array
reload()method 
public function reload(node:TreeNode = null):void

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).

Parameters
node:TreeNode (default = null) — (optional). Default is root.
removeNodeFromParent()method 
public function removeNodeFromParent(node:MutableTreeNode):void

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.

Parameters
node:MutableTreeNode
removeTreeModelListener()method 
public function removeTreeModelListener(l:TreeModelListener):void

Removes a listener previously added with addTreeModelListener().

Parameters
l:TreeModelListener — l the listener to remove

See also

setAsksAllowsChildren()method 
public function setAsksAllowsChildren(newValue:Boolean):void

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.

Parameters
newValue:Boolean
setRoot()method 
public function setRoot(root:TreeNode):void

Sets the root to root. A null root implies the tree is to display nothing, and is legal.

Parameters
root:TreeNode
toString()method 
public function toString():String

Returns
String
valueForPathChanged()method 
public function valueForPathChanged(path:TreePath, newValue:Object):void

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.

Parameters
path:TreePath
 
newValue:Object