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

                Font buttonFont = new Font("SanSerif",Font.BOLD,state.font9);
                button1.setFont(buttonFont); 
                button2.setFont(buttonFont); 
                FontMetrics fmSmall = getFontMetrics(buttonFont);
                int buttonWidth = fmSmall.stringWidth(" START ");
                
                button1.setBounds(state.s6,state.s20,state.s46,state.s20);
		button2.setBounds(state.s60,state.s20,state.s46,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.setEnabled(true);
                button2.setEnabled(false);
                
                button1.setVisible(false);
                button2.setVisible(false);
                
                clockcanvas = new ClockCanvas();
		clockcanvas.setBounds(state.s114,state.s4,state.s52,state.s52);
		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(state.s30,state.s32,state.s38,g);
                //g.setColor(Color.green);
                g.setColor(new Color(0,200,0));
                MaestroG.fillCircle(state.s28,state.s30,state.s38,g);
                g.setColor(Color.green.darker());
                MaestroG.drawCircle(state.s28,state.s30,state.s38,g);
                button1.setEnabled(true);
                button2.setEnabled(false);
                button1.setVisible(true);
                button2.setVisible(true);
                
                // rectangles behind actual buttons
                g.setColor(Color.green.darker());
                g.fillRect(state.s6-1,state.s20-1,state.s46+2,state.s20+2);
            
            }
            else{
                g.setColor(Color.gray);
                MaestroG.fillCircle(state.s30,state.s32,state.s38,g);
                g.setColor(Color.lightGray);
                MaestroG.fillCircle(state.s28,state.s30,state.s38,g);
                g.setColor(Color.gray);
                MaestroG.drawCircle(state.s28,state.s30,state.s38,g);
                button1.setEnabled(false);
                button2.setEnabled(true);
                button1.setVisible(true);
                button2.setVisible(true);
                // rectangles behind actual buttons
                g.setColor(Color.black);
                g.fillRect(state.s6-1,state.s20-1,state.s46+2,state.s20+2);
            }
            
            //--------------------------STOP BUTTON
            
            if(!IsStop){
                g.setColor(Color.black);
                MaestroG.fillCircle(state.s84,state.s32,state.s38,g);
                g.setColor(Color.red);
                MaestroG.fillCircle(state.s82,state.s30,state.s38,g);
                g.setColor(Color.red.darker());
                MaestroG.drawCircle(state.s82,state.s30,state.s38,g);
                // rectangles behind actual buttons
                g.setColor(Color.red.darker());
                g.fillRect(state.s60-1,state.s20-1,state.s46+2,state.s20+2);
            }
            else{
                g.setColor(Color.gray);
                MaestroG.fillCircle(state.s84,state.s32,state.s38,g);
                g.setColor(Color.lightGray);
                MaestroG.fillCircle(state.s82,state.s30,state.s38,g);
                g.setColor(Color.gray);
                MaestroG.drawCircle(state.s82,state.s30,state.s38,g);
                // rectangles behind actual buttons
                g.setColor(Color.black);
                g.fillRect(state.s60-1,state.s20-1,state.s46+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
