import javax.swing.Icon;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Component;

/**
 * Not in image, just a numbered puzzle icon/tile.
 *
 * @author Owen Astrachan
 */

public class PlainPuzzleIcon implements Icon
{
    /**
     * Create a tile with specific label of designated
     * size.
     */
    public PlainPuzzleIcon(String label, int size)
    {
	myLabel = new String(label);
	mySize = size;
    }

    /**
     * Draws this plain icon at the proper size.
     * @param c is used to determine how big to draw this Icon
     * @param g is the graphics context in which drawing takes place
     */
    public void paintIcon(Component c, Graphics g, int x, int y)
    {
	int fillSize = c.getWidth();
	if (! myLabel.equals(PuzzleConsts.BLANK)) {
	    doPaint(g,Color.blue,Color.yellow,fillSize);
	}
	else {
	    doPaint(g,Color.yellow,Color.blue,fillSize);		    
	}
    }

    private void doPaint(Graphics g, Color background,
			 Color foreground, int fillSize)
    {
	g.setColor(background);
	g.fill3DRect(0,0,fillSize,fillSize,true);
	g.setColor(foreground);
	g.fill3DRect(PuzzleConsts.OFFSET,PuzzleConsts.OFFSET,
			 fillSize,fillSize,true);
	g.setColor(Color.black);
	g.drawString(myLabel,PuzzleConsts.OFFSET + fillSize/2,
		     PuzzleConsts.OFFSET + fillSize/2);	
    }

    /**
     * Needed for interface, not used in this project.
     */
    public int getIconHeight()
    {
	return mySize;
    }

    /**
     * Needed for interface, not used in this project.
     */
    public int getIconWidth()
    {
	return mySize;
    }

    protected String myLabel;
    protected int    mySize;    
}
