//Trans_OutputPanel.java
/* 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.text.*;  
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;

public class Trans_OutputPanel extends Panel {
    //private static final Color bgcolor = new Color(180,147,112);
    //private static final Color bgcolor = Color.lightGray;
    private static final Color bgcolor = new Color(236,236,236);
    private static final Font labfont=TheFonts.sanSerif11;
    private static final Font titlefont=TheFonts.bold16;
    public Font newtitlefont, newnormalfont;
    Label titlelabel;
    public SpaceDependentCanvas canvas1;
    public SpaceIndependentCanvas canvas2;
    public StubOutputCanvas canvas3;
    Trans_State state;
    
    public Trans_OutputPanel(Trans_State state){
	super();
	this.state = state;
        newtitlefont = new Font("Sanserif",Font.BOLD,state.s14);
        newnormalfont = new Font("Sanserif",Font.PLAIN,state.s11);
	titlelabel = new Label("Output",Label.LEFT);
	setLayout(null);
	add(titlelabel);
	titlelabel.setFont(newtitlefont);
    
	setBackground(bgcolor);
		
	canvas1 = new SpaceDependentCanvas(state);
	canvas2 = new SpaceIndependentCanvas(state);
	canvas3 = new StubOutputCanvas(state);
	
        add(titlelabel);
	add(canvas1);
	add(canvas2);
	add(canvas3);
		
        FontMetrics fmTitle = getFontMetrics(newtitlefont);
        
        int labelWidth = fmTitle.stringWidth("Output");
	titlelabel.setBounds(state.s10,state.s2,labelWidth+state.s5,state.s25);

	canvas1.setBounds(state.s6,state.s26,state.s298,state.s250);
	canvas2.setBounds(state.s6,state.s26,state.s298,state.s250);
	canvas3.setBounds(state.s6,state.s26,state.s298,state.s250);
    }
    
    /*public void paint(Graphics g){
	    g.setColor(Color.lightGray);
	    g.fill3DRect(0,0,getSize().width-1,getSize().height-1,true);
    }*/
    
    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);
	}
}

class SpaceDependentCanvas extends Canvas{
	private static final Font normalfont = TheFonts.sanSerif11;
	private static final Font symbolfont = TheFonts.symbol12;
	private static final Font subfont    = TheFonts.sanSerif10;
	Font newnormalfont;
        private int fonto, fontoint;
        Trans_State state;
	private Image im;
	private Graphics buf;
        DecimalFormat dec = new DecimalFormat("0.###"); //"0.###E0"
        DecimalFormat dec2 = new DecimalFormat("0.######"); //"0.###E0"
    
    private BufferedImage angle_img;

	public SpaceDependentCanvas(Trans_State state){
	    super();
	    this.state = state;
	    getImages();
	}

    private void getImages() {
        // read in character images that CHEERPJ will not render
	//   (java to javascript converter)
	double font11_factor = 11.0 * state.sfactor;
	long fontsize = Math.round(font11_factor);
	if (fontsize > 30) fontsize = 30;
	else if (fontsize < 11) fontsize = 11;
	String filename = "angle_"+String.valueOf(fontsize)+".png";
        try {
	    angle_img = ImageIO.read(getClass().getResource(filename));
            //angle_img = ImageIO.read(getClass().getResource("angle.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
	
	public void paint(Graphics g){
	    if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawGraph(buf);
	    }
	    else{
		drawGraph(buf);
	    }
	    g.drawImage(im,0,0,null);
	}
	
	//Addition to reduce flicker new routine
	public void update(Graphics g){		// added to avoid clearing
	    paint(g);
	}

	public void drawGraph(Graphics g){
            boolean Gamma_plusone, Gamma_minusone;
	    double epsilon0 = 8.8541878176E-12; // Units: F/m
	    double mu0 = 1.25663706144E-6; //      Units H/m
	    double light_velocity = Math.sqrt(1.0/(epsilon0*mu0)); //  Units m/s
	    int x, y, dx, dxx, dxxx, dxxxx, dy, dyy, stepx;

            double tempR = 0.0; double tempX = 0.0;

	    Complex tempc;
	    
            newnormalfont = new Font("Sanserif",Font.PLAIN,state.s11);
            //fonto = state.s11;
            //fontoint = state.s13;

            fonto = state.font11;
            fontoint = state.font13;
	    
	    
            FontMetrics fm;
		
            //g.setFont(TheFonts.serif11);
		
		String alpha, Ohm, lambda, infinity, Gamma, plusj, minusj, 
                       sign, plusr, minusr, signr;
		alpha="\u03b1";
		lambda="\u03bb";
		Ohm="\u03a9";
		infinity="\u221e";
		Gamma="\u0393";
                plusj =" + j ";
		minusj=" - j ";
                plusr ="";
                minusr =" - ";
                
            Gamma_plusone = false;
            Gamma_minusone = false;
	    
            g.setFont(newnormalfont);
	    fm = g.getFontMetrics();
	    dy = fm.getHeight();
            
	    float dmax, dmin;
		if(state.ZL.Imaginary()>0.0f){
		    dmax=(float)((state.GammaL.Arg2())/(4.0*Math.PI));
		    dmin=dmax+0.25f;
		}
		else{
		    dmax=(float)((state.GammaL.Arg2())/(4.0*Math.PI))+0.5f;
		    dmin=(float)((state.GammaL.Arg2())/(4.0*Math.PI))+0.25f;
		}

		while(dmax>0.5f) dmax=dmax-0.5f;
		while(dmin>0.5f) dmin=dmin-0.5f; 
	    
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
	    
	    x = state.s10;
	    y = state.s10;
	    dx = state.s80;
	    dxx = state.s10;
	    dxxx = state.s120;
	    dxxxx = state.s60;
	    g.setFont(newnormalfont);
	    fm = g.getFontMetrics();
	    dy = fm.getHeight();
	    dyy = dy + state.s4;
	    g.clearRect(0,0,getSize().width,getSize().height);
	    g.setColor(Color.blue);
	    g.drawString("Cursor",x,y+state.s5);
	    
	    g.setColor(Color.black);
	    if(state.xpos == 0.0){
                g.drawString("    d   = "+dec2.format(state.xpos),x+dx,y);
            }
            else{
                g.drawString("    d   = "+dec2.format(state.xpos),x+dx,y);
            }
            MaestroG.subscripterSanSymUnit("  [ ","",""+lambda," ]",g,fonto,x+state.s200,y);
            
	    y+=dy;
	    	
	    double testlength = state.xpos*state.wavelength;
	    if(state.xpos == 0.0){
                g.drawString("         = 0.0",x+dx,y);	
                g.drawString("  [ m ]",x+state.s200,y);
            }
            else{
                if(testlength < 1.0E-9 && testlength > 0.0){
                    g.drawString("         = "+dec.format(state.xpos*state.wavelength*1.0e9),x+dx,y);	
                    g.drawString("  [ nm ]",x+state.s200,y);
                }
                else if(testlength < 1.0E-6 && testlength >= 1.0E-9){
                    g.drawString("         = "+dec.format(state.xpos*state.wavelength*1.0e9),x+dx,y);	
                    g.drawString("  [ nm ]",x+state.s200,y);
                }
                else if(testlength < 1.0E-3 && testlength >= 1.0E-6){
                    g.drawString("         = "+dec.format(state.xpos*state.wavelength*1.0e6),x+dx,y);	
                    g.drawString("  [ \u00b5m ]",x+state.s200,y);
                }
                else if(testlength < 1.0 && testlength >= 1.0E-3){
                    g.drawString("         = "+dec.format(state.xpos*state.wavelength*1000),x+dx,y);	
                    g.drawString("  [ mm ]",x+state.s200,y);
                }
                else if((testlength < 1000.0 && testlength >= 1.0 ) || testlength == 0.0){
                    g.drawString("         = "+dec.format(state.xpos*state.wavelength),x+dx,y);	
                    g.drawString("  [ m ]",x+state.s200,y);
                }
                else if(testlength >= 1000.0 && testlength < 1.0E6){
                    g.drawString("         = "+dec.format(state.xpos*state.wavelength/1000.0),x+dx,y);	
                    g.drawString("  [ km ]",x+state.s200,y);
                }
                else if(testlength >= 1.0E6 && testlength < 1.0E9){
                    g.drawString("         = "+dec.format(state.xpos*state.wavelength/1.0E6),x+dx,y);	
                    //g.drawString("  [ Mm ]",x+state.s200,y);
                    MaestroG.superscripter("  [ 10","3"," km ]",g,fonto,x+state.s200,y);
                }
                else if(testlength >= 1.0E9){
                    g.drawString("         = "+dec.format(state.xpos*state.wavelength/1.0E9),x+dx,y);	
                    //g.drawString("  [ Gm ]",x+state.s200,y);
                    MaestroG.superscripter("  [ 10","6"," km ]",g,fonto,x+state.s200,y);
                }
            }            
	    g.setColor(Color.white);	        
	    g.drawLine(state.s5,y+dyy/3,getSize().width-state.s5,y+dyy/3);
	    //--------------------------------
            y += dyy;
	    dx = state.s80;
            double testmag = Complex.Magnitude(state.Zin);
            Complex Zmag = state.Zin;

            double testmag2 = Complex.Magnitude(state.Yin);
            Complex Ymag = state.Yin;
            
                if(Complex.Real(state.Gammain) > 0.999999 && Math.abs(Complex.Imaginary(state.Gammain)) < 0.000001){
		    Gamma_plusone = true;
		    Gamma_minusone = false;
		}
		else if(Complex.Real(state.Gammain) < -0.999999 && Math.abs(Complex.Imaginary(state.Gammain)) < 0.000001){
		    Gamma_plusone = false;
		    Gamma_minusone = true;
		}
		else{
		    Gamma_plusone = false;
		    Gamma_minusone = false;
		}
	    
            g.setColor(Color.red);
            g.drawString("Impedance",x,y);
            MaestroG.SansNosansSymb2("",""," [ "+Ohm+" ]",g,state.font10,x,y+dy);
            g.setColor(Color.black); 
            	
                MaestroG.subscripter("Z","","(d)",g,fonto,x+dx,y);
                int xinit2, xinit3;
                xinit2 = x+dxx+state.s95;
                    
                if((state.IsLoadOpen || state.IsLoadImaginary) && Gamma_plusone){
		    MaestroG.subscripter("= "+infinity,"","",g,fontoint,xinit2,y);
                    g.drawString("=  (Open Circuit)  " ,xinit2,y+dy);
                    y+=dy;
		}
		else if((state.IsLoadOpen || state.IsLoadImaginary) && Gamma_minusone){
		    MaestroG.subscripter("= 0.0 + j 0.0","","",g,fonto,xinit2,y);
                    //MaestroG.SansMiditalic("= 0.0","  \u2220 ",""+0.0+" rad",g,fonto,xinit2,y+dy);
		    MaestroG.TxtImgTxt("= 0.0",angle_img,""+0.0+" rad",g,fonto,xinit2,y+dy,this);
                    y+=dy;
		}
		else if((state.IsLoadShort || state.IsLoadImaginary) && Gamma_plusone){
		    MaestroG.subscripter("= "+infinity,"","",g,fontoint,xinit2,y);
                    g.drawString("=  (Open Circuit)  " ,xinit2,y+dy);
                    y+=dy;
		}
		else if((state.IsLoadShort || state.IsLoadImaginary) && Gamma_minusone){
		    MaestroG.subscripter("= 0.0 + j 0.0","","",g,fonto,xinit2,y);
                    //MaestroG.SansMiditalic("= 0.0","  \u2220 ",""+0.0+" rad",g,fonto,xinit2,y+dy);
		    MaestroG.TxtImgTxt("= 0.0",angle_img,""+0.0+" rad",g,fonto,xinit2,y+dy,this);
                    y+=dy;
		}
   
		else{
                
                    tempR=0.0; tempX=0.0;
                    stepx = 0;
                    
		    if(Complex.Imaginary(state.Zin) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(state.IsLoadImaginary || state.IsLoadOpen || state.IsLoadShort){
			tempR = 0.0;
		    }
		    else if(state.IsLoadRegular){
			tempR = state.Zin.Real();
		    }
		    
		    if(tempR < 1.0E3 && tempR >= 1.0E-3){
			MaestroG.superscripter("= "+dec.format(tempR),"","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("= 0.0","","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= 0.0 ");
		    }
		    else if(tempR < 1.0E6 && tempR >= 1.0E3){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-3)+" x 10","3","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-3)+"x 10 3");
		    }
		    else if(tempR < 1.0E9 && tempR >= 1.0E6){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-6)+" x 10","6","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-6)+"x 10 6");
		    }
		    else if(tempR < 1.0E12 && tempR >= 1.0E9){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-9)+" x 10","9","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-9)+"x 10 9");
		    }
		    else if(tempR < 1.0E15 && tempR >= 1.0E12){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-12)+" x 10","12","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-12)+"x 10 12");
		    }
		    else if(tempR < 1.0E18 && tempR >= 1.0E15){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-15)+" x 10","15","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-15)+"x 10 15");
		    }
		    else if(tempR < 1.0E21 && tempR >= 1.0E18){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-18)+" x 10","18","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-18)+"x 10 18");
		    }
		    else if(tempR < 1.0E24 && tempR >= 1.0E21){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-21)+" x 10","21","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-21)+"x 10 21");
		    }
		    else if(tempR < 1.0E27 && tempR >= 1.0E24){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-24)+" x 10","24","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-24)+"x 10 24");
		    }
		    else if(tempR < 1.0E30 && tempR >= 1.0E27){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-27)+" x 10","27","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-27)+"x 10 27");
		    }
		    else if(tempR >= 1.0E30){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-30)+" x 10","30","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-30)+"x 10 30");
		    }
		    else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E6)+" x 10","-6","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E6)+"x 10 -6");
		    }
		    else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E9)+" x 10","-9","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E9)+"x 10 -9");
		    }
		    else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E12)+" x 10","-12","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E12)+"x 10 -12");
		    }
		    else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E15)+" x 10","-15","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E15)+"x 10 -15");
		    }
		    else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E18)+" x 10","-18","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E18)+"x 10 -18");
		    }
		    else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E21)+" x 10","-21","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E21)+"x 10 -21");
		    }
		    else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E24)+" x 10","-24","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E24)+"x 10 -24");
		    }
                    else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E27)+" x 10","-27","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E27)+"x 10 -27");
		    }
                    else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E30)+" x 10","-30","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E30)+"x 10 -30");
		    }
                    else if(tempR < 1.0E-30 && tempR != 0.0){
			MaestroG.superscripter("= 0.0","","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= 0.0");
		    }
		    
		    tempX = Math.abs(state.Zin.Imaginary());
		    xinit3 = xinit2+stepx;
		    
		    if(tempX < 1.0E3 && tempX >= 1.0E-3){
			MaestroG.superscripter(sign+""+dec.format(tempX),"","",g,fonto,xinit3,y);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E6 && tempX >= 1.0E3){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-3)+" x 10","3","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E9 && tempX >= 1.0E6){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-6)+" x 10","6","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E12 && tempX >= 1.0E9){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-9)+" x 10","9","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E15 && tempX >= 1.0E12){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-12)+" x 10","12","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E18 && tempX >= 1.0E15){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-15)+" x 10","15","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E21 && tempX >= 1.0E18){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-18)+" x 10","18","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E24 && tempX >= 1.0E21){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-21)+" x 10","21","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E27 && tempX >= 1.0E24){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-24)+" x 10","24","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E30 && tempX >= 1.0E27){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-27)+" x 10","27","",g,fonto,xinit3,y);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-30)+" x 10","30","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E-3 && tempX >= 1.0E-6){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E6)+" x 10","-6","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E-6 && tempX >= 1.0E-9){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E9)+" x 10","-9","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E-9 && tempX >= 1.0E-12){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E12)+" x 10","-12","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E-12 && tempX >= 1.0E-15){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E15)+" x 10","-15","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E-15 && tempX >= 1.0E-18){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E18)+" x 10","-18","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E-18 && tempX >= 1.0E-21){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E21)+" x 10","-21","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E-21 && tempX >= 1.0E-24){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E24)+" x 10","-24","",g,fonto,xinit3,y);
		    }
                    else if(tempX < 1.0E-24 && tempX >= 1.0E-27){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E27)+" x 10","-27","",g,fonto,xinit3,y);
		    }
                    else if(tempX < 1.0E-27 && tempX >= 1.0E-30){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E30)+" x 10","-30","",g,fonto,xinit3,y);
		    }
                    else if(tempX < 1.0E-30 && tempX != 0.0){
			MaestroG.superscripter(sign+" 0.0","","",g,fonto,xinit3,y);
		    }
		//}
                
                ///-----------------------------------------------------------------------       
                
                y += dy;
           	    
		    tempR = Complex.Magnitude(state.Zin);
                    double dtmp2;
     
                    if(tempR == 0.0){dtmp2 = 0.0;}
                    else{dtmp2=MaestroA.rounder(state.Zin.Arg2(),4);}
                
                    		    
		    if(tempR < 1.0E3 && tempR >= 1.0E-3){
                        //MaestroG.SansMiditalic("= "+dec.format(tempR),"  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtImgTxt("= "+MaestroA.rounder(tempR,6),angle_img,""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR == 0.0){
			//MaestroG.SansMiditalic("= 0.0","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtImgTxt("= 0.0",angle_img,""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E6 && tempR >= 1.0E3){
                        //MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-3)+" x 10","3","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-3,2)+" x 10","3",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E9 && tempR >= 1.0E6){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-6)+" x 10","6","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-6,2)+" x 10","6",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E12 && tempR >= 1.0E9){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-9)+" x 10","9","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-9,2)+" x 10","9",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E15 && tempR >= 1.0E12){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-12)+" x 10","12","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-12,2)+" x 10","12",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E18 && tempR >= 1.0E15){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-15)+" x 10","15","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-15,2)+" x 10","15",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E21 && tempR >= 1.0E18){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-18)+" x 10","18","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-18,2)+" x 10","18",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E24 && tempR >= 1.0E21){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-21)+" x 10","21","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-21,2)+" x 10","21",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E27 && tempR >= 1.0E24){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-24)+" x 10","24","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-24,2)+" x 10","24",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E30 && tempR >= 1.0E27){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-27)+" x 10","27","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-27,2)+" x 10","27",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR >= 1.0E30){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-30)+" x 10","30","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-30,2)+" x 10","30",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E6)+" x 10","-6","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E6,2)+" x 10","-6",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E9)+" x 10","-9","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E9,2)+" x 10","-9",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E12)+" x 10","-12","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E12,2)+" x 10","-12",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E15)+" x 10","-15","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E15,2)+" x 10","-15",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E18)+" x 10","-18","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E18,2)+" x 10","-18",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E21)+" x 10","-21","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E21,2)+" x 10","-21",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E24)+" x 10","-24","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E24,2)+" x 10","-24",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
                    else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E27)+" x 10","-27","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E27,2)+" x 10","-27",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
                    else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E30)+" x 10","-30","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E30,2)+" x 10","-30",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
                    else if(tempR < 1.0E-30 && tempR != 0.0){
			//MaestroG.SansMiditalic("= 0.0","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtImgTxt("= 0.0",angle_img,""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
            }


            y+=dy;
            
            g.setColor(Color.red);
            g.drawString("Admittance",x,y);
            g.drawString("  [ S ]",x,y+dy);  
            g.setColor(Color.black); 
            
            MaestroG.subscripter("Y","","(d)",g,fonto,x+dx,y);
               
                xinit2 = x+dxx+state.s95;
                    
                if((state.IsLoadOpen || state.IsLoadImaginary) && Gamma_plusone){
		    MaestroG.subscripter("= 0.0 + j 0.0","","",g,fonto,xinit2,y);
                    //MaestroG.SansMiditalic("= 0.0","  \u2220 ",""+0.0+" rad",g,fonto,xinit2,y+dy);
		    MaestroG.TxtImgTxt("= 0.0",angle_img,""+0.0+" rad",g,fonto,xinit2,y+dy,this);
                    y+=dy;
		}
		else if((state.IsLoadOpen || state.IsLoadImaginary) && Gamma_minusone){
                    MaestroG.subscripter("= "+infinity,"","",g,fontoint,xinit2,y);
                    g.drawString("=  (Short Circuit)  " ,xinit2,y+dy);
                    y+=dy;
		}
		else if((state.IsLoadShort || state.IsLoadImaginary) && Gamma_plusone){
		    MaestroG.subscripter("= 0.0 + j 0.0","","",g,fonto,xinit2,y);
                    //MaestroG.SansMiditalic("= 0.0","  \u2220 ",""+0.0+" rad",g,fonto,xinit2,y+dy);
		    MaestroG.TxtImgTxt("= 0.0",angle_img,""+0.0+" rad",g,fonto,xinit2,y+dy,this);
                    y+=dy;
		}
		else if((state.IsLoadShort || state.IsLoadImaginary) && Gamma_minusone){
		    MaestroG.subscripter("= "+infinity,"","",g,fontoint,xinit2,y);
                    g.drawString("=  (Short Circuit)  " ,xinit2,y+dy);
                    y+=dy;
		}
   
		else{
                
                    tempR=0.0; tempX=0.0;
                    stepx = 0;
                    
		    if(Complex.Imaginary(state.Yin) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(state.IsLoadImaginary || state.IsLoadOpen || state.IsLoadShort){
			tempR = 0.0;
		    }
		    else if(state.IsLoadRegular){
			tempR = state.Yin.Real();
		    }
		    
		    if(tempR < 1.0E3 && tempR >= 1.0E-3){
			//MaestroG.superscripter("= "+dec.format(tempR),"","",g,fonto,xinit2,y);
			//stepx = fm.stringWidth("= "+dec.format(tempR));
			MaestroG.superscripter("= "+dec.format(tempR),"","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("= 0.0","","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= 0.0 ");
		    }
		    else if(tempR < 1.0E6 && tempR >= 1.0E3){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-3)+" x 10","3","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-3)+"x 10 3");
		    }
		    else if(tempR < 1.0E9 && tempR >= 1.0E6){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-6)+" x 10","6","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-6)+"x 10 6");
		    }
		    else if(tempR < 1.0E12 && tempR >= 1.0E9){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-9)+" x 10","9","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-9)+"x 10 9");
		    }
		    else if(tempR < 1.0E15 && tempR >= 1.0E12){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-12)+" x 10","12","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-12)+"x 10 12");
		    }
		    else if(tempR < 1.0E18 && tempR >= 1.0E15){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-15)+" x 10","15","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-15)+"x 10 15");
		    }
		    else if(tempR < 1.0E21 && tempR >= 1.0E18){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-18)+" x 10","18","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-18)+"x 10 18");
		    }
		    else if(tempR < 1.0E24 && tempR >= 1.0E21){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-21)+" x 10","21","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-21)+"x 10 21");
		    }
		    else if(tempR < 1.0E27 && tempR >= 1.0E24){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-24)+" x 10","24","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-24)+"x 10 24");
		    }
		    else if(tempR < 1.0E30 && tempR >= 1.0E27){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-27)+" x 10","27","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-27)+"x 10 27");
		    }
		    else if(tempR >= 1.0E30){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E-30)+" x 10","30","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E-30)+"x 10 30");
		    }
		    else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E6)+" x 10","-6","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E6)+"x 10 -6");
		    }
		    else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E9)+" x 10","-9","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E9)+"x 10 -9");
		    }
		    else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E12)+" x 10","-12","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E12)+"x 10 -12");
		    }
		    else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E15)+" x 10","-15","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E15)+"x 10 -15");
		    }
		    else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E18)+" x 10","-18","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E18)+"x 10 -18");
		    }
		    else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E21)+" x 10","-21","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E21)+"x 10 -21");
		    }
		    else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E24)+" x 10","-24","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E24)+"x 10 -24");
		    }
                    else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E27)+" x 10","-27","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E27)+"x 10 -27");
		    }
                    else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
			MaestroG.superscripter("= "+dec.format(tempR*1.0E30)+" x 10","-30","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR*1.0E30)+"x 10 -30");
		    }
                    else if(tempR < 1.0E-30 && tempR != 0.0){
			MaestroG.superscripter("= 0.0","","",g,fonto,xinit2,y);
			stepx = fm.stringWidth("= 0.0");
		    }
		    
		    tempX = Math.abs(state.Yin.Imaginary());
		    xinit3 = xinit2+stepx;
		    
		    if(tempX < 1.0E3 && tempX >= 1.0E-3){
			MaestroG.superscripter(sign+""+dec.format(tempX),"","",g,fonto,xinit3,y);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E6 && tempX >= 1.0E3){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-3)+" x 10","3","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E9 && tempX >= 1.0E6){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-6)+" x 10","6","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E12 && tempX >= 1.0E9){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-9)+" x 10","9","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E15 && tempX >= 1.0E12){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-12)+" x 10","12","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E18 && tempX >= 1.0E15){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-15)+" x 10","15","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E21 && tempX >= 1.0E18){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-18)+" x 10","18","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E24 && tempX >= 1.0E21){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-21)+" x 10","21","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E27 && tempX >= 1.0E24){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-24)+" x 10","24","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E30 && tempX >= 1.0E27){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-27)+" x 10","27","",g,fonto,xinit3,y);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-30)+" x 10","30","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E-3 && tempX >= 1.0E-6){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E6)+" x 10","-6","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E-6 && tempX >= 1.0E-9){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E9)+" x 10","-9","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E-9 && tempX >= 1.0E-12){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E12)+" x 10","-12","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E-12 && tempX >= 1.0E-15){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E15)+" x 10","-15","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E-15 && tempX >= 1.0E-18){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E18)+" x 10","-18","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E-18 && tempX >= 1.0E-21){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E21)+" x 10","-21","",g,fonto,xinit3,y);
		    }
		    else if(tempX < 1.0E-21 && tempX >= 1.0E-24){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E24)+" x 10","-24","",g,fonto,xinit3,y);
		    }
                    else if(tempX < 1.0E-24 && tempX >= 1.0E-27){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E27)+" x 10","-27","",g,fonto,xinit3,y);
		    }
                    else if(tempX < 1.0E-27 && tempX >= 1.0E-30){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E30)+" x 10","-30","",g,fonto,xinit3,y);
		    }
                    else if(tempX < 1.0E-30 && tempX != 0.0){
			MaestroG.superscripter(sign+" 0.0","","",g,fonto,xinit3,y);
		    }
		//}
                
                ///-----------------------------------------------------------------------       
                
                y += dy;
           	    
		    tempR = Complex.Magnitude(state.Yin);
                    double dtmp2;
     
                    if(tempR == 0.0){dtmp2 = 0.0;}
                    else{dtmp2=MaestroA.rounder(state.Yin.Arg2(),4);}
                
		    if(tempR < 1.0E3 && tempR >= 1.0E-3){
			// MaestroG.SansMiditalic("= "+dec.format(tempR),"  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtImgTxt("= "+MaestroA.rounder(tempR,6),angle_img,""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR == 0.0){
			//MaestroG.SansMiditalic("= 0.0","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtImgTxt("= 0.0",angle_img,""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E6 && tempR >= 1.0E3){
                        //MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-3)+" x 10","3","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-3,2)+" x 10","3",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E9 && tempR >= 1.0E6){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-6)+" x 10","6","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-6,2)+" x 10","6",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E12 && tempR >= 1.0E9){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-9)+" x 10","9","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-9,2)+" x 10","9",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E15 && tempR >= 1.0E12){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-12)+" x 10","12","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-12,2)+" x 10","12",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E18 && tempR >= 1.0E15){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-15)+" x 10","15","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-15,2)+" x 10","15",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E21 && tempR >= 1.0E18){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-18)+" x 10","18","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-18,2)+" x 10","18",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E24 && tempR >= 1.0E21){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-21)+" x 10","21","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-21,2)+" x 10","21",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E27 && tempR >= 1.0E24){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-24)+" x 10","24","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-24,2)+" x 10","24",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E30 && tempR >= 1.0E27){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-27)+" x 10","27","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-27,2)+" x 10","27",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR >= 1.0E30){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-30)+" x 10","30","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E-30,2)+" x 10","30",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E6)+" x 10","-6","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E6,2)+" x 10","-6",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E9)+" x 10","-9","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E9,2)+" x 10","-9",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E12)+" x 10","-12","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E12,2)+" x 10","-12",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E15)+" x 10","-15","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E15,2)+" x 10","-15",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E18)+" x 10","-18","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E18,2)+" x 10","-18",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E21)+" x 10","-21","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E21,2)+" x 10","-21",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
		    else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E24)+" x 10","-24","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E24,2)+" x 10","-24",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
                    else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E27)+" x 10","-27","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E27,2)+" x 10","-27",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
                    else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
			//MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E30)+" x 10","-30","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtSuperImgTxt("= "+MaestroA.rounder(tempR*1.0E30,2)+" x 10","-30",angle_img,
						""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
                    else if(tempR < 1.0E-30 && tempR != 0.0){
			//MaestroG.SansMiditalic("= 0.0","  \u2220 ",""+dtmp2+" rad",g,fonto,xinit2,y);
			MaestroG.TxtImgTxt("= 0.0",angle_img,""+dtmp2+" rad",g,fonto,xinit2,y,this);
		    }
            }
            
	    g.setColor(Color.black);	
            g.drawLine(state.s5,y+dyy/3,getSize().width-state.s5,y+dyy/3);
	    y += dyy;
	    
	    g.setColor(Color.red);	    	    
	    g.drawString("Reflection",x,y);
	    
	    g.setColor(Color.black);
	    MaestroG.subscripterSS3(""+Gamma,"d","",g,fonto,x+dx,y);
	    //g.drawString("= "+state.Gammain.toString(Complex.CARTESIAN,8,false),xinit2,y);
	    g.drawString("= "+state.Gammain.toString(Complex.CARTESIAN,3,false),xinit2,y);
	    y += dy;
	    
	    g.setColor(Color.red);	
	    g.drawString("Coefficient",x,y);
	    g.setColor(Color.black);
            
                double gtmp1, gtmp2, gtmp3;
                    //gtmp1=MaestroA.rounder(state.Gammain.Magnitude(),8);
                    gtmp1=MaestroA.rounder(state.Gammain.Magnitude(),3);
                    if(gtmp1 == 0.0){gtmp2 = 0.0; gtmp3 = 0.0;}
                    else{
                        gtmp2=MaestroA.rounder(state.Gammain.Arg2(),3);
                        gtmp3=MaestroA.rounder(state.Gammain.Arg2()*180/Math.PI,3);
                   }
		    //MaestroG.SansMiditalic("= "+gtmp1,"  \u2220 ",""+gtmp2+" rad",g,fonto,xinit2,y);
		    MaestroG.TxtImgTxt("= "+gtmp1,angle_img,""+gtmp2+" rad",g,fonto,xinit2,y,this);
		    y += dy;
		    //MaestroG.SansMiditalic("= "+gtmp1,"  \u2220 ",""+gtmp3+" \u00ba",g,fonto,xinit2,y);
		    MaestroG.TxtImgTxt("= "+gtmp1,angle_img,""+gtmp3+" \u00ba",g,fonto,xinit2,y,this);
	    
            g.setColor(Color.white);
	    g.drawLine(state.s5,y+dyy/3,getSize().width-state.s5,y+dyy/3);    
	    y += dyy;
	    
	    g.setColor(Color.red);
	    g.drawString("Voltage Standing Wave Ratio",x,y);	
	    y += dy;
	    g.setColor(Color.black);
	    
	    if(state.VSWR > 1.0e15){
		g.drawString("SWR",x+dxx,y);
                MaestroG.subscripter("= "+infinity,"","",g,fontoint,x+dxx+state.s30,y);
		//g.drawString("\u221e",x+dxx+state.s40,y);
            }
	    else{	
		//g.drawString("SWR = "+dec.format(state.VSWR),x+dxx,y);
		g.drawString("SWR = "+dec.format(state.VSWR),x+dxx,y);
	    }	
	    g.setColor(Color.black);	
	    
	    g.drawLine(state.s5,y+dyy/4,getSize().width-state.s5,y+dyy/4);  
	    y+= dyy;
	    
	    g.setColor(Color.red);
	    g.drawString("Location of First Voltage Maximum & Minimum",x,y);
	    y+= dy;
	    
	    g.setColor(Color.black);
	    //g.drawString("d(max) = "+dec.format(dmax,5),x+dxx,y);
	    MaestroG.subscripterSanSym2("d (max) = "+dec.format(dmax)+"","","",""+lambda,g,fonto,x+dxx,y);
            
	    g.setFont(newnormalfont);
	    
	    g.setColor(Color.black);
	    testlength = dmax*state.wavelength;
	        
	    if(testlength < 1.0E-9 && testlength > 0.0){
		g.drawString("         = "+dec.format(dmax*state.wavelength*1.0e9)+"   [ nm ]",x+dxxx,y);	
	    }
	    else if(testlength < 1.0E-6 && testlength >= 1.0E-9){
		g.drawString("         = "+dec.format(dmax*state.wavelength*1.0e9)+"   [ nm ]",x+dxxx,y);	
	    }
	    else if(testlength < 1.0E-3 && testlength >= 1.0E-6){
		g.drawString("         = "+dec.format(dmax*state.wavelength*1.0e6)+"   [ \u00b5m ]",x+dxxx,y);	
	    }
	    else if(testlength < 1.0 && testlength >= 1.0E-3){
		g.drawString("         = "+dec.format(dmax*state.wavelength*1000)+"   [ mm ]",x+dxxx,y);	
	    }
	    else if((testlength < 1000.0 && testlength >= 1.0 ) || testlength == 0.0){
		g.drawString("         = "+dec.format(dmax*state.wavelength)+"   [ m ]",x+dxxx,y);	
	    }
	    else if(testlength >= 1000.0 && testlength < 1.0E6){
		g.drawString("         = "+dec.format(dmax*state.wavelength/1000.0)+"   [ km ]",x+dxxx,y);	
	    }
	    else if(testlength >= 1.0E6 && testlength < 1.0E9){
		//g.drawString("         = "+dec.format(dmax*state.wavelength/1.0E6)+"   [ Mm ]",x+dxxx,y);	
                MaestroG.superscripter("         = "+dec.format(dmax*state.wavelength/1.0E6)+"   [ 10","3"," km ]",g,fonto,x+dxxx,y);
	    }
	    else if(testlength >= 1.0E9){
		//g.drawString("         = "+dec.format(dmax*state.wavelength/1.0E9)+"   [ Gm ]",x+dxxx,y);
                MaestroG.superscripter("         = "+dec.format(dmax*state.wavelength/1.0E9)+"   [ 10","6"," km ]",g,fonto,x+dxxx,y);
	    }
	   
	  	    
	    y+=dy;
	    
	    MaestroG.subscripterSanSym2("d (min) = "+dec.format(dmin)+"","","",""+lambda,g,fonto,x+dxx+4,y);
            
	    g.setFont(newnormalfont);
	    g.setColor(Color.black);
	    testlength = dmin*state.wavelength;
	        
	    if(testlength < 1.0E-9 && testlength > 0.0){
		g.drawString("         = "+dec.format(dmin*state.wavelength*1.0e9)+"   [ nm ]",x+dxxx,y);	
	    }
	    else if(testlength < 1.0E-6 && testlength >= 1.0E-9){
		g.drawString("         = "+dec.format(dmin*state.wavelength*1.0e9)+"   [ nm ]",x+dxxx,y);	
	    }
	    else if(testlength < 1.0E-3 && testlength >= 1.0E-6){
		g.drawString("         = "+dec.format(dmin*state.wavelength*1.0e6)+"   [ \u00b5m ]",x+dxxx,y);	
	    }
	    else if(testlength < 1.0 && testlength >= 1.0E-3){
		g.drawString("         = "+dec.format(dmin*state.wavelength*1000)+"   [ mm ]",x+dxxx,y);	
	    }
	    else if((testlength < 1000.0 && testlength >= 1.0 ) || testlength == 0.0){
		g.drawString("         = "+dec.format(dmin*state.wavelength)+"   [ m ]",x+dxxx,y);	
	    }
	    else if(testlength >= 1000.0 && testlength < 1.0E6){
		g.drawString("         = "+dec.format(dmin*state.wavelength/1000.0)+"   [ km ]",x+dxxx,y);	
	    }
	    else if(testlength >= 1.0E6 && testlength < 1.0E9){
		//g.drawString("         = "+dec.format(dmin*state.wavelength/1.0E6)+"   [ Mm ]",x+dxxx,y);
                MaestroG.superscripter("         = "+dec.format(dmin*state.wavelength/1.0E6)+"   [ 10","3"," km ]",g,fonto,x+dxxx,y);
	    }
	    else if(testlength >= 1.0E9){
		//g.drawString("         = "+dec.format(dmin*state.wavelength/1.0E9)+"   [ Gm ]",x+dxxx,y);
                MaestroG.superscripter("         = "+dec.format(dmin*state.wavelength/1.0E9)+"   [ 10","6"," km ]",g,fonto,x+dxxx,y);
	    }
	    
	    y+= state.s18;
	    
            g.setColor(Color.red);
	    g.drawString("Wavelength",x,y);
	    g.setColor(Color.black);
	    MaestroG.subscripterSanSym2("","","",""+lambda,g,state.font12,x+10+fm.stringWidth("Wavelength"),y);
            
            g.setFont(newnormalfont);
	    
	    testlength = state.wavelength;
	        
	    if(testlength < 1.0E-9 && testlength > 0.0){
		g.drawString("         = "+dec.format(state.wavelength*1.0e9)+"   [ nm ]",x+dxxxx,y);	
	    }
	    else if(testlength < 1.0E-6 && testlength >= 1.0E-9){
		g.drawString("         = "+dec.format(state.wavelength*1.0e9)+"   [ nm ]",x+dxxxx,y);	
	    }
	    else if(testlength < 1.0E-3 && testlength >= 1.0E-6){
		g.drawString("         = "+dec.format(state.wavelength*1.0e6)+"   [ \u00b5m ]",x+dxxxx,y);	
	    }
	    else if(testlength < 1.0 && testlength >= 1.0E-3){
		g.drawString("         = "+dec.format(state.wavelength*1000)+"   [ mm ]",x+dxxxx,y);	
	    }
	    else if((testlength < 1000.0 && testlength >= 1.0 ) || testlength == 0.0){
		g.drawString("         = "+dec.format(state.wavelength)+"   [ m ]",x+dxxxx,y);	
	    }
	    else if(testlength >= 1000.0 && testlength < 1.0E6){
		g.drawString("         = "+dec.format(state.wavelength/1000.0)+"   [ km ]",x+dxxxx,y);	
	    }
	    else if(testlength >= 1.0E6 && testlength < 1.0E9){
		//g.drawString("         = "+dec.format(state.wavelength/1.0E6)+"   [ Mm ]",x+dxxxx,y);	
                MaestroG.superscripter("         = "+dec.format(state.wavelength/1.0E6)+"   [ 10","3"," km ]",g,fonto,x+dxxxx,y);
	    }
	    else if(testlength >= 1.0E9){
		//g.drawString("         = "+dec.format(state.wavelength/1.0E9)+"   [ Gm ]",x+dxxxx,y);	
                MaestroG.superscripter("         = "+dec.format(state.wavelength/1.0E9)+"   [ 10","6"," km ]",g,fonto,x+dxxxx,y);
	    }
	}
}

class SpaceIndependentCanvas extends Canvas{
	private static final Font normalfont = TheFonts.sanSerif12;
	private static final Font symbolfont = TheFonts.symbol12;
	private static final Font subfont    = TheFonts.sanSerif10;
	private Image im;
	private Graphics buf;
	Trans_State state;
        DecimalFormat dec = new DecimalFormat("0.###"); //"0.###E0"
	public SpaceIndependentCanvas(Trans_State state){
	    super();
	    this.state = state;
	}
	
	public void paint(Graphics g){
	    if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawGraph(buf);
	    }
	    else{
		drawGraph(buf);
	    }
	    g.drawImage(im,0,0,null);
	}
	
	//Addition to reduce flicker new routine
	public void update(Graphics g){		// added to avoid clearing
	    paint(g);
	}
	
	public void drawGraph(Graphics g){
	    int x, y, dx, dxx, dy, dyy;
	    double temp;
	    Complex tempc;
	    FontMetrics fm;

		float dmax, dmin;
		if(state.ZL.Imaginary()>0.0f){
		    dmax=(float)((state.GammaL.Arg2())/(4.0*Math.PI));
		    dmin=dmax+0.25f;
		}
		else{
		    dmax=(float)((state.GammaL.Arg2())/(4.0*Math.PI))+0.5f;
		    dmin=(float)((state.GammaL.Arg2())/(4.0*Math.PI))+0.25f;
		}

		while(dmax>0.5f) dmax=dmax-0.5f;
		while(dmin>0.5f) dmin=dmin-0.5f; 
	    
	    
	    x = 10;
	    y = 15;
	    dx = 80;
	    dxx = 15;
	    //g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    dy = fm.getHeight()-1;
	    dyy = dy+5;
	    g.clearRect(0,0,getSize().width,getSize().height);
	    g.setColor(Color.red);
	    g.drawString("Voltage Standing Wave Ratio",x,y);	
	    y += dy;
	    g.setColor(Color.black);
	    
	    if(state.VSWR > 1.0e15){
		g.drawString("VSWR =",x+dxx,y);
		g.setFont(symbolfont);
		g.drawString("\u221e",x+dxx+60,y);
		g.setFont(normalfont);
		}
	    else{	
		//g.drawString("VSWR = "+dec.format(state.VSWR),x+dxx,y);
		g.drawString("VSWR = "+dec.format(state.VSWR),x+dxx,y);
	    }	
	    g.setColor(Color.white);	
	    g.drawLine(5,y+dyy/4,getSize().width-5,y+dyy/4); 
	    
	    y += dyy;
	    g.setColor(Color.red);
	    g.drawString("Amplitude of Incident Voltage Wave",x,y);
	    g.setColor(Color.black);
	    
	    y+= dy;
	    
	    if(Complex.Magnitude(state.VPlus)>=1 && Complex.Magnitude(state.VPlus)<1.0E3 
			|| Complex.Magnitude(state.VPlus)==0.0){
		
		g.setColor(Color.black);
		g.drawString("V+    = "+state.VPlus.toString(Complex.CARTESIAN,5)+" [ V ]",x+dxx,y);
		y += dy;
		g.drawString("         = "+state.VPlus.toString(Complex.POLAR_RADIAN,5)+" [ V ]",x+dxx,y);
	    }
	    
	    else if (Complex.Magnitude(state.VPlus)<1.0E6 && Complex.Magnitude(state.VPlus)>=1.0E3){
		
		g.setColor(Color.black);
		tempc = Complex.Multiply(state.VPlus,1.0E-3);
		g.drawString("V+    = "+tempc.toString(Complex.CARTESIAN)+" [ kV ]",x+dxx,y);
		y += dy;
		g.drawString("         = "+tempc.toString(Complex.POLAR_RADIAN)+" [ kV ]",x+dxx,y);   
	    }
	    else if (Complex.Magnitude(state.VPlus)>=1.0E6){
		
		g.setColor(Color.black);
		tempc = Complex.Multiply(state.VPlus,1.0E-6);
		g.drawString("V+    = "+tempc.toString(Complex.CARTESIAN)+" [ MV ]",x+dxx,y);
		y += dy;
		g.drawString("         = "+tempc.toString(Complex.POLAR_RADIAN)+" [ MV ]",x+dxx,y);   
	    }
	    
	    else if (Complex.Magnitude(state.VPlus)<1.0 && Complex.Magnitude(state.VPlus)>=0.001){
		
		g.setColor(Color.black);
		tempc = Complex.Multiply(state.VPlus,1.0E3);
		g.drawString("V+    = "+tempc.toString(Complex.CARTESIAN)+" [ mV ]",x+dxx,y);
		y += dy;
		g.drawString("         = "+tempc.toString(Complex.POLAR_RADIAN)+" [ mV ]",x+dxx,y);   
	    }
	    else if (Complex.Magnitude(state.VPlus)<0.001 && Complex.Magnitude(state.VPlus)>=1.0E-6){
		
		g.setColor(Color.black);
		tempc = Complex.Multiply(state.VPlus,1.0E6);
		g.drawString("V+    = "+tempc.toString(Complex.CARTESIAN)+" [ \u00b5V ]",x+dxx,y);
		y += dy;
		g.drawString("         = "+tempc.toString(Complex.POLAR_RADIAN)+" [ \u00b5V ]",x+dxx,y);   
	    }
	    else if (Complex.Magnitude(state.VPlus)<1.0E-6 && Complex.Magnitude(state.VPlus)>=1.0E-9){
		
		g.setColor(Color.black);
		tempc = Complex.Multiply(state.VPlus,1.0E9);
		g.drawString("V+    = "+tempc.toString(Complex.CARTESIAN)+" [ nV ]",x+dxx,y);
		y += dy;
		g.drawString("         = "+tempc.toString(Complex.POLAR_RADIAN)+" [ nV ]",x+dxx,y);   
	    }
	    else if (Complex.Magnitude(state.VPlus)<1.0E-9 && Complex.Magnitude(state.VPlus)>=1.0E-12){
		
		g.setColor(Color.black);
		tempc = Complex.Multiply(state.VPlus,1.0E12);
		g.drawString("V+     = "+tempc.toString(Complex.CARTESIAN)+" [ pV ]",x+dxx,y);
		y += dy;
		g.drawString("         = "+tempc.toString(Complex.POLAR_RADIAN)+" [ pV ]",x+dxx,y);   
	    }
	    else if (Complex.Magnitude(state.VPlus)<1.0E-12 && Complex.Magnitude(state.VPlus)>=1.0E-15){
		
		g.setColor(Color.black);
		tempc = Complex.Multiply(state.VPlus,1.0E15);
		g.drawString("V+     = "+tempc.toString(Complex.CARTESIAN)+" [ fV ]",x+dxx,y);
		y += dy;
		g.drawString("         = "+tempc.toString(Complex.POLAR_RADIAN)+" [ fV ]",x+dxx,y);   
	    }
	    else if (Complex.Magnitude(state.VPlus)<1.0E-15){
		
		g.setColor(Color.black);
		tempc = Complex.Multiply(state.VPlus,1.0E18);
		g.drawString("V+     = "+tempc.toString(Complex.CARTESIAN)+" [ aV ]",x+dxx,y);
		y += dy;
		g.drawString("         = "+tempc.toString(Complex.POLAR_RADIAN)+" [ aV ]",x+dxx,y);   
	    }
	    
	    /*
	    g.drawString("V+ = "+state.VPlus.toString(Complex.CARTESIAN)+"  [ V ]",x+dxx,y);
	    y+=dy;
	    g.drawString(" = "
			+state.VPlus.toString(Complex.POLAR_RADIAN)+"  [ V ]",x+dxx+dxx-1,y);
	    */
	    
	    
	    g.drawLine(5,y+dyy/4,getSize().width-5,y+dyy/4);  
	    y+= dyy;
	    
	    g.setColor(Color.red);
	    g.drawString("Location of First Voltage Maximum & Minimum",x,y);
	    y+= dy;
	    
	    g.setColor(Color.black);
	    g.drawString("d(max) = "+dec.format(dmax),x+dxx,y);
	    g.drawString("  [      ]",x+150,y);
	    g.setFont(symbolfont);
	    g.drawString("\u03bb",x+165,y);
	    g.setFont(normalfont);
	    
	    y+=dy;
	    
	    g.drawString("d(min) = "+dec.format(dmin),x+dxx,y);
	    g.drawString("  [      ]",x+150,y);
	    g.setFont(symbolfont);
	    g.drawString("\u03bb",x+165,y);
	    g.setFont(normalfont);
	    
	    g.setColor(Color.white);	
    	    g.drawLine(5,y+dyy/4,getSize().width-5,y+dyy/4);
	    
	    
	    g.setColor(Color.red);
	    y += dyy;
	    g.drawString("TIME-AVERAGE POWER", x, y);
	    y+= dy;
	    g.setColor(Color.blue);
	    g.drawString("Injected by input wave",x+dx+dx,y);
	    g.setColor(Color.black);
	    if(state.Pw[3]>=1.0 && state.Pw[3]<1.0E3 || state.Pw[3]==0.0){
		g.drawString("P( in ) = "+dec.format(state.Pw[3])+" [ W ]",x,y);
	    }
	    else if(state.Pw[3]<1.0E6 && state.Pw[3]>=1.0E3){
		temp = state.Pw[3]*1.0E-3;
		g.drawString("P( in ) = "+dec.format(temp)+" [ k W ]",x,y);
	    }
	    else if(state.Pw[3]>=1.0E6){
		temp = state.Pw[3]*1.0E-6;
		g.drawString("P( in ) = "+dec.format(temp)+" [ M W ]",x,y);
	    }
	    else if(state.Pw[3]<1.0 && state.Pw[3]>=0.001){
		temp = state.Pw[3]*1000;
		g.drawString("P( in ) = "+dec.format(temp)+" [ m W ]",x,y);
	    }
	    else if(state.Pw[3]<0.001 && state.Pw[3]>=1.0E-6){
		temp = state.Pw[3]*1.0E6;
		g.drawString("P( in ) = "+dec.format(temp)+" [ \u00b5 W ]",x,y);
	    }
	    else if(state.Pw[3]<1.0E-6 && state.Pw[3]>=1.0E-9){
		temp = state.Pw[3]*1.0E9;
		g.drawString("P( in ) = "+dec.format(temp)+" [ n W ]",x,y);
	    }
	    else if(state.Pw[3]<1.0E-9 && state.Pw[3]>=1.0E-12){
		temp = state.Pw[3]*1.0E12;
		g.drawString("P( in ) = "+dec.format(temp)+" [ p W ]",x,y);
	    }
	    else if(state.Pw[3]<1.0E-12 && state.Pw[3]>=1.0E-15){
		temp = state.Pw[3]*1.0E15;
		g.drawString("P( in ) = "+dec.format(temp)+" [ f W ]",x,y);
	    }
	    else if(state.Pw[3]<1.0E-15 && state.Pw[3]>=1.0E-18){
		temp = state.Pw[3]*1.0E18;
		g.drawString("P( in ) = "+dec.format(temp)+" [ a W ]",x,y);
	    }
	    else if(state.Pw[3]<1.0E-18){
		temp = 0.0;
		g.drawString("P( in ) = "+dec.format(temp)+" [ W ]",x,y);
	    }
	    
	    g.setColor(Color.blue);
	    y += dy;
	    g.drawString("Absorbed by load",x+dx+dx,y);
	
	    g.setColor(Color.black);
	    if(state.Pw[1]==0.0){
		g.drawString("P( abs ) = "+dec.format(state.Pw[1])+" [ W ]",x,y);
	    }
	    
	    else if(state.Pw[1]>=1.0 && state.Pw[1]<1.0E3){
		g.drawString("P( abs ) = "+dec.format(state.Pw[1])+" [ W ]",x,y);
	    }
	    else if(state.Pw[1]<1.0E6 && state.Pw[1]>=1.0E3){
		temp = state.Pw[1]*1.0E-3;
		g.drawString("P( abs ) = "+dec.format(temp)+" [ k W ]",x,y);
	    }
	    else if(state.Pw[1]>=1.0E6){
		temp = state.Pw[1]*1.0E-6;
		g.drawString("P( abs ) = "+dec.format(temp)+" [ M W ]",x,y);
	    }
	    
	    else if(state.Pw[1]<1.0 && state.Pw[1]>=0.001){
		temp = state.Pw[1]*1000;
		g.drawString("P( abs ) = "+dec.format(temp)+" [ m W ]",x,y);
	    }
	    else if(state.Pw[1]<0.001 && state.Pw[1]>=1.0E-6){
		temp = state.Pw[1]*1.0E6;
		g.drawString("P( abs ) = "+dec.format(temp)+" [ \u00b5 W ]",x,y);
	    }
	    else if(state.Pw[1]<1.0E-6 && state.Pw[1]>=1.0E-9){
		temp = state.Pw[1]*1.0E9;
		g.drawString("P( abs ) = "+dec.format(temp)+" [ n W ]",x,y);
	    }
	    else if(state.Pw[1]<1.0E-9 && state.Pw[1]>=1.0E-12){
		temp = state.Pw[1]*1.0E12;
		g.drawString("P( abs ) = "+dec.format(temp)+" [ p W ]",x,y);
	    }
	    else if(state.Pw[1]<1.0E-12 && state.Pw[1]>=1.0E-15){
		temp = state.Pw[1]*1.0E15;
		g.drawString("P( abs ) = "+dec.format(temp)+" [ f W ]",x,y);
	    }
	    else if(state.Pw[1]<15 && state.Pw[1]>=1.0E-18){
		temp = state.Pw[1]*1.0E18;
		g.drawString("P( abs ) = "+dec.format(temp)+" [ a W ]",x,y);
	    }
	    else if(state.Pw[1]<1.0E-18){
		temp = 0.0;
		g.drawString("P( abs ) = "+dec.format(temp)+" [ W ]",x,y);
	    }
	    
	    //g.drawString("P( abs ) = "+dec.format(state.Pw[1])+" [ W ]",x+dxx,y); 
	    
	    y += dy;
	    g.setColor(Color.blue);
	    g.drawString("Reflected by load",x+dx+dx,y);
	    
	    g.setColor(Color.black);
	    if(state.Pw[4]>=1.0 && state.Pw[4]<1.0E3 || state.Pw[4] == 0.0){
		g.drawString("P( refl ) = "+dec.format(state.Pw[4])+" [ W ]",x,y);
	    }
	    else if(state.Pw[4]<1.0E6 && state.Pw[4]>=1.0E3){
		temp = state.Pw[4]*1.0E-3;
		g.drawString("P( refl ) = "+dec.format(temp)+" [ k W ]",x,y);
	    }
	    else if(state.Pw[4]>=1.0E6){
		temp = state.Pw[4]*1.0E-6;
		g.drawString("P( refl ) = "+dec.format(temp)+" [ M W ]",x,y);
	    }
	    else if(state.Pw[4]<1.0 && state.Pw[4]>=0.001){
		temp = state.Pw[4]*1000;
		g.drawString("P( refl ) = "+dec.format(temp)+" [ m W ]",x,y);
	    }
	    else if(state.Pw[4]<0.001 && state.Pw[4]>=1.0E-6){
		temp = state.Pw[4]*1.0E6;
		g.drawString("P( refl ) = "+dec.format(temp)+" [ \u00b5 W ]",x,y);
	    }
	    else if(state.Pw[4]<1.0E-6 && state.Pw[4]>=1.0E-9){
		temp = state.Pw[4]*1.0E9;
		g.drawString("P( refl ) = "+dec.format(temp)+" [ n W ]",x,y);
	    }
	    else if(state.Pw[4]<1.0E-9 && state.Pw[4]>=1.0E-12){
		temp = state.Pw[4]*1.0E12;
		g.drawString("P( refl ) = "+dec.format(temp)+" [ p W ]",x,y);
	    }
	    else if(state.Pw[4]<1.0E-12 && state.Pw[4]>=1.0E-15){
		temp = state.Pw[4]*1.0E15;
		g.drawString("P( refl ) = "+dec.format(temp)+" [ f W ]",x,y);
	    }
	    else if(state.Pw[4]<1.0E-15 && state.Pw[4]>=1.0E-18){
		temp = state.Pw[4]*1.0E18;
		g.drawString("P( refl ) = "+dec.format(temp)+" [ a W ]",x,y);
	    }
	    else if(state.Pw[4]<1.0E-18){
		temp = 0.0;
		g.drawString("P( refl ) = "+dec.format(temp)+" [ W ]",x,y);
	    }
    	    //g.drawString("P( refl ) = "+dec.format(state.Pw[4])+" [ W ]",x+dxx,y);
	    
	    y += dy;
	    g.setColor(Color.blue);
	    g.drawString("Absorbed by Zg",x+dx+dx,y);
	    
	    g.setColor(Color.black);
	    if(state.Pw[5]>=1.0 && state.Pw[5]<1.0E3 ||state.Pw[5]==0.0){
		g.drawString("P( Zg ) = "+dec.format(state.Pw[5])+" [ W ]",x,y);
	    }
	    
	    else if(state.Pw[5]<1.0E6 && state.Pw[5]>=1.0E3){
		temp = state.Pw[5]*1.0E-3;
		g.drawString("P( Zg ) = "+dec.format(temp)+" [ k W ]",x,y);
	    }
	    else if(state.Pw[5]>=1.0E6){
		temp = state.Pw[5]*1.0E-6;
		g.drawString("P( Zg ) = "+dec.format(temp)+" [ M W ]",x,y);
	    }
	    
	    else if(state.Pw[5]<1.0 && state.Pw[5]>=0.001){
		temp = state.Pw[5]*1000;
		g.drawString("P( Zg ) = "+dec.format(temp)+" [ m W ]",x,y);
	    }
	    else if(state.Pw[5]<0.001 && state.Pw[5]>=1.0E-6){
		temp = state.Pw[5]*1.0E6;
		g.drawString("P( Zg ) = "+dec.format(temp)+" [ \u00b5 W ]",x,y);
	    }
	    else if(state.Pw[5]<1.0E-6 && state.Pw[5]>=1.0E-9){
		temp = state.Pw[5]*1.0E9;
		g.drawString("P( Zg ) = "+dec.format(temp)+" [ n W ]",x,y);
	    }
	    else if(state.Pw[5]<1.0E-9 && state.Pw[5]>=1.0E-12){
		temp = state.Pw[5]*1.0E12;
		g.drawString("P( Zg ) = "+dec.format(temp)+" [ p W ]",x,y);
	    }
	    else if(state.Pw[5]<1.0E-12 && state.Pw[5]>=1.0E-15){
		temp = state.Pw[5]*1.0E15;
		g.drawString("P( Zg ) = "+dec.format(temp)+" [ f W ]",x,y);
	    }
	    else if(state.Pw[5]<1.0E-15 && state.Pw[5]>=1.0E-18){
		temp = state.Pw[5]*1.0E18;
		g.drawString("P( Zg ) = "+dec.format(temp)+" [ a W ]",x,y);
	    }
	    else if(state.Pw[5]<1.0E-18){
		temp = 0.0;
		g.drawString("P( Zg ) = "+dec.format(temp)+" [ W ]",x,y);
	    }
	    //g.drawString("P( Zg ) = "+dec.format(state.Pw[5])+" [ W ]",x+dxx,y);
	    
	    y += dy;
	    g.setColor(Color.red);
	    g.drawString("Total time-average power from the generator",x,y);
	    y += dy;
	    g.setColor(Color.black);
	    if(state.Pw[6]>=1.0 && state.Pw[6]<1.0E3 || state.Pw[6]==0.0){
		g.drawString("P( tot ) = P( abs ) + P( Zg ) = "+dec.format(state.Pw[6])+" [ W ]",x,y);
	    }
	    else if(state.Pw[6]<1.0E6 && state.Pw[6]>=1.0E3){
		temp = state.Pw[6]*1.0E-3;
		g.drawString("P( tot ) = P( abs ) + P( Zg ) = "+dec.format(temp)+" [ k W ]",x,y);
	    }
	    else if(state.Pw[6]>=1.0E6){
		temp = state.Pw[6]*1.0E-6;
		g.drawString("P( tot ) = P( abs ) + P( Zg ) = "+dec.format(temp)+" [ M W ]",x,y);
	    }
	    else if(state.Pw[6]<1.0 && state.Pw[6]>=0.001){
		temp = state.Pw[6]*1000;
		g.drawString("P( tot ) = P( abs ) + P( Zg ) = "+dec.format(temp)+" [ m W ]",x,y);
	    }
	    else if(state.Pw[6]<0.001 && state.Pw[6]>=1.0E-6){
		temp = state.Pw[6]*1.0E6;
		g.drawString("P( tot ) = P( abs ) + P( Zg ) = "+dec.format(temp)+" [ \u00b5 W ]",x,y);
	    }
	    else if(state.Pw[6]<1.0E-6 && state.Pw[6]>=1.0E-9){
		temp = state.Pw[6]*1.0E9;
		g.drawString("P( tot ) = P( abs ) + P( Zg ) = "+dec.format(temp)+" [ n W ]",x,y);
	    }
	    else if(state.Pw[6]<1.0E-9 && state.Pw[6]>=1.0E-12){
		temp = state.Pw[6]*1.0E12;
		g.drawString("P( tot ) = P( abs ) + P( Zg ) = "+dec.format(temp)+" [ p W ]",x,y);
	    }
	    else if(state.Pw[6]<1.0E-12 && state.Pw[6]>=1.0E-15 ){
		temp = state.Pw[6]*1.0E15;
		g.drawString("P( tot ) = P( abs ) + P( Zg ) = "+dec.format(temp)+" [ f W ]",x,y);
	    }
	    else if(state.Pw[6]<1.0E-15 && state.Pw[6]>=1.0E-18){
		temp = state.Pw[6]*1.0E18;
		g.drawString("P( tot ) = P( abs ) + P( Zg ) = "+dec.format(temp)+" [ a W ]",x,y);
	    }
	    else if(state.Pw[6]<1.0E-18){
		temp = 0.0;
		g.drawString("P( tot ) = P( abs ) + P( Zg ) = "+dec.format(temp)+" [ W ]",x,y);
	    }
	    
	}
}

class StubOutputCanvas extends Canvas{
	private static final Font normalfont = TheFonts.sanSerif11;
	private static final Font subfont    = TheFonts.sanSerif9;
	Trans_State state;
	public StubOutputCanvas(Trans_State state){
	    super();
	    this.state = state;
	}
	
	public void paint(Graphics g){
	    int x, y, dx, dy;
	    int i;
	    FontMetrics fm;
	    String tmp;
	    x = 10;
	    y = 15;
	    dx = 80;
	       
	    g.setColor(Color.black);
	    
	    //g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    dy = fm.getHeight();
	    
	    for(i = 0; i < 3; i++){
	    
		tmp = "Stub "+(i+1);
	    
		if(state.stub[i].isEnable()){
		    tmp = tmp + " Enabled ";
		}
		else{
		    tmp = tmp + " Disabled ";
		}
    
		if(state.stub[i].isParallel()){
		    tmp = tmp + " Parallel ";
		}
		else{
		    tmp = tmp + " Series ";
		}
		
		if(state.stub[i].isOpen()){
		    tmp = tmp + " Open ";
		}
		else{
		    tmp = tmp + " Short ";
		}
		
	        g.drawString(tmp,x,y);
	    
		tmp = "Length = "+state.stub[i].getLength()+" \u03bb  ";
		tmp = tmp + "Position = "+state.stub[i].getPosition()+" \u03bb  ";
		tmp = tmp + "Zchar = "+state.stub[i].getZchar()+" \u03a9 ";
	     
		y += dy;
	    
		g.drawString(tmp,x,y);
	    
		y += dy;
		g.drawString("Zstub : ",x,y);
		//g.drawString(""+state.stub[i].getZstub().toString(Complex.CARTESIAN,4)+" \u03a9",x+dx,y);   
		
		y += dy;
		  
		g.drawString("Ystub : ",x,y);
		g.drawString(""+state.stub[i].getYstub().toString(Complex.CARTESIAN,4)+" S",x+dx,y);
		
		y += dy;
		g.drawLine(10,y,getSize().width-10,y);
		y += dy;
	    }
	}
}
