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

public class StartStopClock extends Panel {   
	private static final Color bgcolor = new Color(216,216,191);
	
	public Button button1, button2, button3;
	public ClockCanvas clockcanvas;
        public boolean IsStart, IsStop, IsReset, IsStepNew;
	
	public StartStopClock(){
		super();
		setLayout(null);
                setBackground(bgcolor);
		
                IsStart = false;
                IsStop = false;
                IsReset= true;
                IsStepNew = false;
                
                button1 = new Button("START");
                button2 = new Button("STOP");
                button3 = new Button("RESET");
                
                button1.setBounds(10,18,46,20);
		button2.setBounds(64,18,46,20);
		button3.setBounds(118,18,46,20);
                
                button1.setBackground(new Color(250,250,220));
                button2.setBackground(new Color(250,250,220));
                button3.setBackground(new Color(250,250,220));
                
                button1.setForeground(new Color(0,150,0));
                button2.setForeground(Color.red.darker());
                button3.setForeground(Color.orange.darker());
                
                button1.setFont(new Font("SanSerif",Font.BOLD,10)); 
                button2.setFont(new Font("SanSerif",Font.BOLD,10)); 
                button3.setFont(new Font("SanSerif",Font.BOLD,10)); 
                
                button1.setEnabled(true);
                button2.setEnabled(false);
                button3.setEnabled(false);
                
                clockcanvas = new ClockCanvas();
		clockcanvas.setBounds(174,4,50,50);
                
		add(button1);
		add(button2);
		add(button3);
		add(clockcanvas);				
	}
	
        public void paint(Graphics g){
		//g.draw3DRect(0,0,size().width-1,size().height-1,false);
            
            g.setColor(Color.white);
            g.fillRect(0,0,getSize().width,getSize().height);

            // Start - Stop button backgrounds
            //-------------------------START BUTTON
            
            if(IsStop){
                g.setColor(Color.black);
                MaestroG.fillCircle(34,30,38,g);
                //g.setColor(Color.green);
                g.setColor(new Color(0,200,0));
                MaestroG.fillCircle(32,28,38,g);
                g.setColor(Color.green.darker());
                MaestroG.drawCircle(32,28,38,g);
                // rectangles behind actual buttons
                g.setColor(Color.green.darker());
                g.fillRect(9,17,48,22);
            }
            else if(IsReset){
                g.setColor(Color.black);
                MaestroG.fillCircle(34,30,38,g);
                //g.setColor(Color.green);
                g.setColor(new Color(0,200,0));
                MaestroG.fillCircle(32,28,38,g);
                g.setColor(Color.green.darker());
                MaestroG.drawCircle(32,28,38,g);
                // rectangles behind actual buttons
                g.setColor(Color.green.darker());
                g.fillRect(9,17,48,22);
            }
            else if(IsStart  || IsStepNew){
                g.setColor(Color.gray);
                MaestroG.fillCircle(34,30,38,g);
                g.setColor(Color.lightGray);
                MaestroG.fillCircle(32,28,38,g);
                g.setColor(Color.gray);
                MaestroG.drawCircle(32,28,38,g);
                // rectangles behind actual buttons
                g.setColor(Color.black);
                g.fillRect(9,17,48,22);
            }
            
            //--------------------------STOP BUTTON
            
            if(IsStart){
                g.setColor(Color.black);
                MaestroG.fillCircle(88,30,38,g);
                g.setColor(Color.red);
                MaestroG.fillCircle(86,28,38,g);
                g.setColor(Color.red.darker());
                MaestroG.drawCircle(86,28,38,g);
                // rectangles behind actual buttons
                g.setColor(Color.red.darker());
                g.fillRect(63,17,48,22);
            }
            else if(IsStop || IsReset || IsStepNew){
                g.setColor(Color.gray);
                MaestroG.fillCircle(88,30,38,g);
                g.setColor(Color.lightGray);
                MaestroG.fillCircle(86,28,38,g);
                g.setColor(Color.gray);
                MaestroG.drawCircle(86,28,38,g);
                // rectangles behind actual buttons
                g.setColor(Color.black);
                g.fillRect(63,17,48,22);
            }
            //--------------------------RESET BUTTON
            
            if(IsStop || IsStepNew){
                g.setColor(Color.black);
                MaestroG.fillCircle(142,30,38,g);
                g.setColor(Color.yellow);
                MaestroG.fillCircle(140,28,38,g);
                g.setColor(Color.orange);
                MaestroG.drawCircle(140,28,38,g);
                // rectangles behind actual buttons
                g.setColor(Color.orange);
                g.fillRect(117,17,48,22);
            }
            else{
                g.setColor(Color.gray);
                MaestroG.fillCircle(142,30,38,g);
                g.setColor(Color.lightGray);
                MaestroG.fillCircle(140,28,38,g);
                g.setColor(Color.gray);
                MaestroG.drawCircle(140,28,38,g);
                // rectangles behind actual buttons
                g.setColor(Color.black);
                g.fillRect(117,17,48,22);
            }
            
        }

	
	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

