//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.*;
import java.awt.event.*;
import java.lang.*;

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;
        public static Font buttonFont;
	
	public StartStopClock(){
		super();
		setLayout(null);
                setBackground(bgcolor);
		IsStop = true;
		
                button1 = new Button("START");
                button2 = new Button("STOP");

                Font buttonFont = new Font("SanSerif",Font.BOLD,10);
                button1.setFont(buttonFont); 
                button2.setFont(buttonFont); 
                FontMetrics fmSmall = getFontMetrics(buttonFont);
                int buttonWidth = fmSmall.stringWidth(" START ");
                
                button1.setBounds(6,20,46,20);
		button2.setBounds(60,20,46,20);
                //button1.setBounds(6,20,buttonWidth,20);
		//button2.setBounds(60,20,buttonWidth,20);
		
                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.setEnabled(true);
                button2.setEnabled(false);
                
                button1.setVisible(false);
                button2.setVisible(false);
                
                clockcanvas = new ClockCanvas();
		clockcanvas.setBounds(114,4,52,52);
		add(button1);
		add(button2);
		add(clockcanvas);					
	}
	
	public void paint(Graphics g){
		
            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){
                g.setColor(Color.black);
                MaestroG.fillCircle(30,32,38,g);
                //g.setColor(Color.green);
                g.setColor(new Color(0,200,0));
                MaestroG.fillCircle(28,30,38,g);
                g.setColor(Color.green.darker());
                MaestroG.drawCircle(28,30,38,g);
                button1.setEnabled(true);
                button2.setEnabled(false);
                button1.setVisible(true);
                button2.setVisible(true);
                
                // rectangles behind actual buttons
                g.setColor(Color.green.darker());
                g.fillRect(5,19,48,22);
            
            }
            else{
                g.setColor(Color.gray);
                MaestroG.fillCircle(30,32,38,g);
                g.setColor(Color.lightGray);
                MaestroG.fillCircle(28,30,38,g);
                g.setColor(Color.gray);
                MaestroG.drawCircle(28,30,38,g);
                button1.setEnabled(false);
                button2.setEnabled(true);
                button1.setVisible(true);
                button2.setVisible(true);
                // rectangles behind actual buttons
                g.setColor(Color.black);
                g.fillRect(5,19,48,22);
            
            }
            
            //--------------------------STOP BUTTON
            
            if(!IsStop){
                g.setColor(Color.black);
                MaestroG.fillCircle(84,32,38,g);
                g.setColor(Color.red);
                MaestroG.fillCircle(82,30,38,g);
                g.setColor(Color.red.darker());
                MaestroG.drawCircle(82,30,38,g);
                // rectangles behind actual buttons
                g.setColor(Color.red.darker());
                g.fillRect(59,19,48,22);
            }
            else{
                g.setColor(Color.gray);
                MaestroG.fillCircle(84,32,38,g);
                g.setColor(Color.lightGray);
                MaestroG.fillCircle(82,30,38,g);
                g.setColor(Color.gray);
                MaestroG.drawCircle(82,30,38,g);
                // rectangles behind actual buttons
                g.setColor(Color.black);
                g.fillRect(59,19,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
