import java.awt.*;

//----------------------------------------------------------------------
//Public class Controls
//----------------------------------------------------------------------
//
//Delay Time, Wave Speed, Object Speed,Observer Location (Stop point),
//plus Stop when Wave hits observer or Object hits observer. Start,Stop
public class Controls extends Canvas
{
	public int DelayTime =500;//Timer settings (milliseconds between page updates)
	int WaveSpeed = 0;	//Speed of wave in meters per second
	int ObjectSpeed = 0;//Speed of moving emitter in meters per second
	int Start = 0;		//weither or not to start/stop/reset the program 0,1 stop,start
	int ObjWave = 0;	//stop when wave or Object hits observer 0,1 object,wave
	public int ObsLoc = 500;	//Location of Observer in pixels
	public int ObsTyp = 0;
	public int ready = 0;
	
	public int x,y = 0;		//random storage varibles
	String s;
	Graphics controls;
	public Controls()
	{
		this.repaint();
	}
	public void paint(Graphics g)
	{
		Graphics control = g.create();
		control.setColor(Color.black);
		//control.drawRect(1,1,499,98);
		control.drawLine(10,2,10,100);
		control.drawLine(5,DelayTime/5,15,DelayTime/5);
		s = Integer.toString(DelayTime);
		if (DelayTime >= 500)
		{
			control.setColor(Color.red);
			s = "PAUSED!";
		}
		else s = s + " ms";
		control.drawString("Delay Time:",16,25);
		control.drawString(s,16,50);
		control.setColor(Color.black);
		//-------------OBSLOC----------
		control.drawLine(210,2,210,100);
		control.drawLine(205,ObsLoc/10,215,ObsLoc/10);
		s = "Observer Location";
		control.drawString(s,216,50);
		//------------OBSTYPE----------
		s = "Stop on Wave or Object hit";
		if (ObsTyp == 1)
			control.setColor(Color.blue);
		else control.setColor(Color.green);
		control.fillRect(405,40,10,10);
		control.drawString(s,416,50);
		//-----------RESET--------------
		s = "Restart";
		control.setColor(Color.red);
		control.fillRect(405,60,10,10);
		control.drawString(s,416,70);
		this.show();
	}

//Event Handler
	public boolean handleEvent(Event e)
	{
		//System.out.println(e);
		if((e.target == this) & ((e.id == 506) || (e.id == 501)))
		{
			//--DELAYTIME--------------
			if ((e.x <=15) & (e.x >=5))
			{
				if (e.y <= 0)
					this.DelayTime = 0;
				else
					this.DelayTime = e.y * 5;
				this.repaint();
			}
			//--OBSLOC------------------
			if ((e.x <=215) & (e.x >=205))
			{
				if (e.y <= 0)
					this.ObsLoc = 0;
				else
					this.ObsLoc = e.y * 10;
				this.repaint();
			}
			//--OBSTYP------------------
			if (((e.x <=415) && (e.x >=405)) && ((e.y <= 50) & (e.y >= 40)))
			{
				if (this.ObsTyp == 0)
					this.ObsTyp = 1;
				else this.ObsTyp = 0;
				this.repaint();
			}
			//--RESET--------------------
			if (((e.x <=415) && (e.x >=405)) && ((e.y <= 70) & (e.y >= 60)))
			{
				this.ready = 0;
				//this.repaint();
			}
			return true;
		}

		else return false;
	}
}
