//Trans_MultiGraphPanelA.java
//This is for frequency plots
/* A Java class for
 * LossyWide.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.*;

public class Trans_MultiGraphPanelA extends Panel{
    private  static final Color bgcolor = new Color(255,255,255);
    
    private static final Color tinta = new Color(246,246,231); 
    private static final Color maroon = new Color(185,50,50);
    private static final Color tinta2 = new Color(236,236,236);
    
    private Label titlelabel, selectlabel;   
    public static  Font labfont;
    public static  Font titlefont;
    public static  Font symbolfont;
    public static  Font normalfont;
    private String titulo;
    public Choice c1;
    
    TransGraphCanvas tgc1, tgc2;
    TransGraphCanvas3 tgc3, tgc4;
    Trans_State state;
    
    public Trans_MultiGraphPanelA(String titulo, Trans_State state){
	super();
	this.titulo = titulo;
        this.state = state;
	setLayout(null);
	setBackground(bgcolor);
	
	c1 = new Choice();
        c1.addItem("  Select a Plot");
	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.addItem("  Time-average Power");
	c1.setBackground(Color.white);
	c1.setFont(new Font("SanSerif",Font.ITALIC,state.font12));
	//c1.setFont(normalfont);
	titlelabel = new Label(titulo,Label.CENTER);
	titlelabel.setFont(titlefont);
	     
	selectlabel = new Label("Click to select a plot",Label.RIGHT);
	selectlabel.setFont(labfont);
	selectlabel.setBackground(bgcolor);
	selectlabel.setForeground(Color.blue);
	//add(selectlabel);

	selectlabel.setBounds(state.s280,state.s407,state.s100,state.s25);
	
	tgc1 = new TransGraphCanvas(state);
	tgc2 = new TransGraphCanvas(state);
	tgc3 = new TransGraphCanvas3(state);
	tgc4 = new TransGraphCanvas3(state);
	add(titlelabel);
	add(c1);
	add(tgc1);
	add(tgc2);
	add(tgc3);
	add(tgc4);
	//titlelabel.setBounds(5,5,300,25);
	// CHANGE ==============================================================
        c1.setBounds(state.s10,state.s407,state.s300,state.s22);
        Panel pc1 = new Panel();
	    pc1.setBackground(Color.gray);
	    //add(pc1);
	    pc1.setBounds(state.s10-1,state.s407-1,state.s300+2,state.s22+2);
        //======================================================================
	
	tgc1.setBounds(state.s6,state.s6,state.s882,state.s195);
	tgc2.setBounds(state.s6,state.s207,state.s882,state.s195);
	tgc3.setBounds(state.s6,state.s6,state.s882,state.s195);
	tgc4.setBounds(state.s6,state.s207,state.s882,state.s195);
	
	Panel pgraph1 = new Panel();
	    pgraph1.setBackground(tinta2);
	    add(pgraph1);
	    pgraph1.setBounds(state.s6,state.s6,state.s882,state.s195);
	    
	Panel pgraph2 = new Panel();
	    pgraph2.setBackground(Color.black);
	    add(pgraph2);
	    pgraph2.setBounds(state.s6-1,state.s6-1,state.s882+2,state.s195+2);
	    
	Panel pgraph3 = new Panel();
	    pgraph3.setBackground(tinta2);
	    add(pgraph3);
	    pgraph3.setBounds(state.s6,state.s207,state.s882,state.s195);
	
	Panel pgraph4 = new Panel();
	    pgraph4.setBackground(Color.black);
	    add(pgraph4);
	    pgraph4.setBounds(state.s6-1,state.s207-1,state.s882+2,state.s195+2);
    }		
    
    public void paint(Graphics g){
	    
	    g.setColor(Color.black);
	    g.drawRect(0,0,getSize().width-1,getSize().height-1);
    }	
	
     public synchronized void plotImpedance(Trans_State state){
	String alpha, Ohm, lambda, infinity, Gamma;
        alpha="\u03b1";
        lambda="\u03bb";
        Ohm="\u03a9";
        infinity="\u221e";
        Gamma="\uu0393";
        //setFont(labfont);
        setFont(new Font("SanSerif",Font.PLAIN,state.font11));
	state.ScanImpedance();
	state.IsPhasorPlot = 4;
	
	tgc1.setTitle("Re{Z(d)}");
	
	tgc1.setLabelY("");
	tgc1.setUnits("[ "+Ohm+" ]");
	tgc1.reset();
	tgc1.setDynamics(false);
	tgc1.setYRangeMin(0.0);
	tgc1.plot(state.x,state.y1);
	
        tgc1.setLabFlag(1); // Label is Re{ Z(d) }
        
	double tempvalue;
	tempvalue = Math.abs(state.Zin.Real());
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc1.setValue("Re{Z(d)} = "+MaestroA.rounder(state.Zin.Real(),3)+"  [ "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc1.setValue("Re{Z(d)} = "+MaestroA.rounder(state.Zin.Real()/1.0E3,3)+"  [ k "+Ohm+" ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc1.setValue("Re{Z(d)} = "+MaestroA.rounder(state.Zin.Real()/1.0E6,3)+"  [ M "+Ohm+" ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc1.setValue("Re{Z(d)} = "+MaestroA.rounder(state.Zin.Real()*1.0E3,3)+"  [ m "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc1.setValue("Re{Z(d)} = "+MaestroA.rounder(state.Zin.Real()*1.0E6,3)+"  [ \u00b5 "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc1.setValue("Re{Z(d)} = "+MaestroA.rounder(state.Zin.Real()*1.0E9,3)+"  [ n "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc1.setValue("Re{Z(d)} = "+MaestroA.rounder(state.Zin.Real()*1.0E12,3)+"  [ p "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc1.setValue("Re{Z(d)} = "+MaestroA.rounder(state.Zin.Real()*1.0E15,3)+"  [ f "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc1.setValue("Re{Z(d)} = 0.0  [ "+Ohm+" ]");   
	}
	
	
	tgc2.setTitle("Im{Z(d)}");
	tgc2.setLabelY("");
	tgc2.setUnits("[ "+Ohm+" ]");
	tgc2.setDynamics(false);
	tgc2.reset();
	tgc2.plot(state.x,state.y2);
	tgc2.setLabFlag(2); // Label is Im{Z(d)}
	tempvalue = Math.abs(state.Zin.Imaginary());
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc2.setValue("Im{Z(d)} = "+MaestroA.rounder(state.Zin.Imaginary(),3)+"  [ "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc2.setValue("Im{Z(d)} = "+MaestroA.rounder(state.Zin.Imaginary()/1.0E3,3)+"  [ k "+Ohm+" ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc2.setValue("Im{Z(d)} = "+MaestroA.rounder(state.Zin.Imaginary()/1.0E6,3)+"  [ M "+Ohm+" ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc2.setValue("Im{Z(d)} = "+MaestroA.rounder(state.Zin.Imaginary()*1.0E3,3)+"  [ m "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc2.setValue("Im{Z(d)} = "+MaestroA.rounder(state.Zin.Imaginary()*1.0E6,3)+"  [ \u00b5 "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc2.setValue("Im{Z(d)} = "+MaestroA.rounder(state.Zin.Imaginary()*1.0E9,3)+"  [ n "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc2.setValue("Im{Z(d)} = "+MaestroA.rounder(state.Zin.Imaginary()*1.0E12,3)+"  [ p "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc2.setValue("Im{Z(d)} = "+MaestroA.rounder(state.Zin.Imaginary()*1.0E15,3)+"  [ f "+Ohm+" ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc2.setValue("Im{Z(d)} = 0.0  [ "+Ohm+" ]");   
	}
	
    }
    
    public synchronized void plotAdmittance(Trans_State state){
	state.ScanAdmittance();
	state.IsPhasorPlot = 5;
	tgc1.setTitle("Re{Y(d)}");
	tgc1.setLabelY("");
	tgc1.setUnits("[ S ]");
	tgc1.reset();
	tgc1.setDynamics(false);
	tgc1.setYRangeMin(0.0);
	tgc1.plot(state.x,state.y1);
	tgc1.setLabFlag(3); // Label is Re{Y(d)}
	double tempvalue;
	tempvalue = Math.abs(state.Yin.Real());
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc1.setValue("Re{Y(d)} = "+MaestroA.rounder(state.Yin.Real(),3)+"  [ S ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc1.setValue("Re{Y(d)} = "+MaestroA.rounder(state.Yin.Real()/1.0E3,3)+"  [ k S ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc1.setValue("Re{Y(d)} = "+MaestroA.rounder(state.Yin.Real()/1.0E6,3)+"  [ M S ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc1.setValue("Re{Y(d)} = "+MaestroA.rounder(state.Yin.Real()*1.0E3,3)+"  [ m S ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc1.setValue("Re{Y(d)} = "+MaestroA.rounder(state.Yin.Real()*1.0E6,3)+"  [ \u00b5 S ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc1.setValue("Re{Y(d)} = "+MaestroA.rounder(state.Yin.Real()*1.0E9,3)+"  [ n S ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc1.setValue("Re{Y(d)} = "+MaestroA.rounder(state.Yin.Real()*1.0E12,3)+"  [ p S ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc1.setValue("Re{Y(d)} = "+MaestroA.rounder(state.Yin.Real()*1.0E15,3)+"  [ f S ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc1.setValue("Re{Y(d)} = 0.0  [ S ]");   
	}
        
        //tgc1.setLoadType(state.IsLoadShort, state.IsLoadOpen, state.IsLoadImaginary);
        //tgc2.setLoadType(state.IsLoadShort, state.IsLoadOpen, state.IsLoadImaginary);
	
	tgc2.setTitle("Im{Y(d)}");
	tgc2.setLabelY("");
	tgc2.setUnits("[ S ]");
	tgc2.setDynamics(false);
	tgc2.reset();
	tgc2.plot(state.x,state.y2);
	tgc2.setLabFlag(4); // Label is Im{Y(d)} 
	tempvalue = Math.abs(state.Yin.Imaginary());
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc2.setValue("Im{Y(d)} = "+MaestroA.rounder(state.Yin.Imaginary(),3)+"  [ S ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc2.setValue("Im{Y(d)} = "+MaestroA.rounder(state.Yin.Imaginary()/1.0E3,3)+"  [ k S ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc2.setValue("Im{Y(d)} = "+MaestroA.rounder(state.Yin.Imaginary()/1.0E6,3)+"  [ M S ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc2.setValue("Im{Y(d)} = "+MaestroA.rounder(state.Yin.Imaginary()*1.0E3,3)+"  [ m S ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc2.setValue("Im{Y(d)} = "+MaestroA.rounder(state.Yin.Imaginary()*1.0E6,3)+"  [ \u00b5 S ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc2.setValue("Im{Y(d)} = "+MaestroA.rounder(state.Yin.Imaginary()*1.0E9,3)+"  [ n S ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc2.setValue("Im{Y(d)} = "+MaestroA.rounder(state.Yin.Imaginary()*1.0E12,3)+"  [ p S ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc2.setValue("Im{Y(d)} = "+MaestroA.rounder(state.Yin.Imaginary()*1.0E15,3)+"  [ f S ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc2.setValue("Im{Y(d)} = 0.0  [ S ]");   
	}
    }
    
    public synchronized void plotReflectionCoefficient(Trans_State state){
	String alpha, Ohm, lambda, infinity, Gamma;
	    alpha="\u03b1";
	    lambda="\u03bb";
	    Ohm="\u03a9";
	    infinity="\u221e";
	    Gamma="\uu0393";
	    //setFont(labfont);
	
	state.ScanReflectionCoefficient();
	state.IsPhasorPlot = 6;
	
	tgc1.setTitle("Re{"+Gamma+"(d)}");
	tgc1.setDynamics(false);
	tgc1.setLabelY("");
	tgc1.setUnits("");
	if(state.IsLargerThanOne){
	    tgc1.setYRangeMax(2.414);
	    tgc1.setYRangeMin(-2.414);
	    tgc1.setLabelY("| "+Gamma+" | > 1.0 !!!");
	}
	else{
	    tgc1.setYRangeMax(1.0);
	    tgc1.setYRangeMin(-1.0);
	}
	tgc1.plot(state.x,state.y1);
	tgc1.setLabFlag(5); // Label is Re{Gamma_d} 
        
	tgc1.setValue("Re{"+Gamma+"(d)} = "+MaestroA.rounder(state.Gammain.Real(),8));
	// DEBUGGING
        //System.out.println(state.xpos+"   "+state.Gammain.Real());
        
	tgc2.setTitle(" Im{"+Gamma+"(d)}");
	tgc2.setLabelY("");
	tgc2.setUnits("");
	tgc2.setDynamics(false);
	if(state.IsLargerThanOne){
	    tgc2.setYRangeMax(2.414);
	    tgc2.setYRangeMin(-2.414);
	    tgc2.setLabelY("| "+Gamma+"(d)| > 1.0 !!!");
	}
	else{
	    tgc2.setYRangeMax(1.0);
	    tgc2.setYRangeMin(-1.0);
	}
	tgc2.plot(state.x,state.y2);
	tgc2.setLabFlag(6); // Label is Im{Gamma_d}
	tgc2.setValue("Im{"+Gamma+"(d)} = "+MaestroA.rounder(state.Gammain.Imaginary(),8));
        
    }
    
    public synchronized void plotVoltagePhasor(Trans_State state){
	String alpha, Ohm, lambda, infinity, Gamma;
	    alpha="\u03b1";
	    lambda="\u03bb";
	    Ohm="\u03a9";
	    infinity="\u221e";
	    Gamma="\uu0393";
	    //setFont(labfont);
	
	state.ScanVoltage();
	state.IsPhasorPlot = 2;
	
	//tgc3.setLabelY("2 |V+| exp ("+alpha+" l)");
	tgc3.setLabelY("2 |V+|");
	tgc3.setTitle("Re{V(d)}");
	tgc3.setLabFlag(1); // Label is Re{V(d)} 
        
	if (state.getYRangeMax(1)>=1.0 && state.getYRangeMax(1)<1.0E3|| state.getYRangeMax(1)==0.0){
	    tgc3.setUnits("[ V ]"); 
	}
	else if(state.getYRangeMax(1)<1.0E6 && state.getYRangeMax(1)>=1.0E3  ){
	    tgc3.setUnits("[ k V ]");   
	}
	else if(state.getYRangeMax(1)>=1.0E6  ){
	    tgc3.setUnits("[ M V ]"); 
	}
	else if(state.getYRangeMax(1)<1.0 && state.getYRangeMax(1)>=1.0E-3  ){
	    tgc3.setUnits("[ m V ]");
	}
	else if(state.getYRangeMax(1)<1.0E-3 && state.getYRangeMax(1)>=1.0E-6  ){
	    tgc3.setUnits("[ \u00b5 V ]");   
	}
	else if(state.getYRangeMax(1)<1.0E-6 && state.getYRangeMax(1)>=1.0E-9  ){
	    tgc3.setUnits("[ n V ]");  
	}
	else if(state.getYRangeMax(1)<1.0E-9 && state.getYRangeMax(1)>=1.0E-12  ){
	    tgc3.setUnits("[ p V ]");
	}
	else if(state.getYRangeMax(1)<1.0E-12 &&  state.getYRangeMax(1)>=1.0E-15){
	    tgc3.setUnits("[ f V ]"); 
	}
	else if(state.getYRangeMax(1)<1.0E-15){
	    tgc3.setUnits("[ a V ]");  
	}
	
	double tempvalue;
	tempvalue = Math.abs(state.Vin.Real());
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc3.setValue("Re{V(d)} = "+MaestroA.rounder(state.Vin.Real(),3)+"  [ V ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc3.setValue("Re{V(d)} = "+MaestroA.rounder(state.Vin.Real()/1.0E3,3)+"  [ k V ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc3.setValue("Re{V(d)} = "+MaestroA.rounder(state.Vin.Real()/1.0E6,3)+"  [ M V ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc3.setValue("Re{V(d)} = "+MaestroA.rounder(state.Vin.Real()*1.0E3,3)+"  [ m V ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc3.setValue("Re{V(d)} = "+MaestroA.rounder(state.Vin.Real()*1.0E6,3)+"  [ \u00b5 V ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc3.setValue("Re{V(d)} = "+MaestroA.rounder(state.Vin.Real()*1.0E9,3)+"  [ n V ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc3.setValue("Re{V(d)} = "+MaestroA.rounder(state.Vin.Real()*1.0E12,3)+"  [ p V ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc3.setValue("Re{V(d)} = "+MaestroA.rounder(state.Vin.Real()*1.0E15,3)+"  [ f V ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc3.setValue("Re{V(d)} = 0.0  [ V ]");   
	}
	
	tgc3.reset();
	tgc3.setDynamics(false);
	tgc3.setYRangeMax(state.getYRangeMax(1));
	tgc3.setYRangeMin(-state.getYRangeMax(1));
	tgc3.plot(state.x,state.y1);
	
	//tgc4.setLabelY("2 |V+| exp ("+alpha+" l)");
	tgc4.setLabelY("2 |V+|");
	tgc4.setTitle("Im{V(d)}");
        tgc4.setLabFlag(2); // Label is Im{V(d)}
        
	if (state.getYRangeMax(1)>=1.0 && state.getYRangeMax(1)<1.0E3|| state.getYRangeMax(1)==0.0){
	    tgc4.setUnits("[ V ]");    
	}
	else if(state.getYRangeMax(1)<1.0E6 && state.getYRangeMax(1)>=1.0E3  ){
	    tgc4.setUnits("[ k V ]"); 
	   
	}
	else if(state.getYRangeMax(1)>=1.0E6  ){
	    tgc4.setUnits("[ M V ]");
	   
	}
	else if(state.getYRangeMax(1)<1.0 && state.getYRangeMax(1)>=1.0E-3  ){
	    tgc4.setUnits("[ m V ]");
	   
	}
	else if(state.getYRangeMax(1)<1.0E-3 && state.getYRangeMax(1)>=1.0E-6  ){
	    tgc4.setUnits("[ \u00b5 V ])");
	    
	}
	else if(state.getYRangeMax(1)<1.0E-6 && state.getYRangeMax(1)>=1.0E-9  ){
	    tgc4.setUnits("[ n V ]");
	    
	}
	else if(state.getYRangeMax(1)<1.0E-9 && state.getYRangeMax(1)>=1.0E-12  ){
	    tgc4.setUnits("[ p V ]");
	    
	}
	else if(state.getYRangeMax(1)<1.0E-12 &&  state.getYRangeMax(1)>=1.0E-15){
	    tgc4.setUnits("[ f V ]");
	   
	}
	else if(state.getYRangeMax(1)<1.0E-15){
	    tgc4.setUnits("[ a V ]");
	   
	}
	
	tempvalue = Math.abs(state.Vin.Imaginary());
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc4.setValue("Im{V(d)} = "+MaestroA.rounder(state.Vin.Imaginary(),3)+"  [ V ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc4.setValue("Im{V(d)} = "+MaestroA.rounder(state.Vin.Imaginary()/1.0E3,3)+"  [ k V ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc4.setValue("Im{V(d)} = "+MaestroA.rounder(state.Vin.Imaginary()/1.0E6,3)+"  [ M V ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc4.setValue("Im{V(d)} = "+MaestroA.rounder(state.Vin.Imaginary()*1.0E3,3)+"  [ m V ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc4.setValue("Im{V} = "+MaestroA.rounder(state.Vin.Imaginary()*1.0E6,3)+"  [ \u00b5 V ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc4.setValue("Im{V(d)} = "+MaestroA.rounder(state.Vin.Imaginary()*1.0E9,3)+"  [ n V ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc4.setValue("Im{V(d)} = "+MaestroA.rounder(state.Vin.Imaginary()*1.0E12,3)+"  [ p V ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc4.setValue("Im{V(d)} = "+MaestroA.rounder(state.Vin.Imaginary()*1.0E15,3)+"  [ f V ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc4.setValue("Im{V(d)} = 0.0  [ V ]");   
	}
	
	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){
	String alpha, Ohm, lambda, infinity, Gamma;
	    alpha="\u03b1";
	    lambda="\u03bb";
	    Ohm="\u03a9";
	    infinity="\u221e";
	    Gamma="\uu0393";
	    //setFont(labfont);
	
	state.ScanCurrent();
	state.IsPhasorPlot = 3;
	
	//tgc3.setLabelY("2 |V+| exp ("+alpha+" l)/ Zo");
	tgc3.setLabelY("2 |V+| / Zo");
	tgc3.setTitle("Re{I (d)}");
	tgc3.setLabFlag(3); // Label is Re{I(d)}
        
	if (state.getYRangeMax(2)>=1.0 && state.getYRangeMax(2)<1.0E3|| state.getYRangeMax(2)==0.0){
	    tgc3.setUnits("[ A ]");
	}
	else if(state.getYRangeMax(2)<1.0E6 && state.getYRangeMax(2)>=1.0E3  ){
	    tgc3.setUnits("[ k A ]"); 
	   
	}
	else if(state.getYRangeMax(2)>=1.0E6  ){
	    tgc3.setUnits("[ M A ]");
	   
	}
	else if(state.getYRangeMax(2)<1.0 && state.getYRangeMax(2)>=1.0E-3  ){
	    tgc3.setUnits("[ m A ]");
	   
	}
	else if(state.getYRangeMax(2)<1.0E-3 && state.getYRangeMax(2)>=1.0E-6  ){
	    tgc3.setUnits("[ \u00b5 A ]"); 
	     
	}
	else if(state.getYRangeMax(2)<1.0E-6 && state.getYRangeMax(2)>=1.0E-9  ){
	    tgc3.setUnits("[ n A ]");
	    
	}
	else if(state.getYRangeMax(2)<1.0E-9 && state.getYRangeMax(2)>=1.0E-12  ){
	    tgc3.setUnits("[ p A ]"); 
	    
	}
	else if(state.getYRangeMax(2)<1.0E-12 && state.getYRangeMax(2)>=1.0E-15  ){
	    tgc3.setUnits("[ f A ]"); 
	   
	}
	else if(state.getYRangeMax(2)<1.0E-15  ){
	    tgc3.setUnits("[ a A ]"); 
	    
	}
	
	double tempvalue;
	tempvalue = Math.abs(state.Iin.Real());
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc3.setValue("Re{I(d)} = "+MaestroA.rounder(state.Iin.Real(),3)+"  [ A ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc3.setValue("Re{I(d)} = "+MaestroA.rounder(state.Iin.Real()/1.0E3,3)+"  [ k A ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc3.setValue("Re{I(d)} = "+MaestroA.rounder(state.Iin.Real()/1.0E6,3)+"  [ M A ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc3.setValue("Re{I(d)} = "+MaestroA.rounder(state.Iin.Real()*1.0E3,3)+"  [ m A ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc3.setValue("Re{I(d)} = "+MaestroA.rounder(state.Iin.Real()*1.0E6,3)+"  [ \u00b5 A ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc3.setValue("Re{I(d)} = "+MaestroA.rounder(state.Iin.Real()*1.0E9,3)+"  [ n A ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc3.setValue("Re{I(d)} = "+MaestroA.rounder(state.Iin.Real()*1.0E12,3)+"  [ p A ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc3.setValue("Re{I(d)} = "+MaestroA.rounder(state.Iin.Real()*1.0E15,3)+"  [ f A ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc3.setValue("Re{I(d)} = 0.0  [ A ]");   
	}
	
	tgc3.reset();
	tgc3.setDynamics(false);
	tgc3.setYRangeMax(state.getYRangeMax(2));
	tgc3.setYRangeMin(-state.getYRangeMax(2));
	tgc3.plot(state.x,state.y1);
	
        //tgc4.setLabelY("2 |V+| exp ("+alpha+" l)/ Zo");
        tgc4.setLabelY("2 |V+| / Zo");
	tgc4.setTitle("Im{I (d)}");
	tgc4.setLabFlag(4); // Label is Im{I(d)} 
	if (state.getYRangeMax(2)>=1.0 && state.getYRangeMax(2)<1.0E3|| state.getYRangeMax(2)==0.0){
	    tgc4.setUnits("[ A ]");   
	}
	else if(state.getYRangeMax(2)<1.0E6 && state.getYRangeMax(2)>=1.0E3  ){
	    tgc4.setUnits("[ k A ]");  
	}
	else if(state.getYRangeMax(2)>=1.0E6  ){
	    tgc4.setUnits("[ M A ]");  
	}
	else if(state.getYRangeMax(2)<1.0 && state.getYRangeMax(2)>=1.0E-3  ){
	    tgc4.setUnits("[ m A ]");
	}
	else if(state.getYRangeMax(2)<1.0E-3 && state.getYRangeMax(2)>=1.0E-6  ){
	    tgc4.setUnits("[ \u00b5 A ]"); 
	}
	else if(state.getYRangeMax(2)<1.0E-6 && state.getYRangeMax(2)>=1.0E-9  ){
	    tgc4.setUnits("[ n A ]");  
	}
	else if(state.getYRangeMax(2)<1.0E-9 && state.getYRangeMax(2)>=1.0E-12  ){
	    tgc4.setUnits("[ p A ]"); 
	}
	else if(state.getYRangeMax(2)<1.0E-12 && state.getYRangeMax(2)>=1.0E-15){
	    tgc4.setUnits("[ f A ]");
	}
	else if(state.getYRangeMax(2)<1.0E-15){
	    tgc4.setUnits("[ a A ]");  
	}
	
	tempvalue = Math.abs(state.Iin.Imaginary());
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc4.setValue("Im{I(d)} = "+MaestroA.rounder(state.Iin.Imaginary(),3)+"  [ A ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc4.setValue("Im{I(d)} = "+MaestroA.rounder(state.Iin.Imaginary()/1.0E3,3)+"  [ k A ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc4.setValue("Im{I(d)} = "+MaestroA.rounder(state.Iin.Imaginary()/1.0E6,3)+"  [ M A ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc4.setValue("Im{I(d)} = "+MaestroA.rounder(state.Iin.Imaginary()*1.0E3,3)+"  [ m A ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc4.setValue("Im{I(d)} = "+MaestroA.rounder(state.Iin.Imaginary()*1.0E6,3)+"  [ \u00b5 A ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc4.setValue("Im{I(d)} = "+MaestroA.rounder(state.Iin.Imaginary()*1.0E9,3)+"  [ n A ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc4.setValue("Im{I(d)} = "+MaestroA.rounder(state.Iin.Imaginary()*1.0E12,3)+"  [ p A ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc4.setValue("Im{I(d)} = "+MaestroA.rounder(state.Iin.Imaginary()*1.0E15,3)+"  [ f A ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc4.setValue("Im{I(d)} = 0.0  [ A ]");   
	}
	
	tgc4.reset();
	tgc4.setDynamics(false);
	tgc4.setYRangeMax(state.getYRangeMax(2));
	tgc4.setYRangeMin(-state.getYRangeMax(2));
	tgc4.plot(state.x,state.y2);
    }
    
    public synchronized void plotVoltageCurrent(Trans_State state){
	String alpha, Ohm, lambda, infinity, Gamma;
	    alpha="\u03b1";
	    lambda="\u03bb";
	    Ohm="\u03a9";
	    infinity="\u221e";
	    Gamma="\uu0393";
	    //setFont(labfont);
		
	state.ScanVoltageCurrent();
	state.IsPhasorPlot = 1;
	
	//tgc3.setLabelY("2 |V+| exp ("+alpha+" l)");
	tgc3.setLabelY("2 |V+|");
	tgc3.setTitle("| V(d) |");
	tgc3.setLabFlag(5); // Label is |V(d)|
        
	if (state.getYRangeMax(1)>=1.0 && state.getYRangeMax(1)<1.0E3 || state.getYRangeMax(1)==0.0){
	    tgc3.setUnits("[ V ]");      
	}
	else if(state.getYRangeMax(1)<1.0E6 && state.getYRangeMax(1)>=1.0E3  ){
	    tgc3.setUnits("[ k V ]");    
	}
	else if(state.getYRangeMax(1)>=1.0E6  ){
	    tgc3.setUnits("[ M V ]");  
	}
	
	else if(state.getYRangeMax(1)<1.0 && state.getYRangeMax(1)>=1.0E-3  ){
	    tgc3.setUnits("[ m V ]");    
	}
	else if(state.getYRangeMax(1)<1.0E-3 && state.getYRangeMax(1)>=1.0E-6  ){
	    tgc3.setUnits("[ \u00b5 V ]");    
	}
	else if(state.getYRangeMax(1)<1.0E-6 && state.getYRangeMax(1)>=1.0E-9  ){
	    tgc3.setUnits("[ n V ]");    
	}
	else if(state.getYRangeMax(1)<1.0E-9 && state.getYRangeMax(1)>=1.0E-12  ){
	    tgc3.setUnits("[ p V ]");    
	}
	else if(state.getYRangeMax(1)<1.0E-12 && state.getYRangeMax(1)>=1.0E-15){
	    tgc3.setUnits("[ f V ]");    
	}
	else if(state.getYRangeMax(1)<1.0E-15){
	    tgc3.setUnits("[ a V ]");   
	}
	
	tgc3.reset();
	tgc3.setDynamics(false);
	tgc3.setYRangeMax(state.getYRangeMax(1));
	tgc3.setYRangeMin(0.0);
	tgc3.plot(state.x,state.y1);
	
	double tempvalue;
	tempvalue = Complex.Magnitude(state.Vin);
	
        if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc3.setValue("| V(d) | = "+MaestroA.rounder(tempvalue,3)+"  [ V ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc3.setValue("| V(d) | = "+MaestroA.rounder(tempvalue/1.0E3,3)+"  [ k V ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc3.setValue("| V(d) | = "+MaestroA.rounder(tempvalue/1.0E6,3)+"  [ M V ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc3.setValue("| V(d) | = "+MaestroA.rounder(tempvalue*1.0E3,3)+"  [ m V ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc3.setValue("| V(d) | = "+MaestroA.rounder(tempvalue*1.0E6,3)+"  [ \u00b5 V ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc3.setValue("| V(d) | = "+MaestroA.rounder(tempvalue*1.0E9,3)+"  [ n V ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc3.setValue("| V(d) | = "+MaestroA.rounder(tempvalue*1.0E12,3)+"  [ p V ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc3.setValue("| V(d) | = "+MaestroA.rounder(tempvalue*1.0E15,3)+"  [ f V ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc3.setValue("| V(d) | = 0.0  [ V ]");   
	}
	
        //tgc4.setLabelY("2 |V+| exp ("+alpha+" l)/ Zo");
        tgc4.setLabelY("2 |V+| / Zo");
	tgc4.setTitle("| I (d) |");
	tgc4.setLabFlag(6); // Label is |I(d)|
        
	if (state.getYRangeMax(2)>=1.0 && state.getYRangeMax(2)<1.0E3 || state.getYRangeMax(2)==0.0){
	    tgc4.setUnits("[ A ]");   
	}
	else if(state.getYRangeMax(2)<1.0E6 && state.getYRangeMax(2)>=1.0E3  ){
	    tgc4.setUnits("[ k A ]");  
	}
	else if(state.getYRangeMax(2)>=1.0E6  ){
	    tgc4.setUnits("[ M A ]");
	}
	else if(state.getYRangeMax(2)<1.0 && state.getYRangeMax(2)>=1.0E-3  ){
	    tgc4.setUnits("[ m A ]"); 
	}
	else if(state.getYRangeMax(2)<1.0E-3 && state.getYRangeMax(2)>=1.0E-6  ){
	    tgc4.setUnits("[ \u00b5 A ]");
	} 
	else if(state.getYRangeMax(2)<1.0E-6 && state.getYRangeMax(2)>=1.0E-9  ){
	    tgc4.setUnits("[ n A ]"); 
	}
	else if(state.getYRangeMax(2)<1.0E-9 && state.getYRangeMax(2)>=1.0E-12  ){
	    tgc4.setUnits("[ p A ]");
	}
	else if(state.getYRangeMax(2)<1.0E-12 && state.getYRangeMax(2)>=1.0E-15 ){
	    tgc4.setUnits("[ f A ]");
	}
	else if(state.getYRangeMax(2)<1.0E-15 ){
	    tgc4.setUnits("[ a A ]");
	}
	
	tempvalue = Complex.Magnitude(state.Iin);
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc4.setValue("| I(d) | = "+MaestroA.rounder(tempvalue,3)+"  [ A ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc4.setValue("| I(d) | = "+MaestroA.rounder(tempvalue/1.0E3,3)+"  [ k A ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc4.setValue("| I(d) | = "+MaestroA.rounder(tempvalue/1.0E6,3)+"  [ M A ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc4.setValue("| I(d) | = "+MaestroA.rounder(tempvalue*1.0E3,3)+"  [ m A ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc4.setValue("| I(d) | = "+MaestroA.rounder(tempvalue*1.0E6,3)+"  [ \u00b5 A ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc4.setValue("| I(d) | = "+MaestroA.rounder(tempvalue*1.0E9,3)+"  [ n A ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc4.setValue("| I(d) | = "+MaestroA.rounder(tempvalue*1.0E12,3)+"  [ p A ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc4.setValue("| I(d) | = "+MaestroA.rounder(tempvalue*1.0E15,3)+"  [ f A ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc4.setValue("| I(d) | = 0.0  [ A ]");   
	}
	
	tgc4.reset();
	tgc4.setDynamics(false);
	tgc4.setYRangeMax(state.getYRangeMax(2));
	tgc4.setYRangeMin(0.0);
	tgc4.plot(state.x,state.y2);
    }
     public synchronized void plotPower(Trans_State state){
	String alpha, Ohm, lambda, infinity, Gamma;
	    alpha="\u03b1";
	    lambda="\u03bb";
	    Ohm="\u03a9";
	    infinity="\u221e";
	    Gamma="\uu0393";
	    setFont(labfont);
	
	state.ScanPower();
	state.IsPhasorPlot = 7;
	
        //tgc3.setLabelY("|V+|\u00b2 exp (2"+alpha+" l)/ Zo");
        tgc3.setLabelY("|V+|\u00b2 / Zo");
	tgc3.setTitle("< P(d) >");
	tgc3.setLabFlag(7); // Label is <P(d)>	
        
	if (state.getYRangeMax(4)>=1.0 && state.getYRangeMax(3)<1.0E3 || state.getYRangeMax(3)==0.0){
	    tgc3.setUnits("[ W ]");   
	}
	else if(state.getYRangeMax(4)<1.0E6 && state.getYRangeMax(3)>=1.0E3  ){
	    tgc3.setUnits("[ k W ]"); 
	}
	else if(state.getYRangeMax(4)>=1.0E6  ){
	    tgc3.setUnits("[ M W ]"); 
	}
	else if(state.getYRangeMax(4)<1.0 && state.getYRangeMax(4)>=1.0E-3  ){
	    tgc3.setUnits("[ m W ]"); 
	}
	else if(state.getYRangeMax(4)<1.0E-3 && state.getYRangeMax(4)>=1.0E-6  ){
	    tgc3.setUnits("[ \u00b5 W ]"); 
	}
	else if(state.getYRangeMax(4)<1.0E-6 && state.getYRangeMax(4)>=1.0E-9  ){
	    tgc3.setUnits("[ n W ]"); 
	}
	else if(state.getYRangeMax(4)<1.0E-9 && state.getYRangeMax(4)>=1.0E-12  ){
	    tgc3.setUnits("[ p W ]");   
	}
	else if(state.getYRangeMax(4)<1.0E-12 && state.getYRangeMax(4)>=1.0E-15){
	    tgc3.setUnits("[ f W ]");
	}
	else if(state.getYRangeMax(4)<1.0E-15){
	    tgc3.setUnits("[ a W ]"); 
	}
	
	tgc3.reset();
	tgc3.setDynamics(false);
	tgc3.setYRangeMax(state.getYRangeMax(4));
	tgc3.setYRangeMin(0.0);
	tgc3.plot(state.x,state.y1);
	
	double tempvalue;
	tempvalue = state.Power_flow;
	
	if (tempvalue>=1.0 && tempvalue<1.0E3|| tempvalue==0.0){
	    tgc3.setValue("< P > = "+MaestroA.rounder(tempvalue,3)+"  [ W ]");   
	}
	else if(tempvalue<1.0E6 && tempvalue>=1.0E3  ){
	    tgc3.setValue("< P > = "+MaestroA.rounder(tempvalue/1.0E3,3)+"  [ k W ]");   
	}
	else if(tempvalue>=1.0E6  ){
	    tgc3.setValue("< P > = "+MaestroA.rounder(tempvalue/1.0E6,3)+"  [ M W ]");   
	}
	else if(tempvalue<1.0 && tempvalue>=1.0E-3  ){
	    tgc3.setValue("< P > = "+MaestroA.rounder(tempvalue*1.0E3,3)+"  [ m W ]");   
	}
	else if(tempvalue<1.0E-3 && tempvalue>=1.0E-6  ){
	    tgc3.setValue("< P > = "+MaestroA.rounder(tempvalue*1.0E6,3)+"  [ \u00b5 W ]");   
	}
	else if(tempvalue<1.0E-6 && tempvalue>=1.0E-9  ){
	    tgc3.setValue("< P > = "+MaestroA.rounder(tempvalue*1.0E9,3)+"  [ n W ]");   
	}
	else if(tempvalue<1.0E-9 && tempvalue>=1.0E-12  ){
	    tgc3.setValue("< P > = "+MaestroA.rounder(tempvalue*1.0E12,3)+"  [ p W ]");   
	}
	else if(tempvalue<1.0E-12 &&  tempvalue>=1.0E-15){
	    tgc3.setValue("< P > = "+MaestroA.rounder(tempvalue*1.0E15,3)+"  [ f W ]");   
	}
	else if(tempvalue<1.0E-15){
	    tgc3.setValue("< P > = 0.0  [ W ]");   
	}
	
	tgc2.setLabelY(" ");
	tgc2.setUnits(" ");
		
	tgc2.setTitle("| "+Gamma+"(d) |");
	tgc2.reset();
	tgc2.setDynamics(false);
	tgc2.setLabFlag(7); // Label is |Gamma_d|
	if(state.IsLargerThanOne){
	    tgc2.setYRangeMax(2.414);
	    tgc2.setLabelY("| "+Gamma+" | > 1.0 !!!");
	}
	else{
	    tgc2.setYRangeMax(1.0);
	}
	tgc2.setYRangeMin(0.0);
	tgc2.plot(state.x,state.y2);
	
	tgc2.setValue("| "+Gamma+" | = "+MaestroA.rounder(Complex.Magnitude(state.GammaL),8));
    }
    
}
