    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.

##

fontHeight
items
MULTIPLE
  The policy that enables a multiple selection of nodes.
SCROLLBARS_ALWAYS
  Specifies that the horizontal/vertical scrollbars should always be shown regardless of the respective sizes of the TreeBrowser.
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.
selection
selectionPolicy
SINGLE
  This policy that lets just one node selected at the same time.
topItem
visibleItemCount

##

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

##

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

##

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.

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.

SINGLE

     public static final int SINGLE

  This policy that lets just one node selected at the same time.

MULTIPLE

     public static final int MULTIPLE

  The policy that enables a multiple selection of nodes.

items

     protected Vector items

selection

     protected Vector selection

topItem

     protected int topItem

visibleItemCount

     protected int visibleItemCount

selectionPolicy

     protected int selectionPolicy

fontHeight

     protected int fontHeight

##

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

TreeBrowser

     protected TreeBrowser()

##

initialize

     protected void initialize(Object item,
                               String label,
                               NodeHandler handler,
                               Image icon)

getPreferredSize

     public Dimension getPreferredSize()

  Overrides:
    getPreferredSize in class Component

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

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

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

paint

     public void paint(Graphics g)

  repaints the View.

  Overrides:
    paint in class Canvas

update

     public void update(Graphics pg)

  Overrides:
    update in class Component

insert

     public void insert(TreeNode parent,
                        Object item,
                        NodeHandler handler,
                        String label,
                        Image icon)

  Inserts new node.

  Parameters:
    parent - the parent node.

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

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

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

setSelectionPolicy

     public void setSelectionPolicy(int policy)

  Sets the selection policy.

  Parameters:
    policy: - SINGLE or MULTIPLE

getSelectionPolicy

     public int getSelectionPolicy()

  Gets the selection policy.

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

unselect

     public void unselect(TreeNode node)

  Unselects the specified node. It is caller's responsibility to call repaint()

  Parameters:
    node - the node to unselect

unselectAll

     public void unselectAll()

  Unselects all selected items.

selection

     public Enumeration selection()

  Returns an Enumeraiton of selected items.

setVerticalScrollbar

     public void setVerticalScrollbar(Scrollbar a)

  Sets 'a' as vertical Scrollbar. The Browser becomes an AdjustmentListener of this scrollbar.

setHorizontalScrollbar

     public void setHorizontalScrollbar(Scrollbar a)

  Sets 'a' as horizontal Scrollbar. The Browser becomes an AdjustmentListener of this scrollbar.

adjustmentValueChanged

     public void adjustmentValueChanged(AdjustmentEvent evt)

  Updates graphical appearance in response to a scroll.

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

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