//LinePanel.java
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 labcolor = Color.red;
    protected static final Font labfont=TheFonts.sanSerif12;
    protected static final Font titlefont=TheFonts.bold12;
    private static final Label titlelabel=new Label("Choose length units",Label.CENTER);
    private static final Label lengthlabel=new Label("(press Update to activate choice)",Label.CENTER);
    public boolean Is_Millimeter;
    
    private static final Color bgcolor = new Color(236,236,236);
    private static final Color tinta = new Color(236,236,236);
	
    Checkbox c1, c2;
    Checkbox c3, c4;
    CheckboxGroup cgrp;
    CheckboxGroup cgrp2;
    PR3 lowpanel;
    Trans_State state;
    TransSlidePanel slidepanel;
    
    String arg1A[]={"","",""};
    String arg2A[]={"  [ \u03a9 ]","","  [ mm ]"};
       
    CircuitCanvas ccan;
    
    public LinePanel(Trans_State state){
	setBackground(bgcolor);
	this.state = state;
	setLayout(null);
	//add(titlelabel);
	//add(lengthlabel);
	titlelabel.setBounds(10,165,145,20);
	titlelabel.setFont(titlefont);
	lengthlabel.setBounds(20,185,280,20);
	lengthlabel.setFont(labfont);
	
	cgrp2 = new CheckboxGroup();
	
	c3 = new Checkbox("[ mm ]",cgrp2,true);
	c4 = new Checkbox("[ mils ]",cgrp2,false);
	Is_Millimeter = true;
	
	c3.setFont(labfont); c4.setFont(labfont);
	
	c3.setBackground(bgcolor);
	c4.setBackground(bgcolor);
	
	//add(c3);
	//add(c4);
	
	c3.setBounds(175,165,60,20);
	c4.setBounds(240,165,60,20);
	
    	{	    
	    lowpanel = new PR3("Set Line Parameters",arg1A,arg2A);
	    add(lowpanel);
	    lowpanel.setBounds(10,10,290,200);
	    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,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);
    }
    
    public void itemStateChanged(ItemEvent evt){
	
	if (evt.getSource() ==c3){
	    Is_Millimeter = true;
	    state.Is_Millimeter = true;
	    arg2A[2] = "  [ mm ] ";
	    lowpanel.setStrings(arg1A,arg2A);
	    lowpanel.repaint();
	}
	else if (evt.getSource() ==c4){
	    Is_Millimeter = false;
	    state.Is_Millimeter = false;
	    arg2A[2] = "  [ mils ] ";
	    lowpanel.setStrings(arg1A,arg2A);
	    lowpanel.repaint();
	}   
    }
    
    public void actionPerformed(ActionEvent evt){
	double tempalpha;
	if(evt.getSource() == lowpanel.b1){
	    state.lineZ0 = lowpanel.getValue(0);
	    //state.frequency = lowpanel.getValue(1);
	    state.epsilon_r = lowpanel.getValue(1);
	    state.lineLength = lowpanel.getValue(2);
	}	
    }
}
