/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
*                                                                     *
* \                                                                   *
*  |- MagControls.java                                                *
*  |-  This class defines the control panel, from which the           *
*  |-  user can open up the ColorsWindow, set a block's number, or    *
*  |-  set the number of rows/columns in the magic square.            *
* /                                                                   *
* \                                                                   *
*  |- 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.Panel;
import java.awt.Font;
import java.awt.Choice;
import java.awt.TextField;
import java.awt.Button;
import java.awt.Frame;
import java.awt.Color;
import java.awt.Event;
import java.awt.Label;
import java.awt.TextArea;


public class MagControls extends Panel
{
	MagPuz outerparent;
	Font control_font;
	Choice level;
	TextField number = new TextField(10);
	Button colors;
	ColorsWindow colors_window;
	Color fgcontrols, bgcontrols;

	String comments =
	"This is an Applet created by Michael W.S. Morton for the Math Forum. Any \n" +
	"pieces of code may be used only with consent of the Math Forum. The \n" +
	"instructions for this Magic Square are at: \n" +
	"http://mathforum.org/workshops/sum96/magic.squares.html \n" +
	"This Applet is still under construction, and I would appreciate any \n" +
	"comments/suggestions; please send to Suzanne Alejandre: \n"+
	"\t\tsuzanne@mathforum.org. \n"+
	"Enjoy.";

	MagControls(MagPuz target)
	{
		this.outerparent = target;

		//Setup Colors
		fgcontrols = Color.black;
		bgcontrols = Color.white;
		setBackground(bgcontrols);

		//Trying to set Font for Controls
		control_font = new Font("TimesRoman", Font.PLAIN, 20);

		//Setup Choice Menu
		level = new Choice();
		level.addItem("3");
		level.addItem("4");
		level.addItem("5");
		level.addItem("6");
		level.addItem("7");
		level.select("3");

		//Add Label + Choice Menu
		add(new Label("Level: "));
		add(level);

		//Setup Textfield
		add(new Label("Number of Selected Box: "));
		add(number);

		//Setup Buttons
		colors = new Button("Show Colors Window");
		add(colors);

		//Setup Colors Window
		colors_window = new ColorsWindow(this);
		colors_window.setSize(200,300);

		// Add comments
//		add(new TextArea(comments,10,50));

	}

	//Handle Clicks.
	public boolean action(Event evt, Object arg)
	{
		if (evt.target instanceof Choice)
		{
			//Check if level is clicked, and call the update_level function in the
			// JamCan class.
			if (evt.target == level)
			{
				outerparent.magcan.update_level((level.getSelectedIndex()) + 3);
			}
		}
		
		if (evt.target instanceof TextField)
		{
			outerparent.magcan.update_number(Integer.parseInt(number.getText()));
		}
		
		if (evt.target instanceof Button)
		{
			if(evt.target == colors)
			{
				if(colors.getLabel().equals("Show Colors Window"))
				{
					colors_window.show();
					colors.setLabel("Hide Colors Window");
				}
				else if(colors.getLabel().equals("Hide Colors Window"))
				{
					colors_window.hide();
					colors.setLabel("Show Colors Window");
				}
			}
		}
		return true;
	}

	void updatecolor(String choice, Color col)
	{
		if(choice.equals("fg"))
			fgcontrols = col;
		else if(choice.equals("bg"))
			bgcontrols = col;

		setBackground(bgcontrols);

		repaint();
	}
}