//TransLoadPanel

/* 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 TransLoadPanel extends PC implements ItemListener{
    public Checkbox c1, c2;
    public Checkbox c3, c4;
    
    protected CheckboxGroup cgrp;
    
    private Trans_State state;
    //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 TransLoadPanel(String titulo, String[] nome, String[] unidade,Trans_State state){
	super(titulo,nome,unidade);
	setLayout(null);

        setFont(TheFonts.sanSerif14);

	this.state = state;
	cgrp = new CheckboxGroup();
	c1 = new Checkbox("Impedance",cgrp,true);
	c2 = new Checkbox("Admittance",cgrp,false);
	add(c1);
	add(c2);
	
        titlelabel.setBounds(5,82,300,30);
	lab1[0].setBounds(20,134,11,25);
	text1[0].setBounds(60,137,80,20);
	
	lab2[0].setBounds(148,134,20,25);
	text2[0].setBounds(173,137,80,20);
	
	//lab3[0].setBounds(260,134,30,25);
	lab3[0].setBounds(260,134,45,25);
	c1.setBounds(55,184,110,25);
	c1.setBackground(bgcolor);
	c2.setBounds(170,184,110,25);
	c2.setBackground(bgcolor);
	
        b1.setBounds(105,236,100,20);
        
	//Listeners
	c1.addItemListener(this);
	c2.addItemListener(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);
    
	    g.setColor(Color.red.darker());
            g.drawRect(57,134,85,26);
            g.drawRect(170,134,85,26);
            g.drawRect(102,233,105,25);
            g.setColor(Color.black);
            g.drawString("L",32,156);
            g.drawString("=",45,151);
            
    }
    
    public void itemStateChanged(ItemEvent evt){
	if(evt.getSource()==c1){
	    lab1[0].setText("Z");
	    lab3[0].setText("  [ \u03a9 ]");
	    text1[0].setText(""+state.ZL.Real());
	    text2[0].setText(""+state.ZL.Imaginary());
	}
	
	else if(evt.getSource()==c2){
	    lab1[0].setText("Y");
	    lab3[0].setText("  [ S ]");
	    text1[0].setText(""+state.YL.Real());
	    text2[0].setText(""+state.YL.Imaginary());
	}
    }
}
