//StubPanel.java
import java.awt.*;
//import java.applet.*;
import java.awt.event.*;


public class StubPanelNew extends Panel implements AdjustmentListener, ActionListener, ItemListener{
    //private static final Color bgcolor = new Color(250,250,250);
    private static final Color bgcolor = new Color(236,236,236);
    private Label lab1, lab2, lab3, lab3b, lab3c, lab3d, lab4, lab5, lab5b, lab5c, lab5d, lab6, lab7, titlelabel, labeps, labeps2, labeps3;
    public Label vlab3, vlab4, vlab5, vlab6, vlab7;
    private String titulo = "Unknown Title";
    public CheckboxGroup cgrid1, cgrid2;
    public Checkbox c1, c2, c3, c4;
    public Checkbox lock;
    public TextField text1, text2;
    public Scrollbar s1,s1b, s2, s2b;
    private static final Font labfont = new Font("SanSerif",Font.PLAIN,12);
    private static final Font labfont2 = new Font("SanSerif",Font.PLAIN,13);
    private static final Font labfontI = new Font("Serif",Font.ITALIC,14);
    private static final Font titlefont = new Font("SanSerif",Font.PLAIN,14);
    public int SCROLLMIN=0, SCROLLMAX=10001, SCROLLMAXB=1000; // SCROLLMAXC=2001;
    public int SCROLLMAXC = 501;
     // CHANGE 9/27/2017  =======================================================
    public Button b1, b2a, b2b, b3a, b3b;
    //==========================================================================
    private Stub stub;
    public Color colorstub;
    private Trans_State state;
   
    public StubPanelNew(String titulo,Stub stub,Trans_State state, Color colorstub){
	super();
	this.stub = stub;
	this.state = state;
	setBackground(bgcolor);
	this.titulo = titulo;
        this.colorstub = colorstub;
        
	setLayout(null);
        
        titlelabel  = new Label(titulo,Label.CENTER); 
	titlelabel.setFont(titlefont);
	titlelabel.setForeground(bgcolor);
	lab3 = new Label("y",Label.RIGHT);
        lab3c = new Label("s",Label.LEFT);
        lab3d = new Label(" = ",Label.CENTER);
        lab3b = new Label("[ S ]",Label.LEFT);
	//CHANGE # 1  9/26/2017  ===============================================
        //lab4 = new Label("Ys =",Label.RIGHT);
        lab4 = new Label("Ys",Label.LEFT);
        //======================================================================
	lab5 = new Label("Stub Length =",Label.RIGHT);
        lab5b= new Label("[ @         ]",Label.LEFT);
        lab5c= new Label("f",Label.RIGHT);
	lab5d= new Label("o",Label.LEFT);
        
        labeps3 = new Label(" = ",Label.CENTER);
        labeps = new Label("\u03b5",Label.RIGHT);
        labeps2 = new Label("r",Label.LEFT);
        
	//lab6 = new Label("Ystub  [ S ]   = ",Label.RIGHT);
	//lab7 = new Label("(normalized)   = ",Label.RIGHT);
	//lab1.setFont(labfont);
	//lab2.setFont(labfont);
	
        lab3b.setFont(titlefont);
	lab4.setFont(labfont2);
	lab5.setFont(labfont);
        lab5b.setFont(labfont);
        lab5c.setFont(labfontI);
        lab5d.setFont(labfontI);
        
        labeps.setFont(titlefont);
        labeps2.setFont(labfont);
        labeps3.setFont(labfont);
        
	//lab6.setFont(labfont);
	//lab7.setFont(labfont);
	//lab1.setForeground(colorstub);
	//lab2.setForeground(colorstub);
	lab3.setForeground(colorstub);
        //lab3b.setForeground(colorstub);
        lab3c.setForeground(colorstub);
        lab3d.setForeground(colorstub);
        labeps.setForeground(colorstub);
        labeps2.setForeground(colorstub);
        labeps3.setForeground(colorstub);
        
        //lab3.setBackground(Color.white);
        //lab3c.setBackground(Color.white);
        //lab3d.setBackground(Color.white);
        
	lab4.setForeground(colorstub);
        //lab4.setBackground(Color.yellow);
	lab5.setForeground(colorstub);
	//lab6.setForeground(Color.red.darker());
	//lab7.setForeground(Color.red.darker());
	
        //CHANGE 9/27/2017 =====================================================
        vlab3 = new Label("= j "+MaestroA.rounder(state.ZIMP[0]*state.YS.Imaginary(),3)+" (norm.)",Label.LEFT);
        vlab4 = new Label("= j "+MaestroA.rounder(state.YS.Imaginary(),6)+" [ S ]",Label.LEFT);
        //======================================================================
        lab3.setFont(labfont);
        vlab3.setFont(labfont);
        
        vlab4.setForeground(colorstub);
        //vlab4.setBackground(Color.pink);
	vlab5 = new Label(""+MaestroA.rounder(state.Stub_Length,6)+" \u03bb",Label.LEFT);
	vlab5.setForeground(colorstub);
        
        //vlab6 = new Label("   0.0   ( open )",Label.LEFT);
	//vlab7 = new Label("   0.0 ",Label.LEFT);
	vlab4.setFont(labfont);
        vlab4.setFont(labfont);
	vlab5.setFont(labfont);
	//vlab6.setFont(labfont);
	//vlab7.setFont(labfont);
	//cgrid1 = new CheckboxGroup();
	cgrid2 = new CheckboxGroup();
	//c1 = new Checkbox("Enabled",cgrid1,true);
	//c2 = new Checkbox("Disabled",cgrid1,false);
	c4 = new Checkbox("Open",cgrid2,false);
	c3 = new Checkbox("Short",cgrid2,true);
        
        //c1.setForeground(colorstub);
	c3.setForeground(colorstub);
        //c2.setForeground(colorstub);
	c4.setForeground(colorstub);
        
	//c1.setBackground(bgcolor);
	//c2.setBackground(bgcolor);
	c3.setBackground(bgcolor);
	c4.setBackground(bgcolor);
	
        lock = new Checkbox(" Lock Cursor",false);
        lock.setForeground(Color.black);
        lock.setBackground(bgcolor);
        //lock.setBackground(Color.white);
        
	text1 = new TextField("100.0",8);
        text1.setForeground(colorstub);
        text2 = new TextField("1.0",8);
        text2.setForeground(colorstub);
        
	s1 = new Scrollbar(Scrollbar.HORIZONTAL,(int)((SCROLLMAX-SCROLLMIN)*(1.0-stub.getPosition()/state.lineLength_part1)),
			    1,SCROLLMIN,SCROLLMAX);
        s1b = new Scrollbar(Scrollbar.HORIZONTAL,(SCROLLMAXB-SCROLLMIN),1,SCROLLMIN,SCROLLMAXB);
        
        s2 = new Scrollbar(Scrollbar.HORIZONTAL,(int)((SCROLLMAXC-SCROLLMIN)),
			    1,SCROLLMIN,SCROLLMAXC);
	
	s2b = new Scrollbar(Scrollbar.HORIZONTAL,(int)(SCROLLMAXB-SCROLLMIN),1,SCROLLMIN,SCROLLMAXB);
	s2b.setValue(SCROLLMIN);
        s2.setValue(250);
        
        b1 = new Button("Update");// not used here
	b1.setBackground(bgcolor);
        
        // CHANGE  9/27/2017 =================================================== 
        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);
        //======================================================================
        //titlelabel.setBounds(50,100,100,20);
        //add(titlelabel);
        
        //lab1.setBounds(10,10,70,15);
        //c1.setBounds(80,10,80,15);
        //c2.setBounds(195,10,80,15);
        //add(lab1);
        //add(c1);
        //add(c2);
        add(lock);
        // CHANGE #1 6/14/2017 =================================================
        // MODIFY LINE BELOW
        //lock.setBounds(200,35,100,15);
        lock.setBounds(180,15,120,15);
        //======================================================================
        
        //lab2.setBounds(10,30,70,15);
        c3.setBounds(225,60,80,15);
        c4.setBounds(225,80,80,15);
        //add(lab2);
        add(c3);
        add(c4);
        // CHANGE #2 6/14/2017  ================================================
        // MODIFY LINES BELOW
        //lab3.setBounds(0,10,15,20);
        //lab3c.setBounds(18,14,20,20);
        //lab3d.setBounds(35,10,15,20);
        //lab3b.setBounds(135,10,20,20);
        
        lab3.setBounds(0,0,15,15);
        lab3c.setBounds(15,4,10,15);
        //lab3d.setBounds(43,10,20,20);
        //lab3b.setBounds(155,10,20,20);
        
        vlab3.setBounds(28,2,150,15);
        //======================================================================
        //lab3b.setBounds(135,10,50,20);
        
        labeps.setBounds(201,3,15,20);
        labeps2.setBounds(214,7,10,20);
        labeps3.setBounds(221,3,15,20);
        
        //text1.setBounds(55,10,75,20);
        text2.setBounds(241,4,45,20);

        //b1.setBounds(190,60,60,20);
        b1.setBounds(225,68,60,20);
        b1.setForeground(colorstub);
        add(lab3);
        //  CHANGE =============================================================
        //add(lab3b);
        //======================================================================
        add(lab3c);
        //  CHANGE =============================================================
        //add(lab3d);
        //======================================================================
        add(vlab3);
        //add(labeps);
        //add(labeps2);
        //add(labeps3);
        
        //add(text1);
        //add(text2);
        
        //add(b1);
        
        // CHANGE #2   9/26/2017  USE LINE BELOW AS CHANGED  ===================
        lab4.setBounds(10,20,15,15);
        //======================================================================
        add(lab4);
        // CHANGE ==============================================================
        //vlab4.setBounds(51,30,135,15);
        vlab4.setBounds(28,20,150,15);
        //======================================================================
        add(vlab4);
        //s1.setBounds(40,55,240,11);
        //s1b.setBounds(40,67,240,8);
        //add(s1);
        //add(s1b);
        
        //add(lab5d); add(lab5c); add(lab5b);
        lab5b.setForeground(colorstub);
        lab5c.setForeground(colorstub);
        lab5d.setForeground(colorstub);
        
        lab5b.setBounds(10,40,50,15);
        lab5c.setBounds(31,40,12,17);
        lab5d.setBounds(41,46,12,11);
        
        lab5.setBounds(5,44,95,15);
        add(lab5);
        //lab5.setBackground(Color.yellow);        
        vlab5.setBounds(102,44,120,15);
        add(lab5);
        add(vlab5);
        
        // CHANGE  9/27/2017 ===================================================
        s2.setBounds(10,63,200,15);
        add(s2);
                
        b2a.setBounds(10,63,14,15);
        b2b.setBounds(196,63,14,15);
        
        s2b.setBounds(10,79,200,15);
        add(s2b);
        
        b3a.setBounds(10,79,14,15);
        b3b.setBounds(196,79,14,15);
        //======================================================================
        
        Panel pslid = new Panel();
	    pslid.setBackground(Color.black);
	    add(pslid);
            //CHANGE ===========================================================
	    //pslid.setBounds(9,65,202,33);
            pslid.setBounds(9,62,202,33);
            //==================================================================
        
        //lab6.setBounds(10,190,100,15);
        //add(lab6);
        //vlab6.setBounds(130,190,150,15);
        //add(vlab6);
        
        //lab7.setBounds(10,210,100,15);
        //add(lab7);
        //vlab7.setBounds(130,210,150,15);
        //add(vlab7);
                
	s1.setBackground(new Color(230,230,230));
        s1b.setBackground(Color.white);
        s2.setBackground(Color.white);
	s2b.setBackground(Color.white);
	
        s1.setForeground(colorstub);
        s1b.setForeground(colorstub);
        s2.setForeground(colorstub);
	
	//Listeners
	s1.addAdjustmentListener(this);
        s1b.addAdjustmentListener(this);
        s2.addAdjustmentListener(this);
        s2b.addAdjustmentListener(this);
	b1.addActionListener(this);
        
        // CHANGE 9/27/2017 ====================================================
        b2a.addActionListener(this);
        b2b.addActionListener(this);
	b3a.addActionListener(this);
	b3b.addActionListener(this);
	//======================================================================
        
	//c1.addItemListener(this);
	//c2.addItemListener(this);
	c3.addItemListener(this);
	c4.addItemListener(this);
    }
    
    public void paint(Graphics g){
                Font normalfont = new Font("SanSerif",Font.PLAIN,11);
                Font symbolfont = new Font("Serif",Font.PLAIN,12);
                Graphics2D g2d = (Graphics2D)g;
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);

		int x, y, dx, dxx, dy, dyy, stepx;
            	boolean Gamma_plusone, Gamma_minusone;
            	double tempR = 0.0; double tempX = 0.0;

            	String alpha, Ohm, lambda, infinity, Gamma, plusj, minusj, 
                       sign, plusr, minusr, signr;
		g.setFont(symbolfont);
		alpha="\u03b1";
		lambda="\u03bb";
		Ohm="\u03a9";
		infinity="\u221e";
		Gamma="\u0393";
                g.setFont(normalfont);
		plusj =" + j ";
		minusj=" - j ";
                plusr ="";
                minusr =" - ";
                
                Complex tempc;
	    FontMetrics fm;
	    x = 20;
	    y = 195;
	    dx = 80;
	    dxx = 15;
	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    dy = fm.getHeight();
	    dyy = dy + 5;

            int xinit2, xinit3;
            xinit2 = x+dxx+95;

	//g.setColor(Color.red.darker());
        g.setColor(colorstub);

        // frame of panel
        //g.drawRect(0,0,getSize().width-1,getSize().height-1);
        
        //frame of update button
        //g.drawRect(222,65,65,25);
        
        //frame of Z0 entry
        //g.drawRect(52,7,79,24);
        
        //frame of epsilon entry
        //g.drawRect(238,1,49,24);
        
        // frame of position sliders
        //g.drawRect(37,52,245,25);
        
        // frame of length slider
        g.drawRect(37,527,245,25);
        
        //lab6.setBounds(10,190,100,15);
        //vlab6.setBounds(130,190,150,15);
        
        //lab7.setBounds(10,210,100,15);
        //vlab7.setBounds(130,210,150,15);
        
        //MaestroG.subscripter("       Z","0"," =",g,12,20,25);
        //MaestroG.subscripterSymFirst2("\u03a9","","",g,12,168,25);       
    }
    
    public synchronized void reset(){
            //s1 = new Scrollbar(Scrollbar.HORIZONTAL,(SCROLLMAX-SCROLLMIN),1,SCROLLMIN,SCROLLMAX);
            //s1b = new Scrollbar(Scrollbar.HORIZONTAL,(SCROLLMAXB-SCROLLMIN),1,SCROLLMIN,SCROLLMAXB);
            //int Zreset;
            
            //Zreset = (int)((int)(state.ZBoundHigh/100.0)*100+100);
            //SCROLLMAXC = Zreset+1;
            
            //s2.setMaximum(SCROLLMAXC);
	    
	    //s1.setValue(s1.getMaximum());
	    //s1b.setValue(s1b.getMaximum());
            //stub.setPosition(getValue()+getValue2());
            //vlab3.setText(" j "+MaestroA.rounder(state.ZIMP[0]*state.YS.Imaginary(),6));
            //vlab4.setText(" j "+MaestroA.rounder(state.YS.Imaginary(),6)+" S");
            //s2.setValue((int)((SCROLLMAXC-SCROLLMIN)*0.5));
	    ////s2b.setValue(s2b.getMaximum());
            //s2b.setValue(SCROLLMIN);
            //text1.setText(""+s2.getValue());
            
            //stub.setLength(0.25);
            //vlab5.setText(""+MaestroA.rounder(state.Stub_Length,6)+" \u03bb");
            
            
            state.Stub_Length = MaestroA.rounder((0.001*(s2.getValue())+s2b.getValue()*0.000001),6);
            if(state.StubIsShort){
                if(state.Stub_Length == 0.0 || state.Stub_Length == 0.5){
                    state.YS = new Complex(0.0, 1.0E130);
                    state.ZS = new Complex(0.0, 0.0);
                    vlab3.setText("= \u221E (norm.)");
                    vlab4.setText("= \u221E [ S ]");
                }
                else{
                    state.YS = new Complex(0.0,MaestroA.rounder(-1.0/EMF.computeZShortStub(state.Stub_Length,state.ZIMP[0]).Imaginary(),8));
                    if(state.YS.Imaginary() >= 0.0){
                        if(state.YS.Imaginary() >= 1.0){
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),6)+" [ S ]");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()) >= 1.0){
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),6)+" [ S ]");
                        }
                    }
                    if((state.YS.Imaginary()) >= 0.0){
                        if((state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],6)+" (norm.)");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),6)+" (norm.)");
                        }
                    }
                }
            }
            else{
                if(state.Stub_Length == 0.0 || state.Stub_Length == 0.5){
                    state.YS = new Complex(0.0, 1.0E130);
                    state.ZS = new Complex(0.0, 0.0);
                    vlab3.setText("= \u221E (norm.)");
                    vlab4.setText("= \u221E [ S ]");
                }
                else{
                    state.YS = new Complex(0.0,MaestroA.rounder(-1.0/EMF.computeZOpenStub(state.Stub_Length,state.ZIMP[0]).Imaginary(),8));
                    if(state.YS.Imaginary() >= 0.0){
                        if(state.YS.Imaginary() >= 1.0){
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),6)+" [ S ]");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()) >= 1.0){
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),6)+" [ S ]");
                        }
                    }
                    if((state.YS.Imaginary()) >= 0.0){
                        if((state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],6)+" (norm.)");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),6)+" (norm.)");
                        }
                    }
                }
            }
            
            repaint();
    }
    
    public void adjustmentValueChanged(AdjustmentEvent evt){
	double temp;
	
	if(evt.getSource()==s2b){
	    state.Stub_Length = MaestroA.rounder((0.001*(s2.getValue())+s2b.getValue()*0.000001),6);
            if(state.StubIsShort){
                if(state.Stub_Length == 0.0 || state.Stub_Length == 0.5){
                    state.YS = new Complex(0.0, 1.0E130);
                    state.ZS = new Complex(0.0, 0.0);
                    vlab3.setText("= \u221E (norm.)");
                    vlab4.setText("= \u221E [ S ]");
                }
                else{
                    state.YS = new Complex(0.0,MaestroA.rounder(-1.0/EMF.computeZShortStub(state.Stub_Length,state.ZIMP[0]).Imaginary(),8));
                    if(state.YS.Imaginary() >= 0.0){
                        if(state.YS.Imaginary() >= 1.0){
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),6)+" [ S ]");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()) >= 1.0){
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),6)+" [ S ]");
                        }
                    }
                    if((state.YS.Imaginary()) >= 0.0){
                        if((state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],6)+" (norm.)");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),6)+" (norm.)");
                        }
                    }
                }
            }
            else{
                if(state.Stub_Length == 0.0 || state.Stub_Length == 0.5){
                    state.YS = new Complex(0.0, 1.0E130);
                    state.ZS = new Complex(0.0, 0.0);
                    vlab3.setText("= \u221E ");
                    vlab4.setText("= \u221E [ S ]");
                }
                else{
                    state.YS = new Complex(0.0,MaestroA.rounder(-1.0/EMF.computeZOpenStub(state.Stub_Length,state.ZIMP[0]).Imaginary(),8));
                    if(state.YS.Imaginary() >= 0.0){
                        if(state.YS.Imaginary() >= 1.0){
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),6)+" [ S ]");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()) >= 1.0){
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),6)+" [ S ]");
                        }
                    }
                    if((state.YS.Imaginary()) >= 0.0){
                        if((state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],6)+" (norm.)");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),6)+" (norm.)");
                        }
                    }
                }
            }
                //text1.setText(""+state.YS.Imaginary());
            //System.out.println(state.YS+"   "+(Math.atan(2.0*Math.PI*state.Stub_Length)));
            vlab5.setText(""+MaestroA.rounder(state.Stub_Length,6)+" \u03bb");
            repaint();
	}
        else if(evt.getSource()==s2){
	    s2b.setValue(s2b.getMinimum());
            state.Stub_Length = MaestroA.rounder(0.001*(s2.getValue()),6);
            
            if(state.StubIsShort){
                if(state.Stub_Length == 0.0 || state.Stub_Length == 0.5){
                    state.YS = new Complex(0.0, 1.0E130);
                    state.ZS = new Complex(0.0, 0.0);
                    vlab3.setText("= \u221E (norm.)");
                    vlab4.setText("= \u221E [ S ]");
                }
                else{
                    state.YS = new Complex(0.0,MaestroA.rounder(-1.0/EMF.computeZShortStub(state.Stub_Length,state.ZIMP[0]).Imaginary(),8));
                    if(state.YS.Imaginary() >= 0.0){
                        if(state.YS.Imaginary() >= 1.0){
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),6)+" [ S ]");
                        }
                        
                        if(state.YS.Imaginary()*state.ZIMP[0] >= 1.0){
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],6)+" (norm.)");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()) >= 1.0){
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),6)+" [ S ]");
                        }
                        
                        if(Math.abs(state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),6)+" (norm.)");
                        }
                    }
                }
            }
            else{
                if(state.Stub_Length == 0.25){
                    state.YS = new Complex(0.0, 1.0E130);
                    state.ZS = new Complex(0.0, 0.0);
                    vlab3.setText("= \u221E");
                    vlab4.setText("= \u221E [ S ]");
                }
                else{
                    state.YS = new Complex(0.0,MaestroA.rounder(-1.0/EMF.computeZOpenStub(state.Stub_Length,state.ZIMP[0]).Imaginary(),8));
                    if(state.YS.Imaginary() >= 0.0){
                        if(state.YS.Imaginary() >= 1.0){
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),6)+" [ S ]");
                        }
                        
                        if(state.YS.Imaginary()*state.ZIMP[0] >= 1.0){
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],6)+" (norm.)");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()) >= 1.0){
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),6)+" [ S ]");
                        }
                        
                        if(Math.abs(state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),6)+" (norm.)");
                        }
                    }
                }
            }
            
            //System.out.println(state.YS+"   "+(Math.atan(2.0*Math.PI*state.Stub_Length)));
            vlab5.setText(""+MaestroA.rounder(state.Stub_Length,6)+" \u03bb");
	    
            if(s2.getValue() == (SCROLLMAXC-1)){
                s2b.setEnabled(false);
                
            }
            else{
                s2b.setEnabled(true);
                
            }
	}
    }
    
    public void actionPerformed(ActionEvent evt){
	double temp;
	
	if(evt.getSource()==b1){
	    //double tempstub = Double.valueOf(text1.getText()).doubleValue();
	    //if( tempstub < 0.0){
		//stub.setZchar(0.0);
		//text1.setText("0.0");
		
	    //}
	    //else{
		//stub.setZchar(Double.valueOf(text1.getText()).doubleValue());
	    //}
            
            //double tempeps = Double.valueOf(text2.getText()).doubleValue();
	    //if( tempeps < 0.0){
		//text2.setText("1.0");
	    //}
            //int temp1, temp2;
            //temp1 = (int)(Double.valueOf(text1.getText()).doubleValue()*1000);
            //if(temp1 > 1000.0){temp1 = 1000; temp2 = 0; text1.setText("1.0");}
            //if(temp1 < -1000.0){temp1 = -1000; temp2 = 0; text1.setText("-1.0");}
            //s2.setValue(temp1+(SCROLLMAXC - 1)/2);
            //System.out.println(temp1);
            //System.out.println((SCROLLMAXC - 1)/2);
            
            //temp2 = (int)(1000*(1000*Double.valueOf(text1.getText()).doubleValue()-temp1));
            //if(temp2 > 999){temp2 = 999;}
            //s2b.setValue(temp2);
            //System.out.println(temp2);    
	}
        
        if(evt.getSource()==b2a){
            s2.setValue(s2.getValue()-1);
            s2b.setValue(s2b.getMinimum());
            state.Stub_Length = MaestroA.rounder(0.001*(s2.getValue()),6);
            
            if(state.StubIsShort){
                if(state.Stub_Length == 0.0 || state.Stub_Length == 0.5){
                    state.YS = new Complex(0.0, 1.0E130);
                    state.ZS = new Complex(0.0, 0.0);
                    vlab3.setText("= \u221E (norm.)");
                    vlab4.setText("= \u221E [ S ]");
                }
                else{
                    state.YS = new Complex(0.0,MaestroA.rounder(-1.0/EMF.computeZShortStub(state.Stub_Length,state.ZIMP[0]).Imaginary(),8));
                    if(state.YS.Imaginary() >= 0.0){
                        if(state.YS.Imaginary() >= 1.0){
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),6)+" [ S ]");
                        }
                        
                        if(state.YS.Imaginary()*state.ZIMP[0] >= 1.0){
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],6)+" (norm.)");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()) >= 1.0){
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),6)+" [ S ]");
                        }
                        
                        if(Math.abs(state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),6)+" (norm.)");
                        }
                    }
                }
            }
            else{
                if(state.Stub_Length == 0.25){
                    state.YS = new Complex(0.0, 1.0E130);
                    state.ZS = new Complex(0.0, 0.0);
                    vlab3.setText("= \u221E");
                    vlab4.setText("= \u221E [ S ]");
                }
                else{
                    state.YS = new Complex(0.0,MaestroA.rounder(-1.0/EMF.computeZOpenStub(state.Stub_Length,state.ZIMP[0]).Imaginary(),8));
                    if(state.YS.Imaginary() >= 0.0){
                        if(state.YS.Imaginary() >= 1.0){
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),6)+" [ S ]");
                        }
                        
                        if(state.YS.Imaginary()*state.ZIMP[0] >= 1.0){
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],6)+" (norm.)");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()) >= 1.0){
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),6)+" [ S ]");
                        }
                        
                        if(Math.abs(state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),6)+" (norm.)");
                        }
                    }
                }
            }
            
            //System.out.println(state.YS+"   "+(Math.atan(2.0*Math.PI*state.Stub_Length)));
            vlab5.setText(""+MaestroA.rounder(state.Stub_Length,6)+" \u03bb");
	    
            if(s2.getValue() == (SCROLLMAXC-1)){
                s2b.setEnabled(false);
            }
            else{
                s2b.setEnabled(true);                
            }
        }
        else if(evt.getSource()==b2b){
            s2.setValue(s2.getValue()+1);
            s2b.setValue(s2b.getMinimum());
            state.Stub_Length = MaestroA.rounder(0.001*(s2.getValue()),6);
            
            if(state.StubIsShort){
                if(state.Stub_Length == 0.0 || state.Stub_Length == 0.5){
                    state.YS = new Complex(0.0, 1.0E130);
                    state.ZS = new Complex(0.0, 0.0);
                    vlab3.setText("= \u221E (norm.)");
                    vlab4.setText("= \u221E [ S ]");
                }
                else{
                    state.YS = new Complex(0.0,MaestroA.rounder(-1.0/EMF.computeZShortStub(state.Stub_Length,state.ZIMP[0]).Imaginary(),8));
                    if(state.YS.Imaginary() >= 0.0){
                        if(state.YS.Imaginary() >= 1.0){
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),6)+" [ S ]");
                        }
                        
                        if(state.YS.Imaginary()*state.ZIMP[0] >= 1.0){
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],6)+" (norm.)");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()) >= 1.0){
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),6)+" [ S ]");
                        }
                        
                        if(Math.abs(state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),6)+" (norm.)");
                        }
                    }
                }
            }
            else{
                if(state.Stub_Length == 0.25){
                    state.YS = new Complex(0.0, 1.0E130);
                    state.ZS = new Complex(0.0, 0.0);
                    vlab3.setText("= \u221E");
                    vlab4.setText("= \u221E [ S ]");
                }
                else{
                    state.YS = new Complex(0.0,MaestroA.rounder(-1.0/EMF.computeZOpenStub(state.Stub_Length,state.ZIMP[0]).Imaginary(),8));
                    if(state.YS.Imaginary() >= 0.0){
                        if(state.YS.Imaginary() >= 1.0){
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),6)+" [ S ]");
                        }
                        
                        if(state.YS.Imaginary()*state.ZIMP[0] >= 1.0){
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],6)+" (norm.)");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()) >= 1.0){
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),6)+" [ S ]");
                        }
                        
                        if(Math.abs(state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),6)+" (norm.)");
                        }
                    }
                }
            }
            
            //System.out.println(state.YS+"   "+(Math.atan(2.0*Math.PI*state.Stub_Length)));
            vlab5.setText(""+MaestroA.rounder(state.Stub_Length,6)+" \u03bb");
	    
            if(s2.getValue() == (SCROLLMAXC-1)){
                s2b.setEnabled(false);
            }
            else{
                s2b.setEnabled(true);                
            }
        }
        else if(evt.getSource()==b3a){
            s2b.setValue(s2b.getValue()-1);
            state.Stub_Length = MaestroA.rounder((0.001*(s2.getValue())+s2b.getValue()*0.000001),6);
            if(state.StubIsShort){
                if(state.Stub_Length == 0.0 || state.Stub_Length == 0.5){
                    state.YS = new Complex(0.0, 1.0E130);
                    state.ZS = new Complex(0.0, 0.0);
                    vlab3.setText("= \u221E (norm.)");
                    vlab4.setText("= \u221E [ S ]");
                }
                else{
                    state.YS = new Complex(0.0,MaestroA.rounder(-1.0/EMF.computeZShortStub(state.Stub_Length,state.ZIMP[0]).Imaginary(),8));
                    if(state.YS.Imaginary() >= 0.0){
                        if(state.YS.Imaginary() >= 1.0){
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),6)+" [ S ]");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()) >= 1.0){
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),6)+" [ S ]");
                        }
                    }
                    if((state.YS.Imaginary()) >= 0.0){
                        if((state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],6)+" (norm.)");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),6)+" (norm.)");
                        }
                    }
                }
            }
            else{
                if(state.Stub_Length == 0.0 || state.Stub_Length == 0.5){
                    state.YS = new Complex(0.0, 1.0E130);
                    state.ZS = new Complex(0.0, 0.0);
                    vlab3.setText("= \u221E ");
                    vlab4.setText("= \u221E [ S ]");
                }
                else{
                    state.YS = new Complex(0.0,MaestroA.rounder(-1.0/EMF.computeZOpenStub(state.Stub_Length,state.ZIMP[0]).Imaginary(),8));
                    if(state.YS.Imaginary() >= 0.0){
                        if(state.YS.Imaginary() >= 1.0){
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),6)+" [ S ]");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()) >= 1.0){
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),6)+" [ S ]");
                        }
                    }
                    if((state.YS.Imaginary()) >= 0.0){
                        if((state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],6)+" (norm.)");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),6)+" (norm.)");
                        }
                    }
                }
            }
                //text1.setText(""+state.YS.Imaginary());
            //System.out.println(state.YS+"   "+(Math.atan(2.0*Math.PI*state.Stub_Length)));
            vlab5.setText(""+MaestroA.rounder(state.Stub_Length,6)+" \u03bb");
            repaint();
        }
        if(evt.getSource()==b3b){
            s2b.setValue(s2b.getValue()+1);
            state.Stub_Length = MaestroA.rounder((0.001*(s2.getValue())+s2b.getValue()*0.000001),6);
            if(state.StubIsShort){
                if(state.Stub_Length == 0.0 || state.Stub_Length == 0.5){
                    state.YS = new Complex(0.0, 1.0E130);
                    state.ZS = new Complex(0.0, 0.0);
                    vlab3.setText("= \u221E (norm.)");
                    vlab4.setText("= \u221E [ S ]");
                }
                else{
                    state.YS = new Complex(0.0,MaestroA.rounder(-1.0/EMF.computeZShortStub(state.Stub_Length,state.ZIMP[0]).Imaginary(),8));
                    if(state.YS.Imaginary() >= 0.0){
                        if(state.YS.Imaginary() >= 1.0){
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),6)+" [ S ]");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()) >= 1.0){
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),6)+" [ S ]");
                        }
                    }
                    if((state.YS.Imaginary()) >= 0.0){
                        if((state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],6)+" (norm.)");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),6)+" (norm.)");
                        }
                    }
                }
            }
            else{
                if(state.Stub_Length == 0.0 || state.Stub_Length == 0.5){
                    state.YS = new Complex(0.0, 1.0E130);
                    state.ZS = new Complex(0.0, 0.0);
                    vlab3.setText("= \u221E ");
                    vlab4.setText("= \u221E [ S ]");
                }
                else{
                    state.YS = new Complex(0.0,MaestroA.rounder(-1.0/EMF.computeZOpenStub(state.Stub_Length,state.ZIMP[0]).Imaginary(),8));
                    if(state.YS.Imaginary() >= 0.0){
                        if(state.YS.Imaginary() >= 1.0){
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= j "+MaestroA.rounder(state.YS.Imaginary(),6)+" [ S ]");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()) >= 1.0){
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),3)+" [ S ]");
                        }
                        else{
                            vlab4.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),6)+" [ S ]");
                        }
                    }
                    if((state.YS.Imaginary()) >= 0.0){
                        if((state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],6)+" (norm.)");
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),3)+" (norm.)");
                        }
                        else{
                            vlab3.setText("= - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),6)+" (norm.)");
                        }
                    }
                }
            }
                //text1.setText(""+state.YS.Imaginary());
            //System.out.println(state.YS+"   "+(Math.atan(2.0*Math.PI*state.Stub_Length)));
            vlab5.setText(""+MaestroA.rounder(state.Stub_Length,6)+" \u03bb");
            repaint();
        }
    }
    
    public double getValue(){
		SCROLLMAX = s1.getMaximum();
		SCROLLMIN = s1.getMinimum();
		
		    return (MaestroA.rounder((SCROLLMAX-SCROLLMIN-1-s1.getValue())*state.lineLength_part1/(SCROLLMAX-SCROLLMIN-1),5));
	}
	
	public double getValue2(){
		SCROLLMAXB = s1b.getMaximum();
		SCROLLMIN = s1b.getMinimum();
		if(state.lineLength < 1.0){
		    return (MaestroA.rounder((double)(SCROLLMAXB-SCROLLMIN-1-s1b.getValue())*0.0001/(double)(SCROLLMAXB-SCROLLMIN),7));
		}
		else if(state.lineLength >= 1.0 && state.lineLength < 10.0){
		    return (MaestroA.rounder((double)(SCROLLMAXB-SCROLLMIN-1-s1b.getValue())*0.001/(double)(SCROLLMAXB-SCROLLMIN),6));
		}
		else if(state.lineLength >= 10.0 && state.lineLength < 100.0){
		    return (MaestroA.rounder((double)(SCROLLMAXB-SCROLLMIN-1-s1b.getValue())*0.01/(double)(SCROLLMAXB-SCROLLMIN),5));
		}
		else if(state.lineLength >= 100.0 && state.lineLength < 1000.0){
		    return (MaestroA.rounder((double)(SCROLLMAXB-SCROLLMIN-1-s1b.getValue())*0.1/(double)(SCROLLMAXB-SCROLLMIN),4));
		}
		else if(state.lineLength >= 1000.0 && state.lineLength < 10000.0){
		    return (MaestroA.rounder((double)(SCROLLMAXB-SCROLLMIN-1-s1b.getValue())/(double)(SCROLLMAXB-SCROLLMIN),3));
		}
		else if(state.lineLength >= 10000.0 && state.lineLength < 100000.0){
		    return (MaestroA.rounder((double)(SCROLLMAXB-SCROLLMIN-1-s1b.getValue())*10.0/(double)(SCROLLMAXB-SCROLLMIN),2));
		}
		else{
		    return (MaestroA.rounder((double)(SCROLLMAXB-SCROLLMIN-1-s1b.getValue())*100.0/(double)(SCROLLMAXB-SCROLLMIN),1));
		}
		
	}
	
	public synchronized void setValue(double x){
	    s1.setValue((int)(x));
	}
	
	public synchronized void setValue2(double x){
	    s1.setValue((int)(x));
	}
    
    @Override
    public void itemStateChanged(ItemEvent evt){
	if(evt.getSource()==c3){
	    state.StubIsShort = true;
            if(state.Stub_Length <= 0.25){
                s2.setValue(s2.getValue()+250);
            }
            else{
                s2.setValue(s2.getValue()-250);
            }
            if(state.Stub_Length < 0.5){
                s2b.setEnabled(true);
            }
            // USE THIS IF YOU WISH TO RESET
            //s2.setValue(250);
            //s2b.setValue(0);
            state.Stub_Length = MaestroA.rounder((0.001*(s2.getValue())+s2b.getValue()*0.000001),6);
                if(state.Stub_Length == 0.0 || state.Stub_Length == 0.5){
                    state.YS = new Complex(0.0, 1.0E130);
                    state.ZS = new Complex(0.0, 0.0);
                    vlab3.setText(" \u221E");
                    vlab4.setText(" \u221E S");
                }
                else{
                    state.YS = new Complex(0.0,MaestroA.rounder(-1.0/EMF.computeZShortStub(state.Stub_Length,state.ZIMP[0]).Imaginary(),8));
                    if(state.YS.Imaginary() >= 0.0){
                        if(state.YS.Imaginary() >= 1.0){
                            vlab4.setText(" j "+MaestroA.rounder(state.YS.Imaginary(),3)+" S");
                        }
                        else{
                            vlab4.setText(" j "+MaestroA.rounder(state.YS.Imaginary(),6)+" S");
                        }
                        
                        if(state.YS.Imaginary()*state.ZIMP[0] >= 1.0){
                            vlab3.setText(" j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],3));
                        }
                        else{
                            vlab3.setText(" j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],6));
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()) >= 1.0){
                            vlab4.setText(" - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),3)+" S");
                        }
                        else{
                            vlab4.setText(" - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),6)+" S");
                        }
                        
                        if(Math.abs(state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText(" - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),3));
                        }
                        else{
                            vlab3.setText(" - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),6));
                        }
                    }
                }
                
            vlab5.setText(""+MaestroA.rounder(state.Stub_Length,6)+" \u03bb");
            repaint();
	}
	
	else if(evt.getSource()==c4){
	    state.StubIsShort = false;
            if(state.Stub_Length <= 0.25){
                s2.setValue(s2.getValue()+250);
            }
            else{
                s2.setValue(s2.getValue()-250);
            }
            if(state.Stub_Length < 0.5){
                s2b.setEnabled(true);
            }
            // USE THIS IF YOU WISH TI RESET
            //s2.setValue(0);
            //s2b.setValue(0);
            state.Stub_Length = MaestroA.rounder((0.001*(s2.getValue())+s2b.getValue()*0.000001),6);
            if(state.Stub_Length == 0.25){
                    state.YS = new Complex(0.0, 1.0E130);
                    state.ZS = new Complex(0.0, 0.0);
                    vlab3.setText(" \u221E");
                    vlab4.setText(" \u221E S");
                }
                else{
                    state.YS = new Complex(0.0,MaestroA.rounder(-1.0/EMF.computeZOpenStub(state.Stub_Length,state.ZIMP[0]).Imaginary(),8));
                    if(state.YS.Imaginary() >= 0.0){
                        if(state.YS.Imaginary() >= 1.0){
                            vlab4.setText(" j "+MaestroA.rounder(state.YS.Imaginary(),3)+" S");
                        }
                        else{
                            vlab4.setText(" j "+MaestroA.rounder(state.YS.Imaginary(),6)+" S");
                        }
                        
                        if(state.YS.Imaginary()*state.ZIMP[0] >= 1.0){
                            vlab3.setText(" j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],3));
                        }
                        else{
                            vlab3.setText(" j "+MaestroA.rounder(state.YS.Imaginary()*state.ZIMP[0],6));
                        }
                    }
                    else{
                        if(Math.abs(state.YS.Imaginary()) >= 1.0){
                            vlab4.setText(" - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),3)+" S");
                        }
                        else{
                            vlab4.setText(" - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()),6)+" S");
                        }
                        
                        if(Math.abs(state.YS.Imaginary()*state.ZIMP[0]) >= 1.0){
                            vlab3.setText(" - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),3));
                        }
                        else{
                            vlab3.setText(" - j "+MaestroA.rounder(Math.abs(state.YS.Imaginary()*state.ZIMP[0]),6));
                        }
                    }
                }
            vlab5.setText(""+MaestroA.rounder(state.Stub_Length,6)+" \u03bb");
            repaint();
	}
    }
}//StubPanel
