brf.j2me.dynaworks.ui
Class TreeItem

java.lang.Object
  |
  +--brf.j2me.dynaworks.ui.TreeItem

public final class TreeItem
extends java.lang.Object

A TreeItem represents an item in a tree structure.

Version:
1.0
Author:
Bernd R. Fix

Field Summary
private  java.util.Vector children
          list of children.
protected  boolean expanded
          true if the children are visible
private  int image
          Image number in an image list of the tree
private  TreeItem parent
          reference to parent item
private  java.lang.String text
          label of the item
 int userData
          data associated with the node.
 
Constructor Summary
TreeItem(java.lang.String t, int img)
          Creates a TreeItem.
 
Method Summary
 void addChild(TreeItem child)
          adds a child item to this item
 void collapse()
          collapses a parent item.
 int countVisibleDescendants()
          Return the number of visible descendants
 void expand()
          expands a parent item.
 TreeItem[] getChildren()
          Return a vector of children
 int getImage()
          get the image id of this node.
 TreeItem getParent()
          get the parent of this node.
 java.lang.String getText()
          get the next of this node.
 boolean hasChild(TreeItem item)
          Check if this item holds the specified child
 boolean hasChildren()
          Return true if item has children.
 boolean isExpanded()
           
 boolean removeChild(TreeItem child)
          removes the given child from the list of children
 void setImage(int img)
          sets the image number.
 void setParent(TreeItem parent)
          set the parent item.
 void setText(java.lang.String t)
          sets the item text.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

expanded

protected boolean expanded
true if the children are visible

text

private java.lang.String text
label of the item

image

private int image
Image number in an image list of the tree

children

private java.util.Vector children
list of children.

parent

private TreeItem parent
reference to parent item

userData

public int userData
data associated with the node.
Constructor Detail

TreeItem

public TreeItem(java.lang.String t,
                int img)
Creates a TreeItem.

It is set to visible if the parent is visible.

Parameters:
t - the text
inr - the image number in the image list
par - a reference to this items parent, or null if it has none.
Method Detail

expand

public void expand()
expands a parent item.

collapse

public void collapse()
collapses a parent item.

isExpanded

public boolean isExpanded()

setText

public void setText(java.lang.String t)
sets the item text.

Parameters:
t - the text.

getText

public java.lang.String getText()
get the next of this node.

Returns:
the item text.

setImage

public void setImage(int img)
sets the image number.

Parameters:
img - the image number.

getImage

public int getImage()
get the image id of this node.

Returns:
the image number.

getParent

public TreeItem getParent()
get the parent of this node.

Returns:
the parent of this item, or null if none.

setParent

public void setParent(TreeItem parent)
set the parent item.

Parameters:
parent - TreeItem - reference to new parent

countVisibleDescendants

public int countVisibleDescendants()
Return the number of visible descendants

Returns:
int - number of visible descandants

addChild

public void addChild(TreeItem child)
adds a child item to this item

Parameters:
child - TreeItem - the child TreeItem to be added

removeChild

public boolean removeChild(TreeItem child)
removes the given child from the list of children

Parameters:
child - TreeItem - the child to be removed from the list
Returns:
boolean - true if child was in the list, false otherwhise

hasChild

public boolean hasChild(TreeItem item)
Check if this item holds the specified child

Parameters:
item - TreeItem - child to be searched
Returns:
boolean - true if item is a child

getChildren

public TreeItem[] getChildren()
Return a vector of children

Returns:
TreeItem[] - list of children

hasChildren

public boolean hasChildren()
Return true if item has children.

Returns:
boolean - children available