widgets.awt
Class Tree

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Canvas
              |
              +--widgets.awt.Tree

public class Tree
extends java.awt.Canvas

This class implements a tree widget: a graphical representation of hierarchical data.

The widget supports ActionListener and PopupMenuListener objects. Registered listeners will be notified when a node is double clicked or when a popup menu is requested. Note that TreeNode objects also support these listeners. It is up to the programmer to decide at which level to handle events.

Scroll bars are not directely supported by this widget. If you want a scrollable tree you'll have to put this component in a ScrollPane.

Author:
Erwin Vervaet (erwin@cs.kuleuven.ac.be)
See Also:
TreeNode, Serialized Form

Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
Tree()
          Default constructor.
Tree(java.net.URL openDirectoryIconURL, java.net.URL closeDirectoryIconURL, int parentLineOffset)
          Create a tree widget that will display the specified open/close directory icons before each directory in the tree.
 
Method Summary
 void addActionListener(java.awt.event.ActionListener l)
           
 void addPopupMenuListener(PopupMenuListener l)
           
 java.awt.Dimension getPreferredSize()
           
 TreeNode getRoot()
          Get the root of the tree displayed by the widget.
 TreeNode getSelectedNode()
          Return the currently selected node of the tree, or null if none.
 boolean getShowPreIcons()
          Are pre-icons being shown?
 boolean isDoubleBuffered()
           
 void paint(java.awt.Graphics g)
           
protected  void processActionEvent(java.awt.event.ActionEvent e)
           
protected  void processMouseEvent(java.awt.event.MouseEvent e)
           
protected  void processPopupMenuEvent(PopupMenuEvent e)
           
 void redraw()
          Redraw the tree in the off-screen back buffer, then make sure this back buffer is visible.
 void removeActionListener(java.awt.event.ActionListener l)
           
 void removePopupMenuListener(PopupMenuListener l)
           
 void setFont(java.awt.Font f)
           
 void setIcons(java.net.URL openDirectoryIconURL, java.net.URL closeDirectoryIconURL, int parentLineOffset)
          Set the open and close directory icons of this tree to the given icons.
 void setRoot(TreeNode root)
          Set the root of the tree displayed by the widget.
 void setShowNodeIcons(boolean show)
          Specifies whether or not to display pre-icons in front of the tree.
 
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, 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, 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, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Tree

public Tree()

Default constructor. Creates a tree with no directory icons.


Tree

public Tree(java.net.URL openDirectoryIconURL,
            java.net.URL closeDirectoryIconURL,
            int parentLineOffset)

Create a tree widget that will display the specified open/close directory icons before each directory in the tree. The icons will only be used if both icons can be loaded!

The parentLineOffset specifies by how many pixels the parent connection line should be indented to center under the given directory icons.

Method Detail

processActionEvent

protected void processActionEvent(java.awt.event.ActionEvent e)

addActionListener

public void addActionListener(java.awt.event.ActionListener l)

removeActionListener

public void removeActionListener(java.awt.event.ActionListener l)

processPopupMenuEvent

protected void processPopupMenuEvent(PopupMenuEvent e)

addPopupMenuListener

public void addPopupMenuListener(PopupMenuListener l)

removePopupMenuListener

public void removePopupMenuListener(PopupMenuListener l)

redraw

public void redraw()

Redraw the tree in the off-screen back buffer, then make sure this back buffer is visible.

Make sure you call redraw after programmatic changes to the tree diplayed by the Tree widget!


setFont

public void setFont(java.awt.Font f)
Overrides:
setFont in class java.awt.Component

setIcons

public void setIcons(java.net.URL openDirectoryIconURL,
                     java.net.URL closeDirectoryIconURL,
                     int parentLineOffset)

Set the open and close directory icons of this tree to the given icons. Only if both icons can be loaded will they be used in the tree.

The parentLineOffset specifies by how many pixels the parent connection line should be indented to center under the given directory icons.


setShowNodeIcons

public void setShowNodeIcons(boolean show)

Specifies whether or not to display pre-icons in front of the tree. If a tree node has an icon it will be displayed at the start of that node's tree line, as a pre-icon.


getShowPreIcons

public boolean getShowPreIcons()

Are pre-icons being shown?


setRoot

public void setRoot(TreeNode root)

Set the root of the tree displayed by the widget.


getRoot

public TreeNode getRoot()

Get the root of the tree displayed by the widget.


getSelectedNode

public TreeNode getSelectedNode()

Return the currently selected node of the tree, or null if none.


processMouseEvent

protected void processMouseEvent(java.awt.event.MouseEvent e)
Overrides:
processMouseEvent in class java.awt.Component

paint

public void paint(java.awt.Graphics g)
Overrides:
paint in class java.awt.Canvas

isDoubleBuffered

public boolean isDoubleBuffered()
Overrides:
isDoubleBuffered in class java.awt.Component

getPreferredSize

public java.awt.Dimension getPreferredSize()
Overrides:
getPreferredSize in class java.awt.Component