import objectdraw.*;

/**
 * Abstract base class for representations of a node
 * 
 * @author Russell C. Bjork 
 * @version March 26, 2008
 */
public abstract class Node
{
    /** Draw this node as part of drawing the tree
     * 
     * @param text the text that is to appear in this node
     * @param x the x coordinate of the upper left hand corner of the tree
     *         of which this node is the root
     *  @param y the y coordinate of the upper left hand corner of the tree
     *         of which this node is the root
     *  @param width the width of the area in which to draw the tree - the
     *         tree will be centered within this
     *  (No height is specified - the tree will start at the y coordinate
     *   specified and will be as high as needed)
     *  @param canvas the canvas on which to draw the tree.
     */
    protected void drawNode(String text,
                            double x, 
                            double y, 
                            double width,
                            DrawingCanvas canvas) {
                                
        double nodeX = x + (width - TREE_NODE_DIAMETER)/2;
        FilledOval node = new FilledOval(nodeX, y, TREE_NODE_DIAMETER, TREE_NODE_DIAMETER, canvas);
        node.setColor(java.awt.Color.WHITE);
        new FramedOval(nodeX, y, TREE_NODE_DIAMETER, TREE_NODE_DIAMETER, canvas);
        Text contents = new Text(text, nodeX, y, canvas);
        contents.move((TREE_NODE_DIAMETER - contents.getWidth())/2, 
                      (TREE_NODE_DIAMETER - contents.getHeight())/2);
    }
    
    /** The diameter for circles used to represent tree nodes
     */
    private int TREE_NODE_DIAMETER = 30;
      
}
