//StartStopClock.java

import java.awt.*;

public class StartStopClock extends Panel {   
	//private static final Color bgcolor = new Color(216,216,191);
	//private static final Color bgcolor = new Color(236,236,221);
        private static final Color bgcolor = new Color(180,180,180); // beige
	
	//public ImageButton button1, button2;
	public Button button1, button2;
        public boolean IsStop;        
        public ClockCanvas clockcanvas;
	PlaneWave_State state;
        
	public StartStopClock(PlaneWave_State state){
		super();
                this.state = state;
                
		setLayout(null);
                setBackground(bgcolor);
		
		button1 = new Button("START");
                button2 = new Button("STOP");
                button1.setBounds(state.s6,state.s18,state.s56,state.s20);
		button2.setBounds(state.s70,state.s18,state.s56,state.s20);
		
		button1.setBackground(Color.white);
                button2.setBackground(Color.white);
                button1.setBackground(new Color(255,255,230));
                button2.setBackground(new Color(255,255,230));
                
                button1.setForeground(Color.green.darker());
                button2.setForeground(Color.red.darker());
                button1.setFont(new Font("SanSerif",Font.BOLD,state.font10)); 
                button2.setFont(new Font("SanSerif",Font.BOLD,state.font10)); 
                
                clockcanvas = new ClockCanvas();
		clockcanvas.setBounds(state.s135,state.s2,state.s50,state.s50);
		add(button1);
		add(button2);
		add(clockcanvas);
                
                IsStop = true;
                
                button1.setEnabled(true);
                button2.setEnabled(false);
	}
	
	public void paint(Graphics g){
            g.setColor(Color.white);
            g.fillRect(0,0,getSize().width,getSize().height);
            int ypos = state.s27;
            
            // Start - Stop button
            
            //-------------------------START BUTTON
            
            if(IsStop){
                g.setColor(Color.black);
                MaestroG.fillCircle(state.s35,ypos + state.s2,state.s38,g);
                //g.setColor(Color.green);
                g.setColor(new Color(0,200,0));
                MaestroG.fillCircle(state.s33,ypos,state.s38,g);
                g.setColor(Color.green.darker());
                MaestroG.drawCircle(state.s33,ypos,state.s38,g);
                button1.setEnabled(true);
                button2.setEnabled(false);
                // rectangles behind actual buttons
                g.setColor(Color.green.darker());
                g.fillRect(state.s6-1,state.s18-1,state.s56+2,state.s20+2);
            
            }
            else{
                g.setColor(Color.gray);
                MaestroG.fillCircle(state.s35,ypos + state.s2,state.s38,g);
                g.setColor(Color.lightGray);
                MaestroG.fillCircle(state.s33,ypos,state.s38,g);
                g.setColor(Color.gray);
                MaestroG.drawCircle(state.s33,ypos,state.s38,g);
                button1.setEnabled(false);
                button2.setEnabled(true);
                // rectangles behind actual buttons
                g.setColor(Color.black);
                g.fillRect(state.s6-1,state.s18-1,state.s56+2,state.s20+2);
            
            }
            
            //--------------------------STOP BUTTON
            
            if(!IsStop){
                g.setColor(Color.black);
                MaestroG.fillCircle(state.s99,ypos + state.s2,state.s38,g);
                g.setColor(Color.red);
                MaestroG.fillCircle(state.s97,ypos,state.s38,g);
                g.setColor(Color.red.darker());
                MaestroG.drawCircle(state.s97,ypos,state.s38,g);
                // rectangles behind actual buttons
                g.setColor(Color.red.darker());
                g.fillRect(state.s70-1,state.s18-1,state.s56+2,state.s20+2);
            }
            else{
                g.setColor(Color.gray);
                MaestroG.fillCircle(state.s99,ypos + state.s2,state.s38,g);
                g.setColor(Color.lightGray);
                MaestroG.fillCircle(state.s97,ypos,state.s38,g);
                g.setColor(Color.gray);
                MaestroG.drawCircle(state.s97,ypos,state.s38,g);
                // rectangles behind actual buttons
                g.setColor(Color.black);
                g.fillRect(state.s70-1,state.s18-1,state.s56+2,state.s20+2);
            }
	}
	
	public void pause(boolean arg){
		clockcanvas.pause(arg);
	}
	
	public void start(){
		clockcanvas.start();
	}
	
	public void increment(){
		clockcanvas.increment();
	}
	
	public synchronized void setStatus(int CL_START, int CL_FINISH, int CL_DELTA){
		clockcanvas.setStatus(CL_START,CL_FINISH,CL_DELTA);
	}
	public synchronized void setSleepTime(int SleepTime){
		clockcanvas.setSleepTime(SleepTime);
	}
	public synchronized void reset(){
		clockcanvas.reset();
	}
	
}//End of StartStopClock.java
