//NewGuideInputPanel2.java
import java.awt.*;
import java.awt.event.*;

public class NewGuideInputPanel2 extends Panel implements ActionListener {
    private NewGuide_State state;
    private static final Color bgcolor = new Color(236,236,221);
    private Font labfont=new Font("SanSerif",Font.PLAIN,12);
    private Font normalfont = new Font("SanSerif",Font.PLAIN,14);
    private Font labelfont = new Font("Serif",Font.PLAIN,14);
    
    public int offset = 20;
    private Label titlelabel;
    
    private Label lab1, lab3, lab3b, lab3c, lab4, lab2;
    private Label ulab1, ulab2, ulab3, ulab4;
    public TextField text1, text2, text4;
   
    public  Button ground1, ground2, ground3, ground4, ground5, ground6;
    public  Button bupdate;
  
    public NewGuideInputPanel2(NewGuide_State state){
	super();
	setLayout(null);
	setBackground(bgcolor);
	this.state = state;
        
        labfont=new Font("SanSerif",Font.PLAIN,state.font12);
        normalfont = new Font("SanSerif",Font.PLAIN,state.font14);
        labelfont = new Font("Serif",Font.PLAIN,state.font14);
        
        offset = state.s20;
        
        titlelabel = new Label("Input",Label.LEFT);
	titlelabel.setFont(new Font("SanSerif",Font.BOLD,state.font15));
        
        ground1 = new Button("Perfect Conductor");
        ground2 = new Button("Dry Poor Ground");
        ground3 = new Button("Average Ground");
        ground4 = new Button("Wet Good Ground");
        ground5 = new Button("Fresh Water");
        ground6 = new Button("Sea Water");
        
        add(titlelabel);
        add(ground1);
        add(ground2);
        add(ground3);
        add(ground4);
        add(ground5);
        add(ground6);
        
        titlelabel.setBounds(state.s10,state.s5,state.s150,state.s18);
	ground1.setBounds(state.s10, state.s50, state.s135, state.s30);
        ground2.setBounds(state.s10, state.s90, state.s135, state.s30);
        ground3.setBounds(state.s10, state.s130, state.s135, state.s30);
        ground4.setBounds(state.s10, state.s170, state.s135, state.s30);
        ground5.setBounds(state.s10, state.s200+state.s10, state.s135, state.s30);
        ground6.setBounds(state.s10, state.s200+state.s50, state.s135, state.s30);
        //======================================================================
        ground1.setBackground(Color.white);
        ground2.setBackground(Color.white);
        ground3.setBackground(Color.white);
        ground4.setBackground(Color.white);
        ground5.setBackground(Color.white);
        ground6.setBackground(Color.white);
        
        ground1.setFont(labfont);
        ground2.setFont(labfont);
        ground3.setFont(labfont);
        ground4.setFont(labfont);
        ground5.setFont(labfont);
        ground6.setFont(labfont);
        
        Panel g1 = new Panel();
	    g1.setBackground(Color.black);
	    add(g1);
	    // CHANGE ==========================================================
            g1.setBounds(state.s10-1, state.s50-1, state.s135+2, state.s30+2);
            //==================================================================
        Panel g2 = new Panel();
	    g2.setBackground(Color.black);
	    add(g2);
	    // CHANGE ==========================================================
            g2.setBounds(state.s10-1, state.s90-1, state.s135+2, state.s30+2);
            //==================================================================
        Panel g3 = new Panel();
	    g3.setBackground(Color.black);
	    add(g3);
	    // CHANGE ==========================================================
            g3.setBounds(state.s10-1, state.s130-1, state.s135+2, state.s30+2);
            //==================================================================
        Panel g4 = new Panel();
	    g4.setBackground(Color.black);
	    add(g4);
	    // CHANGE ==========================================================
            g4.setBounds(state.s10-1, state.s170-1, state.s135+2, state.s30+2);
            //==================================================================
        Panel g5 = new Panel();
	    g5.setBackground(Color.black);
	    add(g5);
	    // CHANGE ==========================================================
            g5.setBounds(state.s10-1, state.s200+state.s10-1, state.s135+2, state.s30+2);
            //==================================================================
        Panel g6 = new Panel();
	    g6.setBackground(Color.black);
	    add(g6);
	    // CHANGE ==========================================================
            g6.setBounds(state.s10-1, state.s200+state.s50-1, state.s135+2, state.s30+2);
            //==================================================================
        
            ground1.addActionListener(this);
            ground2.addActionListener(this);
            ground3.addActionListener(this);
            ground4.addActionListener(this);
            ground5.addActionListener(this);
            ground6.addActionListener(this);
    }
    
    @Override
    public void paint(Graphics g){
	
	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);
        
        g.setColor(Color.yellow);
        if(state.GroundChoose == 1){
            g.fillRect(state.s155, state.s43, state.s130, state.s40);
        }
        else if(state.GroundChoose == 2){
            g.fillRect(state.s155, state.s83, state.s130, state.s40);
        }
        else if(state.GroundChoose == 3){
            g.fillRect(state.s155, state.s123, state.s130, state.s40);
        }
        else if(state.GroundChoose == 4){
            g.fillRect(state.s155, state.s163, state.s130, state.s40);
        }
        else if(state.GroundChoose == 5){
            g.fillRect(state.s155, state.s200+state.s3, state.s130, state.s40);
        }
        else if(state.GroundChoose == 6){
            g.fillRect(state.s155, state.s200+state.s43, state.s130, state.s40);  
        }
        
        g.setColor(Color.red.darker());
        MaestroG.superscripter("\u03c3 \u2192 ","","\u221e  [S/m]", g, state.font13, state.s160, state.s60);
        g.setColor(Color.blue.darker());
        MaestroG.superscripter("\u03c3 = 10","-3","  [S/m]", g, state.font13, state.s160, state.s100);
        MaestroG.subscripter("\u03b5","r"," = 5.0", g, state.font14, state.s160, state.s115);
        g.setColor(Color.red.darker());
        MaestroG.superscripter("\u03c3 = 5 \u00b7 10","-3","  [S/m]", g, state.font13, state.s160, state.s140);
        MaestroG.subscripter("\u03b5","r"," = 15.0", g, state.font14, state.s160, state.s155);
        g.setColor(Color.blue.darker());
        MaestroG.superscripter("\u03c3 = 2 \u00b7 10","-2","  [S/m]", g, state.font13, state.s160, state.s180);
        MaestroG.subscripter("\u03b5","r"," = 30.0", g, state.font14, state.s160, state.s195);
        g.setColor(Color.red.darker());
        MaestroG.superscripter("\u03c3 = 10","-2","  [S/m]", g, state.font13, state.s160, state.s200+state.s20);
        MaestroG.subscripter("\u03b5","r"," = 81.0", g, state.font14, state.s160, state.s200+state.s35);
        g.setColor(Color.blue.darker());
        MaestroG.superscripter("\u03c3 = 5.0","","  [S/m]", g, state.font13, state.s160, state.s200+state.s60);
        MaestroG.subscripter("\u03b5","r"," = 81.0", g, state.font14, state.s160, state.s200+state.s75);
    }
    
    public void actionPerformed(ActionEvent evt){
        if(evt.getSource()==ground1){
            state.sigma = 1.0E130;
            state.epsilon_r = 1.0;
            state.GroundChoose = 1;
        }
        if(evt.getSource()==ground2){
            state.sigma = 1.0E-3;
            state.epsilon_r = 5.0;
            state.GroundChoose = 2;
        }
        if(evt.getSource()==ground3){
            state.sigma = 5.0E-3;
            state.epsilon_r = 15.0;
            state.GroundChoose = 3;
        }
        if(evt.getSource()==ground4){
            state.sigma = 2.0E-2;
            state.epsilon_r = 30.0;
            state.GroundChoose = 4;
        }
        if(evt.getSource()==ground5){
            state.sigma = 1.0E-2;
            state.epsilon_r = 81.0;
            state.GroundChoose = 5;
        }
        if(evt.getSource()==ground6){
            state.sigma = 5.0;
            state.epsilon_r = 81.0;
            state.GroundChoose = 6;
        }
	state.ignition();
        repaint();
    }    
    
}


