qflib 0.99

de.qfs.lib.gui
Class AWTTreeAdapter

java.lang.Object
  extended byde.qfs.lib.tree.IndexBasedTreeAdapter
      extended byde.qfs.lib.gui.AWTTreeAdapter
All Implemented Interfaces:
TreeAdapter

public class AWTTreeAdapter
extends IndexBasedTreeAdapter

This is a TreeAdapter for the AWT Component hierarchy. It assumes that all nodes passed are Components.

Special care is taken to handle JMenus. These have a logical hierarchy, meaning that JMenuItems are permanent children of a JMenu and a physical hierarchy in which the Items are added to the menu only while it is popped up.

By default the logical menu structure is assumed. If you want to traverse the component tree's physical structure, use the AWTTreeAdapter(boolean) constructor with a false argument.

Warning: The logical structure is inconsistent in that the parent menu of a MenuItem cannot be determined if the menu is not posted. This doesn't prevent traversing the hierarchy though.

Since:
0.98.1
Author:
Gregor Schmid

Nested Class Summary
 
Nested classes inherited from class de.qfs.lib.tree.IndexBasedTreeAdapter
IndexBasedTreeAdapter.ChildEnumeration
 
Constructor Summary
AWTTreeAdapter()
          Create a new AWTTreeAdapter.
AWTTreeAdapter(boolean specialJMenu)
          Create a new AWTTreeAdapter.
 
Method Summary
 int getChildCount(java.lang.Object parent)
          Get the number of children of a node.
 java.lang.Object getChildNode(java.lang.Object parent, int index)
          Get a child of a node.
 int getIndexOfChildNode(java.lang.Object parent, java.lang.Object child)
          Get the index of a child in a node's list of children.
 java.lang.Object getParentNode(java.lang.Object child)
          Get the parent of a node.
 boolean isLeaf(java.lang.Object node)
          Query whether a node is a leaf.
 
Methods inherited from class de.qfs.lib.tree.IndexBasedTreeAdapter
getChildren, getFirstChildNode, getLastChildNode, getNextSibling, getPreviousSibling, isEnumerationBased, isIndexBased, isLinkBased
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AWTTreeAdapter

public AWTTreeAdapter()
Create a new AWTTreeAdapter.


AWTTreeAdapter

public AWTTreeAdapter(boolean specialJMenu)
Create a new AWTTreeAdapter.

Parameters:
specialJMenu - Whether to treat JMenus specially (see class documentation). Default is true.
Since:
0.99.0
Method Detail

getParentNode

public java.lang.Object getParentNode(java.lang.Object child)
Get the parent of a node.

Parameters:
child - The node to query for the parent.
Returns:
The parent of the node.

isLeaf

public boolean isLeaf(java.lang.Object node)
Query whether a node is a leaf.

Parameters:
node - The node to query.
Returns:
True if the node is a leaf.

getChildCount

public int getChildCount(java.lang.Object parent)
Get the number of children of a node.

Parameters:
parent - The node to query.
Returns:
The number of children of the node.

getChildNode

public java.lang.Object getChildNode(java.lang.Object parent,
                                     int index)
                              throws java.lang.IndexOutOfBoundsException
Get a child of a node.

Parameters:
parent - The node to query.
index - The index of the child.
Returns:
The child at the index.
Throws:
java.lang.IndexOutOfBoundsException - If the index is invalid.

getIndexOfChildNode

public int getIndexOfChildNode(java.lang.Object parent,
                               java.lang.Object child)
Get the index of a child in a node's list of children.

Parameters:
parent - The node to query.
child - The child to look for.
Returns:
The index of the child or -1 if it is not a child of this node.

qflib 0.99