org.zaval.data
Class Tree

java.lang.Object
  |
  +--org.zaval.data.Tree
All Implemented Interfaces:
TreeModel

public class Tree
extends java.lang.Object
implements TreeModel

This class is implementation of TreeModel interface and it is used to organize tree-like structures basing on Item class. The class provides methods to bound items with each other The class supports listener interface that allows to listen when the structure has been modified.


Constructor Summary
Tree()
          Constructs a new tree class.
Tree(Item r)
          Constructs a new tree with the given item as a root of the hierarchy.
 
Method Summary
 void add(Item to, Item item)
          Adds the item into the tree as a child of the parent item.
 void addTreeListener(TreeListener l)
          Adds the specified tree listener to receive the tree events.
 Tree clone(Item item)
          Creates a subtree for the specified item of this tree.
 boolean contains(Item item)
          Tests if the specified item is contained with this tree model.
 Item getChildAt(Item item, int index)
          Returns a child item for the given parent item at the specified index.
 int getChildIndex(Item item)
          Searches for the first occurence of the given item in the parent items vector, testing for equality using the equals method and returns the child index.
 Item[] getChildren()
          Gets all child items for the root item of the tree.
 Item[] getChildren(Item item)
          Gets all child items for the specified item.
 int getChildrenCount(Item item)
          Returns a number of child items for the given parent item.
 int getItemsCount()
          Gets the total items number that are contained by the tree.
 Item getParent(Item item)
          Returns a parent for the given item.
 Item getRoot()
          Gets the root item of the tree model.
 boolean hasChildren(Item item)
          Tests if the item has one or more child items.
 void insert(Item to, Item item, int index)
          Inserts the specified item into the tree as a child of the parent item, at the specified index.
protected  void perform(TreeEvent e)
          Fires the specified tree event to the tree model listeners.
protected  void regItem(Item item, Item parent, java.util.Vector v)
          The method is used to register the specified item as a member of the tree model.
 void remove(Item item)
          Removes the specified item from the tree.
 void removeChild(Item parent, int index)
          Deletes a child item from the specified parent item at the specified index.
 void removeKids(Item item)
          Deletes all child items for the specified parent item.
 void removeTreeListener(TreeListener l)
          Removes the specified tree listener so that it no longer receives tree events from this tree model.
 void set(Item item, java.lang.Object o)
          Sets the specified value for the given tree item.
 void setRoot(Item r)
           
protected  void unregItem(Item item)
          The method is used to unregister the specified item as a member of the tree model.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tree

public Tree()
Constructs a new tree class. The constructur defines a root item as default.

Tree

public Tree(Item r)
Constructs a new tree with the given item as a root of the hierarchy.
Parameters:
r - the initial value of the container root. The root item will be used as root of the hierarchy. Use null value to postpone the root item definition.
Method Detail

setRoot

public void setRoot(Item r)

getRoot

public Item getRoot()
Description copied from interface: TreeModel
Gets the root item of the tree model.
Specified by:
getRoot in interface TreeModel
Following copied from interface: org.zaval.data.TreeModel
Returns:
a root item of the tree model.

getItemsCount

public int getItemsCount()
Description copied from interface: TreeModel
Gets the total items number that are contained by the tree.
Specified by:
getItemsCount in interface TreeModel
Following copied from interface: org.zaval.data.TreeModel
Returns:
a total items number.

getChildren

public Item[] getChildren()
Gets all child items for the root item of the tree.
Returns:
an array of all child items for the root item.

getChildren

public Item[] getChildren(Item item)
Gets all child items for the specified item.
Parameters:
item - the item that is used as a root to get a child items array.
Returns:
an array of all child items for the given root item.

getChildAt

public Item getChildAt(Item item,
                       int index)
Description copied from interface: TreeModel
Returns a child item for the given parent item at the specified index.
Specified by:
getChildAt in interface TreeModel
Following copied from interface: org.zaval.data.TreeModel
Parameters:
item - the item that is used as a parent to get a child item by the index.
index - the index into this parent child items vector.
Returns:
the item at the specified index.

getChildIndex

public int getChildIndex(Item item)
Description copied from interface: TreeModel
Searches for the first occurence of the given item in the parent items vector, testing for equality using the equals method and returns the child index.
Specified by:
getChildIndex in interface TreeModel
Following copied from interface: org.zaval.data.TreeModel
Parameters:
item - the specified item to define it index.
Returns:
the index of the first occurrence of the item in this parent items vector. Returns -1 if the item is not member of the model.

getParent

public Item getParent(Item item)
Description copied from interface: TreeModel
Returns a parent for the given item.
Specified by:
getParent in interface TreeModel
Following copied from interface: org.zaval.data.TreeModel
Parameters:
item - the specified item to define it parent.
Returns:
a parent item of the child item.

getChildrenCount

public int getChildrenCount(Item item)
Description copied from interface: TreeModel
Returns a number of child items for the given parent item.
Specified by:
getChildrenCount in interface TreeModel
Following copied from interface: org.zaval.data.TreeModel
Parameters:
item - the parent item to define a number of child items.
Returns:
a number of child items. Actually the method gets a size of the item child vector.

hasChildren

public boolean hasChildren(Item item)
Description copied from interface: TreeModel
Tests if the item has one or more child items.
Specified by:
hasChildren in interface TreeModel
Following copied from interface: org.zaval.data.TreeModel
Parameters:
item - the item to test.
Returns:
true if the item has one or more child items; false otherwise

contains

public boolean contains(Item item)
Tests if the specified item is contained with this tree model.
Parameters:
item - the specified item to be tested.
Returns:
true if the specified item contained with this tree model; false otherwise.

add

public void add(Item to,
                Item item)
Description copied from interface: TreeModel
Adds the item into the tree as a child of the parent item. The parent item has to belong to the tree.
Specified by:
add in interface TreeModel
Following copied from interface: org.zaval.data.TreeModel
Parameters:
to - the parent item.
item - the child item that has to be added.

insert

public void insert(Item to,
                   Item item,
                   int index)
Description copied from interface: TreeModel
Inserts the specified item into the tree as a child of the parent item, at the specified index. The parent item has to belong to the tree.
Specified by:
insert in interface TreeModel
Following copied from interface: org.zaval.data.TreeModel
Parameters:
to - the specified parent item.
item - the specified child item that has to be added.
index - the specified index where the child has to be inserted.

remove

public void remove(Item item)
Description copied from interface: TreeModel
Removes the specified item from the tree. If the item has child items than the children will be removed too. The method is recursive to remove all hierarchy that is bound with this item.
Specified by:
remove in interface TreeModel
Following copied from interface: org.zaval.data.TreeModel
Parameters:
item - the item that has to be removed.

removeChild

public void removeChild(Item parent,
                        int index)
Deletes a child item from the specified parent item at the specified index.
Parameters:
parent - the parent item for what the child item will be removed.
index - the index of the child item to be removed.

removeKids

public void removeKids(Item item)
Deletes all child items for the specified parent item.
Parameters:
item - the parent item for what all child items will be removed.

clone

public Tree clone(Item item)
Creates a subtree for the specified item of this tree. The specified item is set as the root item for the subtree.
Parameters:
item - the specified item.
Returns:
a clone of the item hierarchy.

addTreeListener

public void addTreeListener(TreeListener l)
Description copied from interface: TreeModel
Adds the specified tree listener to receive the tree events.
Specified by:
addTreeListener in interface TreeModel
Following copied from interface: org.zaval.data.TreeModel
Parameters:
l - the tree listener.

removeTreeListener

public void removeTreeListener(TreeListener l)
Description copied from interface: TreeModel
Removes the specified tree listener so that it no longer receives tree events from this tree model.
Specified by:
removeTreeListener in interface TreeModel
Following copied from interface: org.zaval.data.TreeModel
Parameters:
l - the tree listener.

set

public void set(Item item,
                java.lang.Object o)
Sets the specified value for the given tree item.
Specified by:
set in interface TreeModel
Parameters:
item - the item.
o - the specified value.

regItem

protected void regItem(Item item,
                       Item parent,
                       java.util.Vector v)
The method is used to register the specified item as a member of the tree model. The new item is bound with the given parent item.
Parameters:
item - the item that has to be registered as a member of the tree.
parent - the parent of the registered item.
v - the vector of child items for the given parent item.

unregItem

protected void unregItem(Item item)
The method is used to unregister the specified item as a member of the tree model.
Parameters:
item - the item that has to be unregistered as a member of this tree.

perform

protected void perform(TreeEvent e)
Fires the specified tree event to the tree model listeners.
Parameters:
e - the tree event.


Copyright © Zaval Creative Engineering Group, 2000-2005.
http://www.zaval.org