/*
	PointsPanel.java
	by Richard Unger, March 1998

	This class is purely for user interface stuff - the control panel that
	contains the controls dealing with points and their placement as well
	as the view in general.
*/

import java.awt.*;
import java.awt.event.*;

public class PointsPanel extends Panel{

// UI elements
	Checkbox addBox;
	Checkbox selectBox;
	CheckboxGroup toggler;
	Button deleteButton;
	Button deleteAllButton;
	Button seedButton;
	TextField seedText;
	GridBagLayout theLay;
	

	public PointsPanel(CommandParser commands){
		super();

		theLay = new GridBagLayout();
		setLayout(theLay);
	
		toggler = new CheckboxGroup();

		selectBox = new TalkerCheckbox("Select Points",false,toggler){ 
			public String talkCommand(){
				if (getState())
					return "set SELECTMODE true";
				else
					return "set SELECTMODE false";
				}
			};
		add(selectBox,0,0,2,1);
		selectBox.addItemListener(commands);
		
		addBox = new TalkerCheckbox("Add Points",true,toggler){
			public String talkCommand(){
				if (getState())
					return "set SELECTMODE false";
				else
					return "set SELECTMODE true";
				}
			};
		add(addBox,0,1,2,1);
		addBox.addItemListener(commands);

		deleteButton = new Button("Delete");
		add(deleteButton,0,2,2,1);
		deleteButton.setActionCommand("delete sel");
		deleteButton.addActionListener(commands);
		
		seedButton = new Button("Add Random:"){
			protected void processActionEvent(ActionEvent e){
				setActionCommand("add random "+seedText.getText());
				super.processActionEvent(e);
				}
			};
		add(seedButton,2,0,1,1);
		seedButton.addActionListener(commands);
		
		seedText = new TextField("25",4);
		add(seedText,3,0,1,1);
		
		deleteAllButton = new Button("Clear All Points");
		add(deleteAllButton,2,2,2,1);
		deleteAllButton.setActionCommand("delete all");
		deleteAllButton.addActionListener(commands);
		
		}
		
		
	public void add(Component what,int gridx,int gridy,int wid,int high,int wx,int wy,int anc,int fill){
		GridBagConstraints c = new GridBagConstraints();
		c.gridx=gridx;
		c.gridy=gridy;
		c.gridwidth=wid;
		c.gridheight=high;
		c.weightx=wx;
		c.weighty=wy;
		c.anchor=anc;
		c.fill=fill;
		theLay.setConstraints(what,c);		//set constraints
		add(what);							//add it to panel
		}
	public void add(Component what,int gridx,int gridy,int wid,int high){
		add(what,gridx,gridy,wid,high,100,100,GridBagConstraints.WEST,GridBagConstraints.NONE);
		}
		
	
}


/*
Commands emitted by the points panel...

delete sel
delete all
add random <int>
set SELECTMODE <bool>

*/