widgets.awt
Class TreeNode

java.lang.Object
  |
  +--widgets.awt.TreeNode

public class TreeNode
extends java.lang.Object

This class represents a node in a tree that can be displayed by the Tree widget.

TreeNode objects support ActionListeners that will be notified when the node has been double-clicked in a Tree widget.

TreeNodes also supports popup menus. Registered PopupMenuListeners will be notified when a popup menu was requested for a node.

Author:
Erwin Vervaet (erwin@cs.kuleuven.ac.be)
See Also:
Tree

Constructor Summary
TreeNode(TreeNode parent, java.lang.String name)
          Create a tree node with the given parent and name, but with no icon nor associated content.
TreeNode(TreeNode parent, java.lang.String name, java.awt.Image icon)
          Create a tree node with given parent, name and icon, but no associated content.
TreeNode(TreeNode parent, java.lang.String name, java.lang.Object content)
          Create a tree node with the given parent, name and content but no icon.
TreeNode(TreeNode parent, java.lang.String name, java.lang.Object content, java.awt.Image icon)
          Create a tree node with the given parent, name, content and icon.
 
Method Summary
 void addActionListener(java.awt.event.ActionListener l)
           
 TreeNode addChild(TreeNode node)
          Add a node to the end of the list of children of this node.
 void addPopupMenuListener(PopupMenuListener l)
           
 TreeNode childByName(java.lang.String name)
          Return the child node of this node with the given name or null if there is no such child.
 int countChildren()
          Return the number of direct children of this node.
 int countVisibleChildren()
          Return the number of children (direct or indirect) of this node that are 'visible'.
 TreeNode firstChild()
          Returns this node's first child, or null if none.
 java.lang.Object getContent()
           
 boolean getDirectory()
          Does this node represent a directory?
 boolean getExpanded()
           
 java.awt.Image getIcon()
           
 java.lang.String getName()
           
 TreeNode getParent()
           
 TreeNode insertSibling(TreeNode node)
          Insert the given node directely after this node in the parent's list of children.
 boolean isFirstChild()
          Is this node the first child of its parent?
 boolean isLastChild()
          Is this node the last child of its parent?
 int level()
          Return the level of this node in a tree.
 TreeNode next()
          Get this node's successor within the list of children of this node's parent.
 TreeNode previous()
          Get this node's predecessor within the list of children of this node's parent.
protected  void processActionEvent(java.awt.event.ActionEvent e)
           
protected  void processPopupMenuEvent(PopupMenuEvent e)
           
 void remove()
          Remove this node from its parent's list of children.
 void removeActionListener(java.awt.event.ActionListener l)
           
 void removePopupMenuListener(PopupMenuListener l)
           
 void setContent(java.lang.Object content)
           
 void setDirectory(boolean b)
          Specify whether or not this node represents a directory.
 void setExpanded(boolean b)
          Set whether this node is expanded or collapsed.
 void setIcon(java.awt.Image icon)
           
 void setName(java.lang.String newname)
           
 void setParent(TreeNode parent)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeNode

public TreeNode(TreeNode parent,
                java.lang.String name,
                java.lang.Object content,
                java.awt.Image icon)

Create a tree node with the given parent, name, content and icon.


TreeNode

public TreeNode(TreeNode parent,
                java.lang.String name,
                java.awt.Image icon)

Create a tree node with given parent, name and icon, but no associated content.


TreeNode

public TreeNode(TreeNode parent,
                java.lang.String name,
                java.lang.Object content)

Create a tree node with the given parent, name and content but no icon.


TreeNode

public TreeNode(TreeNode parent,
                java.lang.String name)

Create a tree node with the given parent and name, but with no icon nor associated content.

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)

setParent

public void setParent(TreeNode parent)

getParent

public TreeNode getParent()

setName

public void setName(java.lang.String newname)

getName

public java.lang.String getName()

setContent

public void setContent(java.lang.Object content)

getContent

public java.lang.Object getContent()

setIcon

public void setIcon(java.awt.Image icon)

getIcon

public java.awt.Image getIcon()

setExpanded

public void setExpanded(boolean b)

Set whether this node is expanded or collapsed. Note that a node with no children cannot be expanded and thus a getExpanded() on a leaf node will always return false!


getExpanded

public boolean getExpanded()

setDirectory

public void setDirectory(boolean b)

Specify whether or not this node represents a directory.


getDirectory

public boolean getDirectory()

Does this node represent a directory?


next

public TreeNode next()

Get this node's successor within the list of children of this node's parent. Returns null if this node is the last child of its parent.


previous

public TreeNode previous()

Get this node's predecessor within the list of children of this node's parent. Returns null if this node is the first child of its parent.


firstChild

public TreeNode firstChild()

Returns this node's first child, or null if none.


childByName

public TreeNode childByName(java.lang.String name)

Return the child node of this node with the given name or null if there is no such child.


level

public int level()

Return the level of this node in a tree. The level of the root is 0, it's children have level 1 and so on.


countChildren

public int countChildren()

Return the number of direct children of this node. Possible offspring of those children are not included in the count!


isLastChild

public boolean isLastChild()

Is this node the last child of its parent?


isFirstChild

public boolean isFirstChild()

Is this node the first child of its parent?


countVisibleChildren

public int countVisibleChildren()

Return the number of children (direct or indirect) of this node that are 'visible'. A child is visible if all its parents are expanded.


remove

public void remove()

Remove this node from its parent's list of children. Since a root cannot remove itself, nothing will happen in this case.


addChild

public TreeNode addChild(TreeNode node)

Add a node to the end of the list of children of this node.


insertSibling

public TreeNode insertSibling(TreeNode node)

Insert the given node directely after this node in the parent's list of children.