|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ciips.animation.tree.TreeNode
This class holds the information regarding a node from the heap/complete
binary tree. This class implements the DrawingObj
interface
and hence can be freely added to the drawing panel using the
addDrawingObj
method. e.g.
Any added drawing object can be remove from the panel by using the
TreeNode node = new TreeNode();
drawingPanel.addDrawingObj(node);
removeObj
method. e.g.
drawingPanel.removeObj(node);
DrawingPanel.addDrawingObj(ciips.animation.DrawingObj)
,
DrawingPanel.removeObj(ciips.animation.DrawingObj)
Field Summary | |
protected int |
depth
|
boolean |
highlight
Attribute to indicate if the node is to be highlighted. |
protected boolean |
highlightLeft
Attribute to indicate if the left branch is to be highlighted. |
protected boolean |
highlightRight
Attribute to indicate if the right branch is to be highlighted. |
protected java.lang.String |
label
|
protected java.awt.Color |
labelColor
|
protected TreeNode |
left
|
protected java.awt.Color |
nodeColor
|
protected TreeNode |
right
|
protected int |
weight
|
protected int |
x
|
protected int |
y
|
Constructor Summary | |
TreeNode()
Create a new left node with weight 0. |
|
TreeNode(int weight)
Create a new leaf node with the specified weight. |
|
TreeNode(java.lang.String label)
Create a new leaf node with 0 weight and label as specified. |
|
TreeNode(java.lang.String label,
int weight)
Create a new leaf node with label and weight as specified in the parameters. |
|
TreeNode(TreeNode node)
Create a node with the left node as set and weight of the current node set to 0. |
|
TreeNode(TreeNode node1,
TreeNode node2)
Create a node with the left and right child nodes specified and the weight of the current node is the sum of the child node. |
Method Summary | |
void |
draw(java.awt.Graphics g)
This method draws the node on the corresponding graphical context normally passed in from the drawing panel. |
void |
expandSize(float factor)
Adjust the node size by a factor |
int |
getDepth()
Get the depth of his node. |
java.lang.String |
getLabel()
Get the label of this node. |
TreeNode |
getLeftTreeNode()
Get the left child of this node. |
java.awt.Dimension |
getNodeSize()
Return the current node size - used by other routines, eg, TreeEdge, to control their drawing |
TreeNode |
getRightTreeNode()
Get the right child of this node. |
int |
getWeight()
Get the weight of this node. |
int |
getX()
Get the left most position of the node. |
int |
getY()
Get the top most position of the node. |
void |
initColors(java.awt.Color nodeColor)
Set the color of the node. |
void |
initFonts(java.awt.Font hugeFont,
java.awt.Font bigFont)
Assign some font instances to reduce initialization over during redraw. |
boolean |
isLeaf()
Check if this node is a leaf node. |
void |
move(int x,
int y)
Move the node and all its branches based on the parameters. |
void |
moveTreeNode(int dx,
int dy)
Move the tree starting with node dx pixels to the right and dy pixels down. |
void |
setColour(java.awt.Color x)
|
void |
setDepth(int depth)
Sets the depth of this node corresponding to the root node of the tree. |
void |
setLabel(java.lang.String label)
Set the label of this node. |
void |
setLabelColour(java.awt.Color x)
|
void |
setLeftTreeNode(TreeNode node)
Link the left branch of this node to the node passed in as the parameter. |
void |
setPosition(int x,
int y,
int dx,
int dy)
Start at a node and set the positions for the sub-tree elements |
void |
setRightTreeNode(TreeNode node)
Link the right branch of this node to the node passed in as the parameter. |
void |
setWeight(int weight)
Set the weight of this node. |
void |
setX(int x)
Sets the x coordinate of the top-left corner of the node |
void |
setY(int y)
Sets the y coordinate of the top-left corner of the node |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.lang.String label
protected int weight
protected TreeNode left
protected TreeNode right
protected int x
protected int y
protected int depth
protected boolean highlightLeft
protected boolean highlightRight
public boolean highlight
protected java.awt.Color nodeColor
protected java.awt.Color labelColor
Constructor Detail |
public TreeNode(TreeNode node1, TreeNode node2)
node1
- The left node of this newly created node.node2
- The right node of this newly created node.public TreeNode(TreeNode node)
node
- The left node of the newly created node.public TreeNode()
public TreeNode(java.lang.String label, int weight)
label
- The label of the new node.weight
- The weight of the new node.public TreeNode(int weight)
weight
- The weight of the new node.public TreeNode(java.lang.String label)
label
- Label of the new node.Method Detail |
public void setWeight(int weight)
weight
- The weight to be assigned to this node.public void setLabel(java.lang.String label)
label
- The label to be assigned to this node.public int getWeight()
public java.lang.String getLabel()
public void setLeftTreeNode(TreeNode node)
node
- The new left child of this node.public void setRightTreeNode(TreeNode node)
node
- The new right child of this node.public TreeNode getLeftTreeNode()
public TreeNode getRightTreeNode()
public boolean isLeaf()
public void setX(int x)
public void setY(int y)
public int getX()
getX
in interface DrawingObj
public int getY()
getY
in interface DrawingObj
public int getDepth()
public void setPosition(int x, int y, int dx, int dy)
public void setDepth(int depth)
depth
- Depth of the node.public void move(int x, int y)
move
in interface DrawingObj
x
- The horizontal destination position of this node.y
- The vertical destination position of this node.public void moveTreeNode(int dx, int dy)
node
- The root node of the tree to be moved.dx
- The change in x direction.dy
- The change in y direction.public void initFonts(java.awt.Font hugeFont, java.awt.Font bigFont)
public void initColors(java.awt.Color nodeColor)
nodeColor
- new color of the node.public void setColour(java.awt.Color x)
public void setLabelColour(java.awt.Color x)
public void expandSize(float factor)
factor
- - expansion factor: factor > 1.0 => expansion,
factor < 1.0 => shrinkage
public java.awt.Dimension getNodeSize()
public void draw(java.awt.Graphics g)
draw
in interface DrawingObj
ciips.animation.DrawingObj
g
- A reference to the graphical context.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |