//ObliqueInputPanel.java
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
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 Font labfont;
    private Font labfontS;
    private Font labfontbig;
    private Font labfontbigI;
    private Font labfontbigI2;
    private Font titlefont;
    private static final int SCROLLMIN = 0;
    private static final int SCROLLMAX = 9001;
    Label titlelabel;	
    Label lab1, lab2, lab3, lab1B, lab2B, lab3B, lab4,lab7, lab8, labm1, labm2, labm3, labpa, labpb, labpc, labpd,  
          labr1, labr2, labr3, labr1B, labr2B, labr3B, labHz, labM, 
          labeqa, labeqb, labeqc, labeqd, labeqR;
    Label vlab1, vlab2, vlab3;
    public TextField text1, text2, text3, text1b, text2b, text3b, text4, text7;
    Button b1;
    public Label labscale;
    public Panel scale1, scale2;
    public CheckboxGroup cgrid1;
    public Checkbox c1, c2;
    
    public JSlider slider, slider2, slider_scale;
    // CHANGE ==============================================================
        public Button b_epsilon, b_index;
        public Panel p_epsilon, p_index;
    //======================================================================
    private Oblique_State state;
    public TitleCanvas title;
    
    public ObliqueInputPanel(Oblique_State state){
	super();
	this.state = state;
	setBackground(bgcolor);
	setLayout(null);
        
        labfont = new Font("SanSerif",Font.PLAIN,state.font12);
        labfontS = new Font("Serif",Font.PLAIN,state.font14);
        labfontbig = new Font("SanSerif",Font.PLAIN,state.font14);
        labfontbigI = new Font("Serif",Font.ITALIC,state.font14);
        labfontbigI2 = new Font("Serif",Font.ITALIC,state.font16);
        titlefont = new Font("SanSerif",Font.BOLD,state.font12);
        
	titlelabel = new Label("Input",Label.CENTER);
	titlelabel.setFont(titlefont);
	
	title = new TitleCanvas(state);
	add(title);
	title.setBounds(state.s10,state.s2,state.s50,state.s55);
        
        //  Medium Labels
	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());
        
        labm3 = new Label("medium 3",Label.RIGHT);
	labm3.setFont(labfont);
	labm3.setForeground(Color.black);
        
        cgrid1=new CheckboxGroup();
        c1 = new Checkbox(" \u03b5 ",cgrid1,true);	
        c2 = new Checkbox(" n ",cgrid1,false);
        c1.setFont(labfontbig);
        c2.setFont(labfontbig);
                
        //--------------------------------------------------------
        // epsilon labels
	lab1 = new Label("\u03b5",Label.RIGHT);
	lab1.setFont(labfontbig);
	
	lab2 = new Label("\u03b5",Label.RIGHT);
	lab2.setFont(labfontbig);
        
        lab3 = new Label("\u03b5",Label.RIGHT);
	lab3.setFont(labfontbig);
        
        lab1B = new Label("n",Label.RIGHT);
	lab1B.setFont(labfontbig);
	
	lab2B = new Label("n",Label.RIGHT);
	lab2B.setFont(labfontbig);
        
        lab3B = new Label("n",Label.RIGHT);
	lab3B.setFont(labfontbig);
        
        lab4 = new Label("R",Label.RIGHT);
	lab4.setFont(labfontbig);
	
        labr1 = new Label("r0",Label.LEFT);
	labr1.setFont(labfont);
        labr2 = new Label("rf",Label.LEFT);
	labr2.setFont(labfont);
        labr3 = new Label("rc",Label.LEFT);
	labr3.setFont(labfont);
        
        labr1B = new Label("0",Label.LEFT);
	labr1B.setFont(labfont);
        labr2B = new Label("f ",Label.LEFT);
	labr2B.setFont(labfontS);
        labr3B = new Label("c",Label.LEFT);
	labr3B.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);
        labeqR = new Label("=",Label.RIGHT);
	labeqR.setFont(labfontbig);
        labM = new Label("m",Label.LEFT);
	labM.setFont(labfontbig);
	labHz = new Label("Hz",Label.LEFT);
	labHz.setFont(labfontbig);
        //---------------------------------------------------------
	//  Inputs for epsilon
        text1 = new TextField("1.0");
	text1.setFont(labfont);
	
	text2 = new TextField("2.55");
	text2.setFont(labfont);
	
	text3 = new TextField("2.40");
	text3.setFont(labfont);
	
        //---------------------------------------------------------
	//  Inputs for index of refraction n
        text1b = new TextField(""+MaestroA.rounder(state.index1,6));
	text1b.setFont(labfont);
	
	text2b = new TextField(""+MaestroA.rounder(state.index2,6));
	text2b.setFont(labfont);
	
	text3b = new TextField(""+MaestroA.rounder(state.index3,6));
	text3b.setFont(labfont);
        //-------------------------------------- frequency
	lab7 = new Label("f ",Label.RIGHT);
	lab7.setFont(labfontS);
	
	text7 = new TextField("350.0E12");
	text7.setFont(labfont);
        //-------------------------------------- radius
	lab4 = new Label("R",Label.RIGHT);
	lab4.setFont(labfont);
	
	text4 = new TextField("100.0E-6");
	text4.setFont(labfont);
        
	//-------------------------------------- Update
	b1 = new Button("Update");
	//------------------------------------------------
	
        // use button instead of radio buttons
        b_epsilon = new Button(" \u03b5 ");
        b_epsilon.setBackground(Color.white);        
        b_epsilon.setFont(labfontbig);
        
        b_index = new Button(" n ");
        b_index.setBackground(Color.white);        
        b_index.setFont(labfontbig);
        //======================================================================
        // Sliders
	lab8 = new Label("Angle of Entrance: ",Label.LEFT);
	lab8.setFont(labfont);

	slider = new JSlider(SCROLLMIN,1801);
	slider.setValue(1020);
	slider2 = new JSlider(SCROLLMIN,1999);
	//slider = new Scrollbar(Scrollbar.HORIZONTAL,1020,1,SCROLLMIN,1801);
        //slider2 = new Scrollbar(Scrollbar.HORIZONTAL,0,1,SCROLLMIN,1999);
        slider2.setValue(999);
	slider_scale = new JSlider(1,50);
	slider_scale.setValue(5);
        //slider_scale = new Scrollbar(Scrollbar.HORIZONTAL,5,1,1,50);
        slider.setBackground(bgcolor);
        slider2.setBackground(bgcolor);
        slider_scale.setBackground(bgcolor);
        
	vlab1 = new Label("\u03b8",Label.RIGHT);
        vlab1.setFont(labfontbig);
        vlab2 = new Label("i",Label.LEFT);
        vlab2.setFont(labfontbig);
        vlab3 = new Label(" = 12 \u00ba",Label.LEFT);
        vlab3.setFont(labfontbig);
	//----------------------------------------------------------
	//add(titlelabel);
	add(labm1);
        add(labm2);
        add(labm3);
        add(lab1);
	add(text1); add(text1b);
	add(lab2);
	add(text2); add(text2b);
	add(lab3);
        add(labr1); add(labr2); add(labr3); add(labr1B); add(labr2B); add(labr3B); 
        add(labeqa); add(labeqb); add(labeqc); add(labeqd); add(labeqR);
        add(labHz); add(labM);
        
	add(text3); add(text3b); add(text4);
	add(lab7); add(lab4);
	add(text7);
	add(b1);
	add(lab8);
	add(slider);
        add(slider2);
        add(slider_scale);
	add(vlab1);
       	add(vlab2);
       	add(vlab3);
        
        //add(c1); add(c2);
        add(lab1B); add(lab2B); add(lab3B);
        lab1B.setVisible(false);
        lab2B.setVisible(false);
        lab3B.setVisible(false);
        
        // input for epsilon 1
        int xpos_block2 = state.s70;
        int ypos_block2 = state.s10;
        lab1.setBounds(xpos_block2,ypos_block2,state.s20,state.s20);
        lab1B.setBounds(xpos_block2+5,ypos_block2,state.s20,state.s20);
        labr1.setBounds(xpos_block2+state.s20,ypos_block2+state.s5,state.s15,state.s20);
        labr1B.setBounds(xpos_block2+state.s25,ypos_block2+state.s5,state.s15,state.s20);
        labeqa.setBounds(xpos_block2+state.s37,ypos_block2,state.s15,state.s20);
        lab1.setForeground(Color.red.darker());
        lab1B.setForeground(Color.red.darker());
        labr1.setForeground(Color.red.darker());
        labr1B.setForeground(Color.red.darker());
        labeqa.setForeground(Color.red.darker());
        
	text1.setBounds(xpos_block2+state.s55,ypos_block2,state.s75,state.s20);
        text1.setForeground(Color.red.darker());
        
        text1b.setBounds(xpos_block2+state.s55,ypos_block2,state.s75,state.s20);
        text1b.setForeground(Color.red.darker());
        Panel ptext1b = new Panel();
	    ptext1b.setBackground(Color.black);
	    add(ptext1b);
	    ptext1b.setBounds(xpos_block2+state.s55-1,ypos_block2-1,state.s75+2,state.s20+2);
        
        //----------------------------------------------------------------------
        // input for epsilon 2
        int xpos_block3 = state.s200+state.s30;
        int ypos_block3 = state.s10;
	lab2.setBounds(xpos_block3,ypos_block3,state.s20,state.s20);
        lab2B.setBounds(xpos_block3+6,ypos_block3,state.s20,state.s20);
        labr2.setBounds(xpos_block3+state.s20,ypos_block3+state.s5,state.s15,state.s20);
        labr2B.setBounds(xpos_block3+state.s25,ypos_block3+state.s5,state.s20,state.s25);
        labeqb.setBounds(xpos_block3+state.s37,ypos_block3,state.s15,state.s20);
        lab2.setForeground(Color.blue.darker());
        lab2B.setForeground(Color.blue.darker());
        labr2.setForeground(Color.blue.darker());
        labr2B.setForeground(Color.blue.darker());
        labeqb.setForeground(Color.blue.darker());
        
        text2.setBounds(xpos_block3+state.s55,ypos_block3,state.s75,state.s20);
        text2.setForeground(Color.blue.darker());
        
        text2b.setBounds(xpos_block3+state.s55,ypos_block3,state.s75,state.s20);
        text2b.setForeground(Color.blue.darker());
        Panel ptext2b = new Panel();
	    ptext2b.setBackground(Color.black);
	    add(ptext2b);
	    ptext2b.setBounds(xpos_block3+state.s55-1,ypos_block3-1,state.s75+2,state.s20+2);
        //----------------------------------------------------------------------
        // input for epsilon 3
        int xpos_block4 = state.s300+state.s90;
        int ypos_block4 = state.s10;
        lab3.setBounds(xpos_block4,ypos_block4,state.s20,state.s20);
        lab3B.setBounds(xpos_block4+state.s5,ypos_block4,state.s20,state.s20);
        labr3.setBounds(xpos_block4+state.s20,ypos_block4+state.s5,state.s15,state.s20);
        labr3B.setBounds(xpos_block4+state.s25,ypos_block4+state.s5,state.s15,state.s20);
        labeqc.setBounds(xpos_block4+state.s37,ypos_block4,state.s15,state.s20);
        lab3.setForeground(Color.black.darker());
        lab3B.setForeground(Color.black.darker());
        labr3.setForeground(Color.black.darker());
        labr3B.setForeground(Color.black.darker());
        labeqc.setForeground(Color.black.darker());
        
        text3.setBounds(xpos_block4+state.s55,ypos_block4,state.s75,state.s20);
        text3.setForeground(Color.black.darker());
        
        text3b.setBounds(xpos_block4+state.s55,ypos_block4,state.s75,state.s20);
        text3b.setForeground(Color.black.darker());
        Panel ptext3b = new Panel();
	    ptext3b.setBackground(Color.black);
	    add(ptext3b);
	    ptext3b.setBounds(xpos_block4+state.s55-1,ypos_block4-1,state.s75+2,state.s20+2);
        
        // CHANGE ==============================================================
        c1.setBounds(xpos_block4+state.s140,ypos_block4-state.s5,state.s50,state.s30);
	c2.setBounds(xpos_block4+state.s140,ypos_block4+state.s25,state.s50,state.s30);
        //======================================================================
	c1.setBackground(bgcolor);
	c2.setBackground(bgcolor);
        
        b_epsilon.setBounds(xpos_block4+state.s150,ypos_block4,state.s40,state.s20);
	b_index.setBounds(xpos_block4+state.s150,state.s40,state.s40,state.s20);
        // Around update button
        p_epsilon = new Panel();
	    p_epsilon.setBackground(Color.red);
	    p_epsilon.setBounds(xpos_block4+state.s150-3,ypos_block4-3,state.s40+6,state.s20+6);
	    
	p_index = new Panel();
	    p_index.setBackground(Color.gray.brighter());
	    p_index.setBounds(xpos_block4+state.s150-3,state.s40-3,state.s40+6,state.s20+6);
        
        add(b_epsilon); add(b_index);
        add(p_epsilon); add(p_index);
        
        //----------------------------------------------------------------------
        // Positon frequency and radius input
	int xpos_block0 = state.s125;
        int ypos_block0 = state.s40;   
	text7.setBounds(xpos_block0,ypos_block0,state.s75,state.s20);
        Panel ptext7 = new Panel();
	    ptext7.setBackground(Color.black);
	    add(ptext7);
	    ptext7.setBounds(xpos_block0-1,ypos_block0-1,state.s75+2,state.s20+2);
        
        lab7.setBounds(xpos_block0-state.s45,ypos_block0,state.s20,state.s20);
        lab7.setFont(labfontbigI);
        labeqd.setBounds(xpos_block0-state.s18,ypos_block0,state.s15,state.s20);
	labeqd.setForeground(Color.black);
        labHz.setBounds(xpos_block0+state.s77,ypos_block0,state.s25,state.s20);
        lab7.setForeground(Color.black);
        labHz.setForeground(Color.black);
        
        int xpos_blockR = state.s200+state.s85;
        int ypos_blockR = state.s40;
        text4.setBounds(xpos_blockR,ypos_blockR,state.s75,state.s20);
	Panel ptext4 = new Panel();
	    ptext4.setBackground(Color.black);
	    add(ptext4);
	    ptext4.setBounds(xpos_blockR-1,ypos_blockR-1,state.s75+2,state.s20+2);
        
        lab4.setBounds(xpos_blockR-state.s45,ypos_blockR,state.s20,state.s20);
        lab4.setFont(labfontbigI);
        labeqR.setBounds(xpos_blockR-state.s18,ypos_blockR,state.s15,state.s20);
	labeqR.setForeground(Color.black);
        labM.setBounds(xpos_blockR+state.s77,ypos_blockR,state.s25,state.s20);
        lab4.setForeground(Color.black);
        labM.setForeground(Color.black);
        //----------------------------------------------------------------------
        // Positon update button
        int xpos_block5 = state.s400+state.s45;
        int ypos_block5 = state.s40;
        b1.setBounds(xpos_block5,ypos_block5,state.s75,state.s20);
        b1.setBackground(new Color(250,250,250));
        
        // Around update button
        Panel pb1 = new Panel();
	    pb1.setBackground(Color.cyan);
	    add(pb1);
	    pb1.setBounds(xpos_block5-1,ypos_block5-1,state.s75+2,state.s20+2);
	    
	Panel pb2 = new Panel();
	    pb2.setBackground(Color.black);
	    add(pb2);
	    pb2.setBounds(xpos_block5-2,ypos_block5-2,state.s75+4,state.s20+4);
        //----------------------------------------------------------------------
        //  input for angle
        
        int xpos_block6 = state.s600+state.s10;
        int ypos_block6 = state.s25;
        
	lab8.setBounds(xpos_block6+state.s30,ypos_block6-state.s20,state.s120,state.s14);
	vlab1.setBounds(xpos_block6+state.s160,ypos_block6-state.s22,state.s15,state.s14);
        vlab2.setBounds(xpos_block6+state.s175,ypos_block6-state.s17,state.s8,state.s14);
        vlab3.setBounds(xpos_block6+state.s184,ypos_block6-state.s20,state.s110,state.s14);
        
        if(state.IsMac){
            slider.setBounds(xpos_block6+state.s14,ypos_block6,state.s200+state.s60-state.s28,state.s15);
            slider2.setBounds(xpos_block6+state.s14,ypos_block6+state.s21,state.s200+state.s60-state.s28,state.s15);
        }
        else{
            slider.setBounds(xpos_block6,ypos_block6,state.s200+state.s60,state.s15);
            slider2.setBounds(xpos_block6,ypos_block6+state.s21,state.s200+state.s60,state.s15);
        }
        
        /*
	Panel pslider2 = new Panel();
	    pslider2.setBackground(Color.cyan);
	    add(pslider2);
	    pslider2.setBounds(xpos_block6-1,ypos_block6-1,state.s200+state.s60+2,state.s15+2);
	    
	Panel pslider1 = new Panel();
	    pslider1.setBackground(Color.black);
	    add(pslider1);
	    pslider1.setBounds(xpos_block6-2,ypos_block6-2,state.s200+state.s60+4,state.s15+4);
	
        Panel pslider4 = new Panel();
	    pslider4.setBackground(Color.cyan);
	    add(pslider4);
	    pslider4.setBounds(xpos_block6-1,ypos_block6+state.s21-1,state.s200+state.s60+2,state.s15+2);
	    
	Panel pslider3 = new Panel();
	    pslider3.setBackground(Color.black);
	    add(pslider3);
	    pslider3.setBounds(xpos_block6-2,ypos_block6+state.s21-2,state.s200+state.s60+4,state.s15+4);
	*/
        //----------------------------------------------------------------------
	//Listeners 
	slider.addChangeListener(this);	
        slider2.addChangeListener(this);
        c1.addItemListener(this);
	c2.addItemListener(this);
        b1.addActionListener(this);
        b_epsilon.addActionListener(this);
	b_index.addActionListener(this);
	
   }
   
    public void stateChanged(ChangeEvent evt){
	if(evt.getSource()==slider){
	    if(state.epsilon_r1 == state.epsilon_r2){
                if(slider.getValue()==1800){
                    state.theta1 = Math.PI/2;
                    vlab3.setText(" = 90.0 \u00ba ");
                    slider.setValue(1800);
                    slider2.setValue(999);
                    slider2.setEnabled(false);
                    state.ignition();
                }
                else if(slider.getValue()==0){
                    state.theta1 = -Math.PI/2;
                    vlab3.setText(" = 90.0 \u00ba ");
                    slider.setValue(0);
                    slider2.setValue(999);
                    slider2.setEnabled(false);
                    state.ignition();
                }
                else{
                    if(slider.getValue()==1800 || slider.getValue()==1){slider2.setEnabled(false);}
                    else{slider2.setEnabled(true); slider2.setValue(999);}
                    
                    //state.theta1 = MaestroA.rounder(Math.PI/180.0*(slider.getValue()/10.0-90.0+MaestroA.rounder(slider2.getValue()*0.0001,4)),6);
                    //vlab3.setText("\u03b8  =  "+(MaestroA.rounder(slider.getValue()/10.0-90.0+MaestroA.rounder(slider2.getValue()*0.0001,4),6))+" \u00ba ");
                    state.theta1 = MaestroA.rounder(Math.PI/180.0*(slider.getValue()/10.0-90.0),6);
                    vlab3.setText(" = "+Math.abs((MaestroA.rounder(slider.getValue()/10.0-90.0,6)))+" \u00ba ");

                    state.ignition();
                }
            }
            else{
                if(slider.getValue()==1800){
                    state.theta1 = Math.PI/2;
                    vlab3.setText(" = 90.0 \u00ba ");
                    slider.setValue(1800);
                    slider2.setValue(999);
                    slider2.setEnabled(false);
                    state.ignition();
                }
                else if(slider.getValue()==0){
                    state.theta1 = -Math.PI/2;
                    vlab3.setText(" = 90.0 \u00ba ");
                    slider.setValue(0);
                    slider2.setValue(999);
                    slider2.setEnabled(false);
                    state.ignition();
                }
                else{
                    //state.theta1 = MaestroA.rounder(Math.PI/180.0*(slider.getValue()/10.0-90.0+MaestroA.rounder(slider2.getValue()*0.0001,4)),6);
                    //vlab3.setText("  =  "+(MaestroA.rounder(slider.getValue()/10.0-90.0+MaestroA.rounder(slider2.getValue()*0.0001,4),6))+" \u00ba ");
                    state.theta1 = MaestroA.rounder(Math.PI/180.0*(slider.getValue()/10.0-90.0),6);
                    vlab3.setText(" = "+Math.abs((MaestroA.rounder(slider.getValue()/10.0-90.0,6)))+" \u00ba ");

                    slider2.setEnabled(true);
                    slider2.setValue(999);
                    state.ignition();
                }
            }
	}
        
        if(evt.getSource()==slider2){
                if(slider.getValue()==1800){
                    if(slider2.getValue() > 999){
                        state.theta1 = Math.PI/2;
                        vlab3.setText(" = 90.0 \u00ba ");
                        slider.setValue(1800);
                        slider2.setValue(999);
                        state.ignition();
                    }
                    else{
                        state.theta1 = MaestroA.rounder(Math.PI/180.0*(slider.getValue()/10.0-90.0+MaestroA.rounder((slider2.getValue()-999)*0.0001,4)),6);
                        vlab3.setText(" = "+Math.abs((MaestroA.rounder(slider.getValue()/10.0-90.0+MaestroA.rounder((slider2.getValue()-999)*0.0001,4),6)))+" \u00ba ");
                        state.ignition();
                    }
                }
                if(slider.getValue()==0){
                    if(slider2.getValue() < 999){
                        state.theta1 = -Math.PI/2;
                        vlab3.setText(" = 90.0 \u00ba ");
                        slider.setValue(0);
                        slider2.setValue(999);
                        state.ignition();
                    }
                    else{
                        state.theta1 = MaestroA.rounder(Math.PI/180.0*(slider.getValue()/10.0-90.0+MaestroA.rounder((slider2.getValue()-999)*0.0001,4)),6);
                        vlab3.setText(" = "+Math.abs((MaestroA.rounder(slider.getValue()/10.0-90.0+MaestroA.rounder((slider2.getValue()-999)*0.0001,4),6)))+" \u00ba ");
                        state.ignition();
                    }
                }
                else{
                    state.theta1 = MaestroA.rounder(Math.PI/180.0*(slider.getValue()/10.0-90.0+MaestroA.rounder((slider2.getValue()-999)*0.0001,4)),6);
                    vlab3.setText(" = "+Math.abs((MaestroA.rounder(slider.getValue()/10.0-90.0+MaestroA.rounder((slider2.getValue()-999)*0.0001,4),6)))+" \u00ba ");
                    state.ignition();
                }
                //System.out.println(slider2.getValue());
	}
	
    }

    public void actionPerformed(ActionEvent evt){
	if(evt.getSource() == b_epsilon){
                text1.setText(""+MaestroA.rounder(state.epsilon_r1, 3));
                text2.setText(""+MaestroA.rounder(state.epsilon_r2, 3));
                text3.setText(""+MaestroA.rounder(state.epsilon_r3, 3));
                
                text1.setVisible(true);
                text2.setVisible(true);
                text3.setVisible(true);
              
                text1b.setVisible(false);
                text2b.setVisible(false);
                text3b.setVisible(false);
                
                lab1B.setVisible(false);
                lab2B.setVisible(false);
                lab3B.setVisible(false);
                lab1.setVisible(true);
                lab2.setVisible(true);
                lab3.setVisible(true);
                
                labr1B.setVisible(false);
                labr2B.setVisible(false);
                labr3B.setVisible(false);
                labr1.setVisible(true);
                labr2.setVisible(true);
                labr3.setVisible(true);
                
                p_epsilon.setBackground(Color.red);
                p_index.setBackground(Color.gray.brighter());
                state.IsEpsilon = true;
        }
        if(evt.getSource() == b_index){
                text1b.setText(""+MaestroA.rounder(state.index1, 6));
                text2b.setText(""+MaestroA.rounder(state.index2, 6));
                text3b.setText(""+MaestroA.rounder(state.index3, 6));
                
                text1b.setVisible(true);
                text2b.setVisible(true);
                text3b.setVisible(true);
              
                text1.setVisible(false);
                text2.setVisible(false);
                text3.setVisible(false);
                
                lab1.setVisible(false);
                lab2.setVisible(false);
                lab3.setVisible(false);
                lab1B.setVisible(true);
                lab2B.setVisible(true);
                lab3B.setVisible(true);
                labr1.setVisible(false);
                labr2.setVisible(false);
                labr3.setVisible(false);
                labr1B.setVisible(true);
                labr2B.setVisible(true);
                labr3B.setVisible(true);
                
                p_index.setBackground(Color.red);
                p_epsilon.setBackground(Color.gray.brighter());
                state.IsEpsilon = false;
        }
        
        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(text3.getText()).doubleValue() < 1.0){
                     text3.setText("1.0");
                  }
                  
                  if(Double.valueOf(text1b.getText()).doubleValue() < 1.0){
                     text1b.setText("1.0");
                  }
                  
                  
                  if(Double.valueOf(text2b.getText()).doubleValue() < 1.0){
                     text2b.setText("1.0");
                  }
                  
                  if(Double.valueOf(text3b.getText()).doubleValue() < 1.0){
                     text3b.setText("1.0");
                  }
                  
                  if(Double.valueOf(text4.getText()).doubleValue() < 0.0){
                     text4.setText("1.0e-4");
                  }
                  
                  if(Double.valueOf(text7.getText()).doubleValue() < 0.0){
                     text7.setText("350.0e12");
                  }
                  
                  //p_index.setBackground(Color.red);
                  //p_epsilon.setBackground(Color.gray.brighter());
                  
                  //if(c1.getState()){
                  if(state.IsEpsilon){
                        state.epsilon_r1 = Double.valueOf(text1.getText()).doubleValue();
                        state.epsilon_r2 = Double.valueOf(text2.getText()).doubleValue();
                        state.epsilon_r3 = Double.valueOf(text3.getText()).doubleValue();
                        state.index1 = Math.sqrt(state.epsilon_r1);
                        state.index2 = Math.sqrt(state.epsilon_r2);
                        state.index3 = Math.sqrt(state.epsilon_r3);
                        
                        text1.setText(""+MaestroA.rounder(state.epsilon_r1, 3));
                        text2.setText(""+MaestroA.rounder(state.epsilon_r2, 3));
                        text3.setText(""+MaestroA.rounder(state.epsilon_r3, 3));

                        text1.setVisible(true);
                        text2.setVisible(true);
                        text3.setVisible(true);

                        text1b.setVisible(false);
                        text2b.setVisible(false);
                        text3b.setVisible(false);

                        lab1B.setVisible(false);
                        lab2B.setVisible(false);
                        lab3B.setVisible(false);
                        lab1.setVisible(true);
                        lab2.setVisible(true);
                        lab3.setVisible(true);

                        labr1B.setVisible(false);
                        labr2B.setVisible(false);
                        labr3B.setVisible(false);
                        labr1.setVisible(true);
                        labr2.setVisible(true);
                        labr3.setVisible(true);

                        p_epsilon.setBackground(Color.red);
                        p_index.setBackground(Color.gray.brighter());
                        c1.setState(true);
                        c2.setState(false);
                       
                        if(state.epsilon_r2 > state.epsilon_r3){
                            state.Guiding = true;
                        }
                        else{
                            state.Guiding = false;
                        }
                  }
                  //else if(c2.getState()){
                  if(!state.IsEpsilon){
                        state.index1 = Double.valueOf(text1b.getText()).doubleValue();
                        state.index2 = Double.valueOf(text2b.getText()).doubleValue();
                        state.index3 = Double.valueOf(text3b.getText()).doubleValue();
                        state.epsilon_r1 = state.index1*state.index1;
                        state.epsilon_r2 = state.index2*state.index2;
                        state.epsilon_r3 = state.index3*state.index3;
                        
                        text1b.setText(""+MaestroA.rounder(state.index1, 6));
                        text2b.setText(""+MaestroA.rounder(state.index2, 6));
                        text3b.setText(""+MaestroA.rounder(state.index3, 6));

                        text1b.setVisible(true);
                        text2b.setVisible(true);
                        text3b.setVisible(true);

                        text1.setVisible(false);
                        text2.setVisible(false);
                        text3.setVisible(false);

                        lab1.setVisible(false);
                        lab2.setVisible(false);
                        lab3.setVisible(false);
                        lab1B.setVisible(true);
                        lab2B.setVisible(true);
                        lab3B.setVisible(true);
                        labr1.setVisible(false);
                        labr2.setVisible(false);
                        labr3.setVisible(false);
                        labr1B.setVisible(true);
                        labr2B.setVisible(true);
                        labr3B.setVisible(true);

                        p_index.setBackground(Color.red);
                        p_epsilon.setBackground(Color.gray.brighter());
                        c2.setState(true);
                        c1.setState(false);
                        
                        if(state.index2 > state.index3){
                            state.Guiding = true;
                        }
                        else{
                            state.Guiding = false;
                        }
                       
                }
		state.frequency=Double.valueOf(text7.getText()).doubleValue();
                state.fiber_radius=Double.valueOf(text4.getText()).doubleValue();
	}
	state.ignition();
	state.scan_coefficients();
    }
    
    public void itemStateChanged(ItemEvent evt){
	if(evt.getSource() == c1){
                text1.setText(""+MaestroA.rounder(state.epsilon_r1, 3));
                text2.setText(""+MaestroA.rounder(state.epsilon_r2, 3));
                text3.setText(""+MaestroA.rounder(state.epsilon_r3, 3));
                text1.setVisible(true);
                text2.setVisible(true);
                text3.setVisible(true);
              
                text1b.setVisible(false);
                text2b.setVisible(false);
                text3b.setVisible(false);
                
                lab1B.setVisible(false);
                lab2B.setVisible(false);
                lab3B.setVisible(false);
                lab1.setVisible(true);
                lab2.setVisible(true);
                lab3.setVisible(true);
                
                labr1B.setVisible(false);
                labr2B.setVisible(false);
                labr3B.setVisible(false);
                labr1.setVisible(true);
                labr2.setVisible(true);
                labr3.setVisible(true);
              
        }
        if(evt.getSource() == c2){
                text1b.setText(""+MaestroA.rounder(state.index1, 6));
                text2b.setText(""+MaestroA.rounder(state.index2, 6));
                text3b.setText(""+MaestroA.rounder(state.index3, 6));
                
                text1b.setVisible(true);
                text2b.setVisible(true);
                text3b.setVisible(true);
              
                text1.setVisible(false);
                text2.setVisible(false);
                text3.setVisible(false);
                
                lab1.setVisible(false);
                lab2.setVisible(false);
                lab3.setVisible(false);
                lab1B.setVisible(true);
                lab2B.setVisible(true);
                lab3B.setVisible(true);
                labr1.setVisible(false);
                labr2.setVisible(false);
                labr3.setVisible(false);
                labr1B.setVisible(true);
                labr2B.setVisible(true);
                labr3B.setVisible(true);
        }
    }
	
    public void paint(Graphics g){
	g.setColor(Color.black);
	g.draw3DRect(0,0,getSize().width-1,getSize().height-1,true);     
        //g.setColor(Color.red);
        //g.drawLine(730, 16, 730, 66);
	slider.requestFocusInWindow();
	slider2.requestFocusInWindow();
	slider_scale.requestFocusInWindow();
    }
}


class TitleCanvas extends Canvas{
	
	
	Oblique_State state;
        
	//public TitleCanvas(){
	//    super();
	//}
        public TitleCanvas(Oblique_State state){
	    super();
	    this.state = state;
	}
	
	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;
	    
	    g.setFont(new Font("Sanserif",Font.BOLD,state.font16));
            g.setColor(Color.red.darker());
	    g.drawString("Input",state.s5,state.s20);
            
            g.setColor(Color.magenta.darker());
            MaestroG.subscripterSSym("\u03bc = \u03bc","o","", g, state.font16, state.s5, state.s45);
            
	}
    }
/*
class PanelCanvas 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);
	Oblique_State state;
        
	//public PanelCanvas(){
	//    super();
	//}
        public PanelCanvas(Oblique_State state){
	    super();
	    this.state = state;
	}
	
	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 = 10;
	    dx = 80;
	    dxx = 17;
            dy = 25;
	    g.setFont(normalfont);
            g.setColor(Color.black);
	    
	}
    }
    */
