package widget;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Insets;


/**
 * The parent class of  a GUI component's/widget's view
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public abstract class  WidgetView
{

    protected Color[][]          colors;
    protected Dimension          minimumSize = new Dimension();
    protected Insets             insets = new Insets(0,0,0,0);


    public static final int DISABLED    = 0;
    public static final int FOCUSED     = 1;
    public static final int UNFOCUSED   = 2;

    public static final int BACKGROUND  = 0;
    public static final int BORDER      = 1;
    public static final int FOREGROUND  = 2;



    /**
     * Get a color for this widget/Component
     *
     * @param part   The part of the component (e.g., BORDER)
     * @param state  The state (e.g., DISABLED)
     * @return       The Color
     */
    public Color getColor(int part, int state)
    {
	Color   color;

	color = null;
	if ( (part  >= BACKGROUND) && (part <= FOREGROUND) &&
	     (state >= DISABLED)   && (part <= UNFOCUSED) ) 
        {
	    color = colors[part][state];
	}

	return color;
    }





    /**
     * Get the minimum amount of size required by this
     * component
     *
     * @return    The minimum required size
     */
    public Dimension getMinimumSize()
    {
	return minimumSize;
    }




    /**
     * Get the preferred size for this component
     *
     * @return    The minimum required size
     */
    public Dimension getPreferredSize()
    {
	return getMinimumSize();
    }



    /**
     * Get the component/Widget being controlled
     *
     * @return  The Widget
     */
    public abstract Widget getWidget();




    /**
     * Get the Insets associated with this component/Widget
     *
     * @return  The Insets
     */
    public Insets getInsets()
    {
	return insets;
    }





    /**
     * Paint this component
     *
     * @param g  The Graphics context to use
     */
    public abstract void paint(Graphics g);




    /**
     * Set a color for this widget/Component
     *
     * @param part   The part of the component (e.g., BORDER)
     * @param state  The state (e.g., DISABLED)
     * @param color  The Color
     */
    public void setColor(int part, int state, Color color)
    {
	if ( (part  >= BACKGROUND) && (part <= FOREGROUND) &&
	     (state >= DISABLED)   && (part <= UNFOCUSED) ) 
        {
	    colors[part][state] = color;
	}
    }





    /**
     * Set the colors
     *
     * @param colors  The matrix of Color objects
     */
    protected void setColors(Color[][] colors)
    {
	this.colors = colors;
    }





    /**
     * Set the height of this component/Widget
     *
     * @param height  The height (in pixels)
     */
    public void setHeight(int height)
    {
	Dimension size;
	Widget    widget;

	widget = getWidget();
	size = widget.getSize();
	widget.setSize(size.width, height);
    }





    /**
     * Set the Insets associated with this component/Widget
     *
     * @param insets  The Insets
     */
    public void setInsets(Insets insets)
    {
	this.insets = insets;
    }




    /**
     * Set the minimum size of this component/Widget
     *
     * @param width   The width (in pixels)
     * @param height  The height (in pixels)
     */
    public void setMinimumSize(int width, int height)
    {
	minimumSize.width = width;
	minimumSize.height = height;
    }





    /**
     * Set the width (in pixels) of the component
     *
     * @param width   The width
     */
    public void setWidth(int width)
    {
	Dimension size;
	Widget    widget;

	widget = getWidget();
	size = widget.getSize();
	widget.setSize(size.height, width);
    }





}
