fri.gui.swing.polytreetable
Class AbstractPolyTreeNode

java.lang.Object
  |
  +--fri.gui.swing.polytreetable.AbstractPolyTreeNode
All Implemented Interfaces:
PolyTreeNode
Direct Known Subclasses:
DefaultPolyTreeNode

public abstract class AbstractPolyTreeNode
extends java.lang.Object
implements PolyTreeNode

Implements a basic PolyTreeNode. Such nodes can appear more than once in the tree view, as polyhierarchies can contain cycles. You get an array of rows where it occurs if you request a PolyTreeNode from PolyTreeTable.

Implement getChildCount() and getParentCount() to read data for the rendered structure, as they get messaged when a tree expansion takes place. Override getAllowsParents() and getAllowsChildren() if you can decide the fact of allowing children without reading child data. This saves performance. The model is preset to consider these properties, but if model.asksAllowsChildren or model.asksAllowsParents was set to false, these methods will not be called.

Author:
Ritzberger Fritz
See Also:
PolyTreeNode

Field Summary
protected  boolean allowsChildren
          The allowsChildren property, considered only if model.asksAllowsChildren was set to true, which is default.
protected  boolean allowsParents
          The allowsParents property, considered only if model.asksAllowsParents was set to true, which is default.
protected  java.util.Vector children
          The list of children, preset to null.
static java.util.Enumeration EMPTY_ENUMERATION
          An enumeration that is always empty.
protected  java.util.Vector parents
          The list of parents, preset to null.
protected  java.lang.Object userObject
          The user object, a File or Document or whatever.
 
Constructor Summary
protected AbstractPolyTreeNode()
          Friendly to override do-nothing constructor.
  AbstractPolyTreeNode(java.lang.Object userObject)
          Create a node that allows children and parents and hosts an user object.
  AbstractPolyTreeNode(java.lang.Object userObject, boolean allowsChildren, boolean allowsParents)
          Create a node with an user object and parent/child flags.
 
Method Summary
 java.util.Enumeration children()
          Returns the children of the reciever as an Enumeration.
 boolean getAllowsChildren()
          Returns true if the receiver allows children.
 boolean getAllowsParents()
          Returns true if the receiver allows parents.
 PolyTreeNode getChildAt(int childIndex)
          Returns the child PolyTreeNode at index childIndex.
 int getChildIndex(PolyTreeNode aChild)
          Returns the index of aChild in the receivers children.
protected  int getElementCount(java.util.Vector list)
          Returns size of passed list if not null, else zero.
 PolyTreeNode getParentAt(int parentIndex)
          Returns the parent PolyTreeNode at index parentIndex.
 int getParentIndex(PolyTreeNode aParent)
          Returns the index of aParent in the receivers parents.
 java.lang.Object getUserObject()
          Returns the object representing the File or Document or whatever.
 boolean isChildLeaf()
          Returns true if this node has no children.
 boolean isNodeChild(PolyTreeNode aNode)
          Returns true if passed node is a child of this.
 boolean isNodeParent(PolyTreeNode aNode)
          Returns true if passed node is a parent of this.
 boolean isParentLeaf()
          Returns true if this node has no parents.
 java.util.Enumeration parents()
          Returns the parents of the reciever as an Enumeration.
 void setAllowsChildren(boolean allows)
          Set the fact that the receiver allows children.
 void setAllowsParents(boolean allows)
          Set the fact that the receiver allows parents.
 java.lang.String toString()
          Returns userObject.toString().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface fri.gui.swing.polytreetable.PolyTreeNode
getChildCount, getParentCount
 

Field Detail

userObject

protected java.lang.Object userObject
The user object, a File or Document or whatever.


parents

protected java.util.Vector parents
The list of parents, preset to null.


children

protected java.util.Vector children
The list of children, preset to null.


allowsParents

protected boolean allowsParents
The allowsParents property, considered only if model.asksAllowsParents was set to true, which is default.


allowsChildren

protected boolean allowsChildren
The allowsChildren property, considered only if model.asksAllowsChildren was set to true, which is default.


EMPTY_ENUMERATION

public static final java.util.Enumeration EMPTY_ENUMERATION
An enumeration that is always empty. This is used when an enumeration of a leaf node's children or parents is requested.

Constructor Detail

AbstractPolyTreeNode

protected AbstractPolyTreeNode()
Friendly to override do-nothing constructor.


AbstractPolyTreeNode

public AbstractPolyTreeNode(java.lang.Object userObject)
Create a node that allows children and parents and hosts an user object.


AbstractPolyTreeNode

public AbstractPolyTreeNode(java.lang.Object userObject,
                            boolean allowsChildren,
                            boolean allowsParents)
Create a node with an user object and parent/child flags. These Flags will be considered only if model.asksAllowsChildren and model.asksAllowsParents was set to true (default)

Method Detail

toString

public java.lang.String toString()
Returns userObject.toString().

Overrides:
toString in class java.lang.Object

getUserObject

public java.lang.Object getUserObject()
Returns the object representing the File or Document or whatever.

Specified by:
getUserObject in interface PolyTreeNode

children

public java.util.Enumeration children()
Returns the children of the reciever as an Enumeration.

Specified by:
children in interface PolyTreeNode

parents

public java.util.Enumeration parents()
Returns the parents of the reciever as an Enumeration.

Specified by:
parents in interface PolyTreeNode

getAllowsParents

public boolean getAllowsParents()
Returns true if the receiver allows parents. Override this if you can decide the fact of allowing parents without reading parent data. This saves performance. This method gets called by the model if model.asksAllowsParents was set to true (default).

Specified by:
getAllowsParents in interface PolyTreeNode

getAllowsChildren

public boolean getAllowsChildren()
Returns true if the receiver allows children. Override this if you can decide the fact of allowing children without reading parent data. This saves performance. This method gets called by the model if model.asksAllowsChildren was set to true (default).

Specified by:
getAllowsChildren in interface PolyTreeNode

setAllowsParents

public void setAllowsParents(boolean allows)
Set the fact that the receiver allows parents. Call this from outside if you can decide the fact of allowing children without reading parent data. This saves performance.


setAllowsChildren

public void setAllowsChildren(boolean allows)
Set the fact that the receiver allows children. Call this from outside if you can decide the fact of allowing children without reading child data. This saves performance.


getChildAt

public PolyTreeNode getChildAt(int childIndex)
Returns the child PolyTreeNode at index childIndex.

Specified by:
getChildAt in interface PolyTreeNode

getParentAt

public PolyTreeNode getParentAt(int parentIndex)
Returns the parent PolyTreeNode at index parentIndex.

Specified by:
getParentAt in interface PolyTreeNode

getElementCount

protected int getElementCount(java.util.Vector list)
Returns size of passed list if not null, else zero.


getParentIndex

public int getParentIndex(PolyTreeNode aParent)
Returns the index of aParent in the receivers parents.

Specified by:
getParentIndex in interface PolyTreeNode

getChildIndex

public int getChildIndex(PolyTreeNode aChild)
Returns the index of aChild in the receivers children.

Specified by:
getChildIndex in interface PolyTreeNode

isNodeParent

public boolean isNodeParent(PolyTreeNode aNode)
Returns true if passed node is a parent of this.


isNodeChild

public boolean isNodeChild(PolyTreeNode aNode)
Returns true if passed node is a child of this.


isChildLeaf

public boolean isChildLeaf()
Returns true if this node has no children. This is called by the model when model.asksAllowsParents was set to false. Else getAllowsChildren() is messaged to retrieve this property.

Specified by:
isChildLeaf in interface PolyTreeNode

isParentLeaf

public boolean isParentLeaf()
Returns true if this node has no parents. This is called by the model when model.asksAllowsParents was set to false. Else getAllowsParents() is messaged to retrieve this property.

Specified by:
isParentLeaf in interface PolyTreeNode