//TransLoadPanel

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.lang.*;


public class TransShuntPanel extends PC implements ItemListener, ActionListener, AdjustmentListener{
    public Checkbox c1, c2;
    protected CheckboxGroup cgrp;
    private Trans_State state;
    public Scrollbar slider;
    private Label labela, labelb;
    //public Button b1;
    //private static final Color bgcolor = new Color(216,216,191);
    private static final Color tinta = new Color(236,236,236);
    private static final Color bgcolor = new Color(236,236,236);
    protected static final Font labfont = new Font("SanSerif",Font.PLAIN,12);
    protected static final Font titfont = new Font("SanSerif",Font.PLAIN,14);
	
    //private static final Color bgcolor = new Color(200,200,200);
    
    public TransShuntPanel(String titulo, String[] nome, String[] unidade, Trans_State state){
	super(titulo,nome,unidade);
	setLayout(null);
	setBackground(bgcolor);
	this.state = state;
        
        //button_update = new Button("Update");
	//button_update.setBackground(bgcolor);
	//add(button_update);
        
        labela = new Label("no shunt",Label.CENTER);
        labela.setFont(labfont);
        labela.setForeground(Color.blue.darker());
        labela.setBounds(235,82,60,15);
        labelb = new Label("selected",Label.CENTER);
        labelb.setFont(labfont);
        labelb.setForeground(Color.blue.darker());
        labelb.setBounds(235,95,60,15);
        add(labela); add(labelb);
        
	cgrp = new CheckboxGroup();
	c1 = new Checkbox("Impedance",cgrp,true);
	c2 = new Checkbox("Admittance",cgrp,false);
	add(c1);
	add(c2);
	titlelabel.setBounds(15,5,150,20);
        titlelabel.setForeground(Color.red.darker());
        titlelabel.setFont(titfont);
	lab1[0].setBounds(25,33,10,12);
	text1[0].setBounds(55,30,80,20);
	
	lab2[0].setBounds(145,30,20,20);
	text2[0].setBounds(170,30,80,20);
	
	lab3[0].setBounds(255,30,45,20);
	c1.setBounds(55,60,100,20);
	c1.setBackground(bgcolor);
	c2.setBounds(170,60,100,20);
	c2.setBackground(bgcolor);
	b1.setBounds(120,110,70,20);
        b1.setBackground(bgcolor);
	
	text1[0].setText(""+state.ZS.Real());
	text2[0].setText(""+state.ZS.Imaginary());
	
        slider = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,11);	
        slider.setBounds(80,85,150,15);
        add(slider);
        
        Panel p0 = new Panel();
	    p0.setBackground(Color.cyan);
	    add(p0);
	    p0.setBounds(79,84,152,17);
	    
        Panel p00 = new Panel();
	    p00.setBackground(Color.black);
	    add(p00);
	    p00.setBounds(78,83,154,19);
	    
        
	//Listeners
        b1.addActionListener(this);
	c1.addItemListener(this);
	c2.addItemListener(this);
        slider.addAdjustmentListener(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.black);	
	      
	    MaestroG.subscripter("   ","S","=",g,12,25,45);
            g.setColor(Color.red.darker());
            g.drawRect(52,27,84,24);
            g.drawRect(167,27,84,24);
            g.drawRect(117,107,74,24);
            
            if(state.ShuntPlace < 1){
                //g.drawString("no shunt",10,90);
                //g.drawString("selected",10,105);
            }
            else if(state.ShuntPlace >0){
                //g.drawString("position",10,90);
                //g.drawString("# "+state.ShuntPlace,10,105);
                
            }
    }
    
    public void actionPerformed(ActionEvent evt){
        if(evt.getSource()==b1){
            
        }
    }
    
    public void itemStateChanged(ItemEvent evt){
	if(evt.getSource()==c1){
	    lab1[0].setText("Z");
	    lab3[0].setText("[ \u03a9 ]");
	    text1[0].setText(""+state.ZS.Real());
	    text2[0].setText(""+state.ZS.Imaginary());
	    state.is_Load_Ztype = true;
            
	}
	
	else if(evt.getSource()==c2){
	    lab1[0].setText("Y");
	    lab3[0].setText("[ S ]");
	    text1[0].setText(""+state.YS.Real());
	    text2[0].setText(""+state.YS.Imaginary());
	    state.is_Load_Ztype = false;
            
	}
    }
    public void adjustmentValueChanged(AdjustmentEvent evt){
	  if(evt.getSource()==slider){
                if(slider.getValue()>0){
                    labela.setText("position");
                    labelb.setText("# "+slider.getValue());
                }
                else{
                    labela.setText("no shunt");
                    labelb.setText("selected");
                }
                repaint();
	  }
	}
}
