//NewGuideInputPanel.java
/* A Java class for
 * TwoWire.java
 * Electromagnetic Transmission Line Applet
 * Applet without Smith Chart - Prepared by Umberto Ravaioli 
 * for 6th edition of Fundamentals of Applied Electromagnetics Book
 * May 2009 - All Rights Reserved
 */   

import java.awt.*;
import java.awt.event.*;
import java.text.*;

public class NewGuideInputPanel extends Panel implements ActionListener, AdjustmentListener{
    private NewGuide_State state;
    //private NewModeControlPanel pwmc;
    //private static final Color bgcolor = new Color(160,200,200);
    private static final Color bgcolor = new Color(236,236,236);
    //private static final Font labfont=new Font("SanSerif",Font.PLAIN,12);
    //private static final Font normalfont = new Font("SanSerif",Font.PLAIN,14);
    //private static final Font smallfont = new Font("SanSerif",Font.PLAIN,12);
    private static Font labfont;
    private static Font normalfont;
    private static Font smallfont;
    
    public int ScrollMax = 10000;
    private Label titlelabel;
    private Label lab1, lab2, lab3, lab4, lab5, lab6, lab7;
    private Label ulab1, ulab2, ulab3, ulab4, ulab5, ulab6;
    public TextField text1, text2, text3, text4, text5, text6, text7, text8;
    public Scrollbar slider1, slider2, slider3, slider4;//, slider5;
    //public Checkbox ch1, ch2, ch3;
    // Gauge check buttons
    //public Checkbox cg1, cg2, cg3, cg4, cg5, cg6;
    
    public double diameter_mm[], diameter_mil[];
    
    //public CheckboxGroup cgrp, cgauge;
    public  Button b1, b2, b3, b5;
    public  Button bupdate, binstr;
    public Panel ps1, ps2, ps5, ps6;
  
    public NewGuideInputPanel(NewGuide_State state){
	super();
	setLayout(null);
	setBackground(bgcolor);
	this.state = state;

        if (MaestroG.useBiggerFont) {
            labfont = state.sanSerifFont.deriveFont(14F);
            normalfont = state.sanSerifFont.deriveFont(16F);
            smallfont = state.sanSerifFont.deriveFont(14F);
        } else {
            labfont = state.sanSerifFont.deriveFont(12F);
            normalfont = state.sanSerifFont.deriveFont(14F);
            smallfont = state.sanSerifFont.deriveFont(12F);
        }

        //setFont(normalfont);
        setFont(labfont);

	titlelabel = new Label("Input",Label.CENTER);
	//titlelabel.setFont(new Font("SanSerif",Font.BOLD,16));
        if (MaestroG.useBiggerFont) {
            titlelabel.setFont(state.sanSerifFont.deriveFont(Font.BOLD,18F));
        } else {
            titlelabel.setFont(state.sanSerifFont.deriveFont(Font.BOLD,16F));
        }
			
	lab1 = new Label("Centers distance  D =  ",Label.RIGHT);
	lab2 = new Label("AWG = ",Label.LEFT);
	lab2.setFont(labfont);
	lab2.setForeground(Color.red);
	lab3 = new Label("Relative \u03bc = ",Label.RIGHT);
	lab3.setFont(labfont);
	lab4 = new Label("Frequency   f  =  ",Label.RIGHT);
	lab5 = new Label("Strip thickness t  =  ",Label.RIGHT);
	lab6 = new Label("Wire Diameter  d =  ",Label.RIGHT);
	lab7 = new Label("Line Length  L  =  ",Label.RIGHT);
		
	text1 = new TextField(""+state.a,8);
	text3 = new TextField(""+state.epsilon_r,8);
	text4 = new TextField(""+state.frequency,8);
	text5 = new TextField(""+state.lineLength,8);
	text6 = new TextField(""+state.w,8);
	text7 = new TextField(""+state.sigma2,8);
	//text7 = new TextField(""+state.loss_tangent,8);
	//text8 = new TextField(""+state.rho_metal);
        DecimalFormat dec = new DecimalFormat("0.###E0");
        // NOTE: sigma_metal is 1/rho_metal
	text8 = new TextField(""+dec.format(state.sigma_metal),8);
        text1.setFont(labfont);
        text3.setFont(labfont);
        text4.setFont(labfont);
        text5.setFont(labfont);
        text6.setFont(labfont);
        text7.setFont(labfont);
        text8.setFont(labfont);
	
	ulab1 = new Label(" [ mm ]",Label.LEFT); // not used
	ulab2 = new Label(" [ m ]",Label.LEFT);  // not used
	ulab3 = new Label(" [ mm ]",Label.LEFT); // not used
	ulab4 = new Label(" [ Hz ]",Label.LEFT);
	ulab5 = new Label(" [ S/m ]",Label.LEFT);
	ulab6 = new Label(" [ S/m ]",Label.LEFT);
	//ulab6 = new Label(" [ \u03a9 m ]",Label.LEFT);
	ulab4.setFont(labfont);
	ulab5.setFont(labfont);
	ulab6.setFont(labfont);
	
	slider1 = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,ScrollMax+1);//changes a
	slider2 = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,ScrollMax+1);//changes frequency
	slider3 = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,ScrollMax+1);//changes w
        slider4 = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,52);//changes w
        
	//slider5 = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,ScrollMax+1);//changes lineLength
	
	slider1.setValue((int)((state.a-state.a_minimum)*ScrollMax/(state.a_maximum-state.a_minimum)));
	slider2.setValue((int)((state.frequency-state.frequency_minimum)*ScrollMax/(state.frequency_maximum-state.frequency_minimum)));
	slider3.setValue((int)((state.w-state.w_minimum)*ScrollMax/(state.w_maximum-state.w_minimum)));
        slider4.setValue(25);
        
        slider1.setBackground(Color.white);
        slider2.setBackground(Color.white);
        slider3.setBackground(Color.white);
        slider4.setBackground(Color.white);
        
        //slider1.setForeground(Color.blue);
        //slider2.setForeground(Color.blue);
        //slider3.setForeground(Color.blue);
        //slider4.setForeground(Color.blue);
        
	//slider5.setValue((int)((state.lineLength-state.lineLengthMIN)*ScrollMax/(state.lineLengthMAX-state.lineLengthMIN)));
	
        FontMetrics fmSmall = getFontMetrics(smallfont);
        int buttonWidth = fmSmall.stringWidth("XRangeX");
	b1 = new Button("Range");
        //b1.setFont(smallfont);
	b2 = new Button("Range");
	//b2.setFont(smallfont);
        b3 = new Button("Range");
	//b3.setFont(smallfont);
        
        //b5 = new Button("Range");
	bupdate = new Button("Update");
        
        b1.setBackground(Color.white);
        b2.setBackground(Color.white);
        b3.setBackground(Color.white);
        bupdate.setBackground(Color.white);
        
        // update button
	binstr = new Button("Instructions");
        binstr.setBackground(Color.white);
	add(binstr);
        int buttonx = 175;
        int buttony = 10;
        int buttonwide = 100;
        int buttonheight = 22;
	 
        binstr.setBounds(buttonx,buttony,buttonwide,buttonheight);	
        Panel pin = new Panel();
	    pin.setBackground(Color.black);
	    add(pin);
	    pin.setBounds(buttonx-1,buttony-1,buttonwide+2,buttonheight+2);
        
	add(titlelabel);
	add(lab1);
	add(lab2);
	add(lab3);
	add(lab4);
	//add(lab5);
	add(lab6);
	//add(lab7);
	add(text1);
	//add(text2);
	add(text3);
	add(text4);
	add(text5);
	add(text6);
	add(text7);
	add(text8);
	
	add(ulab4);
	add(ulab5);
	add(ulab6);
        //add(ulab7);
	add(slider1);
	add(slider2);
	add(slider3);
        add(slider4);
	//add(slider5);
	add(b1);
	add(b2);
	add(b3);
	//add(b5);
	add(bupdate);
	
	titlelabel.setBounds(10,10,50,18);
	
	int vPosInit = 35, vPos, dvPos = 7, vHeight = 15; 
	//vPos = vPosInit;
        vPos = vPosInit + 50; // 85
	lab6.setBounds(20,vPos-23,150,vHeight);
	text6.setBounds(170,vPos-25,80,vHeight+3);
	
	//vPos += vHeight + 2; 
	 // slider for  inner radius
	slider3.setBounds(80,vPos,196,vHeight);
	    ps1 = new Panel();
	    ps1.setBackground(Color.cyan);
	    add(ps1);
	    ps1.setBounds(79,vPos-1,198,vHeight+2);
	    
	    ps2 = new Panel();
	    ps2.setBackground(Color.black);
	    add(ps2);
	    ps2.setBounds(78,vPos-2,200,vHeight+4);
	    
	    lab2.setBounds(7,vPos-2,40,16);
            //b3.setBounds(20,vPos-2,45,20);
            b3.setBounds(15,vPos-2,buttonWidth,20); // range button
            Panel pb3 = new Panel();
            pb3.setBackground(Color.black);
	    add(pb3);
	    pb3.setBounds(14,vPos-3,buttonWidth+2,22);
            
            //Wire gauge slider
            slider4.setBounds(80,vPos,196,vHeight);
	    ps5 = new Panel();
	    ps5.setBackground(Color.cyan);
	    add(ps5);
	    ps5.setBounds(79,vPos-1,198,vHeight+2);
	    
	    ps6 = new Panel();
	    ps6.setBackground(Color.black);
	    add(ps6);
	    ps6.setBounds(78,vPos-2,200,vHeight+4);
            
            //vPos += vHeight+5;
            
            //------------------------------------
            
	    lab2.setVisible(false);
            slider4.setVisible(false);
            ps5.setVisible(false);
            ps6.setVisible(false);
            
	// band III
	int y_sub = 135;   
	lab1.setBounds(20,y_sub-23,150,vHeight);    
	text1.setBounds(170,y_sub-25,80,vHeight+3);
	//ulab1.setBounds(250,y_sub-25,40,vHeight);  
	  
	slider1.setBounds(80,y_sub,196,vHeight);
	Panel ps9 = new Panel();
	    ps9.setBackground(Color.cyan);
	    add(ps9);
	    ps9.setBounds(79,y_sub-1,198,vHeight+2);
	    
	Panel ps10 = new Panel();
	    ps10.setBackground(Color.black);
	    add(ps10);
	    ps10.setBounds(78,y_sub-2,200,vHeight+4);
	
        //b1.setBounds(20,y_sub-2,45,20);
	b1.setBounds(15,y_sub-2,buttonWidth,20);
        Panel pb1 = new Panel();
            pb1.setBackground(Color.black);
	    add(pb1);
	    pb1.setBounds(14,y_sub-3,buttonWidth+2,22);
            
	// band IV
	int y_frequency = 185;
	lab4.setBounds(20,y_frequency-23,150,vHeight);
	text4.setBounds(170,y_frequency-25,80,vHeight+3);
	ulab4.setBounds(247,y_frequency-25,40,vHeight);   
	    
	slider2.setBounds(80,y_frequency,196,vHeight);
	Panel ps5 = new Panel();
	    ps5.setBackground(Color.cyan);
	    add(ps5);
	    ps5.setBounds(79,y_frequency-1,198,vHeight+2);
	    
	Panel ps6 = new Panel();
	    ps6.setBackground(Color.black);
	    add(ps6);
	    ps6.setBounds(78,y_frequency-2,200,vHeight+4);
	
        //b2.setBounds(20,y_frequency-2,45,20); // range button
	b2.setBounds(15,y_frequency-2,buttonWidth,20); // range button
        Panel pb2 = new Panel();
            pb2.setBackground(Color.black);
	    add(pb2);
	    pb2.setBounds(14,y_frequency-3,buttonWidth+2,22);
	
	// band V
	int y_material = 227;
        text3.setBounds(20,y_material,70,vHeight+3);
	text7.setBounds(105,y_material,80,vHeight+3);
	text8.setBounds(200,y_material,80,vHeight+3);
	
	ulab5.setBounds(133,y_material-18,50,vHeight);
	ulab6.setBounds(230,y_material-18,50,vHeight);
	
	//  band VI
	int y_update =258;
	bupdate.setBounds(20,y_update,260,20);	
	Panel ps7 = new Panel();
	    ps7.setBackground(Color.cyan);
	    add(ps7);
	    ps7.setBounds(19,y_update-1,262,22);
	    
	Panel ps8 = new Panel();
	    ps8.setBackground(Color.black);
	    add(ps8);
	    ps8.setBounds(18,y_update-2,264,24);

	    
	    
	//Listeners
	bupdate.addActionListener(this);
	
	slider1.addAdjustmentListener(this);
	slider2.addAdjustmentListener(this);
	slider3.addAdjustmentListener(this);
        slider4.addAdjustmentListener(this);
        //slider5.addAdjustmentListener(this);
	        
        diameter_mm = new double[53];
        diameter_mil = new double[53];
        double test = 0.0;
        
        // Calculates diameters for AWG 1/0 to 6/0
            
            test = 5.0* Math.pow(92.0,(36.0+5)/39);
	    diameter_mil[0] = MaestroA.rounder(test,6);  // AWG 6/0
	    diameter_mm[0] = MaestroA.rounder(test*0.0254,6);

            test = 5.0 * Math.pow(92.0,(36.0+4)/39);  
            diameter_mil[1] = MaestroA.rounder(test,6);  // AWG 5/0
	    diameter_mm[1] = MaestroA.rounder(test*0.0254,6);
            
            test = 5.0 * Math.pow(92.0,(36.0+3)/39);  
            diameter_mil[2] = MaestroA.rounder(test,6);  // AWG 4/0
	    diameter_mm[2] = MaestroA.rounder(test*0.0254,6);
            
            test = 5.0 * Math.pow(92.0,(36.0+2)/39);
            diameter_mil[3] = MaestroA.rounder(test,6);  // AWG 3/0
	    diameter_mm[3] = MaestroA.rounder(test*0.0254,6);
            
            test = 5.0 * Math.pow(92.0,(36.0+1)/39);
            diameter_mil[4] = MaestroA.rounder(test,6);  // AWG 2/0
	    diameter_mm[4] = MaestroA.rounder(test*0.0254,6);
            
            test = 5.0 * Math.pow(92.0,(36.0)/39);
	    diameter_mil[5] = MaestroA.rounder(test,6);  // AWG 1/0
	    diameter_mm[5] = MaestroA.rounder(test*0.0254,6);
            
        // Caluclate diameters for AWG 1 - 32
            
        for(int i=0;i<32;i++){
            test = 5.0 * Math.pow(92.0,(36.0-(i+1))/39);
	    diameter_mil[i+6] = MaestroA.rounder(test,6);
	    diameter_mm[i+6] = MaestroA.rounder(test*0.0254,6);
	}

                test = 5.0 * Math.pow(92.0,(36.0-(40))/39);
                diameter_mil[51] = MaestroA.rounder(test,6);
                diameter_mm[51] = MaestroA.rounder(test*0.0254,6);
                //diameter_mil[51] = 3.1;// AWG 40
                //diameter_mm[51] = 0.07874;
        	
                test = 5.0 * Math.pow(92.0,(36.0-(39))/39);
                diameter_mil[50] = MaestroA.rounder(test,6);
                diameter_mm[50] = MaestroA.rounder(test*0.0254,6);
                //diameter_mil[50]= 3.5;// AWG 39
                //diameter_mm[50] = 0.0889;
                
                diameter_mil[49]= 3.94;// Metric 1.0
                diameter_mm[49] = 0.1;
            
                test = 5.0 * Math.pow(92.0,(36.0-(38))/39);
                diameter_mil[48] = MaestroA.rounder(test,6);
                diameter_mm[48] = MaestroA.rounder(test*0.0254,6);
                //diameter_mil[48] = 4.0;// AWG 38
                //diameter_mm[48] = 0.1016;
                
                diameter_mil[47] = 4.41;// Metric 1.12
                diameter_mm[47] = 0.112;
            
                test = 5.0 * Math.pow(92.0,(36.0-(37))/39);
                diameter_mil[46] = MaestroA.rounder(test,6);
                diameter_mm[46] = MaestroA.rounder(test*0.0254,6);
                //diameter_mil[46] = 4.5;// AWG 37
                //diameter_mm[46] = 0.1143;
            
                diameter_mil[45] = 4.92;// Metric 1.25
                diameter_mm[45] = 0.125;
            
                test = 5.0 * Math.pow(92.0,(36.0-(36))/39);
                diameter_mil[44] = MaestroA.rounder(test,6);
                diameter_mm[44] = MaestroA.rounder(test*0.0254,6);
                //diameter_mil[44] = 5.0;// AWG 36
                //diameter_mm[44] = 0.127;
            
                diameter_mil[43] = 5.51;// Metric 1.4
                diameter_mm[43] = 0.140;
            
                test = 5.0 * Math.pow(92.0,(36.0-(35))/39);
                diameter_mil[42] = MaestroA.rounder(test,6);
                diameter_mm[42] = MaestroA.rounder(test*0.0254,6);
                //diameter_mil[42] = 5.6;// AWG 35
                //diameter_mm[42] = 0.14224;
                
                diameter_mil[41] = 6.3;// Metric 1.6 and AWG 34
                diameter_mm[41] = 0.16002;
            
                diameter_mil[40] = 7.09;// Metric 1.8
                diameter_mm[40] = 0.18;
            
                diameter_mil[39] = 5.0 * Math.pow(92.0,(36.0-(33))/39);// AWG 33
                diameter_mm[39] = MaestroA.rounder((diameter_mil[39]*0.0254),8);
                
                diameter_mil[38] = 7.87;// Metric 2.0
                diameter_mm[38] = 0.2;    
}
    
    public void paint(Graphics g){
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        g.clearRect(0,0,getSize().width-1,getSize().height-1);
        
        g.setFont(normalfont);
	FontMetrics fm;
        fm = g.getFontMetrics();
        
	g.setColor(bgcolor.darker());
	g.fillRect(0,getSize().height-2,getSize().width,2);
	g.fillRect(getSize().width-2,0,2,getSize().height);
	g.setColor(bgcolor.brighter());
	g.fillRect(0,0,2,getSize().height-1);
	g.fillRect(0,0,getSize().width-2,2);
	int vPosInit = 30, vPos, dvPos = 2, vHeight = 20; 
	vPos = vPosInit+9*vHeight+8*dvPos;
	g.setColor(Color.red);    
	
	//MaestroG.subscripterSymFirst2NEW("\u03b5","r","",g,14,32,vPos-5);	
	MaestroG.subscripterSymFirst2("\u03b5","r","",g,14,32,vPos-5);	
	MaestroG.subscripterSymFirst2("\u03c3","","",g,14,120,vPos-5);	
	MaestroG.subscripterSymFirst2("\u03c3","c","",g,14,210,vPos-5);

        if (MaestroG.useBiggerFont) {
            g.setFont(state.ttfFont.deriveFont(14));
        } else {
            g.setFont(state.ttfFont.deriveFont(12));
        }
        fm = g.getFontMetrics();
        
	g.setColor(Color.black);    
        //g.drawString("[mm]",252,42);
        g.drawString("[mm]",252,72);
        g.drawString("[mm]",252,123);
	
        int x1 = 120; int y1 = 97; int xoffset = 30;
            
        //g.setColor(Color.red.darker());
        //g.drawLine(10,y1+5,getSize().width-10,y1+5);
        
    }
    
    public void actionPerformed(ActionEvent evt){
        
        //***********
        if(evt.getSource()==bupdate){
            //*********
            try{ if(Double.valueOf(text1.getText()).doubleValue()<=state.a_maximum &&
                    Double.valueOf(text1.getText()).doubleValue()>=state.a_minimum){
                    state.a=Double.valueOf(text1.getText()).doubleValue();
                    slider1.setValue((int)(ScrollMax*(state.a-state.a_minimum)
                                           /(state.a_maximum-state.a_minimum)));
                }
                else if(Double.valueOf(text1.getText()).doubleValue()>state.a_maximum){
                    state.a = state.a_maximum;
                    text1.setText(""+state.a_maximum);
                    slider1.setValue(ScrollMax);
                }
                else if(Double.valueOf(text1.getText()).doubleValue()<state.a_minimum){
                    state.a = state.a_minimum;
                    text1.setText(""+state.a_minimum);
                    slider1.setValue(0);
                }
                else if(Double.valueOf(text1.getText()).doubleValue()<state.w){
                    state.a =state.w;
                    text1.setText(""+state.a);
                    slider1.setValue((int)(ScrollMax*(state.a-state.a_minimum)
                                           /(state.a_maximum-state.a_minimum)));
                }
            }
            catch(NumberFormatException e){
                state.a =  0.0;
            } 
            
            try{if(Double.valueOf(text6.getText()).doubleValue()<=state.w_maximum &&
                   Double.valueOf(text6.getText()).doubleValue()>=state.w_minimum){
                    state.w=Double.valueOf(text6.getText()).doubleValue();
                    slider3.setValue((int)(ScrollMax*(state.w-state.w_minimum)/
                                           (state.w_maximum-state.w_minimum)));
                }
                else if(Double.valueOf(text6.getText()).doubleValue()>state.w_maximum){
                    state.w = state.w_maximum;
                    text6.setText(""+state.w_maximum);
                    slider3.setValue(ScrollMax);
                }
                else if(Double.valueOf(text6.getText()).doubleValue()<state.w_minimum){
                    state.w = state.w_minimum;
                    text6.setText(""+state.w_minimum);
                    slider3.setValue(0);
                }
                
            }
            catch(NumberFormatException e){
                state.w = 0.0;
                
            }
            	    
	    try{if(Double.valueOf(text3.getText()).doubleValue()>=1.0){
		    state.epsilon_r=Double.valueOf(text3.getText()).doubleValue();
		}
		else{
		    state.epsilon_r=1.0;
		    text3.setText(""+state.epsilon_r);
		}
	    }
	    catch(NumberFormatException e){
                state.epsilon_r = 1.0;
	    }  
	    
	    
	    try{if(Double.valueOf(text7.getText()).doubleValue()>=0.0){
		    state.sigma2=Double.valueOf(text7.getText()).doubleValue();
		    //state.loss_tangent=Double.valueOf(text7.getText()).doubleValue();
		}
		else{
		    state.sigma2=0.0;
		    text7.setText(""+state.sigma2);
		    //state.loss_tangent=0.0;
		    //text7.setText(""+state.loss_tangent);
		}
	    }
	    catch(NumberFormatException e){
                state.sigma2 = 0.0;
                //state.loss_tangent = 0.0;
	    }  
	    try{if(Double.valueOf(text8.getText()).doubleValue()>=0.0){
		    //state.rho_metal=Double.valueOf(text8.getText()).doubleValue();
		    state.sigma_metal=Double.valueOf(text8.getText()).doubleValue();
                    state.rho_metal = 1.0/state.sigma_metal;
		}
		else{
		    //state.rho_metal=0.0;
		    //text8.setText(""+state.rho_metal);
		    state.sigma_metal=1.0E-99;
                    state.rho_metal=1.0/state.sigma_metal;
		}
	    }
	    catch(NumberFormatException e){
                //state.rho_metal = 0.0;
                state.sigma_metal = 0.0;
	    }
            
	    try{if(Double.valueOf(text4.getText()).doubleValue()<=state.frequency_maximum &&
                   Double.valueOf(text4.getText()).doubleValue()>=state.frequency_minimum){
		    state.frequency=Double.valueOf(text4.getText()).doubleValue();
		    slider2.setValue((int)(ScrollMax*(state.frequency-state.frequency_minimum)/
                                           (state.frequency_maximum-state.frequency_minimum)));
		}
		else if(Double.valueOf(text4.getText()).doubleValue()>state.frequency_maximum){
		    state.frequency = state.frequency_maximum;
		    text4.setText(""+state.frequency_maximum);
		    slider2.setValue(ScrollMax);
		}
		else if(Double.valueOf(text4.getText()).doubleValue()<state.frequency_minimum){
		    state.frequency = state.frequency_minimum;
		    text4.setText(""+state.frequency_minimum);
		    slider2.setValue(0);
		}
	    }
	    catch(NumberFormatException e){
                state.frequency = 0.0; 
	    }
            
	    
        }
        //************************
        state.ignition();
    }//End of actionPerformed()
    




    public void adjustmentValueChanged(AdjustmentEvent evt){
	if(evt.getSource()==slider2){
	    if(slider2.getValue()>=ScrollMax){
		state.frequency=state.frequency_maximum;
		slider2.setValue((int)(ScrollMax*(state.frequency-state.frequency_minimum)
						    /(state.frequency_maximum-state.frequency_minimum)));
	    }
	    else{
		state.frequency = state.frequency_minimum + 
		    (state.frequency_maximum-state.frequency_minimum)*slider2.getValue()/ScrollMax;
	    }
	    
	    text4.setText(""+state.frequency);
	    state.ignition();
	    
	}
	//-----------------------------------------
	else if(evt.getSource()==slider1){
	  if(!state.IsMilsOn){
	    if(slider1.getValue()>=ScrollMax){
		    state.a=state.a_maximum;
		    slider1.setValue((int)(ScrollMax*(state.a-state.a_minimum)
						    /(state.a_maximum-state.a_minimum)));
	    }
	    else{
	    state.a  = state.a_minimum + 
		(state.a_maximum-state.a_minimum)*slider1.getValue()/ScrollMax;
	    }
	    text1.setText(""+MaestroA.rounder(state.a,7));
	    state.ignition();
	    
	    
	    if(state.a <= state.w){
		    state.a =state.w;
		    
		    slider1.setValue((int)(ScrollMax*(state.a-state.a_minimum)
						    /(state.a_maximum-state.a_minimum)));
		    text1.setText(""+MaestroA.rounder(state.a,7));
		    state.ignition();
		    
	    }
	
	    
	  }
	  else{
	    if(slider1.getValue()>=ScrollMax){
		    state.a_mil=state.a_mil_maximum;
		    slider1.setValue((int)(ScrollMax*(state.a_mil-state.a_mil_minimum)
						    /(state.a_mil_maximum-state.a_mil_minimum)));
	    }
	    else{
	    state.a_mil  = state.a_mil_minimum + 
		(state.a_mil_maximum-state.a_mil_minimum)*slider1.getValue()/ScrollMax;
	    }
	    text1.setText(""+MaestroA.rounder(state.a_mil,7));
	    state.ignition();
	    
	    
	    if(state.a_mil<=state.w_mil){
		    state.a_mil =state.w_mil;
		    
		    slider1.setValue((int)(ScrollMax*(state.a_mil-state.a_mil_minimum)
						    /(state.a_mil_maximum-state.a_mil_minimum)));
		    text1.setText(""+MaestroA.rounder(state.a_mil,7));
		    state.ignition();
		    
	    }
	  }
	}
	//----------------------------------------------------------------------
	
	else if(evt.getSource()==slider3){
	    state.WG = 0;
	  if(!state.IsMilsOn){
	    if(slider3.getValue()>=ScrollMax){
		    state.w=state.w_maximum;
		    slider3.setValue((int)(ScrollMax*(state.w-state.w_minimum)
						    /(state.w_maximum-state.w_minimum)));
	    }
	    else{
		state.w = state.w_minimum + 
		    (state.w_maximum-state.w_minimum)*slider3.getValue()/ScrollMax;
	    }
	
	    text6.setText(""+MaestroA.rounder(state.w,7));
	    state.ignition();
	    
	    if(state.w > state.a){
		    state.w =state.a;
		    
		    slider3.setValue((int)(ScrollMax*(state.w-state.w_minimum)
						    /(state.w_maximum-state.w_minimum)));
		    text6.setText(""+MaestroA.rounder(state.w,7));
		    state.ignition();
		    
	    }
	    
	  }
	  else{
	    if(slider3.getValue()>=ScrollMax){
		    state.w_mil=state.w_mil_maximum;
		    slider3.setValue((int)(ScrollMax*(state.w_mil-state.w_mil_minimum)
						    /(state.w_mil_maximum-state.w_mil_minimum)));
	    }
	    else{
		state.w_mil = state.w_mil_minimum + 
		    (state.w_mil_maximum-state.w_mil_minimum)*slider3.getValue()/ScrollMax;
	    }
	
	    text6.setText(""+MaestroA.rounder(state.w_mil,7));
	    state.ignition();
	    
	    if(state.w_mil > state.a_mil){
		    state.w_mil =state.a_mil;
		    
		    slider3.setValue((int)(ScrollMax*(state.w_mil-state.w_mil_minimum)
						    /(state.w_mil_maximum-state.w_mil_minimum)));
		    text6.setText(""+MaestroA.rounder(state.w_mil,7));
		    state.ignition();
		    
	    }
	  }
	}
        //------------------------------------------------------------------------------
        
        else if(evt.getSource()==slider4){
            int slider_ref ;
            slider_ref = slider4.getValue();
            
            state.w_mil = diameter_mil[slider4.getValue()];
            state.w = diameter_mm[slider4.getValue()];
            state.WG = slider4.getValue()+1;
            
            while(state.w > state.a){
                slider_ref = slider_ref + 1;
                slider4.setValue(slider_ref);
                state.w_mil = diameter_mil[slider4.getValue()];
                state.w = diameter_mm[slider4.getValue()];
                state.WG = slider4.getValue()+1;
            }
            
            if(state.IsMilsOn){  
                text6.setText(""+MaestroA.rounder(state.w_mil,7));
            }
            else{
                text6.setText(""+MaestroA.rounder(state.w,7));
            }
            
            
            
	}
        
        //---------------------------------------------
	/*
        else if(evt.getSource()==slider5){
	  if(!state.IsMilsOn){
	    if(slider5.getValue()>=ScrollMax){
		    state.lineLength=state.lineLengthMAX;
		    slider5.setValue((int)(ScrollMax*(state.lineLength-state.lineLengthMIN)
						    /(state.lineLengthMAX-state.lineLengthMIN)));
	    }
	    else{
		state.lineLength = state.lineLengthMIN + 
		    (state.lineLengthMAX - state.lineLengthMIN)*slider5.getValue()/ScrollMax;
	    }
	
	    text5.setText(""+MaestroA.rounder(state.lineLength,7));
	    state.ignition();	
	    
	  }
	  else{
	    if(slider5.getValue()>=ScrollMax){
		    state.lineLength_mil=state.lineLengthMAX_mil;
		    slider5.setValue((int)(ScrollMax*(state.lineLength_mil-state.lineLengthMIN_mil)
						    /(state.lineLengthMAX_mil-state.lineLengthMIN_mil)));
	    }
	    else{
		state.lineLength_mil = state.lineLengthMIN_mil + 
		    (state.lineLengthMAX_mil - state.lineLengthMIN_mil)*slider5.getValue()/ScrollMax;
	    }
	    text5.setText(""+MaestroA.rounder(state.lineLength_mil,7));
	    state.ignition();
	    
	  }
	}
	*/
    }
    
}


