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
- implements ItemSelectable
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. Image can also be specified for
individual nodes. The node image overrides forest wide image.
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, an ItemEvent.SELECTED is generated with
item equaling the node selected. If mouse is double clicked, an
ActionEvent.ACTION_PERFORMED is also generated with the same information.
Forest supports the following properties:
Property Name | Property Type | Description |
Separator | char |
Separator character used to separate nodes in a tree path. |
IconOnly | boolean |
True if only expend or collapse subtrees when mouse click happens
inside the node icon. |
Style | int |
Forest style flag. |
SelectedLabel | String (Readonly) |
Label of the currently selected node. |
SelectedPath | String (Readonly) |
Path of the currently selected node. |
SelectedObjects | Object[] (Readonly) |
List of selected node paths. |
MultiSelect | boolean |
Multiple selection flag. |
Forest generates the following events:
Event Type | Event ID | Generated |
Description |
ObjActionEvent | ActionEvent.ACTION_PERFORMED |
Mouse double click on a node. |
ActionEvent.getActionCommand() is the path of the node.
ObjActionEvent.getObject() points to the node. |
ItemEvent | ItemEvent.SELECTED |
Node selected |
ItemEvent.getItem() points to the selected node. |
ItemEvent | ItemEvent.DESELECTED |
Node deselected. |
ItemEvent.getItem() points to the deselected node. |
-
eventMgr
- EventMgr object handles added event processing and dispatching.
-
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.
-
LINE_BOX
- Display lines and a box with plus or minus sign for every
non-leaf node.
-
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.
-
addActionListener(ActionListener)
- Add an action listener.
-
addItemListener(ItemListener)
- Add an item listener.
-
deselect(String)
- De-select(dehighlight) the specified node.
-
doLayout()
- This function is called automatically to layout the tree nodes.
-
findNode(String, boolean)
- Find the node with the specified path.
-
forceOpen(String, boolean)
- Set the force open mode on or off on the node pointed to by path.
-
getImage(int)
- Return a folder image.
-
getMinimumSize()
- Return the minimum size of the forest.
-
getPreferredSize()
- Return the preferred size of the forest.
-
getRoot(int)
- Return the root node of the specified tree.
-
getRootCount()
- Return the number of trees in the forest.
-
getSelectedIndexes()
- This method always returns null.
-
getSelectedLabel()
- Return the label of the node selected.
-
getSelectedObjects()
- Returns the list of node paths that are currently selected.
-
getSelectedPath()
- Return the path of the node selected.
-
getSeparator()
- Return the current separator.
-
getStyle()
- Return the Forest style.
-
hide(String)
- Hide the specified node and its children.
-
hide(String, int)
- Hide the specified node.
-
isIconOnly()
- Return the icon only flag.
-
isMultiSelect()
- Get multiple selection status.
-
locateNode(int, int)
- Locate the node where the (x, y) coordinate is in.
-
paint(Graphics)
- Paint the forest.
-
processActionEvent(ActionEvent)
- Process and dispatch action event.
-
processEvent(AWTEvent)
- Process and dispatch event.
-
processItemEvent(ItemEvent)
- Handle and translate events.
-
processMouseEvent(MouseEvent)
- Process mouse event to handle node selection and tree expension/
collapsing.
-
remove(String)
- Remove the specified node and its subtree.
-
removeActionListener(ActionListener)
- Remove an action listener.
-
removeAll()
- Remove all nodes from the tree.
-
removeItemListener(ItemListener)
- Remove an item listener.
-
select(String)
- Select(highlight) the specified node.
-
setIconOnly(boolean)
- Set folder open/close behavior.
-
setImage(Image, int)
- Set the image for tree nodes.
-
setImage(String, Image)
- Set the image icon for the specified node.
-
setMultiSelect(boolean)
- Enabled or disable multiple node selection.
-
setSeparator(char)
- Set the separator to the new charactor.
-
setStyle(int)
- Set the display style of this Forest to either LINE, LINE_BOX,
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 static final int NO_LINE
- Display nodes without connecting them with lines.
This is the default.
LINE
public static final int LINE
- Display lines connecting parent nodes to their children nodes.
LINE_BOX
public static final int LINE_BOX
- Display lines and a box with plus or minus sign for every
non-leaf node.
FOLDER_OPEN
public static final int FOLDER_OPEN
- Folder openned image.
FOLDER_CLOSE
public static final int FOLDER_CLOSE
- Folder closed image.
FOLDER_LEAF
public static final int FOLDER_LEAF
- Leaf node image.
eventMgr
protected EventMgr eventMgr
- EventMgr object handles added event processing and dispatching.
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 synchronized 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 synchronized 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.
isIconOnly
public boolean isIconOnly()
- Return the icon only flag.
- Returns:
- true if icon only is set.
setStyle
public synchronized void setStyle(int style)
- Set the display style of this Forest to either LINE, LINE_BOX,
or NO_LINE.
- Parameters:
- style - line option.
getStyle
public int getStyle()
- Return the Forest style.
- Returns:
- forest style flag.
add
public synchronized 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 synchronized 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 synchronized 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 synchronized 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 synchronized 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 synchronized 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 synchronized 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 synchronized 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 synchronized 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.
removeAll
public synchronized void removeAll()
- Remove all nodes from the tree.
getSelectedLabel
public synchronized String getSelectedLabel()
- Return the label of the node selected.
- Returns:
- label of selected node.
getSelectedPath
public synchronized 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.
getSelectedIndexes
public int[] getSelectedIndexes()
- This method always returns null.
getSelectedObjects
public synchronized Object[] getSelectedObjects()
- Returns the list of node paths that are currently selected.
setMultiSelect
public synchronized void setMultiSelect(boolean f)
- Enabled or disable multiple node selection.
- Parameters:
- f - true to enable multiple node selection.
isMultiSelect
public boolean isMultiSelect()
- Get multiple selection status.
- Returns:
- true if multiple select is enabled.
setImage
public synchronized 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.
If image is set to null, no icon will be drawn for the specified
node type.
- Parameters:
- img - node imae.
- type - type of image, FOLDER_OPEN, FOLDER_CLOSE, or FOLDER_LEAF.
setImage
public synchronized void setImage(String path,
Image image)
- Set the image icon for the specified node.
- Parameters:
- path - node full path.
- image - node image.
getRootCount
public int getRootCount()
- Return the number of trees in the forest.
- Returns:
- number of roots.
getRoot
public Node getRoot(int idx)
- Return the root node of the specified tree.
- Parameters:
- idx - tree index, between 0 and getRootCount()-1.
- Returns:
- the root node of the specified tree.
locateNode
public synchronized Node locateNode(int x,
int y)
- Locate the node where the (x, y) coordinate is in.
- Parameters:
- x - x coordinate.
- y - y coordinate.
- Returns:
- node.
findNode
public Node findNode(String path,
boolean createit)
- Find the node with the specified path. If the path does not exist,
null is returned, or it can be optionally created. This does not
call layout or repaint. Explicit call to them are necessary.
- Parameters:
- path - node full path.
- Returns:
- node object.
getImage
public Image getImage(int type)
- Return a folder image. This method must be called after the component
has been added to a parent and fully validated. Otherwise a null
will be returned.
- Parameters:
- type - the image type: FOLDER_OPEN, FOLDER_CLOSE, or
FOLDER_LEAF.
- Returns:
- folder image.
getMinimumSize
public synchronized Dimension getMinimumSize()
- Return the minimum size of the forest.
- Returns:
- minimum size of forest.
- Overrides:
- getMinimumSize in class Component
getPreferredSize
public Dimension getPreferredSize()
- Return the preferred size of the forest.
- Returns:
- preferred size of forest.
- Overrides:
- getPreferredSize in class Component
doLayout
public void doLayout()
- This function is called automatically to layout the tree nodes.
The user of this class need not to call it explicitly.
- Overrides:
- doLayout 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
addActionListener
public void addActionListener(ActionListener listener)
- Add an action listener.
- Parameters:
- listener - action listener.
removeActionListener
public void removeActionListener(ActionListener listener)
- Remove an action listener.
- Parameters:
- listener - action listener.
addItemListener
public void addItemListener(ItemListener listener)
- Add an item listener.
- Parameters:
- listener - item listener.
removeItemListener
public void removeItemListener(ItemListener listener)
- Remove an item listener.
- Parameters:
- listener - item listener.
processEvent
public void processEvent(AWTEvent e)
- Process and dispatch event.
- Parameters:
- e - event object.
- Overrides:
- processEvent in class Component
processActionEvent
public void processActionEvent(ActionEvent e)
- Process and dispatch action event.
- Parameters:
- e - action event.
processItemEvent
public void processItemEvent(ItemEvent e)
- Handle and translate events. An ItemEvent.SELECTED event is generated
when a node is highlighted. If an user double clicks on a node, an
ACTION event is also generated.
- Parameters:
- e - item event.
processMouseEvent
public void processMouseEvent(MouseEvent e)
- Process mouse event to handle node selection and tree expension/
collapsing.
- Overrides:
- processMouseEvent in class Component
All Packages Class Hierarchy This Package Previous Next Index