/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
*                                                                     *
* \                                                                   *
*  |- ColorsWindow.java                                               *
*  |-  This is the class for the popup window in which the            *
*  |-  user can set the colors of various things on the page.         *
* /                                                                   *
* \                                                                   *
*  |- Author: Mike Morton                                             *
*  |- Created: Summer 1996                                            *
* /                                                                   *
* \                                                                   *
*  |- Revised on: 12/02/03                                            *
*  |- by Pavel Safronov                                               *
* /                                                                   *
* \                                                                   *
*  |- Last updated: 1/22/04                                           *
*  |- by Michael McKelvey                                             *
* /                                                                   *
*                                                                     *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

import java.awt.Frame;
import java.awt.Choice;
import java.awt.Event;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Color;

public class ColorsWindow extends Frame
{
	MagControls outerparent;
	MagPuz super_parent;
	Choice bgmagcontrols, bgmagpuz, fgmagpuz, box, outline, numbers;
	
	ColorsWindow(MagControls target)
	{
		super("Colors");
		
		this.outerparent = target;
		this.super_parent = target.outerparent;
		
		//Setup Layout
		setLayout(new GridLayout(6,2,0,0));
		
		//Setup Choice Menus
		bgmagcontrols = new Choice();
		bgmagpuz = new Choice();
		fgmagpuz = new Choice();
		box = new Choice();
		outline = new Choice();
		numbers = new Choice();
		
		add_items(bgmagcontrols);	//Add colors to the Choice Menu
		add_items(bgmagpuz);	//Add colors to the Choice Menu
		add_items(fgmagpuz);	//Add colors to the Choice Menu
		add_items(box);
		add_items(outline);
		add_items(numbers);
		
		bgmagcontrols.select("White");
		bgmagpuz.select("White");
		fgmagpuz.select("Black");
		box.select("Yellow");
		outline.select("Red");
		numbers.select("Black");
		
		//Add Labels and Menus to Control Frame
		add(new Label("BG Control: "));
		add(bgmagcontrols);
		add(new Label("FG Puzzle: "));
		add(fgmagpuz);
		add(new Label("BG Puzzle: "));
		add(bgmagpuz);
		add(new Label("Numbers: "));
		add(numbers);
		add(new Label("Box: "));
		add(box);
		add(new Label("Outline: "));
		add(outline);
	}
	
	//Add colors to a Choice Menu
	public void add_items(Choice name)
	{
		name.addItem("Black");
		name.addItem("Red");
		name.addItem("Green");
		name.addItem("Blue");
		name.addItem("White");
		name.addItem("Yellow");	
	}		
  
	//Handle Clicks.
	public boolean action(Event evt, Object arg)
	{
		if (evt.target instanceof Choice)
		{
			String col = (String)arg;
			Color theColor = Color.black;
			if(col != null)
			{
				if(col.equals("Blue")) theColor = Color.blue;
				else if (col.equals("Red")) theColor = Color.red;
				else if (col.equals("Green")) theColor = Color.green;
				else if (col.equals("Black")) theColor = Color.black;
				else if (col.equals("White")) theColor = Color.white;
				else if (col.equals("Yellow")) theColor = Color.yellow;
			
				//Check which color to update and call color_update.
				if (evt.target == bgmagcontrols)
					outerparent.updatecolor("bg", theColor);
				else if (evt.target == fgmagpuz)
					super_parent.magcan.updatecolor("fg", theColor);
				else if (evt.target == bgmagpuz)
					super_parent.magcan.updatecolor("bg", theColor);
				else if (evt.target == box)
					super_parent.magcan.updatecolor("box", theColor);
				else if (evt.target == outline)
					super_parent.magcan.updatecolor("outline", theColor);
				else if (evt.target == numbers)
					super_parent.magcan.updatecolor("numbers", theColor);
			}
		}
		
		return true;
	}

	//Might also be able to put this in the action method...
	public boolean handleEvent(Event evt)
	{
		action(evt,evt.arg);
		switch(evt.id)
		{
			case Event.WINDOW_DESTROY:
				outerparent.colors.setLabel("Show Colors Window");
				hide();
				break;
		}
		return (true);		
	}
}


