# 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

##

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

##

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

##

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

##

highlightLeft

     public boolean highlightLeft

  Attribute to indicate if the left branch is to be highlighted.

highlightRight

     public boolean highlightRight

  Attribute to indicate if the right branch is to be highlighted.

highlight

     public boolean highlight

  Attribute to indicate if the node is to be highlighted.

##

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.

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.

Node

     public Node()

  Create a new left node with weight 0.

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.

Node

     public Node(int weight)

  Create a new leaf node with the specified weight.

  Parameters:
    weight - The weight of the new node.

Node

     public Node(String label)

  Create a new leaf node with 0 weight and label as specified.

  Parameters:
    label - Label of the new node.

##

setWeight

     public void setWeight(int weight)

  Set the weight of this node.

  Parameters:
    weight - The weight to be assigned to this node.

setLabel

     public void setLabel(String label)

  Set the label of this node.

  Parameters:
    label - The label to be assigned to this node.

getWeight

     public int getWeight()

  Get the weight of this node.

  Returns:
    Weight of this node.

getLabel

     public String getLabel()

  Get the label of this node.

  Returns:
    Label of this node.

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.

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.

getLeftNode

     public Node getLeftNode()

  Get the left child of this node.

  Returns:
    the left child this this node.

getRightNode

     public Node getRightNode()

  Get the right child of this node.

  Returns:
    the right child this this node.

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.

setX

     public void setX(int x)

  Sets the x coordinate of the top-left corner of the node

setY

     public void setY(int y)

  Sets the y coordinate of the top-left corner of the node

getX

     public int getX()

  Get the left most position of the node.

  Returns:
    The x coordinates of the top-left corner of the node

getY

     public int getY()

  Get the top most position of the node.

  Returns:
    The y coordinates of the top-left corner of the node

getDepth

     public int getDepth()

  Get the depth of his node.

  Returns:
    The depth of this node in a tree.

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.

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.

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.

initFonts

     public void initFonts(Font hugeFont,
                           Font bigFont)

  Assign some font instances to reduce initialization over during redraw.

initColors

     public void initColors(Color nodeColor)

  Set the color of the node.

  Parameters:
    nodeColor - new color of the node.

draw

     public void draw(Graphics g)

  This method draws the node on the corresponding graphical context normally passed in from the drawing panel.