//StartStopClock.java
/* A Java class for
 * LossyWide.java
 * Electromagnetic Transmission Line Applet
 * Applet without Smith Chart - Prepared by Umberto Ravaioli 
 * for 6th edition of Fundamentals of Applied Electromagnetics Book
 * May 2009 - All Rights Reserved
 */ 
import java.awt.*;

public class StartStopClock extends Panel {   
	private static final Color bgcolor = new Color(255,255,255); 
	
	public Button button1, button2;        
        public ClockCanvas clockcanvas;
        public boolean IsStop;
	Mod1State state;
        
	public StartStopClock(Mod1State state){
		super();
                this.state = state;
                
		setLayout(null);
                setBackground(bgcolor);
		IsStop = true;
		
                button1 = new Button("START");
                button2 = new Button("STOP");
                //button1.setBounds(6,20,46,20);
		//button2.setBounds(60,20,46,20);
                button1.setBounds(state.s7,state.s20,state.s58,state.s20);
		button2.setBounds(state.s73,state.s20,state.s58,state.s20);
		
                button1.setBackground(new Color(250,250,220));
                button2.setBackground(new Color(250,250,220));
                
                button1.setForeground(new Color(0,100,0));
                
                button2.setForeground(Color.red.darker());
                
                //button1.setFont(TheFonts.bold10); 
                button1.setFont(new Font("SanSerif",Font.BOLD, state.font10));
                //button2.setFont(TheFonts.bold10); 
                button2.setFont(new Font("SanSerif",Font.BOLD, state.font10));
                button1.setEnabled(true);
                button2.setEnabled(false);
                
                clockcanvas = new ClockCanvas();
		clockcanvas.setBounds(state.s138,state.s4,state.s52,state.s52);
		add(button1);
		add(button2);
		add(clockcanvas);					
	}
	
	public void paint(Graphics g){
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                           RenderingHints.VALUE_ANTIALIAS_ON);

            g.setColor(Color.white);
            g.fillRect(0,0,getSize().width,getSize().height);
            
            g.setColor(Color.black);
            g.drawRect(0,0,getSize().width-1,getSize().height-1);
            
            // Start - Stop button backgrounds
            //-------------------------START BUTTON
            
            if(IsStop){
                button1.setEnabled(true);
                button2.setEnabled(false);
                g.setColor(new Color(0,200,0));
                MaestroG.fillCircle(state.s35,state.s30,state.s38,g);
                g.setColor(Color.green.darker());
                MaestroG.drawCircle(state.s35,state.s30,state.s38,g);
                // rectangles behind actual buttons
                g.setColor(new Color(0,200,0));
                g.fillRect(state.s7-1,state.s20-1,state.s58+2,state.s20+2);
            }
            else{
                button1.setEnabled(false);
                button2.setEnabled(true);
                g.setColor(new Color(200,200,200));
                MaestroG.fillCircle(state.s35,state.s30,state.s38,g);
                g.setColor(Color.gray);
                MaestroG.drawCircle(state.s35,state.s30,state.s38,g);
                // rectangles behind actual buttons
                g.setColor(Color.black);
                g.fillRect(state.s7-1,state.s20-1,state.s58+2,state.s20+2);
            }
            
            //--------------------------STOP BUTTON
            
            if(!IsStop){
                g.setColor(Color.red);
                MaestroG.fillCircle(state.s101,state.s30,state.s38,g);
                g.setColor(Color.red.darker());
                MaestroG.drawCircle(state.s101,state.s30,state.s38,g);
                // rectangles behind actual buttons
                g.setColor(Color.red);
                g.fillRect(state.s73-1,state.s20-1,state.s58+2,state.s20+2);
            }
            else{
                g.setColor(new Color(200,200,200));
                MaestroG.fillCircle(state.s101,state.s30,state.s38,g);
                g.setColor(Color.gray);
                MaestroG.drawCircle(state.s101,state.s30,state.s38,g);
                // rectangles behind actual buttons
                g.setColor(Color.black);
                g.fillRect(state.s73-1,state.s20-1,state.s58+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
