//ObliqueInputPanel.java
import java.awt.*;
import java.awt.event.*;
import java.lang.*;

public class ObliqueInputPanel extends Panel implements AdjustmentListener, ActionListener, ItemListener{
    private static final Color bgcolor = new Color(236,236,236);
    //private static final Color bgcolor = new Color(170,240,240);
    private static final Font labfont=new Font("SanSerif",Font.PLAIN,12);
    private static final Font labfontS=new Font("Serif",Font.PLAIN,13);
    private static final Font labfontbig=new Font("SanSerif",Font.PLAIN,14);
    private static final Font labfontbigI=new Font("Serif",Font.ITALIC,14);
    private static final Font labfontbigI2=new Font("Serif",Font.ITALIC,16);
    private static final 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, 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 Scrollbar slider, slider2, slider_scale;
    // CHANGE ==============================================================
        public Button b2a, b2b, b3a, b3b;
    //======================================================================
    private Oblique_State state;
    public TitleCanvas title;
    //public PanelCanvas panelcanvas;
    
    public ObliqueInputPanel(Oblique_State state){
	super();
	this.state = state;
	setBackground(bgcolor);
	setLayout(null);
	titlelabel = new Label("Input",Label.CENTER);
	titlelabel.setFont(titlefont);
	
	title = new TitleCanvas();
	add(title);
	title.setBounds(10,2,50,55);
        
        //panelcanvas = new PanelCanvas(state);
	//add(panelcanvas);
	//panelcanvas.setBounds(330,2,175,95);
	
        //  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(labfont);
        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(labfont);
	
	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");
	//------------------------------------------------
	
        // CHANGE  =====================================================
                b2a = new Button("<");
                b2a.setBackground(bgcolor);        
                b2b = new Button(">");
                b2b.setBackground(bgcolor);
                b3a = new Button("<");
                b3a.setBackground(bgcolor);
                b3b = new Button(">");
                b3b.setBackground(bgcolor);
                add(b2a); add(b2b); add(b3a); add(b3b);
        //==============================================================
	
        // Sliders
	lab8 = new Label("Angle of Entrance: ",Label.LEFT);
	lab8.setFont(labfont);
	
	slider = new Scrollbar(Scrollbar.HORIZONTAL,1020,1,SCROLLMIN,1801);
	//slider2 = new Scrollbar(Scrollbar.HORIZONTAL,0,1,SCROLLMIN,1000);
        slider2 = new Scrollbar(Scrollbar.HORIZONTAL,0,1,SCROLLMIN,1999);
        slider2.setValue(999);
        slider_scale = new Scrollbar(Scrollbar.HORIZONTAL,5,1,1,50);
        slider.setBackground(Color.white);
        slider2.setBackground(Color.white);
        slider_scale.setBackground(Color.white);
        
	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);
        //Draw lines as panels - To avoid flickering on MAC --- MAC sucks!!!
        //Panel back1 = new Panel();
	//    back1.setBackground(Color.gray);
	//    add(back1);
	//    back1.setBounds(15,123,270,1);
        //----------------------------------------------------------------------
	// input for epsilon 1
        int xpos_block2 = 70;
        int ypos_block2 = 10;
        lab1.setBounds(xpos_block2,ypos_block2,20,20);
        lab1B.setBounds(xpos_block2+5,ypos_block2,20,20);
        labr1.setBounds(xpos_block2+20,ypos_block2+5,15,20);
        labr1B.setBounds(xpos_block2+25,ypos_block2+5,15,20);
        labeqa.setBounds(xpos_block2+37,ypos_block2,15,20);
        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+55,ypos_block2,75,20);
        text1.setForeground(Color.red.darker());
        
        text1b.setBounds(xpos_block2+55,ypos_block2,75,20);
        text1b.setForeground(Color.red.darker());
        
        //labm1.setBounds(xpos_block2,ypos_block2+25,65,15);
        //----------------------------------------------------------------------
        // input for epsilon 2
        int xpos_block3 = 230;
        int ypos_block3 = 10;
	lab2.setBounds(xpos_block3,ypos_block3,20,20);
        lab2B.setBounds(xpos_block3+6,ypos_block3,20,20);
        labr2.setBounds(xpos_block3+20,ypos_block3+5,15,20);
        labr2B.setBounds(xpos_block3+25,ypos_block3+5,15,20);
        labeqb.setBounds(xpos_block3+37,ypos_block3,15,20);
        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+55,ypos_block3,75,20);
        text2.setForeground(Color.blue.darker());
        
        text2b.setBounds(xpos_block3+55,ypos_block3,75,20);
        text2b.setForeground(Color.blue.darker());
        
        //labm2.setBounds(xpos_block3,ypos_block3+25,65,15);
        //----------------------------------------------------------------------
        // input for epsilon 3
        int xpos_block4 = 390;
        int ypos_block4 = 10;
        lab3.setBounds(xpos_block4,ypos_block4,20,20);
        lab3B.setBounds(xpos_block4+5,ypos_block4,20,20);
        labr3.setBounds(xpos_block4+20,ypos_block4+5,15,20);
        labr3B.setBounds(xpos_block4+25,ypos_block4+5,15,20);
        labeqc.setBounds(xpos_block4+37,ypos_block4,15,20);
        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+55,ypos_block4,75,20);
        text3.setForeground(Color.black.darker());
        
        text3b.setBounds(xpos_block4+55,ypos_block4,75,20);
        text3b.setForeground(Color.black.darker());
        //labm3.setBounds(xpos_block4,ypos_block4+25,65,15);
        
        // CHANGE ==============================================================
        //c1.setBounds(xpos_block4+140,ypos_block4+5,30,14);
	//c2.setBounds(xpos_block4+175,ypos_block4+5,30,14);
        c1.setBounds(xpos_block4+140,ypos_block4-5,50,30);
	c2.setBounds(xpos_block4+140,ypos_block4+25,50,30);
        
        //======================================================================
	c1.setBackground(bgcolor);
	c2.setBackground(bgcolor);
        
                
        //----------------------------------------------------------------------
        // Positon frequency and radius input
	int xpos_block0 = 80+45;
        int ypos_block0 = 40;   
	text7.setBounds(xpos_block0,ypos_block0,75,20);
	
        lab7.setBounds(xpos_block0-45,ypos_block0,20,20);
        lab7.setFont(labfontbigI);
        labeqd.setBounds(xpos_block0-18,ypos_block0,15,20);
	labeqd.setForeground(Color.black);
        labHz.setBounds(xpos_block0+77,ypos_block0,25,20);
        lab7.setForeground(Color.black);
        labHz.setForeground(Color.black);
        
        int xpos_blockR = 240+45;
        int ypos_blockR = 40;
        text4.setBounds(xpos_blockR,ypos_blockR,75,20);
	
        lab4.setBounds(xpos_blockR-45,ypos_blockR,20,20);
        lab4.setFont(labfontbigI);
        labeqR.setBounds(xpos_blockR-18,ypos_blockR,15,20);
	labeqR.setForeground(Color.black);
        labM.setBounds(xpos_blockR+77,ypos_blockR,25,20);
        lab4.setForeground(Color.black);
        labM.setForeground(Color.black);
        //----------------------------------------------------------------------
        // Positon update button
        int xpos_block5 = 400+45;
        int ypos_block5 = 40;
        b1.setBounds(xpos_block5,ypos_block5,75,20);
        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,77,22);
	    
	Panel pb2 = new Panel();
	    pb2.setBackground(Color.black);
	    add(pb2);
	    pb2.setBounds(xpos_block5-2,ypos_block5-2,79,24);
        //----------------------------------------------------------------------
        //  input for angle
        
        int xpos_block6 = 610;
        int ypos_block6 = 25;
        
	lab8.setBounds(xpos_block6+30,ypos_block6-20,120,14);
	vlab1.setBounds(xpos_block6+160,ypos_block6-22,15,14);
        vlab2.setBounds(xpos_block6+175,ypos_block6-17,8,14);
        vlab3.setBounds(xpos_block6+184,ypos_block6-20,110,14);
        slider.setBounds(xpos_block6,ypos_block6,260,15);
        slider2.setBounds(xpos_block6,ypos_block6+21,260,15);
        
        // CHANGE  =====================================================
                b2a.setBounds(xpos_block6,ypos_block6,14,15);
                b2b.setBounds(xpos_block6+246,ypos_block6,14,15);
                b3a.setBounds(xpos_block6,ypos_block6+21,14,15);
                b3b.setBounds(xpos_block6+246,ypos_block6+21,14,15);
        //==============================================================
        
        
	Panel pslider2 = new Panel();
	    pslider2.setBackground(Color.cyan);
	    add(pslider2);
	    pslider2.setBounds(xpos_block6-1,ypos_block6-1,262,17);
	    
	Panel pslider1 = new Panel();
	    pslider1.setBackground(Color.black);
	    add(pslider1);
	    pslider1.setBounds(xpos_block6-2,ypos_block6-2,264,19);
	
        Panel pslider4 = new Panel();
	    pslider4.setBackground(Color.cyan);
	    add(pslider4);
	    pslider4.setBounds(xpos_block6-1,ypos_block6+20,262,17);
	    
	Panel pslider3 = new Panel();
	    pslider3.setBackground(Color.black);
	    add(pslider3);
	    pslider3.setBounds(xpos_block6-2,ypos_block6+19,264,19);
        
        //----------------------------------------------------------------------
	        
	//Listeners 
	slider.addAdjustmentListener(this);	
        slider2.addAdjustmentListener(this);
        c1.addItemListener(this);
	c2.addItemListener(this);
        b1.addActionListener(this);
	// CHANGE ======================================================
                b2a.addActionListener(this);
                b2b.addActionListener(this);
                b3a.addActionListener(this);
                b3b.addActionListener(this);
        //==============================================================
   }
   
    public void adjustmentValueChanged(AdjustmentEvent 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()==b2a){
            slider.setValue(slider.getValue()-1);
            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("\u03b8  =  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();
                }
            }
        }
        else if(evt.getSource()==b2b){
            slider.setValue(slider.getValue()+1);
            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("\u03b8  =  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();
                }
            }    
        }
        else if(evt.getSource()==b3a){
            slider2.setValue(slider2.getValue()-1);
                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();
                }
        }
        else if(evt.getSource()==b3b){
            slider2.setValue(slider2.getValue()+1);
                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();
                }
        }
        
                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");
                  }
                  
                  
                  if(c1.getState()){
                        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);
                  }
                  else if(c2.getState()){
                        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;
                  }
		  //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.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);
    }
}


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);
	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;
	    x = 220;
	    y = 20;
	    dx = 80;
	    dxx = 15;
            dy = 20;
	    g.setFont(titlefont);
            g.setColor(Color.red.darker());
	    g.drawString("Input",5,20);
            
            g.setColor(Color.magenta.darker());
            MaestroG.subscripterSSym("\u03bc = \u03bc","o","", g, 16, 5, 45);
            
	}
    }
/*
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);
	    
	}
    }
    */