/**
 * LineImpedance.java
 * Electromagnetic Transmission Line Application
 * Application without Smith Chart - Prepared by Umberto Ravaioli 
 * for 6th edition of Fundamentals of Applied Electromagnetics Book
 * May 2009 - All Rights Reserved
 */   
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.awt.font.*;
import java.net.URL;
import java.text.*;
import java.util.Map;
import java.util.Hashtable;
import java.util.jar.Attributes;

public class LineImpedance extends Frame implements AdjustmentListener, ActionListener, ItemListener, WindowListener{
    Instructions instructions;
    //About about;
    TitlePanel titlepanel;
    CircuitCanvas ccan;
    SmithPanel sp;
    SmithPanel2 sp2;
    ChoicePanel cp;
    TransSlidePanel slidepanel;
    Trans_OutputPanel outputpanel;
    Trans_State state;
    FrequencyInputPanel fpanel;
    PC generatorpanel;
    TransLoadPanel loadpanel;
    Trans_MultiStubPanel msp;
    Trans_MultiGraphPanelA mgpa;
    Trans_MultiGraphPanelB mgpb;
    LinePanel linepanel;
    Panel psmith, psmith2;
    Image image;
    
    public Panel pgraph;
    public Panel pout;
    public Panel pinput;
    
    // CHANGE ==================================================================
    public int xmove = 10;
    public int ymove = 34;
    //==========================================================================
    
    Font ttfFont, phiFont, italicFont;

    private static final boolean useOldFonts = true;    

public static void main(String[] args){
        LineImpedance f = new LineImpedance();
        int xxmove = 20;
        int yymove = 41;
        f.setSize(644+xxmove,560+yymove);
        //f.setSize(960,712);
        f.setVisible(true);
        f.setLayout(null);
}

public LineImpedance(){
    setLayout(null);
    String lcOSName = System.getProperty("os.name").toLowerCase();
    boolean MAC_OS_X = lcOSName.startsWith("mac os x");
    //System.out.println(lcOSName);
    
    // CHANGE ==================================================================
    //int xmove = 10;
    //int ymove = 34;
    //==========================================================================
    
    if (!useOldFonts) {
        //getUlabyFonts();
        state = new Trans_State();
        state.ttfFont = ttfFont;
        state.sanSerifFont = ttfFont;
        state.serifFont = ttfFont;
        state.symbolFont = phiFont;
        state.italicFont = phiFont;
        MaestroG.serifFont = ttfFont;
        MaestroG.sanSerifFont = ttfFont;
        MaestroG.italicFont = italicFont;
        MaestroG.useBiggerFont = true;
        TheFonts.setNewFonts(ttfFont, phiFont, italicFont);
    } else {
        state = new Trans_State();
        state.ttfFont = new Font("SanSerif",Font.PLAIN,12);
        state.sanSerifFont = new Font("SanSerif",Font.PLAIN,12);
        state.serifFont = new Font("Serif",Font.PLAIN,12);
        state.symbolFont = new Font("Symbol",Font.PLAIN,12);
        state.italicFont = new Font("Serif",Font.ITALIC,12);
        MaestroG.serifFont = state.serifFont;
        MaestroG.sanSerifFont = state.sanSerifFont;
        MaestroG.italicFont = state.italicFont;
        MaestroG.useBiggerFont = false;
        TheFonts.setOldFonts();
    }

    
    //titlepanel = new TitlePanel(subtitleFont,"Module 2.5","Wave and Input Impedance");
    titlepanel = new TitlePanel(state.ttfFont.deriveFont(Font.BOLD,15f),
                                "Module 2.5","Wave and Input Impedance",
                                true);   // was MAC_OS_X:  use Smaller Font
    titlepanel.setBounds(10+xmove,10+ymove,310,40);
    
    ccan = new CircuitCanvas(state);
    //add(ccan);
    ccan.setBounds(10+xmove,95+ymove,625,125);
    
    instructions = new Instructions(state);
    //instructions.setBounds(12,262,625,286);
    instructions.setBounds(10+xmove,223+ymove,625,322);
    instructions.setVisible(true);


    fpanel = new FrequencyInputPanel(state);
    //add(fpanel);
    fpanel.setBounds(11+xmove,224+ymove,623,37);
    
    sp = new SmithPanel();
    //add(sp);
    sp.setBounds(326+xmove,56+ymove,311,467);
    sp.setxpos(state.xpos);
    sp.setZin(state.Zin,state.lineZ0);
    sp.setZL(state.ZL,state.lineZ0);
    sp.set_swr_circle(true);
    sp.set_swr_line(true);
    //sp.set_arcs(true);
    
    sp2 = new SmithPanel2();
    //add(sp2);
    sp2.setBounds(326+xmove,56+ymove,573,663);
    sp2.setxpos(state.xpos);
    sp2.setZin(state.Zin,state.lineZ0);
    sp2.setZL(state.ZL,state.lineZ0);
    sp2.setVisible(false);
    
    //String arg1[] = {"Options:","  Display Wide Format Plots","  Display Plots & Output Data","  Set Line and Load","  About"};
    //String arg2[] = {"Review:","   Plot","   Output"};
    String arg1[] = {"Options:","  Display Wide Format Plots","  Display Plots & Output Data","  Set Line and Load"};
    String arg2[] = {"Review:","   Plot","   Output"};
    cp = new ChoicePanel(arg1,arg2);
    //add(cp);
    cp.setBounds(326+xmove,11+ymove,308,38);
    
    slidepanel = new TransSlidePanel();
    //add(slidepanel);
    slidepanel.setBounds(11+xmove,54+ymove,623,37);
    slidepanel.setLineLength(state.lineLength, state.lineLength_part1, state.lineLength_part2, state.linecounter1, state.linecounter2);
       
    {
      linepanel = new LinePanel(state);
      //add(linepanel);
      linepanel.setBounds(11+xmove,266+ymove,308,278);
    }

    {
      String[] str1 =  {"Z"};
      String[] str2 =  {" [ \u03a9 ]"};
      loadpanel = new TransLoadPanel("Set Load",str1,str2,state);
      //add(loadpanel);
      loadpanel.setValue(state.ZL,0);
      loadpanel.setBounds(326+xmove,266+ymove,308,278);
    }
    {
      String[] str1 =  {"Vg =","Zg ="};
      String[] str2 =  {" [ V ]"," [ \u03a9 ]"};
      generatorpanel = new PC("Set Generator",str1,str2);
      //add(generatorpanel);
      generatorpanel.setValue(state.generator.getVg(),0);
      generatorpanel.setValue(state.generator.getZg(),1);
      generatorpanel.setBounds(11+xmove,264+ymove,308,288);
    }
    
    msp = new Trans_MultiStubPanel("Set Stubs",state);
    //add(msp);
    msp.setBounds(11+xmove,236+ymove,308,288);

    mgpa = new Trans_MultiGraphPanelA("Impedance");
    //add(mgpa);
    mgpa.setBounds(11+xmove,266+ymove,308,278);

    mgpb = new Trans_MultiGraphPanelB("Impedance");
    //add(mgpb);
    mgpb.setBounds(11+xmove,266+ymove,623,278);
    
    outputpanel = new Trans_OutputPanel(state);
    //add(outputpanel);
    outputpanel.setBounds(326+xmove,266+ymove,308,278);
    
    {
	loadpanel.setVisible(false);
	linepanel.setVisible(false);
	msp.setVisible(false);
	generatorpanel.setVisible(false);
	mgpa.setVisible(false);
        
        // CHANGE ==============================================================
        //mgpb.setVisible(true);
        mgpb.setVisible(false);
        //======================================================================
        
	//about.setVisible(false);
	instructions.setVisible(true);
	outputpanel.setVisible(false);
    }
    
    
    pgraph = new Panel();
	    pgraph.setBackground(Color.black);
	    //add(pgraph);
	    pgraph.setBounds(10+xmove,265+ymove,310,280);
            pgraph.setVisible(false);
    
    pout = new Panel();
	    pout.setBackground(Color.black);
	    //add(pout);
	    pout.setBounds(325+xmove,265+ymove,310,280);
            pout.setVisible(false);
            
    pinput = new Panel();
	    pinput.setBackground(Color.black);
	    //add(pinput);
	    pinput.setBounds(10+xmove,265+ymove,625,280);
            pinput.setVisible(true);
    
    psmith = new Panel();
	    psmith.setBackground(Color.black);
	    //add(psmith);
	    psmith.setBounds(325+xmove,55+ymove,313,470);
	    
    psmith2 = new Panel();
	    psmith2.setBackground(Color.black);
	    //add(psmith2);
	    psmith2.setBounds(325+xmove,55+ymove,575,665);
	    psmith2.setVisible(false);
    
    Panel pslide = new Panel();
	    pslide.setBackground(Color.black);
	    //add(pslide);
	    pslide.setBounds(10+xmove,53+ymove,625,39);
	    
    Panel pchoice = new Panel();
	    pchoice.setBackground(Color.black);
	    //add(pchoice);
	    pchoice.setBounds(325+xmove,10+ymove,310,40);
	    
    Panel ptitle = new Panel();
	    ptitle.setBackground(Color.black);
	    //add(ptitle);
	    ptitle.setBounds(10+xmove,10+ymove,310,40);
            
    Panel pfreq = new Panel();
	    pfreq.setBackground(Color.black);
	    //add(pfreq);
	    pfreq.setBounds(10+xmove,223+ymove,625,39);
	        
    Panel p0 = new Panel();
	    p0.setBackground(Color.cyan);
	    //add(p0);
	    p0.setBounds(3+xmove,3+ymove,638,548);
	    
    Panel p00 = new Panel();
	    p00.setBackground(Color.black);
	    //add(p00);
	    p00.setBounds(xmove,ymove,644,554);
    
    //Panel p000 = new Panel();
	//    p000.setBackground(Color.white);
	    //add(p000);
	//    p000.setBounds(0,0,925,745);
    
            //if(state.this_year > line.magicyear || (state.this_year == line.magicyear && state.this_month > line.magicmonth)){
	    //state.LicenseExpired = true;
            //}
            //else
            //{ 	    
	    
            add(instructions);
	    //add(about);
            add(titlepanel); 	    
	    add(ccan); 	    
	    //add(sp); 	    
	    //add(sp2); 	    
	    add(cp);
	    add(fpanel); 	    
	    add(slidepanel);
	    add(linepanel);
	    add(loadpanel);
	    //add(generatorpanel);
	    add(outputpanel);
            
	    //add(msp);
	    add(mgpa);
	    add(mgpb);
            
            
	    add(pgraph);
            add(pout);
            
            add(pinput);
	    //add(psmith);
	    //add(psmith2);
	    
	    add(pslide);
	    add(pchoice);
	    add(ptitle); 
	    add(pfreq);
            add(p0); 
	    add(p00);
            
            //add(p000);
	    state.LicenseExpired = false; 	
            //}

    
    //Listeners
            
    instructions.bupdate.addActionListener(this);
    fpanel.bupdate.addActionListener(this);
    this.addWindowListener(this);
    slidepanel.slider.addAdjustmentListener(this);
    slidepanel.slider2.addAdjustmentListener(this);
    
    // CHANGE ==================================================================
    slidepanel.b2a.addActionListener(this);
    slidepanel.b2b.addActionListener(this);
    slidepanel.b3a.addActionListener(this);
    slidepanel.b3b.addActionListener(this);
    fpanel.b2a.addActionListener(this);
    fpanel.b2b.addActionListener(this);
    fpanel.b3a.addActionListener(this);
    fpanel.b3b.addActionListener(this);
    //==========================================================================
    fpanel.slider2.addAdjustmentListener(this);
    fpanel.slider1.addAdjustmentListener(this);
    
    linepanel.lowpanel.b1.addActionListener(this);
    linepanel.c3.addItemListener(this);
    linepanel.c4.addItemListener(this);
    loadpanel.b1.addActionListener(this);
    linepanel.c1.addItemListener(this);
    linepanel.c2.addItemListener(this);
    generatorpanel.b1.addActionListener(this);
    cp.c1.addItemListener(this);
    cp.c2.addItemListener(this);
    mgpa.c1.addItemListener(this);
   
    msp.stp1.c1.addItemListener(this);
    msp.stp1.c2.addItemListener(this);
    msp.stp1.c3.addItemListener(this);
    msp.stp1.c4.addItemListener(this);
    msp.stp1.s1.addAdjustmentListener(this);
    msp.stp1.s2.addAdjustmentListener(this);
    msp.stp1.b1.addActionListener(this);
    msp.stp2.c1.addItemListener(this);
    msp.stp2.c2.addItemListener(this);
    msp.stp2.c3.addItemListener(this);
    msp.stp2.c4.addItemListener(this);
    msp.stp2.s1.addAdjustmentListener(this);
    msp.stp2.s2.addAdjustmentListener(this);
    msp.stp2.b1.addActionListener(this);
    msp.stp3.c1.addItemListener(this);
    msp.stp3.c2.addItemListener(this);
    msp.stp3.c3.addItemListener(this);
    msp.stp3.c4.addItemListener(this);
    msp.stp3.s1.addAdjustmentListener(this);
    msp.stp3.s2.addAdjustmentListener(this);
    msp.stp3.b1.addActionListener(this);
    send_shock_wave();
    mgpa.plotImpedance(state);
    mgpb.plotImpedance(state);
    
    sp.colore.addActionListener(this);
    sp2.colore.addActionListener(this);

    sp.small.addActionListener(this);
    sp2.large.addActionListener(this);
    sp.scon.imp.addItemListener(this);
    sp.scon.adm.addItemListener(this);
    sp.scon.swr.addItemListener(this);
    sp.scon.swrline.addItemListener(this);
    sp2.scon.imp.addItemListener(this);
    sp2.scon.adm.addItemListener(this);
    sp2.scon.swr.addItemListener(this);
    sp2.scon.swrline.addItemListener(this);
}

   
/*
public void paint(Graphics g){
    
    Font licensefont = new Font("SanSerif",Font.BOLD,18); 	
	g.setColor(Color.white);	 	
	g.fillRect(0,0,945,765); 	
	g.drawImage(image,5,535,this);
		
	if(state.LicenseExpired){
	g.setFont(licensefont);
	
	g.setColor(Color.red);
	g.drawString("The software license has expired.", 50, 200);
	g.setColor(Color.black);
	g.drawString("Obtain updated files from www.amanogawa.com", 50, 230);
	} 
}
*/

public void paint(Graphics g){
    
    Font licensefont = new Font("SanSerif",Font.BOLD,18); 
    Font fonto = new Font("SanSerif",Font.PLAIN,12);
    Font fontc = new Font("SanSerif",Font.BOLD,16);
    
	Graphics2D g2d = (Graphics2D)g;
        //g.setColor(Color.white);	
	//g.fillRect(0,0,644,580);  	
	
        /*
	if(state.LicenseExpired){
	    g.setFont(licensefont);
	
	    g.setColor(Color.red);
	    g.drawString("The software license has expired.", 50, 200);
	    g.setColor(Color.black);
	    g.drawString("Obtain updated files from www.amanogawa.com", 50, 230);
	} 
        
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        int annonuovo = 2006;
        int anno = 2006;
        
        if(anno > state.this_year){
            annonuovo = anno;
        }
        else{
            annonuovo = state.this_year;
        }
        g.setColor(Color.red.darker());
        g.setFont(fontc);
        //g.drawString("\u00a9",10,567);
        g.setFont(fonto);
        //g.drawString("Amanogawa, "+annonuovo+" - All Rights Reserved",30,565);
        */
}

public void start(){}

public void stop(){}

public void windowClosing(WindowEvent e) {
        dispose();
        System.exit(0);
    }
    
    public void windowOpened(WindowEvent evt){}
    
    public void windowIconified(WindowEvent evt){}
    
    public void windowClosed(WindowEvent evt){}
    
    public void windowDeiconified(WindowEvent evt){}
    
    public void windowActivated(WindowEvent evt){}
    
    public void windowDeactivated(WindowEvent evt){}

public void adjustmentValueChanged(AdjustmentEvent evt){
    
    if(evt.getSource()==slidepanel.slider){
        slidepanel.slider2.setValue(slidepanel.slider2.getMaximum());
	state.xpos = slidepanel.getValue();
        
	// not needed with double slider - necessary with single slider 
        //if(slidepanel.slider.getValue() == 0){
	  //  state.xpos = state.lineLength;
	//}
        
        if(state.xpos == state.lineLength){
	    slidepanel.slider2.setEnabled(false);  
	}
	else{
	    slidepanel.slider2.setEnabled(true);
	}

	state.xpos_meters = state.xpos*state.wavelength;
	send_shock_wave();
        ccan.repaint();
	sp.setZin(state.Zin, state.lineZ0);
	sp2.setZin(state.Zin, state.lineZ0);
        mgpa.tgc1.setXpos(state.xpos);
	mgpa.tgc2.setXpos(state.xpos);
        mgpb.tgc1.setXpos(state.xpos);
	mgpb.tgc2.setXpos(state.xpos);
    }
    if(evt.getSource()==slidepanel.slider2){
	
	if(slidepanel.slider.getValue() == 0){
	    if(slidepanel.slider2.getValue() < (slidepanel.SCROLLMAX2 - state.linecounter2)){
		slidepanel.slider2.setValue(slidepanel.SCROLLMAX2 - state.linecounter2-1);
	    }
	}
	state.xpos = slidepanel.getValue()+slidepanel.getValue2();
        
        state.xpos_meters = state.xpos*state.wavelength;
	send_shock_wave();
        ccan.repaint();
	sp.setZin(state.Zin, state.lineZ0);
	sp2.setZin(state.Zin, state.lineZ0);
	mgpa.tgc1.setXpos(state.xpos);
	mgpa.tgc2.setXpos(state.xpos);
        mgpb.tgc1.setXpos(state.xpos);
	mgpb.tgc2.setXpos(state.xpos);
    }

    if(evt.getSource()==fpanel.slider2 || evt.getSource()==fpanel.slider1){
	state.ignition();
	
	if(state.Is_Wavelength){
	    state.lineLength_meters = linepanel.lowpanel.getValue(2)*state.wavelength;
	    //slidepanel.setLineLength(state.lineLength);
            slidepanel.setLineLength(state.lineLength, state.lineLength_part1, state.lineLength_part2, state.linecounter1, state.linecounter2);
    
	    //slidepanel.setValue(state.xpos);
	    double temp1;
            temp1 = state.xpos;
		    
	    state.xpos_meters = state.xpos * state.wavelength;
	    
	    sp.setxpos(state.xpos);
	    sp.setZin(state.Zin,state.lineZ0);
	    sp.setZL(state.ZL,state.lineZ0);
	    
	    sp2.setxpos(state.xpos);
	    sp2.setZin(state.Zin,state.lineZ0);
	    sp2.setZL(state.ZL,state.lineZ0);
	    
	    mgpa.tgc1.setXpos(state.xpos);
	    mgpa.tgc2.setXpos(state.xpos);
	    mgpa.plotImpedance(state);
	    mgpb.tgc1.setXpos(state.xpos);
	    mgpb.tgc2.setXpos(state.xpos);
	    mgpb.plotImpedance(state);
	    
            ccan.repaint();
	    outputpanel.canvas1.repaint();
	    outputpanel.canvas2.repaint();   
	    state.ignition();
	    mgpa.tgc1.repaint();
	    mgpa.tgc2.repaint();
            
            mgpb.tgc1.repaint();
	    mgpb.tgc2.repaint();
                        
            if(state.lineLength_meters > (15.0*state.wavelength)){
                state.IsLengthTooLarge = true;
                state.IsLengthTooSmall = false;
                mgpa.setTooLarge(state.IsLengthTooLarge);
                mgpa.setTooSmall(state.IsLengthTooSmall);
                mgpa.repaint();
            }
            else if(state.lineLength < 1.0E-4){
                state.IsLengthTooLarge = false;
                state.IsLengthTooSmall = true;
                mgpa.setTooLarge(state.IsLengthTooLarge);
                mgpa.setTooSmall(state.IsLengthTooSmall);
                mgpa.repaint();
            }
            else{
                state.IsLengthTooLarge = false;
                state.IsLengthTooSmall = false;
                mgpa.setTooLarge(state.IsLengthTooLarge);
                mgpa.setTooSmall(state.IsLengthTooSmall);
                mgpa.repaint();
            }
            
            if(state.lineLength_meters > (15.0*state.wavelength)){
                state.IsLengthTooLarge2 = true;
                state.IsLengthTooSmall2 = false;
                mgpb.setTooLarge(state.IsLengthTooLarge2);
                mgpb.setTooSmall(state.IsLengthTooSmall2);
                mgpb.repaint();
            }
            else if(state.lineLength < 1.0E-4){
                state.IsLengthTooLarge2 = false;
                state.IsLengthTooSmall2 = true;
                mgpb.setTooLarge(state.IsLengthTooLarge2);
                mgpb.setTooSmall(state.IsLengthTooSmall2);
                mgpb.repaint();
            }
            else{
                state.IsLengthTooLarge2 = false;
                state.IsLengthTooSmall2 = false;
                mgpb.setTooLarge(state.IsLengthTooLarge2);
                mgpb.setTooSmall(state.IsLengthTooSmall2);
                mgpb.repaint();
            }
            
	}
	else{
	    int temp;
	    
            state.ignition();
            
            //---------------------
            
            state.xpos = 0.0;
	    state.xpos_meters = 0.0;
            
            int templine = 10000;
	    int templine2 = 1000;
            
            if(state.lineLength < 0.0001){
		templine = (int)(100000000.0*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/100000000.0),5);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,7);
		templine2 = (int)(100000000000.0*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,8);
	    }
            else if(state.lineLength >= 0.0001 && state.lineLength < 0.001){
		templine = (int)(10000000.0*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/10000000.0),5);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,7);
		templine2 = (int)(10000000000.0*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,8);
	    }
            else if(state.lineLength >= 0.001 && state.lineLength < 0.01){
		templine = (int)(1000000.0*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/1000000.0),5);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,7);
		templine2 = (int)(1000000000.0*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,8);
	    }
            else if(state.lineLength >= 0.01 && state.lineLength < 0.1){
		templine = (int)(100000.0*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/100000.0),5);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,7);
		templine2 = (int)(100000000.0*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,8);
	    }
            else if(state.lineLength >= 0.1 && state.lineLength < 1.0){
		templine = (int)(10000*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/10000.0),5);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,7);
		templine2 = (int)(10000000*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,8);
	    }
	    else if(state.lineLength >= 1.0 && state.lineLength < 10.0){
		templine = (int)(1000*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/1000.0),5);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,6);
		templine2 = (int)(1000000*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,7);
	    }
	    else if(state.lineLength >= 10.0 && state.lineLength < 100.0){
		templine = (int)(100*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/100.0),4);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,5);
		templine2 = (int)(100000*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,6);
	    }
	    else if(state.lineLength >= 100.0 && state.lineLength < 1000.0){
		templine = (int)(10*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/10.0),3);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,4);
		templine2 = (int)(10000*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,5);
	    }
	    else if(state.lineLength >= 1000.0 && state.lineLength < 10000.0){
		templine = (int)(state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine),2);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,3);
		templine2 = (int)(1000*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,4);
	    }
	    else if(state.lineLength >= 10000.0 && state.lineLength <= 100000.0){
		templine = (int)(state.lineLength/10);
		state.lineLength_part1 = MaestroA.rounder((double)(templine)*10,2);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,2);
		templine2 = (int)(100*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,3);
	    }
	    else if(state.lineLength > 100000.0 ){
		state.lineLength = 100000.0;
		templine = (int)(state.lineLength/100);
		state.lineLength_part1 = MaestroA.rounder((double)(templine)*100,2);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,3);
		templine2 = (int)(1000*state.lineLength_part2);
	    }
	    state.linecounter1 = templine;
	    state.linecounter2 = templine2;
	    
	    state.ignition();
	    slidepanel.setLineLength(state.lineLength,state.lineLength_part1,state.lineLength_part2,state.linecounter1,state.linecounter2);
	    send_shock_wave();
	    
            state.xpos = 0.0;
	    state.xpos_meters = 0.0;
	    slidepanel.reset();
            
	    sp.setxpos(state.xpos);
	    sp.setZin(state.Zin,state.lineZ0);
	    sp.setZL(state.ZL,state.lineZ0);
	    
	    sp2.setxpos(state.xpos);
	    sp2.setZin(state.Zin,state.lineZ0);
	    sp2.setZL(state.ZL,state.lineZ0);
	    
	    mgpa.tgc1.setXpos(state.xpos);
	    mgpa.tgc2.setXpos(state.xpos);
	    mgpa.plotImpedance(state);
	    mgpb.tgc1.setXpos(state.xpos);
	    mgpb.tgc2.setXpos(state.xpos);
	    mgpb.plotImpedance(state);
	    
            ccan.repaint();
	    outputpanel.canvas1.repaint();
	    outputpanel.canvas2.repaint();   
	    state.ignition();
	    mgpa.tgc1.repaint();
	    mgpa.tgc2.repaint();
	    mgpb.tgc1.repaint();
	    mgpb.tgc2.repaint();
	    if(state.lineLength_meters > (15.0*state.wavelength)){
                state.IsLengthTooLarge = true;
                state.IsLengthTooSmall = false;
                mgpa.setTooLarge(state.IsLengthTooLarge);
                mgpa.setTooSmall(state.IsLengthTooSmall);
                mgpa.repaint();
            }
            else if(state.lineLength < 1.0E-4){
                state.IsLengthTooLarge = false;
                state.IsLengthTooSmall = true;
                mgpa.setTooLarge(state.IsLengthTooLarge);
                mgpa.setTooSmall(state.IsLengthTooSmall);
                mgpa.repaint();
            }
            else{
                state.IsLengthTooLarge = false;
                state.IsLengthTooSmall = false;
                mgpa.setTooLarge(state.IsLengthTooLarge);
                mgpa.setTooSmall(state.IsLengthTooSmall);
                mgpa.repaint();
            }
            
            if(state.lineLength_meters > (15.0*state.wavelength)){
                state.IsLengthTooLarge2 = true;
                state.IsLengthTooSmall2 = false;
                mgpb.setTooLarge(state.IsLengthTooLarge2);
                mgpb.setTooSmall(state.IsLengthTooSmall2);
                mgpb.repaint();
            }
            else if(state.lineLength < 1.0E-4){
                state.IsLengthTooLarge2 = false;
                state.IsLengthTooSmall2 = true;
                mgpb.setTooLarge(state.IsLengthTooLarge2);
                mgpb.setTooSmall(state.IsLengthTooSmall2);
                mgpb.repaint();
            }
            else{
                state.IsLengthTooLarge2 = false;
                state.IsLengthTooSmall2 = false;
                mgpb.setTooLarge(state.IsLengthTooLarge2);
                mgpb.setTooSmall(state.IsLengthTooSmall2);
                mgpb.repaint();
            }
            
            if(state.frequency <state.f_bottom || state.frequency > state.f_top){
                slidepanel.slider.setEnabled(false);
                slidepanel.slider2.setEnabled(false);
            }
            else{
                slidepanel.slider.setEnabled(true);
                slidepanel.slider2.setEnabled(true);
            }
            
	}	
    }
    
    //position and length sliders for stub 1
    else if(evt.getSource()==msp.stp1.s1 || evt.getSource()==msp.stp1.s2){
	if(state.stub[0].isEnable()){
	    send_shock_wave();
	}
    }
    //position and length sliders for stub 2
    else if(evt.getSource()==msp.stp2.s1 || evt.getSource()==msp.stp2.s2){
	if(state.stub[1].isEnable()){
	    send_shock_wave();
	}
    }
    //position and length sliders for stub 3
    else if(evt.getSource()==msp.stp3.s1 || evt.getSource()==msp.stp3.s2){
	if(state.stub[2].isEnable()){
	    send_shock_wave();
	}
    }	 
}

public void actionPerformed(ActionEvent evt){
        
    //if(evt.getSource()==about.bupdate){
    //          about.setVisible(false);
    //          if(state.OptionOne){cp.c1.select("  Display Plots & Output Data");}
    //          else if(state.OptionTwo){cp.c1.select("  Display Wide Format Plots");}
    //          else if(state.OptionThree){cp.c1.select("  Set Line and Load");}
    //      }
    
            //if(evt.getSource()==instructions.bupdate){ 
            //    instructions.setVisible(false);
            //}
            
    if(evt.getSource()==fpanel.b2a || evt.getSource()==fpanel.b2b ||
       evt.getSource()==fpanel.b3a || evt.getSource()==fpanel.b3b ){
                
        state.ignition();
	
	if(state.Is_Wavelength){
	    state.lineLength_meters = linepanel.lowpanel.getValue(2)*state.wavelength;
	    //slidepanel.setLineLength(state.lineLength);
            slidepanel.setLineLength(state.lineLength, state.lineLength_part1, state.lineLength_part2, state.linecounter1, state.linecounter2);
    
	    //slidepanel.setValue(state.xpos);
	    double temp1;
            temp1 = state.xpos;
		    
	    state.xpos_meters = state.xpos * state.wavelength;
	    
	    sp.setxpos(state.xpos);
	    sp.setZin(state.Zin,state.lineZ0);
	    sp.setZL(state.ZL,state.lineZ0);
	    
	    sp2.setxpos(state.xpos);
	    sp2.setZin(state.Zin,state.lineZ0);
	    sp2.setZL(state.ZL,state.lineZ0);
	    
	    mgpa.tgc1.setXpos(state.xpos);
	    mgpa.tgc2.setXpos(state.xpos);
	    mgpa.plotImpedance(state);
	    mgpb.tgc1.setXpos(state.xpos);
	    mgpb.tgc2.setXpos(state.xpos);
	    mgpb.plotImpedance(state);
	    
            ccan.repaint();
	    outputpanel.canvas1.repaint();
	    outputpanel.canvas2.repaint();   
	    state.ignition();
	    mgpa.tgc1.repaint();
	    mgpa.tgc2.repaint();
            
            mgpb.tgc1.repaint();
	    mgpb.tgc2.repaint();
                        
            if(state.lineLength_meters > (15.0*state.wavelength)){
                state.IsLengthTooLarge = true;
                state.IsLengthTooSmall = false;
                mgpa.setTooLarge(state.IsLengthTooLarge);
                mgpa.setTooSmall(state.IsLengthTooSmall);
                mgpa.repaint();
            }
            else if(state.lineLength < 1.0E-4){
                state.IsLengthTooLarge = false;
                state.IsLengthTooSmall = true;
                mgpa.setTooLarge(state.IsLengthTooLarge);
                mgpa.setTooSmall(state.IsLengthTooSmall);
                mgpa.repaint();
            }
            else{
                state.IsLengthTooLarge = false;
                state.IsLengthTooSmall = false;
                mgpa.setTooLarge(state.IsLengthTooLarge);
                mgpa.setTooSmall(state.IsLengthTooSmall);
                mgpa.repaint();
            }
            
            if(state.lineLength_meters > (15.0*state.wavelength)){
                state.IsLengthTooLarge2 = true;
                state.IsLengthTooSmall2 = false;
                mgpb.setTooLarge(state.IsLengthTooLarge2);
                mgpb.setTooSmall(state.IsLengthTooSmall2);
                mgpb.repaint();
            }
            else if(state.lineLength < 1.0E-4){
                state.IsLengthTooLarge2 = false;
                state.IsLengthTooSmall2 = true;
                mgpb.setTooLarge(state.IsLengthTooLarge2);
                mgpb.setTooSmall(state.IsLengthTooSmall2);
                mgpb.repaint();
            }
            else{
                state.IsLengthTooLarge2 = false;
                state.IsLengthTooSmall2 = false;
                mgpb.setTooLarge(state.IsLengthTooLarge2);
                mgpb.setTooSmall(state.IsLengthTooSmall2);
                mgpb.repaint();
            }
            
	}
	else{
	    int temp;
	    
            state.ignition();
            
            //---------------------
            
            state.xpos = 0.0;
	    state.xpos_meters = 0.0;
            
            int templine = 10000;
	    int templine2 = 1000;
            
            if(state.lineLength < 0.0001){
		templine = (int)(100000000.0*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/100000000.0),5);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,7);
		templine2 = (int)(100000000000.0*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,8);
	    }
            else if(state.lineLength >= 0.0001 && state.lineLength < 0.001){
		templine = (int)(10000000.0*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/10000000.0),5);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,7);
		templine2 = (int)(10000000000.0*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,8);
	    }
            else if(state.lineLength >= 0.001 && state.lineLength < 0.01){
		templine = (int)(1000000.0*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/1000000.0),5);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,7);
		templine2 = (int)(1000000000.0*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,8);
	    }
            else if(state.lineLength >= 0.01 && state.lineLength < 0.1){
		templine = (int)(100000.0*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/100000.0),5);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,7);
		templine2 = (int)(100000000.0*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,8);
	    }
            else if(state.lineLength >= 0.1 && state.lineLength < 1.0){
		templine = (int)(10000*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/10000.0),5);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,7);
		templine2 = (int)(10000000*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,8);
	    }
	    else if(state.lineLength >= 1.0 && state.lineLength < 10.0){
		templine = (int)(1000*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/1000.0),5);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,6);
		templine2 = (int)(1000000*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,7);
	    }
	    else if(state.lineLength >= 10.0 && state.lineLength < 100.0){
		templine = (int)(100*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/100.0),4);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,5);
		templine2 = (int)(100000*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,6);
	    }
	    else if(state.lineLength >= 100.0 && state.lineLength < 1000.0){
		templine = (int)(10*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/10.0),3);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,4);
		templine2 = (int)(10000*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,5);
	    }
	    else if(state.lineLength >= 1000.0 && state.lineLength < 10000.0){
		templine = (int)(state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine),2);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,3);
		templine2 = (int)(1000*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,4);
	    }
	    else if(state.lineLength >= 10000.0 && state.lineLength <= 100000.0){
		templine = (int)(state.lineLength/10);
		state.lineLength_part1 = MaestroA.rounder((double)(templine)*10,2);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,2);
		templine2 = (int)(100*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,3);
	    }
	    else if(state.lineLength > 100000.0 ){
		state.lineLength = 100000.0;
		templine = (int)(state.lineLength/100);
		state.lineLength_part1 = MaestroA.rounder((double)(templine)*100,2);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,3);
		templine2 = (int)(1000*state.lineLength_part2);
	    }
	    state.linecounter1 = templine;
	    state.linecounter2 = templine2;
	    
	    state.ignition();
	    slidepanel.setLineLength(state.lineLength,state.lineLength_part1,state.lineLength_part2,state.linecounter1,state.linecounter2);
	    send_shock_wave();
	    
            state.xpos = 0.0;
	    state.xpos_meters = 0.0;
	    slidepanel.reset();
            
	    sp.setxpos(state.xpos);
	    sp.setZin(state.Zin,state.lineZ0);
	    sp.setZL(state.ZL,state.lineZ0);
	    
	    sp2.setxpos(state.xpos);
	    sp2.setZin(state.Zin,state.lineZ0);
	    sp2.setZL(state.ZL,state.lineZ0);
	    
	    mgpa.tgc1.setXpos(state.xpos);
	    mgpa.tgc2.setXpos(state.xpos);
	    mgpa.plotImpedance(state);
	    mgpb.tgc1.setXpos(state.xpos);
	    mgpb.tgc2.setXpos(state.xpos);
	    mgpb.plotImpedance(state);
	    
            ccan.repaint();
	    outputpanel.canvas1.repaint();
	    outputpanel.canvas2.repaint();   
	    state.ignition();
	    mgpa.tgc1.repaint();
	    mgpa.tgc2.repaint();
	    mgpb.tgc1.repaint();
	    mgpb.tgc2.repaint();
	    if(state.lineLength_meters > (15.0*state.wavelength)){
                state.IsLengthTooLarge = true;
                state.IsLengthTooSmall = false;
                mgpa.setTooLarge(state.IsLengthTooLarge);
                mgpa.setTooSmall(state.IsLengthTooSmall);
                mgpa.repaint();
            }
            else if(state.lineLength < 1.0E-4){
                state.IsLengthTooLarge = false;
                state.IsLengthTooSmall = true;
                mgpa.setTooLarge(state.IsLengthTooLarge);
                mgpa.setTooSmall(state.IsLengthTooSmall);
                mgpa.repaint();
            }
            else{
                state.IsLengthTooLarge = false;
                state.IsLengthTooSmall = false;
                mgpa.setTooLarge(state.IsLengthTooLarge);
                mgpa.setTooSmall(state.IsLengthTooSmall);
                mgpa.repaint();
            }
            
            if(state.lineLength_meters > (15.0*state.wavelength)){
                state.IsLengthTooLarge2 = true;
                state.IsLengthTooSmall2 = false;
                mgpb.setTooLarge(state.IsLengthTooLarge2);
                mgpb.setTooSmall(state.IsLengthTooSmall2);
                mgpb.repaint();
            }
            else if(state.lineLength < 1.0E-4){
                state.IsLengthTooLarge2 = false;
                state.IsLengthTooSmall2 = true;
                mgpb.setTooLarge(state.IsLengthTooLarge2);
                mgpb.setTooSmall(state.IsLengthTooSmall2);
                mgpb.repaint();
            }
            else{
                state.IsLengthTooLarge2 = false;
                state.IsLengthTooSmall2 = false;
                mgpb.setTooLarge(state.IsLengthTooLarge2);
                mgpb.setTooSmall(state.IsLengthTooSmall2);
                mgpb.repaint();
            }
            
            if(state.frequency <state.f_bottom || state.frequency > state.f_top){
                slidepanel.slider.setEnabled(false);
                slidepanel.slider2.setEnabled(false);
            }
            else{
                slidepanel.slider.setEnabled(true);
                slidepanel.slider2.setEnabled(true);
            }
            
	}
                
    }
            
            
            if(evt.getSource()==slidepanel.b2a || evt.getSource()==slidepanel.b2b){
                slidepanel.slider2.setValue(slidepanel.slider2.getMaximum());
                state.xpos = slidepanel.getValue();
                
                if(state.xpos == state.lineLength){
                    slidepanel.slider2.setEnabled(false);  
                }
                else{
                    slidepanel.slider2.setEnabled(true);
                }

                state.xpos_meters = state.xpos*state.wavelength;
                send_shock_wave();
                ccan.repaint();
                sp.setZin(state.Zin, state.lineZ0);
                sp2.setZin(state.Zin, state.lineZ0);
                mgpa.tgc1.setXpos(state.xpos);
                mgpa.tgc2.setXpos(state.xpos);
                mgpb.tgc1.setXpos(state.xpos);
                mgpb.tgc2.setXpos(state.xpos);
            }
            
            if(evt.getSource()==slidepanel.b3a || evt.getSource()==slidepanel.b3b){
                if(slidepanel.slider.getValue() == 0){
                    if(slidepanel.slider2.getValue() < (slidepanel.SCROLLMAX2 - state.linecounter2)){
                        slidepanel.slider2.setValue(slidepanel.SCROLLMAX2 - state.linecounter2-1);
                    }
                }
                state.xpos = slidepanel.getValue()+slidepanel.getValue2();

                state.xpos_meters = state.xpos*state.wavelength;
                send_shock_wave();
                ccan.repaint();
                sp.setZin(state.Zin, state.lineZ0);
                sp2.setZin(state.Zin, state.lineZ0);
                mgpa.tgc1.setXpos(state.xpos);
                mgpa.tgc2.setXpos(state.xpos);
                mgpb.tgc1.setXpos(state.xpos);
                mgpb.tgc2.setXpos(state.xpos);
            }
            
            if(evt.getSource()==fpanel.bupdate){ 
                instructions.setVisible(true);
                
                // CHANGE ======================================================
                instructions.setBounds(10+xmove,223+ymove,625,322);
                //==============================================================
            }
                
           
            if(evt.getSource()==instructions.bupdate){ 
                instructions.setVisible(false);
                
                // CHANGE ======================================================
                instructions.setBounds(10+xmove,223+ymove+10000,625,322);
                //==============================================================
                
                if(state.OptionOne){
                    loadpanel.setVisible(false);
		    linepanel.setVisible(false);
                    
		    mgpa.setVisible(true);
		    mgpa.tgc1.setVisible(true);
		    mgpa.tgc2.setVisible(true);
		    
                    mgpb.setVisible(false);
		    mgpb.tgc1.setVisible(false);
		    mgpb.tgc2.setVisible(false);
		    
                    outputpanel.setVisible(true);
		    mgpa.plotImpedance(state);
                    mgpb.plotImpedance(state);
                    pgraph.setVisible(true);
                    pout.setVisible(true);
                    pinput.setVisible(false);
                    cp.c1.select("  Display Plots & Output Data");
                }
                else if(state.OptionTwo){
                    loadpanel.setVisible(false);
		    linepanel.setVisible(false);
		    mgpa.setVisible(false);
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
		    outputpanel.setVisible(false);
		    mgpa.plotImpedance(state);
                    mgpb.plotImpedance(state);
                    
                    mgpb.setVisible(true);
		    mgpb.tgc1.setVisible(true);
		    mgpb.tgc2.setVisible(true);
		    mgpb.plotImpedance(state);
                    
                    pgraph.setVisible(false);
                    pout.setVisible(false);
                    pinput.setVisible(true);
                    cp.c1.select("  Display Wide Format Plots");
                }
                else if(state.OptionThree){
                    loadpanel.setVisible(true);
		    linepanel.setVisible(true);
		    mgpa.setVisible(false);
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
                    mgpb.setVisible(false);
		    mgpb.tgc1.setVisible(false);
		    mgpb.tgc2.setVisible(false);
                    
		    outputpanel.setVisible(false);
		    mgpa.plotImpedance(state);
                    mgpb.plotImpedance(state);
                    
                    pgraph.setVisible(true);
                    pout.setVisible(true);
                    pinput.setVisible(false);
                    cp.c1.select("  Set Line and Load");
                }
            }
               
            if(evt.getSource()==sp.small){
		sp.setVisible(false);
		psmith.setVisible(false);
		sp2.setVisible(true);
		psmith2.setVisible(true);
		//sp2.large.setState(false);
		//------------------------------------------
		if(sp.scon.imp.getState()){
		    sp2.scon.imp.setState(true);
		    sp2.scon.adm.setState(false);
		    sp2.set_impedance(true);
		    sp2.set_admittance(false);
		    sp2.sm.setMode(1);
		    sp2.sm.setZL(sp2.sc.getZL());
		    sp2.sm.setZin(sp2.sc.getZin());
		}
		else{
		    sp2.scon.imp.setState(false);
		    sp2.scon.adm.setState(true);
		    sp2.set_impedance(false);
		    sp2.set_admittance(true);
		    sp2.sm.setMode(2);
		    sp2.sm.setZL(sp2.sc.getZL());
		    sp2.sm.setYin(sp2.sc.getYin());
		}
		//-------------------------------------------
		if(sp.scon.swr.getState()){
		    sp2.scon.swr.setState(true);
		    sp2.sc.set_swr_circle(true);
		}
		else{
		    sp2.scon.swr.setState(false);
		    sp2.set_swr_circle(false);
		}
		//-------------------------------------------
		if(sp.scon.swrline.getState()){
		    sp2.scon.swrline.setState(true);
		    sp2.set_swr_line(true);
		}
		else{
		    sp2.scon.swrline.setState(false);
		    sp2.set_swr_line(false);
		}
		//-------------------------------------------
		sp2.repaint();
	}
        
        if(evt.getSource()==sp2.large){
		sp.setVisible(true);
		psmith.setVisible(true);
		sp2.setVisible(false);
		psmith2.setVisible(false);
		//sp.small.setState(false);
		
		//------------------------------------------
		if(sp2.scon.imp.getState()){
		    sp.scon.imp.setState(true);
		    sp.scon.adm.setState(false);
		    sp.set_impedance(true);
		    sp.set_admittance(false);
		    sp.sm.setMode(1);
		    sp.sm.setZL(sp.sc.getZL());
		    sp.sm.setZin(sp.sc.getZin());
		}
		else{
		    sp.scon.imp.setState(false);
		    sp.scon.adm.setState(true);
		    sp.set_impedance(false);
		    sp.set_admittance(true);
		    sp.sm.setMode(2);
		    sp.sm.setZL(sp.sc.getZL());
		    sp.sm.setYin(sp.sc.getYin());
		}
		//-------------------------------------------
		if(sp2.scon.swr.getState()){
		    sp.scon.swr.setState(true);
		    sp.set_swr_circle(true);
		}
		else{
		    sp.scon.swr.setState(false);
		    sp.set_swr_circle(false);
		}
		//-------------------------------------------
		if(sp2.scon.swrline.getState()){
		    sp.scon.swrline.setState(true);
		    sp.set_swr_line(true);
		}
		else{
		    sp.scon.swrline.setState(false);
		    sp.set_swr_line(false);
		}
		//-------------------------------------------
		sp.repaint();
	    }
        
        if(evt.getSource()==sp2.colore){
            if(sp2.colore_dark){
                sp2.colore_dark=false;
                sp2.sc.setColoreDark(false);
                sp.colore_dark=false;
                sp.sc.setColoreDark(false);
            }
            else{
                sp2.colore_dark=true;
                sp2.sc.setColoreDark(true);
                sp.colore_dark=true;
                sp.sc.setColoreDark(true);
            }
        }
        if(evt.getSource()==sp.colore){
            if(sp.colore_dark){
                sp.colore_dark=false;
                sp.sc.setColoreDark(false);
                sp2.colore_dark=false;
                sp2.sc.setColoreDark(false);
            }
            else{
                sp.colore_dark=true;
                sp.sc.setColoreDark(true);
                sp2.colore_dark=true;
                sp2.sc.setColoreDark(true);
            }
        }
 
        
	if(evt.getSource()==linepanel.lowpanel.b1){
	                
            if(linepanel.lowpanel.getValue(0) < 0.0){
		state.lineZ0 = 50.0;
		linepanel.lowpanel.setValue(50.0,0);
	    }
	    else{
		state.lineZ0 = linepanel.lowpanel.getValue(0);
	    }
            
	    if(linepanel.lowpanel.getValue(1) < 1.0){
		state.epsilon_r = 1.0;
		linepanel.lowpanel.setValue(1.0,1);
	    }
	    else{
		state.epsilon_r = linepanel.lowpanel.getValue(1);
	    }
	   
            state.wavelength = state.light_velocity/(Math.sqrt(state.epsilon_r*state.mu_r)*state.frequency); 
                      
	    if(linepanel.Is_Wavelength){
		if(linepanel.lowpanel.getValue(2) < 0.0){
		    state.lineLength = 0.0;
		    state.lineLength_meters = 0.0;
		    linepanel.lowpanel.setValue(0.0,2);
		}
		else{
		    state.lineLength = linepanel.lowpanel.getValue(2);
		    state.lineLength_meters = linepanel.lowpanel.getValue(2)*state.wavelength;
		}
	    }
	    else{
		
		if(linepanel.lowpanel.getValue(2) < 0.0){
		    state.lineLength = 0.0;
		    state.lineLength_meters = 0.0;
		    linepanel.lowpanel.setValue(0.0,2);
		}
		else{
		    state.lineLength = linepanel.lowpanel.getValue(2)/state.wavelength;
		    state.lineLength_meters = linepanel.lowpanel.getValue(2);	
		}
	    }  
	    
            //System.out.println(linepanel.Is_Wavelength+"   "+state.wavelength);
	    //state.xpos = state.lineLength;
	    //state.xpos_meters = state.xpos * state.wavelength;
            state.xpos = 0.0;
	    state.xpos_meters = 0.0;
            
            int templine = 10000;
	    int templine2 = 1000;
	    
	    if(state.lineLength < 1.0){
		templine = (int)(10000*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/10000.0),5);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,7);
		templine2 = (int)(10000000*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,8);
	    }
	    else if(state.lineLength >= 1.0 && state.lineLength < 10.0){
		templine = (int)(1000*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/1000.0),5);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,6);
		templine2 = (int)(1000000*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,7);
	    }
	    else if(state.lineLength >= 10.0 && state.lineLength < 100.0){
		templine = (int)(100*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/100.0),4);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,5);
		templine2 = (int)(100000*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,6);
	    }
	    else if(state.lineLength >= 100.0 && state.lineLength < 1000.0){
		templine = (int)(10*state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine/10.0),3);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,4);
		templine2 = (int)(10000*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,5);
	    }
	    else if(state.lineLength >= 1000.0 && state.lineLength < 10000.0){
		templine = (int)(state.lineLength);
		state.lineLength_part1 = MaestroA.rounder((double)(templine),2);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,3);
		templine2 = (int)(1000*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,4);
	    }
	    else if(state.lineLength >= 10000.0 && state.lineLength <= 100000.0){
		templine = (int)(state.lineLength/10);
		state.lineLength_part1 = MaestroA.rounder((double)(templine)*10,2);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,2);
		templine2 = (int)(100*state.lineLength_part2);
		state.lineLength = MaestroA.rounder(state.lineLength_part1 + state.lineLength_part2,3);
	    }
	    else if(state.lineLength > 100000.0 ){
		state.lineLength = 100000.0;
		templine = (int)(state.lineLength/10);
		state.lineLength_part1 = MaestroA.rounder((double)(templine)*10,2);
		state.lineLength_part2 = MaestroA.rounder(state.lineLength - state.lineLength_part1,3);
		templine2 = (int)(100*state.lineLength_part2);
	    }
	    state.linecounter1 = templine;
	    state.linecounter2 = templine2;
            
	    if(linepanel.Is_Wavelength){
                linepanel.lowpanel.setValue(state.lineLength,2);
            }
            else{
                linepanel.lowpanel.setValue(state.lineLength_meters,2);
            }
	    
	    state.ignition();
	    
            if(state.lineLength_meters > (15.0*state.wavelength)){
                state.IsLengthTooLarge = true;
                state.IsLengthTooSmall = false;
                mgpa.setTooLarge(state.IsLengthTooLarge);
                mgpa.setTooSmall(state.IsLengthTooSmall);
                mgpa.repaint();
            }
            else if(state.lineLength < 1.0E-4){
                state.IsLengthTooLarge = false;
                state.IsLengthTooSmall = true;
                mgpa.setTooLarge(state.IsLengthTooLarge);
                mgpa.setTooSmall(state.IsLengthTooSmall);
                mgpa.repaint();
            }
            else{
                state.IsLengthTooLarge = false;
                state.IsLengthTooSmall = false;
                mgpa.setTooLarge(state.IsLengthTooLarge);
                mgpa.setTooSmall(state.IsLengthTooSmall);
                mgpa.repaint();
            }
            
            if(state.lineLength_meters > (15.0*state.wavelength)){
                state.IsLengthTooLarge2 = true;
                state.IsLengthTooSmall2 = false;
                mgpb.setTooLarge(state.IsLengthTooLarge2);
                mgpb.setTooSmall(state.IsLengthTooSmall2);
                mgpb.repaint();
            }
            else if(state.lineLength < 1.0E-4){
                state.IsLengthTooLarge2 = false;
                state.IsLengthTooSmall2 = true;
                mgpb.setTooLarge(state.IsLengthTooLarge2);
                mgpb.setTooSmall(state.IsLengthTooSmall2);
                mgpb.repaint();
            }
            else{
                state.IsLengthTooLarge2 = false;
                state.IsLengthTooSmall2 = false;
                mgpb.setTooLarge(state.IsLengthTooLarge2);
                mgpb.setTooSmall(state.IsLengthTooSmall2);
                mgpb.repaint();
            }
            
            slidepanel.setLineLength(state.lineLength,state.lineLength_part1,state.lineLength_part2,state.linecounter1,state.linecounter2);
	    
            slidepanel.slider.setMaximum(templine+1);
	    slidepanel.slider.setValues(templine,1,0,templine+1);
            
	    //------------------------------------------------------------------------   
            
            slidepanel.reset();
            
            sp.setxpos(state.xpos);
	    sp.setZin(state.Zin,state.lineZ0);
	    sp.setZL(state.ZL,state.lineZ0);
            sp.setYin(state.Yin,state.lineZ0);
            sp.setYL(state.YL,state.lineZ0);
	    sp2.setxpos(state.xpos);
	    sp2.setZin(state.Zin,state.lineZ0);
	    sp2.setZL(state.ZL,state.lineZ0);
            sp2.setYin(state.Yin,state.lineZ0);
            sp2.setYL(state.YL,state.lineZ0);
            
	    ccan.repaint();
	    outputpanel.canvas1.repaint();
	    outputpanel.canvas2.repaint();   
	    
            state.ignition();
	    
	    mgpa.tgc1.setXpos(state.xpos);
	    mgpa.tgc2.setXpos(state.xpos);
	
	    mgpa.tgc1.repaint();
	    mgpa.tgc2.repaint();
            
            mgpb.tgc1.setXpos(state.xpos);
	    mgpb.tgc2.setXpos(state.xpos);
	
	    mgpb.tgc1.repaint();
	    mgpb.tgc2.repaint();
            
            if(state.frequency < state.f_bottom || state.frequency > state.f_top){
                slidepanel.slider.setEnabled(false);
                slidepanel.slider2.setEnabled(false);
            }
            else{
                slidepanel.slider.setEnabled(true);
                slidepanel.slider2.setEnabled(true);
            }
            
	}
	
	
	else if(evt.getSource()==loadpanel.b1){
	    
	    if(loadpanel.c1.getState()){//Impedance choice is on
		
		double temp1, temp2;
		temp1 = Complex.Real(loadpanel.getValue(0));
		temp2 = Complex.Imaginary(loadpanel.getValue(0));
		
		if(temp1 < 0.0){
		    state.ZL = new Complex(0.0,temp2);
		    state.YL = new Complex(0.0,-1.0/temp2);
		    loadpanel.setValue(state.ZL,0);
		}
		else{
		state.ZL = loadpanel.getValue(0);
		}
		state.is_Load_Ztype = true;
	    }
	    else{ //Admittance choice is on
		
		double temp1, temp2;
		temp1 = Complex.Real(loadpanel.getValue(0));
		temp2 = Complex.Imaginary(loadpanel.getValue(0));
		
		if(temp1 < 0.0){
		    state.YL = new Complex(0.0,temp2);
		    state.ZL = new Complex(0.0,-1.0/temp2);
		    loadpanel.setValue(state.YL,0);
		}
		else{
		state.YL = loadpanel.getValue(0);
		}
		state.is_Load_Ztype = false;
	    }
	   
	    state.ignition();
            
            sp.setxpos(state.xpos);
	    sp.setZin(state.Zin,state.lineZ0);
	    sp.setZL(state.ZL,state.lineZ0);
            sp.setYin(state.Yin,state.lineZ0);
            sp.setYL(state.YL,state.lineZ0);
	    sp2.setxpos(state.xpos);
	    sp2.setZin(state.Zin,state.lineZ0);
	    sp2.setZL(state.ZL,state.lineZ0);
            sp2.setYin(state.Yin,state.lineZ0);
            sp2.setYL(state.YL,state.lineZ0);
            
            /*
	    sp.setxpos(state.xpos);
	    if(loadpanel.c1.getState()){//Impedance choice is on
		sp.setZin(state.Zin,state.lineZ0);
		sp.setZL(state.ZL,state.lineZ0);
	    }
	    else{ //Admittance choice is on
		sp.setYin(state.Yin,state.lineZ0);
		sp.setYL(state.YL,state.lineZ0);
	    }
	    
	    sp2.setxpos(state.xpos);
	    if(loadpanel.c1.getState()){//Impedance choice is on
		sp2.setZin(state.Zin,state.lineZ0);
		sp2.setZL(state.ZL,state.lineZ0);
	    }
	    else{ //Admittance choice is on
		sp2.setYin(state.Yin,state.lineZ0);
		sp2.setYL(state.YL,state.lineZ0);
	    }
	    */
            
	    ccan.repaint();
	    outputpanel.canvas1.repaint();
	    outputpanel.canvas2.repaint();
	}
	else if(evt.getSource()==generatorpanel.b1){
	    state.generator.setVg(generatorpanel.getValue(0));
	    double temp1, temp2;
	    Complex temp3 = new Complex(1.0,1.0);
	    temp1 = Complex.Real(generatorpanel.getValue(1));
	    temp2 = Complex.Imaginary(generatorpanel.getValue(1));
		
	    if(temp1 < 0.0){
	        temp3 = new Complex(100.0,temp2);
		state.generator.setZg(temp3);
		generatorpanel.setValue(temp3,1);
	    }
	    else{	    
	        state.generator.setZg(generatorpanel.getValue(1));
	    }	    
	    //state.generator.setZg(generatorpanel.getValue(1));
	    send_shock_wave();
	}
	// This is set characterisitc impedance button (update) on stub panel 1 
	else if(evt.getSource()==msp.stp1.b1){
	    if(state.stub[0].isEnable()){
		send_shock_wave();
	    }
	}
	// This is set characterisitc impedance button (update) on stub panel 2
	else if(evt.getSource()==msp.stp2.b1){
	    if(state.stub[1].isEnable()){
		send_shock_wave();
	    }	
	}
	// This is set characterisitc impedance button (update) on stub panel 3 
	else if(evt.getSource()==msp.stp3.b1){
	    if(state.stub[2].isEnable()){
		send_shock_wave();
	    }	
	}
}

public void itemStateChanged(ItemEvent evt){
	    ItemSelectable ie = evt.getItemSelectable();
	    
	    if(evt.getSource()==sp2.large){
		sp.setVisible(true);
		psmith.setVisible(true);
		sp2.setVisible(false);
		psmith2.setVisible(false);
		//sp.small.setState(false);
		
		//------------------------------------------
		if(sp2.scon.imp.getState()){
		    sp.scon.imp.setState(true);
		    sp.scon.adm.setState(false);
		    sp.set_impedance(true);
		    sp.set_admittance(false);
		    sp.sm.setMode(1);
		    sp.sm.setZL(sp2.sc.getZL());
		    sp.sm.setZin(sp2.sc.getZin());
		}
		else{
		    sp.scon.imp.setState(false);
		    sp.scon.adm.setState(true);
		    sp.set_impedance(false);
		    sp.set_admittance(true);
		    sp.sm.setMode(2);
		    sp.sm.setZL(sp2.sc.getZL());
		    sp.sm.setYin(sp2.sc.getYin());
		}
		//-------------------------------------------
		if(sp2.scon.swr.getState()){
		    sp.scon.swr.setState(true);
		    sp.set_swr_circle(true);
		}
		else{
		    sp.scon.swr.setState(false);
		    sp.set_swr_circle(false);
		}
		//-------------------------------------------
		if(sp2.scon.swrline.getState()){
		    sp.scon.swrline.setState(true);
		    sp.set_swr_line(true);
		}
		else{
		    sp.scon.swrline.setState(false);
		    sp.set_swr_line(false);
		}
		//-------------------------------------------
		sp2.repaint();
	    }
            
            if(evt.getSource()==linepanel.c1){
                state.UseExactLight = true;
                state.wavelength = state.light_velocity/(Math.sqrt(state.epsilon_r*state.mu_r)*state.frequency);
                
                state.ignition();
                mgpa.setXpos(state.xpos);
                mgpb.setXpos(state.xpos);
                //ccan.repaint();
                sp.setxpos(state.xpos);
                sp.setZin(state.Zin,state.lineZ0);
                sp2.setxpos(state.xpos);
                sp2.setZin(state.Zin,state.lineZ0);
                mgpa.tgc1.repaint();
                mgpa.tgc2.repaint();
                mgpb.tgc1.repaint();
                mgpb.tgc2.repaint();

                outputpanel.canvas1.repaint();
                outputpanel.canvas2.repaint();
                slidepanel.repaint();
            }
            
            if(evt.getSource()==linepanel.c2){
                state.UseExactLight = false;
                state.wavelength = state.light_velocity/(Math.sqrt(state.epsilon_r*state.mu_r)*state.frequency);
                
                state.ignition();
                mgpa.setXpos(state.xpos);
                mgpb.setXpos(state.xpos);
                //ccan.repaint();
                sp.setxpos(state.xpos);
                sp.setZin(state.Zin,state.lineZ0);
                sp2.setxpos(state.xpos);
                sp2.setZin(state.Zin,state.lineZ0);
                mgpa.tgc1.repaint();
                mgpa.tgc2.repaint();
                mgpb.tgc1.repaint();
                mgpb.tgc2.repaint();

                outputpanel.canvas1.repaint();
                outputpanel.canvas2.repaint();
                slidepanel.repaint();
            }
            
	    if(evt.getSource()==cp.c1){
                /*
                if(ie.getSelectedObjects()[0]=="  Instructions"){
                    instructions.setVisible(true);
                    loadpanel.setVisible(false);
		    linepanel.setVisible(false);
                    
		    mgpa.setVisible(false);
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
		    
                    mgpb.setVisible(false);
		    mgpb.tgc1.setVisible(false);
		    mgpb.tgc2.setVisible(false);
		    
                    outputpanel.setVisible(false);
		    mgpa.plotImpedance(state);
                    mgpb.plotImpedance(state);
                    pgraph.setVisible(false);
                    pout.setVisible(false);
                    pinput.setVisible(false);
                    
                }
                */
                
                if(ie.getSelectedObjects()[0]=="  Display Plots & Output Data"){
		    
                    loadpanel.setVisible(false);
		    linepanel.setVisible(false);
                    
		    mgpa.setVisible(true);
		    mgpa.tgc1.setVisible(true);
		    mgpa.tgc2.setVisible(true);
		    
                    mgpb.setVisible(false);
		    mgpb.tgc1.setVisible(false);
		    mgpb.tgc2.setVisible(false);
		    
                    outputpanel.setVisible(true);
		    mgpa.plotImpedance(state);
                    mgpb.plotImpedance(state);
                    pgraph.setVisible(true);
                    pout.setVisible(true);
                    pinput.setVisible(false);
                    
                    //about.setVisible(false);
                    instructions.setVisible(false);
                    
                    state.OptionOne = true;
                    state.OptionTwo = false;
                    state.OptionThree = false;
                    
                    // CHANGE - MOVE HIDDEN PANELS OUT OF RANGE ================
                    // TO CORRECT MAC PROBLEM WITH setVisible() - MAC SUCKS
                    linepanel.setBounds(11+xmove,266+ymove+10000,308,278);
                    loadpanel.setBounds(326+xmove,266+ymove+10000,308,278);
                    outputpanel.setBounds(326+xmove,266+ymove,308,278);
                    mgpa.setBounds(11+xmove,266+ymove,308,278);
                    mgpb.setBounds(11+xmove,266+ymove+10000,623,278);
                    pgraph.setBounds(10+xmove,265+ymove,310,280);
                    pout.setBounds(325+xmove,265+ymove,310,280);
                    pinput.setBounds(10+xmove,265+ymove+10000,625,280);
                    //==========================================================
		}
                if(ie.getSelectedObjects()[0]=="  Display Wide Format Plots"){
                    
		    loadpanel.setVisible(false);
		    linepanel.setVisible(false);
		    mgpa.setVisible(false);
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
		    outputpanel.setVisible(false);
		    mgpa.plotImpedance(state);
                    mgpb.plotImpedance(state);
                    
                    mgpb.setVisible(true);
		    mgpb.tgc1.setVisible(true);
		    mgpb.tgc2.setVisible(true);
		    mgpb.plotImpedance(state);
                    
                    pgraph.setVisible(false);
                    pout.setVisible(false);
                    pinput.setVisible(true);
                    
                    //about.setVisible(false);
                    instructions.setVisible(false);
                    
                    state.OptionOne = false;
                    state.OptionTwo = true;
                    state.OptionThree = true;
                    
                    // CHANGE - MOVE HIDDEN PANELS OUT OF RANGE ================
                    // TO CORRECT MAC PROBLEM WITH setVisible() - MAC SUCKS
                    linepanel.setBounds(11+xmove,266+ymove+10000,308,278);
                    loadpanel.setBounds(326+xmove,266+ymove+10000,308,278);
                    outputpanel.setBounds(326+xmove,266+ymove+10000,308,278);
                    mgpa.setBounds(11+xmove,266+ymove+10000,308,278);
                    mgpb.setBounds(11+xmove,266+ymove,623,278);
                    pgraph.setBounds(10+xmove,265+ymove+10000,310,280);
                    pout.setBounds(325+xmove,265+ymove+10000,310,280);
                    pinput.setBounds(10+xmove,265+ymove,625,280);
                    //==========================================================
		}
                if(ie.getSelectedObjects()[0]=="  Set Line and Load"){
                    
		    loadpanel.setVisible(true);
		    linepanel.setVisible(true);
		    mgpa.setVisible(false);
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
                    mgpb.setVisible(false);
		    mgpb.tgc1.setVisible(false);
		    mgpb.tgc2.setVisible(false);
                    
		    outputpanel.setVisible(false);
		    mgpa.plotImpedance(state);
                    mgpb.plotImpedance(state);
                    
                    pgraph.setVisible(true);
                    pout.setVisible(true);
                    pinput.setVisible(false);
                    
                    //about.setVisible(false);
                    instructions.setVisible(false);
                    
                    state.OptionOne = false;
                    state.OptionTwo = false;
                    state.OptionThree = true;
                    // CHANGE - MOVE HIDDEN PANELS OUT OF RANGE ================
                    // TO CORRECT MAC PROBLEM WITH setVisible() - MAC SUCKS
                    linepanel.setBounds(11+xmove,266+ymove,308,278);
                    loadpanel.setBounds(326+xmove,266+ymove,308,278);
                    outputpanel.setBounds(326+xmove,266+ymove+10000,308,278);
                    mgpa.setBounds(11+xmove,266+ymove+10000,308,278);
                    mgpb.setBounds(11+xmove,266+ymove+10000,623,278);
                    pgraph.setBounds(10+xmove,265+ymove,310,280);
                    pout.setBounds(325+xmove,265+ymove,310,280);
                    pinput.setBounds(10+xmove,265+ymove+10000,625,280);
                    //==========================================================
		}
                //if(ie.getSelectedObjects()[0]=="  About"){
		//    
                //    about.setVisible(true);
		//}	
	    }
	    else if(evt.getSource()==cp.c2){
		 if(ie.getSelectedObjects()[0]=="   Plot"){
		    loadpanel.setVisible(false);
		    linepanel.setVisible(false);
		    msp.setVisible(false);
		    generatorpanel.setVisible(false);
		    mgpa.setVisible(true);
		    mgpa.tgc1.setVisible(true);
		    mgpa.tgc2.setVisible(true);
		   
		    outputpanel.setVisible(false);
		    mgpa.plotImpedance(state);
		 }	
		 if(ie.getSelectedObjects()[0]=="Plots (time)"){
		    loadpanel.setVisible(false);
		    linepanel.setVisible(false);
		    msp.setVisible(false);
		    generatorpanel.setVisible(false);
		    mgpa.setVisible(false);
		    
		    
		    outputpanel.setVisible(false);
		    
		 }	
		 if(ie.getSelectedObjects()[0]=="   Output"){
		    loadpanel.setVisible(false);
		    linepanel.setVisible(false);
		    msp.setVisible(false);
		    generatorpanel.setVisible(false);
		    mgpa.setVisible(false);
		    
		    outputpanel.setVisible(true);
		 }
	    }
	    //Trans_MultiGraphPanelA Choices
	    else if(evt.getSource()==mgpa.c1){
		/*if(ie.getSelectedObjects()[0]=="Impedance"){
		    mgpa.plotImpedance(state);
		}
		else if(ie.getSelectedObjects()[0]=="Admittance"){
		    mgpa.plotAdmittance(state);
		}
		else if(ie.getSelectedObjects()[0]=="Reflection Coefficient"){
		    mgpa.plotReflectionCoefficient(state);
		}
		else if(ie.getSelectedObjects()[0]=="Voltage Phasor"){
		    mgpa.plotVoltagePhasor(state);
		} 
		else if(ie.getSelectedObjects()[0]=="Current Phasor"){
		    mgpa.plotCurrentPhasor(state);
		} */
		 if(ie.getSelectedObjects()[0]=="Standing Wave Pattern - | V | & | I |"){
		    mgpa.plotImpedance(state);
		} 		
		mgpa.tgc1.setVisible(true);
		mgpa.tgc2.setVisible(true);
	    }
	    
	    //Stub_Panel Choices
	    //Enable and Disable choices on stub panel 1
	    else if(evt.getSource()==msp.stp1.c1 || evt.getSource()==msp.stp1.c2){
		send_shock_wave();
	    }
	    //Open and short choices on stub panel 1
	    else if(evt.getSource()==msp.stp1.c3 || evt.getSource()==msp.stp1.c4){
		    send_shock_wave();
	    }
	    //Enable and Disable choices on stub panel 2
	    else if(evt.getSource()==msp.stp2.c1 || evt.getSource()==msp.stp2.c2){
		send_shock_wave();
		
	    }
	    //Open and short choices on stub panel 2
	    else if(evt.getSource()==msp.stp2.c3 || evt.getSource()==msp.stp2.c4){
		    send_shock_wave();
	    }
	    //Enable and Disable choices on stub panel 3
	    else if(evt.getSource()==msp.stp3.c1 || evt.getSource()==msp.stp3.c2){
		send_shock_wave();
	    }
	    //Open and short choices on stub panel 3
	    else if(evt.getSource()==msp.stp3.c3 || evt.getSource()==msp.stp3.c4){
		    send_shock_wave();
	    }		
}


private void send_shock_wave(){
	state.ignition();
	mgpa.setXpos(state.xpos);
	mgpb.setXpos(state.xpos);
        ccan.repaint();
	sp.setxpos(state.xpos);
	sp.setZin(state.Zin,state.lineZ0);
	sp2.setxpos(state.xpos);
	sp2.setZin(state.Zin,state.lineZ0);
	mgpa.tgc1.repaint();
	mgpa.tgc2.repaint();
	mgpb.tgc1.repaint();
	mgpb.tgc2.repaint();
	
        outputpanel.canvas1.repaint();
	outputpanel.canvas2.repaint();
	slidepanel.repaint();
}    
     

}
