// Transient in transmission line

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.awt.font.*;
import java.net.URL;
import java.text.*;
import java.util.Map;
import java.util.Hashtable;
import java.util.jar.Attributes;


public class TransientResponse extends Frame implements AdjustmentListener, ActionListener, ItemListener, MouseListener, WindowListener{
    Instructions instructions;
    Panel instrOutline;
    //About about;
    TitlePanel titlepanel;
    CircuitCanvas ccan;
    ChoicePanel cp;
    TransSlidePanel slidepanel;
    Trans_OutputPanel outputpanel;
    ClosePanel closepanel;
    Trans_State state;
    LinePanel linepanel;
    TransLoadPanel loadpanel;
    PR2 generatorpanel;
    Trans_MultiGraphPanelA mgpa;
    Trans_MultiGraphPanelC mgpc;
    
    private static final Color tinta = new Color(245,245,245);
    // CHANGE ==================================================================
    public int xmove = 10;
    public int ymove = 34;
    //==========================================================================
    
    Font ttfFont, phiFont, italicFont;

    private static final boolean useOldFonts = true;    
   
    public static void main(String[] args){
        TransientResponse f = new TransientResponse();
        int xxmove = 20;
        int yymove = 41;
        f.setSize(960+xxmove,538+yymove);
        f.setVisible(true);
        f.setLayout(null);
    }
    
public TransientResponse(){
    
    setLayout(null);
    String lcOSName = System.getProperty("os.name").toLowerCase();
    boolean MAC_OS_X = lcOSName.startsWith("mac os x");
    //System.out.println(lcOSName);
    
    // CHANGE ==================================================================
    //int xmove = 10;
    //int ymove = 34;
    //==========================================================================
    
    if (!useOldFonts) {
        //getUlabyFonts();
        state = new Trans_State();
        state.ttfFont = ttfFont;
        state.sanSerifFont = ttfFont;
        state.serifFont = ttfFont;
        state.symbolFont = phiFont;
        state.italicFont = phiFont;
        MaestroG.serifFont = ttfFont;
        MaestroG.sanSerifFont = ttfFont;
        MaestroG.italicFont = italicFont;
        MaestroG.useBiggerFont = true;
        TheFonts.setNewFonts(ttfFont, phiFont, italicFont);
    } else {
        state = new Trans_State();
        state.ttfFont = new Font("SanSerif",Font.PLAIN,12);
        state.sanSerifFont = new Font("SanSerif",Font.PLAIN,12);
        state.serifFont = new Font("Serif",Font.PLAIN,12);
        state.symbolFont = new Font("Symbol",Font.PLAIN,12);
        state.italicFont = new Font("Serif",Font.ITALIC,12);
        MaestroG.serifFont = state.serifFont;
        MaestroG.sanSerifFont = state.sanSerifFont;
        MaestroG.italicFont = state.italicFont;
        MaestroG.useBiggerFont = false;
        TheFonts.setOldFonts();
    }
	    
    //titlepanel = new TitlePanel(subtitleFont,"Module 2.10","Transient Response");
    titlepanel = new TitlePanel(state.ttfFont.deriveFont(Font.BOLD,15f),
                                "Module 2.10","Transient Response");
    //add(titlepanel);
    titlepanel.setBounds(10+xmove,10+ymove,310,40);
    
    ccan = new CircuitCanvas(state);
    //add(ccan);
    ccan.setBounds(10+xmove,90+ymove,625,140);
    
    String arg1[] = {"Options:","  Set Line","  Set Load/Generator",
       "  Transient Response Animation","  Transient Plots"};
    String arg2[] = {"Review:"," Transient 1"," Transient 2"};
    cp = new ChoicePanel(arg1,arg2);
    //add(cp);
    cp.setBounds(326+xmove,11+ymove,308,38);
    
    instructions = new Instructions(state);
    instructions.setBounds(11+xmove,56+ymove,623,468);  // was 471
    instructions.setVisible(true);
    instrOutline = new Panel();
    instrOutline.setBackground(Color.black);
    instrOutline.setBounds(10+xmove,55+ymove,625,470);
    instrOutline.setVisible(true);


    slidepanel = new TransSlidePanel();
    //add(slidepanel);
    slidepanel.setBounds(11+xmove,56+ymove,623,28);
    slidepanel.setLineLength(state.lineLength);
    
    {
      linepanel = new LinePanel(state);
      //add(linepanel);
      //linepanel.setBounds(11,236,308,288);
      linepanel.setBounds(641+xmove,11+ymove,308,218);
    }
    
    {
      String[] str1 =  {""};
      String[] str2 =  {"  [ \u03a9 ]"};
      loadpanel = new TransLoadPanel("Set Load",str1,str2,state);
      //add(loadpanel);
      loadpanel.setValue(100.0,0);
      //loadpanel.setBounds(11,236,308,140);
      loadpanel.setBounds(641+xmove,11+ymove,308,100);
    }
    
    {
      String[] str1 =  {"",""};
      String[] str2 =  {"  [ V ]","  [ \u03a9 ]"};
      generatorpanel = new PR2("Set Generator",str1,str2);
      //add(generatorpanel);
      generatorpanel.setValue(1.0,0);
      generatorpanel.setValue(200.0,1);
      //generatorpanel.setBounds(11,381,308,143);
      generatorpanel.setBounds(641+xmove,109+ymove,308,120);
    }

    mgpa = new Trans_MultiGraphPanelA("Transient 2");
    //add(mgpa);
    // CHANGE - MOVE AWAY BCAUSE OF setVisible() PROBLEM WITH MAC (WHICH SUCKS)
    //mgpa.setBounds(11+xmove,236+ymove,623,288);
    mgpa.setBounds(11+xmove,236+ymove+10000,623,288);
    //==========================================================================
    
    mgpc = new Trans_MultiGraphPanelC("Transient 1");
    //add(mgpc);
    mgpc.setBounds(11+xmove,236+ymove,623,288);
        
    //hide and show panels
    {
	loadpanel.setVisible(false);
	linepanel.setVisible(true);
	//about.setVisible(false);
	generatorpanel.setVisible(false);
	mgpc.setVisible(true);
	mgpa.setVisible(false);
        
        //initialize plots
        mgpc.c1.setEnabled(true);//*****
        mgpc.c1.select(" Select a Plot");//*****
        mgpa.setVisible(false);
        mgpc.setVisible(true);
        mgpc.ssc.setVisible(false);//*****
        mgpc.ssc.setEnabled(false);
        mgpc.cb1.setEnabled(true);
        mgpc.cb2.setEnabled(true);			
        mgpc.slider2.setEnabled(true);
        mgpc.tgc3.setVisible(false);
        //outputpanel.setVisible(false);
        mgpc.watch1.setText("0.0");
        mgpc.watch3.setText("0.0");
        mgpc.watch4.setText("s");
        mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
        mgpc.ssc.clockcanvas.reset();
        mgpc.tgc3.setScale(state.VScale, state.IScale, state.PScale, 
        state.VScale, state.IScale, state.PScale, state.VScaleFlag, state.IScaleFlag, state.PScaleFlag);
    }
    
    outputpanel = new Trans_OutputPanel(state);
    //add(outputpanel);
    //outputpanel.setBounds(326,236,308,288);
    outputpanel.setBounds(641+xmove,236+ymove,308,288);
    
    closepanel = new ClosePanel(state);
    closepanel.setBounds(810+xmove,240+ymove,112,24);
    
    Panel p000 = new Panel();
	    p000.setBackground(Color.cyan);
	    //add(p000);
	    p000.setBounds(11+xmove,377+ymove,308,3); 
            
    Panel pgraph = new Panel(); // behind graphs
	    pgraph.setBackground(Color.black);
	    //add(pgraph);
	    pgraph.setBounds(10+xmove,235+ymove,625,290);
	    
    Panel pgraph2 = new Panel(); // behind line panel
	    pgraph2.setBackground(Color.black);
	    //add(pgraph2);
	    pgraph2.setBounds(640+xmove,10+ymove,310,220);
            
    Panel pout = new Panel(); // behind line panel
	    pout.setBackground(Color.black);
	    //add(pgraph2);
	    pout.setBounds(640+xmove,235+ymove,310,290);

    Panel pslide = new Panel();
	    pslide.setBackground(Color.black);
	    //add(pslide);
	    pslide.setBounds(10+xmove,55+ymove,625,30);
	    
    Panel pchoice = new Panel();
	    pchoice.setBackground(Color.black);
	    //add(pchoice);
	    pchoice.setBounds(325+xmove,10+ymove,310,40);
    
    Panel p0 = new Panel();
	    p0.setBackground(Color.cyan);
	    //add(p0);
	    p0.setBounds(3+xmove,3+ymove,954,529);
	    
    Panel p00 = new Panel();
	    p00.setBackground(Color.black);
	    //add(p00);
	    p00.setBounds(xmove,ymove,960,535);
	    
     
            //if(state.this_year > line.magicyear || (state.this_year == line.magicyear && state.this_month > line.magicmonth)){
	    //state.LicenseExpired = true;
            //}
            //else
            //{   
            add(closepanel);
            add(instructions);
            add(instrOutline);
            //add(about);
            add(titlepanel); 	    
            add(ccan);
	    add(cp); 	
	    
            add(slidepanel);
	    add(linepanel);
	    add(loadpanel);
	    
	    add(generatorpanel);	   
	    add(mgpa);
	    add(mgpc);
	    add(outputpanel);
	    
	    add(p000);
	    
	    add(pgraph);
	    add(pgraph2);
            add(pout);
	    
	    add(pslide);
	    add(pchoice);
	        
            add(p0); 	    
            add(p00);
	    state.LicenseExpired = false; 	
            //}
            
    //Listeners
    this.addWindowListener(this);
    instructions.bupdate.addActionListener(this);
    closepanel.binstr.addActionListener(this);
    slidepanel.b2a.addActionListener(this);
    slidepanel.b2b.addActionListener(this);
    
    slidepanel.slider.addAdjustmentListener(this);
    slidepanel.details.addActionListener(this);

    mgpa.slider2.addAdjustmentListener(this);
    mgpa.b2a.addActionListener(this);
    mgpa.b2b.addActionListener(this);
    
    mgpc.slider2.addAdjustmentListener(this);
    mgpc.b2a.addActionListener(this);
    mgpc.b2b.addActionListener(this);
    
    linepanel.lowpanel.b1.addActionListener(this);
    loadpanel.b1.addActionListener(this);
    generatorpanel.b1.addActionListener(this);
    
    cp.c1.addItemListener(this);
    cp.c2.addItemListener(this);
    
    mgpa.c1.addItemListener(this);
    mgpc.c1.addItemListener(this);
    
    mgpc.ssc.button1.addMouseListener(this);
    mgpc.ssc.button2.addMouseListener(this);
    mgpc.ssc.button3.addMouseListener(this);
    mgpc.cb1.addItemListener(this);
    mgpc.cb2.addItemListener(this);
    
    mgpa.cb1.addItemListener(this);
    mgpa.cb2.addItemListener(this);

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



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

public void paint(Graphics g){
    
    Font licensefont = new Font("SanSerif",Font.BOLD,18); 
    Font fonto = new Font("SanSerif",Font.PLAIN,12);
    Font fontc = new Font("SanSerif",Font.BOLD,16);
    
	Graphics2D g2d = (Graphics2D)g;
        //g.setColor(Color.white);	
	//g.fillRect(0,0,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,552);
        //g.setFont(fonto);
        //g.drawString("Amanogawa, "+annonuovo+" - All Rights Reserved",30,550);
        */
}

public void start(){}


public void stop(){}

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

public void adjustmentValueChanged(AdjustmentEvent evt){
    if(evt.getSource()==slidepanel.slider){
	if(linepanel.Is_Millimeter){
	    state.xpos = slidepanel.getValue();
	}
	else{
	    state.xpos = slidepanel.getValue()*0.0254;
	}    
	
	send_shock_wave();
	mgpa.tgc1.setXpos(state.xpos);
	mgpa.tgc2.setXpos(state.xpos);
	//mgpa.tgc3.setXpos(state.xpos);
	//mgpa.tgc4.setXpos(state.xpos);
	mgpc.tgc3.setXpos(state.xpos);
	
	mgpc.tgc3.setDynamics(false);
	
	//mgpa.plotTimeVoltage(state);
	if(mgpa.Flag == 1){
	    mgpa.plotTimeVoltage(state);
	}
	else if (mgpa.Flag == 2){
	    mgpa.plotTimeCurrent(state);
	}
	else if (mgpa.Flag == 3){
	    mgpa.plotTimePower(state);
	}
	
	mgpa.tgc1.repaint();
	mgpa.tgc2.repaint();
	mgpc.tgc3.repaint();
	
    }
    else if(evt.getSource()==mgpc.slider2){
        
	mgpa.slider2.setValue(mgpc.slider2.getValue());
	mgpa.rise1.setText(mgpc.rise1.getText());
	mgpa.rise2.setText(mgpc.rise2.getText());
	mgpa.repaint();
	state.setRiseTime(mgpc.RiseTime);
	state.ignition();
	//mgpa.tgc1.setFiftyDelay(state.Delay, state.Delay2);
	mgpc.tgc3.repaint();
        outputpanel.canvas1.repaint();
    }
    else if(evt.getSource()==mgpa.slider2){
	mgpc.slider2.setValue(mgpa.slider2.getValue());
	mgpc.rise1.setText(mgpa.rise1.getText());
	mgpc.rise2.setText(mgpa.rise2.getText());
	state.setRiseTime(mgpa.RiseTime);
	state.ignition();
	//mgpa.tgc1.setFiftyDelay(state.Delay, state.Delay2);
	mgpc.repaint();
	if(mgpa.Flag == 1){
	    mgpa.plotTimeVoltage(state);
	}
	else if (mgpa.Flag == 2){
	    mgpa.plotTimeCurrent(state);
	}
	else if (mgpa.Flag == 3){
	    mgpa.plotTimePower(state);
	}
	
	mgpa.tgc1.repaint();
	mgpa.tgc2.repaint();
        outputpanel.canvas1.repaint();
    }
     
}

public void actionPerformed(ActionEvent evt){
    //if(evt.getSource()==about.bupdate){
    //        about.setVisible(false);
    //        if(state.OptionOne){cp.c1.select("  Set Line");}
    //        else if(state.OptionTwo){cp.c1.select("  Set Load/Generator");}
    //        else if(state.OptionThree){cp.c1.select("  Transient Response Animation");}
    //        else if(state.OptionFour){cp.c1.select("  Transient Plots");}
    //}

        if(evt.getSource()==mgpc.b2a || evt.getSource()==mgpc.b2b){
            mgpa.slider2.setValue(mgpc.slider2.getValue());
            mgpa.rise1.setText(mgpc.rise1.getText());
            mgpa.rise2.setText(mgpc.rise2.getText());
            mgpa.repaint();
            state.setRiseTime(mgpc.RiseTime);
            state.ignition();
            //mgpa.tgc1.setFiftyDelay(state.Delay, state.Delay2);
            mgpc.repaint();
            mgpc.tgc3.repaint();
            outputpanel.canvas1.repaint();
        }
        
        if(evt.getSource()==mgpa.b2a || evt.getSource()==mgpa.b2b){
            mgpc.slider2.setValue(mgpa.slider2.getValue());
            mgpc.rise1.setText(mgpa.rise1.getText());
            mgpc.rise2.setText(mgpa.rise2.getText());
            state.setRiseTime(mgpa.RiseTime);
            state.ignition();
            //mgpa.tgc1.setFiftyDelay(state.Delay, state.Delay2);
            mgpc.repaint();
            if(mgpa.Flag == 1){
                mgpa.plotTimeVoltage(state);
            }
            else if (mgpa.Flag == 2){
                mgpa.plotTimeCurrent(state);
            }
            else if (mgpa.Flag == 3){
                mgpa.plotTimePower(state);
            }

            mgpa.tgc1.repaint();
            mgpa.tgc2.repaint();
            outputpanel.canvas1.repaint();
        }
        
        if(evt.getSource()==slidepanel.b2a || evt.getSource()==slidepanel.b2b){
            
            if(linepanel.Is_Millimeter){
                state.xpos = slidepanel.getValue();
            }
            else{
                state.xpos = slidepanel.getValue()*0.0254;
            }    

            send_shock_wave();
            mgpa.tgc1.setXpos(state.xpos);
            mgpa.tgc2.setXpos(state.xpos);
            //mgpa.tgc3.setXpos(state.xpos);
            //mgpa.tgc4.setXpos(state.xpos);
            mgpc.tgc3.setXpos(state.xpos);

            mgpc.tgc3.setDynamics(false);

            //mgpa.plotTimeVoltage(state);
            if(mgpa.Flag == 1){
                mgpa.plotTimeVoltage(state);
            }
            else if (mgpa.Flag == 2){
                mgpa.plotTimeCurrent(state);
            }
            else if (mgpa.Flag == 3){
                mgpa.plotTimePower(state);
            }

            mgpa.tgc1.repaint();
            mgpa.tgc2.repaint();
            mgpc.tgc3.repaint();
        }
    
        if(evt.getSource() == closepanel.binstr){ 
            instructions.setVisible(true);
            instrOutline.setVisible(true);
        }
                  
        if(evt.getSource() == instructions.bupdate){ 
            instructions.setVisible(false);
            instrOutline.setVisible(false);
        }
        
	if(evt.getSource()==linepanel.lowpanel.b1){
            
	    if(linepanel.lowpanel.getValue(0) < 0.0){
		state.lineZ0 = 50.0;
		//state.Rg = 50.0;
		linepanel.lowpanel.setValue(50.0,0);
		//generatorpanel.setValue(50.0,1);
	    }
	    else{
		state.lineZ0 = linepanel.lowpanel.getValue(0);
		//state.Rg = linepanel.lowpanel.getValue(0);
		//generatorpanel.setValue(linepanel.lowpanel.getValue(0),1);
	    }
	    
	    if(linepanel.lowpanel.getValue(1) < 1.0){
		state.epsilon_r = 1.0;
		linepanel.lowpanel.setValue(1.0,1);
	    }
	    else{
		state.epsilon_r = linepanel.lowpanel.getValue(1);
	    }
	    
	    
	    //-------------------------------------------------------------------------------
	    if(linepanel.Is_Millimeter){
		if(linepanel.lowpanel.getValue(2) < 0.0){
		    state.lineLength = 1.0;
		    linepanel.lowpanel.setValue(1.0,2);
		}
		else if(linepanel.lowpanel.getValue(2) > 5000.0){
		    state.lineLength = 5000.0;
		    linepanel.lowpanel.setValue(5000.0,2);
		}
		else{
		    state.lineLength = linepanel.lowpanel.getValue(2);
		}
		slidepanel.SetMillimeter(true);
	    }
	    else{
		
		if(linepanel.lowpanel.getValue(2) < 0.0){
		    state.lineLength = 1.0;
		    linepanel.lowpanel.setValue(1.0,2);
		}
		else if(linepanel.lowpanel.getValue(2) > 5000.0/0.0254){
		    state.lineLength = 5000.0;
		    linepanel.lowpanel.setValue(5000.0/0.0254,2);
		}
		else{
		    state.lineLength = linepanel.lowpanel.getValue(2)*0.0254;
		    //Conversion factor: 1 mil = 0.0254 mm
		}
		slidepanel.SetMillimeter(false);
	    } 
	    //-------------------------------------------------------------------------------  
	    
	    state.xpos = state.lineLength;
	    int templine=10000;
	if(linepanel.Is_Millimeter)
	{
	    
	    if(state.lineLength >= 1.0 && state.lineLength < 5.0){
		templine = (int)(10000*state.lineLength)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength >= 5.0 && state.lineLength < 10.0){
		templine = (int)(5000*state.lineLength)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength >= 10.0 && state.lineLength < 50.0){
		templine = (int)(1000*state.lineLength)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength >= 50.0 && state.lineLength < 100.0){
		templine = (int)(500*state.lineLength)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength >= 100.0 && state.lineLength < 500.0){
		templine = (int)(100*state.lineLength)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength >= 500.0 && state.lineLength < 1000.0){
		templine = (int)(50*state.lineLength)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength >= 1000.0 && state.lineLength < 5000.0){
		templine = (int)(10*state.lineLength)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength >= 5000.0 && state.lineLength < 10000.0){
		templine = (int)(5*state.lineLength)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength >= 10000.0 && state.lineLength < 50000.0){
		templine = (int)(1*state.lineLength)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength >= 50000.0 && state.lineLength < 100000.0){
		templine = (int)(0.5*state.lineLength)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength >= 100000.0 && state.lineLength < 500000.0){
		templine = (int)(0.1*state.lineLength)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength >= 500000.0 && state.lineLength < 1000000.0){
		templine = (int)(0.05*state.lineLength)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength >= 1000000.0 && state.lineLength < 5000000.0){
		templine = (int)(0.01*state.lineLength)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength >= 5000000.0 && state.lineLength <= 10000000.0){
		templine = (int)(0.005*state.lineLength)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	   
	}
	else{
	    double length_mils = state.lineLength/0.0254;
	    if(state.lineLength/0.0254 >= 1.0 && state.lineLength/0.0254 < 5.0){
		templine = (int)(10000*length_mils)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength/0.0254 >= 5.0 && state.lineLength/0.0254 < 10.0){
		templine = (int)(5000*length_mils)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength/0.0254 >= 10.0 && state.lineLength/0.0254 < 50.0){
		templine = (int)(1000*length_mils)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength/0.0254 >= 50.0 && state.lineLength/0.0254 < 100.0){
		templine = (int)(500*length_mils)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength/0.0254 >= 100.0 && state.lineLength/0.0254 < 500.0){
		templine = (int)(100*length_mils)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength/0.0254 >= 500.0 && state.lineLength/0.0254 < 1000.0){
		templine = (int)(50*length_mils)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength/0.0254 >= 1000.0 && state.lineLength/0.0254 < 5000.0){
		templine = (int)(10*length_mils)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength/0.0254 >= 5000.0 && state.lineLength/0.0254 < 10000.0){
		templine = (int)(5*length_mils)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength/0.0254 >= 10000.0 && state.lineLength/0.0254 < 50000.0){
		templine = (int)(1*length_mils)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength/0.0254 >= 50000.0 && state.lineLength/0.0254 < 100000.0){
		templine = (int)(0.5*length_mils)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength/0.0254 >= 100000.0 && state.lineLength/0.0254 < 500000.0){
		templine = (int)(0.1*length_mils)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength/0.0254 >= 500000.0 && state.lineLength/0.0254 < 1000000.0){
		templine = (int)(0.05*length_mils)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength/0.0254 >= 1000000.0 && state.lineLength/0.0254 < 5000000.0){
		templine = (int)(0.01*length_mils)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	    else if(state.lineLength/0.0254 >= 5000000.0 && state.lineLength/0.0254 <= 10000000.0){
		templine = (int)(0.005*length_mils)+1;
		slidepanel.slider.setBlockIncrement(10);
	    }
	}
	    
	    state.ignition();
	    slidepanel.setLineLength(state.lineLength);
	    slidepanel.slider.setMaximum(templine);
	    slidepanel.slider.setValues(templine-1,1,0,templine);
	   
	    slidepanel.reset();
            slidepanel.slider.setValue(0);
	    ccan.repaint();
	    outputpanel.canvas1.repaint();
	    
	    state.ignition();
	    
	    mgpa.tgc1.setXpos(state.xpos);
	    mgpa.tgc2.setXpos(state.xpos);
	    mgpc.tgc3.setXpos(state.xpos);
	    mgpc.tgc3.setDynamics(false);
	    
	    
	    mgpc.tgc3.setScale(state.VScale, state.IScale, state.PScale, 
		state.VScale, state.IScale, state.PScale, state.VScaleFlag, state.IScaleFlag, state.PScaleFlag);
	
	    mgpa.tgc1.setScale(state.VScale, state.IScale, state.PScale,
		state.VScale, state.IScale, state.PScale);
	    mgpa.tgc2.setScale(state.VScale, state.IScale, state.PScale,
		state.VScale, state.IScale, state.PScale);

	    mgpa.tgc1.repaint();
	    mgpa.tgc2.repaint();
	    mgpc.tgc3.repaint();
	    
    	
            if(state.IsTransient1){//reset transient1
                    mgpc.c1.setEnabled(true);//*****
                    mgpc.c1.select(" Select a Plot");//*****
		    mgpa.setVisible(false);
		    mgpc.setVisible(true);
                    mgpc.ssc.setVisible(false);//*****
		    mgpc.ssc.setEnabled(false);
		    mgpc.cb1.setEnabled(true);
		    mgpc.cb2.setEnabled(true);			
		    mgpc.slider2.setEnabled(true);
		    mgpc.tgc3.setVisible(false);
		    //outputpanel.setVisible(false);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		    mgpc.tgc3.setScale(state.VScale, state.IScale, state.PScale, 
		    state.VScale, state.IScale, state.PScale, state.VScaleFlag, state.IScaleFlag, state.PScaleFlag);
            }
            else{// reset transient2
                    mgpa.setVisible(true);
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
		    mgpc.setVisible(false);
		    //outputpanel.setVisible(false);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		    mgpa.tgc1.setScale(state.VScale, state.IScale, state.PScale,
			state.VScale, state.IScale, state.PScale);
		    mgpa.tgc2.setScale(state.VScale, state.IScale, state.PScale,
			state.VScale, state.IScale, state.PScale);
            }
        
        
        }
	else if(evt.getSource()==loadpanel.b1){
	    
	    //Resistance choice is on
	    if(loadpanel.c1.getState()){
		double temp1;
		temp1 = loadpanel.getValue(0);
		
		if(temp1 < 0.0){
		    state.Resistance = 0.0;
		    loadpanel.setValue(0.0,0);
		}
		else{
		    state.Resistance = loadpanel.getValue(0);
		}
		state.is_Load_Ztype = true;
	    }
	    //Admittance choice is on
	    else{
		double temp1;
		temp1 = loadpanel.getValue(0);
		
		if(temp1 < 0.0){
		    state.Conductance = 0.0;
		    loadpanel.setValue(0.0,0);
		}
		else{
		    state.Conductance = loadpanel.getValue(0);
		}
		state.is_Load_Ztype = false;
	    }
	    state.ignition();
	    
	   
	    mgpc.tgc3.setScale(state.VScale, state.IScale, state.PScale, 
		state.VScale, state.IScale, state.PScale, state.VScaleFlag, state.IScaleFlag, state.PScaleFlag);
	   
	    mgpa.tgc1.setScale(state.VScale, state.IScale, state.PScale,
		state.VScale, state.IScale, state.PScale);
	    mgpa.tgc2.setScale(state.VScale, state.IScale, state.PScale,
		state.VScale, state.IScale, state.PScale);
		
	    ccan.repaint();
	    outputpanel.canvas1.repaint();
            
            if(state.IsTransient1){//reset transient1
                    mgpc.c1.setEnabled(true);//*****
                    mgpc.c1.select(" Select a Plot");//*****
		    mgpa.setVisible(false);
		    mgpc.setVisible(true);
                    mgpc.ssc.setVisible(false);//*****
		    mgpc.ssc.setEnabled(false);
		    mgpc.cb1.setEnabled(true);
		    mgpc.cb2.setEnabled(true);			
		    mgpc.slider2.setEnabled(true);
		    mgpc.tgc3.setVisible(false);
		    //outputpanel.setVisible(false);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		    mgpc.tgc3.setScale(state.VScale, state.IScale, state.PScale, 
		    state.VScale, state.IScale, state.PScale, state.VScaleFlag, state.IScaleFlag, state.PScaleFlag);
            }
            else{// reset transient2
                    mgpa.setVisible(true);
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
		    mgpc.setVisible(false);
		    //outputpanel.setVisible(false);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		    mgpa.tgc1.setScale(state.VScale, state.IScale, state.PScale,
			state.VScale, state.IScale, state.PScale);
		    mgpa.tgc2.setScale(state.VScale, state.IScale, state.PScale,
			state.VScale, state.IScale, state.PScale);
            }
	    
	}
        else if(evt.getSource()==slidepanel.details){
            if(ccan.IsFocusOn){
                ccan.IsFocusOn = false;
                ccan.repaint();
            }
            else{
                ccan.IsFocusOn = true;
                ccan.repaint();
            }
        }
	else if(evt.getSource()==generatorpanel.b1){
	    state.Vg=generatorpanel.getValue(0);
	    
	    if(generatorpanel.getValue(1) < 0.0){
		state.Rg=50.0;
		generatorpanel.setValue(50.0,1);
		//state.lineZ0 = generatorpanel.getValue(1);
		//linepanel.lowpanel.setValue(generatorpanel.getValue(1),0);
	    }
	    else{	    
	        state.Rg=generatorpanel.getValue(1);
		//state.lineZ0 = generatorpanel.getValue(1);
		//linepanel.lowpanel.setValue(generatorpanel.getValue(1),0);
	    }
	    send_shock_wave();
	  
	    mgpc.tgc3.setScale(state.VScale, state.IScale, state.PScale, 
		state.VScale, state.IScale, state.PScale, state.VScaleFlag, state.IScaleFlag, state.PScaleFlag);
		
	    mgpa.tgc1.setScale(state.VScale, state.IScale, state.PScale,
		state.VScale, state.IScale, state.PScale);
	    mgpa.tgc2.setScale(state.VScale, state.IScale, state.PScale,
		state.VScale, state.IScale, state.PScale);
	    
            
            if(state.IsTransient1){//reset transient1
                    mgpc.c1.setEnabled(true);//*****
                    mgpc.c1.select(" Select a Plot");//*****
		    mgpa.setVisible(false);
		    mgpc.setVisible(true);
                    mgpc.ssc.setVisible(false);//*****
		    mgpc.ssc.setEnabled(false);
		    mgpc.cb1.setEnabled(true);
		    mgpc.cb2.setEnabled(true);			
		    mgpc.slider2.setEnabled(true);
		    mgpc.tgc3.setVisible(false);
		    //outputpanel.setVisible(false);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		    mgpc.tgc3.setScale(state.VScale, state.IScale, state.PScale, 
		    state.VScale, state.IScale, state.PScale, state.VScaleFlag, state.IScaleFlag, state.PScaleFlag);
            }
            else{// reset transient2
                    mgpa.setVisible(true);
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
		    mgpc.setVisible(false);
		    //outputpanel.setVisible(false);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		    mgpa.tgc1.setScale(state.VScale, state.IScale, state.PScale,
			state.VScale, state.IScale, state.PScale);
		    mgpa.tgc2.setScale(state.VScale, state.IScale, state.PScale,
			state.VScale, state.IScale, state.PScale);
            }
	}
}

public void itemStateChanged(ItemEvent evt){
	    ItemSelectable ie = evt.getItemSelectable();
	    if(evt.getSource()==cp.c1){
                if(ie.getSelectedObjects()[0]=="  Instructions"){
		    instructions.setVisible(true);
                    instrOutline.setVisible(true);
                    //about.setVisible(true);
		}	

		if(ie.getSelectedObjects()[0]=="  Set Load/Generator"){
		    state.OptionOne = false;
                    state.OptionTwo = true;
                    state.OptionThree = false;
                    state.OptionFour = false;
		    //about.setVisible(false);
                    instructions.setVisible(false);
                    instrOutline.setVisible(false);
                    
                    loadpanel.setVisible(true);
		    linepanel.setVisible(false);
		    generatorpanel.setVisible(true);
		    //mgpa.setVisible(false);
		    //mgpc.setVisible(false);
		    //outputpanel.setVisible(true);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		}
		else if(ie.getSelectedObjects()[0]=="  Set Line"){
                    state.OptionOne = true;
                    state.OptionTwo = false;
                    state.OptionThree = false;
                    state.OptionFour = false;
		    //about.setVisible(false);
                    instructions.setVisible(false);
                    instrOutline.setVisible(false);
                    
                    loadpanel.setVisible(false);
		    linepanel.setVisible(true);
		    generatorpanel.setVisible(false);
		    //mgpa.setVisible(false);
		    //mgpc.setVisible(false);
		    //outputpanel.setVisible(true);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		}
                
                if(ie.getSelectedObjects()[0]=="  Transient Plots"){
		    mgpa.c1.select(" Select a Plot"); // *****
                    //loadpanel.setVisible(false);
		    //linepanel.setVisible(false);
		    //generatorpanel.setVisible(false);
		    
                    state.OptionOne = false;
                    state.OptionTwo = false;
                    state.OptionThree = false;
                    state.OptionFour = true;
		    //about.setVisible(false);
                    instructions.setVisible(false);
                    instrOutline.setVisible(false);
                    
                    state.IsTransient1 = false;
                    mgpa.setVisible(true);
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
		    mgpc.setVisible(false);
                    
                    // CHANGE ==================================================
                    mgpa.setBounds(11+xmove,236+ymove,623,288);
                    mgpc.setBounds(11+xmove,236+ymove+10000,623,288);
                    //==========================================================
                    
		    //outputpanel.setVisible(false);
		    
                    if(state.IsStepOn){
                        mgpc.slider2.setEnabled(false);
                        mgpc.slider2.setVisible(false);
                        mgpc.b2a.setVisible(false);
                        mgpc.b2b.setVisible(false);
                        mgpc.ps4.setVisible(false);
                        mgpc.rise1.setVisible(false);
                        mgpc.rise2.setVisible(false);
                        mgpc.rise3.setVisible(false);
                        mgpa.slider2.setEnabled(false);
                        mgpa.slider2.setVisible(false);
                        mgpa.b2a.setVisible(false);
                        mgpa.b2b.setVisible(false);
                        mgpa.ps4.setVisible(false);
                        mgpa.rise1.setVisible(false);
                        mgpa.rise2.setVisible(false);
                        mgpa.rise3.setVisible(false);
                    }
                    else{
                        mgpc.slider2.setEnabled(true);
                        mgpc.slider2.setVisible(true);
                        mgpc.b2a.setVisible(true);
                        mgpc.b2b.setVisible(true);
                        mgpc.ps4.setVisible(true);
                        mgpc.rise1.setVisible(true);
                        mgpc.rise2.setVisible(true);
                        mgpc.rise3.setVisible(true);
                        mgpa.slider2.setEnabled(true);
                        mgpa.slider2.setVisible(true);
                        mgpa.b2a.setVisible(true);
                        mgpa.b2b.setVisible(true);
                        
                        mgpa.ps4.setVisible(true);
                        mgpa.rise1.setVisible(true);
                        mgpa.rise2.setVisible(true);
                        mgpa.rise3.setVisible(true);
                    }
                    
                    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		    mgpa.tgc1.setScale(state.VScale, state.IScale, state.PScale,
			state.VScale, state.IScale, state.PScale);
		    mgpa.tgc2.setScale(state.VScale, state.IScale, state.PScale,
			state.VScale, state.IScale, state.PScale);
		 }
		
                 if(ie.getSelectedObjects()[0]=="  Transient Response Animation"){
		    //loadpanel.setVisible(false);
		    //linepanel.setVisible(false);
		    //generatorpanel.setVisible(false);
                    
                    state.OptionOne = false;
                    state.OptionTwo = false;
                    state.OptionThree = true;
                    state.OptionFour = false;
		    //about.setVisible(false);
                    instructions.setVisible(false);
                    instrOutline.setVisible(false);
                    
                    state.IsTransient1 = true;
                    mgpc.c1.setEnabled(true);//*****
                    mgpc.c1.select(" Select a Plot");//*****
		    mgpa.setVisible(false);
		    mgpc.setVisible(true);
                    mgpc.ssc.setVisible(false);//*****
		    mgpc.ssc.setEnabled(false);
		    mgpc.cb1.setEnabled(true);
		    mgpc.cb2.setEnabled(true);	
                    
                    // CHANGE ==================================================
                    mgpa.setBounds(11+xmove,236+ymove+10000,623,288);
                    mgpc.setBounds(11+xmove,236+ymove,623,288);
                    //==========================================================
                    if(state.IsStepOn){
                        mgpc.slider2.setEnabled(false);
                        mgpc.slider2.setVisible(false);
                        mgpc.b2a.setVisible(false);
                        mgpc.b2b.setVisible(false);
                        mgpc.ps4.setVisible(false);
                        mgpc.rise1.setVisible(false);
                        mgpc.rise2.setVisible(false);
                        mgpc.rise3.setVisible(false);
                        mgpa.slider2.setEnabled(false);
                        mgpa.slider2.setVisible(false);
                        mgpa.b2a.setVisible(false);
                        mgpa.b2b.setVisible(false);
                        mgpa.ps4.setVisible(false);
                        mgpa.rise1.setVisible(false);
                        mgpa.rise2.setVisible(false);
                        mgpa.rise3.setVisible(false);
                    }
                    else{
                        mgpc.slider2.setEnabled(true);
                        mgpc.slider2.setVisible(true);
                        mgpc.b2a.setVisible(true);
                        mgpc.b2b.setVisible(true);
                        mgpc.ps4.setVisible(true);
                        mgpc.rise1.setVisible(true);
                        mgpc.rise2.setVisible(true);
                        mgpc.rise3.setVisible(true);
                        mgpa.slider2.setEnabled(true);
                        mgpa.slider2.setVisible(true);
                        mgpa.b2a.setVisible(true);
                        mgpa.b2b.setVisible(true);
                        mgpa.ps4.setVisible(true);
                        mgpa.rise1.setVisible(true);
                        mgpa.rise2.setVisible(true);
                        mgpa.rise3.setVisible(true);
                    }
                    
		    mgpc.tgc3.setVisible(false);
		    //outputpanel.setVisible(false);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		    mgpc.tgc3.setScale(state.VScale, state.IScale, state.PScale, 
		    state.VScale, state.IScale, state.PScale, state.VScaleFlag, state.IScaleFlag, state.PScaleFlag);
		 }
	    }
	    else if(evt.getSource()==cp.c2){
		 if(ie.getSelectedObjects()[0]==" Transient 2"){
		    mgpa.c1.select(" Select a Plot"); // *****
                    //loadpanel.setVisible(false);
		    //linepanel.setVisible(false);
		    //generatorpanel.setVisible(false);
		    
                    state.IsTransient1 = false;
                    mgpa.setVisible(true);
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
		    mgpc.setVisible(false);
		    //outputpanel.setVisible(false);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		    mgpa.tgc1.setScale(state.VScale, state.IScale, state.PScale,
			state.VScale, state.IScale, state.PScale);
		    mgpa.tgc2.setScale(state.VScale, state.IScale, state.PScale,
			state.VScale, state.IScale, state.PScale);
		 }	
		 if(ie.getSelectedObjects()[0]=="Plots (time-s.s.)"){
		    loadpanel.setVisible(false);
		    linepanel.setVisible(false);
		    generatorpanel.setVisible(false);
		    mgpa.setVisible(false);
		    mgpc.setVisible(false);
		    //outputpanel.setVisible(false);
		 }
		 if(ie.getSelectedObjects()[0]==" Transient 1"){
		    //loadpanel.setVisible(false);
		    //linepanel.setVisible(false);
		    //generatorpanel.setVisible(false);
                    state.IsTransient1 = true;
                    mgpc.c1.setEnabled(true);//*****
                    mgpc.c1.select(" Select a Plot");//*****
		    mgpa.setVisible(false);
		    mgpc.setVisible(true);
                    mgpc.ssc.setVisible(false);//*****
		    mgpc.ssc.setEnabled(false);
		    mgpc.cb1.setEnabled(true);
		    mgpc.cb2.setEnabled(true);			
		    mgpc.slider2.setEnabled(true);
		    mgpc.tgc3.setVisible(false);
		    //outputpanel.setVisible(false);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		    mgpc.tgc3.setScale(state.VScale, state.IScale, state.PScale, 
		    state.VScale, state.IScale, state.PScale, state.VScaleFlag, state.IScaleFlag, state.PScaleFlag);
		 }
		 
		 if(ie.getSelectedObjects()[0]==" Data"){
		    //loadpanel.setVisible(false);
		    //linepanel.setVisible(true);
		    //generatorpanel.setVisible(false);
		    //mgpa.setVisible(false);
		    //mgpc.setVisible(false);
		    //outputpanel.setVisible(true);
		    //mgpc.watch1.setText("0.0");
		    //mgpc.watch3.setText("0.0");
		    //mgpc.watch4.setText("s");
		    //mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    //mgpc.ssc.clockcanvas.reset();
		 }
	    }
	    //Trans_MultiGraphPanelA Choices
	    else if(evt.getSource()==mgpa.c1){
		if(ie.getSelectedObjects()[0]==" Current I(t)"){
		    mgpa.setRiseTime(state.RiseTime);	
		    mgpa.plotTimeCurrent(state);
		    mgpa.tgc1.setVisible(true);
		    mgpa.tgc2.setVisible(true);
		    mgpa.Flag = 2;
		    mgpa.tgc1.setFlag(2);
		    mgpa.tgc2.setFlag(2);
		    state.SwitchIsOpen = false;
		    state.ignition();
		    ccan.repaint();
		} 
		else if(ie.getSelectedObjects()[0]==" Power P(t)"){
		    mgpa.setRiseTime(state.RiseTime);	
		    mgpa.plotTimePower(state);
		    mgpa.tgc1.setVisible(true);
		    mgpa.tgc2.setVisible(true);
		    mgpa.Flag = 3;
		    mgpa.tgc1.setFlag(3);
		    mgpa.tgc2.setFlag(3);
		    state.SwitchIsOpen = false;
		    state.ignition();
		    ccan.repaint();
		} 
		else if(ie.getSelectedObjects()[0]==" Voltage V(t)"){
		    mgpa.setRiseTime(state.RiseTime);	
		    mgpa.plotTimeVoltage(state);
		    mgpa.tgc1.setVisible(true);
		    mgpa.tgc2.setVisible(true);
		    mgpa.Flag = 1;
		    mgpa.tgc1.setFlag(1);
		    mgpa.tgc2.setFlag(1);
		    state.SwitchIsOpen = false;
		    state.ignition();
		    ccan.repaint();
		    mgpa.tgc1.setFiftyDelay(state.Delay, state.Delay2);
		} 
                else if(ie.getSelectedObjects()[0]==" Select a Plot"){//*******
                    mgpa.c1.select(" Select a Plot"); // *****
                    //loadpanel.setVisible(false);
		    //linepanel.setVisible(false);
		    //generatorpanel.setVisible(false);
		    mgpa.setVisible(true);
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
		    mgpc.setVisible(false);
		    //outputpanel.setVisible(false);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		    mgpa.tgc1.setScale(state.VScale, state.IScale, state.PScale,
			state.VScale, state.IScale, state.PScale);
		    mgpa.tgc2.setScale(state.VScale, state.IScale, state.PScale,
			state.VScale, state.IScale, state.PScale);
                }

		
	    }
	    
	    //Trans_MultiGraphPanelC Choices
	    else if(evt.getSource()==mgpc.c1){
		mgpc.tgc3.setVisible(true);
		state.SwitchIsOpen = true;
		state.ignition();
		ccan.repaint();
		
		if(ie.getSelectedObjects()[0]==" Transient Voltage"){
		    mgpc.ssc.setVisible(true);//******
                    mgpc.setRiseTime(state.RiseTime);	
		    mgpc.ssc.setEnabled(true);
		    mgpc.plotTransientVoltage(state);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		    mgpc.ssc.button2.setEnabled(false);
		    mgpc.tgc3.setFlag(1);		    
		}
		else if(ie.getSelectedObjects()[0]==" Transient Current"){
		    mgpc.ssc.setVisible(true);
                    mgpc.setRiseTime(state.RiseTime);	
		    mgpc.ssc.setEnabled(true);
		    mgpc.plotTransientCurrent(state);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		    mgpc.ssc.button2.setEnabled(false);
		    mgpc.tgc3.setFlag(2);
		    
		}
		else if(ie.getSelectedObjects()[0]==" Transient Power"){
		    mgpc.ssc.setVisible(true);
                    mgpc.setRiseTime(state.RiseTime);	
		    mgpc.ssc.setEnabled(true);
		    mgpc.plotTransientPower(state);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		    mgpc.ssc.button2.setEnabled(false);
		    mgpc.tgc3.setFlag(3);
		}
                else if(ie.getSelectedObjects()[0]==" Select a Plot"){
                    //loadpanel.setVisible(false);
		    //linepanel.setVisible(false);
		    //generatorpanel.setVisible(false);
                    mgpc.c1.setEnabled(true);//*****
                    mgpc.c1.select(" Select a Plot");//*****
		    mgpa.setVisible(false);
		    mgpc.setVisible(true);
                    mgpc.ssc.setVisible(false);//*****
		    mgpc.ssc.setEnabled(false);
		    mgpc.cb1.setEnabled(true);
		    mgpc.cb2.setEnabled(true);			
		    mgpc.slider2.setEnabled(true);
		    mgpc.tgc3.setVisible(false);
		    //outputpanel.setVisible(false);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		    mgpc.tgc3.setScale(state.VScale, state.IScale, state.PScale, 
		    state.VScale, state.IScale, state.PScale, state.VScaleFlag, state.IScaleFlag, state.PScaleFlag);
                }
	    }
	    
	    else if(evt.getSource() == mgpc.cb1){
		state.IsStepOn = true;
		//state.RiseTime = 0.0;
		state.ignition();
		
                //mgpc.ssc.setVisible(false);//*****
                //mgpc.c1.select(" Select a Plot");//*****
		
                ccan.setStep(true);
		
		mgpc.IsStepOn = true;
		mgpa.IsStepOn = true;
		
		mgpa.cb1.setState(true);
		mgpc.cb1.setState(true);
                
		mgpa.cb2.setState(false);
		mgpc.cb2.setState(false);
		
                mgpc.tgc3.setPulse(false);
                
                mgpc.tgc3.setStep(true);
		mgpa.tgc1.setStep(true);
		mgpa.tgc2.setStep(true);
		
                mgpc.tgc3.setScale(state.VScale, state.IScale, state.PScale, 
		    state.VScale, state.IScale, state.PScale, state.VScaleFlag, state.IScaleFlag, state.PScaleFlag);
                
		//mgpc.rise1.setText("0.0");
		//mgpa.rise1.setText("0.0");
		
		//mgpc.rise2.setText(" s");
		//mgpa.rise2.setText(" s");
		
		//mgpc.slider2.setValue(0);
		//mgpa.slider2.setValue(0);
                
                mgpc.slider2.setVisible(false);
                mgpa.slider2.setVisible(false);
                mgpc.b2a.setVisible(false);
                mgpc.b2b.setVisible(false);
                mgpa.b2a.setVisible(false);
                mgpa.b2b.setVisible(false);
                mgpc.ps4.setVisible(false);
                               
                mgpc.rise1.setVisible(false);
                mgpc.rise2.setVisible(false);
                mgpa.rise1.setVisible(false);
                mgpa.rise2.setVisible(false);
                
                mgpc.rise3.setVisible(false);
                mgpc.rise5.setVisible(false);
                mgpa.rise3.setVisible(false);
                mgpa.rise5.setVisible(false); 
                
		//mgpc.RiseTime = 0.0;
		//mgpa.RiseTime = 0.0;
		
		ccan.repaint();
		mgpc.repaint();
		mgpa.repaint();
		mgpc.tgc3.repaint();
		mgpa.tgc1.repaint();
		mgpa.tgc2.repaint();
		//mgpc.tgc3.setVisible(false); //****
                
                if(state.IsTransient1){//reset transient1
                    mgpc.c1.setEnabled(true);//*****
                    mgpc.c1.select(" Select a Plot");//*****
		    mgpa.setVisible(false);
		    mgpc.setVisible(true);
                    mgpc.ssc.setVisible(false);//*****
		    mgpc.ssc.setEnabled(false);
		    mgpc.cb1.setEnabled(true);
		    mgpc.cb2.setEnabled(true);			
		    mgpc.slider2.setEnabled(true);
		    mgpc.tgc3.setVisible(false);
		    //outputpanel.setVisible(false);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		    mgpc.tgc3.setScale(state.VScale, state.IScale, state.PScale, 
		    state.VScale, state.IScale, state.PScale, state.VScaleFlag, state.IScaleFlag, state.PScaleFlag);
                }
                else{// reset transient2
                    mgpa.setVisible(true);
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
		    mgpc.setVisible(false);
		    //outputpanel.setVisible(false);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		    mgpa.tgc1.setScale(state.VScale, state.IScale, state.PScale,
			state.VScale, state.IScale, state.PScale);
		    mgpa.tgc2.setScale(state.VScale, state.IScale, state.PScale,
			state.VScale, state.IScale, state.PScale);
                }
		outputpanel.canvas1.repaint();
	    }
	    else if(evt.getSource() == mgpc.cb2){
		
                //mgpc.ssc.setVisible(false);//*****
                //mgpc.c1.select(" Select a Plot");//*****
                mgpc.slider2.setVisible(true);
                mgpa.slider2.setVisible(true);
                mgpa.b2a.setVisible(true);
                mgpa.b2b.setVisible(true);
                mgpc.b2a.setVisible(true);
                mgpc.b2b.setVisible(true);
		mgpc.rise1.setVisible(true);
                mgpc.rise2.setVisible(true);
                mgpa.rise1.setVisible(true);
                mgpa.rise2.setVisible(true);
                
                mgpc.rise3.setVisible(true);
                mgpc.rise5.setVisible(true);
                mgpa.rise3.setVisible(true);
                mgpa.rise5.setVisible(true); 
                
                ccan.setStep(false);
		state.IsStepOn = false;
		//state.RiseTime = 0.5e-15;
		//mgpc.rise1.setText("0.5");
		//mgpc.rise2.setText("fs");
		state.ignition();
                
		mgpc.tgc3.setPulse(true);
                
		mgpc.IsStepOn = false;
		mgpa.IsStepOn = false;
		
		mgpa.cb1.setState(false);
		mgpc.cb1.setState(false);
		mgpa.cb2.setState(true);
		mgpc.cb2.setState(true);
		mgpc.tgc3.setStep(false);
		mgpa.tgc1.setStep(false);
		mgpa.tgc2.setStep(false);
		
                mgpc.tgc3.setScale(state.VScale, state.IScale, state.PScale, 
		    state.VScale, state.IScale, state.PScale, state.VScaleFlag, state.IScaleFlag, state.PScaleFlag);
		                
		state.ignition();
		ccan.repaint();
		mgpa.repaint();
		mgpc.repaint();
		mgpc.tgc3.repaint();
		mgpa.tgc1.repaint();
		mgpa.tgc2.repaint();
		//mgpc.tgc3.setVisible(false);//****	
                if(state.IsTransient1){//reset transient1
                    mgpc.c1.setEnabled(true);//*****
                    mgpc.c1.select(" Select a Plot");//*****
		    mgpa.setVisible(false);
		    mgpc.setVisible(true);
                    mgpc.ssc.setVisible(false);//*****
		    mgpc.ssc.setEnabled(false);
		    mgpc.cb1.setEnabled(true);
		    mgpc.cb2.setEnabled(true);			
		    mgpc.slider2.setEnabled(true);
		    mgpc.tgc3.setVisible(false);
		    //outputpanel.setVisible(false);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		    mgpc.tgc3.setScale(state.VScale, state.IScale, state.PScale, 
		    state.VScale, state.IScale, state.PScale, state.VScaleFlag, state.IScaleFlag, state.PScaleFlag);
                }
                else{// reset transient2
                    mgpa.setVisible(true);
		    mgpa.tgc1.setVisible(false);
		    mgpa.tgc2.setVisible(false);
		    mgpc.setVisible(false);
		    //outputpanel.setVisible(false);
		    mgpc.watch1.setText("0.0");
		    mgpc.watch3.setText("0.0");
		    mgpc.watch4.setText("s");
		    mgpc.ssc.clockcanvas.setStatus(0,state.NTime,state.dtime);
		    mgpc.ssc.clockcanvas.reset();
		    mgpa.tgc1.setScale(state.VScale, state.IScale, state.PScale,
			state.VScale, state.IScale, state.PScale);
		    mgpa.tgc2.setScale(state.VScale, state.IScale, state.PScale,
			state.VScale, state.IScale, state.PScale);
                }
                outputpanel.canvas1.repaint();
	    }
	    else if(evt.getSource() == mgpa.cb1){
		state.IsStepOn = true;
		//state.RiseTime = 0.0;
		state.ignition();
		
                
		ccan.setStep(true);
		
		mgpc.IsStepOn = true;
		mgpa.IsStepOn = true;
		
		mgpa.cb1.setState(true);
		mgpc.cb1.setState(true);
		mgpa.cb2.setState(false);
		mgpc.cb2.setState(false);
		mgpc.tgc3.setStep(true);
		mgpa.tgc1.setStep(true);
		mgpa.tgc2.setStep(true);
		
		//mgpc.rise1.setText("0.0");
		//mgpa.rise1.setText("0.0");
		
		//mgpc.rise2.setText(" s");
		//mgpa.rise2.setText(" s");
		
		//mgpc.slider2.setValue(0);
		//mgpa.slider2.setValue(0);
                
                mgpc.slider2.setVisible(false);
                mgpc.b2a.setVisible(false);
                mgpc.b2b.setVisible(false);
                mgpa.slider2.setVisible(false);
                mgpa.b2a.setVisible(false);
                mgpa.b2b.setVisible(false);
		//mgpa.ps4.setVisible(false);
                
                mgpc.tgc3.setPulse(false);
                
                mgpc.ps3.setVisible(false);
                mgpc.ps4.setVisible(false);
                mgpc.rise1.setVisible(false);
                mgpc.rise2.setVisible(false);
                mgpa.rise1.setVisible(false);
                mgpa.rise2.setVisible(false);
                
                mgpc.rise3.setVisible(false);
                mgpc.rise5.setVisible(false);
                mgpa.rise3.setVisible(false);
                mgpa.rise5.setVisible(false); 
        		
		//mgpc.RiseTime = 0.0;
		//mgpa.RiseTime = 0.0;
		mgpa.tgc1.setFiftyDelay(state.Delay, state.Delay2);
		
		//mgpa.plotTimeVoltage(state);
		if(mgpa.Flag == 1){
		    mgpa.plotTimeVoltage(state);
		}
		else if (mgpa.Flag == 2){
		    mgpa.plotTimeCurrent(state);
		}
		else if (mgpa.Flag == 3){
		    mgpa.plotTimePower(state);
		}
		
		ccan.repaint();
		mgpc.repaint();
		mgpa.repaint();
		mgpc.tgc3.repaint();
		mgpa.tgc1.repaint();
		mgpa.tgc2.repaint();
                outputpanel.canvas1.repaint();
	    }
	    else if(evt.getSource() == mgpa.cb2){		
		
                mgpa.slider2.setVisible(true);
		mgpa.b2a.setVisible(true);
                mgpa.b2b.setVisible(true);                
                mgpc.rise1.setVisible(true);
                mgpc.rise2.setVisible(true);
                mgpa.rise1.setVisible(true);
                mgpa.rise2.setVisible(true);
                
                mgpc.rise3.setVisible(true);
                mgpc.rise5.setVisible(true);
                mgpa.rise3.setVisible(true);
                mgpa.rise5.setVisible(true); 
                
                ccan.setStep(false);
		state.IsStepOn = false;
		//state.RiseTime = 0.5e-15;
		//mgpa.rise1.setText("0.5");
		//mgpa.rise2.setText("fs");
		state.ignition();
		
		mgpc.IsStepOn = false;
		mgpa.IsStepOn = false;
		mgpc.tgc3.setPulse(true);
                
		mgpa.cb1.setState(false);
		mgpc.cb1.setState(false);
		mgpa.cb2.setState(true);
		mgpc.cb2.setState(true);
		mgpc.tgc3.setStep(false);
		mgpa.tgc1.setStep(false);
		mgpa.tgc2.setStep(false);
		
                //----
                //mgpc.rise1.setText("0.5");
		//mgpa.rise1.setText("0.5");
		
		//mgpc.rise2.setText(" fs");
		//mgpa.rise2.setText(" fs");
		
		//mgpc.slider2.setValue(0);
		//mgpa.slider2.setValue(0);
		
		//mgpc.RiseTime = 0.5e-15;
		//mgpa.RiseTime = 0.5e-15;
		mgpa.tgc1.setFiftyDelay(state.Delay, state.Delay2);
                mgpa.setRiseTime(state.RiseTime);
		//mgpa.tgc1.setPulse(true);
                //mgpa.tgc2.setPulse(true);
                //state.setRiseTime(mgpa.RiseTime);
                //state.ignition();
		//mgpa.plotTimeVoltage(state);
		if(mgpa.Flag == 1){
		    mgpa.plotTimeVoltage(state);
		}
		else if (mgpa.Flag == 2){
		    mgpa.plotTimeCurrent(state);
		}
		else if (mgpa.Flag == 3){
		    mgpa.plotTimePower(state);
		}
                //----
                
		ccan.repaint();
		mgpa.repaint();
		mgpc.repaint();
		mgpc.tgc3.repaint();
		mgpa.tgc1.repaint();
		mgpa.tgc2.repaint();
                
                outputpanel.canvas1.repaint();
	    }
	    		
}

    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){;}
    
    public synchronized void mouseHandler(MouseEvent evt){
	if(evt.getSource() == mgpc.ssc.button1){
	    
		state.SwitchIsOpen = false;
		state.ignition();
		ccan.repaint();
                
                cp.c1.setEnabled(false);//******
                cp.c2.setEnabled(false);//******
                
                mgpc.ssc.IsStart = true;
                mgpc.ssc.IsStop = false;
                mgpc.ssc.IsReset = false;
                
                mgpc.ssc.button1.setEnabled(false);
                mgpc.ssc.button2.setEnabled(true);
                mgpc.ssc.button3.setEnabled(false);
                linepanel.setEnabled(false);
                loadpanel.setEnabled(false);
                generatorpanel.setEnabled(false);

                mgpc.ssc.repaint();
	}

        if(evt.getSource() == mgpc.ssc.button2){
                mgpc.c1.setEnabled(true);//*****
		state.SwitchIsOpen = false;
		state.ignition();
		ccan.repaint();
                
                cp.c1.setEnabled(true);//******
                cp.c2.setEnabled(true);//******
                
                mgpc.ssc.IsStart = false;
                mgpc.ssc.IsStop = true;
                mgpc.ssc.IsReset = false;
                
                mgpc.ssc.button1.setEnabled(true);
                mgpc.ssc.button2.setEnabled(false);
                mgpc.ssc.button3.setEnabled(true);
                
                linepanel.setEnabled(true);
                loadpanel.setEnabled(true);
                generatorpanel.setEnabled(true);

                mgpc.ssc.repaint();
	}
        
	if(evt.getSource() == mgpc.ssc.button3){
                mgpc.c1.setEnabled(true);//******
                
		state.SwitchIsOpen = true;
                state.reset();
		state.ignition();
		ccan.repaint();
		
                cp.c1.setEnabled(true);//*****
                cp.c2.setEnabled(true);//*****
                
		//mgpc.tgc3.repaint();
		mgpc.tgc3.setXpos(state.xpos);
	
		mgpc.tgc3.setDynamics(false);
		if(mgpa.Flag == 1){
		    mgpa.plotTimeVoltage(state);
		}
		else if (mgpa.Flag == 2){
		    mgpa.plotTimeCurrent(state);
		}
		else if (mgpa.Flag == 3){
		    mgpa.plotTimePower(state);
		}
	
		mgpa.tgc1.repaint();
		mgpa.tgc2.repaint();
	
		mgpc.tgc3.repaint();
                
                mgpc.ssc.button1.setEnabled(true);
                mgpc.ssc.button2.setEnabled(false);
                mgpc.ssc.button3.setEnabled(false);
                
                linepanel.setEnabled(true);
                loadpanel.setEnabled(true);
                generatorpanel.setEnabled(true);
                
                mgpc.ssc.IsStart = false;
                mgpc.ssc.IsStop = false;
                mgpc.ssc.IsReset = true;
                
                mgpc.ssc.repaint();

    	}

    }


    private void send_shock_wave(){
	state.ignition();
	
	ccan.repaint();
	outputpanel.canvas1.repaint();
	
    }    
     

}
