/**
 * Trans.java
 * Electromagnetic Transmission Line Application
 * Amanogawa's Maestro Series
 */   
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class Trans extends Frame implements AdjustmentListener, ActionListener, ItemListener, MouseListener, WindowListener{
    Instructions instructions;
    
    TitlePanel titlepanel;
    CircuitCanvas ccan;
    SmithPanel sp;
    SmithPanel2 sp2;
        
    ChoicePanel cp;
    TimeChoicePanel tcp;
    PlotSizeControl psc;
    TargetPanel target;
    TransSlidePanel slidepanel;
    Trans_OutputPanel outputpanel;
    Trans_State state;
    TransLinePanel linepanel;
    //PC generatorpanel;
    TransGeneratorPanel generatorpanel;
    TransLoadPanel loadpanel;
    TransShuntPanel shuntpanel;
    Trans_MultiStubPanel msp;
    Trans_MultiStubPanelLarge msp2;
    Trans_MultiGraphPanelA mgpa;
    Trans_MultiGraphPanelB mgpb;
    Panel psmith, psmith2;
    Image image;
      
    private static final Color tinta = new Color(245,245,245);
    // CHANGE #1 6/18/2017 =====================================================
    // ADD LINES BELOW
    public static int sp_xmove = 10;
    public static int sp_ymove = 34;
    //==========================================================================
    
    public int this_month, today_week, this_year, this_hour, this_minute, today_month, 
	       today_year,this_zone, saving_time;
    GregorianCalendar Greg = new GregorianCalendar();
    

public static void main(String[] args){
        Trans f = new Trans();
        int xmove = 20;
        int ymove = 41;
        f.setSize(1146+xmove,655+ymove);
        f.setVisible(true);
        f.setLayout(null);
}

public Trans(){
    
    setLayout(null);
        
    state = new Trans_State();
    
        // CHANGE #2 6/18/2017 =================================================
        //int xmove = 10;
        //int ymove = 34;
        int xmove = sp_xmove;
        int ymove = sp_ymove;
        //======================================================================
        
	this_month = Greg.get(Calendar.MONTH);
	//System.out.println("  This is the month = "+this_month);
	today_week = Greg.get(Calendar.DAY_OF_WEEK);
	//System.out.println("  This is the day_week = "+today_week);
	this_year = Greg.get(Calendar.YEAR);
	this_hour = Greg.get(Calendar.HOUR_OF_DAY);
	//System.out.println("  This is the year = "+this_year);
	this_minute = Greg.get(Calendar.MINUTE);
	//System.out.println("  This is the minute = "+this_minute);
	today_month = Greg.get(Calendar.DAY_OF_MONTH);
	//System.out.println("  This is the day_month = "+today_month);
	today_year = Greg.get(Calendar.DAY_OF_YEAR);
	//System.out.println("  This is the day_year = "+today_year);
	this_zone = Greg.get(Calendar.ZONE_OFFSET);
	//System.out.println("  This is the zone_offset = "+this_zone/3600000);
	saving_time = Greg.get(Calendar.DST_OFFSET);
	//System.out.println("  This is the dst_offset = "+saving_time/3600000);
    
    titlepanel = new TitlePanel("Module 2.7 Design","","Quarter Wavelength Transformer Match");
    //add(titlepanel);
    titlepanel.setBounds(10+xmove,10+ymove,310,40);
    
    ccan = new CircuitCanvas(state);
    //add(ccan);
    ccan.setBounds(10+xmove,102+ymove,807,140);
    
    sp = new SmithPanel();
    //add(sp);
    sp.setBounds(824+xmove,248+ymove,311,395);
    sp.setxpos(state.xpos);
    sp.setZin(state.Zin,state.lineZ0);
    sp.setZL(state.ZL,state.lineZ0);
    
    sp2 = new SmithPanel2();
    //add(sp2);
    sp2.setBounds(326+xmove,56+ymove,573,675);
    sp2.setxpos(state.xpos);
    sp2.setZin(state.Zin,state.lineZ0);
    sp2.setZL(state.ZL,state.lineZ0);
    sp2.setVisible(false);

    String arg1[] = {"Menu:"," Set Load"," Set Line/Transformer"," Set Frequency"," Set Generator"," View Phasor Plots"," View Time Plots"};
    //String arg1[] = {"Set:"," Load"," Shunt"," Line Sections"," Frequency"," Generator"};
    //String arg1[] = {"Set:"," Load"," Shunt"," Line Sections"," Generator"}; // no frequency here
    //String arg2[] = {"Review:"," Complete Line"," Plots (phasors)"," Plots (time)"};
    String arg2[] = {"Plots:"," Phasors"," Time"};
    cp = new ChoicePanel(arg1,arg2);
    //add(cp);
    cp.setBounds(326+xmove,11+ymove,491,38);
    
    tcp = new TimeChoicePanel();
    tcp.setBounds(20+xmove,350+ymove,60,45);
    tcp.setVisible(false);
    
    psc = new PlotSizeControl();
    //psc.setBounds(300,325,10,100);
    psc.setBounds(690+xmove,253+ymove,120,50);
    psc.setVisible(false);
    
    slidepanel = new TransSlidePanel();
    //add(slidepanel);
    slidepanel.setBounds(11+xmove,56+ymove,805,40);
    //slidepanel.setLineLength(state.lineLength);
    slidepanel.setLineLength(state.lineLength, state.lineLength_part1, state.lineLength_part2, state.linecounter1, state.linecounter2);
        
    {
      String[] str1 = {"Char. Impedance   Zo   ","Frequency   f   ","Rel. Permittivity   \u03b5   ","Total Length  L   "};
      String[] str2 = {"  [ \u03a9 ]","  [ Hz ]","  ","  [ \u03bb ]"};
      linepanel = new TransLinePanel("Set Frequency",str1,str2);
      linepanel.setValue(50.0,0);
      linepanel.setValue(3.0E9,1);
      linepanel.setValue(1.0,2);
      linepanel.setValue(1.0,3);
      //add(linepanel);
      //linepanel.setBounds(10,235,310,180);
      linepanel.setBounds(824+xmove,11+ymove,311,230);
    }
    {
      String[] str1 =  {"Z ="};
      String[] str2 =  {"  [ \u03a9 ]"};
      loadpanel = new TransLoadPanel("Set Load",str1,str2,state);
      //add(loadpanel);
      loadpanel.setValue(state.ZL,0);
      //loadpanel.setBounds(10,235,310,170);
      loadpanel.setBounds(824+xmove,11+ymove,311,160);
    }
    {
      String[] str5 =  {"SWR = "};
      String[] str6 =  {""};
      target = new TargetPanel("Target SWR for Impedance Matching",str5,str6,state);
      //add(target);
      target.setValue(state.targetVSWR,0);
      target.setBounds(824+xmove,170+ymove,311,71);
    }
    {
      String[] str3 =  {"Z ="};
      String[] str4 =  {"  [ \u03a9 ]"};
      shuntpanel = new TransShuntPanel("Set Shunt Impedance",str3,str4,state);
      //add(loadpanel);
      shuntpanel.setValue(state.ZS,0); 
      shuntpanel.setBounds(824+xmove,11+ymove,311,230);
      shuntpanel.setVisible(false);
    }
    {
      String[] str1 =  {"Vg =","Zg ="};
      String[] str2 =  {"[ V ]","[ \u03a9 ]"};
      generatorpanel = new TransGeneratorPanel("Set Generator",str1,str2,state);
      //add(generatorpanel);
      generatorpanel.setValue(state.generator.getVg(),0);
      generatorpanel.setValue(state.generator.getZg(),1);
      //generatorpanel.setBounds(10,235,310,170);
      generatorpanel.setBounds(824+xmove,11+ymove,311,230);
      
    }
    
    msp = new Trans_MultiStubPanel("Set Line /Transformer",state);    
    //add(msp);
    msp.setBounds(824+xmove,11+ymove,311,230);
    
    msp2 = new Trans_MultiStubPanelLarge("Set Line Sections",state);
    //add(msp2);
    msp2.setBounds(11+xmove,236+ymove,805,395);
    
    mgpa = new Trans_MultiGraphPanelA(" Phasor Plots");
    //add(mgpa);
    //mgpa.setBounds(10,235,310,290);
    mgpa.setBounds(11+xmove,248+ymove,805,395);
    
    mgpb = new Trans_MultiGraphPanelB(" Time Plots");
    //add(mgpb);
    //mgpb.setBounds(10,235,310,290);
    mgpb.setBounds(11+xmove,248+ymove,805,395);
    
    instructions = new Instructions(state);
    //instructions.setBounds(12,262,625,286);
    instructions.setBounds(10+xmove,247+ymove,807,397);
    instructions.setVisible(true);
    
    outputpanel = new Trans_OutputPanel(state);
    //add(outputpanel);
    //outputpanel.setBounds(10,235,310,290);
    outputpanel.setBounds(824+xmove,248+ymove,311,395);
    
    //panels behind graphs
    Panel pgraph2 = new Panel();
	    pgraph2.setBackground(Color.white);
	    //add(pgraph2);
	    pgraph2.setBounds(11+xmove,248+ymove,805,395);
    
    Panel pgraph = new Panel();
	    pgraph.setBackground(Color.black);
	    //add(pgraph);
	    pgraph.setBounds(10+xmove,247+ymove,807,397);
    //----------------------------------------------
    psmith = new Panel();
	    psmith.setBackground(Color.black);
	    //add(psmith);
	    psmith.setBounds(823+xmove,247+ymove,313,397);
    
    Panel psections = new Panel();
	    psections.setBackground(Color.black);
	    //add(psections);
	    psections.setBounds(823+xmove,10+ymove,313,232);      
            
    psmith2 = new Panel();
	    psmith2.setBackground(Color.black);
	    //add(psmith2);
	    psmith2.setBounds(325+xmove,55+ymove,575,677);
	    psmith2.setVisible(false);

	    
    Panel pslide = new Panel();
	    pslide.setBackground(Color.black);
	    //add(pslide);
	    pslide.setBounds(10+xmove,55+ymove,807,42);
	    
    Panel pchoice = new Panel();
	    pchoice.setBackground(Color.black);
	    //add(pchoice);
	    pchoice.setBounds(325+xmove,10+ymove,493,40);
    
    Panel p0 = new Panel();
	    p0.setBackground(Color.cyan);
	    //p0.setBackground(tinta);
	    //add(p0);
	    p0.setBounds(3+xmove,3+ymove,1140,647);
	    
    Panel p00 = new Panel();
	    p00.setBackground(Color.black);
	    //add(p00);
	    p00.setBounds(xmove,ymove,1146,653);
	    
    Panel p000 = new Panel();
	    p000.setBackground(Color.white);
	    ////add(p000);
	    p000.setBounds(xmove,ymove,1146,653);
            
    //hide and show panels
    {
	loadpanel.setVisible(true);
        target.setVisible(true);
	linepanel.setVisible(false);
	msp.setVisible(false);
        msp2.setVisible(true);
	generatorpanel.setVisible(false);
	mgpa.setVisible(true);
	mgpb.setVisible(false);
        outputpanel.setVisible(false);
        instructions.setVisible(true);
    }
            
    if(state.this_year > line.magicyear || (state.this_year == line.magicyear && state.this_month > line.magicmonth)){
	    state.LicenseExpired = true;
	}
	else
	{   
            add(instructions);
            add(titlepanel); 	    
            add(ccan); 	    
            add(msp);
            //add(msp2);
	    add(sp); 	    
            //add(sp2); 	    
            add(cp); 
            add(tcp);
            add(psc);
            add(slidepanel);
	    add(linepanel);
	    add(loadpanel);
            add(target);
            add(shuntpanel);
	    add(generatorpanel);
	    add(outputpanel);
	    add(mgpa);
	    add(mgpb);
            add(pgraph2);
	    add(pgraph);
	    add(psmith);
            add(psections);
	    //add(psmith2);
	    
	    add(pslide);
	    add(pchoice);
	        
            add(p0); 	    
            add(p00);
	    state.LicenseExpired = false; 	
       }

    
    //Listeners
    this.addWindowListener(this);
    instructions.bupdate.addActionListener(this);

    slidepanel.slider.addAdjustmentListener(this);
    slidepanel.slider2.addAdjustmentListener(this);
    slidepanel.b2a.addActionListener(this);
    slidepanel.b2b.addActionListener(this);
    slidepanel.b3a.addActionListener(this);
    slidepanel.b3b.addActionListener(this);
    
    shuntpanel.slider.addAdjustmentListener(this);
    psc.slider.addAdjustmentListener(this);
    linepanel.slider.addAdjustmentListener(this);
    
    linepanel.b1.addActionListener(this);
    linepanel.bfa.addActionListener(this);
    linepanel.bfb.addActionListener(this);
    loadpanel.b1.addActionListener(this);
    
    //---------------------------------------
    loadpanel.SetTr.addActionListener(this);
    msp.SetLoad.addActionListener(this);
    //---------------------------------------
    
    target.b1.addActionListener(this);
    shuntpanel.b1.addActionListener(this);
    generatorpanel.b1.addActionListener(this);
    
    tcp.button1.addActionListener(this);
    tcp.button2.addActionListener(this);
    tcp.button3.addActionListener(this);
 
    cp.binstructions.addActionListener(this);
    cp.c1.addItemListener(this);
    cp.c2.addItemListener(this);
    cp.cbx1.addItemListener(this);
    cp.cbx2.addItemListener(this);
    shuntpanel.c1.addItemListener(this);
    shuntpanel.c2.addItemListener(this);
    
    mgpa.c1.addItemListener(this);
    mgpb.c1.addItemListener(this);
    mgpb.cbx1.addItemListener(this);
    mgpb.cbx2.addItemListener(this);
    mgpb.ssc.button1.addMouseListener(this);
    mgpb.ssc.button2.addMouseListener(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.s1b.addAdjustmentListener(this);
    msp.stp1.s2.addAdjustmentListener(this);
    msp.stp1.s2b.addAdjustmentListener(this);
    msp.stp1.b1.addActionListener(this);
    
    msp2.stp1.s1.addAdjustmentListener(this);
    msp2.stp1.s1b.addAdjustmentListener(this);
    msp2.stp1.s2.addAdjustmentListener(this);
    msp2.stp1.s2b.addAdjustmentListener(this);
    msp2.stp1.b1.addActionListener(this);
    // CHANGE 1/10/2017 ========================================================
    msp.stp1.b4a.addActionListener(this);
    msp.stp1.b4b.addActionListener(this);
    msp.stp1.b5a.addActionListener(this);
    msp.stp1.b5b.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.s1b.addAdjustmentListener(this);
    msp.stp2.s2.addAdjustmentListener(this);
    msp.stp2.s2b.addAdjustmentListener(this);
    msp.stp2.b1.addActionListener(this);
    
    msp.stpnew2.s1.addAdjustmentListener(this);
    msp.stpnew2.s1b.addAdjustmentListener(this);
    msp.stpnew2.s2.addAdjustmentListener(this);
    msp.stpnew2.s2b.addAdjustmentListener(this);
    msp.stpnew2.b1.addActionListener(this);
    // CHANGE 1/10/2017  =======================================================
    msp.stpnew2.b2a.addActionListener(this);
    msp.stpnew2.b2b.addActionListener(this);
    msp.stpnew2.b3a.addActionListener(this);
    msp.stpnew2.b3b.addActionListener(this);
    //==========================================================================
    
    msp.stpnew2.lock.addItemListener(this);
    
    msp2.stp2.s1.addAdjustmentListener(this);
    msp2.stp2.s1b.addAdjustmentListener(this);
    msp2.stp2.s2.addAdjustmentListener(this);
    msp2.stp2.s2b.addAdjustmentListener(this);
    msp2.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.s1b.addAdjustmentListener(this);
    msp.stp3.s2.addAdjustmentListener(this);
    msp.stp3.s2b.addAdjustmentListener(this);
    msp.stp3.b1.addActionListener(this);
    
    msp2.stp3.s1.addAdjustmentListener(this);
    msp2.stp3.s1b.addAdjustmentListener(this);
    msp2.stp3.s2.addAdjustmentListener(this);
    msp2.stp3.s2b.addAdjustmentListener(this);
    msp2.stp3.b1.addActionListener(this);
    
    msp.stp4.s1.addAdjustmentListener(this);
    msp.stp4.s1b.addAdjustmentListener(this);
    msp.stp4.s2.addAdjustmentListener(this);
    msp.stp4.s2b.addAdjustmentListener(this);
    msp.stp4.b1.addActionListener(this);
    
    msp2.stp4.s1.addAdjustmentListener(this);
    msp2.stp4.s1b.addAdjustmentListener(this);
    msp2.stp4.s2.addAdjustmentListener(this);
    msp2.stp4.s2b.addAdjustmentListener(this);
    msp2.stp4.b1.addActionListener(this);
    
    msp.stp5.s1.addAdjustmentListener(this);
    msp.stp5.s1b.addAdjustmentListener(this);
    msp.stp5.s2.addAdjustmentListener(this);
    msp.stp5.s2b.addAdjustmentListener(this);
    msp.stp5.b1.addActionListener(this);
    
    msp2.stp5.s1.addAdjustmentListener(this);
    msp2.stp5.s1b.addAdjustmentListener(this);
    msp2.stp5.s2.addAdjustmentListener(this);
    msp2.stp5.s2b.addAdjustmentListener(this);
    msp2.stp5.b1.addActionListener(this);
    
    msp.stp6.s1.addAdjustmentListener(this);
    msp.stp6.s1b.addAdjustmentListener(this);
    msp.stp6.s2.addAdjustmentListener(this);
    msp.stp6.s2b.addAdjustmentListener(this);
    msp.stp6.b1.addActionListener(this);
    
    msp2.stp6.s1.addAdjustmentListener(this);
    msp2.stp6.s1b.addAdjustmentListener(this);
    msp2.stp6.s2.addAdjustmentListener(this);
    msp2.stp6.s2b.addAdjustmentListener(this);
    msp2.stp6.b1.addActionListener(this);
    
    msp.stp7.s1.addAdjustmentListener(this);
    msp.stp7.s1b.addAdjustmentListener(this);
    msp.stp7.s2.addAdjustmentListener(this);
    msp.stp7.s2b.addAdjustmentListener(this);
    msp.stp7.b1.addActionListener(this);
   
    msp2.stp7.s1.addAdjustmentListener(this);
    msp2.stp7.s1b.addAdjustmentListener(this);
    msp2.stp7.s2.addAdjustmentListener(this);
    msp2.stp7.s2b.addAdjustmentListener(this);
    msp2.stp7.b1.addActionListener(this);
   
    msp.stp8.s1.addAdjustmentListener(this);
    msp.stp8.s1b.addAdjustmentListener(this);
    msp.stp8.s2.addAdjustmentListener(this);
    msp.stp8.s2b.addAdjustmentListener(this);
    msp.stp8.b1.addActionListener(this);
   
    msp2.stp8.s1.addAdjustmentListener(this);
    msp2.stp8.s1b.addAdjustmentListener(this);
    msp2.stp8.s2.addAdjustmentListener(this);
    msp2.stp8.s2b.addAdjustmentListener(this);
    msp2.stp8.b1.addActionListener(this);
   
    msp.stp9.s1.addAdjustmentListener(this);
    msp.stp9.s1b.addAdjustmentListener(this);
    msp.stp9.s2.addAdjustmentListener(this);
    msp.stp9.s2b.addAdjustmentListener(this);
    msp.stp9.b1.addActionListener(this);
    
    msp2.stp9.s1.addAdjustmentListener(this);
    msp2.stp9.s1b.addAdjustmentListener(this);
    msp2.stp9.s2.addAdjustmentListener(this);
    msp2.stp9.s2b.addAdjustmentListener(this);
    msp2.stp9.b1.addActionListener(this);
    
    msp.stp10.s1.addAdjustmentListener(this);
    msp.stp10.s1b.addAdjustmentListener(this);
    msp.stp10.s2.addAdjustmentListener(this);
    msp.stp10.s2b.addAdjustmentListener(this);
    msp.stp10.b1.addActionListener(this);
    
    msp2.stp10.s1.addAdjustmentListener(this);
    msp2.stp10.s1b.addAdjustmentListener(this);
    msp2.stp10.s2.addAdjustmentListener(this);
    msp2.stp10.s2b.addAdjustmentListener(this);
    msp2.stp10.b1.addActionListener(this);
    
   // sp.small.addItemListener(this);
    //sp2.large.addItemListener(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);
    
    sp.colore.addActionListener(this);
    sp2.colore.addActionListener(this);
    
    // Initialize the Line panels with impedances
        msp.stp1.text1.setText(""+state.ZIMP[0]);
    	msp.stp2.text1.setText(""+state.ZIMP[1]);
        msp.stpnew2.text1.setText(""+state.ZIMP[1]); // NEW
        msp.stp3.text1.setText(""+state.ZIMP[2]);
        msp.stp4.text1.setText(""+state.ZIMP[3]);
        msp.stp5.text1.setText(""+state.ZIMP[4]);
        msp.stp6.text1.setText(""+state.ZIMP[5]);
        msp.stp7.text1.setText(""+state.ZIMP[6]);
        msp.stp8.text1.setText(""+state.ZIMP[7]);
        msp.stp9.text1.setText(""+state.ZIMP[8]);
        msp.stp10.text1.setText(""+state.ZIMP[9]);
    
        msp2.stp1.text1.setText(""+state.ZIMP[0]);
    	msp2.stp2.text1.setText(""+state.ZIMP[1]);
        msp2.stp3.text1.setText(""+state.ZIMP[2]);
        msp2.stp4.text1.setText(""+state.ZIMP[3]);
        msp2.stp5.text1.setText(""+state.ZIMP[4]);
        msp2.stp6.text1.setText(""+state.ZIMP[5]);
        msp2.stp7.text1.setText(""+state.ZIMP[6]);
        msp2.stp8.text1.setText(""+state.ZIMP[7]);
        msp2.stp9.text1.setText(""+state.ZIMP[8]);
        msp2.stp10.text1.setText(""+state.ZIMP[9]);
        
        msp.stp1.text2.setText(""+state.eps_r[0]);
    	msp.stp2.text2.setText(""+state.eps_r[1]);
        msp.stpnew2.text2.setText(""+state.eps_r[1]);// NEW
        msp.stp3.text2.setText(""+state.eps_r[2]);
        msp.stp4.text2.setText(""+state.eps_r[3]);
        msp.stp5.text2.setText(""+state.eps_r[4]);
        msp.stp6.text2.setText(""+state.eps_r[5]);
        msp.stp7.text2.setText(""+state.eps_r[6]);
        msp.stp8.text2.setText(""+state.eps_r[7]);
        msp.stp9.text2.setText(""+state.eps_r[8]);
        msp.stp10.text2.setText(""+state.eps_r[9]);
    
        msp2.stp1.text2.setText(""+state.eps_r[0]);
    	msp2.stp2.text2.setText(""+state.eps_r[1]);
        msp2.stp3.text2.setText(""+state.eps_r[2]);
        msp2.stp4.text2.setText(""+state.eps_r[3]);
        msp2.stp5.text2.setText(""+state.eps_r[4]);
        msp2.stp6.text2.setText(""+state.eps_r[5]);
        msp2.stp7.text2.setText(""+state.eps_r[6]);
        msp2.stp8.text2.setText(""+state.eps_r[7]);
        msp2.stp9.text2.setText(""+state.eps_r[8]);
        msp2.stp10.text2.setText(""+state.eps_r[9]);
        
        
        msp.stp1.setVisible(true);
		    msp.stp2.setVisible(true);
                    msp.stpnew2.setVisible(true); // NEW
		    msp.stp3.setVisible(false);
                    msp.stp4.setVisible(false);
		    msp.stp5.setVisible(false);
                    msp.stp6.setVisible(false);
		    msp.stp7.setVisible(false);
                    msp.stp8.setVisible(false);
		    msp.stp9.setVisible(false);
                    msp.stp10.setVisible(false);  
                    
      mgpa.tgc1.setVisible(false);
      mgpa.tgc2.setVisible(false);
      mgpa.tgc3.setVisible(false);
      mgpa.tgc4.setVisible(false);
}

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,626,565);  	
		
	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,652);
        //g.setFont(fonto);
        //g.drawString("Amanogawa, "+annonuovo+" - All Rights Reserved",30,650);
}

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()==psc.slider){
        //int old = state.PlotTimeScale;
        
	if(mgpb.button_one_ON){
            state.PlotTimeScale = psc.slider.getValue()+1;
        }
        else{
            psc.slider.setValue(state.PlotTimeScale-1);
            psc.repaint();
        }
        
	send_shock_wave();
        sp.setZin(state.Zin, state.lineZ0);
	sp2.setZin(state.Zin, state.lineZ0);
        
	mgpa.tgc1.setXpos(state.xpos);
	mgpa.tgc2.setXpos(state.xpos);
	mgpa.tgc3.setXpos(state.xpos);
	mgpa.tgc4.setXpos(state.xpos);
	mgpb.tgc3.setXpos(state.xpos);
	mgpb.tgc3.setDynamics(false);
        
        if(state.plotFlag == 1){mgpa.plotVoltageCurrent(state);}
        else if(state.plotFlag == 2){mgpa.plotVoltagePhasor(state);}
        else if(state.plotFlag == 3){mgpa.plotCurrentPhasor(state);}
        
        mgpa.tgc1.cleanUp();
        mgpa.tgc2.cleanUp();
        mgpa.tgc3.cleanUp();
        
        if(mgpb.DynamicRunType == 1){mgpb.plotTimeDependentVoltage(state);}
        else if(mgpb.DynamicRunType == 2){mgpb.plotTimeDependentCurrent(state);}
        else if(mgpb.DynamicRunType == 3){mgpb.plotTimeDependentPower(state);}
        mgpb.tgc3.cleanUp();
	
	mgpa.tgc1.repaint();
	mgpa.tgc2.repaint();
	mgpa.tgc3.repaint();
	mgpa.tgc4.repaint();
	mgpb.tgc3.repaint();
    }
    
    if(evt.getSource()== linepanel.slider){
            
            // Only go down to half of original frequency
            if(linepanel.slider.getValue() < 2500){
                linepanel.slider.setValue(2500);
            }
            state.frequency = state.frequency_ref*( 1.0 + (double)(linepanel.slider.getValue() - 5000)/5000.0);
                
            //state.frequency = state.frequency_ref*( 1.0 + (double)(linepanel.slider.getValue() - 5000)/5000.0);
            if(state.frequency == 0.0){
                linepanel.slider.setValue(1);
                state.frequency = state.frequency_ref*( 1.0 + (double)(linepanel.slider.getValue() - 5000)/5000.0);
            }
            /*
            if(!state.zoom_f)
            {
                state.frequency = state.frequency_ref*( 1.0 + (double)(linepanel.slider.getValue() - 2500)/5000.0);
            }
            
             else{
                if(linepanel.slider.getValue() > 0){
                    state.frequency = state.frequency_ref*( 1.0 + (double)(linepanel.slider.getValue() - 2500)/2500.0);
                }
                else{
                    state.frequency = state.frequency_ref*( 1.0 + (double)(1 - 2500)/2500.0);
                }
            }
            */
            
            //mgpb.tgc3.setTrace(false);
            //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
	    
	    send_shock_wave();
            adjust_main_sliders();
	    
	    //state.xpos = 0.0;
            state.xpos = state.lineLength;
	    
            // new version
            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)(10000001*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)(1000001*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)(100001*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)(10001*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)(1001*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;
	    
	    linepanel.setValue(state.lineLength,3);
	    
	    state.ignition();
	    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);
            
            msp.stp1.s1.setMaximum(templine+1);
            msp.stp1.SCROLLMAX=templine+1;
            msp.stp2.s1.setMaximum(templine+1);
            msp.stp2.SCROLLMAX=templine+1;
            msp.stp3.s1.setMaximum(templine+1);
            msp.stp3.SCROLLMAX=templine+1;
            
	    //------------------------------------------------------------------------   
            
            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);
	    ccan.repaint();
	    outputpanel.canvas1.repaint();
	    outputpanel.canvas3.repaint();   
	    
            state.ignition();
	    
	    mgpa.tgc1.setXpos(state.xpos);
	    mgpa.tgc2.setXpos(state.xpos);
	    mgpa.tgc3.setXpos(state.xpos);
	    mgpa.tgc4.setXpos(state.xpos);
	    mgpb.tgc3.setXpos(state.xpos);
	    mgpb.tgc3.setDynamics(false);
	
	    mgpa.tgc1.repaint();
	    mgpa.tgc2.repaint();
	    mgpa.tgc3.repaint();
	    mgpa.tgc4.repaint();
	    mgpb.tgc3.repaint();
	    
            ccan.repaint();
	    linepanel.repaint();
    }
    
    if(evt.getSource()==shuntpanel.slider){
            state.ShuntPlace = shuntpanel.slider.getValue(); 
            //mgpb.tgc3.setTrace(false);
            //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
	    
	    state.ignition();
	    
	    sp.setxpos(state.xpos);
	    if(shuntpanel.c1.getState()){//Impedance choice is on
		sp.setZin(state.Zin,state.lineZ0);
		sp.setZL(state.ZL,state.lineZ0);
                sp.setYin(state.Yin,state.lineZ0);
		sp.setYL(state.YL,state.lineZ0);
	    }
	    else{ //Admittance choice is on
                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);
	    if(shuntpanel.c1.getState()){//Impedance choice is on
		sp2.setZin(state.Zin,state.lineZ0);
		sp2.setZL(state.ZL,state.lineZ0);
                sp2.setYin(state.Yin,state.lineZ0);
		sp2.setYL(state.YL,state.lineZ0);
	    }
	    else{ //Admittance choice is on
                sp2.setZin(state.Zin,state.lineZ0);
		sp2.setZL(state.ZL,state.lineZ0);
		sp2.setYin(state.Yin,state.lineZ0);
		sp2.setYL(state.YL,state.lineZ0);
	    }
            
            send_shock_wave();
            adjust_main_sliders();
	                
	    ccan.repaint();
	    outputpanel.canvas1.repaint();
	    outputpanel.canvas3.repaint();
            sp.repaint();
            sp2.repaint();
            
            mgpa.tgc1.repaint();
            mgpa.tgc2.repaint();
            mgpa.tgc3.repaint();
            mgpa.tgc4.repaint();
            mgpb.tgc3.repaint();
    }
    if(evt.getSource()==slidepanel.slider){
        slidepanel.slider2.setValue(slidepanel.slider2.getMaximum());
	state.xpos = slidepanel.getValue();
	
	if(state.xpos == state.lineLength){
	    slidepanel.slider2.setEnabled(false);  
	}
	else{
	    slidepanel.slider2.setEnabled(true);
	}

	send_shock_wave();
        sp.setZin(state.Zin, state.lineZ0);
	sp2.setZin(state.Zin, state.lineZ0);
        
	mgpa.tgc1.setXpos(state.xpos);
	mgpa.tgc2.setXpos(state.xpos);
	mgpa.tgc3.setXpos(state.xpos);
	mgpa.tgc4.setXpos(state.xpos);
	mgpb.tgc3.setXpos(state.xpos);
	mgpb.tgc3.setDynamics(false);
	
	mgpa.tgc1.repaint();
	mgpa.tgc2.repaint();
	mgpa.tgc3.repaint();
	mgpa.tgc4.repaint();
	mgpb.tgc3.repaint();
    }
    
    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();
	send_shock_wave();
	sp.setZin(state.Zin, state.lineZ0);
	sp2.setZin(state.Zin, state.lineZ0);
	mgpa.tgc1.setXpos(state.xpos);
	mgpa.tgc2.setXpos(state.xpos);
	mgpa.tgc3.setXpos(state.xpos);
	mgpa.tgc4.setXpos(state.xpos);
	mgpb.tgc3.setXpos(state.xpos);
	mgpb.tgc3.setDynamics(false);

        mgpa.tgc1.repaint();
	mgpa.tgc2.repaint();
	mgpa.tgc3.repaint();
	mgpa.tgc4.repaint();
	mgpb.tgc3.repaint();

    }
    
   
    //line section 1
    else if(evt.getSource()==msp.stp1.s2 ||evt.getSource()==msp.stp1.s2b){
            
            msp2.stp1.s2.setValue(msp.stp1.s2.getValue());
            msp2.stp1.s2b.setValue(msp.stp1.s2b.getValue());
            
            send_shock_wave();
            adjust_main_sliders();
	    synchro2();
            msp2.stp1.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[0],7)+" \u03bb");
            msp2.stp1.repaint();
            
    }
    //line section 2
    else if(evt.getSource()==msp.stp2.s2 ||evt.getSource()==msp.stp2.s2b || evt.getSource()==msp.stpnew2.s2 ||evt.getSource()==msp.stpnew2.s2b){
	    
            msp2.stp2.s2.setValue(msp.stp2.s2.getValue());
            msp2.stp2.s2b.setValue(msp.stp2.s2b.getValue());
                
            send_shock_wave();
            adjust_main_sliders();
            synchro2();
            
            msp2.stp2.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[1],7)+" \u03bb");
            msp2.stp2.repaint();
            ccan.repaint();
            
    }
    //line section 3
    else if(evt.getSource()==msp.stp3.s2 ||evt.getSource()==msp.stp3.s2b){
	    
            msp2.stp3.s2.setValue(msp.stp3.s2.getValue());
            msp2.stp3.s2b.setValue(msp.stp3.s2b.getValue());
            
            send_shock_wave();
            adjust_main_sliders();
            synchro2();
            
            msp2.stp3.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[2],7)+" \u03bb");
            msp2.stp3.repaint();
            ccan.repaint();
    }	
    //line section 4
    else if(evt.getSource()==msp.stp4.s2 ||evt.getSource()==msp.stp4.s2b){
	    
            msp2.stp4.s2.setValue(msp.stp4.s2.getValue());
            msp2.stp4.s2b.setValue(msp.stp4.s2b.getValue());
            
            send_shock_wave();
            adjust_main_sliders();
            synchro2();
            
            msp2.stp4.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[3],7)+" \u03bb");
            msp2.stp4.repaint();
            
    }
    //line section 5
    else if(evt.getSource()==msp.stp5.s2 ||evt.getSource()==msp.stp5.s2b){
	    
            msp2.stp5.s2.setValue(msp.stp5.s2.getValue());
            msp2.stp5.s2b.setValue(msp.stp5.s2b.getValue());
            
            send_shock_wave();
            adjust_main_sliders();
            synchro2();
            
            msp2.stp5.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[4],7)+" \u03bb");
            msp2.stp5.repaint();
            
    }
    //line section 6
    else if(evt.getSource()==msp.stp6.s2 ||evt.getSource()==msp.stp6.s2b){
	    
            msp2.stp6.s2.setValue(msp.stp6.s2.getValue());
            msp2.stp6.s2b.setValue(msp.stp6.s2b.getValue());
            
            send_shock_wave();
            adjust_main_sliders();
            synchro2();
            
            msp2.stp6.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[5],7)+" \u03bb");
            msp2.stp6.repaint();
            
    }
    //line section 7
    else if(evt.getSource()==msp.stp7.s2 ||evt.getSource()==msp.stp7.s2b){
	    
            msp2.stp7.s2.setValue(msp.stp7.s2.getValue());
            msp2.stp7.s2b.setValue(msp.stp7.s2b.getValue());
            
            send_shock_wave();
            adjust_main_sliders();
            synchro2();
            
            msp2.stp7.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[6],7)+" \u03bb");
            msp2.stp7.repaint();
            
    }
    //line section 8
    else if(evt.getSource()==msp.stp8.s2 ||evt.getSource()==msp.stp8.s2b){
	    
            msp2.stp8.s2.setValue(msp.stp9.s2.getValue());
            msp2.stp8.s2b.setValue(msp.stp9.s2b.getValue());
            
            send_shock_wave();
            adjust_main_sliders();
            synchro2();
            
            msp2.stp8.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[7],7)+" \u03bb");
            msp2.stp8.repaint();
            
    }
    //line section 9
    else if(evt.getSource()==msp.stp9.s2 ||evt.getSource()==msp.stp9.s2b){
	    
            msp2.stp9.s2.setValue(msp.stp9.s2.getValue());
            msp2.stp9.s2b.setValue(msp.stp9.s2b.getValue());
            
            send_shock_wave();
            adjust_main_sliders();
            synchro2();
            
            msp2.stp9.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[8],7)+" \u03bb");
            msp2.stp9.repaint();
            
    }
    //line section 10
    else if(evt.getSource()==msp.stp10.s2 ||evt.getSource()==msp.stp10.s2b){
	    
            msp2.stp10.s2.setValue(msp.stp10.s2.getValue());
            msp2.stp10.s2b.setValue(msp.stp10.s2b.getValue());
            
            send_shock_wave();
            adjust_main_sliders();
            synchro2();
            
            msp2.stp10.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[9],7)+" \u03bb");
            msp2.stp10.repaint();
            
    }

    //line section 1
    else if(evt.getSource()==msp2.stp1.s2 ||evt.getSource()==msp2.stp1.s2b){
            
            msp.stp1.s2.setValue(msp2.stp1.s2.getValue());
            msp.stp1.s2b.setValue(msp2.stp1.s2b.getValue());
            
            send_shock_wave();
            adjust_main_sliders();
	    synchro1();
            
            msp.stp1.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[0],7)+" \u03bb");
            msp.stp1.repaint();
            
    }
    //line section 2
    else if(evt.getSource()==msp2.stp2.s2 ||evt.getSource()==msp2.stp2.s2b){
	    
            msp.stp2.s2.setValue(msp2.stp2.s2.getValue());
            msp.stp2.s2b.setValue(msp2.stp2.s2b.getValue());
                
            send_shock_wave();
            adjust_main_sliders();
            synchro1();
            
            msp.stp2.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[1],7)+" \u03bb");
            msp.stp2.repaint();
    }
    //line section 3
    else if(evt.getSource()==msp2.stp3.s2 ||evt.getSource()==msp2.stp3.s2b){
	    
            msp.stp3.s2.setValue(msp2.stp3.s2.getValue());
            msp.stp3.s2b.setValue(msp2.stp3.s2b.getValue());
            
            send_shock_wave();
            adjust_main_sliders();
            synchro1();
            
            msp.stp3.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[2],7)+" \u03bb");
            msp.stp3.repaint();
    }	
    //line section 4
    else if(evt.getSource()==msp2.stp4.s2 ||evt.getSource()==msp2.stp4.s2b){
	    
            msp.stp4.s2.setValue(msp2.stp4.s2.getValue());
            msp.stp4.s2b.setValue(msp2.stp4.s2b.getValue());
            
            send_shock_wave();
            adjust_main_sliders();
            synchro1();
            
            msp.stp4.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[3],7)+" \u03bb");
            msp.stp4.repaint();
    }
    //line section 5
    else if(evt.getSource()==msp2.stp5.s2 ||evt.getSource()==msp2.stp5.s2b){
	    
            msp.stp5.s2.setValue(msp2.stp5.s2.getValue());
            msp.stp5.s2b.setValue(msp2.stp5.s2b.getValue());
            
            send_shock_wave();
            adjust_main_sliders();
            synchro1();
            
            msp.stp5.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[4],7)+" \u03bb");
            msp.stp5.repaint();
    }
    //line section 6
    else if(evt.getSource()==msp2.stp6.s2 ||evt.getSource()==msp2.stp6.s2b){
	    
            msp.stp6.s2.setValue(msp2.stp6.s2.getValue());
            msp.stp6.s2b.setValue(msp2.stp6.s2b.getValue());
            
            send_shock_wave();
            adjust_main_sliders();
            synchro1();
            
            msp.stp6.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[5],7)+" \u03bb");
            msp.stp6.repaint();
    }
    //line section 7
    else if(evt.getSource()==msp2.stp7.s2 ||evt.getSource()==msp2.stp7.s2b){
	    
            msp.stp7.s2.setValue(msp2.stp7.s2.getValue());
            msp.stp7.s2b.setValue(msp2.stp7.s2b.getValue());
            
            send_shock_wave();
            adjust_main_sliders();
            synchro1();
            
            msp.stp7.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[6],7)+" \u03bb");
            msp.stp7.repaint();
    }
    //line section 8
    else if(evt.getSource()==msp2.stp8.s2 ||evt.getSource()==msp2.stp8.s2b){
	    
            msp.stp8.s2.setValue(msp2.stp8.s2.getValue());
            msp.stp8.s2b.setValue(msp2.stp8.s2b.getValue());
            
            send_shock_wave();
            adjust_main_sliders();
            synchro1();
            
            msp.stp8.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[7],7)+" \u03bb");
            msp.stp8.repaint();
    }
    //line section 9
    else if(evt.getSource()==msp2.stp9.s2 ||evt.getSource()==msp2.stp9.s2b){
	    
            msp.stp9.s2.setValue(msp2.stp9.s2.getValue());
            msp.stp9.s2b.setValue(msp2.stp9.s2b.getValue());
            
            send_shock_wave();
            adjust_main_sliders();
            synchro1();
            
            msp.stp9.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[8],7)+" \u03bb");
            msp.stp9.repaint();
    }
    //line section 10
    else if(evt.getSource()==msp2.stp10.s2 ||evt.getSource()==msp2.stp10.s2b){
	    
            msp.stp10.s2.setValue(msp2.stp10.s2.getValue());
            msp.stp10.s2b.setValue(msp2.stp10.s2b.getValue());
            
            send_shock_wave();
            adjust_main_sliders();
            synchro1();
            
            msp.stp10.vlab5.setText(""+MaestroA.rounder(state.Section_length_ref[9],7)+" \u03bb");
            msp.stp10.repaint();
    }
    
}

public void actionPerformed(ActionEvent evt){
        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);
            }

            send_shock_wave();
            sp.setZin(state.Zin, state.lineZ0);
            sp2.setZin(state.Zin, state.lineZ0);

            mgpa.tgc1.setXpos(state.xpos);
            mgpa.tgc2.setXpos(state.xpos);
            mgpa.tgc3.setXpos(state.xpos);
            mgpa.tgc4.setXpos(state.xpos);
            mgpb.tgc3.setXpos(state.xpos);
            mgpb.tgc3.setDynamics(false);

            mgpa.tgc1.repaint();
            mgpa.tgc2.repaint();
            mgpa.tgc3.repaint();
            mgpa.tgc4.repaint();
            mgpb.tgc3.repaint();
        }
        
        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();
            send_shock_wave();
            sp.setZin(state.Zin, state.lineZ0);
            sp2.setZin(state.Zin, state.lineZ0);
            mgpa.tgc1.setXpos(state.xpos);
            mgpa.tgc2.setXpos(state.xpos);
            mgpa.tgc3.setXpos(state.xpos);
            mgpa.tgc4.setXpos(state.xpos);
            mgpb.tgc3.setXpos(state.xpos);
            mgpb.tgc3.setDynamics(false);

            mgpa.tgc1.repaint();
            mgpa.tgc2.repaint();
            mgpa.tgc3.repaint();
            mgpa.tgc4.repaint();
            mgpb.tgc3.repaint();
        }
        
        if(evt.getSource()==msp.SetLoad){
           loadpanel.setVisible(true);
           target.setVisible(true);
           shuntpanel.setVisible(false);
	   linepanel.setVisible(false);
	   msp.setVisible(false);
	   generatorpanel.setVisible(false);
           cp.c1.select(" Set Load");
        }
        if(evt.getSource()==loadpanel.SetTr){
           loadpanel.setVisible(false);
           target.setVisible(false);
           shuntpanel.setVisible(false);
	   linepanel.setVisible(false);
	   msp.setVisible(true);
	   generatorpanel.setVisible(false);
           cp.c1.select(" Set Line/Transformer");
        }
        if(evt.getSource()==instructions.bupdate){ 
            //mgpa.setVisible(true);
            //mgpb.setVisible(false);
            instructions.setVisible(false);
            mgpa.tgc1.repaint();
            mgpa.tgc2.repaint();
            mgpa.tgc3.repaint();
            mgpa.tgc4.repaint();
            mgpb.tgc3.repaint();
        }
        if(evt.getSource()==cp.binstructions){ 
            //mgpa.setVisible(true);
            //mgpb.setVisible(false);
            instructions.setVisible(true);
        }
    
        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();
	    }
        
        else 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);
            }
        }
        else 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);
            }
        }
    
        else if(evt.getSource()==linepanel.b1){
	    //mgpb.tgc3.setTrace(false);
            //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
	    
	    if(linepanel.getValue(1) < 0.0){
		state.frequency_ref = 3.0E9;
		linepanel.setValue(3.0E9,1);
	    }
	    else{
		state.frequency_ref = linepanel.getValue(1);
                linepanel.slider.setValue(5000); 
	    }
	    
            state.frequency = state.frequency_ref; 
            
	    /*
            if(linepanel.getValue(2) < 1.0){
		state.epsilon_r = 1.0;
		linepanel.setValue(1.0,2);
	    }
	    else{
		state.epsilon_r = linepanel.getValue(2);
	    }
	    */
            
	      
            send_shock_wave();
            adjust_main_sliders();
	    
	    //state.xpos = 0.0;
	    state.xpos = state.lineLength;
            
            // new version
            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)(10000001*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)(1000001*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)(100001*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)(10001*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)(1001*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;
	    
	    linepanel.setValue(state.lineLength,3);
	    
	    state.ignition();
	    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);
            
            msp.stp1.s1.setMaximum(templine+1);
            msp.stp1.SCROLLMAX=templine+1;
            msp.stp2.s1.setMaximum(templine+1);
            msp.stp2.SCROLLMAX=templine+1;
            msp.stp3.s1.setMaximum(templine+1);
            msp.stp3.SCROLLMAX=templine+1;
            
	    //------------------------------------------------------------------------   
            
            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);
	    ccan.repaint();
	    outputpanel.canvas1.repaint();
	    outputpanel.canvas3.repaint();   
	    
            state.ignition();
	    
	    mgpa.tgc1.setXpos(state.xpos);
	    mgpa.tgc2.setXpos(state.xpos);
	    mgpa.tgc3.setXpos(state.xpos);
	    mgpa.tgc4.setXpos(state.xpos);
	    mgpb.tgc3.setXpos(state.xpos);
	    mgpb.tgc3.setDynamics(false);
	
	    mgpa.tgc1.repaint();
	    mgpa.tgc2.repaint();
	    mgpa.tgc3.repaint();
	    mgpa.tgc4.repaint();
	    mgpb.tgc3.repaint();
	    
            ccan.repaint();
            linepanel.repaint();
	    
	}
        
        else if(evt.getSource()==linepanel.bfa){
        //==============
        
            linepanel.slider.setValue(linepanel.slider.getValue()-1);
            // Only go down to half of original frequency
            if(linepanel.slider.getValue() < 2500){
                linepanel.slider.setValue(2500);
            }
            state.frequency = state.frequency_ref*( 1.0 + (double)(linepanel.slider.getValue() - 5000)/5000.0);
                
            //state.frequency = state.frequency_ref*( 1.0 + (double)(linepanel.slider.getValue() - 5000)/5000.0);
            if(state.frequency == 0.0){
                linepanel.slider.setValue(1);
                state.frequency = state.frequency_ref*( 1.0 + (double)(linepanel.slider.getValue() - 5000)/5000.0);
            }
            
	    send_shock_wave();
            adjust_main_sliders();
	    
	    //state.xpos = 0.0;
            state.xpos = state.lineLength;
	    
            // new version
            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)(10000001*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)(1000001*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)(100001*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)(10001*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)(1001*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;
	    
	    linepanel.setValue(state.lineLength,3);
	    
	    state.ignition();
	    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);
            
            msp.stp1.s1.setMaximum(templine+1);
            msp.stp1.SCROLLMAX=templine+1;
            msp.stp2.s1.setMaximum(templine+1);
            msp.stp2.SCROLLMAX=templine+1;
            msp.stp3.s1.setMaximum(templine+1);
            msp.stp3.SCROLLMAX=templine+1;
            
	    //------------------------------------------------------------------------   
            
            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);
	    ccan.repaint();
	    outputpanel.canvas1.repaint();
	    outputpanel.canvas3.repaint();   
	    
            state.ignition();
	    
	    mgpa.tgc1.setXpos(state.xpos);
	    mgpa.tgc2.setXpos(state.xpos);
	    mgpa.tgc3.setXpos(state.xpos);
	    mgpa.tgc4.setXpos(state.xpos);
	    mgpb.tgc3.setXpos(state.xpos);
	    mgpb.tgc3.setDynamics(false);
	
	    mgpa.tgc1.repaint();
	    mgpa.tgc2.repaint();
	    mgpa.tgc3.repaint();
	    mgpa.tgc4.repaint();
	    mgpb.tgc3.repaint();
	    
            ccan.repaint();
	    linepanel.repaint();
        //==============
        }
        
        else if(evt.getSource()==linepanel.bfb){
        //==============
        
            linepanel.slider.setValue(linepanel.slider.getValue()+1);
            // Only go down to half of original frequency
            if(linepanel.slider.getValue() < 2500){
                linepanel.slider.setValue(2500);
            }
            state.frequency = state.frequency_ref*( 1.0 + (double)(linepanel.slider.getValue() - 5000)/5000.0);
                
            //state.frequency = state.frequency_ref*( 1.0 + (double)(linepanel.slider.getValue() - 5000)/5000.0);
            if(state.frequency == 0.0){
                linepanel.slider.setValue(1);
                state.frequency = state.frequency_ref*( 1.0 + (double)(linepanel.slider.getValue() - 5000)/5000.0);
            }
            
	    send_shock_wave();
            adjust_main_sliders();
	    
	    //state.xpos = 0.0;
            state.xpos = state.lineLength;
	    
            // new version
            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)(10000001*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)(1000001*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)(100001*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)(10001*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)(1001*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;
	    
	    linepanel.setValue(state.lineLength,3);
	    
	    state.ignition();
	    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);
            
            msp.stp1.s1.setMaximum(templine+1);
            msp.stp1.SCROLLMAX=templine+1;
            msp.stp2.s1.setMaximum(templine+1);
            msp.stp2.SCROLLMAX=templine+1;
            msp.stp3.s1.setMaximum(templine+1);
            msp.stp3.SCROLLMAX=templine+1;
            
	    //------------------------------------------------------------------------   
            
            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);
	    ccan.repaint();
	    outputpanel.canvas1.repaint();
	    outputpanel.canvas3.repaint();   
	    
            state.ignition();
	    
	    mgpa.tgc1.setXpos(state.xpos);
	    mgpa.tgc2.setXpos(state.xpos);
	    mgpa.tgc3.setXpos(state.xpos);
	    mgpa.tgc4.setXpos(state.xpos);
	    mgpb.tgc3.setXpos(state.xpos);
	    mgpb.tgc3.setDynamics(false);
	
	    mgpa.tgc1.repaint();
	    mgpa.tgc2.repaint();
	    mgpa.tgc3.repaint();
	    mgpa.tgc4.repaint();
	    mgpb.tgc3.repaint();
	    
            ccan.repaint();
	    linepanel.repaint();
        //==============
        }
        
        else if(evt.getSource()==target.b1){
            double temp1;
            temp1 = target.getValue(0);
            state.targetVSWR = temp1;
            state.ignition();
        }
	else if(evt.getSource()==loadpanel.b1){
            //mgpb.tgc3.setTrace(false);
            //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
            state.frequency = state.frequency_ref;
            linepanel.slider.setValue(5000);
            
	    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);
                    state.ZL_ref = state.ZL;
                    state.YL_ref = state.YL;
		    loadpanel.setValue(state.ZL,0);
		}
		else{
                    state.ZL = loadpanel.getValue(0);
                    state.ZL_ref = state.ZL;
		}
		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);
                    state.ZL_ref = state.ZL;
                    state.YL_ref = state.YL;
		    loadpanel.setValue(state.YL,0);
		}
		else{
                    state.YL = loadpanel.getValue(0);
                    state.YL_ref = state.YL;
		}
		state.is_Load_Ztype = false;
	    }
	    state.ignition();
	    
	    sp.setxpos(state.xpos);
	    if(loadpanel.c1.getState()){//Impedance choice is on
		sp.setZin(state.Zin,state.lineZ0);
		sp.setZL(state.ZL,state.lineZ0);
                sp.setYin(state.Yin,state.lineZ0);
		sp.setYL(state.YL,state.lineZ0);
	    }
	    else{ //Admittance choice is on
                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);
	    if(loadpanel.c1.getState()){//Impedance choice is on
		sp2.setZin(state.Zin,state.lineZ0);
		sp2.setZL(state.ZL,state.lineZ0);
                sp2.setYin(state.Yin,state.lineZ0);
		sp2.setYL(state.YL,state.lineZ0);
	    }
	    else{ //Admittance choice is on
                sp2.setZin(state.Zin,state.lineZ0);
		sp2.setZL(state.ZL,state.lineZ0);
		sp2.setYin(state.Yin,state.lineZ0);
		sp2.setYL(state.YL,state.lineZ0);
	    }
            
            send_shock_wave();
            adjust_main_sliders();
	                
	    ccan.repaint();
	    outputpanel.canvas1.repaint();
	    outputpanel.canvas3.repaint();
            sp.repaint();
            sp2.repaint();
            
            mgpa.tgc1.repaint();
            mgpa.tgc2.repaint();
            mgpa.tgc3.repaint();
            mgpa.tgc4.repaint();
            mgpb.tgc3.repaint();
            
            msp.stpnew2.reset();
            ccan.repaint();
            
            if((state.is_Load_Ztype && (state.ZL.Real() == 0.0 && state.ZL.Imaginary() == 0.0))){
                    cp.setEnabled(false); loadpanel.SetTr.setEnabled(false);
                }
                else if(state.is_Load_Ztype && (state.ZL.Real() == 0.0 && state.ZL.Imaginary() != 0.0)){
                    cp.setEnabled(false); loadpanel.SetTr.setEnabled(false);
                }
                else if(!state.is_Load_Ztype && (state.YL.Real() == 0.0 && state.YL.Imaginary() != 0.0)){
                    cp.setEnabled(false); loadpanel.SetTr.setEnabled(false);
                }
                else if(!state.is_Load_Ztype && (state.YL.Real() == 0.0 && state.YL.Imaginary() == 0.0)){
                    cp.setEnabled(false); loadpanel.SetTr.setEnabled(false);
                }
                else{
                    cp.setEnabled(true); loadpanel.SetTr.setEnabled(true);
                }
	}
        
        else if(evt.getSource()==shuntpanel.b1){
            //mgpb.tgc3.setTrace(false);
            //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
            if(shuntpanel.c1.getState()){//Impedance choice is on
		
		double temp1, temp2;
                temp1 = Double.valueOf(shuntpanel.text1[0].getText()).doubleValue();
		temp2 = Double.valueOf(shuntpanel.text2[0].getText()).doubleValue();
		
                //temp1 = Complex.Real(shuntpanel.getValue(0));
		//temp2 = Complex.Imaginary(shuntpanel.getValue(0));
		
		if(temp1 < 0.0){
		    state.ZS = new Complex(0.0,temp2);
		    state.YS = new Complex(0.0,-1.0/temp2);
                    state.ZS_ref = state.ZS;
                    state.YS_ref = state.YS;
		    shuntpanel.setValue(state.ZS,0);
		}
		else{
                    state.ZS = new Complex(temp1, temp2);
                    state.ZS_ref = state.ZS;
		}
		state.is_Shunt_Ztype = true;
               
	    }
	    else{ //Admittance choice is on
		
		double temp1, temp2;
		temp1 = Double.valueOf(shuntpanel.text1[0].getText()).doubleValue();
		temp2 = Double.valueOf(shuntpanel.text2[0].getText()).doubleValue();
		
                //temp1 = Complex.Real(shuntpanel.getValue(0));
		//temp2 = Complex.Imaginary(shuntpanel.getValue(0));
		
		if(temp1 < 0.0){
		    state.YS = new Complex(0.0,temp2);
		    state.ZS = new Complex(0.0,-1.0/temp2);
                    state.ZS_ref = state.ZS;
                    state.YS_ref = state.YS;
		    shuntpanel.setValue(state.YS,0);
		}
		else{
                    state.YS = new Complex(temp1,temp2);//shuntpanel.getValue(0);
                    state.YS_ref = state.YS;
		}
		state.is_Shunt_Ztype = false;
	    }
            state.ignition();
	    
	    sp.setxpos(state.xpos);
	    if(shuntpanel.c1.getState()){//Impedance choice is on
		sp.setZin(state.Zin,state.lineZ0);
		sp.setZL(state.ZL,state.lineZ0);
                sp.setYin(state.Yin,state.lineZ0);
		sp.setYL(state.YL,state.lineZ0);
	    }
	    else{ //Admittance choice is on
                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);
	    if(shuntpanel.c1.getState()){//Impedance choice is on
		sp2.setZin(state.Zin,state.lineZ0);
		sp2.setZL(state.ZL,state.lineZ0);
                sp2.setYin(state.Yin,state.lineZ0);
		sp2.setYL(state.YL,state.lineZ0);
	    }
	    else{ //Admittance choice is on
                sp2.setZin(state.Zin,state.lineZ0);
		sp2.setZL(state.ZL,state.lineZ0);
		sp2.setYin(state.Yin,state.lineZ0);
		sp2.setYL(state.YL,state.lineZ0);
	    }
            
            send_shock_wave();
            adjust_main_sliders();
	                
	    ccan.repaint();
	    outputpanel.canvas1.repaint();
	    outputpanel.canvas3.repaint();
            sp.repaint();
            sp2.repaint();
            
            mgpa.tgc1.repaint();
            mgpa.tgc2.repaint();
            mgpa.tgc3.repaint();
            mgpa.tgc4.repaint();
            mgpb.tgc3.repaint();
	}
        
	else if(evt.getSource()==generatorpanel.b1){
            //mgpb.tgc3.setTrace(false);
            //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
	    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));
	    }
		
            send_shock_wave();
            adjust_main_sliders();
	    
	    mgpa.tgc1.repaint();
            mgpa.tgc2.repaint();
            mgpa.tgc3.repaint();
            mgpa.tgc4.repaint();
            mgpb.tgc3.repaint();
	}
	// This is set characteristic impedance button (update) on line 1 
	else if(evt.getSource()==msp.stp1.b1 || evt.getSource()==msp.stp1.b4a 
                || evt.getSource()==msp.stp1.b4b || evt.getSource()==msp.stp1.b5a
                || evt.getSource()==msp.stp1.b5b){
            //mgpb.tgc3.setTrace(false);
            //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
	    msp.stp1.repaint();
            synchro2();
            send_shock_wave();
            adjust_main_sliders();
	    
	}
	// This is set characteristic impedance button (update) on line 2
	else if(evt.getSource()==msp.stp2.b1){
            //mgpb.tgc3.setTrace(false);
            //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
	    msp.stp2.repaint();
            synchro2();
            send_shock_wave();
            adjust_main_sliders();
	    
	}
        //CHANGE 10/1/2017  ====================================================
        else if(evt.getSource()==msp.stpnew2.b1 || evt.getSource()==msp.stpnew2.b2a 
                 || evt.getSource()==msp.stpnew2.b2b  || evt.getSource()==msp.stpnew2.b3a 
                 || evt.getSource()==msp.stpnew2.b3b){
        //======================================================================
            //mgpb.tgc3.setTrace(false);
            //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
	    msp.stpnew2.repaint();
            synchro2();
            send_shock_wave();
            adjust_main_sliders();
	    
	}
	// This is set characteristic impedance button (update) on line 3 
	else if(evt.getSource()==msp.stp3.b1){
            //mgpb.tgc3.setTrace(false);
            //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
	    msp.stp3.repaint();
            synchro2();
            send_shock_wave();
            adjust_main_sliders();
	    
	}
        // This is set characteristic impedance button (update) on line 4 
	else if(evt.getSource()==msp.stp4.b1){
            //mgpb.tgc3.setTrace(false);
	    //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
            msp.stp4.repaint();
            adjust_main_sliders();
	    synchro2();
            send_shock_wave();
            
	}
        // This is set characteristic impedance button (update) on line 5 
	else if(evt.getSource()==msp.stp5.b1){
            //mgpb.tgc3.setTrace(false);
	    //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
            msp.stp5.repaint();
            synchro2();
            send_shock_wave();
            adjust_main_sliders();
	    
	}
        // This is set characterisitc impedance button (update) on line 6 
	else if(evt.getSource()==msp.stp6.b1){
            //mgpb.tgc3.setTrace(false);
	    //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
            msp.stp6.repaint();
            synchro2();
            send_shock_wave();
            adjust_main_sliders();
	    
	}
        // This is set characterisitc impedance button (update) on line 7
	else if(evt.getSource()==msp.stp7.b1){
            //mgpb.tgc3.setTrace(false);
	    //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
            msp.stp7.repaint();
            synchro2();
            send_shock_wave();
            adjust_main_sliders();
	    
	}
        // This is set characterisitc impedance button (update) on line 8
	else if(evt.getSource()==msp.stp8.b1){
            //mgpb.tgc3.setTrace(false);
	    //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
            msp.stp8.repaint();
            synchro2();
            send_shock_wave();
            adjust_main_sliders();
	    
	}
        // This is set characterisitc impedance button (update) on line 9
	else if(evt.getSource()==msp.stp9.b1){
            //mgpb.tgc3.setTrace(false);
	    //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
            msp.stp9.repaint();
            synchro2();
            send_shock_wave();
            adjust_main_sliders();
	    
	}
        // This is set characterisitc impedance button (update) on line 10
	else if(evt.getSource()==msp.stp10.b1){
            //mgpb.tgc3.setTrace(false);
            //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
	    msp.stp10.repaint();
            synchro2();
            send_shock_wave();
            adjust_main_sliders();
            
	}

        //-------------------------------------------------------------------
        
        else if(evt.getSource()==msp2.stp1.b1){
            //mgpb.tgc3.setTrace(false);
	    //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
            msp2.stp1.repaint();
            synchro1();
            send_shock_wave();
            adjust_main_sliders();
	    
	}
	// This is set characteristic impedance button (update) on line 2
	else if(evt.getSource()==msp2.stp2.b1){
            //mgpb.tgc3.setTrace(false);
	    //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
            msp2.stp2.repaint();
            synchro1();
            send_shock_wave();
            adjust_main_sliders();
	    
	}
	// This is set characteristic impedance button (update) on line 3 
	else if(evt.getSource()==msp2.stp3.b1){
            //mgpb.tgc3.setTrace(false);
	    //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
            msp2.stp3.repaint();
            synchro1();
            send_shock_wave();
            adjust_main_sliders();
	    
	}
        // This is set characteristic impedance button (update) on line 4 
	else if(evt.getSource()==msp2.stp4.b1){
            //mgpb.tgc3.setTrace(false);
	    //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
            msp2.stp4.repaint();
            synchro1();
            send_shock_wave();
            adjust_main_sliders();
	    
	}
        // This is set characteristic impedance button (update) on line 5 
	else if(evt.getSource()==msp2.stp5.b1){
            //mgpb.tgc3.setTrace(false);
	    //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
            msp2.stp5.repaint();
            synchro1();
            send_shock_wave();
            adjust_main_sliders();
	    
	}
        // This is set characterisitc impedance button (update) on line 6 
	else if(evt.getSource()==msp2.stp6.b1){
            //mgpb.tgc3.setTrace(false);
	    //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
            msp2.stp6.repaint();
            synchro1();
            send_shock_wave();
            adjust_main_sliders();
	    
	}
        // This is set characterisitc impedance button (update) on line 7
	else if(evt.getSource()==msp2.stp7.b1){
            //mgpb.tgc3.setTrace(false);
	    //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
            msp2.stp7.repaint();
            synchro1();
            send_shock_wave();
            adjust_main_sliders();
	    
	}
        // This is set characterisitc impedance button (update) on line 8
	else if(evt.getSource()==msp2.stp8.b1){
            //mgpb.tgc3.setTrace(false);
	    //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
            msp2.stp8.repaint();
            synchro1();
            send_shock_wave();
            adjust_main_sliders();
	    
	}
        // This is set characterisitc impedance button (update) on line 9
	else if(evt.getSource()==msp2.stp9.b1){
            //mgpb.tgc3.setTrace(false);
	    //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
            msp2.stp9.repaint();
            synchro1();
            send_shock_wave();
            adjust_main_sliders();
	    
	}
        // This is set characterisitc impedance button (update) on line 10
	else if(evt.getSource()==msp2.stp10.b1){
            //mgpb.tgc3.setTrace(false);
            //mgpb.cbx1.setState(false);
            //mgpb.cbx2.setState(true);
            
	    msp2.stp10.repaint();
            synchro1();
            send_shock_wave();
            adjust_main_sliders();
            
	}
        
        //-------------------------------------------------------------------
        
        else if(evt.getSource()==tcp.button1){
	    state.IsIncident = true;
            state.IsReflected = false;
            state.IsTotal = false; 
            
            if(mgpb.DynamicRunType == 1){mgpb.plotTimeDependentVoltage(state);}
            else if(mgpb.DynamicRunType == 2){mgpb.plotTimeDependentCurrent(state);}
            else if(mgpb.DynamicRunType == 3){mgpb.plotTimeDependentPower(state);}
            mgpb.tgc3.cleanUp();
            
            /*
            if(state.IwantTraceOn){
                mgpb.cbx1.setState(true);
                mgpb.cbx2.setState(false);
                mgpb.tgc3.setTrace(true);
                
            }
            else{
                mgpb.cbx1.setState(false);
                mgpb.cbx2.setState(true);
                mgpb.tgc3.setTrace(false);
                
            }
            */
            
            tcp.IsButtonOne = true;
            tcp.IsButtonTwo = false;
            tcp.IsButtonThree = false;
            tcp.repaint();
      	}
        
        else if(evt.getSource()==tcp.button2){
	    state.IsIncident = false;
            state.IsReflected = true;
            state.IsTotal = false; 
            
            if(mgpb.DynamicRunType == 1){mgpb.plotTimeDependentVoltage(state);}
            else if(mgpb.DynamicRunType == 2){mgpb.plotTimeDependentCurrent(state);}
            else if(mgpb.DynamicRunType == 3){mgpb.plotTimeDependentPower(state);}
            mgpb.tgc3.cleanUp();
            
            /*
            if(state.IwantTraceOn){
                mgpb.cbx1.setState(true);
                mgpb.cbx2.setState(false);
                mgpb.tgc3.setTrace(true);
            }
            else{
                mgpb.cbx1.setState(false);
                mgpb.cbx2.setState(true);
                mgpb.tgc3.setTrace(false);
            }
            */
            
            tcp.IsButtonOne = false;
            tcp.IsButtonTwo = true;
            tcp.IsButtonThree = false;
            tcp.repaint();
        }
        
        else if(evt.getSource()==tcp.button3){
	    state.IsIncident = false;
            state.IsReflected = false;
            state.IsTotal = true; 
            
            if(mgpb.DynamicRunType == 1){mgpb.plotTimeDependentVoltage(state);}
            else if(mgpb.DynamicRunType == 2){mgpb.plotTimeDependentCurrent(state);}
            else if(mgpb.DynamicRunType == 3){mgpb.plotTimeDependentPower(state);}
            mgpb.tgc3.cleanUp();
            
            /*
            if(state.IwantTraceOn){
                mgpb.cbx1.setState(true);
                mgpb.cbx2.setState(false);
                mgpb.tgc3.setTrace(true);
            }
            else{
                mgpb.cbx1.setState(false);
                mgpb.cbx2.setState(true);
                mgpb.tgc3.setTrace(false);
            }
            */
            
            tcp.IsButtonOne = false;
            tcp.IsButtonTwo = false;
            tcp.IsButtonThree = true;
            tcp.repaint();
	}        
}

public void itemStateChanged(ItemEvent evt){
	    ItemSelectable ie = evt.getItemSelectable();
	    /*
	    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()==msp.stpnew2.lock){
                
                if(msp.stpnew2.lock.getState()){
                    state.xpos = state.locations[1];
                    state.LockCursor = true;
                    slidepanel.slider.setEnabled(false);
                    slidepanel.slider2.setEnabled(false);
                }
                else{
                    state.LockCursor = false;
                    slidepanel.slider.setEnabled(true);
                    slidepanel.slider2.setEnabled(true);
                    state.xpos = slidepanel.getValue()+slidepanel.getValue2();
	
                    //if(state.xpos == state.lineLength){
                     //   slidepanel.slider2.setEnabled(false);  
                    //}
                    //else{
                      //  slidepanel.slider2.setEnabled(true);
                    //}
                }
                
                send_shock_wave();
                sp.setZin(state.Zin, state.lineZ0);
                sp2.setZin(state.Zin, state.lineZ0);
        
                mgpa.tgc1.setXpos(state.xpos);
                mgpa.tgc2.setXpos(state.xpos);
                mgpa.tgc3.setXpos(state.xpos);
                mgpa.tgc4.setXpos(state.xpos);
                mgpb.tgc3.setXpos(state.xpos);
                mgpb.tgc3.setDynamics(false);
	
                mgpa.tgc1.repaint();
                mgpa.tgc2.repaint();
                mgpa.tgc3.repaint();
                mgpa.tgc4.repaint();
                mgpb.tgc3.repaint();
                
            }
                        
	    if(evt.getSource()==cp.c1){
                
                tcp.setVisible(false);
                //psc.setVisible(false);
                
                if(ie.getSelectedObjects()[0]==" Instructions"){
		    instructions.setVisible(true);
		    mgpa.setVisible(false);
		    mgpb.setVisible(false);
		}
                
		if(ie.getSelectedObjects()[0]==" Set Load"){
		    loadpanel.setVisible(true);
                    target.setVisible(true);
                    shuntpanel.setVisible(false);
		    linepanel.setVisible(false);
		    msp.setVisible(false);
		    generatorpanel.setVisible(false);
		    //mgpa.setVisible(false);
		    //mgpb.setVisible(false);
		    
		}
                if(ie.getSelectedObjects()[0]==" Set Shunt"){
		    loadpanel.setVisible(false);
                    target.setVisible(false);
                    shuntpanel.setVisible(true);
		    linepanel.setVisible(false);
		    msp.setVisible(false);
		    generatorpanel.setVisible(false);
		    //mgpa.setVisible(false);
		    //mgpb.setVisible(false);
		    
		}
                else if(ie.getSelectedObjects()[0]==" Set Frequency"){
		    loadpanel.setVisible(false);
                    target.setVisible(false);
                    shuntpanel.setVisible(false);
		    linepanel.setVisible(true);
		    msp.setVisible(false);
		    generatorpanel.setVisible(false);
		    //mgpa.setVisible(false);
		    //mgpb.setVisible(false);
		    
		}		
		else if(ie.getSelectedObjects()[0]==" Set Line/Transformer"){
		    loadpanel.setVisible(false);
                    shuntpanel.setVisible(false);
		    linepanel.setVisible(false);
		    msp.setVisible(true);
		    generatorpanel.setVisible(false);
		    //mgpa.setVisible(false);
		    //mgpb.setVisible(false);
		    
		}	
		else if(ie.getSelectedObjects()[0]==" Set Generator"){
		    loadpanel.setVisible(false);
                    target.setVisible(false);
                    shuntpanel.setVisible(false);
		    linepanel.setVisible(false);
		    msp.setVisible(false);
		    generatorpanel.setVisible(true);
		    //mgpa.setVisible(false);
		    //mgpb.setVisible(false);
		    
		}
                if(ie.getSelectedObjects()[0]==" View Phasor Plots"){
                    //mgpa.c1.select(" Select a Plot"); //*****
		    mgpa.setVisible(true);
                    // CHANGE #4 6/18/2017 =====================================
                    // ADD LINE BELOW
                    // REPOSITION PHASOR PLOT PANEL IN CORRECT PLACE
                    mgpa.setBounds(11+sp_xmove,248+sp_ymove,805,395);
                    //==========================================================
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
		    mgpa.tgc3.setVisible(false);
		    mgpa.tgc4.setVisible(false);
		    mgpb.setVisible(false);
		    msp2.setVisible(false);
                    
                    // Reset "Total" to make sure one has the total waveform when returning to phasor plots - NOT USED
                    //state.IsIncident = false;
                    //state.IsReflected = false;
                    //state.IsTotal = true; 
                    
                    //tcp.IsButtonOne = false;
                    //tcp.IsButtonTwo = false;
                    //tcp.IsButtonThree = true;
                    
                    if(state.WasSWP){
                        mgpa.tgc3.setEnvelope(false);
                        mgpa.tgc4.setEnvelope(false);
                        mgpa.plotVoltageCurrent(state);
                        mgpa.tgc1.setVisible(false);
                        mgpa.tgc2.setVisible(false);
                        mgpa.tgc3.setVisible(true);
                        mgpa.tgc4.setVisible(true);
                        mgpa.tgc1.setFlag(0);
                        mgpa.tgc2.setFlag(0);
                        state.plotFlag = 1;
                    }
                    else if(state.WasVoltPhasor){
                        mgpa.tgc3.setEnvelope(true);
                        mgpa.tgc4.setEnvelope(true);
                        mgpa.plotVoltagePhasor(state);
                        mgpa.tgc1.setVisible(false);
                        mgpa.tgc2.setVisible(false);
                        mgpa.tgc3.setVisible(true);
                        mgpa.tgc4.setVisible(true);
                        mgpa.tgc1.setFlag(0);
                        mgpa.tgc2.setFlag(0);
                        state.plotFlag = 2;
                        psc.setVisible(true);
                    }
                    else if(state.WasCurPhasor){
                        mgpa.tgc3.setEnvelope(true);
                        mgpa.tgc4.setEnvelope(true);
                        mgpa.plotCurrentPhasor(state);
                        mgpa.tgc1.setVisible(false);
                        mgpa.tgc2.setVisible(false);
                        mgpa.tgc3.setVisible(true);
                        mgpa.tgc4.setVisible(true);
                        mgpa.tgc1.setFlag(0);
                        mgpa.tgc2.setFlag(0);
                        state.plotFlag = 3;
                        psc.setVisible(true);
                    }
                    else if(state.WasZ){
                        mgpa.tgc3.setEnvelope(false);
                        mgpa.tgc4.setEnvelope(false);
                        mgpa.plotImpedance(state);
                        mgpa.tgc1.setVisible(true);
                        mgpa.tgc2.setVisible(true);
                        mgpa.tgc3.setVisible(false);
                        mgpa.tgc4.setVisible(false);
                        mgpa.tgc1.setFlag(1);
                        mgpa.tgc2.setFlag(1);
                        state.plotFlag = 4;
                        psc.setVisible(false);
                    }
                    else if(state.WasY){
                        mgpa.tgc3.setEnvelope(false);
                        mgpa.tgc4.setEnvelope(false);
                        mgpa.plotAdmittance(state);
                        mgpa.tgc1.setVisible(true);
                        mgpa.tgc2.setVisible(true);
                        mgpa.tgc3.setVisible(false);
                        mgpa.tgc4.setVisible(false);
                        mgpa.tgc1.setFlag(0);
                        mgpa.tgc2.setFlag(0);
                        state.plotFlag = 5;
                        psc.setVisible(false);
                    }
                    else if(state.WasGamma){
                        mgpa.plotReflectionCoefficient(state);
                        mgpa.tgc1.setVisible(true);
                        mgpa.tgc2.setVisible(true);
                        mgpa.tgc3.setVisible(false);
                        mgpa.tgc4.setVisible(false);
                        mgpa.tgc1.setFlag(2);
                        mgpa.tgc2.setFlag(2);
                        state.plotFlag = 6;
                        psc.setVisible(false);
                    }
                    
                    tcp.repaint();
                    //-------------------------------------------------------------------------
		 }	
		 if(ie.getSelectedObjects()[0]==" View Time Plots"){
		    mgpa.setVisible(false);
		    mgpb.setVisible(true);
                    // CHANGE #5 6/18/2017 =====================================
                    // ADD LINE BELOW
                    // MOVE PHASOR PLOT PANEL OUT OF THE WAY BECAUSE IF FLICKERS
                    // UNDER TIME PLOTS PANEL.  MAC DOES IMPLEMENT setVisible 
                    // CORRECTLT. MAC SUCKS!!!
                    mgpa.setBounds(11+10000,248+10000,805,395);
                    //==========================================================
		    
                    mgpb.c1.setEnabled(true);//*****
                    if(state.WasVoltage){
                        mgpb.c1.select(" Time Dependent Voltage");
                        state.WasVoltage = true;
                        state.WasCurrent = false;
                        state.WasPower = false;                    
                        
                        mgpb.tgc3.setEnabled(true);
                        mgpb.tgc3.setVisible(true);
                        mgpb.ssc.setEnabled(true);
                        mgpb.ssc.setVisible(true);
                        mgpb.plotTimeDependentVoltage(state);
                        
                        mgpb.tgc3.setEnvelope(true);
                        
                        if(state.IsTcpVisible){
                            tcp.setVisible(true);
                        }
                        else{
                            tcp.setVisible(false);
                        }
                     
                        psc.setVisible(true);
                    
                        /*
                        if(state.IwantTraceOn){
                            mgpb.tgc3.setTrace(true);
                            mgpb.cbx1.setState(true);
                            mgpb.cbx2.setState(false);
                        }
                        else{
                            mgpb.tgc3.setTrace(false);
                            mgpb.cbx2.setState(true);
                            mgpb.cbx1.setState(false);
                        }
                        */
                    }
                    else if(state.WasCurrent){
                        mgpb.c1.select(" Time Dependent Current");
                        state.WasVoltage = false;
                        state.WasCurrent = true;
                        state.WasPower = false;                    

                        mgpb.tgc3.setVisible(true);
                        mgpb.tgc3.setEnabled(true);
                        mgpb.ssc.setVisible(true);
                        mgpb.ssc.setEnabled(true);
                        mgpb.plotTimeDependentCurrent(state);
                        mgpb.tgc3.setEnvelope(true);

                         if(state.IsTcpVisible){
                            tcp.setVisible(true);
                        }
                        else{
                            tcp.setVisible(false);
                        }

                            psc.setVisible(true);

                        /*
                        if(state.IwantTraceOn){
                            mgpb.tgc3.setTrace(true);
                            mgpb.cbx1.setState(true);
                            mgpb.cbx2.setState(false);
                        }
                        else{
                            mgpb.tgc3.setTrace(false);
                            mgpb.cbx2.setState(true);
                            mgpb.cbx1.setState(false);
                        }
                        */
                    }
                    else if(state.WasPower){
                        mgpb.c1.select(" Time Dependent Power");
                        state.WasVoltage = false;
                        state.WasCurrent = false;
                        state.WasPower = true;                    

                        mgpb.tgc3.setVisible(true);
                        mgpb.tgc3.setEnabled(true);
                        mgpb.ssc.setVisible(true);//******
                        mgpb.ssc.setEnabled(true);
                        mgpb.plotTimeDependentPower(state);
                        mgpb.tgc3.setEnvelope(false);

                         if(state.IsTcpVisible){
                            tcp.setVisible(true);
                        }
                        else{
                            tcp.setVisible(false);
                        }

                            psc.setVisible(true);

                        /*
                        if(state.IwantTraceOn){
                            mgpb.tgc3.setTrace(true);
                            mgpb.cbx1.setState(true);
                            mgpb.cbx2.setState(false);
                        }
                        else{
                            mgpb.tgc3.setTrace(false);
                            mgpb.cbx2.setState(true);
                            mgpb.cbx1.setState(false);
                        }
                        */
                    }
                    else{
                        mgpb.c1.select(" Select a Plot");
                        mgpa.setVisible(false);
                        mgpb.setVisible(true);

                        mgpb.c1.setEnabled(true);//*****
                        mgpb.c1.select(" Select a Plot");//*****

                        tcp.setVisible(false);
                        mgpb.ssc.setVisible(false);//*****
                        mgpb.ssc.setEnabled(false);
                        mgpb.tgc3.setVisible(false);
                    }
	    
                 }
            }
	    else if(evt.getSource()==cp.c2){
                tcp.setVisible(false);
                psc.setVisible(false);
		if(ie.getSelectedObjects()[0]==" Complete Line"){
                    mgpa.setVisible(false);
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
		    mgpa.tgc3.setVisible(false);
		    mgpa.tgc4.setVisible(false);
		    mgpb.setVisible(false);
                    msp2.setVisible(true);
		    
                } 
                if(ie.getSelectedObjects()[0]==" View Phasor Plots"){
                    mgpa.c1.select(" Select a Plot"); //*****
		    mgpa.setVisible(true);
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
		    mgpa.tgc3.setVisible(false);
		    mgpa.tgc4.setVisible(false);
		    mgpb.setVisible(false);
		    msp2.setVisible(false);
                    
                    // Reset "Total" to make sure one has the total waveform when returning to phasor plots
                    state.IsIncident = false;
                    state.IsReflected = false;
                    state.IsTotal = true; 
           
                    tcp.IsButtonOne = false;
                    tcp.IsButtonTwo = false;
                    tcp.IsButtonThree = true;
                    tcp.repaint();
                    //-------------------------------------------------------------------------
		 }	
		 if(ie.getSelectedObjects()[0]==" Time"){
		    mgpa.setVisible(false);
		    mgpb.setVisible(true);
                    
                    mgpb.c1.setEnabled(true);//*****
                    if(state.WasVoltage){
                        mgpb.c1.select(" Time Dependent Voltage");
                        state.WasVoltage = true;
                        state.WasCurrent = false;
                        state.WasPower = false;                    
                        
                        mgpb.tgc3.setEnabled(true);
                        mgpb.tgc3.setVisible(true);
                        mgpb.ssc.setEnabled(true);
                        mgpb.ssc.setVisible(true);
                        mgpb.plotTimeDependentVoltage(state);
                        
                        mgpb.tgc3.setEnvelope(true);
                        
                        if(state.IsTcpVisible){
                            tcp.setVisible(true);
                        }
                        else{
                            tcp.setVisible(false);
                        }
                     
                        psc.setVisible(true);
                    
                        /*
                        if(state.IwantTraceOn){
                            mgpb.tgc3.setTrace(true);
                            mgpb.cbx1.setState(true);
                            mgpb.cbx2.setState(false);
                        }
                        else{
                            mgpb.tgc3.setTrace(false);
                            mgpb.cbx2.setState(true);
                            mgpb.cbx1.setState(false);
                        }
                        */
                    }
                    else if(state.WasCurrent){
                        mgpb.c1.select(" Time Dependent Current");
                        state.WasVoltage = false;
                        state.WasCurrent = true;
                        state.WasPower = false;                    

                        mgpb.tgc3.setVisible(true);
                        mgpb.tgc3.setEnabled(true);
                        mgpb.ssc.setVisible(true);
                        mgpb.ssc.setEnabled(true);
                        mgpb.plotTimeDependentCurrent(state);
                        mgpb.tgc3.setEnvelope(true);

                         if(state.IsTcpVisible){
                            tcp.setVisible(true);
                        }
                        else{
                            tcp.setVisible(false);
                        }

                            psc.setVisible(true);
                            
                        /*
                        if(state.IwantTraceOn){
                            mgpb.tgc3.setTrace(true);
                            mgpb.cbx1.setState(true);
                            mgpb.cbx2.setState(false);
                        }
                        else{
                            mgpb.tgc3.setTrace(false);
                            mgpb.cbx2.setState(true);
                            mgpb.cbx1.setState(false);
                        }
                        */
                    }
                    else if(state.WasPower){
                        mgpb.c1.select(" Time Dependent Power");
                        state.WasVoltage = false;
                        state.WasCurrent = false;
                        state.WasPower = true;                    

                        mgpb.tgc3.setVisible(true);
                        mgpb.tgc3.setEnabled(true);
                        mgpb.ssc.setVisible(true);//******
                        mgpb.ssc.setEnabled(true);
                        mgpb.plotTimeDependentPower(state);
                        mgpb.tgc3.setEnvelope(false);

                         if(state.IsTcpVisible){
                            tcp.setVisible(true);
                        }
                        else{
                            tcp.setVisible(false);
                        }

                            psc.setVisible(true);

                        /*
                        if(state.IwantTraceOn){
                            mgpb.tgc3.setTrace(true);
                            mgpb.cbx1.setState(true);
                            mgpb.cbx2.setState(false);
                        }
                        else{
                            mgpb.tgc3.setTrace(false);
                            mgpb.cbx2.setState(true);
                            mgpb.cbx1.setState(false);
                        }
                        */
                    }
                    else{
                        mgpb.c1.select(" Select a Plot");
                        mgpa.setVisible(false);
                        mgpb.setVisible(true);

                        mgpb.c1.setEnabled(true);//*****
                        mgpb.c1.select(" Select a Plot");//*****

                        tcp.setVisible(false);
                        mgpb.ssc.setVisible(false);//*****
                        mgpb.ssc.setEnabled(false);
                        mgpb.tgc3.setVisible(false);
                    }
                    mgpb.ssc.setVisible(false);//*****
                    
		    mgpb.ssc.setEnabled(false);
		    //mgpb.tgc1.setVisible(false);
		    mgpb.tgc3.setVisible(false);
		    msp2.setVisible(false);
                    
		 }
                
                /*
		 if(ie.getSelectedObjects()[0]==" Output"){
		    outputpanel.setVisible(true);
                    sp.setVisible(false);
		 }
                 if(ie.getSelectedObjects()[0]==" Smith Chart"){
		    outputpanel.setVisible(false);
                    sp.setVisible(true);
		 }
                 */
                
	    }
	    //Trans_MultiGraphPanelA Choices
	    else if(evt.getSource()==mgpa.c1){
		if(ie.getSelectedObjects()[0]==" Impedance"){
                    state.WasSWP = false;
                    state.WasVoltPhasor = false;
                    state.WasCurPhasor = false;
                    state.WasZ = true;
                    state.WasY = false;
                    state.WasGamma = false;
		    mgpa.tgc3.setEnvelope(false);
                    mgpa.tgc4.setEnvelope(false);
                    mgpa.plotImpedance(state);
		    mgpa.tgc1.setVisible(true);
		    mgpa.tgc2.setVisible(true);
		    mgpa.tgc3.setVisible(false);
		    mgpa.tgc4.setVisible(false);
		    mgpa.tgc1.setFlag(1);
		    mgpa.tgc2.setFlag(1);
                    state.plotFlag = 4;
                    psc.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]==" Admittance"){
                    state.WasSWP = false;
                    state.WasVoltPhasor = false;
                    state.WasCurPhasor = false;
                    state.WasZ = false;
                    state.WasY = true;
                    state.WasGamma = false;
		    mgpa.tgc3.setEnvelope(false);
                    mgpa.tgc4.setEnvelope(false);
                    mgpa.plotAdmittance(state);
		    mgpa.tgc1.setVisible(true);
		    mgpa.tgc2.setVisible(true);
		    mgpa.tgc3.setVisible(false);
		    mgpa.tgc4.setVisible(false);
		    mgpa.tgc1.setFlag(0);
		    mgpa.tgc2.setFlag(0);
                    state.plotFlag = 5;
                    psc.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]==" Reflection Coefficient"){
                    state.WasSWP = false;
                    state.WasVoltPhasor = false;
                    state.WasCurPhasor = false;
                    state.WasZ = false;
                    state.WasY = false;
                    state.WasGamma = true;
		    mgpa.plotReflectionCoefficient(state);
		    mgpa.tgc1.setVisible(true);
		    mgpa.tgc2.setVisible(true);
		    mgpa.tgc3.setVisible(false);
		    mgpa.tgc4.setVisible(false);
		    mgpa.tgc1.setFlag(2);
		    mgpa.tgc2.setFlag(2);
                    state.plotFlag = 6;
                    psc.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]==" Voltage Phasor"){
                    state.WasSWP = false;
                    state.WasVoltPhasor = true;
                    state.WasCurPhasor = false;
                    state.WasZ = false;
                    state.WasY = false;
                    state.WasGamma = false;
		    mgpa.tgc3.setEnvelope(true);
                    mgpa.tgc4.setEnvelope(true);
                    mgpa.plotVoltagePhasor(state);
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
		    mgpa.tgc3.setVisible(true);
		    mgpa.tgc4.setVisible(true);
		    mgpa.tgc1.setFlag(0);
		    mgpa.tgc2.setFlag(0);
                    state.plotFlag = 2;
                    psc.setVisible(true);
		} 
		else if(ie.getSelectedObjects()[0]==" Current Phasor"){
                    state.WasSWP = false;
                    state.WasVoltPhasor = false;
                    state.WasCurPhasor = true;
                    state.WasZ = false;
                    state.WasY = false;
                    state.WasGamma = false;
		    mgpa.tgc3.setEnvelope(true);
                    mgpa.tgc4.setEnvelope(true);
                    mgpa.plotCurrentPhasor(state);
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
		    mgpa.tgc3.setVisible(true);
		    mgpa.tgc4.setVisible(true);
		    mgpa.tgc1.setFlag(0);
		    mgpa.tgc2.setFlag(0);
                    state.plotFlag = 3;
                    psc.setVisible(true);
		} 
		else if(ie.getSelectedObjects()[0]==" Standing Wave Pattern - | V | & | I |"){
		    state.WasSWP = true;
                    state.WasVoltPhasor = false;
                    state.WasCurPhasor = false;
                    state.WasZ = false;
                    state.WasY = false;
                    state.WasGamma = false;
                    mgpa.tgc3.setEnvelope(false);
                    mgpa.tgc4.setEnvelope(false);
                    mgpa.plotVoltageCurrent(state);
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
		    mgpa.tgc3.setVisible(true);
		    mgpa.tgc4.setVisible(true);
		    mgpa.tgc1.setFlag(0);
		    mgpa.tgc2.setFlag(0);
                    state.plotFlag = 1;
                    
                        psc.setVisible(true);
                    
		}
                else if(ie.getSelectedObjects()[0]==" Select a Plot"){
                    mgpa.c1.select(" Select a Plot"); 
		    state.WasSWP = false;
                    state.WasVoltPhasor = false;
                    state.WasCurPhasor = false;
                    state.WasZ = false;
                    state.WasY = false;
                    state.WasGamma = false;
		    //position.setDark(false);
		    //position.setVisible(false);
		    
		    mgpa.setVisible(true);
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
		    mgpa.tgc3.setVisible(false);
		    mgpa.tgc4.setVisible(false);
		    mgpb.setVisible(false);
                    
                    // Reset "Total" to make sure one has the total waveform when returning to phasor plots
                    state.IsIncident = false;
                    state.IsReflected = false;
                    state.IsTotal = true; 
           
                    tcp.IsButtonOne = false;
                    tcp.IsButtonTwo = false;
                    tcp.IsButtonThree = true;
                    tcp.repaint();
                    
                    //---------------------------------
                
                }
		//mgpa.tgc1.setVisible(true);
		//mgpa.tgc2.setVisible(true);
	    }
	    //Trans_MultiGraphPanelB Choices
	    else if(evt.getSource()==mgpb.c1){
		//mgpb.tgc3.setVisible(true);
                 
		if(ie.getSelectedObjects()[0]==" Time Dependent Voltage"){
                   
                    state.WasVoltage = true;
                    state.WasCurrent = false;
                    state.WasPower = false;                    
                    
                    mgpb.tgc3.setEnabled(true);
                    mgpb.tgc3.setVisible(true);
		    mgpb.ssc.setEnabled(true);
                    mgpb.ssc.setVisible(true);
		    mgpb.plotTimeDependentVoltage(state);
                    
                    mgpb.tgc3.setEnvelope(true);
                    
                    if(state.IsTcpVisible){
                        tcp.setVisible(true);
                    }
                    else{
                        tcp.setVisible(false);
                    }
                     
                        psc.setVisible(true);
                    /*
                    if(state.IwantTraceOn){
			mgpb.tgc3.setTrace(true);
                        mgpb.cbx1.setState(true);
                        mgpb.cbx2.setState(false);
                    }
                    else{
                        mgpb.tgc3.setTrace(false);
                        mgpb.cbx2.setState(true);
                        mgpb.cbx1.setState(false);
                    }
                    */
                }
		else if(ie.getSelectedObjects()[0]==" Time Dependent Current"){
                    state.WasVoltage = false;
                    state.WasCurrent = true;
                    state.WasPower = false;                    
                    
                    mgpb.tgc3.setVisible(true);
                    mgpb.tgc3.setEnabled(true);
                    mgpb.ssc.setVisible(true);
		    mgpb.ssc.setEnabled(true);
		    mgpb.plotTimeDependentCurrent(state);
                    mgpb.tgc3.setEnvelope(true);
                    
                     if(state.IsTcpVisible){
                        tcp.setVisible(true);
                    }
                    else{
                        tcp.setVisible(false);
                    }
                     
                        psc.setVisible(true);
                    /*
                    if(state.IwantTraceOn){
			mgpb.tgc3.setTrace(true);
                        mgpb.cbx1.setState(true);
                        mgpb.cbx2.setState(false);
                    }
                    else{
                        mgpb.tgc3.setTrace(false);
                        mgpb.cbx2.setState(true);
                        mgpb.cbx1.setState(false);
                    }
                    */
		}
		else if(ie.getSelectedObjects()[0]==" Time Dependent Power"){
                    state.WasVoltage = false;
                    state.WasCurrent = false;
                    state.WasPower = true;                    
                    
                    mgpb.tgc3.setVisible(true);
                    mgpb.tgc3.setEnabled(true);
                    mgpb.ssc.setVisible(true);//******
		    mgpb.ssc.setEnabled(true);
		    mgpb.plotTimeDependentPower(state);
                    mgpb.tgc3.setEnvelope(false);
                    
                     if(state.IsTcpVisible){
                        tcp.setVisible(true);
                    }
                    else{
                        tcp.setVisible(false);
                    }
                     
                        psc.setVisible(true);
                    /*
                    if(state.IwantTraceOn){
			mgpb.tgc3.setTrace(true);
                        mgpb.cbx1.setState(true);
                        mgpb.cbx2.setState(false);
                    }
                    else{
                        mgpb.tgc3.setTrace(false);
                        mgpb.cbx2.setState(true);
                        mgpb.cbx1.setState(false);
                    }
                    */
		}
                else if(ie.getSelectedObjects()[0]==" Select a Plot"){//*****
                    mgpa.setVisible(false);
		    mgpb.setVisible(true);

                    mgpb.c1.setEnabled(true);//*****
                    mgpb.c1.select(" Select a Plot");//*****
                    
                    tcp.setVisible(false);
                    mgpb.ssc.setVisible(false);//*****
                    mgpb.ssc.setEnabled(false);
                    mgpb.tgc3.setVisible(false);
                }
	    }
	    /*
            //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();
		//System.out.println("Stub 2 : "+state.stub[1]);
	    }
	    //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();
	    }	
            */
            
            if(evt.getSource() == mgpb.cbx1){
                mgpb.tgc3.setTrace(true);
                state.TraceWasOn = true;
                state.IwantTraceOn = true;
                 mgpb.tgc3.cleanUp();
            }
            else if(evt.getSource() == mgpb.cbx2){
                mgpb.tgc3.setTrace(false);
                state.TraceWasOn = false;
                state.IwantTraceOn = false;
                 mgpb.tgc3.cleanUp();
            }
            
            if(evt.getSource() == cp.cbx1){
                outputpanel.setVisible(false);
                sp.setVisible(true);
                // CHANGE #3 6/18/2017 =========================================
                // ADD LINE BELOW
                // REPOSITIONs SMITH CHART IN CORRECT PLACE WHEN SELECTED
                sp.setBounds(824+sp_xmove,248+sp_ymove,311,395);
                //==============================================================
            }
            else if(evt.getSource() == cp.cbx2){
                outputpanel.setVisible(true);
                sp.setVisible(false);
                // CHANGE #4 6/18/2017 =========================================
                // ADD LINE BELOW
                // MOVEs SMITH CHART AWAY BECAUSE IT FLICKERS UNDER THE OUTPUT
                // PANEL - MAC DOES NOT IMPLEMENT CORRECTLY "setVisible"
                // MAC SUCKS!!!
                sp.setBounds(824+10000,248+10000,311,395);
                //==============================================================
            }
            
}

public void mouseClicked(MouseEvent evt){mouseHandler(evt);}
    public void mouseEntered(MouseEvent evt){;}
    public void mouseExited(MouseEvent evt){;}
    public void mousePressed(MouseEvent evt){;}
    public void mouseReleased(MouseEvent evt){;}
    
     private synchronized void mouseHandler(MouseEvent evt){
	if(evt.getSource() == mgpb.ssc.button1){
            if(mgpb.DynamicRunType==3)
            {
                tcp.button1.setEnabled(false);
                tcp.button2.setEnabled(false);
                tcp.button3.setEnabled(false);
            }
            mgpb.c1.setEnabled(false);
            //state.IsTronRunning = true;
            slidepanel.slider.setEnabled(false);
	    slidepanel.slider2.setEnabled(false);
            
            
            if(state.TraceWasOn && !mgpb.cbx1.getState()){
                state.IwantTraceOn = true; 
                mgpb.cbx1.setState(true);
                mgpb.cbx2.setState(false);
                mgpb.tgc3.setTrace(true);
                
            }
            
             
            msp.stp1.setEnabled(false);
            msp.stp2.setEnabled(false);
            msp.stpnew2.setEnabled(false);
            msp.stp3.setEnabled(false);
            msp.stp4.setEnabled(false);
            msp.stp5.setEnabled(false);
            msp.stp6.setEnabled(false);
            msp.stp7.setEnabled(false);
            msp.stp8.setEnabled(false);
            msp.stp9.setEnabled(false);
            msp.stp10.setEnabled(false);
            generatorpanel.setEnabled(false);
            loadpanel.setEnabled(false);
            shuntpanel.setEnabled(false);
            linepanel.setEnabled(false);
            cp.c1.setEnabled(false);
            cp.c2.setEnabled(false);
            mgpb.ssc.IsStop = false;
            mgpb.ssc.repaint();
	}
	if(evt.getSource() == mgpb.ssc.button2){
	    tcp.button1.setEnabled(true);
            tcp.button2.setEnabled(true);
            tcp.button3.setEnabled(true);
            mgpb.c1.setEnabled(true);
            
            //state.IsTronRunning = false;
            slidepanel.slider.setEnabled(true);
	    slidepanel.slider2.setEnabled(true);
            
            msp.stp1.setEnabled(true);
            msp.stp2.setEnabled(true);
            msp.stpnew2.setEnabled(true);
            msp.stp3.setEnabled(true);
            msp.stp4.setEnabled(true);
            msp.stp5.setEnabled(true);
            msp.stp6.setEnabled(true);
            msp.stp7.setEnabled(true);
            msp.stp8.setEnabled(true);
            msp.stp9.setEnabled(true);
            msp.stp10.setEnabled(true);
            generatorpanel.setEnabled(true);
            loadpanel.setEnabled(true);
            shuntpanel.setEnabled(true);
            linepanel.setEnabled(true);
            cp.c1.setEnabled(true);
            cp.c2.setEnabled(true);
            mgpb.ssc.IsStop = true;
            mgpb.ssc.repaint();
	}
    }

private void adjust_main_sliders(){
            
            //state.xpos = 0.0;
            state.xpos = state.lineLength;
	    
            state.locations[0] = state.Section_length[0];
            
            for(int i = 1; i < 10; i++){
                state.locations[i] = state.locations[i-1] + state.Section_length[i];
            }
         
            state.lineLength = state.locations[9];
            
            state.lineLength_meters = 0.0;
            for(int i = 0; i < 10; i++){
                state.lineLength_meters = state.lineLength_meters + state.Section_length_meters[i];
                //System.out.println(i+"   "+state.Section_length_meters[i]);
            }
            //System.out.println(state.lineLength_meters);
            
            if(state.plotFlag == 1){mgpa.plotVoltageCurrent(state);}
            if(state.plotFlag == 2){mgpa.plotVoltagePhasor(state);}
            if(state.plotFlag == 3){mgpa.plotCurrentPhasor(state);}
            if(state.plotFlag == 4){mgpa.plotImpedance(state);}
            if(state.plotFlag == 5){mgpa.plotAdmittance(state);}
            if(state.plotFlag == 6){mgpa.plotReflectionCoefficient(state);}
            
            //state.ScanTimeDependentVoltage();
            //state.ScanTimeDependentCurrent();
            //state.ScanTimeDependentPower();
            if(mgpb.DynamicRunType == 1){mgpb.plotTimeDependentVoltage(state);}
            else if(mgpb.DynamicRunType == 2){mgpb.plotTimeDependentCurrent(state);}
            else if(mgpb.DynamicRunType == 3){mgpb.plotTimeDependentPower(state);}
            mgpb.tgc3.cleanUp();
	
            
            // new version
            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)(10000001*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)(1000001*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)(100001*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)(10001*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)(1001*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;
	    
	    linepanel.setValue(state.lineLength,3);
	    
	    state.ignition();
	    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);
            
            msp.stp1.s1.setMaximum(templine+1);
            msp.stp1.SCROLLMAX=templine+1;
            msp.stp2.s1.setMaximum(templine+1);
            msp.stp2.SCROLLMAX=templine+1;
            msp.stp3.s1.setMaximum(templine+1);
            msp.stp3.SCROLLMAX=templine+1;
            
	    //------------------------------------------------------------------------   
            
            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);
	    ccan.repaint();
            outputpanel.canvas1.repaint();
	    outputpanel.canvas3.repaint();   
	    
            state.ignition();
	    
	    mgpa.tgc1.setXpos(state.xpos);
	    mgpa.tgc2.setXpos(state.xpos);
	    mgpa.tgc3.setXpos(state.xpos);
	    mgpa.tgc4.setXpos(state.xpos);
	    mgpb.tgc3.setXpos(state.xpos);
	    mgpb.tgc3.setDynamics(false);
	
	    mgpa.tgc1.repaint();
	    mgpa.tgc2.repaint();
	    mgpa.tgc3.repaint();
	    mgpa.tgc4.repaint();
	    mgpb.tgc3.repaint();
	    
            ccan.repaint();
	    
}

private void synchro1(){
        msp.stp1.text1.setText(""+Double.valueOf(msp2.stp1.text1.getText()).doubleValue());
    	msp.stp2.text1.setText(""+Double.valueOf(msp2.stp2.text1.getText()).doubleValue());
        msp.stp3.text1.setText(""+Double.valueOf(msp2.stp3.text1.getText()).doubleValue());
        msp.stp4.text1.setText(""+Double.valueOf(msp2.stp4.text1.getText()).doubleValue());
        msp.stp5.text1.setText(""+Double.valueOf(msp2.stp5.text1.getText()).doubleValue());
        msp.stp6.text1.setText(""+Double.valueOf(msp2.stp6.text1.getText()).doubleValue());
        msp.stp7.text1.setText(""+Double.valueOf(msp2.stp7.text1.getText()).doubleValue());
        msp.stp8.text1.setText(""+Double.valueOf(msp2.stp8.text1.getText()).doubleValue());
        msp.stp9.text1.setText(""+Double.valueOf(msp2.stp9.text1.getText()).doubleValue());
        msp.stp10.text1.setText(""+Double.valueOf(msp2.stp10.text1.getText()).doubleValue());

        msp.stp1.text2.setText(""+Double.valueOf(msp2.stp1.text2.getText()).doubleValue());
    	msp.stp2.text2.setText(""+Double.valueOf(msp2.stp2.text2.getText()).doubleValue());
        msp.stp3.text2.setText(""+Double.valueOf(msp2.stp3.text2.getText()).doubleValue());
        msp.stp4.text2.setText(""+Double.valueOf(msp2.stp4.text2.getText()).doubleValue());
        msp.stp5.text2.setText(""+Double.valueOf(msp2.stp5.text2.getText()).doubleValue());
        msp.stp6.text2.setText(""+Double.valueOf(msp2.stp6.text2.getText()).doubleValue());
        msp.stp7.text2.setText(""+Double.valueOf(msp2.stp7.text2.getText()).doubleValue());
        msp.stp8.text2.setText(""+Double.valueOf(msp2.stp8.text2.getText()).doubleValue());
        msp.stp9.text2.setText(""+Double.valueOf(msp2.stp9.text2.getText()).doubleValue());
        msp.stp10.text2.setText(""+Double.valueOf(msp2.stp10.text2.getText()).doubleValue());
}

private void synchro2(){
        msp2.stp1.text1.setText(""+Double.valueOf(msp.stp1.text1.getText()).doubleValue());
    	msp2.stp2.text1.setText(""+Double.valueOf(msp.stp2.text1.getText()).doubleValue());
        msp2.stp3.text1.setText(""+Double.valueOf(msp.stp3.text1.getText()).doubleValue());
        msp2.stp4.text1.setText(""+Double.valueOf(msp.stp4.text1.getText()).doubleValue());
        msp2.stp5.text1.setText(""+Double.valueOf(msp.stp5.text1.getText()).doubleValue());
        msp2.stp6.text1.setText(""+Double.valueOf(msp.stp6.text1.getText()).doubleValue());
        msp2.stp7.text1.setText(""+Double.valueOf(msp.stp7.text1.getText()).doubleValue());
        msp2.stp8.text1.setText(""+Double.valueOf(msp.stp8.text1.getText()).doubleValue());
        msp2.stp9.text1.setText(""+Double.valueOf(msp.stp9.text1.getText()).doubleValue());
        msp2.stp10.text1.setText(""+Double.valueOf(msp.stp10.text1.getText()).doubleValue());
    
        msp2.stp1.text2.setText(""+Double.valueOf(msp.stp1.text2.getText()).doubleValue());
    	msp2.stp2.text2.setText(""+Double.valueOf(msp.stp2.text2.getText()).doubleValue());
        msp2.stp3.text2.setText(""+Double.valueOf(msp.stp3.text2.getText()).doubleValue());
        msp2.stp4.text2.setText(""+Double.valueOf(msp.stp4.text2.getText()).doubleValue());
        msp2.stp5.text2.setText(""+Double.valueOf(msp.stp5.text2.getText()).doubleValue());
        msp2.stp6.text2.setText(""+Double.valueOf(msp.stp6.text2.getText()).doubleValue());
        msp2.stp7.text2.setText(""+Double.valueOf(msp.stp7.text2.getText()).doubleValue());
        msp2.stp8.text2.setText(""+Double.valueOf(msp.stp8.text2.getText()).doubleValue());
        msp2.stp9.text2.setText(""+Double.valueOf(msp.stp9.text2.getText()).doubleValue());
        msp2.stp10.text2.setText(""+Double.valueOf(msp.stp10.text2.getText()).doubleValue());
}

private void send_shock_wave(){
    
        
        state.ZIMP[0]=Double.valueOf(msp.stp1.text1.getText()).doubleValue();
        state.ZIMP[1]=Double.valueOf(msp.stp2.text1.getText()).doubleValue();
        state.ZIMP[1]=Double.valueOf(msp.stpnew2.text1.getText()).doubleValue(); // NEW
        state.ZIMP[2]=Double.valueOf(msp.stp3.text1.getText()).doubleValue();
        state.ZIMP[3]=Double.valueOf(msp.stp4.text1.getText()).doubleValue();
        state.ZIMP[4]=Double.valueOf(msp.stp5.text1.getText()).doubleValue();
        state.ZIMP[5]=Double.valueOf(msp.stp6.text1.getText()).doubleValue();
        state.ZIMP[6]=Double.valueOf(msp.stp7.text1.getText()).doubleValue();
        state.ZIMP[7]=Double.valueOf(msp.stp8.text1.getText()).doubleValue();
        state.ZIMP[8]=Double.valueOf(msp.stp9.text1.getText()).doubleValue();
        state.ZIMP[9]=Double.valueOf(msp.stp10.text1.getText()).doubleValue();
        
        state.eps_r[0]=Double.valueOf(msp.stp1.text2.getText()).doubleValue();
        state.eps_r[1]=Double.valueOf(msp.stp2.text2.getText()).doubleValue();
        state.eps_r[1]=Double.valueOf(msp.stpnew2.text2.getText()).doubleValue();
        state.eps_r[2]=Double.valueOf(msp.stp3.text2.getText()).doubleValue();
        state.eps_r[3]=Double.valueOf(msp.stp4.text2.getText()).doubleValue();
        state.eps_r[4]=Double.valueOf(msp.stp5.text2.getText()).doubleValue();
        state.eps_r[5]=Double.valueOf(msp.stp6.text2.getText()).doubleValue();
        state.eps_r[6]=Double.valueOf(msp.stp7.text2.getText()).doubleValue();
        state.eps_r[7]=Double.valueOf(msp.stp8.text2.getText()).doubleValue();
        state.eps_r[8]=Double.valueOf(msp.stp9.text2.getText()).doubleValue();
        state.eps_r[9]=Double.valueOf(msp.stp10.text2.getText()).doubleValue();
        
        state.Section_length_ref[0] = (msp.stp1.SCROLLMAXC-msp.stp1.SCROLLMIN-1-msp.stp1.s2.getValue())
                                  *0.5/(msp.stp1.SCROLLMAXC-msp.stp1.SCROLLMIN-1)
                                  +(0.000001*(double)(msp.stp1.SCROLLMAXB-msp.stp1.SCROLLMIN-1-msp.stp1.s2b.getValue()));
        
        state.Section_length_ref[1] = (msp.stp2.SCROLLMAXC-msp.stp2.SCROLLMIN-1-msp.stp2.s2.getValue())
                                  *0.5/(msp.stp2.SCROLLMAXC-msp.stp2.SCROLLMIN-1)
                                  +(0.000001*(double)(msp.stp2.SCROLLMAXB-msp.stp2.SCROLLMIN-1-msp.stp2.s2b.getValue()));
        
        state.Section_length_ref[2] = (msp.stp3.SCROLLMAXC-msp.stp3.SCROLLMIN-1-msp.stp3.s2.getValue())
                                  *0.5/(msp.stp3.SCROLLMAXC-msp.stp3.SCROLLMIN-1)
                                  +(0.000001*(double)(msp.stp3.SCROLLMAXB-msp.stp3.SCROLLMIN-1-msp.stp3.s2b.getValue()));
        
        state.Section_length_ref[3] = (msp.stp4.SCROLLMAXC-msp.stp4.SCROLLMIN-1-msp.stp4.s2.getValue())
                                  *0.5/(msp.stp4.SCROLLMAXC-msp.stp4.SCROLLMIN-1)
                                  +(0.000001*(double)(msp.stp4.SCROLLMAXB-msp.stp4.SCROLLMIN-1-msp.stp4.s2b.getValue()));
        
        state.Section_length_ref[4] = (msp.stp5.SCROLLMAXC-msp.stp5.SCROLLMIN-1-msp.stp5.s2.getValue())
                                  *0.5/(msp.stp5.SCROLLMAXC-msp.stp5.SCROLLMIN-1)
                                  +(0.000001*(double)(msp.stp5.SCROLLMAXB-msp.stp5.SCROLLMIN-1-msp.stp5.s2b.getValue()));
                                  
        state.Section_length_ref[5] = (msp.stp6.SCROLLMAXC-msp.stp6.SCROLLMIN-1-msp.stp6.s2.getValue())
                                  *0.5/(msp.stp6.SCROLLMAXC-msp.stp6.SCROLLMIN-1)
                                  +(0.000001*(double)(msp.stp6.SCROLLMAXB-msp.stp6.SCROLLMIN-1-msp.stp6.s2b.getValue()));
        
        state.Section_length_ref[6] = (msp.stp7.SCROLLMAXC-msp.stp7.SCROLLMIN-1-msp.stp7.s2.getValue())
                                  *0.5/(msp.stp7.SCROLLMAXC-msp.stp7.SCROLLMIN-1)
                                  +(0.000001*(double)(msp.stp7.SCROLLMAXB-msp.stp7.SCROLLMIN-1-msp.stp7.s2b.getValue()));
        
        state.Section_length_ref[7] = (msp.stp8.SCROLLMAXC-msp.stp8.SCROLLMIN-1-msp.stp8.s2.getValue())
                                  *0.5/(msp.stp8.SCROLLMAXC-msp.stp8.SCROLLMIN-1)
                                  +(0.000001*(double)(msp.stp8.SCROLLMAXB-msp.stp8.SCROLLMIN-1-msp.stp8.s2b.getValue()));
        
        state.Section_length_ref[8] = (msp.stp9.SCROLLMAXC-msp.stp9.SCROLLMIN-1-msp.stp9.s2.getValue())
                                  *0.5/(msp.stp9.SCROLLMAXC-msp.stp9.SCROLLMIN-1)
                                  +(0.000001*(double)(msp.stp9.SCROLLMAXB-msp.stp9.SCROLLMIN-1-msp.stp9.s2b.getValue()));
        
        state.Section_length_ref[9] = (msp.stp10.SCROLLMAXC-msp.stp10.SCROLLMIN-1-msp.stp10.s2.getValue())
                                  *0.5/(msp.stp10.SCROLLMAXC-msp.stp10.SCROLLMIN-1)
                                  +(0.000001*(double)(msp.stp10.SCROLLMAXB-msp.stp10.SCROLLMIN-1-msp.stp10.s2b.getValue()));
        
        
        state.Section_length[0] = state.Section_length_ref[0] * state.f_ratio;
	state.Section_length[1] = state.Section_length_ref[1] * state.f_ratio;
        state.Section_length[2] = state.Section_length_ref[2] * state.f_ratio;
        state.Section_length[3] = state.Section_length_ref[3] * state.f_ratio;
        state.Section_length[4] = state.Section_length_ref[4] * state.f_ratio;
        state.Section_length[5] = state.Section_length_ref[5] * state.f_ratio;
        state.Section_length[6] = state.Section_length_ref[6] * state.f_ratio;
        state.Section_length[7] = state.Section_length_ref[7] * state.f_ratio;
        state.Section_length[8] = state.Section_length_ref[8] * state.f_ratio;
        state.Section_length[9] = state.Section_length_ref[9] * state.f_ratio;
        
        state.ignition();
        /*
        state.ScanImpedance();
        state.ScanAdmittance();
        state.ScanReflectionCoefficient();
        state.ScanVoltage();
        state.ScanCurrent();
        state.ScanVoltageCurrent();
        
        mgpa.plotVoltageCurrent(state);
        mgpa.plotVoltagePhasor(state);
        mgpa.plotCurrentPhasor(state);
        mgpa.plotImpedance(state);
        mgpa.plotAdmittance(state);
        mgpa.plotReflectionCoefficient(state);
        */
        
	ccan.repaint();
	sp.setxpos(state.xpos);
	sp.setZin(state.Zin,state.lineZ0);
	
        //sp2.setxpos(state.xpos);
	//sp2.setZin(state.Zin,state.lineZ0);
	//sp.setYin(state.Yin,state.lineZ0);
	
        outputpanel.canvas1.repaint();
	outputpanel.canvas3.repaint();
        
        //try{
	//	mgpb.tron.sleep(1000);
	//}
	//catch(InterruptedException e){e.printStackTrace();}
        
        mgpa.tgc1.cleanUp();
        mgpa.tgc2.cleanUp();
        mgpa.tgc3.cleanUp();
        mgpa.tgc4.cleanUp();
        mgpb.tgc3.cleanUp();
	
	mgpa.tgc1.repaint();
	mgpa.tgc2.repaint();
	mgpa.tgc3.repaint();
	mgpa.tgc4.repaint();
	mgpb.tgc3.repaint();
        
        
}    
     

}
