/**
 * Coaxial.java
 * Prepared by Umberto Ravaioli 
 * for 6th edition of Fundamentals of Applied Electromagnetics Book
 * May 2009 - All Rights Reserved
 */   

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

public class Coaxial extends Frame implements ActionListener, AdjustmentListener, ItemListener, MouseListener, WindowListener{
    Instructions instructions;
    //About about;
    TitlePanel titlepanel;
    NewGuideCanvas rwc;
    NewGuideInputPanel inputpanel;
    NewGuide_State state;
    SetRangePanel a_panel, a_to_b_panel, frequency_panel, w_panel;
    NewGuideControlPanel rwconp;
    NewGuideOutputPanel outputpanel;
    NewGuideGraphCanvas rwcc;
    NewGuideGraphCanvasB rwccb;

    Font ttfFont, phiFont;

    Panel pInstrWhite, pInstrBlack;
    Panel pOutputWhite, pOutputBlack1, pOutputBlack2;
    Panel pInputWhite, pInputBlack;

    private static final boolean useOldFonts = true;
    
    /**
     * Initializes the applet.  You never need to call this directly; it is
     * called automatically by the system once the applet is created.
     */
    
    public static void main(String[] args){
        Coaxial f = new Coaxial();
        int xmove = 20;
        int ymove = 41;
        f.setSize(626+xmove,565+ymove);
        //f.setSize(960,712);
        f.setVisible(true);
        f.setLayout(null);
    }
        
    public Coaxial() {
	setLayout(null);
        String lcOSName = System.getProperty("os.name").toLowerCase();
        boolean MAC_OS_X = lcOSName.startsWith("mac os x");
        //System.out.println(lcOSName);
        
        int xmove = 10;
        int ymove = 34;
        
        if (!useOldFonts) {
            //getUlabyFonts();
            state = new NewGuide_State();
            state.ttfFont = ttfFont;
            state.sanSerifFont = ttfFont;
            state.serifFont = ttfFont;
            state.symbolFont = phiFont;
            MaestroG.serifFont = ttfFont;
            MaestroG.sanSerifFont = ttfFont;
            MaestroG.useBiggerFont = true;
            //GraphCanvas.font1 = ttfFont.deriveFont(11f);
            //NewGuideCanvas.labfont = ttfFont.deriveFont(10F);
            //NewGuideCanvas.symbfont = phiFont.deriveFont(12F);
            //NewGuideCanvas.normalfont = ttfFont.deriveFont(12F);
            //NewGuideControlPanel.labfont = ttfFont.deriveFont(Font.BOLD,14F);
            //SetRangePanel.labfont = ttfFont.deriveFont(12f);
            //SetRangePanel.titlefont = ttfFont.deriveFont(Font.BOLD,16f);
            GraphCanvas.font1 = ttfFont.deriveFont(13f);
            NewGuideCanvas.labfont = ttfFont.deriveFont(12F);
            NewGuideCanvas.symbfont = phiFont.deriveFont(14F);
            NewGuideCanvas.normalfont = ttfFont.deriveFont(14F);
            NewGuideControlPanel.labfont = ttfFont.deriveFont(Font.BOLD,16F);
            SetRangePanel.labfont = ttfFont.deriveFont(14f);
            SetRangePanel.titlefont = ttfFont.deriveFont(Font.BOLD,18f);
            
        } else {
            state = new NewGuide_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);
            MaestroG.serifFont = state.serifFont;
            MaestroG.sanSerifFont = state.sanSerifFont;
            MaestroG.useBiggerFont = false;
            GraphCanvas.font1 = new Font("SanSerif",Font.PLAIN,11);
            NewGuideCanvas.labfont = new Font("SanSerif",Font.PLAIN,10);
            NewGuideCanvas.symbfont = new Font("Serif",Font.PLAIN,12);
            NewGuideCanvas.normalfont = new Font("SanSerif",Font.PLAIN,12);
            NewGuideControlPanel.labfont = new Font("SanSerif",Font.BOLD,12);
            SetRangePanel.labfont = new Font("SanSerif",Font.PLAIN,12);
            SetRangePanel.titlefont = new Font("SanSerif",Font.BOLD,16);
        }

        setFont(state.ttfFont.deriveFont(Font.PLAIN,12f));

	//titlepanel = new TitlePanel(subtitleFont,"Module 2.2","Coaxial Cable");
	titlepanel = new TitlePanel(state.ttfFont.deriveFont(Font.BOLD,15f),
                                    "Module 2.2","Coaxial Cable");
	//add(titlepanel);
	titlepanel.setBounds(10+xmove,10+ymove,300,40);
	
	
	rwc = new NewGuideCanvas();
	//add(rwc);
	rwc.setBounds(11+xmove,56+ymove,298,198);
	rwc.setThick(state.b);
	rwc.setThickmax(state.b_maximum);
	rwc.setStrip(state.w);
	rwc.setStripmax(state.w_maximum);
	
	inputpanel = new NewGuideInputPanel(state);
	//add(inputpanel);
	inputpanel.setBounds(12+xmove,262+ymove,296,286);
	
	outputpanel = new NewGuideOutputPanel(state);
	//add(outputpanel);
	outputpanel.setBounds(317+xmove,262+ymove,296,286);
	outputpanel.setVisible(true);
	
        instructions = new Instructions(state);
        instructions.setBounds(12+xmove,262+ymove,600,286);
        instructions.setVisible(true);
        
	frequency_panel = new SetRangePanel("Frequency","[ Hz ]");
	//add(frequency_panel);
	frequency_panel.setBounds(12+xmove,262+ymove,296,286);
	frequency_panel.setVisible(false);
	frequency_panel.setMinimum(state.frequency_minimum);
	frequency_panel.setMaximum(state.frequency_maximum);
	// CHANGE ==============================================================
        //frequency_panel.setBackg(new Color(236,236,221));
	frequency_panel.setBackground(new Color(236,236,221));
        //======================================================================
	
	a_panel = new SetRangePanel("Shield Radius R ","");
	//add(a_panel);
	a_panel.setBounds(12+xmove,262+ymove,296,286);
	a_panel.setVisible(false);
	a_panel.setMinimum(state.a_minimum);
	a_panel.setMaximum(state.a_maximum);
	// CHANGE ==============================================================
        //a_panel.setBackg(new Color(236,236,221));
	a_panel.setBackground(new Color(236,236,221));
        //======================================================================
        
	a_to_b_panel = new SetRangePanel("Strip Thickness t ","");
	//add(a_to_b_panel);
	a_to_b_panel.setBounds(12+xmove,262+ymove,296,286);
	a_to_b_panel.setVisible(false);
	a_to_b_panel.setMinimum(state.b_minimum);
	a_to_b_panel.setMaximum(state.b_maximum);
	// CHANGE ==============================================================
        //a_to_b_panel.setBackg(new Color(236,236,221));
        a_to_b_panel.setBackground(new Color(236,236,221));
	//======================================================================
	
	w_panel = new SetRangePanel("Inner Radius ","");
	//add(w_panel);
	w_panel.setBounds(12+xmove,262+ymove,296,286);
	w_panel.setVisible(false);
	w_panel.setMinimum(state.w_minimum);
	w_panel.setMaximum(state.w_maximum);
	// CHANGE  =============================================================
        //w_panel.setBackg(new Color(236,236,221));
        w_panel.setBackground(new Color(236,236,221));
	//======================================================================
	rwconp = new NewGuideControlPanel();
	//add(rwconp);
	rwconp.setBounds(317+xmove,12+ymove,296,36);
	
	rwcc = new NewGuideGraphCanvas(state);
	//add(rwcc);
	rwcc.setVisible(true);
	rwcc.setBounds(315+xmove,55+ymove,300,200);
	
	rwccb = new NewGuideGraphCanvasB(state);
	//add(rwccb);
	rwccb.setVisible(false);
	rwccb.setBounds(315+xmove,55+ymove,300,200);
	
	Panel p1 = new Panel();
	    p1.setBackground(Color.black);
	    //add(p1);
	    p1.setBounds(10+xmove,55+ymove,300,200);
            
	//backpanels for output panel
	pOutputWhite = new Panel();
	    pOutputWhite.setBackground(Color.white);
	    pOutputWhite.setBounds(316+xmove,261+ymove,298,288);
	    pOutputWhite.setVisible(false);
    
        pOutputBlack1 = new Panel();
	    pOutputBlack1.setBackground(Color.black);
	    pOutputBlack1.setBounds(315+xmove,260+ymove,300,290);
	    pOutputBlack1.setVisible(false);
	    
        pOutputBlack2 = new Panel();
	    pOutputBlack2.setBackground(Color.black);
	    //pOutputBlack2.setBounds(315+xmove,55+ymove,300,200);
	    pOutputBlack2.setVisible(false);
	  
	//backpanels for plot panel
	Panel p40 = new Panel();
	    p40.setBackground(Color.white);
	    //add(p40);
	    p40.setBounds(316+xmove,11+ymove,298,38);
    
	Panel p4 = new Panel();
	    p4.setBackground(Color.black);
	    //add(p4);
	    p4.setBounds(315+xmove,10+ymove,300,40);

	
	//backpanels for inputpanel        
        pInputWhite = new Panel();
	    pInputWhite.setBackground(Color.white);
	    pInputWhite.setBounds(11+xmove,261+ymove,298,288);
	    pInputWhite.setVisible(false);
    
        pInputBlack = new Panel();
	    pInputBlack.setBackground(Color.black);
	    pInputBlack.setBounds(10+xmove,260+ymove,300,290);
	    pInputBlack.setVisible(false);

        // backpanels for instructions
        pInstrWhite = new Panel();
        pInstrBlack = new Panel();
            pInstrWhite.setBackground(Color.white);
            pInstrWhite.setBounds(11+xmove,261+ymove,602,288);
            pInstrBlack.setBackground(Color.black);
            pInstrBlack.setBounds(10+xmove,260+ymove,604,290);

	//backpanels for applet
	Panel p0 = new Panel();
	    p0.setBackground(Color.cyan);
	    //add(p0);
	    p0.setBounds(3+xmove,3+ymove,620,555);
	    
	Panel p00 = new Panel();
	    p00.setBackground(Color.black);
	    //add(p00);
	    p00.setBounds(xmove,ymove,626,561);
    
            //if(state.this_year > line.magicyear || (state.this_year == line.magicyear && state.this_month > line.magicmonth)){
            //    state.LicenseExpired = true;
            //}
            //else
            //{   
            add(instructions);
            //add(about);
            add(titlepanel); 	    
	    add(rwc);
	    add(inputpanel);
	    add(outputpanel);
	    add(frequency_panel);
	    add(a_panel);
	    add(a_to_b_panel);
	    add(w_panel);
	    add(rwconp);
	    add(rwcc);
	    add(rwccb);
	    add(p1);
	    
	    add(pOutputWhite);
	    add(pOutputBlack1);
	    //add(pOutputBlack2);
	    add(p40);
	    add(p4);
	    add(pInputWhite);
	    add(pInputBlack);
            add(pInstrWhite);
            add(pInstrBlack);

	    add(p0);
	    add(p00);
	    
	    state.LicenseExpired = false; 	
            //}

		
	//Listeners
        this.addWindowListener(this);
        instructions.bupdate.addActionListener(this);
        inputpanel.binstr.addActionListener(this);
	//rwconp.ch1.addItemListener(this);
	rwconp.ch2.addItemListener(this);
	inputpanel.b1.addActionListener(this);
	inputpanel.b2.addActionListener(this);
	inputpanel.b3.addActionListener(this);
	inputpanel.b5.addActionListener(this);
	inputpanel.slider1.addAdjustmentListener(this);
	inputpanel.slider2.addAdjustmentListener(this);
	inputpanel.slider3.addAdjustmentListener(this);
	inputpanel.slider5.addAdjustmentListener(this);
	//inputpanel.ch1.addItemListener(this);
	//inputpanel.ch2.addItemListener(this);
	a_panel.b1.addActionListener(this);
	a_to_b_panel.b1.addActionListener(this);
	w_panel.b1.addActionListener(this);
	frequency_panel.b1.addActionListener(this);
	inputpanel.bupdate.addActionListener(this);
	
    }
    

    
    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,585);  	
	/*	
	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,582);
        //g.setFont(fonto);
        //g.drawString("Amanogawa, "+annonuovo+" - All Rights Reserved",30,580);
        */
    }

    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()==inputpanel.slider1){
	    state.ignition();
	    state.scan_coefficients();
	    
	    rwcc.setYRangeMax(state.Z0f_max);
	    rwcc.setYRangeMin(state.Z0f_min);
	    rwcc.plot(state.x_geom1,state.F_array);
	    rwcc.setRefPoint(state.a);
	    rwcc.setWZero(state.IsWZero);
	    rwcc.ignition();
	    rwcc.repaint();
	    
	    rwccb.setYRangeMax(state.Z0g_max);
	    rwccb.setYRangeMin(state.Z0g_min);
	    rwccb.plot(state.x_geom2,state.G_array);
	    rwccb.setRefPoint(state.w);
	    rwccb.setWZero(state.IsWZero);
	    rwccb.ignition();
	    rwccb.repaint();
	
	    rwc.setWidth(state.a);
	    rwc.repaint();
	    
	    outputpanel.rwocA.repaint();
	    outputpanel.rwocB.repaint();
		
	}
	if(evt.getSource()==inputpanel.slider2){
	    rwc.setFrequency(state.frequency);
	    
	    state.ignition();
	    state.scan_coefficients();
	    
	    rwcc.setYRangeMax(state.Z0f_max);
	    rwcc.setYRangeMin(state.Z0f_min);
	    
	    rwcc.plot(state.x_geom1,state.F_array);
	    rwcc.setRefPoint(state.a);
	    rwcc.setWZero(state.IsWZero);
	    rwcc.ignition();
	    rwcc.repaint();
	    
	    rwccb.setYRangeMax(state.Z0g_max);
	    rwccb.setYRangeMin(state.Z0g_min);
	    rwccb.plot(state.x_geom2,state.G_array);
	    rwccb.setRefPoint(state.w);
	    rwccb.setWZero(state.IsWZero);
	    rwccb.ignition();
	    rwccb.repaint();
	    
	    rwc.repaint();  
	    outputpanel.rwocA.repaint();
	    outputpanel.rwocB.repaint();
	    
	}
	if(evt.getSource()==inputpanel.slider3){
	    state.ignition();
	    state.scan_coefficients();
	    
	    rwcc.setYRangeMax(state.Z0f_max);
	    rwcc.setYRangeMin(state.Z0f_min);
	    rwcc.plot(state.x_geom1,state.F_array);
	    rwcc.setRefPoint(state.a);
	    rwcc.setWZero(state.IsWZero);
	    rwcc.ignition();
	    rwcc.repaint();
	    
	    rwccb.setYRangeMax(state.Z0g_max);
	    rwccb.setYRangeMin(state.Z0g_min);
	    rwccb.plot(state.x_geom2,state.G_array);
	    rwccb.setRefPoint(state.w);
	    rwccb.setWZero(state.IsWZero);
	    rwccb.ignition();
	    rwccb.repaint();
	
	    rwc.setStrip(state.w);
	    rwc.repaint();
	    state.ignition();
	    outputpanel.rwocA.repaint();
	    outputpanel.rwocB.repaint();
    	}
	if(evt.getSource()==inputpanel.slider5){
	    state.ignition();
	    state.scan_coefficients();
	    
	    rwcc.setYRangeMax(state.Z0f_max);
	    rwcc.setYRangeMin(state.Z0f_min);
	    rwcc.plot(state.x_geom1,state.F_array);
	    rwcc.setRefPoint(state.a);
	    rwcc.setWZero(state.IsWZero);
	    rwcc.ignition();
	    rwcc.repaint();
	
	    rwccb.setYRangeMax(state.Z0g_max);
	    rwccb.setYRangeMin(state.Z0g_min);
	    rwccb.plot(state.x_geom2,state.G_array);
	    rwccb.setRefPoint(state.w);
	    rwccb.setWZero(state.IsWZero);
	    rwccb.ignition();
	    rwccb.repaint();
	    rwc.setThick(state.b);
	    rwc.setWidth(state.a);
	    rwc.repaint();
	    outputpanel.rwocA.repaint();
	    outputpanel.rwocB.repaint();
	}
    }
    
    public void mouseClicked(MouseEvent evt){/*myEventHandler(evt);*/}
    public void mouseEntered(MouseEvent evt){ }
    public void mouseExited(MouseEvent evt) { }
    //public void mousePressed(MouseEvent evt) {rwcc.repaint();}
    public void mouseReleased(MouseEvent evt) { }
    public void mousePressed(MouseEvent evt) {
	
    }
    
    public void actionPerformed(ActionEvent evt){
        //if(evt.getSource()==about.bupdate){
        //        about.setVisible(false);
        //        if(state.OptionOne){rwconp.ch2.select(" Impedance vs. Radius R");} 
        //        else if(state.OptionTwo){rwconp.ch2.select(" Impedance vs. Radius r");} 
        //        
        //    }
        if(evt.getSource()==instructions.bupdate){
            instructions.setVisible(false);
            pInstrWhite.setVisible(false);
	    pInstrBlack.setVisible(false);
            inputpanel.setVisible(true);
            outputpanel.setVisible(true);
            pInputWhite.setVisible(true);
	    pInputBlack.setVisible(true);
            pOutputWhite.setVisible(true);
            pOutputBlack1.setVisible(true);
            pInputWhite.setVisible(true);
            pInputBlack.setVisible(true);
        }
        if(evt.getSource()==inputpanel.binstr){
            instructions.setVisible(true);
            pInstrWhite.setVisible(true);
	    pInstrBlack.setVisible(true);
            inputpanel.setVisible(false);
            outputpanel.setVisible(false);
            pInputWhite.setVisible(false);
	    pInputBlack.setVisible(false);
            pOutputWhite.setVisible(false);
            pOutputBlack1.setVisible(false);
            pInputWhite.setVisible(false);
            pInputBlack.setVisible(false);
        }
        
	if(evt.getSource()==inputpanel.bupdate){
	    
	    state.ignition();
	    state.scan_coefficients();
	    
	    rwcc.setYRangeMax(state.Z0f_max);
	    rwcc.setYRangeMin(state.Z0f_min);
	    rwcc.plot(state.x_geom1,state.F_array);
	    rwcc.setRefPoint(state.a);
	    rwcc.setWZero(state.IsWZero);
	    rwcc.ignition();
	    rwcc.repaint();
	    
	    rwccb.setYRangeMax(state.Z0g_max);
	    rwccb.setYRangeMin(state.Z0g_min);
	    rwccb.plot(state.x_geom2,state.G_array);
	    rwccb.setRefPoint(state.w);
	    rwccb.setWZero(state.IsWZero);
	    rwccb.ignition();
	    rwccb.repaint();
	    
	    rwc.setWidth(state.a);
	    rwc.setThick(state.b);
	    rwc.setStrip(state.w);
	    rwc.setFrequency(state.frequency);
	    rwc.setEpsilon(state.epsilon_r);
	   
	    rwc.setSigma2(state.sigma2);
	    rwc.setSigmaMetal(state.sigma_metal);
	    
	    rwc.repaint();
	    outputpanel.rwocA.repaint();
	    outputpanel.rwocB.repaint();
	}
	else if(evt.getSource()==inputpanel.b1){
	    a_panel.setUnit(true);
	    a_panel.setMils(state.IsMilsOn);
	    a_panel.setVisible(true);
	    if(!state.IsMilsOn){
		a_panel.setMinimum(state.a_minimum);
		a_panel.setMaximum(state.a_maximum);
	    }
	    else{
		a_panel.setMinimum(state.a_mil_minimum);
		a_panel.setMaximum(state.a_mil_maximum);
	    }
	    inputpanel.setVisible(false);
	    a_to_b_panel.setVisible(false);
	    frequency_panel.setVisible(false);
	    w_panel.setVisible(false);	    
	}
	else if(evt.getSource()==inputpanel.b2){
	    frequency_panel.setUnit(false);
	    a_panel.setVisible(false);
	    inputpanel.setVisible(false);
	    a_to_b_panel.setVisible(false);
	    frequency_panel.setVisible(true);
	    w_panel.setVisible(false);	
	    
	}
	else if(evt.getSource()==inputpanel.b3){
	    w_panel.setUnit(true);
	    w_panel.setMils(state.IsMilsOn);
	    a_panel.setVisible(false);
	    inputpanel.setVisible(false);
	    a_to_b_panel.setVisible(false);
	    frequency_panel.setVisible(false);
	    w_panel.setVisible(true);
	    if(!state.IsMilsOn){
		w_panel.setMinimum(state.w_minimum);
		w_panel.setMaximum(state.w_maximum);
	    }
	    else{
		w_panel.setMinimum(state.w_mil_minimum);
		w_panel.setMaximum(state.w_mil_maximum);
	    }
	}
	else if(evt.getSource()==inputpanel.b5){
	    a_to_b_panel.setUnit(true);
	    a_to_b_panel.setMils(state.IsMilsOn);
	    a_panel.setVisible(false);
	    inputpanel.setVisible(false);
	    a_to_b_panel.setVisible(true);
	    if(!state.IsMilsOn){
		a_to_b_panel.setMinimum(state.b_minimum);
		a_to_b_panel.setMaximum(state.b_maximum);
	    }
	    else{
		a_to_b_panel.setMinimum(state.b_mil_minimum);
		a_to_b_panel.setMaximum(state.b_mil_maximum);
	    }
	    frequency_panel.setVisible(false);
	    w_panel.setVisible(false);	
	    
	}
	else if(evt.getSource()==a_panel.b1){
	    a_panel.setVisible(false);
	    inputpanel.setVisible(true);
	    a_to_b_panel.setVisible(false);
	    w_panel.setVisible(false);
	    frequency_panel.setVisible(false);
	if(!state.IsMilsOn){
		state.a_minimum = a_panel.getMinimum();
		state.a_maximum = a_panel.getMaximum();
	
	    if(state.a >= state.a_minimum && state.a <= state.a_maximum){
		inputpanel.slider1.setValue((int)(inputpanel.ScrollMax*(state.a-state.a_minimum)
						    /(state.a_maximum-state.a_minimum)));
	    }
	    else if(state.a < state.a_minimum){
		state.a = state.a_minimum;
		inputpanel.slider1.setValue(0);
		inputpanel.text1.setText(""+state.a);
	    }
	
	    else if(state.a > state.a_maximum){
		state.a = state.a_maximum;
		inputpanel.slider1.setValue(inputpanel.ScrollMax);
		inputpanel.text1.setText(""+state.a);
	    }
	    if(state.a < state.w){
		state.w = state.a;
		inputpanel.slider3.setValue((int)(inputpanel.ScrollMax*(state.w-state.w_minimum)
						    /(state.w_maximum-state.w_minimum)));
		inputpanel.text6.setText(""+state.w);
	    }
	    
	}
	else{
		state.a_mil_minimum = a_panel.getMinimum();
		state.a_mil_maximum = a_panel.getMaximum();
		
		if(state.a_mil >= state.a_mil_minimum && state.a_mil <= state.a_mil_maximum){
		inputpanel.slider1.setValue((int)(inputpanel.ScrollMax*(state.a_mil-state.a_mil_minimum)
						    /(state.a_mil_maximum-state.a_mil_minimum)));
	    }
	    else if(state.a_mil < state.a_mil_minimum){
		state.a_mil = state.a_mil_minimum;
		inputpanel.slider1.setValue(0);
		inputpanel.text1.setText(""+state.a_mil);
	    }
	
	    else if(state.a_mil > state.a_mil_maximum){
		state.a_mil = state.a_mil_maximum;
		inputpanel.slider1.setValue(inputpanel.ScrollMax);
		inputpanel.text1.setText(""+state.a_mil);
	    }
	    if(state.a_mil < state.w_mil){
		state.w_mil = state.a_mil;
		inputpanel.slider3.setValue((int)(inputpanel.ScrollMax*(state.w_mil-state.w_mil_minimum)
						    /(state.w_mil_maximum-state.w_mil_minimum)));
		inputpanel.text6.setText(""+state.w_mil);
	    }
	}
	
	        
	    state.ignition();
	    state.scan_coefficients();
	    
	    rwcc.setYRangeMax(state.Z0f_max);
	    rwcc.setYRangeMin(state.Z0f_min);
	    rwcc.plot(state.x_geom1,state.F_array);
	    rwcc.setRefPoint(state.a);
	    rwcc.setWZero(state.IsWZero);
	    rwcc.ignition();
	    rwcc.repaint();
	    
	    rwccb.setYRangeMax(state.Z0g_max);
	    rwccb.setYRangeMin(state.Z0g_min);
	    rwccb.plot(state.x_geom2,state.G_array);
	    rwccb.setRefPoint(state.w);
	    rwccb.setWZero(state.IsWZero);
	    rwccb.ignition();
	    rwccb.repaint();
	    
	    rwc.setWidthMax(state.a_maximum);
	    
	    rwc.setWidth(state.a);
	    rwc.setStrip(state.w);
	    rwc.repaint();
	    outputpanel.rwocA.repaint();
	    outputpanel.rwocB.repaint();
	}
	else if(evt.getSource()==frequency_panel.b1){
	    a_panel.setVisible(false);
	    inputpanel.setVisible(true);
	    a_to_b_panel.setVisible(false);
	    w_panel.setVisible(false);
	    frequency_panel.setVisible(false);
	    
	    state.frequency_minimum = frequency_panel.getMinimum();
	    state.frequency_maximum = frequency_panel.getMaximum();
	    
	    
	    if(state.frequency >= state.frequency_minimum && state.frequency <= state.frequency_maximum){
		inputpanel.slider2.setValue((int)(inputpanel.ScrollMax*(state.frequency-state.frequency_minimum)
						    /(state.frequency_maximum-state.frequency_minimum)));
	    }
	    else if(state.frequency < state.frequency_minimum){
		state.frequency = state.frequency_minimum;
		inputpanel.slider2.setValue(0);
		inputpanel.text4.setText(""+state.frequency);
	    }
	
	    else if(state.frequency > state.frequency_maximum){
		state.frequency = state.frequency_maximum;
		inputpanel.slider2.setValue(inputpanel.ScrollMax);
		inputpanel.text4.setText(""+state.frequency);
	    }
	    state.ignition();
	    state.scan_coefficients();
	    
	    rwcc.setYRangeMax(state.Z0f_max);
	    rwcc.setYRangeMin(state.Z0f_min);
	    rwcc.plot(state.x_geom1,state.F_array);
	    rwcc.setRefPoint(state.a);
	    rwcc.setWZero(state.IsWZero);
	    rwcc.ignition();
	    rwcc.repaint();
	    
	    rwccb.setYRangeMax(state.Z0g_max);
	    rwccb.setYRangeMin(state.Z0g_min);
	    rwccb.plot(state.x_geom2,state.G_array);
	    rwccb.setRefPoint(state.w);
	    rwccb.setWZero(state.IsWZero);
	    rwccb.ignition();
	    rwccb.repaint();
	    
	    outputpanel.rwocA.repaint();
	    outputpanel.rwocB.repaint();
	    rwc.repaint();
	    rwcc.repaint();  
	}
	else if(evt.getSource()==a_to_b_panel.b1){
	    a_panel.setVisible(false);
	    inputpanel.setVisible(true);
	    a_to_b_panel.setVisible(false);
	    w_panel.setVisible(false);
	    frequency_panel.setVisible(false);
	  if(!state.IsMilsOn){
	    state.b_minimum = a_to_b_panel.getMinimum();
	    state.b_maximum = a_to_b_panel.getMaximum();
	    
	   if(state.b >= state.b_minimum && state.b <= state.b_maximum){
		inputpanel.slider5.setValue((int)(inputpanel.ScrollMax*(state.b-state.b_minimum)
						    /(state.b_maximum-state.b_minimum)));
	    }
	    else if(state.b < state.b_minimum){
		state.b = state.b_minimum;
		inputpanel.slider5.setValue(0);
		inputpanel.text5.setText(""+state.b);
	    }
	
	    else if(state.b > state.b_maximum){
		state.b = state.b_maximum;
		inputpanel.slider5.setValue(inputpanel.ScrollMax);
		inputpanel.text5.setText(""+state.b);
	    }
	  }
	  else{
		state.b_mil_minimum = a_to_b_panel.getMinimum();
		state.b_mil_maximum = a_to_b_panel.getMaximum();
	    
	   if(state.b_mil >= state.b_mil_minimum && state.b_mil <= state.b_mil_maximum){
		inputpanel.slider5.setValue((int)(inputpanel.ScrollMax*(state.b_mil-state.b_mil_minimum)
						    /(state.b_mil_maximum-state.b_mil_minimum)));
	    }
	    else if(state.b_mil < state.b_mil_minimum){
		state.b_mil = state.b_mil_minimum;
		inputpanel.slider5.setValue(0);
		inputpanel.text5.setText(""+state.b_mil);
	    }
	
	    else if(state.b_mil > state.b_mil_maximum){
		state.b_mil = state.b_mil_maximum;
		inputpanel.slider5.setValue(inputpanel.ScrollMax);
		inputpanel.text5.setText(""+state.b_mil);
	    }
	  }
	    
	    
	    state.ignition();
	    state.scan_coefficients();
	    
	    rwcc.setYRangeMax(state.Z0f_max);
	    rwcc.setYRangeMin(state.Z0f_min);
	    rwcc.plot(state.x_geom1,state.F_array);
	    rwcc.setRefPoint(state.a);
	    rwcc.setWZero(state.IsWZero);
	    rwcc.ignition();
	    rwcc.repaint();
	    
	    rwccb.setYRangeMax(state.Z0g_max);
	    rwccb.setYRangeMin(state.Z0g_min);
	    rwccb.plot(state.x_geom2,state.G_array);
	    rwccb.setRefPoint(state.w);
	    rwccb.setWZero(state.IsWZero);
	    rwccb.ignition();
	    rwccb.repaint();
	    
	    rwc.setThickmax(state.b_maximum);
	    rwc.setThick(state.b);
	    rwc.repaint();
	    outputpanel.rwocA.repaint();
	    outputpanel.rwocB.repaint(); 	    
	}
	else if(evt.getSource()==w_panel.b1){
	    a_panel.setVisible(false);
	    inputpanel.setVisible(true);
	    a_to_b_panel.setVisible(false);
	    w_panel.setVisible(false);
	    frequency_panel.setVisible(false);
	  if(!state.IsMilsOn){
	    state.w_minimum = w_panel.getMinimum();
	    state.w_maximum = w_panel.getMaximum();
	    
	   if(state.w >= state.w_minimum && state.w <= state.w_maximum){
		inputpanel.slider3.setValue((int)(inputpanel.ScrollMax*(state.w-state.w_minimum)
						    /(state.w_maximum-state.w_minimum)));
	    }
	    else if(state.w < state.w_minimum){
		state.w = state.w_minimum;
		inputpanel.slider3.setValue(0);
		inputpanel.text6.setText(""+state.w);
	    }
	
	    else if(state.w > state.w_maximum){
		state.w = state.w_maximum;
		inputpanel.slider3.setValue(inputpanel.ScrollMax);
		inputpanel.text6.setText(""+state.w);
	    }
	    if(state.a < state.w){
		state.a = state.w;
		inputpanel.slider1.setValue((int)(inputpanel.ScrollMax*(state.a-state.a_minimum)
						    /(state.a_maximum-state.a_minimum)));
		inputpanel.text1.setText(""+state.a);
	    }
	    
	  }
	  else{
	    state.w_mil_minimum = w_panel.getMinimum();
	    state.w_mil_maximum = w_panel.getMaximum();
	    
	   if(state.w_mil >= state.w_mil_minimum && state.w_mil <= state.w_mil_maximum){
		inputpanel.slider3.setValue((int)(inputpanel.ScrollMax*(state.w_mil-state.w_mil_minimum)
						    /(state.w_mil_maximum-state.w_mil_minimum)));
	    }
	    else if(state.w_mil < state.w_mil_minimum){
		state.w_mil = state.w_mil_minimum;
		inputpanel.slider3.setValue(0);
		inputpanel.text6.setText(""+state.w_mil);
	    }
	
	    else if(state.w_mil > state.w_mil_maximum){
		state.w_mil = state.w_mil_maximum;
		inputpanel.slider3.setValue(inputpanel.ScrollMax);
		inputpanel.text6.setText(""+state.w_mil);
	    }
	    if(state.a_mil < state.w_mil){
		state.a_mil = state.w_mil;
		inputpanel.slider1.setValue((int)(inputpanel.ScrollMax*(state.a_mil-state.a_mil_minimum)
						    /(state.a_mil_maximum-state.a_mil_minimum)));
		inputpanel.text1.setText(""+state.a_mil);
	    }
	  }
	    state.ignition();
	    state.scan_coefficients();
	    
	    rwcc.setYRangeMax(state.Z0f_max);
	    rwcc.setYRangeMin(state.Z0f_min);
	    rwcc.plot(state.x_geom1,state.F_array);
	    rwcc.setRefPoint(state.a);
	    rwcc.setWZero(state.IsWZero);
	    rwcc.ignition();
	    rwcc.repaint();
	    
	    rwccb.setYRangeMax(state.Z0g_max);
	    rwccb.setYRangeMin(state.Z0g_min);
	    rwccb.plot(state.x_geom2,state.G_array);
	    rwccb.setRefPoint(state.w);
	    rwccb.setWZero(state.IsWZero);
	    rwccb.ignition();
	    rwccb.repaint();
	    
	    rwc.setStripmax(state.w_maximum);
	    
	    rwc.setWidth(state.a);
	    rwc.setStrip(state.w);
	    outputpanel.rwocA.repaint();
	    outputpanel.rwocB.repaint();
	    
	    rwc.repaint();
	}  
    }
    
    public void itemStateChanged(ItemEvent evt){
	ItemSelectable ie = evt.getItemSelectable();
           //if(evt.getSource() == inputpanel.ch1){
	   //    state.IsMilsOn=false;
	   //    state.ignition();
	   //    outputpanel.rwocA.repaint();
	   //    outputpanel.rwocB.repaint();
	   //    inputpanel.repaint();
	   //    
	   //}
	   //if(evt.getSource() == inputpanel.ch2){
	   //    state.IsMilsOn=true;
	   //    state.ignition();
	   //    outputpanel.rwocA.repaint();
	   //    outputpanel.rwocB.repaint();
	   //    inputpanel.repaint();
	   //}
	
	
	if(evt.getSource()==rwconp.ch2){

		if(ie.getSelectedObjects()[0]==" Instructions"){
                    instructions.setVisible(true);
                    pInstrWhite.setVisible(true);
                    pInstrBlack.setVisible(true);
                    inputpanel.setVisible(false);
                    outputpanel.setVisible(false);
                    pOutputWhite.setVisible(false);
                    pOutputBlack1.setVisible(false);
                    pOutputBlack2.setVisible(false);
                    pInputWhite.setVisible(false);
                    pInputBlack.setVisible(false);
                }


		if(ie.getSelectedObjects()[0]==" Impedance vs. Radius b"){
		    state.ignition();
		    state.scan_coefficients();
                    state.OptionOne = true;
                    state.OptionTwo = false;
		    rwcc.setYRangeMax(state.Z0f_max);
		    rwcc.setYRangeMin(state.Z0f_min);
		    rwcc.plotZeroLine(false);
		    rwcc.plotRefPoint(true);
		    rwcc.setLabels("Real Part of Characteristic Impedance","Z"," b [mm]","0");
		    rwcc.setRefPoint(state.a);
		    rwcc.setWZero(state.IsWZero);
		    rwcc.plot(state.x_geom1,state.F_array);
		    
                    instructions.setVisible(false);
                    pInstrWhite.setVisible(false);
                    pInstrBlack.setVisible(false);
                    inputpanel.setVisible(true);
                    outputpanel.setVisible(true);
                    pOutputWhite.setVisible(true);
                    pOutputBlack1.setVisible(true);
                    pOutputBlack2.setVisible(true);
                    pInputWhite.setVisible(true);
                    pInputBlack.setVisible(true);
		    
		    rwcc.setVisible(true);
		    rwccb.setVisible(false);
                    //about.setVisible(false);
		    rwcc.ignition();
		    rwcc.repaint();  
		}
		if(ie.getSelectedObjects()[0]==" Impedance vs. Radius a"){
		    state.ignition();
		    state.scan_coefficients();
                    state.OptionOne = false;
                    state.OptionTwo = true;
		    rwccb.setYRangeMax(state.Z0g_max);
		    rwccb.setYRangeMin(state.Z0g_min);
		    rwccb.plotZeroLine(false);
		    rwccb.plotRefPoint(true);
		    rwccb.setLabels("Real Part of Characteristic Impedance","Z","a  [mm]","0");
		    rwccb.setRefPoint(state.w);
		    rwccb.setWZero(state.IsWZero);
		    rwccb.plot(state.x_geom2,state.G_array);

		    instructions.setVisible(false);
                    pInstrWhite.setVisible(false);
                    pInstrBlack.setVisible(false);
                    inputpanel.setVisible(true);
                    outputpanel.setVisible(true);
                    pOutputWhite.setVisible(true);
                    pOutputBlack1.setVisible(true);
                    pOutputBlack2.setVisible(true);
                    pInputWhite.setVisible(true);
                    pInputBlack.setVisible(true);

		    rwccb.setVisible(true);
		    rwcc.setVisible(false);
		    //about.setVisible(false);
                    rwccb.ignition();
		    rwccb.repaint();  
		}
		
	}
	
    }
    /**
     * Called to start the applet.  You never need to call this directly; it
     * is called when the applet's document is visited.
     */
    public void start() {
    }

    /**
     * Called to stop the applet.  This is called when the applet's document is
     * no longer on the screen.  It is guaranteed to be called before destroy()
     * is called.  You never need to call this method directly
     */
    public void stop() {
    }

    /**
     * Cleans up whatever resources are being held.  If the applet is active
     * it is stopped.
     */
    public void destroy() {
    }
}

