package Nodepad; import java.awt.*; import java.awt.event.*; import javax.swing.*; /** * GhostNode.java * * * Created: Mon Dec 30 13:56:15 2002 * * @author Stuart C. Shapiro * @version * * An unbordered, integer-valued node * that can be moved from one Node to another. */ public class GhostNode extends ParentNode { /** * Creates a GhostNode, 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 GhostNode (Pad p, int x, int y, int v){ super(p, x, y, v); // A GhostNode is only created to drag it somewhere. shouldmove = true; } /** * Paints this node as just a value. * * @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); } /** * Deletes this GhostNode when it's no longer being dragged. */ public void mouseReleased (MouseEvent evt){ pad.removeMouseListener(this); pad.removeMouseMotionListener(this); pad.remove(this); pad.repaint(getBounds()); } }// GhostNode