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.
-
FOLDER_CLOSE
- Folder closed image.
-
FOLDER_LEAF
- Leaf node image.
-
FOLDER_OPEN
- Folder openned image.
-
LINE
- Display lines connecting parent nodes to their children nodes.
-
NO_LINE
- Display nodes without connecting them with lines.
-
Forest()
- Construct a Forest widget defaults to NO_LINE option.
-
Forest(int)
- Construct a Forest widget with the specified style.
-
Forest(int, boolean)
- Construct a Forest widget with the specified style and behavior.
-
add(String)
- Add a node to the forest.
-
deselect(String)
- De-select(dehighlight) the specified node.
-
forceOpen(String, boolean)
- Set the force open mode on or off on the node pointed to by path.
-
getImage(int)
- Return a folder image.
-
getSelectedLabel()
- Return the label of the node selected.
-
getSelectedPath()
- Return the path of the node selected.
-
getSeparator()
- Return the current separator.
-
handleEvent(Event)
- Handle and translate events.
-
hide(String)
- Hide the specified node and its children.
-
hide(String, int)
- Hide the specified node.
-
layout()
- This function is called automatically to layout the tree nodes.
-
minimumSize()
- Return the minimum size of the forest.
-
paint(Graphics)
- Paint the forest.
-
preferredSize()
- Return the preferred size of the forest.
-
remove(String)
- Remove the specified node and its subtree.
-
select(String)
- Select(highlight) the specified node.
-
setIconOnly(boolean)
- Set folder open/close behavior.
-
setImage(Image, int)
- Set the image for tree nodes.
-
setSeparator(char)
- Set the separator to the new charactor.
-
setStyle(int)
- Set the display style of this Forest to either LINE or NO_LINE.
-
show(int)
- Show the nodes in the first 'level' levels.
-
show(String)
- Show the specified node.
-
show(String, int)
- Show the specified node.
-
showAll()
- Show all nodes in the trees.
-
update(Graphics)
- Overriden for double buffering.
NO_LINE
public final static int NO_LINE
- Display nodes without connecting them with lines.
This is the default.
LINE
public final static int LINE
- Display lines connecting parent nodes to their children nodes.
FOLDER_OPEN
public final static int FOLDER_OPEN
- Folder openned image.
FOLDER_CLOSE
public final static int FOLDER_CLOSE
- Folder closed image.
FOLDER_LEAF
public final static int FOLDER_LEAF
- Leaf node image.
Forest
public Forest()
- Construct a Forest widget defaults to NO_LINE option.
Forest
public Forest(int style)
- Construct a Forest widget with the specified style.
- Parameters:
- style - line option.
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.
getSeparator
public char getSeparator()
- Return the current separator.
- Returns:
- separator charactor.
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.
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.
setStyle
public void setStyle(int style)
- Set the display style of this Forest to either LINE or NO_LINE.
- Parameters:
- style - line option.
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.
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.
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.
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.
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.
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.
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.
showAll
public void showAll()
- Show all nodes in the trees.
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.
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.
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.
getSelectedLabel
public String getSelectedLabel()
- Return the label of the node selected.
- Returns:
- label of selected node.
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.
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.
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.
minimumSize
public Dimension minimumSize()
- Return the minimum size of the forest.
- Returns:
- minimum size of forest.
- Overrides:
- minimumSize in class Component
preferredSize
public Dimension preferredSize()
- Return the preferred size of the forest.
- Returns:
- preferred size of forest.
- Overrides:
- preferredSize in class Component
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
paint
public void paint(Graphics g)
- Paint the forest.
- Parameters:
- g - Graphics content of this component.
- Overrides:
- paint in class Canvas
update
public void update(Graphics g)
- Overriden for double buffering.
- Parameters:
- g - Graphics content of this component.
- Overrides:
- update in class Component
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