All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class org.w3c.tools.widgets.TreeBrowser

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----org.w3c.tools.widgets.TreeBrowser

public class TreeBrowser
extends Canvas
implements AdjustmentListener
The TreeBrowser class. This class is a generic framework to browser any hierachical structure.

Genericity is obtained through the use of 'handlers': the TreeBrowser itself does not perform any action in response to user events, but simply forward them as notifications to handlers. Each item inserted may have its own handler, but handlers may also (this is the most common case) be shared between handlers.

Any item added in the Tree is displayed with an icon and a label. When a handler receive a notification on a node, it may change this node, to modify or update its appearance.


Variable Index

 o fontHeight
 o items
 o MULTIPLE
The policy that enables a multiple selection of nodes.
 o SCROLLBARS_ALWAYS
Specifies that the horizontal/vertical scrollbars should always be shown regardless of the respective sizes of the TreeBrowser.
 o SCROLLBARS_ASNEEDED
Specifies that horizontal/vertical scrollbars should be shown only when the size of the nodes exceeds the size of the TreeBrowser in the horizontal/vertical dimension.
 o selection
 o selectionPolicy
 o SINGLE
This policy that lets just one node selected at the same time.
 o topItem
 o visibleItemCount

Constructor Index

 o TreeBrowser()
 o TreeBrowser(Object, String, NodeHandler, Image)
Builds a new browser instance

Method Index

 o adjustmentValueChanged(AdjustmentEvent)
Updates graphical appearance in response to a scroll.
 o collapse(TreeNode)
Contracts the representation of the specified node.
 o getNode(Object)
Gets the node associated to the specified object, or null if any.
 o getParent(TreeNode)
Returns the parent node of the specified node.
 o getPreferredSize()
 o getSelectionPolicy()
Gets the selection policy.
 o initialize(Object, String, NodeHandler, Image)
 o insert(TreeNode, Object, NodeHandler, String, Image)
Inserts new node.
 o paint(Graphics)
repaints the View.
 o remove(TreeNode)
Removes the specified node.
 o removeBranch(TreeNode)
Removes the specified node and its children.
 o select(TreeNode)
Selects the specified node.
 o selection()
Returns an Enumeraiton of selected items.
 o setHorizontalScrollbar(Scrollbar)
Sets 'a' as horizontal Scrollbar.
 o setScrollbarDisplayPolicy(int)
Sets the scrollbars display policy to the specified policy.
 o setSelectionBackgroudColor(Color)
Sets the background color of a selected node to the specified color.
 o setSelectionFontColor(Color)
Sets the color of a selected node to the specified color.
 o setSelectionPolicy(int)
Sets the selection policy.
 o setVerticalScrollbar(Scrollbar)
Sets 'a' as vertical Scrollbar.
 o unselect(TreeNode)
Unselects the specified node.
 o unselectAll()
Unselects all selected items.
 o update(Graphics)

Variables

 o SCROLLBARS_ALWAYS
 public static final int SCROLLBARS_ALWAYS
Specifies that the horizontal/vertical scrollbars should always be shown regardless of the respective sizes of the TreeBrowser.

 o SCROLLBARS_ASNEEDED
 public static final int SCROLLBARS_ASNEEDED
Specifies that horizontal/vertical scrollbars should be shown only when the size of the nodes exceeds the size of the TreeBrowser in the horizontal/vertical dimension.

 o SINGLE
 public static final int SINGLE
This policy that lets just one node selected at the same time.

 o MULTIPLE
 public static final int MULTIPLE
The policy that enables a multiple selection of nodes.

 o items
 protected Vector items
 o selection
 protected Vector selection
 o topItem
 protected int topItem
 o visibleItemCount
 protected int visibleItemCount
 o selectionPolicy
 protected int selectionPolicy
 o fontHeight
 protected int fontHeight

Constructors

 o TreeBrowser
 public TreeBrowser(Object root,
                    String label,
                    NodeHandler handler,
                    Image icon)
Builds a new browser instance

Parameters:
root - the root node for this hierarchy
label - the label that should be displayed for this item
handler - the handler for this node
icon - the icon that must be displayed for this item
 o TreeBrowser
 protected TreeBrowser()

Methods

 o initialize
 protected void initialize(Object item,
                           String label,
                           NodeHandler handler,
                           Image icon)
 o getPreferredSize
 public Dimension getPreferredSize()
Overrides:
getPreferredSize in class Component
 o setSelectionFontColor
 public void setSelectionFontColor(Color color)
Sets the color of a selected node to the specified color.

Parameters:
color - the color used to paint a selected node
 o setSelectionBackgroudColor
 public void setSelectionBackgroudColor(Color color)
Sets the background color of a selected node to the specified color.

Parameters:
color - the color used to paint the background of a selected node
 o setScrollbarDisplayPolicy
 public void setScrollbarDisplayPolicy(int scrollbarDisplayPolicy)
Sets the scrollbars display policy to the specified policy. The default is SCROLLBARS_ALWAYS

Parameters:
scrollbarDisplayPolicy - SCROLLBARS_NEVER | SCROLLBARS_ASNEEDED | SCROLLBARS_ALWAYS
 o paint
 public void paint(Graphics g)
repaints the View.

Overrides:
paint in class Canvas
 o update
 public void update(Graphics pg)
Overrides:
update in class Component
 o insert
 public void insert(TreeNode parent,
                    Object item,
                    NodeHandler handler,
                    String label,
                    Image icon)
Inserts new node.

Parameters:
parent - the parent node.
 o remove
 public void remove(TreeNode node)
Removes the specified node. This simply removes a node, without modifying its children if any. USE WITH CAUTION.

Parameters:
node - the node to remove
 o removeBranch
 public void removeBranch(TreeNode node)
Removes the specified node and its children. NOTE: if two threads are doing adds and removes, this can lead to IndexOutOfBound exception. You will probably have to use locks to get rid of that problem

Parameters:
node - the node to remove
 o collapse
 public synchronized void collapse(TreeNode item)
Contracts the representation of the specified node. removes all the children nodes of 'item'. It is caller's responsibility to call repaint() afterwards.

Parameters:
item - the node to contracts
 o setSelectionPolicy
 public void setSelectionPolicy(int policy)
Sets the selection policy.

Parameters:
policy: - SINGLE or MULTIPLE
 o getSelectionPolicy
 public int getSelectionPolicy()
Gets the selection policy.

 o select
 public void select(TreeNode node)
Selects the specified node. Selects the given node. If selectionPolicy is SINGLE any previously selected node is unselected first. It is caller's responsibility to call repaint()

Parameters:
node - the node to select
 o unselect
 public void unselect(TreeNode node)
Unselects the specified node. It is caller's responsibility to call repaint()

Parameters:
node - the node to unselect
 o unselectAll
 public void unselectAll()
Unselects all selected items.

 o selection
 public Enumeration selection()
Returns an Enumeraiton of selected items.

 o setVerticalScrollbar
 public void setVerticalScrollbar(Scrollbar a)
Sets 'a' as vertical Scrollbar. The Browser becomes an AdjustmentListener of this scrollbar.

 o setHorizontalScrollbar
 public void setHorizontalScrollbar(Scrollbar a)
Sets 'a' as horizontal Scrollbar. The Browser becomes an AdjustmentListener of this scrollbar.

 o adjustmentValueChanged
 public void adjustmentValueChanged(AdjustmentEvent evt)
Updates graphical appearance in response to a scroll.

 o getParent
 public TreeNode getParent(TreeNode child)
Returns the parent node of the specified node. If 'child' is a valid node belonging to the Tree and has a parent node, returns its parent. Returns null otherwise.

Parameters:
child - the child node you want to get its parent
 o getNode
 public TreeNode getNode(Object obj)
Gets the node associated to the specified object, or null if any.

Parameters:
obj - the object related to a node

All Packages  Class Hierarchy  This Package  Previous  Next  Index