ca.ucalgary.innovis
Class NAryTreeNode

java.lang.Object
  extended by ca.ucalgary.innovis.NAryTreeNode
All Implemented Interfaces:
NAryTreeNodeModel, javax.swing.tree.TreeNode

public class NAryTreeNode
extends java.lang.Object
implements NAryTreeNodeModel

This class implements a typical node that can be used for storing a hierarchical data structure and some information for representing the data structyre. Other node types can be implemented by using the TNodeModel.

Version:
1.5
Author:
pneumann

Constructor Summary
NAryTreeNode()
           
NAryTreeNode(java.lang.String id)
          Constructor.
 
Method Summary
 void addChild(NAryTreeNode child)
          Adds the given node to the tree as a child.
 void addChild(java.lang.String id)
          Creates a new node with the given id.
 java.util.Enumeration children()
           
 boolean getAllowsChildren()
          I don't use this but what the heck
 javax.swing.tree.TreeNode getChildAt(int index)
          Returns the child at the current index in the list of children.
 int getChildCount()
          Returns the number of children of this node.
 double getHeight()
          Returns the height of the bounding box for this node.
 java.lang.String getID()
          Returns the id for this node.
 int getIndex(javax.swing.tree.TreeNode n)
           
 java.lang.String getLabel()
          Returns a string representing the label for this node.
 int getLevel()
          Returns the level of this node in the tree hierarchy.
 java.lang.Object getObject()
          Returns the object stored in this node.
 javax.swing.tree.TreeNode getParent()
          Returns the parent of this node.
 java.lang.String getType()
          Returns this node's type.
 double getWeight()
          Returns the weight (count) for this node.
 double getWidth()
          Returns the width of the bounding box for this node.
 double getXPosition()
          Returns the x position of the representation of this node.
 double getYPosition()
          Returns the y position of the representation of this node.
 boolean isLeaf()
          Returns whether this node is a leaf or not.
 void removeChild(NAryTreeNode child)
          Removes a child from this node's list of children.
 void removeChildAt(int index)
          Removed a child from this node's list of children.
 void setHeight(double height)
          Sets the height of the bounding box for this node.
 void setID(java.lang.String id)
          Sets an id or name for this node.
 void setLabel(java.lang.String title)
          Sets a string as a label for this node.
 void setNodeSize(double width, double height)
          Sets the drawing size of this node.
 void setObject(java.lang.Object o)
          Gives this node an object to store.
 void setPosition(double x, double y)
          Sets an arbitrary drawing position for this node
 void setType(java.lang.String type)
          Gives the node a type.
 void setWeight(double nodeWeight)
          Sets a variable
 void setWidth(double width)
          Sets the width of the bounding box for this node.
 void setXPosition(double x)
          Sets an arbitrary drawing position for this node.
 void setYPosition(double y)
          Sets an arbitrary drawing position for this node.
 java.lang.String toString()
          Returns a string with info about this node, containing the Node id, number of children (degree) and whether it is a leaf or not.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NAryTreeNode

public NAryTreeNode()

NAryTreeNode

public NAryTreeNode(java.lang.String id)
Constructor. Creates the node with an associated id, no associated parent, an empty list of children.

Parameters:
id - - the unique id of this node
Method Detail

addChild

public void addChild(java.lang.String id)
Creates a new node with the given id. This node is added to the current node as a child. The node is added at the end of the current list of children.

Parameters:
id - unique identifier for the child. It should be unique in the whole tree.

addChild

public void addChild(NAryTreeNode child)
Adds the given node to the tree as a child. The node is added at the end of the current list of children.

Specified by:
addChild in interface NAryTreeNodeModel
Parameters:
child - the child to be added to this node.

setLabel

public void setLabel(java.lang.String title)
Sets a string as a label for this node. This can be displayed in a representation of the node.

Parameters:
title - the string to be set as the label of this node.

getLabel

public java.lang.String getLabel()
Returns a string representing the label for this node.

Returns:
the label of this node

getChildAt

public javax.swing.tree.TreeNode getChildAt(int index)
Returns the child at the current index in the list of children.

Specified by:
getChildAt in interface javax.swing.tree.TreeNode
Parameters:
index - the index of the requested child in the list of children.

removeChildAt

public void removeChildAt(int index)
Removed a child from this node's list of children.

Parameters:
index - The index of the child to be removed.

removeChild

public void removeChild(NAryTreeNode child)
Removes a child from this node's list of children.

Specified by:
removeChild in interface NAryTreeNodeModel
Parameters:
child - The child to be removed.

getParent

public javax.swing.tree.TreeNode getParent()
Returns the parent of this node. Returns NULL if the node has no parent (should only happen for the root node).

Specified by:
getParent in interface javax.swing.tree.TreeNode

setID

public void setID(java.lang.String id)
Description copied from interface: NAryTreeNodeModel
Sets an id or name for this node. This value should be unique for each node in the tree.

Specified by:
setID in interface NAryTreeNodeModel
Parameters:
id - identifier for this node.
See Also:
NAryTreeNodeModel.setID(java.lang.String)

getID

public java.lang.String getID()
Description copied from interface: NAryTreeNodeModel
Returns the id for this node.

Specified by:
getID in interface NAryTreeNodeModel
Returns:
the id for this node.
See Also:
NAryTreeNodeModel.getID()

getChildCount

public int getChildCount()
Returns the number of children of this node.

Specified by:
getChildCount in interface javax.swing.tree.TreeNode

isLeaf

public boolean isLeaf()
Returns whether this node is a leaf or not.

Specified by:
isLeaf in interface javax.swing.tree.TreeNode

toString

public java.lang.String toString()
Returns a string with info about this node, containing the Node id, number of children (degree) and whether it is a leaf or not.

Overrides:
toString in class java.lang.Object

setType

public void setType(java.lang.String type)
Gives the node a type.

Specified by:
setType in interface NAryTreeNodeModel
Parameters:
type - the string holding a type specifier.

getType

public java.lang.String getType()
Returns this node's type.

Specified by:
getType in interface NAryTreeNodeModel
Returns:
a type for this node.

setObject

public void setObject(java.lang.Object o)
Gives this node an object to store. This object can hold all sorts of info on this node.

Parameters:
o - The object to store in the node.

getObject

public java.lang.Object getObject()
Returns the object stored in this node.

Returns:
the object stored in this node.

getIndex

public int getIndex(javax.swing.tree.TreeNode n)
Specified by:
getIndex in interface javax.swing.tree.TreeNode
See Also:
TreeNode.getIndex(javax.swing.tree.TreeNode)

getAllowsChildren

public boolean getAllowsChildren()
I don't use this but what the heck

Specified by:
getAllowsChildren in interface javax.swing.tree.TreeNode
See Also:
TreeNode.getAllowsChildren()

children

public java.util.Enumeration children()
Specified by:
children in interface javax.swing.tree.TreeNode
See Also:
TreeNode.children()

setNodeSize

public void setNodeSize(double width,
                        double height)
Sets the drawing size of this node. Don't use this function if you are drawing more than one representation of this data structure.

Parameters:
width - The width of the bounding box of this node.
height - The height of the bounding box of this node.

getWidth

public double getWidth()
Returns the width of the bounding box for this node.

Returns:
The width of the bounding box for this node.

getHeight

public double getHeight()
Returns the height of the bounding box for this node.

Returns:
The height of the bounding box for this node.

setWidth

public void setWidth(double width)
Sets the width of the bounding box for this node.

Parameters:
width - The width of the bounding box for this node.

setHeight

public void setHeight(double height)
Sets the height of the bounding box for this node.

Parameters:
height - The height of the bounding box for this node.

setXPosition

public void setXPosition(double x)
Sets an arbitrary drawing position for this node.

Parameters:
x - the x position of the representation of this node

setYPosition

public void setYPosition(double y)
Sets an arbitrary drawing position for this node.

Parameters:
y - the y position of the representation of this npde

setPosition

public void setPosition(double x,
                        double y)
Sets an arbitrary drawing position for this node

Parameters:
x - the position along the x-axis
y - the position along the y-axis

getXPosition

public double getXPosition()
Returns the x position of the representation of this node.

Returns:

getYPosition

public double getYPosition()
Returns the y position of the representation of this node.

Returns:

getLevel

public int getLevel()
Returns the level of this node in the tree hierarchy. The root is at level 0.

Specified by:
getLevel in interface NAryTreeNodeModel
Returns:

setWeight

public void setWeight(double nodeWeight)
Sets a variable

Parameters:
nodeWeight - the weight (count) that will be saved for this node.

getWeight

public double getWeight()
Returns the weight (count) for this node.

Returns:
the weight for this node.