## org.w3c.tools.widgets
Class TreeBrowser

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

Direct Known Subclasses:
  FrameBrowser, ServerBrowser

public class TreeBrowser
extends java.awt.Canvas
implements java.awt.event.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.

See Also:
  Serialized Form

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

Fields inherited from class java.awt.Component
`BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT`

Constructor Summary
`protected` `TreeBrowser()`
`` `TreeBrowser(java.lang.Object root, java.lang.String label, NodeHandler handler, java.awt.Image icon)` Builds a new browser instance

Method Summary
`void` `adjustmentValueChanged(java.awt.event.AdjustmentEvent evt)` Updates graphical appearance in response to a scroll.
`void` `collapse(TreeNode item)` Contracts the representation of the specified node.
`TreeNode` `getNode(java.lang.Object obj)` Gets the node associated to the specified object, or null if any.
`TreeNode` `getParent(TreeNode child)` Returns the parent node of the specified node.
`java.awt.Dimension` `getPreferredSize()`
`int` `getSelectionPolicy()` Gets the selection policy.
`protected void` `initialize(java.lang.Object item, java.lang.String label, NodeHandler handler, java.awt.Image icon)`
`void` `insert(TreeNode parent, java.lang.Object item, NodeHandler handler, java.lang.String label, java.awt.Image icon)` Inserts new node.
`protected TreeNode` `itemAt(int y)` this should be private.
`void` `paint(java.awt.Graphics g)` repaints the View.
`void` `remove(TreeNode node)` Removes the specified node.
`void` `removeBranch(TreeNode node)` Removes the specified node and its children.
`void` `select(TreeNode node)` Selects the specified node.
`java.util.Enumeration` `selection()` Returns an Enumeraiton of selected items.
`void` `setHorizontalScrollbar(java.awt.Scrollbar a)` Sets 'a' as horizontal Scrollbar.
`void` `setScrollbarDisplayPolicy(int scrollbarDisplayPolicy)` Sets the scrollbars display policy to the specified policy.
`void` `setSelectionBackgroudColor(java.awt.Color color)` Sets the background color of a selected node to the specified color.
`void` `setSelectionFontColor(java.awt.Color color)` Sets the color of a selected node to the specified color.
`void` `setSelectionPolicy(int policy)` Sets the selection policy.
`void` `setVerticalScrollbar(java.awt.Scrollbar a)` Sets 'a' as vertical Scrollbar.
`void` `unselect(TreeNode node)` Unselects the specified node.
`void` `unselectAll()` Unselects all selected items.
`void` `update(java.awt.Graphics pg)`

Methods inherited from class java.awt.Canvas
`addNotify`

Methods inherited from class java.awt.Component

`action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, validate`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### 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 java.util.Vector items

### selection

    protected java.util.Vector selection

### topItem

    protected int topItem

### visibleItemCount

    protected int visibleItemCount

### selectionPolicy

    protected int selectionPolicy

### fontHeight

    protected int fontHeight

Constructor Detail

### TreeBrowser

    public TreeBrowser(java.lang.Object root,
                       java.lang.String label,
                       NodeHandler handler,
                       java.awt.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()

Method Detail

### initialize

    protected void initialize(java.lang.Object item,
                              java.lang.String label,
                              NodeHandler handler,
                              java.awt.Image icon)

### getPreferredSize

    public java.awt.Dimension getPreferredSize()

  Overrides:
    getPreferredSize in class java.awt.Component

### setSelectionFontColor

    public void setSelectionFontColor(java.awt.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(java.awt.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(java.awt.Graphics g)

  repaints the View.
  Overrides:
    paint in class java.awt.Canvas

### itemAt

    protected TreeNode itemAt(int y)

  this should be private. having it protected is a present for dummy VM that doesn't know that an inner class can access private method of its parent class

### update

    public void update(java.awt.Graphics pg)

  Overrides:
    update in class java.awt.Component

### insert

    public void insert(TreeNode parent,
                       java.lang.Object item,
                       NodeHandler handler,
                       java.lang.String label,
                       java.awt.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 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 java.util.Enumeration selection()

  Returns an Enumeraiton of selected items.

### setVerticalScrollbar

    public void setVerticalScrollbar(java.awt.Scrollbar a)

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

### setHorizontalScrollbar

    public void setHorizontalScrollbar(java.awt.Scrollbar a)

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

### adjustmentValueChanged

    public void adjustmentValueChanged(java.awt.event.AdjustmentEvent evt)

  Updates graphical appearance in response to a scroll.
  Specified by:
    adjustmentValueChanged in interface java.awt.event.AdjustmentListener

### 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(java.lang.Object obj)

  Gets the node associated to the specified object, or null if any.
  Parameters:
    `obj` - the object related to a node