Class Node

java.lang.Object
   |
   +----Node

public class Node
extends Object
implements DrawingObj
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.
	Node node = new Node();
	drawingPanel.addDrawingObj(node);
 
Any added drawing object can be remove from the panel by using the removeObj method. e.g.
	drawingPanel.removeObj(node);
 

See Also:
addDrawingObj, removeObj, Heap

Variable Index

 o highlight
Attribute to indicate if the node is to be highlighted.
 o highlightLeft
Attribute to indicate if the left branch is to be highlighted.
 o highlightRight
Attribute to indicate if the right branch is to be highlighted.

Constructor Index

 o Node()
Create a new left node with weight 0.
 o Node(int)
Create a new leaf node with the specified weight.
 o Node(Node)
Create a node with the left node as set and weight of the current node set to 0.
 o Node(Node, Node)
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.
 o Node(String)
Create a new leaf node with 0 weight and label as specified.
 o Node(String, int)
Create a new leaf node with label and weight as specified in the parameters.

Method Index

 o draw(Graphics)
This method draws the node on the corresponding graphical context normally passed in from the drawing panel.
 o getDepth()
Get the depth of his node.
 o getLabel()
Get the label of this node.
 o getLeftNode()
Get the left child of this node.
 o getRightNode()
Get the right child of this node.
 o getWeight()
Get the weight of this node.
 o getX()
Get the left most position of the node.
 o getY()
Get the top most position of the node.
 o initColors(Color)
Set the color of the node.
 o initFonts(Font, Font)
Assign some font instances to reduce initialization over during redraw.
 o isLeaf()
Check if this node is a leaf node.
 o move(int, int)
Move the node and all its branches based on the parameters.
 o moveNode(int, int)
Move the tree starting with node dx pixels to the right and dy pixels down.
 o setDepth(int)
Sets the depth of this node corresponding to the root node of the tree.
 o setLabel(String)
Set the label of this node.
 o setLeftNode(Node)
Link the left branch of this node to the node passed in as the parameter.
 o setRightNode(Node)
Link the right branch of this node to the node passed in as the parameter.
 o setWeight(int)
Set the weight of this node.
 o setX(int)
Sets the x coordinate of the top-left corner of the node
 o setY(int)
Sets the y coordinate of the top-left corner of the node

Variables

 o highlightLeft
 public boolean highlightLeft
Attribute to indicate if the left branch is to be highlighted.

 o highlightRight
 public boolean highlightRight
Attribute to indicate if the right branch is to be highlighted.

 o highlight
 public boolean highlight
Attribute to indicate if the node is to be highlighted.

Constructors

 o Node
 public Node(Node node1,
             Node 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.

Parameters:
node1 - The left node of this newly created node.
node2 - The right node of this newly created node.
 o Node
 public Node(Node node)
Create a node with the left node as set and weight of the current node set to 0.

Parameters:
node - The left node of the newly created node.
 o Node
 public Node()
Create a new left node with weight 0.

 o Node
 public Node(String label,
             int weight)
Create a new leaf node with label and weight as specified in the parameters.

Parameters:
label - The label of the new node.
weight - The weight of the new node.
 o Node
 public Node(int weight)
Create a new leaf node with the specified weight.

Parameters:
weight - The weight of the new node.
 o Node
 public Node(String label)
Create a new leaf node with 0 weight and label as specified.

Parameters:
label - Label of the new node.

Methods

 o setWeight
 public void setWeight(int weight)
Set the weight of this node.

Parameters:
weight - The weight to be assigned to this node.
 o setLabel
 public void setLabel(String label)
Set the label of this node.

Parameters:
label - The label to be assigned to this node.
 o getWeight
 public int getWeight()
Get the weight of this node.

Returns:
Weight of this node.
 o getLabel
 public String getLabel()
Get the label of this node.

Returns:
Label of this node.
 o setLeftNode
 public void setLeftNode(Node node)
Link the left branch of this node to the node passed in as the parameter.

Parameters:
node - The new left child of this node.
 o setRightNode
 public void setRightNode(Node node)
Link the right branch of this node to the node passed in as the parameter.

Parameters:
node - The new right child of this node.
 o getLeftNode
 public Node getLeftNode()
Get the left child of this node.

Returns:
the left child this this node.
 o getRightNode
 public Node getRightNode()
Get the right child of this node.

Returns:
the right child this this node.
 o isLeaf
 public boolean isLeaf()
Check if this node is a leaf node. A leaf node has both left and right nodes null.

Returns:
true if the node is a leaf node; false otherwise.
 o setX
 public void setX(int x)
Sets the x coordinate of the top-left corner of the node

 o setY
 public void setY(int y)
Sets the y coordinate of the top-left corner of the node

 o getX
 public int getX()
Get the left most position of the node.

Returns:
The x coordinates of the top-left corner of the node
 o getY
 public int getY()
Get the top most position of the node.

Returns:
The y coordinates of the top-left corner of the node
 o getDepth
 public int getDepth()
Get the depth of his node.

Returns:
The depth of this node in a tree.
 o setDepth
 public void setDepth(int depth)
Sets the depth of this node corresponding to the root node of the tree.

Parameters:
depth - Depth of the node.
 o move
 public void move(int x,
                  int y)
Move the node and all its branches based on the parameters.

Parameters:
x - The horizontal destination position of this node.
y - The vertical destination position of this node.
 o moveNode
 public void moveNode(int dx,
                      int dy)
Move the tree starting with node dx pixels to the right and dy pixels down.

Parameters:
node - The root node of the tree to be moved.
dx - The change in x direction.
dy - The change in y direction.
 o initFonts
 public void initFonts(Font hugeFont,
                       Font bigFont)
Assign some font instances to reduce initialization over during redraw.

 o initColors
 public void initColors(Color nodeColor)
Set the color of the node.

Parameters:
nodeColor - new color of the node.
 o draw
 public void draw(Graphics g)
This method draws the node on the corresponding graphical context normally passed in from the drawing panel.