//ObliqueInputPanel.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class ObliqueInputPanel extends Panel implements ChangeListener, ActionListener, ItemListener{
    private static final Color bgcolor = new Color(236,236,236);
    //private static final Color bgcolor = new Color(236,236,236);
    private static Font labfont = new Font("SanSerif",Font.PLAIN,12);
    private static Font labfontS = new Font("Serif",Font.PLAIN,13);
    private static Font labfontSI = new Font("Serif",Font.ITALIC,14);
    private static Font labfontB = new Font("SanSerif",Font.BOLD,17);
    private static Font labfontB2 = new Font("SanSerif",Font.BOLD,12);
    
    private static Font labfontbig=new Font("SanSerif",Font.PLAIN,14);
    private static Font labfontbigI=new Font("Serif",Font.ITALIC,14);
    private static Font titlefont=new Font("SanSerif",Font.BOLD,12);
    private static final int SCROLLMIN = 0;
    private static final int SCROLLMAX = 9001;
    Label titlelabel;	
    Label lab1, lab2, lab3, lab3b, lab4, lab5, lab6, lab7, lab8, lab9, lab10,
          labm1, labm2, labpa, labpb, labpc, labpd, labpe, labpf, 
          labr1, labr2, labr3, labr4, labHz, 
          labeqa, labeqb, labeqc, labeqd, labeqe;
    public Label labplot;
    Label vlab1;
    TextField text1, text2, text3, text4, text5, text6, text7;
    public Button b1;
    //  Buttons instead on radio buttons (which do not scale easily)    
    public Button button1, button2, button3, button4, button5, button6, button7, button8, button9;
    public Panel pbut1, pbut2, pbut3, pbut4, pbut5, pbut6, pbut7, pbut8, pbut9;
    
    public Label labscale;
    public Panel scale1, scale2;
    
    public Checkbox c1, c2, c3, c4, c5, c6, c7, c8, c9;
    public CheckboxGroup cgrp, cgrp2, cgrp3, cgfield;
    public JSlider slider, slider2, slider_scale;
    private Oblique_State state;
    public TitleCanvas title;
    
    public ObliqueInputPanel(Oblique_State state){
	super();
	this.state = state;
        
        labfont = new Font("SanSerif",Font.PLAIN,state.font12);
        labfontS = new Font("Serif",Font.PLAIN,state.font13);
        labfontSI = new Font("Serif",Font.ITALIC,state.font13);
        labfontB2 = new Font("SanSerif",Font.BOLD,state.font12);
        labfontB = new Font("SanSerif",Font.BOLD,state.font14);
        labfontbig = new Font("SanSerif",Font.PLAIN,state.font14);
        labfontbigI = new Font("Serif",Font.ITALIC,state.font14);
        titlefont = new Font("SanSerif",Font.BOLD,state.font12);
        
	setBackground(bgcolor);
	setLayout(null);
	titlelabel = new Label("Input",Label.LEFT);
	titlelabel.setFont(new Font("SanSerif",Font.BOLD,state.font16));
	titlelabel.setBounds(state.s5,state.s3,state.s45,state.s17);
        titlelabel.setForeground(Color.red.darker());
        add(titlelabel);
	//title = new TitleCanvas();
	//add(title);
	//title.setBounds(state.s2,state.s2,state.s75,state.s25);
	        
	labm1 = new Label("Medium 1",Label.RIGHT);
	labm1.setFont(labfont);
	labm1.setForeground(Color.red.darker());
        
        labm2 = new Label("Medium 2",Label.RIGHT);
	labm2.setFont(labfont);
	labm2.setForeground(Color.blue.darker());
        
	lab1 = new Label("\u03b5",Label.RIGHT);
	lab1.setFont(labfontbig);
	
	lab2 = new Label("\u03bc",Label.RIGHT);
	lab2.setFont(labfontbig);
        
        labr1 = new Label("r",Label.LEFT);
	labr1.setFont(labfont);
        labr2 = new Label("r",Label.LEFT);
	labr2.setFont(labfont);
        labr3 = new Label("r",Label.LEFT);
	labr3.setFont(labfont);
        labr4 = new Label("r",Label.LEFT);
	labr4.setFont(labfont);
        
        labeqa = new Label("=",Label.RIGHT);
	labeqa.setFont(labfontbig);
	labeqb = new Label("=",Label.RIGHT);
	labeqb.setFont(labfontbig);
        labeqc = new Label("=",Label.RIGHT);
	labeqc.setFont(labfontbig);
        labeqd = new Label("=",Label.RIGHT);
	labeqd.setFont(labfontbig);
	labeqe = new Label("=",Label.RIGHT);
	labeqe.setFont(labfontbig);
        labHz = new Label("Hz",Label.LEFT);
	labHz.setFont(labfontbig);
        
	lab3 = new Label("Incident Transverse Field",Label.LEFT);
	lab3.setFont(labfont);
	
        lab3b = new Label("Component",Label.CENTER);
	lab3b.setFont(labfont);
        
        labpa = new Label("| \u0393 | , | \u03c4 |",Label.CENTER);
	labpa.setFont(labfontS);
        labpb = new Label("|t|",Label.CENTER);
	labpb.setFont(labfontS);
        
        labpc = new Label("\u0393 , \u03c4",Label.CENTER);
	labpc.setFont(labfontS);
        labpd = new Label("tS",Label.CENTER);
	labpd.setFont(labfont);
        
        labpe = new Label("R , T",Label.CENTER);
	labpe.setFont(labfontS);
        labpf = new Label("T",Label.CENTER);
	labpf.setFont(labfontS);
        
        labplot = new Label("PLOT",Label.LEFT);
        labplot.setFont(labfont);
        
	labscale = new Label("plot-zoom",Label.RIGHT);
	labscale.setFont(labfont);
                
        text1 = new TextField("1.0");
	text1.setFont(labfont);
	
	text2 = new TextField("1.0");
	text2.setFont(labfont);
	
	text3 = new TextField("0.0");
	text3.setFont(labfont);
	
	lab4 = new Label("\u03b5",Label.RIGHT);
	lab4.setFont(labfontbig);
	
	lab5 = new Label("\u03bc",Label.RIGHT);
	lab5.setFont(labfontbig);
	
	lab6 = new Label("Conductivity  \u03c3  = ",Label.RIGHT);
	lab6.setFont(labfont);
	
        lab10 = new Label("FIELD",Label.LEFT);
	lab10.setFont(labfont);
	
        text4 = new TextField("2.55");
	text4.setFont(labfont);
	
	text5 = new TextField("1.0");
	text5.setFont(labfont);
	
	text6 = new TextField("0.0");
	text6.setFont(labfont);
	
	lab7 = new Label("f ",Label.RIGHT);
	lab7.setFont(labfont);
	
	text7 = new TextField("1.0E9");
	text7.setFont(labfont);
	
	b1 = new Button("UPDATE");
	b1.setFont(labfont);
	
        cgrp = new CheckboxGroup();
	c1 = new Checkbox("//",cgrp,true);
	c1.setFont(labfont);
	c2 = new Checkbox("\u22a5",cgrp,false);
	c2.setFont(labfont);
	
        button2 = new Button("//");
	button2.setFont(labfontB);
	button1 = new Button("\u22a5");
	button1.setFont(labfontB);
	
        cgrp2 = new CheckboxGroup();
        c3 = new Checkbox(" In ",cgrp2,true);
	c3.setFont(labfont);
	c4 = new Checkbox("Out",cgrp2,false);
	c4.setFont(labfont);
	
        button3 = new Button(" In ");
	button3.setFont(labfontB2);
	button4 = new Button("Out");
	button4.setFont(labfontB2);
	
        cgrp3 = new CheckboxGroup();
	c5 = new Checkbox("",cgrp3,true);
	c5.setFont(labfont);
	c6 = new Checkbox("",cgrp3,false);
	c6.setFont(labfont);
	c7 = new Checkbox("",cgrp3,false);
	c7.setFont(labfont);
        
        button5 = new Button("| \u0393 | , | \u03c4 |");
	button5.setFont(labfontSI);
	button6 = new Button("\u0393 ,  \u03c4");
	button6.setFont(labfontSI);
	button7 = new Button("R ,  T");
	button7.setFont(labfontSI);
	
        cgfield = new CheckboxGroup();
	c8 = new Checkbox("Electric",cgfield,true);
	c8.setFont(labfont);
	c9 = new Checkbox("Magnetic",cgfield,false);
	c9.setFont(labfont);
        
        button8 = new Button("Electric");
	button8.setFont(labfontB2);
	button9 = new Button("Magnetic");
	button9.setFont(labfontB2);
                
	lab8 = new Label("Angle of Incidence: ",Label.LEFT);
	lab8.setFont(labfont);
	
	lab9 = new Label("Polarization: ",Label.LEFT);
	lab9.setFont(labfont);

 	slider = new JSlider(SCROLLMIN,901);
	slider.setValue(450);
	slider2 = new JSlider(SCROLLMIN,1000);
	slider2.setValue(0);
        slider_scale = new JSlider(1,50);
	slider_scale.setValue(5);
	/*
 	slider = new Scrollbar(Scrollbar.HORIZONTAL,450,1,SCROLLMIN,901);
	slider2 = new Scrollbar(Scrollbar.HORIZONTAL,0,1,SCROLLMIN,1000);
        slider_scale = new Scrollbar(Scrollbar.HORIZONTAL,5,1,1,50);
	*/
        slider.setBackground(bgcolor);
        slider2.setBackground(bgcolor);
        slider_scale.setBackground(bgcolor);
        
	vlab1 = new Label("45 \u00ba",Label.LEFT);
	
	//add(titlelabel);
	add(labm1);
        add(labm2);
        add(lab1);
	add(text1);
	add(lab2);
	add(text2);
	add(lab3);
        add(lab3b);
        add(labr1); add(labr2); add(labr3); add(labr4);
        add(labeqa); add(labeqb); add(labeqc); add(labeqd); add(labeqe);
        add(labHz);
        //add(labpa); 
        add(labpb); 
        //add(labpc); 
        add(labpd); 
        //add(labpe); 
        add(labpf);
        add(labplot);
        
	//add(text3);
	add(lab4);
	add(text4);
	add(lab5);
	add(text5);
	add(lab10);
        //add(lab6);
	//add(text6);
	add(lab7);
	add(text7);
	add(b1);
        add(button1);
        add(button2);
        add(button3);
        add(button4);
        add(button5);
        add(button6);
        add(button7);
        add(button8);
        add(button9);
        
	//add(c1);
	//add(c2);
        //add(c3);
        //add(c4);
        //add(c5);
        //add(c6);
        //add(c7);
        //add(c8);
        //add(c9);
	add(lab8);
	add(lab9);
	add(slider);
        add(slider2);
        add(slider_scale);
	add(vlab1);
        
            
        //Draw the lines as panels - To avoid flickering on MAC --- MAC sucks!!!
        Panel back1 = new Panel();
	    back1.setBackground(Color.gray);
	    add(back1);
	    back1.setBounds(state.s15,state.s123,state.s200+state.s70,1);
        
        Panel back2 = new Panel();
	    back2.setBackground(Color.gray);
	    add(back2);
	    back2.setBounds(state.s15,state.s169,state.s200+state.s70,1);
       
        Panel back3 = new Panel();
	    back3.setBackground(Color.gray);
	    add(back3);
	    back3.setBounds(state.s15,state.s200+state.s20,state.s200+state.s70,1);
	
	//titlelabel.setBounds(5,25,290,25); 
	
	int ypos_block1 = state.s30;   
	text7.setBounds(state.s55,ypos_block1+state.s2,state.s75,state.s20);
	
        lab7.setBounds(state.s10,ypos_block1+state.s2,state.s25,state.s20);
        lab7.setFont(labfontbigI);
        labeqe.setBounds(state.s40,ypos_block1+state.s2,state.s15,state.s20);
        labHz.setBounds(state.s132,ypos_block1+state.s2,state.s25,state.s20);
        lab7.setForeground(Color.black);
        labeqe.setForeground(Color.black);
        labHz.setForeground(Color.black);
        
        b1.setBounds(state.s195,ypos_block1,state.s75,state.s20);
        b1.setBackground(new Color(250,250,250));
        
        Panel pb1 = new Panel();
	    pb1.setBackground(Color.cyan);
	    add(pb1);
	    pb1.setBounds(state.s195-1,ypos_block1-1,state.s75+2,state.s20+2);
	    
	Panel pb2 = new Panel();
	    pb2.setBackground(Color.black);
	    add(pb2);
	    pb2.setBounds(state.s195-2,ypos_block1-2,state.s75+4,state.s20+4);
	        
        //-----------------------------------------
	
        int ypos_block2 = state.s60;
        lab1.setBounds(state.s10,ypos_block2,state.s20,state.s20);
        labr1.setBounds(state.s30,ypos_block2+state.s5,state.s10,state.s20);
        labeqa.setBounds(state.s40,ypos_block2,state.s15,state.s20);
        lab1.setForeground(Color.red.darker());
        labr1.setForeground(Color.red.darker());
        labeqa.setForeground(Color.red.darker());
        
	text1.setBounds(state.s55,ypos_block2,state.s75,state.s20);
        text1.setForeground(Color.red.darker());
	lab2.setBounds(state.s10,ypos_block2+state.s22,state.s20,state.s20);
        labr2.setBounds(state.s30,ypos_block2+state.s28,state.s10,state.s20);
        labeqb.setBounds(state.s40,ypos_block2+state.s22,state.s15,state.s20);
        lab2.setForeground(Color.red.darker());
        labr2.setForeground(Color.red.darker());
        labeqb.setForeground(Color.red.darker());
        text2.setBounds(state.s55,ypos_block2+state.s22,state.s75,state.s20);
        text2.setForeground(Color.red.darker());
        
        labm1.setBounds(state.s55,ypos_block2+state.s44,state.s65,state.s15);
        labm2.setBounds(state.s195,ypos_block2+state.s44,state.s65,state.s15);
        lab4.setBounds(state.s150,ypos_block2,state.s20,state.s20);
        labr3.setBounds(state.s170,ypos_block2+state.s5,state.s10,state.s20);
        labeqc.setBounds(state.s180,ypos_block2,state.s15,state.s20);
        lab4.setForeground(Color.blue.darker());
        labr3.setForeground(Color.blue.darker());
        labeqc.setForeground(Color.blue.darker());
        
	text4.setBounds(state.s195,ypos_block2,state.s75,state.s20); 
	text4.setForeground(Color.blue.darker());
        lab5.setBounds(state.s150,ypos_block2+state.s22,state.s20,state.s20);
        labr4.setBounds(state.s170,ypos_block2+state.s28,state.s10,state.s20);
        labeqd.setBounds(state.s180,ypos_block2+state.s22,state.s15,state.s20);
	lab5.setForeground(Color.blue.darker());
        labr4.setForeground(Color.blue.darker());
        labeqd.setForeground(Color.blue.darker());
        text5.setBounds(state.s195,ypos_block2+state.s22,state.s75,state.s20);
        text5.setForeground(Color.blue.darker());
	//---------------------------------------------
	int ypos_block3 = state.s125;
	lab9.setBounds(state.s25,ypos_block3,state.s90,state.s15);
        lab3.setBounds(state.s130,ypos_block3,state.s160,state.s15);
        
        // CHANGE ==============================================================
        //c1.setBounds(70,ypos_block3+17,35,25);
	//c2.setBounds(30,ypos_block3+17,35,25);
	//
        //c3.setBounds(145,ypos_block3+17,37,25);
	//c4.setBounds(210,ypos_block3+17,47,25);
	//
        c1.setBounds(state.s65,ypos_block3+state.s17,state.s45,state.s25);
	c2.setBounds(state.s15,ypos_block3+state.s17,state.s45,state.s25);
	c1.setBackground(bgcolor);
	c2.setBackground(bgcolor);
	
        button2.setBounds(state.s65,ypos_block3+state.s17,state.s40,state.s20);
	button1.setBounds(state.s15,ypos_block3+state.s17,state.s40,state.s20);
        pbut2 = new Panel();
	    pbut2.setBackground(Color.black);
	    pbut2.setBounds(state.s65-1,ypos_block3+state.s17-1,state.s40+2,state.s20+2);
	pbut1 = new Panel();
	    pbut1.setBackground(Color.black);
	    pbut1.setBounds(state.s15-1,ypos_block3+state.s17-1,state.s40+2,state.s20+2);
	add(pbut2); add(pbut1);
        
	button2.setBackground(Color.white);
	button1.setBackground(Color.white);
        button2.setForeground(Color.red);
	button1.setForeground(Color.gray);
        //----------------------------------------------------------------------        
        c3.setBounds(state.s120,ypos_block3+state.s17,state.s52,state.s25);
	c3.setBackground(bgcolor);
	c4.setBounds(state.s200+state.s15,ypos_block3+state.s17,state.s52,state.s25);
	c4.setBackground(bgcolor);
        
        button3.setBounds(state.s125,ypos_block3+state.s17,state.s50,state.s20);
	button3.setBackground(Color.white);
        button3.setForeground(Color.red);
	button4.setBounds(state.s200+state.s15,ypos_block3+state.s17,state.s50,state.s20);
	button4.setBackground(Color.white);
        button4.setForeground(Color.gray);
        
        pbut3 = new Panel();
	    pbut3.setBackground(Color.black);
	    pbut3.setBounds(state.s125-1,ypos_block3+state.s17-1,state.s50+2,state.s20+2);
	pbut4 = new Panel();
	    pbut4.setBackground(Color.black);
	    pbut4.setBounds(state.s200+state.s15-1,ypos_block3+state.s17-1,state.s50+2,state.s20+2);
	add(pbut3); add(pbut4);
        
        
	//======================================================================
	//  CHANGES HERE =======================================================
	int ypos_block4 = state.s192;
        c5.setBounds(state.s140,ypos_block4+state.s3,state.s25,state.s22);
	c5.setBackground(bgcolor);
        c6.setBounds(state.s200+state.s30,ypos_block4+state.s3,state.s25,state.s22);
	c6.setBackground(bgcolor);
        c7.setBounds(state.s65,ypos_block4+state.s3,state.s25,state.s22);
	c7.setBackground(bgcolor);
        labpa.setBounds(state.s165,ypos_block4+state.s7,state.s55,state.s15); 
        labpc.setBounds(state.s200+state.s55,ypos_block4+state.s7,state.s30,state.s15); 
        labpe.setBounds(state.s90,ypos_block4+state.s7,state.s30,state.s15); 
        labplot.setBounds(state.s15,ypos_block4+state.s7,state.s42,state.s15);
        
        button5.setBounds(state.s131,ypos_block4+state.s5,state.s80,state.s20);
	button6.setBounds(state.s200+state.s20,ypos_block4+state.s5,state.s60,state.s20);
	button7.setBounds(state.s60,ypos_block4+state.s5,state.s60,state.s20);
        
        pbut5 = new Panel();
	    pbut5.setBackground(Color.black);
	    pbut5.setBounds(state.s131-1,ypos_block4+state.s5-1,state.s80+2,state.s20+2);
	pbut6 = new Panel();
	    pbut6.setBackground(Color.black);
	    pbut6.setBounds(state.s200+state.s20-1,ypos_block4+state.s5-1,state.s60+2,state.s20+2);
	pbut7 = new Panel();
	    pbut7.setBackground(Color.black);
	    pbut7.setBounds(state.s60-1,ypos_block4+state.s5-1,state.s60+2,state.s20+2);
	add(pbut5); add(pbut6); add(pbut7);
        
        button5.setBackground(Color.white);
        button6.setBackground(Color.white);
        button7.setBackground(Color.white);

        button5.setForeground(Color.red);
        button6.setForeground(Color.gray);
        button7.setForeground(Color.gray);
                    
        //======================================================================
        int ypos_block5 = state.s173;
        c8.setBounds(state.s65,ypos_block5,state.s80,state.s25);
	c8.setBackground(bgcolor);
        c8.setForeground(Color.magenta.darker());
        c9.setBounds(state.s167,ypos_block5,state.s85,state.s25);
	c9.setBackground(bgcolor);
        c9.setForeground(Color.blue);
        
        button8.setBounds(state.s75,ypos_block5,state.s90,state.s20);
	button8.setBackground(Color.white);
        button8.setForeground(Color.magenta.darker());
        button9.setBounds(state.s175,ypos_block5,state.s90,state.s20);
	button9.setBackground(Color.white);
        button9.setForeground(Color.gray);
        
        pbut8 = new Panel();
	    pbut8.setBackground(Color.black);
	    pbut8.setBounds(state.s75-1,ypos_block5-1,state.s90+2,state.s20+2);
	pbut9 = new Panel();
	    pbut9.setBackground(Color.black);
	    pbut9.setBounds(state.s175-1,ypos_block5-1,state.s90+2,state.s20+2);
	add(pbut8); add(pbut9);
        
        lab10.setBounds(state.s15, ypos_block5+state.s3, state.s45, state.s15);
        //------------------------------------------------------------------
        lab8.setBounds(state.s50,state.s200+state.s24,state.s120,state.s15);
	
        if(state.IsMac){
            slider.setBounds(state.s20+state.s14,state.s200+state.s44,state.s200+state.s60-state.s28,state.s15);
            slider2.setBounds(state.s20+state.s14,state.s200+state.s64,state.s200+state.s60-state.s28,state.s15);
        }
        else{
            slider.setBounds(state.s20,state.s200+state.s44,state.s200+state.s60,state.s15);
            slider2.setBounds(state.s20,state.s200+state.s64,state.s200+state.s60,state.s15);
        }
        
        slider_scale.setBounds(state.s195,state.s7,state.s75,state.s15);
	/*
	scale2 = new Panel();
            scale2.setBackground(Color.cyan);
            add(scale2);
            scale2.setBounds(state.s195-1,state.s7-1,state.s75+2,state.s15+2);
	scale1 = new Panel();
            scale1.setBackground(Color.black);
            add(scale1);
            scale1.setBounds(state.s195-2,state.s7-2,state.s75+4,state.s15+4);
	add(scale2); add(scale1);  
        scale1.setVisible(false);
        scale2.setVisible(false);
	*/
        labscale.setVisible(false);
        slider_scale.setVisible(false);
        
        labscale.setBounds(state.s110,state.s5,state.s80,state.s15);
        add(labscale);
        
        vlab1.setBounds(state.s180,state.s200+state.s24,state.s80,state.s15);
        vlab1.setFont(labfont);
        //======================================================================
        //Panel pslider1 = new Panel();
	    //pslider1.setBackground(new Color(200,200,200));
	    //pslider1.setBounds(state.s18,state.s200+state.s42,state.s200+state.s64,state.s38);
        //======================================================================
	/*
	Panel pslider2 = new Panel();
	    pslider2.setBackground(Color.cyan);
	    pslider2.setBounds(state.s20-1,state.s200+state.s44-1,state.s200+state.s60+2,state.s15+2);
	    
	Panel pslider1 = new Panel();
	    pslider1.setBackground(Color.black);
	    pslider1.setBounds(state.s20-2,state.s200+state.s44-2,state.s200+state.s60+4,state.s15+4);
        
        Panel pslider4 = new Panel();
	    pslider4.setBackground(Color.gray.cyan);
	    pslider4.setBounds(state.s20-1,state.s200+state.s64-1,state.s200+state.s60+2,state.s15+2);
                              
	Panel pslider3 = new Panel();
	    pslider3.setBackground(Color.black);
	    pslider3.setBounds(state.s20-2,state.s200+state.s64-2,state.s200+state.s60+4,state.s15+4);
	
        add(pslider4);
        add(pslider3);
        add(pslider2);
        add(pslider1);
	*/
	
        //Listeners 
	slider.addChangeListener(this);	
        slider2.addChangeListener(this);
        slider_scale.addChangeListener(this);
               
        b1.addActionListener(this);
        button1.addActionListener(this);
        button2.addActionListener(this);
        button3.addActionListener(this);
        button4.addActionListener(this);
        button5.addActionListener(this);
        button6.addActionListener(this);
        button7.addActionListener(this);
	button8.addActionListener(this);
        button9.addActionListener(this);
	
	c1.addItemListener(this);
	c2.addItemListener(this);
        c3.addItemListener(this);
        c4.addItemListener(this);
   }
   
    public void stateChanged(ChangeEvent evt){
	if(evt.getSource()==slider){
	    if(slider.getValue()==900){
		state.theta1 = Math.PI/2;
		vlab1.setText("90.0 \u00ba ");
		slider.setValue(900);
                slider2.setValue(0);
                slider2.setEnabled(false);
                state.ignition();
            }
	    else{
		//state.theta1 = slider.getValue()*Math.PI/1800.0;
		//vlab1.setText(""+slider.getValue()/10.0+" \u00ba ");
                state.theta1 = MaestroA.rounder(Math.PI/180.0*(slider.getValue()/10.0+MaestroA.rounder(slider2.getValue()*0.0001,4)),6);
                vlab1.setText(""+(MaestroA.rounder(slider.getValue()/10.0+MaestroA.rounder(slider2.getValue()*0.0001,4),6))+" \u00ba ");
                slider2.setEnabled(true);
                //slider2.setValue(0);
                //System.out.println("slider 1 "+MaestroA.rounder((180.0*state.theta1/Math.PI),5));
                state.ignition();
            }
	}
        if(evt.getSource()==slider2){
	    
		//state.theta1 = slider.getValue()*Math.PI/1800.0 +MaestroA.rounder(slider2.getValue()*Math.PI/180.0*0.0001,4);
		
                state.theta1 = MaestroA.rounder(Math.PI/180.0*(slider.getValue()/10.0+MaestroA.rounder(slider2.getValue()*0.0001,4)),6);
                vlab1.setText(""+(MaestroA.rounder(slider.getValue()/10.0+MaestroA.rounder(slider2.getValue()*0.0001,4),6))+" \u00ba ");
                //System.out.println("slider 2 "+MaestroA.rounder((180.0*state.theta1/Math.PI),5));
                state.ignition();
	}
	//state.ignition();
    }

    
    public void actionPerformed(ActionEvent evt){
		// CHANGE ======================================================
                // CHANGE - ADD THIS CODE ======================================
                if(evt.getSource() == button2){
                    //button2.setBackground(Color.white);
                    //button1.setBackground(Color.white);
                    button2.setForeground(Color.red);
                    button1.setForeground(Color.gray);
                    
                    state.isPolarizationParallel=true;
                    state.ignition();
                    state.scan_coefficients();
                }
                else if(evt.getSource() == button1){
                    //button1.setBackground(Color.white);
                    //button2.setBackground(Color.white);
                    button1.setForeground(Color.red);
                    button2.setForeground(Color.gray);
                    
                    state.isPolarizationParallel=false;
                    state.ignition();
                    state.scan_coefficients();
                }
                if(evt.getSource() == button3){
                    //button3.setBackground(Color.red);
                    //button4.setBackground(Color.white);
                    button3.setForeground(Color.red);
                    button4.setForeground(Color.gray);
                    state.ignition();
                    state.scan_coefficients();
                }
                else if(evt.getSource() == button4){
                    //button4.setBackground(Color.red);
                    //button3.setBackground(Color.white);
                    button4.setForeground(Color.red);
                    button3.setForeground(Color.gray);
                    
                    state.ignition();
                    state.scan_coefficients();
                }
                if(evt.getSource() == button5){
                    //button5.setBackground(Color.white);
                    //button6.setBackground(Color.white);
                    //button7.setBackground(Color.white);
                    
                    button5.setForeground(Color.red);
                    button6.setForeground(Color.gray);
                    button7.setForeground(Color.gray);
                    state.ignition();
                    state.scan_coefficients();
                }
                else if(evt.getSource() == button6){
                    //button5.setBackground(Color.white);
                    //button6.setBackground(Color.white);
                    //button7.setBackground(Color.white);
                    
                    button5.setForeground(Color.gray);
                    button6.setForeground(Color.red);
                    button7.setForeground(Color.gray);
                    
                    state.ignition();
                    state.scan_coefficients();
                }
                else if(evt.getSource() == button7){
                    //button5.setBackground(Color.white);
                    //button6.setBackground(Color.white);
                    //button7.setBackground(Color.white);
                    
                    button5.setForeground(Color.gray);
                    button6.setForeground(Color.gray);
                    button7.setForeground(Color.red);
                    
                    state.ignition();
                    state.scan_coefficients();
                }
                if(evt.getSource() == button8){
                    button8.setBackground(Color.white);
                    button9.setBackground(Color.white);
                    button8.setForeground(Color.magenta.darker());
                    button9.setForeground(Color.gray);
                    state.ignition();
                    state.scan_coefficients();
                }
                else if(evt.getSource() == button9){
                    button8.setBackground(Color.white);
                    button9.setBackground(Color.white);
                    button8.setForeground(Color.gray);
                    button9.setForeground(Color.blue);
                    
                    state.ignition();
                    state.scan_coefficients();
                }
                
                if(evt.getSource() == b1){
                  
                  if(Double.valueOf(text1.getText()).doubleValue() < 1.0){
                     text1.setText("1.0");
                  }
                  
                  
                  if(Double.valueOf(text2.getText()).doubleValue() < 1.0){
                     text2.setText("1.0");
                  }
                  
                  if(Double.valueOf(text4.getText()).doubleValue() < 1.0){
                     text4.setText("1.0");
                  }
                  
                  if(Double.valueOf(text5.getText()).doubleValue() < 1.0){
                     text5.setText("1.0");
                  }
                  
		  state.epsilon_r1=Double.valueOf(text1.getText()).doubleValue();
		  state.mu_r1=Double.valueOf(text2.getText()).doubleValue();
		  state.conductivity1=Double.valueOf(text3.getText()).doubleValue();
		  state.epsilon_r2=Double.valueOf(text4.getText()).doubleValue();
		  state.mu_r2=Double.valueOf(text5.getText()).doubleValue();
		  state.conductivity2=Double.valueOf(text6.getText()).doubleValue();
		  state.frequency=Double.valueOf(text7.getText()).doubleValue();
		}
		state.ignition();
		state.scan_coefficients();
    }
    
    public void itemStateChanged(ItemEvent evt){
	if(evt.getSource() == c1){
	    state.isPolarizationParallel=true;
	    state.ignition();
	    state.scan_coefficients();
	}
	else if(evt.getSource() == c2){
	    state.isPolarizationParallel=false;
	    state.ignition();
	    state.scan_coefficients();
	}
    }
	
    public void paint(Graphics g){
	//g.setColor(Color.black);
	//g.draw3DRect(0,0,getSize().width-1,getSize().height-1,true);
        
            //g.setColor(Color.gray);
            //g.drawLine(15,123,getSize().width-15,123);
            //g.drawLine(15,169,getSize().width-15,169);
            //g.drawLine(15,220,getSize().width-15,220);
        // CHANGE ==============================================================
        //double radiusH = 6;
        //double xpos = 265;
        //double ypos2 = 155.0;
        //double xpos2 = 190.0;
        //double ypos = 155.0;
        
        double radiusH = state.s6;
        double xpos = state.s200+state.s80;
        double ypos = (double)state.s152;
        double xpos2 = (double)state.s190;
        double ypos2 = (double)state.s152;
        //======================================================================
            Color colore;
            if(state.isPolarizationParallel){colore = Color.blue;}
            else{colore = Color.magenta.darker();}
            
            MaestroG.fillCircleThick(g, xpos, ypos, radiusH, state.s2, Color.white);
                                    
            MaestroG.drawCircleThick(g, xpos, ypos, (double)state.s1, state.s2, colore);
            MaestroG.drawCircleThick(g, xpos, ypos, radiusH, state.s2, colore);
            
            MaestroG.fillCircleThick(g, xpos2, ypos2, radiusH, state.s2, Color.white);
            MaestroG.drawLineThick(g, xpos2-(double)(radiusH/2), ypos2-(double)(radiusH/2),
                                    xpos2 + (double)(radiusH/2), ypos2 + (double)(radiusH/2), state.s1, colore);
            MaestroG.drawLineThick(g, xpos2+(double)(radiusH/2),
                                    ypos2-(double)(radiusH/2),
                                    xpos2 - (double)(radiusH/2),
                                    ypos2 + (double)(radiusH/2), state.s1,colore);
            MaestroG.drawCircleThick(g, xpos2, ypos2, radiusH, state.s2, colore);
	    slider.requestFocusInWindow();
	    slider2.requestFocusInWindow();
	    slider_scale.requestFocusInWindow();
    }
}

class TitleCanvas extends Canvas{
	
	private static final Font normalfont = new Font("Sanserif",Font.PLAIN,12);
	private static final Font subfont    = new Font("Sanserif",Font.PLAIN,10);
	private static final Font titlefont  =new Font("Sanserif",Font.BOLD,16);
	
	public TitleCanvas(){
	    super();
	}
	
	public void paint(Graphics g){
	    int x, y, dx, dxx, dy, dyy;
	    Complex temp1, temp2, ratioZ;
	    double temp3, temp4, temp5, test1, test2, test3, factor1;
	    Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            FontMetrics fm;
	    x = 10;
	    y = 20;
	    dx = 80;
	    dxx = 15;
	    g.setFont(titlefont);
            g.setColor(Color.red.darker());
	    //g.drawString("Input",20,20);
            
            
	}
    }
