package widget;

import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Image;

/**
 * The View (from the Model-View-Controller pattern)
 * for a Button.
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public abstract class AbstractButtonView extends WidgetView
{
    protected Dimension        textSize;
    protected FontMetrics      fm;
    protected Image            disabledIcon, enabledIcon;
    protected int              arcHeight, arcWidth, horizontalTextPosition;
    protected int              mouseState, shape, verticalTextPosition;
    protected int              viewState;
    protected String           text;


    public static final int   DOWN = 0;
    public static final int   UP   = 1;



    /**
     * Default constructor
     */
    public AbstractButtonView()
    {
	this(0, 0);
    }



    /**
     * Constructor
     *
     * @param width         The width of the button (in pixels)
     * @param height        The height of the button (in pixels)
     */
    public AbstractButtonView(int width, int height)
    {
	setMinimumSize(width, height);

	viewState  = UP;
	shape = AbstractButton.RECTANGLE;

	arcHeight = 20;
	arcWidth  = 20;

	disabledIcon = null;
	enabledIcon = null;

	horizontalTextPosition  = AbstractButton.CENTER;
	verticalTextPosition    = AbstractButton.CENTER;
    }






    /**
     * Get the default icon Image associated with  the button
     *
     * @return   The Image
     */
    public Image getIcon()
    {
	return enabledIcon;
    }






    /**
     * Get the shape of this  Button
     *
     * @return  The shape
     */
    public int getShape()
    {
	return shape;
    }





    /**
     * Get the text on this Button
     *
     * @return  The text
     */
    public String getText()
    {
	return text;
    }




    /**
     * Get the view state (e.g., UP, DOWN)
     *
     * @return  The view state
     */
    public int getViewState()
    {
	return viewState;
    }





    /**
     * Paint this component
     *
     * @param g  The Graphics context to use
     */
    public abstract void paint(Graphics g);





    /**
     * Set the horizontal position of the text
     *
     * @param hpos   The horizontal position (LEFT, CENTER, RIGHT)
     */
    public void setHorizontalTextPosition(int hpos)
    {
	horizontalTextPosition = hpos;
    }






    /**
     * Set the default icon Image associated with  the button
     *
     * @param icon   The Image
     */
    public void setIcon(Image icon)
    {
	enabledIcon = icon;
    }






    /**
     * Set the state of the mouse
     *
     * @param state  The new state
     */
    /*
    public void setMouseState(int state)
    {
	AbstractButton         button;

	button = (Button)(getWidget());


	if ((state >= MOUSE_OUT) && (state <= MOUSE_UP)) {

	    mouseState = state;

	} else {

	    mouseState = MOUSE_OUT;
	}

	button.repaint();
    }
    */




    /**
     * Set the shape of this Button
     *
     * @param shape    The shape (RECTANGLE, ROUNDED_RECTANGLE)
     */
    public void setShape(int shape)
    {
	this.shape = shape;
    }




    /**
     * Set the text on this Button
     *
     * @param text    The text
     */
    public void setText(String text)
    {
	this.text = text;
    }





    /**
     * Set the size of the text on this Button
     *
     * @param size    The size of the text
     */
    public void setTextSize(Dimension size)
    {
	this.textSize = size;
    }





    /**
     * Set the vertical position of the text
     *
     * @param vpos   The vertical position (TOP, CENTER, BOTTOM)
     */
    public void setVerticalTextPosition(int vpos)
    {
	verticalTextPosition = vpos;
    }



    /**
     * Set the view state (e.g., UP, DOWN)
     *
     * @param  The viewState
     */
    public void setViewState(int viewState)
    {
	AbstractButton         button;

	button = (Button)(getWidget());
	if ((viewState >= DOWN) && (viewState <=UP))
        {
	    this.viewState = viewState;
	    button.repaint();
	}
    }




}

