//NewGuideControlPanel.java
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class NewGuideControlPanel extends Panel implements ActionListener{
    private static final Color bgcolor = new Color(236,236,221);
    private Color unselected = new Color(240,240,240);
    
    Label lab1, lab2;
    Choice ch1, ch2;
    public  Button about;
    public Button perpendicular, parallel;
    
    public Checkbox c1, c2, cdB;
    CheckboxGroup cgrid1;
    NewGuide_State state;
    Panel p_par, p_per;
    
    public NewGuideControlPanel(NewGuide_State state){
	super();
        this.state = state;
        
        setLayout(null);
	setBackground(bgcolor);
	about = new Button("Instructions");
	lab1 = new Label("Polarization:", Label.CENTER);
	lab1.setFont(new Font("SanSerif",Font.BOLD,state.font12));
	add(lab1);
        
        cgrid1=new CheckboxGroup();
	c1 = new Checkbox("\u22a5",cgrid1,true);	
	c2 = new Checkbox("//",cgrid1,false);
	//add(c1);
	//add(c2);
        
        // CHANGE ==============================================================
	c1.setBounds(state.s95,state.s8,state.s50,state.s20);
	c2.setBounds(state.s140,state.s8,state.s50,state.s20);
        c1.setFont(new Font("SanSerif",Font.BOLD,state.font12));
        c2.setFont(new Font("SanSerif",Font.BOLD,state.font12));
        //======================================================================
        
        perpendicular = new Button("\u22a5");
	perpendicular.setFont(new Font("SanSerif",Font.BOLD,state.font12));
        perpendicular.setBounds(state.s95,state.s8,state.s40,state.s20);
	add(perpendicular);
        
        p_per = new Panel();
	    p_per.setBackground(Color.red);
	    add(p_per);
            p_per.setBounds(state.s95-3,state.s8-3,state.s40+6,state.s20+6);
            
        parallel = new Button("//");
	parallel.setFont(new Font("SanSerif",Font.BOLD,state.font12));
	parallel.setBounds(state.s145,state.s8,state.s40,state.s20);
        add(parallel);
        
        p_par = new Panel();
	    p_par.setBackground(Color.gray.brighter());
	    add(p_par);
            p_par.setBounds(state.s145-3,state.s8-3,state.s40+6,state.s20+6);
        
        perpendicular.setForeground(Color.red);
        parallel.setForeground(Color.gray);
        perpendicular.setBackground(Color.white);
        parallel.setBackground(unselected);
        
        lab1.setBounds(state.s1,state.s10,state.s90,state.s15);
	
	// CHANGE ==============================================================
        about.setBounds(state.s195,state.s8,state.s90,state.s20);
        //======================================================================
        about.setBackground(Color.white);
        about.setFont(new Font("SanSerif",Font.PLAIN,state.font12));
        add(about);
	
        Panel p3 = new Panel();
	    p3.setBackground(Color.black);
	    add(p3);
            // CHANGE ==========================================================
            p3.setBounds(state.s195-1,state.s8-1,state.s90+2,state.s20+2);
            //==================================================================
            
        perpendicular.addActionListener(this);
        parallel.addActionListener(this);
    }
    
    public void paint(Graphics g){
	g.setColor(bgcolor.darker());
	g.fillRect(0,getSize().height-2,getSize().width,2);
	g.fillRect(getSize().width-2,0,2,getSize().height);
	g.setColor(bgcolor.brighter());
	g.fillRect(0,0,2,getSize().height-1);
	g.fillRect(0,0,getSize().width-2,2);
    }
    
    public void actionPerformed(ActionEvent evt){
                // CHANGE - ADD THIS CODE ======================================
                if(evt.getSource() == parallel){
                    parallel.setForeground(Color.red);
                    perpendicular.setForeground(Color.gray);
                    
                    parallel.setBackground(Color.white);
                    perpendicular.setBackground(unselected);
                    
                    p_par.setBackground(Color.red);
                    p_per.setBackground(Color.gray.brighter());
                    
                    state.IsTE = false;
                    state.ignition();
                    state.scan_coefficients();
                }
                else if(evt.getSource() == perpendicular){
                    perpendicular.setForeground(Color.red);
                    parallel.setForeground(Color.gray);
                    
                    perpendicular.setBackground(Color.white);
                    parallel.setBackground(unselected);
                    
                    p_per.setBackground(Color.red);
                    p_par.setBackground(Color.gray.brighter());
                    
                    state.IsTE = true;
                    state.ignition();
                    state.scan_coefficients();
                }
    }
    
}