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


public class StubPanel extends Panel implements AdjustmentListener, ActionListener, ItemListener{
    //private static final Color bgcolor = new Color(180,147,112);
    //private static final Color bgcolor = new Color(200,200,200);
     private static final Color bgcolor = new Color(216,216,191); // kaki
    private Label lab1, lab2, lab3, lab4, lab5, lab6, lab7, titlelabel, spacelabel;
    private Label vlab4, vlab5, vlab6, vlab7;
    private String titulo = "Unknown Title";
    public CheckboxGroup cgrid1, cgrid2;
    public Checkbox c1, c2, c3, c4;
    private TextField text1;
    public Scrollbar s1, s2;
    private double frequency;
    private int multiplier;
    GridBagLayout gb = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    private static final Font labfont = TheFonts.sanSerif12;
    private static final Font titlefont = TheFonts.bold16;
    private static final int SCROLLMIN=0, SCROLLMAX=10001;
    public Button b1;
    private Stub stub;
    private Trans_State state;
   
    public StubPanel(String titulo,Stub stub,Trans_State state){
	super();
	this.stub = stub;
	this.state = state;
	setBackground(bgcolor);
	this.titulo = titulo;
	setLayout(gb);
	titlelabel  = new Label(titulo,Label.CENTER); 
	titlelabel.setFont(titlefont);
	titlelabel.setForeground(bgcolor);
	lab1 = new Label("Status        ",Label.LEFT);
	lab2 = new Label("Type        ",Label.LEFT);
	lab3 = new Label("Stub Zo [ \u03a9 ]  =      ",Label.RIGHT);
	lab4 = new Label("Position  = ",Label.RIGHT);
	lab5 = new Label("Capacitance  = ",Label.RIGHT);
	lab6 = new Label("Admittance  [ S ] = ",Label.RIGHT);
	lab7 = new Label("   (normalized)   = ",Label.RIGHT);
	spacelabel = new Label("  ",Label.CENTER);
	lab1.setFont(labfont);
	lab2.setFont(labfont);
	lab3.setFont(labfont);
	lab4.setFont(labfont);
	lab5.setFont(labfont);
	lab6.setFont(labfont);
	lab7.setFont(labfont);
	lab1.setForeground(Color.blue);
	lab2.setForeground(Color.blue);
	lab3.setForeground(Color.blue);
	lab4.setForeground(Color.magenta);
	lab5.setForeground(Color.red);
	lab6.setForeground(Color.red);
	lab7.setForeground(Color.red);
	vlab4 = new Label("   "+MaestroA.rounder(stub.getPosition(),5)+" \u03bb",Label.LEFT);
	vlab5 = new Label("   0.0 [ F ]",Label.LEFT);
	vlab6 = new Label("   0.0   ( open )",Label.LEFT);
	vlab7 = new Label("   0.0 ",Label.LEFT);
	vlab4.setFont(labfont);
	vlab5.setFont(labfont);
	vlab6.setFont(labfont);
	vlab7.setFont(labfont);
	cgrid1 = new CheckboxGroup();
	cgrid2 = new CheckboxGroup();
	c1 = new Checkbox("Enabled                      ",cgrid1,false);
	c2 = new Checkbox("Disabled                     ",cgrid1,true);
	c3 = new Checkbox("Capacitance                  ",cgrid2,true);
	c4 = new Checkbox("Inductance                   ",cgrid2,false);
	c1.setBackground(bgcolor);
	c2.setBackground(bgcolor);
	c1.setForeground(Color.blue);
	c2.setForeground(Color.blue);
	c3.setBackground(bgcolor);
	c4.setBackground(bgcolor);
	c3.setForeground(Color.red);
	c4.setForeground(Color.red);
	
	text1 = new TextField("0.0",8);
	
	frequency = 3.0E9;
	multiplier = 1;
	
	s1 = new Scrollbar(Scrollbar.HORIZONTAL,(int)((SCROLLMAX-SCROLLMIN)*(1.0-stub.getPosition()/state.lineLength)),
			    1,SCROLLMIN,SCROLLMAX);
	//s2 = new Scrollbar(Scrollbar.HORIZONTAL,(int)((SCROLLMAX-SCROLLMIN)*(0.25-stub.getLength()/0.25)),
		//	    1,SCROLLMIN,SCROLLMAX);
	s2 = new Scrollbar(Scrollbar.HORIZONTAL,(int)((SCROLLMAX*multiplier-SCROLLMIN)*(0.25/0.25)),
			    1,SCROLLMIN,SCROLLMAX*multiplier);
	
	/*s1.setBackground(Color.lightGray);
	s2.setBackground(Color.lightGray);
	s1.setForeground(Color.black);
	s2.setForeground(Color.black);*/
	
	b1 = new Button("Update");
	b1.setBackground(bgcolor);
	
			
	//try{
	//    MaestroG.addComponent(this,titlelabel,0,0,3,1,
	//	    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	//    } catch(Exception e){e.printStackTrace();}
	
	//try{
	//    MaestroG.addComponent(this,lab1,0,0,1,1,
	//	    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	//    } catch(Exception e){e.printStackTrace();}
	//try{
	//    MaestroG.addComponent(this,lab2,0,2,1,1,
	//	    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	//    } catch(Exception e){e.printStackTrace();}
	/*try{
	    MaestroG.addComponent(this,lab3,0,3,1,1,
		    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	    } catch(Exception e){e.printStackTrace();}*/
	try{
	    MaestroG.addComponent(this,lab4,0,4,1,1,
		    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	    } catch(Exception e){e.printStackTrace();}
	try{
	    MaestroG.addComponent(this,lab5,0,7,1,1,
		    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	    } catch(Exception e){e.printStackTrace();}
	try{
	    MaestroG.addComponent(this,spacelabel,0,6,1,1,
		    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	    } catch(Exception e){e.printStackTrace();}
	try{
	    MaestroG.addComponent(this,lab6,0,11,1,1,
		    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	    } catch(Exception e){e.printStackTrace();}
	try{
	    MaestroG.addComponent(this,lab7,0,12,1,1,
		    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	    } catch(Exception e){e.printStackTrace();}
	try{
	    MaestroG.addComponent(this,c1,0,1,1,1,
		    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	    } catch(Exception e){e.printStackTrace();}
	try{
	    MaestroG.addComponent(this,c2,0,2,1,1,
		    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	    } catch(Exception e){e.printStackTrace();}
	try{
	    MaestroG.addComponent(this,c3,1,1,1,1,
		    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	    } catch(Exception e){e.printStackTrace();}
	try{
	    MaestroG.addComponent(this,c4,1,2,1,1,
		    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	    } catch(Exception e){e.printStackTrace();}
	try{
	    MaestroG.addComponent(this,s1,0,5,3,1,
		    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	    } catch(Exception e){e.printStackTrace();}
	try{
	    MaestroG.addComponent(this,s2,0,8,3,1,
		    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	    } catch(Exception e){e.printStackTrace();}
	try{
	    MaestroG.addComponent(this,vlab4,1,4,1,1,
		    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	    } catch(Exception e){e.printStackTrace();}
	try{
	    MaestroG.addComponent(this,vlab5,1,7,1,1,
		    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	    } catch(Exception e){e.printStackTrace();}
	try{
	    MaestroG.addComponent(this,text1,0,9,2,1,
		    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	    } catch(Exception e){e.printStackTrace();}
	try{
	    MaestroG.addComponent(this,b1,0,10,2,1,
		    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	    } catch(Exception e){e.printStackTrace();}
	try{
	    MaestroG.addComponent(this,vlab6,1,11,2,1,
		    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	    } catch(Exception e){e.printStackTrace();}
	try{
	    MaestroG.addComponent(this,vlab7,1,12,2,1,
		    GridBagConstraints.BOTH,GridBagConstraints.CENTER);
	    } catch(Exception e){e.printStackTrace();}
	
	
	s1.setBackground(Color.lightGray);
	s2.setBackground(Color.lightGray);
	s1.setForeground(Color.black);
	s2.setForeground(Color.black);
	
	//Listeners
	s1.addAdjustmentListener(this);
	s2.addAdjustmentListener(this);
	b1.addActionListener(this);
	c1.addItemListener(this);
	c2.addItemListener(this);
	c3.addItemListener(this);
	c4.addItemListener(this);
	
    
    }
    
    public void paint(Graphics g){
	
    }
    
    public void adjustmentValueChanged(AdjustmentEvent evt){
	double temp;
	
	if(evt.getSource()==s1){
	    stub.setPosition((SCROLLMAX-SCROLLMIN-1-s1.getValue())*state.lineLength/(SCROLLMAX-SCROLLMIN-1));
	    vlab4.setText(""+MaestroA.rounder(stub.getPosition(),4)+" \u03bb");
	}
	else if(evt.getSource()==s2){
	    stub.setLength((SCROLLMAX*multiplier-SCROLLMIN-1-s2.getValue())*0.25/(SCROLLMAX*multiplier-SCROLLMIN-1));
	       
	    if(c3.getState()==true){
		//lab5.setText("Capacitance  = ");
		stub.Open();
		
		double tempcap, printcap;
		tempcap = Complex.Imaginary(stub.getYAsIfOn())/(2.0*Math.PI*state.frequency);
		printcap = Complex.Imaginary(stub.getYAsIfOn())/(2.0*Math.PI*state.frequency);
		
		if (tempcap < 1.0E-9){
		    printcap = tempcap*1.0E12;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ pF ]");
		    text1.setText(""+MaestroA.rounder(printcap,5)*1.0E-12); 
		}
		else if(tempcap < 1.0E-6 && tempcap >= 1.0E-9){
		    printcap = tempcap*1.0E9;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ nF ]");
		    text1.setText(""+MaestroA.rounder(printcap,5)*1.0E-9); 
		}
		else if(tempcap < 1.0E-3 && tempcap >= 1.0E-6){
		    printcap = tempcap*1.0E6;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ \u00b5F ]");
		    text1.setText(""+MaestroA.rounder(printcap,5)*1.0E-6); 
		}
		else if(tempcap < 1.0 && tempcap >= 1.0E-3){
		    printcap = tempcap*1.0E3;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ mF ]");
		    text1.setText(""+MaestroA.rounder(printcap,5)*1.0E-3); 
		}
		else if(tempcap >= 1.0){
		    vlab5.setText(""+MaestroA.rounder(tempcap,5)+" [ F ]");
		    text1.setText(""+MaestroA.rounder(printcap,5)); 
		}
		
		
		temp = Complex.Imaginary(Complex.Multiply(stub.getYAsIfOn(),stub.getZchar()));
		if(stub.getLength() == 0.25){
		    vlab5.setText("   \u221e   [ F ]");
		    vlab6.setText("   \u221e  ( short )");
		    vlab7.setText("   \u221e ");
		}
		else if(stub.getLength() == 0.0 || stub.getLength() == 0.5){
		    vlab6.setText("   0.0   ( open )");
		    vlab7.setText("   0.0 ");
		}
		else{
		    if(temp < 0.0){
		    vlab6.setText("- j "+MaestroA.rounder(Complex.Imaginary(stub.getYAsIfOn())*(-1.0),8));
		    vlab7.setText("- j "+MaestroA.rounder(temp*(-1.0),12));
		  }
		  else{
		    vlab6.setText(" j "+MaestroA.rounder(Complex.Imaginary(stub.getYAsIfOn()),8));
		    vlab7.setText(" j "+MaestroA.rounder(temp,8));
		  }
		}
		
	    }
	    else if(c4.getState()==true){
	    
		//lab5.setText(" Inductance  = ");
		stub.Short();
		
		double tempinduc, printinduc;
		tempinduc =  1.0/(Complex.Imaginary(stub.getYAsIfOn())*(-2.0*Math.PI*state.frequency));
		printinduc = 1.0/(Complex.Imaginary(stub.getYAsIfOn())*(-2.0*Math.PI*state.frequency));
	    
		if (tempinduc < 1.0E-9){
		    printinduc = tempinduc*1.0E12;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ pH ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5)*1.0E-12); 
		}
		else if(tempinduc < 1.0E-6 && tempinduc >= 1.0E-9){
		    printinduc = tempinduc*1.0E9;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ nH ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5)*1.0E-9); 
		}
		else if(tempinduc < 1.0E-3 && tempinduc >= 1.0E-6){
		    printinduc = tempinduc*1.0E6;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ \u00b5H ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5)*1.0E-6); 
		}
		else if(tempinduc < 1.0 && tempinduc >= 1.0E-3){
		    printinduc = tempinduc*1.0E3;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ mH ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5)*1.0E-3); 
		}
		else if(tempinduc >= 1.0){
		    vlab5.setText(""+MaestroA.rounder(tempinduc,5)+" [ H ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5)); 
		}
		
		temp = Complex.Imaginary(Complex.Multiply(stub.getYAsIfOn(),stub.getZchar()));
		
		if(stub.getLength() == 0.0 || stub.getLength() == 0.5){
		    vlab6.setText("   \u221e   ( short )");
		    vlab7.setText("   \u221e ");
		}
		else if(stub.getLength() == 0.25){
		    vlab5.setText("   \u221e   [ H ]");
		    vlab6.setText("   0.0   ( open )");
		    vlab7.setText("   0.0 ");
		}
		else{
		  if(temp < 0.0){
		    vlab6.setText("- j "+MaestroA.rounder(Complex.Imaginary(stub.getYAsIfOn())*(-1.0),8));
		    vlab7.setText("- j "+MaestroA.rounder(temp*(-1.0),8));
		  }
		  else{
		    vlab6.setText(" j "+MaestroA.rounder(Complex.Imaginary(stub.getYAsIfOn()),8));
		    vlab7.setText(" j "+MaestroA.rounder(temp,8));
		  }
		}
		
	    }
	}
    }
    
    public void actionPerformed(ActionEvent evt){
	double temp;
	
	if(evt.getSource()==b1){
	    
	    double tempstub = Double.valueOf(text1.getText()).doubleValue();
	    
	    
	    
	    if(c4.getState()==true){
	    
		stub.Short();
		
		double tempinduc, printinduc,lengthstub;
		
		if(tempstub<0.0){
		    tempstub = 0.0;
		    text1.setText(""+0.0);
		}
		
		tempinduc = tempstub;
		printinduc = tempstub;
		
		vlab6.setText(" -j "+MaestroA.rounder(1.0/(tempinduc*2.0*Math.PI*state.frequency),8));
		vlab7.setText(" -j "+MaestroA.rounder(stub.getZchar()/(tempinduc*2.0*Math.PI*state.frequency),8));
		
		if (tempinduc < 1.0E-9){
		    printinduc = tempinduc*1.0E12;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ pH ]");
		}
		else if(tempinduc < 1.0E-6 && tempinduc >= 1.0E-9){
		    printinduc = tempinduc*1.0E9;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ nH ]");
		}
		else if(tempinduc < 1.0E-3 && tempinduc >= 1.0E-6){
		    printinduc = tempinduc*1.0E6;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ \u00b5H ]");
		}
		else if(tempinduc < 1.0 && tempinduc >= 1.0E-3){
		    printinduc = tempinduc*1.0E3;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ mH ]");
		}
		else if(tempinduc >= 1.0){
		    vlab5.setText(""+MaestroA.rounder(tempinduc,5)+" [ H ]");
		}
		
		lengthstub = Math.atan((tempinduc*2.0*Math.PI*state.frequency)/stub.getZchar())/(2.0*Math.PI);
		s2.setValue((int)((SCROLLMAX*multiplier-SCROLLMIN-1)-((SCROLLMAX*multiplier-SCROLLMIN-1)*lengthstub/0.25)));
		stub.setLength((SCROLLMAX*multiplier-SCROLLMIN-1-s2.getValue())*0.25/(SCROLLMAX*multiplier-SCROLLMIN-1));
		
	    }
	    else if(c3.getState()==true){
		
		stub.Open();
		
		double tempcap, printcap, lengthstub;
		
		if(tempstub<0.0){
		    tempstub = 0.0;
		    text1.setText(""+0.0); 
		}
		
		tempcap = tempstub;
		printcap = tempstub;
		
		vlab6.setText(" j "+MaestroA.rounder(tempcap*2.0*Math.PI*state.frequency,8));
		vlab7.setText(" j "+MaestroA.rounder(stub.getZchar()*(tempcap*2.0*Math.PI*state.frequency),8));
	    
		if (tempcap < 1.0E-9){
		    printcap = tempcap*1.0E12;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ pF ]");
		}
		else if(tempcap < 1.0E-6 && tempcap >= 1.0E-9){
		    printcap = tempcap*1.0E9;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ nF ]");
		}
		else if(tempcap < 1.0E-3 && tempcap >= 1.0E-6){
		    printcap = tempcap*1.0E6;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ \u00b5F ]");
		}
		else if(tempcap < 1.0 && tempcap >= 1.0E-3){
		    printcap = tempcap*1.0E3;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ mF ]");
		}
		else if(tempcap >= 1.0){
		    vlab5.setText(""+MaestroA.rounder(tempcap,5)+" [ F ]");
		}
		lengthstub = Math.atan(stub.getZchar()*tempcap*2.0*Math.PI*state.frequency)/(2.0*Math.PI);
		s2.setValue((int)((SCROLLMAX*multiplier-SCROLLMIN-1)-((SCROLLMAX*multiplier-SCROLLMIN-1)*lengthstub/0.25)));
		stub.setLength((SCROLLMAX*multiplier-SCROLLMIN-1-s2.getValue())*0.25/(SCROLLMAX*multiplier-SCROLLMIN-1));
		
	    }
	    	    
	}
	else if(c3.getState()==true){
		
		stub.Open();
		
		if(c3.getState()==true){
		
		//lab5.setText("Capacitance  = ");
		double tempcap, printcap;
		tempcap = Complex.Imaginary(stub.getYAsIfOn())/(2.0*Math.PI*state.frequency);
		printcap = Complex.Imaginary(stub.getYAsIfOn())/(2.0*Math.PI*state.frequency);
	    
		if (tempcap < 1.0E-9){
		    printcap = tempcap*1.0E12;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ pF ]");
		    text1.setText(""+MaestroA.rounder(printcap,5)*1.0E-12); 
		}
		else if(tempcap < 1.0E-6 && tempcap >= 1.0E-9){
		    printcap = tempcap*1.0E9;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ nF ]");
		    text1.setText(""+MaestroA.rounder(printcap,5)*1.0E-9); 
		}
		else if(tempcap < 1.0E-3 && tempcap >= 1.0E-6){
		    printcap = tempcap*1.0E6;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ \u00b5F ]");
		    text1.setText(""+MaestroA.rounder(printcap,5)*1.0E-6); 
		}
		else if(tempcap < 1.0 && tempcap >= 1.0E-3){
		    printcap = tempcap*1.0E3;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ mF ]");
		    text1.setText(""+MaestroA.rounder(printcap,5)*1.0E-3); 
		}
		else if(tempcap >= 1.0){
		    vlab5.setText(""+MaestroA.rounder(tempcap,5)+" [ F ]");
		    text1.setText(""+MaestroA.rounder(printcap,5)); 
		}
		
		temp = Complex.Imaginary(Complex.Multiply(stub.getYAsIfOn(),stub.getZchar()));
		if(stub.getLength() == 0.25){
		    vlab5.setText("   \u221e   [ F ]");
		    vlab6.setText("   \u221e  ( short )");
		    vlab7.setText("   \u221e ");
		}
		else if(stub.getLength() == 0.0 || stub.getLength() == 0.5){
		    vlab6.setText("   0.0   ( open )");
		    vlab7.setText("   0.0 ");
		}
		else{
		    if(temp < 0.0){
		    vlab6.setText("- j "+MaestroA.rounder(Complex.Imaginary(stub.getYAsIfOn())*(-1.0),8));
		    vlab7.setText("- j "+MaestroA.rounder(temp*(-1.0),8));
		  }
		  else{
		    vlab6.setText(" j "+MaestroA.rounder(Complex.Imaginary(stub.getYAsIfOn()),8));
		    vlab7.setText(" j "+MaestroA.rounder(temp,8));
		  }
		}
		
		temp = Complex.Imaginary(Complex.Multiply(stub.getYAsIfOn(),stub.getZchar()));
		if(stub.getLength() == 0.25){
		    vlab6.setText("   \u221e   ( short )");
		    vlab7.setText("   \u221e ");
		}
		else if(stub.getLength() == 0.0 || stub.getLength() == 0.5){
		    vlab6.setText("   0.0   ( open )");
		    vlab7.setText("   0.0 ");
		}
		else{
		  if(temp < 0.0){
		    vlab6.setText("- j "+MaestroA.rounder(Complex.Imaginary(stub.getYAsIfOn())*(-1.0),8));
		    vlab7.setText("- j "+MaestroA.rounder(temp*(-1.0),8));
		  }
		  else{
		    vlab6.setText(" j "+MaestroA.rounder(Complex.Imaginary(stub.getYAsIfOn()),8));
		    vlab7.setText(" j "+MaestroA.rounder(temp,8));
		  }
		}
		
	}
	else if(c4.getState()==true){
		
		stub.Short();
		
		//lab5.setText(" Inductance  = ");
		double tempinduc, printinduc;
		tempinduc =  1.0/(Complex.Imaginary(stub.getYAsIfOn())*(-2.0*Math.PI*state.frequency));
		printinduc = 1.0/(Complex.Imaginary(stub.getYAsIfOn())*(-2.0*Math.PI*state.frequency));
	    
		if (tempinduc < 1.0E-9){
		    printinduc = tempinduc*1.0E12;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ pH ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5)*1.0E-12);
		}
		else if(tempinduc < 1.0E-6 && tempinduc >= 1.0E-9){
		    printinduc = tempinduc*1.0E9;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ nH ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5)*1.0E-9);
		}
		else if(tempinduc < 1.0E-3 && tempinduc >= 1.0E-6){
		    printinduc = tempinduc*1.0E6;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ \u00b5H ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5)*1.0E-6);
		}
		else if(tempinduc < 1.0 && tempinduc >= 1.0E-3){
		    printinduc = tempinduc*1.0E3;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ mH ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5)*1.0E-3);
		}
		else if(tempinduc >= 1.0){
		    vlab5.setText(""+MaestroA.rounder(tempinduc,5)+" [ H ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5));
		}
				
		stub.Short();
		temp = Complex.Imaginary(Complex.Multiply(stub.getYAsIfOn(),stub.getZchar()));
		
		if(stub.getLength() == 0.0 || stub.getLength() == 0.5){
		    vlab6.setText("   \u221e   ( short )");
		    vlab7.setText("   \u221e ");
		}
		else if(stub.getLength() == 0.25){
		    vlab5.setText("   \u221e   [ H ]");
		    vlab6.setText("   0.0   ( open )");
		    vlab7.setText("   0.0 ");
		}
		else{
		  if(temp < 0.0){
		    vlab6.setText("- j "+MaestroA.rounder(Complex.Imaginary(stub.getYAsIfOn())*(-1.0),8));
		    vlab7.setText("- j "+MaestroA.rounder(temp*(-1.0),8));
		  }
		  else{
		    vlab6.setText(" j "+MaestroA.rounder(Complex.Imaginary(stub.getYAsIfOn()),8));
		    vlab7.setText(" j "+MaestroA.rounder(temp,8));
		  }
		}
		
		
		temp = Complex.Imaginary(Complex.Multiply(stub.getYAsIfOn(),stub.getZchar()));
		if(stub.getLength() == 0.0 || stub.getLength() == 0.5){
		    vlab6.setText("   \u221e   ( short )");
		    vlab7.setText("   \u221e ");
		}
		else if(stub.getLength() == 0.25){
			vlab6.setText("   0.0   ( open )");
			vlab7.setText("   0.0 ");
		}
		else{
		  if(temp < 0.0){
		    vlab6.setText("- j "+MaestroA.rounder(Complex.Imaginary(stub.getYAsIfOn())*(-1.0),8));
		    vlab7.setText("- j "+MaestroA.rounder(temp*(-1.0),8));
		  }
		  else{
		    vlab6.setText(" j "+MaestroA.rounder(Complex.Imaginary(stub.getYAsIfOn()),8));
		    vlab7.setText(" j "+MaestroA.rounder(temp,8));
		  }
		}
		}
	}	       
    }
    
    public void itemStateChanged(ItemEvent evt){
	double temp;
	ItemSelectable ie = evt.getItemSelectable();
	if(evt.getSource()==c3 || evt.getSource()==c4){
		if(c3.getState()==true){
		    
		    lab5.setText("Capacitance  = ");
		    stub.Open();
		    
		double tempcap, printcap;
		tempcap = Complex.Imaginary(stub.getYAsIfOn())/(2.0*Math.PI*state.frequency);
		printcap = Complex.Imaginary(stub.getYAsIfOn())/(2.0*Math.PI*state.frequency);
	    
		if (tempcap < 1.0E-9){
		    printcap = tempcap*1.0E12;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ pF ]");
		    text1.setText(""+MaestroA.rounder(printcap,5)*1.0E-12); 
		}
		else if(tempcap < 1.0E-6 && tempcap >= 1.0E-9){
		    printcap = tempcap*1.0E9;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ nF ]");
		    text1.setText(""+MaestroA.rounder(printcap,5)*1.0E-9); 
		}
		else if(tempcap < 1.0E-3 && tempcap >= 1.0E-6){
		    printcap = tempcap*1.0E6;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ \u00b5F ]");
		    text1.setText(""+MaestroA.rounder(printcap,5)*1.0E-6); 
		}
		else if(tempcap < 1.0 && tempcap >= 1.0E-3){
		    printcap = tempcap*1.0E3;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ mF ]");
		    text1.setText(""+MaestroA.rounder(printcap,5)*1.0E-3); 
		}
		else if(tempcap >= 1.0){
		    vlab5.setText(""+MaestroA.rounder(tempcap,5)+" [ F ]");
		    text1.setText(""+MaestroA.rounder(printcap,5)); 
		}
		   
		    
		    temp = Complex.Imaginary(Complex.Multiply(stub.getYAsIfOn(),stub.getZchar()));
		    if(stub.getLength() == 0.25){
			vlab5.setText("   \u221e   [ F ]");
			vlab6.setText("   \u221e   ( short )");
			vlab7.setText("   \u221e ");
		    }
		    else if(stub.getLength() == 0.0 || stub.getLength() == 0.5){
			vlab6.setText("   0.0   ( open )");
			vlab7.setText("   0.0 ");
		    }
		    else{
			if(temp < 0.0){
			    vlab6.setText("- j "+MaestroA.rounder(Complex.Imaginary(stub.getYAsIfOn())*(-1.0),8));
			    vlab7.setText("- j "+MaestroA.rounder(temp*(-1.0),8));
			}
			else{
			    vlab6.setText(" j "+MaestroA.rounder(Complex.Imaginary(stub.getYAsIfOn()),8));
			    vlab7.setText(" j "+MaestroA.rounder(temp,8));
			}
		    }
		    
		}
		else if(c4.getState()==true){
		    
		    lab5.setText(" Inductance  = ");
		    stub.Short();
		    
		double tempinduc, printinduc;
		tempinduc =  1.0/(Complex.Imaginary(stub.getYAsIfOn())*(-2.0*Math.PI*state.frequency));
		printinduc = 1.0/(Complex.Imaginary(stub.getYAsIfOn())*(-2.0*Math.PI*state.frequency));
	    
		if (tempinduc < 1.0E-9){
		    printinduc = tempinduc*1.0E12;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ pH ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5)*1.0E-12);
		    
		}
		else if(tempinduc < 1.0E-6 && tempinduc >= 1.0E-9){
		    printinduc = tempinduc*1.0E9;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ nH ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5)*1.0E-9);
		}
		else if(tempinduc < 1.0E-3 && tempinduc >= 1.0E-6){
		    printinduc = tempinduc*1.0E6;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ \u00b5H ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5)*1.0E-6);
		}
		else if(tempinduc < 1.0 && tempinduc >= 1.0E-3){
		    printinduc = tempinduc*1.0E3;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ mH ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5)*1.0E-3);
		}
		else if(tempinduc >= 1.0){
		    vlab5.setText(""+MaestroA.rounder(tempinduc,5)+" [ H ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5));
		} 
		    
		    temp = Complex.Imaginary(Complex.Multiply(stub.getYAsIfOn(),stub.getZchar()));
		    if(stub.getLength() == 0.0 || stub.getLength() == 0.5){
			vlab6.setText("   \u221e   ( short )");
			vlab7.setText("   \u221e ");
		    }
		    else if(stub.getLength() == 0.25){
			vlab5.setText("   \u221e   [ H ]");
			vlab6.setText("   0.0   ( open )");
			vlab7.setText("   0.0 ");
		    }
		    else{
			if(temp < 0.0){
			    vlab6.setText("- j "+MaestroA.rounder(Complex.Imaginary(stub.getYAsIfOn())*(-1.0),8));
			    vlab7.setText("- j "+MaestroA.rounder(temp*(-1.0),8));
			}
			else{
			    vlab6.setText(" j "+MaestroA.rounder(Complex.Imaginary(stub.getYAsIfOn()),8));
			    vlab7.setText(" j "+MaestroA.rounder(temp,8));
			}
		    }
		    
		}	 
	}
	if(evt.getSource()==c1 || evt.getSource()==c2){
		if(c1.getState()==true){
		    stub.isEnable(true);
		}
		else if(c2.getState()==true){
		    stub.isEnable(false);
		}	 
	}
    }
    
    public void adjust(){
	    if(c3.getState()==true){
		//lab5.setText("Capacitance  = ");
		stub.Open();
		double tempcap, printcap;
		tempcap = Complex.Imaginary(stub.getYAsIfOn())/(2.0*Math.PI*state.frequency);
		printcap = Complex.Imaginary(stub.getYAsIfOn())/(2.0*Math.PI*state.frequency);
	    
		if (tempcap < 1.0E-9){
		    printcap = tempcap*1.0E12;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ pF ]");
		    text1.setText(""+MaestroA.rounder(printcap,5)*1.0E-12);
		}
		else if(tempcap < 1.0E-6 && tempcap >= 1.0E-9){
		    printcap = tempcap*1.0E9;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ nF ]");
		    text1.setText(""+MaestroA.rounder(printcap,5)*1.0E-9);
		}
		else if(tempcap < 1.0E-3 && tempcap >= 1.0E-6){
		    printcap = tempcap*1.0E6;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ \u00b5F ]");
		    text1.setText(""+MaestroA.rounder(printcap,5)*1.0E-6);
		}
		else if(tempcap < 1.0 && tempcap >= 1.0E-3){
		    printcap = tempcap*1.0E3;
		    vlab5.setText(""+MaestroA.rounder(printcap,5)+" [ mF ]");
		    text1.setText(""+MaestroA.rounder(printcap,5)*1.0E-3);
		}
		else if(tempcap >= 1.0){
		    vlab5.setText(""+MaestroA.rounder(tempcap,5)+" [ F ]");
		    text1.setText(""+MaestroA.rounder(printcap,5));
		}
		else if(stub.getLength() == 0.25){
		    vlab5.setText("   \u221e   [ F ]");
		}
		
		
	    }
	    else if(c4.getState()==true){
	    
		//lab5.setText(" Inductance  = ");
		stub.Short();
		double tempinduc, printinduc;
		tempinduc =  1.0/(Complex.Imaginary(stub.getYAsIfOn())*(-2.0*Math.PI*state.frequency));
		printinduc = 1.0/(Complex.Imaginary(stub.getYAsIfOn())*(-2.0*Math.PI*state.frequency));
	    
		if (tempinduc < 1.0E-9){
		    printinduc = tempinduc*1.0E12;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ pH ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5)*1.0E-12);
		}
		else if(tempinduc < 1.0E-6 && tempinduc >= 1.0E-9){
		    printinduc = tempinduc*1.0E9;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ nH ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5)*1.0E-9);
		}
		else if(tempinduc < 1.0E-3 && tempinduc >= 1.0E-6){
		    printinduc = tempinduc*1.0E6;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ \u00b5H ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5)*1.0E-6);
		}
		else if(tempinduc < 1.0 && tempinduc >= 1.0E-3){
		    printinduc = tempinduc*1.0E3;
		    vlab5.setText(""+MaestroA.rounder(printinduc,5)+" [ mH ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5)*1.0E-3);
		}
		else if(tempinduc >= 1.0){
		    vlab5.setText(""+MaestroA.rounder(tempinduc,5)+" [ H ]");
		    text1.setText(""+MaestroA.rounder(printinduc,5));
		}
		else if(stub.getLength() == 0.25){
		    vlab5.setText("   \u221e   [ H ]");
		}
				
	    }
    }
     
}//StubPanel
