Class tea.set.Forest
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class tea.set.Forest

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----tea.set.Forest

public class Forest
extends Canvas
Forest widget implements an tree interface. Because there could be multiple roots, hence the name Forest. There are two types of nodes in the tree: leaf nodes and non-leaf nodes. Leaf nodes don't have any child nodes of their own, and it's associated with a page icon. A non-leaf node has one or more child nodes, and it's associated with a folder icon. The icon for the nodes can be changed by users. There are three types of images: folder open, folder close, and leaf node. One or all of them can be changed by calling setImage() method. If the user supplied image is null, the icon will not be drawn for the specified type.

Each node in the tree must have a name. The naming of the tree nodes is similar to a file path, but instead of using slash or back-slash, a dot is used to separate the components. For example, a root node can have a name "root", and it can have a child with name "root.child1". In turn this child can have another child "root.child1.grandchild1". This naming scheme is used to decide where to place a new node in the add(String) method. If one or more nonleaf nodes don't exist when a node is added, they are created automatically. Therefore, to create "root.child1.grandchild1", only one call is needed to create the entire branch.

The separator can be changed from the default '.' to any charactor by calling setSeparator() method. This method must be called before any node is added to the tree.

A subtree(folder) can be expended(open) or collapsed(close) by clicking on the subtree root node. If IconOnly option is set to true, then open/close operations are only performed if mouse click is inside the node icon area, not the entire node. When a node is selected, a LIST_SELECT event is generated with target equaling Forest and arg equaling the path name of the node selected. If mouse is double clicked, an ACTION_EVENT is also generated with the same information. All other event which happens inside a node has the Event.arg set to the node path.


Variable Index

 o FOLDER_CLOSE
Folder closed image.
 o FOLDER_LEAF
Leaf node image.
 o FOLDER_OPEN
Folder openned image.
 o LINE
Display lines connecting parent nodes to their children nodes.
 o NO_LINE
Display nodes without connecting them with lines.

Constructor Index

 o Forest()
Construct a Forest widget defaults to NO_LINE option.
 o Forest(int)
Construct a Forest widget with the specified style.
 o Forest(int, boolean)
Construct a Forest widget with the specified style and behavior.

Method Index

 o add(String)
Add a node to the forest.
 o deselect(String)
De-select(dehighlight) the specified node.
 o forceOpen(String, boolean)
Set the force open mode on or off on the node pointed to by path.
 o getImage(int)
Return a folder image.
 o getSelectedLabel()
Return the label of the node selected.
 o getSelectedPath()
Return the path of the node selected.
 o getSeparator()
Return the current separator.
 o handleEvent(Event)
Handle and translate events.
 o hide(String)
Hide the specified node and its children.
 o hide(String, int)
Hide the specified node.
 o layout()
This function is called automatically to layout the tree nodes.
 o minimumSize()
Return the minimum size of the forest.
 o paint(Graphics)
Paint the forest.
 o preferredSize()
Return the preferred size of the forest.
 o remove(String)
Remove the specified node and its subtree.
 o select(String)
Select(highlight) the specified node.
 o setIconOnly(boolean)
Set folder open/close behavior.
 o setImage(Image, int)
Set the image for tree nodes.
 o setSeparator(char)
Set the separator to the new charactor.
 o setStyle(int)
Set the display style of this Forest to either LINE or NO_LINE.
 o show(int)
Show the nodes in the first 'level' levels.
 o show(String)
Show the specified node.
 o show(String, int)
Show the specified node.
 o showAll()
Show all nodes in the trees.
 o update(Graphics)
Overriden for double buffering.

Variables

 o NO_LINE
  public final static int NO_LINE
Display nodes without connecting them with lines. This is the default.
 o LINE
  public final static int LINE
Display lines connecting parent nodes to their children nodes.
 o FOLDER_OPEN
  public final static int FOLDER_OPEN
Folder openned image.
 o FOLDER_CLOSE
  public final static int FOLDER_CLOSE
Folder closed image.
 o FOLDER_LEAF
  public final static int FOLDER_LEAF
Leaf node image.

Constructors

 o Forest
  public Forest()
Construct a Forest widget defaults to NO_LINE option.
 o Forest
  public Forest(int style)
Construct a Forest widget with the specified style.
Parameters:
style - line option.
 o Forest
  public Forest(int style,
                boolean iconOnly)
Construct a Forest widget with the specified style and behavior.
Parameters:
style - line option.
iconOnly - only open/close folder if clicked in icon. Default is entire node.

Methods

 o getSeparator
  public char getSeparator()
Return the current separator.
Returns:
separator charactor.
 o setSeparator
  public void setSeparator(char separator)
Set the separator to the new charactor. This method must be called before any node is added to the forest.
 o setIconOnly
  public void setIconOnly(boolean t)
Set folder open/close behavior. Only affect subsequent nodes. Existing nodes are not changed. If icon only option is true, subtrees are openned/closed only when the mouse click is inside the node image icon.
Parameters:
t - true if only open/close folder if click in node icon.
 o setStyle
  public void setStyle(int style)
Set the display style of this Forest to either LINE or NO_LINE.
Parameters:
style - line option.
 o add
  public void add(String path)
Add a node to the forest. If the nodes in the middle of the path don't exist, they are created automatically. Nothing is done if the node already exists in the tree.
Parameters:
path - node path, node names from root to the node separated by the separator.
 o select
  public void select(String path)
Select(highlight) the specified node.
Parameters:
path - node path, node names from root to the node separated by the separator.
 o deselect
  public void deselect(String path)
De-select(dehighlight) the specified node.
Parameters:
path - node path, node names from root to the node separated by the separator.
 o show
  public void show(String path)
Show the specified node.
Parameters:
path - node path, node names from root to the node separated by the separator.
 o show
  public void show(String path,
                   int level)
Show the specified node. Level must be greater than or equal to zero. If level is greater than zero, the child nodes in the next "level" levels will also be shown.
Parameters:
path - node path, node names from root to the node separated by the separator.
level - tree level.
 o forceOpen
  public void forceOpen(String path,
                        boolean t)
Set the force open mode on or off on the node pointed to by path. If force open is true, the node will always be open (the next level shown).
Parameters:
path - node path, node names from root to the node separated by the separator.
t - true to force node always open.
 o show
  public void show(int level)
Show the nodes in the first 'level' levels. This method should be called after all add() has been done.
Parameters:
level - tree level.
 o showAll
  public void showAll()
Show all nodes in the trees.
 o hide
  public void hide(String path)
Hide the specified node and its children.
Parameters:
path - node path, node names from root to the node separated by the separator.
 o hide
  public void hide(String path,
                   int level)
Hide the specified node. If level is zero, the node pointed by to path and all its children will be hiden. If level is greater than zero, only those node "level" levels below the specified node will be hiden.
Parameters:
path - node path, node names from root to the node separated by the separator.
level - tree level.
 o remove
  public void remove(String path)
Remove the specified node and its subtree.
Parameters:
path - node path, node names from root to the node separated by the separator.
 o getSelectedLabel
  public String getSelectedLabel()
Return the label of the node selected.
Returns:
label of selected node.
 o getSelectedPath
  public String getSelectedPath()
Return the path of the node selected. It is the labels from the root of the tree to the selected node concatenated together separated by the current separator.
Returns:
path of selected node.
 o setImage
  public void setImage(Image img,
                       int type)
Set the image for tree nodes. The type parameter specifies the type of image to change: FOLDER_OPEN specifies the image used when folder is open; FOLDER_CLOSE specifies the image used when folder is closed; FOLDER_LEAF specifies the leaf node image. The images are set for all existing nodes and subsequent nodes.
Parameters:
img - node imae.
type - type of image, FOLDER_OPEN, FOLDER_CLOSE, or FOLDER_LEAF.
 o getImage
  public synchronized Image getImage(int type)
Return a folder image.
Parameters:
type - the image type: FOLDER_OPEN, FOLDER_CLOSE, or FOLDER_LEAF.
Returns:
folder image.
 o minimumSize
  public Dimension minimumSize()
Return the minimum size of the forest.
Returns:
minimum size of forest.
Overrides:
minimumSize in class Component
 o preferredSize
  public Dimension preferredSize()
Return the preferred size of the forest.
Returns:
preferred size of forest.
Overrides:
preferredSize in class Component
 o layout
  public void layout()
This function is called automatically to layout the tree nodes. The user of this class need not to call it explicitly.
Overrides:
layout in class Component
 o paint
  public void paint(Graphics g)
Paint the forest.
Parameters:
g - Graphics content of this component.
Overrides:
paint in class Canvas
 o update
  public void update(Graphics g)
Overriden for double buffering.
Parameters:
g - Graphics content of this component.
Overrides:
update in class Component
 o handleEvent
  public boolean handleEvent(Event e)
Handle and translate events. A LIST_SELECT event is generated when a node is highlighted. If an user double clicks on a node, an ACTION event is also generated.
Parameters:
e - event object.
Returns:
false;
Overrides:
handleEvent in class Component

All Packages  Class Hierarchy  This Package  Previous  Next  Index