yu.ac.bg.etf.javaqx.qswing.tree
Class DefaultTreeModel

java.lang.Object
  extended byyu.ac.bg.etf.javaqx.qswing.tree.DefaultTreeModel
All Implemented Interfaces:
TreeModel

public class DefaultTreeModel
extends java.lang.Object
implements TreeModel

Default Tree Model.

Version:
0.2.0
Author:
Slobodan Vrkacevic (slobodan.vrkacevic@gmail.com)

Field Summary
protected  boolean asksAllowsChildren
           
static TreeNode[] EMPTY_TREE_NODE_ARRAY
          Empty array of tree nodes (the value is TreeNode[0]).
protected  EventListenerList listenerList
           
protected  TreeNode root
           
 
Constructor Summary
DefaultTreeModel(TreeNode root)
          Constructs new DefaultTreeModel object.
DefaultTreeModel(TreeNode root, boolean asksAllowsChildren)
          Constructs new DefaultTreeModel object.
 
Method Summary
 void addTreeModelListener(TreeModelListener listener)
          Adds tree mode listener.
 boolean asksAllowsChildren()
          Returns true if leaf nodes are determined.
protected  void fireTreeNodesChanged(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
          Fires tree nodes changed event.
protected  void fireTreeNodesInserted(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
          Fires tree nodes removed event.
protected  void fireTreeNodesRemoved(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
          Fires tree nodes inserted event.
protected  void fireTreeStructureChanged(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children)
          Fires tree structure changed event.
protected  void fireTreeStructureChanged(java.lang.Object source, TreePath path)
          Fires tree structure changed event.
 java.lang.Object getChild(java.lang.Object parent, int index)
          Returns child of the specified parent at specified index.
 int getChildCount(java.lang.Object parent)
          Returns the number of children of specified parent.
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
          Returns index of child of specified parent.
 TreeNode[] getPathToRoot(TreeNode node)
          Returns path to the root for the specified node.
protected  TreeNode[] getPathToRoot(TreeNode node, int depth)
          Returns path to the root for the specified node.
 java.lang.Object getRoot()
          Returns root.
 TreeModelListener[] getTreeModelListeners()
          Returns tree model listeners.
 boolean isLeaf(java.lang.Object node)
          Returns true if node is leaf.
 void nodeChanged(TreeNode node)
          Called when node has changed.
 void nodesChanged(TreeNode node, int[] childIndices)
          Called when node has changed.
 void nodeStructureChanged(TreeNode node)
          Called when node structure has changed.
 void removeTreeModelListener(TreeModelListener listener)
          Removes tree mode listener.
 void setAsksAllowsChildren(boolean asksAllowsChildren)
          Sets whether or not the leaf nodes are determined.
 void setRoot(TreeNode root)
          Sets root node.
 void valueForPathChanged(TreePath path, java.lang.Object value)
          Sets new value for the specified node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_TREE_NODE_ARRAY

public static final TreeNode[] EMPTY_TREE_NODE_ARRAY
Empty array of tree nodes (the value is TreeNode[0]).


root

protected TreeNode root

asksAllowsChildren

protected boolean asksAllowsChildren

listenerList

protected final EventListenerList listenerList
Constructor Detail

DefaultTreeModel

public DefaultTreeModel(TreeNode root)
Constructs new DefaultTreeModel object.

Parameters:
root - the root

DefaultTreeModel

public DefaultTreeModel(TreeNode root,
                        boolean asksAllowsChildren)
Constructs new DefaultTreeModel object.

Parameters:
root - the root
asksAllowsChildren - true if leaf nodes are determined
Method Detail

setRoot

public void setRoot(TreeNode root)
Sets root node.

Parameters:
root - the root node

asksAllowsChildren

public boolean asksAllowsChildren()
Returns true if leaf nodes are determined.

Returns:
true if leaf nodes are determined

setAsksAllowsChildren

public void setAsksAllowsChildren(boolean asksAllowsChildren)
Sets whether or not the leaf nodes are determined.

Parameters:
asksAllowsChildren - true if determined

getTreeModelListeners

public TreeModelListener[] getTreeModelListeners()
Returns tree model listeners.

Returns:
tree model listeners

nodeStructureChanged

public void nodeStructureChanged(TreeNode node)
Called when node structure has changed.

Parameters:
node - the node

nodeChanged

public void nodeChanged(TreeNode node)
Called when node has changed.

Parameters:
node - the node

nodesChanged

public void nodesChanged(TreeNode node,
                         int[] childIndices)
Called when node has changed.

Parameters:
node - the node
childIndices - the child indices

getPathToRoot

public TreeNode[] getPathToRoot(TreeNode node)
Returns path to the root for the specified node.

Parameters:
node - the node
Returns:
path to the root for the specified node

getPathToRoot

protected TreeNode[] getPathToRoot(TreeNode node,
                                   int depth)
Returns path to the root for the specified node.

Parameters:
node - the node
depth - the depth
Returns:
path to the root for the specified node

fireTreeNodesChanged

protected void fireTreeNodesChanged(java.lang.Object source,
                                    java.lang.Object[] path,
                                    int[] childIndices,
                                    java.lang.Object[] children)
Fires tree nodes changed event.

Parameters:
source - the source node
path - the path
childIndices - the child indices
children - the new children

fireTreeStructureChanged

protected void fireTreeStructureChanged(java.lang.Object source,
                                        TreePath path)
Fires tree structure changed event.

Parameters:
source - the source node
path - the path

fireTreeStructureChanged

protected void fireTreeStructureChanged(java.lang.Object source,
                                        java.lang.Object[] path,
                                        int[] childIndices,
                                        java.lang.Object[] children)
Fires tree structure changed event.

Parameters:
source - the source node
path - the path
childIndices - the child indices
children - the new children

fireTreeNodesInserted

protected void fireTreeNodesInserted(java.lang.Object source,
                                     java.lang.Object[] path,
                                     int[] childIndices,
                                     java.lang.Object[] children)
Fires tree nodes removed event.

Parameters:
source - the source node
path - the path
childIndices - the child indices
children - the new children

fireTreeNodesRemoved

protected void fireTreeNodesRemoved(java.lang.Object source,
                                    java.lang.Object[] path,
                                    int[] childIndices,
                                    java.lang.Object[] children)
Fires tree nodes inserted event.

Parameters:
source - the source node
path - the path
childIndices - the child indices
children - the new children

getRoot

public java.lang.Object getRoot()
Returns root.

Specified by:
getRoot in interface TreeModel
Returns:
root

isLeaf

public boolean isLeaf(java.lang.Object node)
Returns true if node is leaf.

Specified by:
isLeaf in interface TreeModel
Parameters:
node - the node
Returns:
true if node is leaf

getChildCount

public int getChildCount(java.lang.Object parent)
Returns the number of children of specified parent.

Specified by:
getChildCount in interface TreeModel
Parameters:
parent - the parent
Returns:
the number of children of specified parent

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)
Returns child of the specified parent at specified index.

Specified by:
getChild in interface TreeModel
Parameters:
parent - the parent
index - the index
Returns:
child of the specified parent at specified index

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
Returns index of child of specified parent.

Specified by:
getIndexOfChild in interface TreeModel
Parameters:
parent - the parent
child - the child
Returns:
index of child of specified parent

valueForPathChanged

public void valueForPathChanged(TreePath path,
                                java.lang.Object value)
Sets new value for the specified node.

Specified by:
valueForPathChanged in interface TreeModel
Parameters:
path - the path to the node that should be modified
value - the new value

addTreeModelListener

public void addTreeModelListener(TreeModelListener listener)
Adds tree mode listener.

Specified by:
addTreeModelListener in interface TreeModel
Parameters:
listener - the tree mode listener

removeTreeModelListener

public void removeTreeModelListener(TreeModelListener listener)
Removes tree mode listener.

Specified by:
removeTreeModelListener in interface TreeModel
Parameters:
listener - the tree mode listener


Copyright © 2007 ETF and contributors. All Rights Reserved.