//LinePanel.java
/* A Java class for
 * LineImpedance.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.applet.*;
import java.lang.*;


public class LinePanel extends Panel implements ActionListener,ItemListener{
    //protected static final Color bgcolor = Color.lightGray;
    protected static final Color labcolor = Color.red;
    protected static final Font labfont=TheFonts.sanSerif12;
    protected static final Font titlefont=TheFonts.bold12;
    protected static final Font labfont10=TheFonts.sanSerif10;
    private static final Label titlelabel=new Label("",Label.CENTER);
    private static final Label lengthlabel=new Label("Choose length units:",Label.CENTER);
    private static final Label choicelabel=new Label("(press Update to activate choice)",Label.CENTER);
    public boolean Is_Wavelength;
    
    //private static final Color bgcolor = new Color(216,216,191);
    private static final Color bgcolor = new Color(236,236,221);
    private static final Color tinta = new Color(236,236,221);
    
    public Checkbox c1, c2;
    protected CheckboxGroup ceps;
        
    Checkbox c3, c4;
    CheckboxGroup cgrp2;
    PR lowpanel;
    Trans_State state;
    TransSlidePanel slidepanel;
    SmithPanel sp;
    
    String arg1A[]={"Char. Imp. Zo  = ",
		"Rel. Permittivity \u03b5  =  ","Total Length  L  =  "};
    String arg2A[]={"  [ \u03a9 ]","","  [ m ]"};

    CircuitCanvas ccan;
    public LinePanel(Trans_State state){
	setBackground(bgcolor);
	this.state = state;
	setLayout(null);
	//add(titlelabel);
	add(lengthlabel);
	add(choicelabel);
	//titlelabel.setBounds(10,6,45,20);
	titlelabel.setFont(titlefont);
	//lengthlabel.setBounds(30,15,120,16);
	lengthlabel.setBounds(10,15,140,16);
	lengthlabel.setFont(labfont);
	choicelabel.setBounds(20,40,270,16);
	choicelabel.setFont(labfont);
	choicelabel.setForeground(Color.red);
	
	cgrp2 = new CheckboxGroup();
	
	c3 = new Checkbox("[ \u03bb ]",cgrp2,false);
        c3.setFont(labfont);
	c4 = new Checkbox("[ m ]",cgrp2,true);
        c4.setFont(labfont);
	Is_Wavelength = false;
	
	c3.setBackground(bgcolor);
	c4.setBackground(bgcolor);
	
	add(c3);
	add(c4);
	
        // CHANGE ==============================================================
	//c3.setBounds(165,15,50,16);
	//c4.setBounds(230,15,50,16);
        c3.setBounds(165,15,60,16);
	c4.setBounds(230,15,60,16);
        //======================================================================
        
        ceps = new CheckboxGroup();
        c1 = new Checkbox("Exact speed of light",ceps,false);
        c1.setFont(labfont10);
        c2 = new Checkbox("Approximate speed of light",ceps,true);
        c2.setFont(labfont10);
        //add(c1);
        //add(c2);
        
        c1.setBounds(10,23,130,16);
	c2.setBounds(10,40,180,16);
	        
    	{	    
	    lowpanel = new PR("Set Line",arg1A,arg2A);
	    add(lowpanel);
	    
	    lowpanel.setBounds(10,75,290,190);
	    lowpanel.setValue(state.lineZ0,0);//characteristic impedance
	    //lowpanel.setValue(state.frequency,1);//frequency
	    lowpanel.setValue(state.epsilon_r,1);//relative dielectric constant
	    lowpanel.setValue(state.lineLength_meters,2);//total length
	}
	
	//Listeners
	c3.addItemListener(this);
	c4.addItemListener(this);
	
	lowpanel.b1.addActionListener(this);	
    }
    
    public void paint(Graphics g){
	    g.clearRect(0,0,getSize().width,getSize().height);
	    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);
            
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            //g.setColor(Color.black);
            //MaestroG.superscripter("( c = 2.997924... x 10","8","m/s )",g,11,145,35);
            //MaestroG.superscripter("( c = 3 x 10","8","m/s )",g,11,195,52);
            //g.setColor(Color.gray);
            //g.drawLine(10,20,getSize().width-10,20);
            //g.drawLine(10,57,getSize().width-10,57);
    }
    
    public void itemStateChanged(ItemEvent evt){
	
	if (evt.getSource() ==c3){
	    Is_Wavelength = true;
	    arg2A[2] = " [ \u03bb ] ";
	    lowpanel.setStrings(arg1A,arg2A);
	    state.Is_Wavelength = true;
	}
	else if (evt.getSource() ==c4){
	    Is_Wavelength = false;
	    arg2A[2] = " [ m ] ";
	    lowpanel.setStrings(arg1A,arg2A);
	    state.Is_Wavelength = false;
	}   
	
    }
    
    public void actionPerformed(ActionEvent evt){
	double tempalpha;
	
    }
}
