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

java.lang.Object
  extended byyu.ac.bg.etf.javaqx.qswing.tree.DefaultMutableTreeNode
All Implemented Interfaces:
java.lang.Cloneable, MutableTreeNode, TreeNode

public class DefaultMutableTreeNode
extends java.lang.Object
implements java.lang.Cloneable, MutableTreeNode

Default Mutable Tree Node.

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

Field Summary
protected  boolean allowsChildren
           
protected  java.util.ArrayList children
           
protected  MutableTreeNode parent
           
protected  java.lang.Object userObject
           
 
Constructor Summary
DefaultMutableTreeNode()
          Constructs new DefaultMutableTreeNode object.
DefaultMutableTreeNode(java.lang.Object userObject)
          Constructs new DefaultMutableTreeNode object.
DefaultMutableTreeNode(java.lang.Object userObject, boolean allowsChildren)
          Constructs new DefaultMutableTreeNode object.
 
Method Summary
 void add(MutableTreeNode child)
          Adds a new child.
 java.util.Iterator children()
          Returns iterator over the children of the node.
 java.lang.Object clone()
          
 boolean getAllowsChildren()
          Returns true if the node allows children.
 TreeNode getChildAt(int index)
          Returns child at the specified index.
 int getChildCount()
          Returns the number of children.
 TreeNode getFirstChild()
          Returns the first child of this node.
 Icon getIcon()
          Returns node's icon.
 int getIndex(TreeNode node)
          Returns index of specified node or -1 if there is no such node.
 TreeNode getLastChild()
          Returns the last child of this node.
 TreeNode getParent()
          Returns parent of the node.
 java.lang.Object getUserObject()
          Returns the user object.
 void insert(MutableTreeNode child, int index)
          Inserts specified child at specified index.
 boolean isLeaf()
          Returns true if the node is leaf.
 boolean isNodeAncestor(TreeNode node)
          Returns true if the specified node is ancestor of the this node.
 boolean isNodeChild(TreeNode node)
          Returns true if the specified node is a child of this node.
 void remove(int index)
          Removes child at the specified index.
 void remove(MutableTreeNode node)
          Removes specified node.
 void removeFromParent()
          Removes the node form its parent.
 void setParent(MutableTreeNode parent)
          Sets the parent of the node.
 void setUserObject(java.lang.Object object)
          Sets user object.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parent

protected MutableTreeNode parent

children

protected java.util.ArrayList children

userObject

protected java.lang.Object userObject

allowsChildren

protected boolean allowsChildren
Constructor Detail

DefaultMutableTreeNode

public DefaultMutableTreeNode()
Constructs new DefaultMutableTreeNode object.


DefaultMutableTreeNode

public DefaultMutableTreeNode(java.lang.Object userObject)
Constructs new DefaultMutableTreeNode object.

Parameters:
userObject - the user object.

DefaultMutableTreeNode

public DefaultMutableTreeNode(java.lang.Object userObject,
                              boolean allowsChildren)
Constructs new DefaultMutableTreeNode object.

Parameters:
userObject - the user object.
allowsChildren - if true the node allows children
Method Detail

getUserObject

public java.lang.Object getUserObject()
Returns the user object.

Returns:
the user object

add

public void add(MutableTreeNode child)
Adds a new child.

Parameters:
child - the child node
Throws:
java.lang.IllegalArgumentException - if child is null or child is an ancestor
java.lang.IllegalStateException - if the node does not allow children

isNodeAncestor

public boolean isNodeAncestor(TreeNode node)
Returns true if the specified node is ancestor of the this node.

Parameters:
node - the specified node
Returns:
true if the specified node is ancestor of the this node

isNodeChild

public boolean isNodeChild(TreeNode node)
Returns true if the specified node is a child of this node.

Parameters:
node - the node
Returns:
true if the specified node is a child of this node

getFirstChild

public TreeNode getFirstChild()
Returns the first child of this node.

Returns:
the first child of this node
Throws:
java.util.NoSuchElementException - if the node has no children

getLastChild

public TreeNode getLastChild()
Returns the last child of this node.

Returns:
the last child of this node
Throws:
java.util.NoSuchElementException - if the node has no children

getIcon

public Icon getIcon()
Returns node's icon.

NOTE: This method is preliminary.

Returns:
node's icon

getParent

public TreeNode getParent()
Returns parent of the node.

Specified by:
getParent in interface TreeNode
Returns:
parent of the node

setParent

public void setParent(MutableTreeNode parent)
Sets the parent of the node.

Specified by:
setParent in interface MutableTreeNode
Parameters:
parent - the new parent

removeFromParent

public void removeFromParent()
Removes the node form its parent.

Specified by:
removeFromParent in interface MutableTreeNode

isLeaf

public boolean isLeaf()
Returns true if the node is leaf.

Specified by:
isLeaf in interface TreeNode
Returns:
true if the node is leaf

getAllowsChildren

public boolean getAllowsChildren()
Returns true if the node allows children.

Specified by:
getAllowsChildren in interface TreeNode
Returns:
true if the node allows children

getChildCount

public int getChildCount()
Returns the number of children.

Specified by:
getChildCount in interface TreeNode
Returns:
the number of children

getChildAt

public TreeNode getChildAt(int index)
Returns child at the specified index.

Specified by:
getChildAt in interface TreeNode
Parameters:
index - the child index
Returns:
child at the specified index

getIndex

public int getIndex(TreeNode node)
Returns index of specified node or -1 if there is no such node.

Specified by:
getIndex in interface TreeNode
Parameters:
node - the node
Returns:
index of specified node or -1 if there is no such node

insert

public void insert(MutableTreeNode child,
                   int index)
Inserts specified child at specified index.

Specified by:
insert in interface MutableTreeNode
Parameters:
child - the child
index - the index

remove

public void remove(int index)
Removes child at the specified index.

Specified by:
remove in interface MutableTreeNode
Parameters:
index - the index

remove

public void remove(MutableTreeNode node)
Removes specified node.

Specified by:
remove in interface MutableTreeNode
Parameters:
node - the node

setUserObject

public void setUserObject(java.lang.Object object)
Sets user object.

Specified by:
setUserObject in interface MutableTreeNode
Parameters:
object - the object

children

public java.util.Iterator children()
Returns iterator over the children of the node.

Specified by:
children in interface TreeNode
Returns:
iterator over the children of the node

clone

public java.lang.Object clone()


toString

public java.lang.String toString()



Copyright © 2007 ETF and contributors. All Rights Reserved.