//Trans_MultiGraphPanelA.java

import java.net.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;


public class Trans_MultiGraphPanelB extends Panel{
    //private static final Color bgcolor = new Color(216,216,191);
    private  static final Color bgcolor = new Color(255,255,255);
    private static final Color tinta2 = new Color(216,216,191); // kaki
    //private  static final Color bgcolor = new Color(161,220,220);
    private static final Color tinta = new Color(236,236,236);
    private static final Font titlefont = TheFonts.bold14;
    private static final Font labfont = TheFonts.sanSerif11;
    private Label titlelabel, selectlabel;   
    private String titulo;
    public Choice c1;
    TransGraphCanvas tgc1, tgc2;
    TransGraphCanvas2 tgc3, tgc4;

    public Trans_MultiGraphPanelB(String titulo){
	super();
	this.titulo=titulo;
	setLayout(null);
	setBackground(bgcolor);
	 
	c1 = new Choice();
	
	c1.addItem(" Standing Wave Pattern - | V | & | I |");
	c1.addItem(" Voltage Phasor");
	c1.addItem(" Current Phasor");
	c1.addItem(" Impedance");
	c1.addItem(" Admittance");
	c1.addItem(" Reflection Coefficient");
	c1.setBackground(tinta);
	c1.setForeground(Color.black);
	c1.setFont(TheFonts.sanSerif11);
	titlelabel = new Label(titulo,Label.LEFT);
	titlelabel.setFont(titlefont);
	
	selectlabel = new Label("click to select plot",Label.CENTER);
	selectlabel.setFont(labfont);
	selectlabel.setBackground(bgcolor);
	selectlabel.setForeground(Color.blue);
	
	
	tgc1 = new TransGraphCanvas();
	tgc2 = new TransGraphCanvas();
	tgc3 = new TransGraphCanvas2();
	tgc4 = new TransGraphCanvas2();
	//add(titlelabel);
	//add(selectlabel);
	//add(c1);
	add(tgc1);
	add(tgc2);
	//add(tgc3);
	//add(tgc4);
	titlelabel.setBounds(5,0,200,20);
	//selectlabel.setBounds(200,30,100,25);
        selectlabel.setBounds(200,30,100,25);
	c1.setBounds(5,30,195,25);
	//tgc1.setBounds(5,60,300,110);
	//tgc2.setBounds(5,175,300,110);
	
	tgc1.setBounds(4,4,270,128);
	tgc2.setBounds(4,136,270,128);
	tgc3.setBounds(4,4,270,128);
	tgc4.setBounds(4,136,270,128);
	
	Panel pgraph2 = new Panel();
	    pgraph2.setBackground(Color.black);
	    add(pgraph2);
	    pgraph2.setBounds(3,3,272,130);
	   
	Panel pgraph4 = new Panel();
	    pgraph4.setBackground(Color.black);
	    add(pgraph4);
	    pgraph4.setBounds(3,135,272,130);
	    
    }	
    
    public void paint(Graphics g){
	g.setColor(Color.black);
        g.drawLine(10,3,getSize().width - 10,3);
    }
	
     public synchronized void plotImpedance(Trans_State state){
	state.ScanImpedance(); 
	//HERE
	tgc1.setTitle("Re{ Z(d) }   [ \u03a9 ]");
	tgc1.setFlag(1);
        tgc1.reset();
	tgc1.setDynamics(false);
	tgc1.setYRangeMin(0.0);
	//tgc1.reset();
	tgc1.plot(state.x,state.y1);
	
	tgc2.setTitle("Im{ Z(d) }   [ \u03a9 ]");
	tgc2.setFlag(2);
        tgc2.setDynamics(false);
	tgc2.reset();
	tgc2.plot(state.x,state.y2);
    }
    
    public synchronized void plotAdmittance(Trans_State state){
	state.ScanAdmittance(); 
	
	tgc1.setTitle("Re{ Y(d) }   [ S ]");
	tgc1.setFlag(1);
        tgc1.reset();
	tgc1.setDynamics(false);
	tgc1.setYRangeMin(0.0);
	
	//tgc1.reset();
	tgc1.plot(state.x,state.y1);
	
	tgc2.setTitle("Im{ Y(d) }   [ S ]");
        tgc2.setFlag(2);
        
	tgc2.setDynamics(false);
	tgc2.reset();
	tgc2.plot(state.x,state.y2);
        
    }
    
    public synchronized void plotReflectionCoefficient(Trans_State state){
	//state.ScanReflectionCoefficient();
	/*
	tgc1.setTitle("Re{    (d)}");
	tgc1.setDynamics(false);
	tgc1.setYRangeMax(1.0);
	tgc1.setYRangeMin(-1.0);
	tgc1.plot(state.x,state.y1);
	//HERE
	tgc2.setTitle(" Im{    (d)}");
	tgc2.setDynamics(false);
	tgc2.setYRangeMax(1.0);
	tgc2.setYRangeMin(-1.0);
	tgc2.plot(state.x,state.y2);
         */
    }
    
    public synchronized void plotVoltagePhasor(Trans_State state){
	//state.ScanVoltage();
	String labella;
	/*
        labella =""+state.PlotTimeScale+" |V+|";
        if(state.PlotTimeScale==1){labella ="  |V+|";}
	
	if (state.getYRangeMax(1)>=1.0 && state.getYRangeMax(1)<1.0E3|| state.getYRangeMax(1)==0.0){
	    tgc3.setTitle("   Re{ V(d) }   [ V ]                                  "+labella);    
	}
	else if(state.getYRangeMax(1)<1.0E6 && state.getYRangeMax(1)>=1.0E3  ){
	    tgc3.setTitle("   Re{ V(d) } [ k V ]                                "+labella); 
	   
	}
	else if(state.getYRangeMax(1)>=1.0E6  ){
	    tgc3.setTitle("   Re{ V(d) } [ M V ]                                "+labella); 
	   
	}
	else if(state.getYRangeMax(1)<1.0 && state.getYRangeMax(1)>=1.0E-3  ){
	    tgc3.setTitle("   Re{ V(d) } [ m V ]                                "+labella); 
	   
	}
	else if(state.getYRangeMax(1)<1.0E-3 && state.getYRangeMax(1)>=1.0E-6  ){
	    tgc3.setTitle("   Re{ V(d) } \u00b5 V ]                                "+labella); 
	    
	}
	else if(state.getYRangeMax(1)<1.0E-6 && state.getYRangeMax(1)>=1.0E-9  ){
	    tgc3.setTitle("   Re{ V(d) } [ n V ]                                "+labella); 
	    
	}
	else if(state.getYRangeMax(1)<1.0E-9 && state.getYRangeMax(1)>=1.0E-12  ){
	    tgc3.setTitle("   Re{ V(d) } [ p V ]                                "+labella); 
	    
	}
	else if(state.getYRangeMax(1)<1.0E-12 &&  state.getYRangeMax(1)>=1.0E-15){
	    tgc3.setTitle("   Re{ V(d) } [ f V ]                                "+labella); 
	   
	}
	else if(state.getYRangeMax(1)<1.0E-15){
	    tgc3.setTitle("   Re{ V(d) } [ a V ]                                "+labella); 
	   
	}
	
	tgc3.reset();
	tgc3.setDynamics(false);
	tgc3.setYRangeMax(state.getYRangeMax(1));
	tgc3.setYRangeMin(-state.getYRangeMax(1));
	tgc3.plot(state.x,state.y1);
	
	
	if (state.getYRangeMax(1)>=1.0 && state.getYRangeMax(1)<1.0E3|| state.getYRangeMax(1)==0.0){
	    tgc4.setTitle("   Im{ V(d) }   [ V ]                                   "+labella);    
	}
	else if(state.getYRangeMax(1)<1.0E6 && state.getYRangeMax(1)>=1.0E3  ){
	    tgc4.setTitle("   Im{ V(d) } [ k V ]                               "+labella);  
	}
	else if(state.getYRangeMax(1)>=1.0E6  ){
	    tgc4.setTitle("   Im{ V(d) } [ M V ]                               "+labella);  
	}
	else if(state.getYRangeMax(1)<1.0 && state.getYRangeMax(1)>=1.0E-3  ){
	    tgc4.setTitle("   Im{ V(d) } [ m V ]                               "+labella);  
	}
	else if(state.getYRangeMax(1)<1.0E-3 && state.getYRangeMax(1)>=1.0E-6  ){
	    tgc4.setTitle("   Im{ V(d) } [ \u00b5 V ]                               "+labella);  
	}
	else if(state.getYRangeMax(1)<1.0E-6 && state.getYRangeMax(1)>=1.0E-9  ){
	    tgc4.setTitle("   Im{ V(d) } [ n V ]                               "+labella);  
	}
	else if(state.getYRangeMax(1)<1.0E-9 && state.getYRangeMax(1)>=1.0E-12  ){
	    tgc4.setTitle("   Im{ V(d) } [ p V ]                               "+labella);  
	}
	else if(state.getYRangeMax(1)<1.0E-12 && state.getYRangeMax(1)>=1.0E-15){
	    tgc4.setTitle("   Im{ V(d) } [ f V ]                               "+labella);  
	}
	else if(state.getYRangeMax(1)<1.0E-15){
	    tgc4.setTitle("   Im{ V(d) } [ a V ]                               "+labella);  
	}
	
	
	tgc4.reset();
	tgc4.setDynamics(false);
	tgc4.setYRangeMax(state.getYRangeMax(1));
	tgc4.setYRangeMin(-state.getYRangeMax(1));
	tgc4.plot(state.x,state.y2);
	*/
	
    }
    
    public synchronized void plotCurrentPhasor(Trans_State state){
	//state.ScanCurrent();
	String labella;
	//if(!state.stub[0].isEnable() && !state.stub[1].isEnable() && !state.stub[2].isEnable()){
	 //   labella = "2 |V+|/ Zo";
	//}
	//else{
	  //  labella = "3 |V+|/ Zo";
	//}
        
        //labella =""+state.PlotTimeScale+" |V+|/ Zo";
        //if(state.PlotTimeScale==1){labella ="  |V+|/ Zo";};
	/*
	if (state.getYRangeMax(2)>=1.0 && state.getYRangeMax(2)<1.0E3|| state.getYRangeMax(2)==0.0){
	    tgc3.setTitle("   Re{ I(d) }   [ A ]                                "+labella);    
	}
	else if(state.getYRangeMax(2)<1.0E6 && state.getYRangeMax(2)>=1.0E3  ){
	    tgc3.setTitle("   Re{ I(d) } [ k A ]                              "+labella); 
	   
	}
	else if(state.getYRangeMax(2)>=1.0E6  ){
	    tgc3.setTitle("   Re{ I(d) } [ M A ]                              "+labella); 
	   
	}
	else if(state.getYRangeMax(2)<1.0 && state.getYRangeMax(2)>=1.0E-3  ){
	    tgc3.setTitle("   Re{ I(d) } [ m A ]                              "+labella); 
	   
	}
	else if(state.getYRangeMax(2)<1.0E-3 && state.getYRangeMax(2)>=1.0E-6  ){
	    tgc3.setTitle("   Re{ I(d) } [ \u00b5 A ]                              "+labella); 
	    
	}
	else if(state.getYRangeMax(2)<1.0E-6 && state.getYRangeMax(2)>=1.0E-9  ){
	    tgc3.setTitle("   Re{ I(d) } [ n A ]                              "+labella); 
	    
	}
	else if(state.getYRangeMax(2)<1.0E-9 && state.getYRangeMax(2)>=1.0E-12  ){
	    tgc3.setTitle("   Re{ I(d) } [ p A ]                              "+labella); 
	    
	}
	else if(state.getYRangeMax(2)<1.0E-12 && state.getYRangeMax(2)>=1.0E-15  ){
	    tgc3.setTitle("   Re{ I(d) } [ f A ]                              "+labella); 
	   
	}
	else if(state.getYRangeMax(2)<1.0E-15  ){
	    tgc3.setTitle("   Re{ I(d) } [ a A ]                              "+labella); 
	   
	}
	
	tgc3.reset();
	tgc3.setDynamics(false);
	tgc3.setYRangeMax(state.getYRangeMax(2));
	tgc3.setYRangeMin(-state.getYRangeMax(2));
	tgc3.plot(state.x,state.y1);
	
	
	if (state.getYRangeMax(2)>=1.0 && state.getYRangeMax(2)<1.0E3|| state.getYRangeMax(2)==0.0){
	    tgc4.setTitle("   Im{ I(d) }   [ A ]                                 "+labella);    
	}
	else if(state.getYRangeMax(2)<1.0E6 && state.getYRangeMax(2)>=1.0E3  ){
	    tgc4.setTitle("   Im{ I(d) } [ k A ]                               "+labella);  
	}
	else if(state.getYRangeMax(2)>=1.0E6  ){
	    tgc4.setTitle("   Im{ I(d) } [ M A ]                               "+labella);  
	}
	else if(state.getYRangeMax(2)<1.0 && state.getYRangeMax(2)>=1.0E-3  ){
	    tgc4.setTitle("   Im{ I(d) } [ m A ]                               "+labella);  
	}
	else if(state.getYRangeMax(2)<1.0E-3 && state.getYRangeMax(2)>=1.0E-6  ){
	    tgc4.setTitle("   Im{ I(d) } [ \u00b5 A ]                               "+labella);  
	}
	else if(state.getYRangeMax(2)<1.0E-6 && state.getYRangeMax(2)>=1.0E-9  ){
	    tgc4.setTitle("   Im{ I(d) } [ n A ]                               "+labella);  
	}
	else if(state.getYRangeMax(2)<1.0E-9 && state.getYRangeMax(2)>=1.0E-12  ){
	    tgc4.setTitle("   Im{ I(d) } [ p A ]                               "+labella);  
	}
	else if(state.getYRangeMax(2)<1.0E-12 && state.getYRangeMax(2)>=1.0E-15){
	    tgc4.setTitle("   Im{ I(d) } [ f A ]                               "+labella);  
	}
	else if(state.getYRangeMax(2)<1.0E-15){
	    tgc4.setTitle("   Im{ I(d) } [ a A ]                               "+labella);  
	}
	
	tgc4.reset();
	tgc4.setDynamics(false);
	tgc4.setYRangeMax(state.getYRangeMax(2));
	tgc4.setYRangeMin(-state.getYRangeMax(2));
	tgc4.plot(state.x,state.y2);
	*/
    }
    
    public synchronized void setIsVoltage(boolean IsVoltage){
	tgc3.setIsVoltage(IsVoltage);
	tgc4.setIsVoltage(IsVoltage);
    }
    
    public synchronized void plotVoltageCurrent(Trans_State state){
	state.ScanVoltageCurrent();
	String labella1, labella2;
	
	  labella1 = "2 |V+|";
	  labella2 = "2 |V+|/ Zo";
	 
        
        
	    tgc3.setTitle(labella1+"           | V (d) |   [ V ]");    
	
	tgc3.reset();
	tgc3.setDynamics(false);
        tgc3.setFlag(1);
	tgc3.setIsVoltage(true);
	tgc3.setYRangeMax(2.0);
	tgc3.setYRangeMin(0.0);
	tgc3.plot(state.x,state.y1);
	
	    tgc4.setTitle(labella2+"           | I (d) |   [ A ]");    
	
	tgc4.reset();
	tgc4.setDynamics(false);
        tgc3.setFlag(2);
	tgc4.setYRangeMax(2.0/50.0);//state.Complex.Real(Z0));
	tgc4.setYRangeMin(0.0);
	tgc4.setIsVoltage(false);
	tgc4.plot(state.x,state.y2);
    
	//System.out.println("in the plotVoltageCurrent");
    }
}
