//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.awt.event.*;
import java.applet.*;
import java.lang.*;  
import java.text.*;  

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;
    Label titlelabel;
    public SpaceDependentCanvas canvas1;
    public SpaceIndependentCanvas canvas2;
    public StubOutputCanvas canvas3;
    Trans_State state;
    public Trans_OutputPanel(Trans_State state){
	super();
	this.state = state;
	titlelabel = new Label("Output",Label.LEFT);
	setLayout(null);
	add(titlelabel);
	titlelabel.setFont(titlefont);
    
	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(titlefont);
        int labelWidth = fmTitle.stringWidth("Output");
	//titlelabel.setBounds(10,2,60,25);
	//titlelabel.setBounds(10,2,labelWidth,25);
	titlelabel.setBounds(10,2,labelWidth+5,25);

	canvas1.setBounds(6,26,298,250);
	canvas2.setBounds(6,26,298,250);
	canvas3.setBounds(6,26,298,250);
    }
    
    /*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;
	Trans_State state;
	private Image im;
	private Graphics buf;
        DecimalFormat dec = new DecimalFormat("0.###"); //"0.###E0"

	public SpaceDependentCanvas(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){
            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;
	    
            Font symbolfont=TheFonts.symbol12;
            FontMetrics fm;
		
            g.setFont(TheFonts.serif11);
		
		String alpha, Ohm, lambda, infinity, Gamma, plusj, minusj, 
                       sign, plusr, minusr, signr;
		g.setFont(symbolfont);
		alpha="\u03b1";
		lambda="\u03bb";
		Ohm="\u03a9";
		infinity="\u221e";
		Gamma="\u0393";
                g.setFont(normalfont);
		plusj =" + j ";
		minusj=" - j ";
                plusr ="";
                minusr =" - ";
                
            Gamma_plusone = false;
            Gamma_minusone = false;
	    
	    
	    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 = 10;
	    y = 10;
	    dx = 80;
	    dxx = 10;
	    dxxx = 120;
	    dxxxx =60;
	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    dy = fm.getHeight();
	    dyy = dy + 4;
	    g.clearRect(0,0,getSize().width,getSize().height);
	    g.setColor(Color.blue);
	    g.drawString("Cursor",x,y+5);
	    
	    g.setColor(Color.black);
	    if(state.xpos == 0.0){
                g.drawString("    d   = "+dec.format(state.xpos),x+dx,y);
            }
            else{
                g.drawString("    d   = "+dec.format(state.xpos),x+dx,y);
            }
            MaestroG.subscripterSanSymUnit("  [ ","",""+lambda," ]",g,11,x+200,y);
            
	    //g.drawString("  [ "+lambda+" ]",x+200,y);
	    //g.setFont(symbolfont);
	    //g.drawString(""+lambda,x+215,y);
	    //g.setFont(normalfont);
	    
	    y+=dy;
	    	
	    double testlength = state.xpos*state.wavelength;
	    if(state.xpos == 0.0){
                g.drawString("         = 0.0",x+dx,y);	
                    g.drawString("  [ m ]",x+200,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+200,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+200,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+200,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+200,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+200,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+200,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+200,y);
                    MaestroG.superscripter("  [ 10","3"," km ]",g,11,x+200,y);
                }
                else if(testlength >= 1.0E9){
                    g.drawString("         = "+dec.format(state.xpos*state.wavelength/1.0E9),x+dx,y);	
                    //g.drawString("  [ Gm ]",x+200,y);
                    MaestroG.superscripter("  [ 10","6"," km ]",g,11,x+200,y);
                }

            }
            
	    g.setColor(Color.white);	        
	    g.drawLine(5,y+dyy/3,getSize().width-5,y+dyy/3);
	    
	    //--------------------------------
            
            
            y += dyy;
	    dx = 80;
            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);
            //g.drawString("  [ "+Ohm+" ]",x,y+dy); 
            MaestroG.SansNosansSymb2("",""," [ "+Ohm+" ]",g,10,x,y+dy);

            g.setColor(Color.black); 
            	
                MaestroG.subscripter("Z","","(d)",g,11,x+dx,y);
                int xinit2, xinit3;
                xinit2 = x+dxx+95;
                    
                if((state.IsLoadOpen || state.IsLoadImaginary) && Gamma_plusone){
		    MaestroG.subscripter("= "+infinity,"","",g,11,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,11,xinit2,y);
                    MaestroG.SansMiditalic("= 0.0","  \u2220 ",""+0.0+" rad",g,11,xinit2,y+dy);
                    y+=dy;
		}
		else if((state.IsLoadShort || state.IsLoadImaginary) && Gamma_plusone){
		    MaestroG.subscripter("= "+infinity,"","",g,11,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,11,xinit2,y);
                    MaestroG.SansMiditalic("= 0.0","  \u2220 ",""+0.0+" rad",g,11,xinit2,y+dy);
                    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,11,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("= 0.0","","",g,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,xinit3,y);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E6 && tempX >= 1.0E3){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-3)+" x 10","3","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E9 && tempX >= 1.0E6){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-6)+" x 10","6","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E12 && tempX >= 1.0E9){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-9)+" x 10","9","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E15 && tempX >= 1.0E12){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-12)+" x 10","12","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E18 && tempX >= 1.0E15){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-15)+" x 10","15","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E21 && tempX >= 1.0E18){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-18)+" x 10","18","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E24 && tempX >= 1.0E21){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-21)+" x 10","21","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E27 && tempX >= 1.0E24){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-24)+" x 10","24","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E30 && tempX >= 1.0E27){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-27)+" x 10","27","",g,11,xinit3,y);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-30)+" x 10","30","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E-3 && tempX >= 1.0E-6){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E6)+" x 10","-6","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E-6 && tempX >= 1.0E-9){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E9)+" x 10","-9","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E-9 && tempX >= 1.0E-12){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E12)+" x 10","-12","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E-12 && tempX >= 1.0E-15){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E15)+" x 10","-15","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E-15 && tempX >= 1.0E-18){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E18)+" x 10","-18","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E-18 && tempX >= 1.0E-21){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E21)+" x 10","-21","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E-21 && tempX >= 1.0E-24){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E24)+" x 10","-24","",g,11,xinit3,y);
		    }
                    else if(tempX < 1.0E-24 && tempX >= 1.0E-27){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E27)+" x 10","-27","",g,11,xinit3,y);
		    }
                    else if(tempX < 1.0E-27 && tempX >= 1.0E-30){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E30)+" x 10","-30","",g,11,xinit3,y);
		    }
                    else if(tempX < 1.0E-30 && tempX != 0.0){
			MaestroG.superscripter(sign+" 0.0","","",g,11,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,11,xinit2,y);
		    }
		    else if(tempR == 0.0){
			MaestroG.SansMiditalic("= 0.0","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E6 && tempR >= 1.0E3){
                        MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-3)+" x 10","3","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E9 && tempR >= 1.0E6){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-6)+" x 10","6","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E12 && tempR >= 1.0E9){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-9)+" x 10","9","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E15 && tempR >= 1.0E12){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-12)+" x 10","12","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E18 && tempR >= 1.0E15){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-15)+" x 10","15","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E21 && tempR >= 1.0E18){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-18)+" x 10","18","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E24 && tempR >= 1.0E21){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-21)+" x 10","21","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E27 && tempR >= 1.0E24){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-24)+" x 10","24","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E30 && tempR >= 1.0E27){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-27)+" x 10","27","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR >= 1.0E30){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-30)+" x 10","30","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E6)+" x 10","-6","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E9)+" x 10","-9","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E12)+" x 10","-12","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E15)+" x 10","-15","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E18)+" x 10","-18","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E21)+" x 10","-21","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E24)+" x 10","-24","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
                    else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E27)+" x 10","-27","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
                    else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E30)+" x 10","-30","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
                    else if(tempR < 1.0E-30 && tempR != 0.0){
			MaestroG.SansMiditalic("= 0.0","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
            }


            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,11,x+dx,y);
               
                xinit2 = x+dxx+95;
                    
                if((state.IsLoadOpen || state.IsLoadImaginary) && Gamma_plusone){
		    MaestroG.subscripter("= 0.0 + j 0.0","","",g,11,xinit2,y);
                    MaestroG.SansMiditalic("= 0.0","  \u2220 ",""+0.0+" rad",g,11,xinit2,y+dy);
                    y+=dy;
		}
		else if((state.IsLoadOpen || state.IsLoadImaginary) && Gamma_minusone){
                    MaestroG.subscripter("= "+infinity,"","",g,11,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,11,xinit2,y);
                    MaestroG.SansMiditalic("= 0.0","  \u2220 ",""+0.0+" rad",g,11,xinit2,y+dy);
                    y+=dy;
		}
		else if((state.IsLoadShort || state.IsLoadImaginary) && Gamma_minusone){
		    MaestroG.subscripter("= "+infinity,"","",g,11,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,11,xinit2,y);
			//stepx = fm.stringWidth("= "+dec.format(tempR));
			MaestroG.superscripter("= "+dec.format(tempR),"","",g,11,xinit2,y);
			stepx = fm.stringWidth("= "+dec.format(tempR));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("= 0.0","","",g,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,xinit3,y);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E6 && tempX >= 1.0E3){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-3)+" x 10","3","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E9 && tempX >= 1.0E6){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-6)+" x 10","6","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E12 && tempX >= 1.0E9){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-9)+" x 10","9","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E15 && tempX >= 1.0E12){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-12)+" x 10","12","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E18 && tempX >= 1.0E15){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-15)+" x 10","15","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E21 && tempX >= 1.0E18){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-18)+" x 10","18","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E24 && tempX >= 1.0E21){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-21)+" x 10","21","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E27 && tempX >= 1.0E24){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-24)+" x 10","24","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E30 && tempX >= 1.0E27){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-27)+" x 10","27","",g,11,xinit3,y);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E-30)+" x 10","30","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E-3 && tempX >= 1.0E-6){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E6)+" x 10","-6","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E-6 && tempX >= 1.0E-9){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E9)+" x 10","-9","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E-9 && tempX >= 1.0E-12){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E12)+" x 10","-12","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E-12 && tempX >= 1.0E-15){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E15)+" x 10","-15","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E-15 && tempX >= 1.0E-18){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E18)+" x 10","-18","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E-18 && tempX >= 1.0E-21){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E21)+" x 10","-21","",g,11,xinit3,y);
		    }
		    else if(tempX < 1.0E-21 && tempX >= 1.0E-24){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E24)+" x 10","-24","",g,11,xinit3,y);
		    }
                    else if(tempX < 1.0E-24 && tempX >= 1.0E-27){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E27)+" x 10","-27","",g,11,xinit3,y);
		    }
                    else if(tempX < 1.0E-27 && tempX >= 1.0E-30){
			MaestroG.superscripter(sign+""+dec.format(tempX*1.0E30)+" x 10","-30","",g,11,xinit3,y);
		    }
                    else if(tempX < 1.0E-30 && tempX != 0.0){
			MaestroG.superscripter(sign+" 0.0","","",g,11,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,11,xinit2,y);
		    }
		    else if(tempR == 0.0){
			MaestroG.SansMiditalic("= 0.0","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E6 && tempR >= 1.0E3){
                        MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-3)+" x 10","3","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E9 && tempR >= 1.0E6){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-6)+" x 10","6","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E12 && tempR >= 1.0E9){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-9)+" x 10","9","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E15 && tempR >= 1.0E12){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-12)+" x 10","12","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E18 && tempR >= 1.0E15){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-15)+" x 10","15","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E21 && tempR >= 1.0E18){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-18)+" x 10","18","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E24 && tempR >= 1.0E21){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-21)+" x 10","21","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E27 && tempR >= 1.0E24){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-24)+" x 10","24","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E30 && tempR >= 1.0E27){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-27)+" x 10","27","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR >= 1.0E30){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E-30)+" x 10","30","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E6)+" x 10","-6","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E9)+" x 10","-9","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E12)+" x 10","-12","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E15)+" x 10","-15","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E18)+" x 10","-18","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E21)+" x 10","-21","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
		    else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E24)+" x 10","-24","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
                    else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E27)+" x 10","-27","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
                    else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
			MaestroG.SansMiditalicSuper("= "+dec.format(tempR*1.0E30)+" x 10","-30","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
                    else if(tempR < 1.0E-30 && tempR != 0.0){
			MaestroG.SansMiditalic("= 0.0","  \u2220 ",""+dtmp2+" rad",g,11,xinit2,y);
		    }
            }
            
	    g.setColor(Color.black);	
            g.drawLine(5,y+dyy/3,getSize().width-5,y+dyy/3);
	    y += dyy;
	    
	    g.setColor(Color.red);	    	    
	    g.drawString("Reflection",x,y);
	    
	    g.setColor(Color.black);
	    MaestroG.subscripterSS3(""+Gamma,"d","",g,11,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(),6);
                        //gtmp3=MaestroA.rounder(state.Gammain.Arg2()*180/Math.PI,6);
                        gtmp2=MaestroA.rounder(state.Gammain.Arg2(),3);
                        gtmp3=MaestroA.rounder(state.Gammain.Arg2()*180/Math.PI,3);
                   }
                MaestroG.SansMiditalic("= "+gtmp1,"  \u2220 ",""+gtmp2+" rad",g,11,xinit2,y);
	    y += dy;
                MaestroG.SansMiditalic("= "+gtmp1,"  \u2220 ",""+gtmp3+" \u00ba",g,11,xinit2,y);
	    
            g.setColor(Color.white);
	    g.drawLine(5,y+dyy/3,getSize().width-5,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);
		g.setFont(symbolfont);
		g.drawString("\u221e",x+dxx+60,y);
		g.setFont(normalfont);
		}
	    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(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,5),x+dxx,y);
	    MaestroG.subscripterSanSym2("d (max) = "+dec.format(dmax)+"","","",""+lambda,g,11,x+dxx,y);
            
	    //g.setFont(symbolfont);
	    //g.drawString("\u03bb",x+dxx+10+fm.stringWidth("d(max) = "+dec.format(dmax)),y);
	    g.setFont(normalfont);
	    
	    g.setColor(Color.black);
	    //g.drawString(" = "+dec.format(dmax*state.wavelength,5)+"   [ m ]",160,y);
	    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,11,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,11,x+dxxx,y);
	    }
	   
	  	    
	    y+=dy;
	    
	    //g.drawString("d(min) = "+dec.format(dmin,5),x+dxx,y);
            MaestroG.subscripterSanSym2("d (min) = "+dec.format(dmin)+"","","",""+lambda,g,11,x+dxx+4,y);
            
	    //g.setFont(symbolfont);
	    //g.drawString("\u03bb",x+dxx+10+fm.stringWidth("d(min) = "+dec.format(dmin)),y);
	    g.setFont(normalfont);
	    
	    g.setColor(Color.black);
	    //g.drawString(" = "+dec.format(dmax*state.wavelength)+"   [ m ]",160,y);
	    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,11,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,11,x+dxxx,y);
	    }
	    
	    //g.setColor(Color.black);	
    	    //g.drawLine(5,y+dyy/4,getSize().width-5,y+dyy/4);
	    
	    y+=18;
	    g.setColor(Color.red);
	    g.drawString("Wavelength",x,y);
	    g.setColor(Color.black);
	    //g.setFont(symbolfont);
	    MaestroG.subscripterSanSym2("","","",""+lambda,g,11,x+10+fm.stringWidth("Wavelength"),y);
            
            //g.drawString(""+lambda,x+10+fm.stringWidth("Wavelength"),y);
	    g.setFont(normalfont);
	    
	    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,11,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,11,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;
	    }
	}
}
