package Nodepad;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * ListNode.java
 *
 *
 * Created: Fri Feb 21 08:18:54 2003
 *
 * @author <a href="mailto:shapiro@cse.buffalo.edu">Stuart C. Shapiro</a>
 */

public class ListNode extends ParentNode{
    private PointerCell pcell;

    /**
     * Creates a bordered Node, with a given Pad, location, and value.
     *
     * @param p the Pad this node is on.
     * @param x the x value of this node's initial location.
     * @param y the y value of this node's initial location.
     * @param v the integer value of this node.
     */
    public ListNode (Pad p, int x, int y, int v){
	super(p, x, y, v);
	pcell = new PointerCell(p, x+getWidth(), y, Pointer.width+6, getHeight());
	pad.add(pcell);
	this.setBorder(BorderFactory.createLineBorder(Color.black,1));
    }

    public int getTotalWidth() {
	return getWidth() + pcell.getTotalWidth();
    }

    /**
     * Paints this node as a rectangle with its value centered inside.
     *
     * @param g the Graphics component of this node.
     */
    public void paintComponent(Graphics g) {
	setSize(size);
	setLocation(locpt);
	g.setColor(Color.black);
	//Draw the label, centered, twice the size of the standard font.
	{Font currFont = g.getFont();
	g.setFont(currFont.deriveFont(2*currFont.getSize2D()));}
	g.drawString(label,
		     (size.width - g.getFontMetrics().stringWidth(label))/2,
		     30);
    }

    /**
     * Terminates cursor following.
     */
    public void mouseReleased (MouseEvent evt){
	shouldmove = false;
	if (this.getBounds().contains(evt.getX(), evt.getY())
	    && !pad.getMovingNodes()) {
	    value = pad.getAcc();
	    label = "" + value;
	    repaint();
	}    }

    /**
     * Moves this node to a new location.
     * 
     * @param x the new x location.
     * @param y the new y location.
     */
    protected void moveTo(int x, int y){
	super.moveTo(x,y);
	pcell.moveTo(x+getWidth(), y);
    }
    
}// ListNode
