//SmithPanel.java
/*
 * @author - Singh T. Jr, and U. Ravaioli
 * Maestro Series, Amanogawa, 1997
 *  Smith Chart panel
*/

import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;

public class SmithPanel extends Panel implements MouseListener, MouseMotionListener, ItemListener{
	private static final Color bgcolor = Color.white;
	public SmithCanvas sc;
	public SmithMan sm; 
	private SmithProbe sp;
	public SmithControls scon;
	//public Checkbox small;
        public Button small;
        public Button colore;
        public boolean colore_dark;
        
        protected Font buttonfont;
        Trans_State state;
        
public SmithPanel(Trans_State state){
	setLayout(null);
        this.state = state;
	
        Font buttonfont = new Font("SanSerif",Font.PLAIN,state.font10);
	//small = new Checkbox("Enlarge",null,false);
        small = new Button("Enlarge");
        //add(small);
	small.setBackground(Color.white);
	small.setBounds(state.s7,state.s7,state.s50,state.s20);
        small.setFont(buttonfont);
        
         colore = new Button("Color");
	add(colore);
	colore.setBackground(Color.white);
	colore.setBounds(state.s245,state.s10,state.s55,state.s20);
        colore.setFont(buttonfont);
        
        colore_dark = false;

	
	setBackground(bgcolor);
	
	sc = new SmithCanvas(state);
	add(sc);
	sc.setBounds(state.s5,state.s5,state.s300,state.s300);
	
	sm = new SmithMan(state.s298,state.s74, state);
	add(sm);
	sm.setBounds(state.s6,state.s310,state.s298,state.s78);

	sp = new SmithProbe(state.s297,state.s33);
	//add(sp);
	sp.setBounds(state.s6,state.s391,state.s297,state.s33);

	scon = new SmithControls();
	//add(scon);
	scon.setBounds(state.s12,state.s431,state.s291,state.s30);
	
	sc.addMouseListener(this);
	sc.addMouseMotionListener(this);
	scon.imp.addItemListener(this);
	scon.adm.addItemListener(this);
	scon.swr.addItemListener(this);
	scon.swrline.addItemListener(this);
	
	Panel pgraph1 = new Panel();
	    pgraph1.setBackground(Color.black);
	    add(pgraph1);
	    pgraph1.setBounds(state.s5,state.s309,state.s300,state.s80);
	    
	Panel pgraph2 = new Panel();
	    pgraph2.setBackground(Color.black);
	    //add(pgraph2);
	    pgraph2.setBounds(state.s5,state.s390,state.s300,state.s36);
	 
	Panel pgraph3 = new Panel();
            pgraph3.setBackground(new Color(236,236,221));
	    //add(pgraph3);
	    pgraph3.setBounds(state.s6,state.s430,state.s297,state.s31);
	      
	Panel pgraph4 = new Panel();
	    pgraph4.setBackground(Color.black);
	    //add(pgraph4);
	    pgraph4.setBounds(state.s5,state.s429,state.s300,state.s34);
}
public void paint(Graphics g){
	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);
}


public  synchronized void setZin(Complex Zin){
	sc.setZin(Zin);
	sm.setZin(Zin);
}

public synchronized void setYin(Complex Yin){
	sc.setYin(Yin);
	sm.setYin(Yin);
}

public synchronized void setZin(Complex Zin, double Z0){
	setZin(Complex.Divide(Zin,Z0));
}

public synchronized void setYin(Complex Yin, double Z0){
	setYin(Complex.Multiply(Yin,Z0));
}

public synchronized void setZin(Complex Zin, Complex Z0){
	setZin(Complex.Divide(Zin,Z0));
}

public synchronized void setYin(Complex Yin, Complex Z0){
	setYin(Complex.Multiply(Yin,Z0));
}

public synchronized void setZL(Complex ZL){
	sc.setZL(ZL);
	sm.setZL(ZL);
}

public synchronized void setZL(Complex ZL, double Z0){
	setZL(Complex.Divide(ZL,Z0));
}

public synchronized void setZL(Complex ZL, Complex Z0){
	setZL(Complex.Divide(ZL,Z0));
}

public synchronized void setYL(Complex YL){
	sc.setYL(YL);
	sm.setYL(YL);
}

public synchronized void setYL(Complex YL, double Z0){
	setYL(Complex.Multiply(YL,Z0));
}

public synchronized void setYL(Complex YL, Complex Z0){
	setYL(Complex.Multiply(YL,Z0));
}

public synchronized void setColoreDark(boolean colore_dark){
        sc.setColoreDark(colore_dark);
}

public synchronized void set_swr_circle(boolean arg){
	sc.set_swr_circle(arg);
}

public synchronized void set_swr_line(boolean arg){
	sc.set_swr_line(arg);
}

public synchronized void set_impedance(boolean arg){
	sc.set_impedance(arg);
}

public synchronized void set_admittance(boolean arg){
	sc.set_admittance(arg);
}

public synchronized void setZL(boolean arg){
	sc.setZL(arg);
}

public synchronized void setZin(boolean arg){
	sc.setZin(arg);	
}

public synchronized void setYin(boolean arg){
	sc.setYin(arg);
}

public synchronized void setxpos(double xpos){
	sc.setxpos(xpos);
	sp.setxpos(xpos);
	sp.setmode(1);
}

public void mouseDragged(MouseEvent evt){cricket_1();}
public void mouseMoved(MouseEvent evt){;}
public void mouseClicked(MouseEvent evt){cricket_1();}
public void mouseEntered(MouseEvent evt){;}
public void mouseExited(MouseEvent evt){;}
public void mousePressed(MouseEvent evt){cricket_1();}
public void mouseReleased(MouseEvent evt){cricket_1();}
public void itemStateChanged(ItemEvent evt){cricket_2(evt);}

private void cricket_1(){
    String str1, str2;
    str1="z = "+sc.getZProbe().toString(Complex.CARTESIAN,5)+
	 "       y = "+Complex.Divide(1.0,sc.getZProbe()).toString(Complex.CARTESIAN,5);
    str2="\u0393 = "+sc.getGammaProbe().toString(Complex.POLAR_DEGREE,5);
    sp.setmode(2);
    sp.set(str1,str2);
}

private void cricket_2(ItemEvent evt){
    if(evt.getSource()==scon.imp){
			sc.set_impedance(scon.imp.getState());
			sm.setMode(1);
			sm.setZL(sc.getZL());
			sm.setZin(sc.getZin());
    }
    else if(evt.getSource()==scon.adm){
			sc.set_admittance(scon.adm.getState());
			sm.setMode(2);
			sm.setZL(sc.getZL());
			sm.setYin(sc.getYin());
    }
    else if(evt.getSource()==scon.swr){
			sc.set_swr_circle(scon.swr.getState());
    }
    else if(evt.getSource()==scon.swrline){
			sc.set_swr_line(scon.swrline.getState());
    }
    sc.repaint();
    sm.repaint();
}

}//End of SmithPanel


/****************************************************************************************/

class SmithCanvas extends Canvas implements MouseListener, MouseMotionListener{
//private final Color bgcolor = new Color(216,216,191);
private final Color bgcolor = new Color(236,236,236);

private int xCenter, yCenter;
private int Radius1, Diam1, Radius2, Diam2, Radius3;
private int width, height;
public boolean draw_impedance_chart;
public boolean draw_admittance_chart;
public boolean draw_swr_circle;
public boolean draw_swr_line;
private boolean draw_arcs;
private boolean draw_vline;
private boolean draw_ZL, draw_Zin, draw_Yin;
private Complex Zin, Yin, ZL, YL;
private Complex GammaZin, GammaYin, GammaZL;
private double xpos, Z0;
private Complex GammaProbe, ZProbe; 
private int xProbe, yProbe;
private static final Cursor cursorA = new Cursor(Cursor.DEFAULT_CURSOR);
private static final Cursor cursorB = new Cursor(Cursor.CROSSHAIR_CURSOR);
private Image im;
private Graphics buf;
private boolean colore_dark;
Trans_State state;

public SmithCanvas(Trans_State state){
	super();
        this.state = state;
	setBackground(Color.white); 
	draw_impedance_chart=true;
	draw_admittance_chart=false;
	draw_swr_circle=true;
	draw_swr_line=true;
	draw_ZL=true;
	draw_Zin=true;
	draw_Yin=true;
	draw_arcs=true;
	draw_vline=true;
	xpos = 0.0;
	Z0 = 1.0;
	ZL = new Complex(1.0,1.0);
	//ZL = state.ZL;
	YL = EMF.Inv(ZL);
	GammaZL = EMF.computeGamma(ZL);
	Zin = new Complex(0.0,0.0);
	GammaZin = EMF.computeGamma(Zin);
	Yin = EMF.Inv(Zin);
	GammaYin = EMF.computeGamma(Yin);
	ZProbe = new Complex();
	GammaProbe = new Complex();
	xProbe=0;
	yProbe=0;
        
        colore_dark = false;

	this.addMouseListener(this);
	this.addMouseMotionListener(this);
}

public void paint(Graphics g){
	//drawSmith(g);
	    if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawSmith(buf);
	    }
	    else{
		drawSmith(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 clear(){
	this.getGraphics().clearRect(0,0,getSize().width,getSize().height);
	repaint();
}

public void drawSmith(Graphics g){
    
    Graphics2D g2d = (Graphics2D)g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);


	int i;
	int Ncurves = 16;
	double[] rl={0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.0,3.0,4.0,5.0,10.0,20.0,50.0};
	double[] xl={0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.0,3.0,4.0,5.0,10.0,20.0,50.0};
	
	width=getSize().width;
	height=getSize().height;

	xCenter = width/2;
	yCenter = height/2;

	Radius1 = (width/2)*85/100;
	Radius2 = (width/2)*95/100;
        Radius3 = Radius1;
	Diam1 = 2*Radius1;
	Diam2 = 2*Radius2;
	
	//Draw the background circle
	
        if(colore_dark){
            g.setColor(bgcolor.darker());
        }
        else{
            g.setColor(bgcolor);
        }

	fillCircle(g,xCenter,yCenter,Radius1);

	//Draw a horizontal line
	g.setColor(Color.lightGray);
	g.drawLine(xCenter-Radius1,yCenter,xCenter+Radius1,yCenter);
	
	//Draw a vertical line
	if(draw_vline){g.drawLine(xCenter,yCenter-Radius1,xCenter,yCenter+Radius1);}
	
        Color plotchart = Color.lightGray;

	if(draw_impedance_chart){
	//Draw resistance and reactance circles
		for(i=0;i<Ncurves;i++){
			draw_resistance(rl[i],g,plotchart);
			draw_reactance(xl[i],g,plotchart);
		}
	}
	if(draw_admittance_chart){
	//Draw conductance and susceptance circles
		for(i=0;i<Ncurves;i++){
			draw_conductance(rl[i],g,plotchart);
			draw_susceptance(xl[i],g,plotchart);
		}
	}
        
         //draw background with circular hole for chart
        
        Color outer;
        
        if(colore_dark){
            outer = new Color(236,236,236);
        }
        else{
            //outer = new Color(205,195,180);
            outer = Color.lightGray;
        }

        
        drawStencil(g, width, height, Radius1, xCenter, yCenter, outer);
	
        //draw black frame
        g.setColor(Color.black);
	g.drawRect(0,0,width-1,height-1);
	

	//Draw tick-marks in the peripheries
	draw_tick_marks(g);
        
        //Draw external and internal circles
	g.setColor(Color.black);
	drawCircle(g,xCenter,yCenter,Radius1);
	drawCircle(g,xCenter,yCenter,Radius2);

	//Draw rl=1 circle in blue
        Color r_one_color;
        
            if(colore_dark){
                r_one_color = Color.white;
            }
            else{
                r_one_color = Color.gray;
            }
        
	if(draw_impedance_chart){
		draw_resistance(1.0,g,r_one_color);
	}
	else{
		draw_conductance(1.0,g,r_one_color);
	}

	//Draw a small blue circle at the center
	g.setColor(Color.blue);
	drawCircle(g,xCenter,yCenter,(int)(Radius1*0.04));
	
	//draw_arcs()
	if(draw_arcs){draw_arcs(g);}

	//draw swr_circle
	if(draw_swr_circle){draw_swr_circle(g);}

	//draw swr_line
	if(draw_swr_line){draw_swr_line(g);}

	//drawPoints();
	drawPoints(g);

	
}

private void drawStencil(Graphics g, int width, int height, int radius, int xcenter, int ycenter, Color stencilcolor){
	int rule; float alpha;
        rule = AlphaComposite.SRC_OVER;
        alpha = 1.0f;
        
        Graphics2D g2d = (Graphics2D)g;
        g2d.setPaint(stencilcolor);      
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setComposite(AlphaComposite.getInstance(rule, alpha));
        
        Area a1, a2, a3;
        
	Rectangle2D newrect = new Rectangle2D.Double(0.0,0.0,(double)width,(double)height);
        a1 = new Area(newrect);
        Ellipse2D newellipse = new Ellipse2D.Double((double)(xcenter-radius),(double)(ycenter-radius),(double)(radius*2),(double)(radius*2));
        a2 = new Area(newellipse);
        a3 = new Area();
        a3.add(a1);
        a3.subtract(a2);
        g2d.fill(a3);
        
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
}

private void drawCircle(Graphics g, int xCenter, int yCenter, int Radius){
	g.drawOval(xCenter-Radius,yCenter-Radius,2*Radius,2*Radius);
}

private void fillCircle(Graphics g, int xCenter, int yCenter, int Radius){
	g.fillOval(xCenter-Radius,yCenter-Radius,2*Radius,2*Radius);
}

private void draw_resistance(double rl, Graphics g, Color color){
	double xcen, ycen, raio;
	//Microwave Engineering, David M. Pozar, Equation 3.56a, Page 86.
	xcen = (rl)/(1.0+rl);
	ycen = 0.0;
	raio = 1.0/(1.0+rl);

	g.setColor(color);
	drawCircle(g,xCenter+(int)(xcen*Radius1),xCenter+(int)(ycen*Radius1),(int)(raio*Radius1));
}

private void draw_conductance(double rl, Graphics g, Color color){
	double xcen, ycen, raio;
	//Microwave Engineering, David M. Pozar, Equation 3.56a, Page 86.
	xcen = -(rl)/(1.0+rl);
	ycen = 0.0;
	raio = 1.0/(1.0+rl);
	
	g.setColor(color);
	drawCircle(g,xCenter+(int)(xcen*Radius1),xCenter+(int)(ycen*Radius1),(int)(raio*Radius1));
}

private void draw_reactance(double xl, Graphics g, Color color){
	double xcen, ycen, raio;
	//Microwave Engineering, David M. Pozar, Equation 3.56b, Page 86.
	xcen = 1.0;
	ycen = 1.0/xl;
	raio = 1.0/xl;

	g.setColor(color);
	drawCircle(g,xCenter+(int)(xcen*Radius1),xCenter+(int)(ycen*Radius1),(int)(raio*Radius1));

	ycen = -1.0/xl;
	drawCircle(g,xCenter+(int)(xcen*Radius1),xCenter+(int)(ycen*Radius1),(int)(raio*Radius1));
}

private void draw_susceptance(double xl, Graphics g, Color color){
	double xcen, ycen, raio;
	//Microwave Engineering, David M. Pozar, Equation 3.56b, Page 86.
	xcen = -1.0;
	ycen = 1.0/xl;
	raio = 1.0/xl;

	g.setColor(color);
	drawCircle(g,xCenter+(int)(xcen*Radius1),xCenter+(int)(ycen*Radius1),(int)(raio*Radius1));

	ycen = -1.0/xl;
	drawCircle(g,xCenter+(int)(xcen*Radius1),xCenter+(int)(ycen*Radius1),(int)(raio*Radius1));
}

private void draw_tick_marks(Graphics g){
	int Nmarks=360;
	int i;
	int tmpx1, tmpy1;
	int tmpx2, tmpy2;
	double beta = 2.0*Math.PI;
	int r1, r2,r3,r4;
	
	r4=(int)(Radius3+(Radius2-Radius3)*0.3);
        r3=(int)(Radius3+(Radius2-Radius3)*0.5);
        r1=(int)(Radius3+(Radius2-Radius3)*0.7);
	r2=(int)(Radius2*0.98);

	//g.setColor(bgcolor);
	
	for(i=0;i<Nmarks;i++){
                g.setColor(Color.gray);
                
		tmpx1=(int)(xCenter+r1*Math.cos(beta*i/(Nmarks)));
		tmpy1=(int)(yCenter+r1*Math.sin(beta*i/(Nmarks)));
		if(i%5==0){
			tmpx1=(int)(xCenter+r3*Math.cos(beta*i/(Nmarks)));
			tmpy1=(int)(yCenter+r3*Math.sin(beta*i/(Nmarks)));
                        
		}
                if(i%10==0){
			tmpx1=(int)(xCenter+r4*Math.cos(beta*i/(Nmarks)));
			tmpy1=(int)(yCenter+r4*Math.sin(beta*i/(Nmarks)));
                        
                }
		tmpx2=(int)(xCenter+r2*Math.cos(beta*i/(Nmarks)));
		tmpy2=(int)(yCenter+r2*Math.sin(beta*i/(Nmarks)));
                if(i == 270){tmpx1 = tmpx1+1; tmpx2=tmpx1;}
                {
		g.drawLine(tmpx1,tmpy1,tmpx2,tmpy2);}
	}	
}


public void draw_arcs(Graphics g){

	double beginAngle, beginAngle2, Angle, Angle2;
	double raio, del;
	double txpos=xpos;
	while(txpos>0.5){txpos-=0.5;}
	raio = (double)(2.03*Radius3);	

	beginAngle=GammaZL.Arg2(Complex.POLAR_DEGREE);
	Angle=-720.0*xpos;
        while(Math.abs(beginAngle)>360){beginAngle = beginAngle+360.0;}
        while(Math.abs(Angle)>360){Angle = Angle+360.0;}
        
        //drawArcThick(g,(double)(xCenter-raio/2),(double)(yCenter-raio/2),raio,beginAngle,Angle,3,Color.red);
                
	beginAngle2 = GammaZL.Arg2(Complex.POLAR_DEGREE) + Angle;
	Angle2=-(0.5-txpos)*720.0;
        if(Math.abs(beginAngle2)>360){beginAngle2 = beginAngle2+360.0;}
        if(Math.abs(Angle2)>360){Angle2 = Angle2+360.0;}
        
        drawArcThick(g,(double)(xCenter-raio/2),(double)(yCenter-raio/2),raio+1.0,beginAngle2,Angle2,3,Color.green);
        drawArcThick(g,(double)(xCenter-raio/2),(double)(yCenter-raio/2),raio+1.0,beginAngle,Angle,3,Color.red);
}

private void drawArcThick(Graphics g, double xCenter, double yCenter, double Radius, double startangle, double endangle, int thick, Color color){
	
        Graphics2D g2d = (Graphics2D)g;
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(thick));
        
        
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
        Arc2D.Double arc_one = new Arc2D.Double(xCenter,yCenter,Radius,Radius,startangle,endangle,0);
        g2d.draw(arc_one);
  
        g2d.setStroke(new BasicStroke(1));
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
}

public void drawPoints(Graphics g){
	int radius=state.s3;
	int tmpx, tmpy;
        
        //-------------------------------------
       
            draw_Zin = true;
            draw_Yin = true;
        
            /*
            if(xpos == 0.0){
		if(draw_impedance_chart){

                    draw_Zin = false;
                    draw_Yin = true;
                }
                if(draw_admittance_chart){
                    draw_Yin = false;
                    draw_Zin = true;
                }
	    }
	    else{
		draw_Zin = true;
                draw_Yin = true;
	    }
            */
        //---------------------------------------
        if(xpos<0.1){
            if(draw_Zin){
		//Zin
		if(draw_impedance_chart){
		    tmpx=xCenter+(int)(GammaZin.Real()*Radius1);
		    tmpy=yCenter+(int)(-GammaZin.Imaginary()*Radius1);
		    g.setColor(Color.green);
		    fillCircle(g,tmpx,tmpy,radius);
		    g.setColor(Color.black);
		    drawCircle(g,tmpx,tmpy,radius);
		}
		if(draw_admittance_chart){
		    tmpx=xCenter+(int)(GammaYin.Real()*Radius1);
		    tmpy=yCenter+(int)(-GammaYin.Imaginary()*Radius1);
		    g.setColor(Color.green);
		    fillCircle(g,tmpx,tmpy,radius);
		    g.setColor(Color.black);
		    drawCircle(g,tmpx,tmpy,radius);
		}
            }	
            if(draw_Yin){
		//Yin
		if(draw_impedance_chart){
		    tmpx=xCenter+(int)(GammaYin.Real()*Radius1);
		    tmpy=yCenter+(int)(-GammaYin.Imaginary()*Radius1);
		    //g.setColor(Color.blue);
                    g.setColor(new Color(0,150,255));

		    fillCircle(g,tmpx,tmpy,radius);
		    g.setColor(Color.black);
		    drawCircle(g,tmpx,tmpy,radius);
		}
		if(draw_admittance_chart){
		    tmpx=xCenter+(int)(GammaZin.Real()*Radius1);
		    tmpy=yCenter+(int)(-GammaZin.Imaginary()*Radius1);
		    //g.setColor(Color.blue);
                    g.setColor(new Color(0,150,255));

		    fillCircle(g,tmpx,tmpy,radius);
		    g.setColor(Color.black);
		    drawCircle(g,tmpx,tmpy,radius);
		}		
            }
            if(draw_ZL){
		//ZL
		if(draw_impedance_chart){
		tmpx=xCenter+(int)(GammaZL.Real()*Radius1);
		tmpy=yCenter+(int)(-GammaZL.Imaginary()*Radius1);
		g.setColor(Color.red);
		fillCircle(g,tmpx,tmpy,radius);
		g.setColor(Color.black);
		drawCircle(g,tmpx,tmpy,radius);
		}
		if(draw_admittance_chart){
		tmpx=xCenter+(int)(GammaZL.Real()*Radius1);
		tmpy=yCenter+(int)(-GammaZL.Imaginary()*Radius1);
		g.setColor(Color.yellow);
		fillCircle(g,tmpx,tmpy,radius);
		g.setColor(Color.black);
		drawCircle(g,tmpx,tmpy,radius);
		}
            }
        }
        else{
            if(draw_ZL){
		//ZL
		if(draw_impedance_chart){
		tmpx=xCenter+(int)(GammaZL.Real()*Radius1);
		tmpy=yCenter+(int)(-GammaZL.Imaginary()*Radius1);
		g.setColor(Color.red);
		fillCircle(g,tmpx,tmpy,radius);
		g.setColor(Color.black);
		drawCircle(g,tmpx,tmpy,radius);
		}
		if(draw_admittance_chart){
		tmpx=xCenter+(int)(GammaZL.Real()*Radius1);
		tmpy=yCenter+(int)(-GammaZL.Imaginary()*Radius1);
		g.setColor(Color.yellow);
		fillCircle(g,tmpx,tmpy,radius);
		g.setColor(Color.black);
		drawCircle(g,tmpx,tmpy,radius);
		}
            }
            if(draw_Zin){
		//Zin
		if(draw_impedance_chart){
		    tmpx=xCenter+(int)(GammaZin.Real()*Radius1);
		    tmpy=yCenter+(int)(-GammaZin.Imaginary()*Radius1);
		    g.setColor(Color.green);
		    fillCircle(g,tmpx,tmpy,radius);
		    g.setColor(Color.black);
		    drawCircle(g,tmpx,tmpy,radius);
		}
		if(draw_admittance_chart){
		    tmpx=xCenter+(int)(GammaYin.Real()*Radius1);
		    tmpy=yCenter+(int)(-GammaYin.Imaginary()*Radius1);
		    g.setColor(Color.green);
		    fillCircle(g,tmpx,tmpy,radius);
		    g.setColor(Color.black);
		    drawCircle(g,tmpx,tmpy,radius);
		}
            }	
            if(draw_Yin){
		//Yin
		if(draw_impedance_chart){
		    tmpx=xCenter+(int)(GammaYin.Real()*Radius1);
		    tmpy=yCenter+(int)(-GammaYin.Imaginary()*Radius1);
		    //g.setColor(Color.blue);
                    g.setColor(new Color(0,150,255));

		    fillCircle(g,tmpx,tmpy,radius);
		    g.setColor(Color.black);
		    drawCircle(g,tmpx,tmpy,radius);
		}
		if(draw_admittance_chart){
		    tmpx=xCenter+(int)(GammaZin.Real()*Radius1);
		    tmpy=yCenter+(int)(-GammaZin.Imaginary()*Radius1);
		    //g.setColor(Color.blue);
                    g.setColor(new Color(0,150,255));

		    fillCircle(g,tmpx,tmpy,radius);
		    g.setColor(Color.black);
		    drawCircle(g,tmpx,tmpy,radius);
		}		
            }
        }
}


private void draw_swr_circle(Graphics g){
	
        if(colore_dark){
            g.setColor(Color.cyan);
        }
        else{
            g.setColor(Color.magenta);
        }

	drawCircle(g,xCenter,yCenter,(int)(Radius1*GammaZL.Magnitude()));
        
        g.setColor(Color.orange);
        if(GammaZL.Magnitude() >= GammaZin.Magnitude()/1.001 && GammaZL.Magnitude() <= GammaZin.Magnitude()*1.001){
            
        }
        else{
            drawCircle(g,xCenter,yCenter,(int)(Radius1*GammaZin.Magnitude()));
        }
}


private void draw_swr_line(Graphics g){
	int xcor, ycor, xxcor, yycor;
	double theta;
        
        draw_Zin = true;
	draw_Yin = true;
	
        /*
            if(xpos == 0.0){
		
                draw_Zin = false;
                draw_Yin = true;
      
	    }
	    else{
		draw_Zin = true;
		draw_Yin = true;
	    }
	*/
        
      if(xpos < 0.1){
          if(draw_Zin){
		//For Zin
		theta=-GammaZin.Arg2();
		//g.setColor(new Color(204,50,50));
		if(draw_impedance_chart){
		g.setColor(Color.green.darker());
		}
		if(draw_admittance_chart){
		g.setColor(Color.blue);
		}
		
		xcor=(int)(GammaZin.Real()*Radius1)+xCenter;
		ycor=(int)(-GammaZin.Imaginary()*Radius1)+yCenter;
		g.drawLine(xCenter,yCenter,xcor,ycor);
		xxcor=(int)(Math.cos(theta)*Radius2)+xCenter;
		yycor=(int)(Math.sin(theta)*Radius2)+yCenter;
		
		g.drawLine(xcor,ycor,xxcor,yycor);
	}
	if(draw_Yin){
		//For Yin
		theta=-GammaYin.Arg2();
		//g.setColor(new Color(204,50,50));
		if(draw_impedance_chart){
		g.setColor(Color.blue);
		}
		if(draw_admittance_chart){
		g.setColor(Color.green.darker());
		}
		xcor=(int)(GammaYin.Real()*Radius1)+xCenter;
		ycor=(int)(-GammaYin.Imaginary()*Radius1)+yCenter;
		g.drawLine(xCenter,yCenter,xcor,ycor);
		xxcor=(int)(Math.cos(theta)*Radius2)+xCenter;
		yycor=(int)(Math.sin(theta)*Radius2)+yCenter;
	
		g.drawLine(xcor,ycor,xxcor,yycor);
	}
        if(draw_ZL){
		//For  ZL ...
		theta=-GammaZL.Arg2();
		g.setColor(new Color(204,50,50));
		xcor=(int)(GammaZL.Real()*Radius1)+xCenter;
		ycor=(int)(-GammaZL.Imaginary()*Radius1)+yCenter;
		g.drawLine(xCenter,yCenter,xcor,ycor);
		xxcor=(int)(Math.cos(theta)*Radius2)+xCenter;
		yycor=(int)(Math.sin(theta)*Radius2)+yCenter;
		if(draw_impedance_chart){
		    g.setColor(Color.red);
		}
		if(draw_admittance_chart){
		    g.setColor(Color.yellow);
		}
		g.drawLine(xcor,ycor,xxcor,yycor);
	}
      }
      else{
	if(draw_ZL){
		//For  ZL ...
		theta=-GammaZL.Arg2();
		g.setColor(new Color(204,50,50));
		xcor=(int)(GammaZL.Real()*Radius1)+xCenter;
		ycor=(int)(-GammaZL.Imaginary()*Radius1)+yCenter;
		g.drawLine(xCenter,yCenter,xcor,ycor);
		xxcor=(int)(Math.cos(theta)*Radius2)+xCenter;
		yycor=(int)(Math.sin(theta)*Radius2)+yCenter;
		if(draw_impedance_chart){
		    g.setColor(Color.red);
		}
		if(draw_admittance_chart){
		    g.setColor(Color.yellow);
		}
		g.drawLine(xcor,ycor,xxcor,yycor);
	}
	if(draw_Zin){
		//For Zin
		theta=-GammaZin.Arg2();
		//g.setColor(new Color(204,50,50));
		if(draw_impedance_chart){
		g.setColor(Color.green.darker());
		}
		if(draw_admittance_chart){
		g.setColor(Color.blue);
		}
		
		xcor=(int)(GammaZin.Real()*Radius1)+xCenter;
		ycor=(int)(-GammaZin.Imaginary()*Radius1)+yCenter;
		g.drawLine(xCenter,yCenter,xcor,ycor);
		xxcor=(int)(Math.cos(theta)*Radius2)+xCenter;
		yycor=(int)(Math.sin(theta)*Radius2)+yCenter;
		
		g.drawLine(xcor,ycor,xxcor,yycor);
	}
	if(draw_Yin){
		//For Yin
		theta=-GammaYin.Arg2();
		//g.setColor(new Color(204,50,50));
		if(draw_impedance_chart){
		g.setColor(Color.blue);
		}
		if(draw_admittance_chart){
		g.setColor(Color.green.darker());
		}
		xcor=(int)(GammaYin.Real()*Radius1)+xCenter;
		ycor=(int)(-GammaYin.Imaginary()*Radius1)+yCenter;
		g.drawLine(xCenter,yCenter,xcor,ycor);
		xxcor=(int)(Math.cos(theta)*Radius2)+xCenter;
		yycor=(int)(Math.sin(theta)*Radius2)+yCenter;
	
		g.drawLine(xcor,ycor,xxcor,yycor);
	}
      }
}



public final synchronized void setZin(Complex Zin){
	this.Zin = Zin;
	GammaZin = EMF.computeGamma(Zin);
	this.Yin = EMF.Inv(Zin);
	GammaYin = EMF.computeGamma(Yin);
	repaint();
}

public final synchronized void setZin(Complex Zin, double Z0){
	setZin(Complex.Divide(Zin,Z0));
}

public final synchronized void setZin(Complex Zin, Complex Z0){
	setZin(Complex.Divide(Zin,Z0));
}

public final synchronized void setYin(Complex Yin){
	this.Yin = Yin;
	this.Zin = EMF.Inv(Yin);
	GammaZin = EMF.computeGamma(Zin);
	GammaYin = EMF.computeGamma(Yin);
	repaint();
}

public final synchronized void setYin(Complex Yin, double Z0){
	setZin(Complex.Divide(Yin,Z0));
}

public final synchronized void setYin(Complex Yin, Complex Z0){
	setZin(Complex.Divide(Zin,Z0));
}

public final synchronized void setZL(Complex ZL){
	this.ZL = ZL;
	GammaZL = EMF.computeGamma(this.ZL);
	this.YL = EMF.Inv(ZL);
	repaint();
}

public final synchronized void setZL(Complex ZL, double Z0){
	setZL(Complex.Divide(ZL,Z0));
}

public final synchronized void setZL(Complex ZL, Complex Z0){
	setZL(Complex.Divide(ZL,Z0));
}

public final synchronized void setYL(Complex YL){
	this.YL = YL;
	GammaZL = EMF.computeGamma(this.YL,false);
	this.ZL = EMF.Inv(YL);
	repaint();
}

public final synchronized void setYL(Complex YL, double Z0){
	setYL(Complex.Multiply(YL,Z0));
}

public final synchronized void setYL(Complex YL, Complex Z0){
	setYL(Complex.Multiply(YL,Z0));
}


public synchronized void set_swr_circle(boolean arg){
	draw_swr_circle=arg;
	repaint();
}

public synchronized void set_swr_line(boolean arg){
	draw_swr_line=arg;
	repaint();
}

public synchronized void set_impedance(boolean arg){
	draw_impedance_chart=arg;
	draw_admittance_chart=!arg;
	repaint();
}

public synchronized void set_admittance(boolean arg){
	draw_admittance_chart=arg;
	draw_impedance_chart=!arg;
	repaint();
}

public synchronized void setColoreDark(boolean colore_dark){
	this.colore_dark = colore_dark;
	repaint();
}

public synchronized void setZL(boolean arg){
	draw_ZL = arg;
	repaint();
}

public synchronized void setZin(boolean arg){
	draw_Zin = arg;	
	repaint();
}

public synchronized void setYin(boolean arg){
	draw_Yin = arg;
	repaint();
}

public synchronized void setxpos(double xpos){
	this.xpos=xpos;
	repaint();
}

private  void cricket_1(MouseEvent evt){
	int tx1, ty1;
	int x, y;
	x=evt.getX();
	y=evt.getY();
	tx1=x-xCenter;
	ty1=y-yCenter;	
	if(Math.pow(tx1,2.0)+Math.pow(ty1,2.0)<=Math.pow(Radius1,2.0)){
		Graphics g = this.getGraphics();
		g.clipRect(xProbe-10,yProbe-10,20,20);
		paint(g);
		g.clipRect(0,0,getSize().width,getSize().height);
		SmithCanvas.plot_red_cross(g,x,y);
		g.dispose();
		xProbe=x;
		yProbe=y;
		GammaProbe=new Complex(1.0*tx1/Radius1,-1.0*ty1/Radius1);
		ZProbe=EMF.computeZ(GammaProbe);
	}
}
public void mouseDragged(MouseEvent evt){cricket_1(evt);}
public void mouseMoved(MouseEvent evt){;}
public void mouseClicked(MouseEvent evt){cricket_1(evt);}
public void mouseEntered(MouseEvent evt){setCursor(cursorB);}
public void mouseExited(MouseEvent evt){setCursor(cursorA);}
public void mousePressed(MouseEvent evt){cricket_1(evt);}
public void mouseReleased(MouseEvent evt){cricket_1(evt);}


public final Complex getZProbe(){
	return ZProbe;
}

public final Complex getGammaProbe(){
	return GammaProbe;
}

public static void plot_red_cross(Graphics g, int x, int y){
	g.setColor(Color.white);
			g.fillRect(x-5, y-1,11,3);
			g.fillRect(x-1,y-5,3,11);
		g.setColor(Color.red);
			g.drawLine(x-4,y,x+4,y);
			g.drawLine(x,y-4,x,y+4);
}

public Complex getZL(){
	return (Complex)ZL.clone();
}

public Complex getZin(){
	return (Complex)Zin.clone();
}

public Complex getYin(){
	return (Complex)Yin.clone();
}

}//End SmithCanvas

/*******************************************************************************************/
class SmithMan extends Panel{
    private Label[] vlab, lab;
    private static final Color bgcolor = new Color(236,236,236);
    int mode;//mode=1 Impedance, mode=2 Admittance Chart
    boolean IsLoadOpen, IsLoadShort, IsLoadImaginary, IsLoadRegular, Gamma_plusone, Gamma_minusone;

    public Complex ZL, YL, GammaL, Zin, Yin, GammaIn;
    private Image imago;
    private Graphics buffer;    

    Trans_State state;
    
    private BufferedImage angle_img;

	SmithMan(int width, int height, Trans_State state){
		super();
                this.state = state;
                
		getImages();
		setLayout(null);
		mode=1;
		setBackground(bgcolor);
		Font labelfont=new Font("SanSerif",Font.PLAIN,state.font11);
		//Panel p = new Panel();
		//p.setLayout(new GridLayout(5,2));
		int ystart = state.s1;
                int ystep = state.s14; 
                int yhigh = state.s12;
                IsLoadOpen = false;
                IsLoadShort = false;
                IsLoadImaginary = false;
                IsLoadRegular = true;
                ZL = new Complex(1.0,1.0);
                YL = new Complex(0.5,-0.5);
                Zin = new Complex(1.0,1.0);
                Yin = new Complex(0.5,-0.5);
                
                if(Complex.Real(ZL)==0.0 && Complex.Imaginary(ZL)==0.0){
                    IsLoadShort = true;
                    IsLoadOpen = false;
                    IsLoadImaginary = false;
                    IsLoadRegular = false;
                }
                else if(Complex.Real(YL)==0.0 && Complex.Imaginary(YL)==0.0){
                    IsLoadOpen = true;
                    IsLoadShort = false;
                    IsLoadImaginary = false;
                    IsLoadRegular = false;
                }
                else if(Complex.Real(ZL)==0.0 && Complex.Imaginary(ZL)!=0.0){
                    IsLoadImaginary = true;
                    IsLoadShort = false;
                    IsLoadOpen = false;
                    IsLoadRegular = false;
                }
                else if((Complex.Real(ZL)!=0.0 && Complex.Imaginary(ZL)!=0.0) ||
                    (Complex.Real(ZL)!=0.0 && Complex.Imaginary(ZL)==0.0))
                {
                    IsLoadRegular = true;
                    IsLoadShort = false;
                    IsLoadOpen = false;
                    IsLoadImaginary = false;
                }
                
                lab = new Label[5];
		vlab = new Label[5];
		lab[0] = new Label("z",Label.LEFT);
		lab[1] = new Label("",Label.LEFT);
		lab[2] = new Label("z(d)",Label.LEFT);
		lab[3] = new Label("(d)",Label.LEFT);
		lab[4] = new Label("y(d)",Label.LEFT);
                
                lab[0].setBounds(state.s30,ystart-state.s1,state.s10,yhigh);
                lab[1].setBounds(state.s30,ystart+ystep-state.s1,0,yhigh);
                lab[2].setBounds(state.s30,ystart+2*ystep+state.s1,state.s30,yhigh);
                lab[3].setBounds(state.s40,ystart+3*ystep+state.s1,state.s20,yhigh);
                lab[4].setBounds(state.s30,ystart+4*ystep+state.s1,state.s30,yhigh);
                
		for(int i = 0; i<lab.length; i++){
			vlab[i] = new Label("",Label.LEFT);
			vlab[i].setFont(labelfont);
			lab[i].setFont(labelfont);
                        //lab[i].setBounds(30,ystart+(i)*ystep,40,yhigh);
                        //vlab[i].setBounds(65,ystart+(i)*ystep,200,yhigh);
                        //add(lab[i]);
			//add(vlab[i]);
                        
                        //p.add(lab[i]);
			//p.add(vlab[i]);
		}
		//add(p);
		//p.setBounds(20,2,width-25,height-4);
                
                
	}


    private void getImages() {
        // read in the angle image, because CHEERPJ does not render this
	//  symbol in any font!  (java to javascript converter)
        try {
            //angle_img = ImageIO.read(getClass().getResource("angle.png"));
	    BufferedImage img =
		ImageIO.read(getClass().getResource("angle.png"));
	    int targetWidth = (int) (state.sfactor * img.getWidth());
	    int targetHeight = (int) (state.sfactor * img.getHeight());
	    angle_img =
		new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB);
	    Graphics2D graphics2D = angle_img.createGraphics();
	    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
					RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	    graphics2D.drawImage(img, 0, 0, targetWidth, targetHeight, 0, 0,
				 img.getWidth(), img.getHeight(), null);
	    graphics2D.dispose();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
        
	public void paint(Graphics g){
	    if(imago == null){
		imago = createImage(getSize().width,getSize().height);
		buffer = imago.getGraphics();
		drawSmithMan(buffer);
	    }
	    else{
		drawSmithMan(buffer);
	    }
	    g.drawImage(imago,0,0,null);
        }

        //Addition to reduce flicker new routine
        public void update(Graphics g){		// added to avoid clearing
            paint(g);
        }
        
	public void drawSmithMan(Graphics g){
		    
            g.clearRect(0,0,getSize().width,getSize().height);
            Font symbolfont=new Font("Symbol",Font.PLAIN,12);
            FontMetrics fm;
		
            g.setFont(new Font("Serif",Font.PLAIN,state.font12));
		
		String alpha, Ohm, lambda, infinity, Gamma, plusj, minusj, sign;
		g.setFont(symbolfont);
		alpha="\u03b1";
		lambda="\u03bb";
		Ohm="\u03a9";
		infinity="\u221e";
		Gamma="\u0393";
                int vstep = state.s75/5;
		int vstepinit = state.s12;
		int xinit = state.s35;
		int xinit2 = xinit+state.s30;
		int xinit3 = xinit2+state.s70;
            
            //---------------------------------------------------------------------------------------    
            g.setColor(Color.white);
            g.drawLine(0,0,0,getSize().height-1);
            g.drawLine(0,0,getSize().width-1,0);
            g.setColor(Color.black);
            g.drawLine(getSize().width-1,0,getSize().width-1,getSize().height-1);
            g.drawLine(0,getSize().height-1,getSize().width-1,getSize().height-1);
                
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        	
	    if(mode==1){
		g.setColor(Color.red);
		g.fillOval(state.s8,state.s3,state.s8,state.s8);
		g.setColor(Color.green);
		g.fillOval(state.s8,state.s32,state.s8,state.s8);
		//g.setColor(Color.blue);
                g.setColor(new Color(0,150,255));
		g.fillOval(state.s8,state.s60,state.s8,state.s8);	
    	    }
	    if(mode==2){
		g.setColor(Color.yellow);
		g.fillOval(state.s8,state.s3,state.s8,state.s8);
		//g.setColor(Color.blue);
                g.setColor(new Color(0,150,255));
		g.fillOval(state.s8,state.s32,state.s8,state.s8);
		g.setColor(Color.green);
		g.fillOval(state.s8,state.s60,state.s8,state.s8);
	    }
            g.setColor(Color.black);
            g.drawOval(state.s8,state.s3,state.s8,state.s8);
            g.drawOval(state.s8,state.s32,state.s8,state.s8);
            g.drawOval(state.s8,state.s60,state.s8,state.s8);
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
            //-------------------------------------------------------------------------------------------
		g.setFont(new Font("SanSerif",Font.PLAIN,state.font11));
		plusj =" + j ";
		minusj=" - j ";
                
                fm = g.getFontMetrics();
             //-----------------------------------------------------------------------
             double tempR = 1.0, tempX = 2.0;
             int stepx = 0;
	    
             if(mode==1){
                 if(Complex.Real(ZL)==0.0 && Complex.Imaginary(ZL)==0.0){
                    IsLoadShort = true;
                    IsLoadOpen = false;
                    IsLoadImaginary = false;
                    IsLoadRegular = false;
                }
                else if((Complex.Real(ZL)==0.0 && Complex.Imaginary(ZL)<-1.0E130)||Complex.Magnitude(ZL)>1.0E130){
                    IsLoadOpen = true;
                    IsLoadShort = false;
                    IsLoadImaginary = false;
                    IsLoadRegular = false;
                }
                else if(Complex.Real(ZL)==0.0 && Complex.Imaginary(ZL)!=0.0){
                    IsLoadImaginary = true;
                    IsLoadShort = false;
                    IsLoadOpen = false;
                    IsLoadRegular = false;
                }
                else if((Complex.Real(ZL)!=0.0 && Complex.Imaginary(ZL)!=0.0) ||
                    (Complex.Real(ZL)!=0.0 && Complex.Imaginary(ZL)==0.0))
                {
                    IsLoadRegular = true;
                    IsLoadShort = false;
                    IsLoadOpen = false;
                    IsLoadImaginary = false;
                }
                
                //-----------------------------------------------------------------------------
                    g.setColor(Color.black);
                    MaestroG.subscripter(" z","L","",g,state.font11,xinit,vstepinit);
		
		if(IsLoadOpen){
		    MaestroG.subscripterInfinityOne("=    ","","","",g,state.font11,xinit2,vstepinit);
		}
		else if(IsLoadShort){
		    MaestroG.subscripter("=    0.0 + j 0.0","","",g,state.font11,xinit2,vstepinit);
		}
		else{
		    if(Complex.Imaginary(ZL) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(IsLoadImaginary){
			tempR = 0.0;
		    }
		    else if(IsLoadRegular){
			tempR = ZL.Real();
		    }
		    
		    if(tempR < 1.0E3 && tempR >= 1.0E-3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR,6),"","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR,6));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("=    0.0","","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=    0.0 ");
		    }
		    else if(tempR < 1.0E6 && tempR >= 1.0E3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-3,2)+" x 10","3","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-3,2)+"x 10 3");
		    }
		    else if(tempR < 1.0E9 && tempR >= 1.0E6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-6,2)+" x 10","6","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-6,2)+"x 10 6");
		    }
		    else if(tempR < 1.0E12 && tempR >= 1.0E9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-9,2)+" x 10","9","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-9,2)+"x 10 9");
		    }
		    else if(tempR < 1.0E15 && tempR >= 1.0E12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-12,2)+" x 10","12","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-12,2)+"x 10 12");
		    }
		    else if(tempR < 1.0E18 && tempR >= 1.0E15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-15,2)+" x 10","15","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-15,2)+"x 10 15");
		    }
		    else if(tempR < 1.0E21 && tempR >= 1.0E18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-18,2)+" x 10","18","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-18,2)+"x 10 18");
		    }
		    else if(tempR < 1.0E24 && tempR >= 1.0E21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-21,2)+" x 10","21","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-21,2)+"x 10 21");
		    }
		    else if(tempR < 1.0E27 && tempR >= 1.0E24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-24,2)+" x 10","24","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-24,2)+"x 10 24");
		    }
		    else if(tempR < 1.0E30 && tempR >= 1.0E27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-27,2)+" x 10","27","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-27,2)+"x 10 27");
		    }
		    else if(tempR >= 1.0E30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-30,2)+" x 10","30","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-30,2)+"x 10 30");
		    }
		    else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E6,2)+" x 10","-6","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E6,2)+"x 10 -6");
		    }
		    else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E9,2)+" x 10","-9","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E9,2)+"x 10 -9");
		    }
		    else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E12,2)+" x 10","-12","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E12,2)+"x 10 -12");
		    }
		    else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E15,2)+" x 10","-15","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E15,2)+"x 10 -15");
		    }
		    else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E18,2)+" x 10","-18","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=  "+MaestroA.rounder(tempR*1.0E18,2)+"x 10 -18");
		    }
		    else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E21,2)+" x 10","-21","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E21,2)+"x 10 -21");
		    }
		    else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E24,2)+" x 10","-24","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E24,2)+"x 10 -24");
		    }
                    else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E27,2)+" x 10","-27","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E27,2)+"x 10 -27");
		    }
                    else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E30,2)+" x 10","-30","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E30,2)+"x 10 -30");
		    }
                    else if(tempR < 1.0E-30 && tempR != 0.0){
			MaestroG.superscripter("=   0.0","","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   0.0");
		    }
		    
		    tempX = Math.abs(ZL.Imaginary());
		    xinit3 = xinit2+stepx;
		    
		    if(tempX < 1.0E3 && tempX >= 1.0E-3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX,6),"","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E6 && tempX >= 1.0E3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-3,2)+" x 10","3","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E9 && tempX >= 1.0E6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-6,2)+" x 10","6","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E12 && tempX >= 1.0E9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-9,2)+" x 10","9","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E15 && tempX >= 1.0E12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-12,2)+" x 10","12","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E18 && tempX >= 1.0E15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-15,2)+" x 10","15","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E21 && tempX >= 1.0E18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-18,2)+" x 10","18","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E24 && tempX >= 1.0E21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-21,2)+" x 10","21","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E27 && tempX >= 1.0E24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-24,2)+" x 10","24","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E30 && tempX >= 1.0E27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-27,2)+" x 10","27","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-3 && tempX >= 1.0E-6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E6,2)+" x 10","-6","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-6 && tempX >= 1.0E-9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E9,2)+" x 10","-9","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-9 && tempX >= 1.0E-12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E12,2)+" x 10","-12","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-12 && tempX >= 1.0E-15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E15,2)+" x 10","-15","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-15 && tempX >= 1.0E-18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E18,2)+" x 10","-18","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-18 && tempX >= 1.0E-21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E21,2)+" x 10","-21","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-21 && tempX >= 1.0E-24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,state.font11,xinit3,vstepinit);
		    }
                    else if(tempX < 1.0E-24 && tempX >= 1.0E-27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E27,2)+" x 10","-27","",g,state.font11,xinit3,vstepinit);
		    }
                    else if(tempX < 1.0E-27 && tempX >= 1.0E-30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E30,2)+" x 10","-30","",g,state.font11,xinit3,vstepinit);
		    }
                    else if(tempX < 1.0E-30 && tempX != 0.0){
			MaestroG.superscripter(sign+" 0.0","","",g,state.font11,xinit3,vstepinit);
		    }
                }

                MaestroG.subscripterSS3(" "+Gamma,"L","",g,state.font11,xinit+1,vstepinit + vstep);
		
                //write the angle with italic L for angle symbol - modify the toString process
                double dtmp1, dtmp2;
                dtmp1=MaestroA.rounder(GammaL.Magnitude(),8);
                    if(dtmp1 == 0.0){dtmp2 = 0.0;}
                    else{dtmp2=MaestroA.rounder(GammaL.Arg2()*180/Math.PI,6);}
		//MaestroG.SansPLAIN("=   "+dtmp1,"  \u2220 ",""+dtmp2+" \u00ba",g,state.font11,xinit2,vstepinit + vstep);
		MaestroG.TxtImgTxt("=   "+dtmp1,angle_img,""+dtmp2+" \u00ba",g,state.font11,xinit2,vstepinit + vstep,this);

                MaestroG.subscripterSS3(""+Gamma,"","(d)",g,state.font11,xinit+1,vstepinit + 3*vstep);
		//MaestroG.superscripter("= "+Ginput.toString(Complex.POLAR_DEGREE,4),"","",g,state.font11,xinit2,vstepinit + 3*vstep);
		
                //write the angle with italic L for angle symbol - modify the toString process
                dtmp1=MaestroA.rounder(GammaIn.Magnitude(),8);
                    if(dtmp1 == 0.0){dtmp2 = 0.0;}
                    else{dtmp2=MaestroA.rounder(GammaIn.Arg2()*180/Math.PI,6);}
		//MaestroG.SansPLAIN("=   "+dtmp1,"  \u2220 ",""+dtmp2+" \u00ba",g,state.font11,xinit2,vstepinit + 3*vstep-state.s1);
		MaestroG.TxtImgTxt("=   "+dtmp1,angle_img,""+dtmp2+" \u00ba",g,state.font11,xinit2,vstepinit + 3*vstep-state.s1,this);
                
		if(Complex.Real(GammaIn) > 0.999999 && Math.abs(Complex.Imaginary(GammaIn)) < 0.000001){
		    Gamma_plusone = true;
		    Gamma_minusone = false;
		}
		else if(Complex.Real(GammaIn) < -0.999999 && Math.abs(Complex.Imaginary(GammaIn)) < 0.000001){
		    Gamma_plusone = false;
		    Gamma_minusone = true;
		}
		else{
		    Gamma_plusone = false;
		    Gamma_minusone = false;
		}
		
		MaestroG.subscripter("z","","(d)",g,state.font11,xinit,vstepinit + 2*vstep);
                
                if((IsLoadOpen || IsLoadImaginary) && Gamma_plusone){
		    MaestroG.subscripterInfinityOne("=    ","","","",g,state.font11,xinit2,vstepinit + 2*vstep);
		}
		else if((IsLoadOpen || IsLoadImaginary) && Gamma_minusone){
		    MaestroG.subscripter("=    0.0 + j 0.0","","",g,state.font11,xinit2,vstepinit + 2*vstep);
		}
		else if((IsLoadShort || IsLoadImaginary) && Gamma_plusone){
		    MaestroG.subscripterInfinityOne("=    ","","","",g,state.font11,xinit2,vstepinit + 2*vstep);
		}
		else if((IsLoadShort || IsLoadImaginary) && Gamma_minusone){
		    MaestroG.subscripter("=    0.0 + j 0.0","","",g,state.font11,xinit2,vstepinit + 2*vstep);
		}
    
		else{
                   
		    if(Complex.Imaginary(Zin) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(IsLoadImaginary || IsLoadOpen || IsLoadShort){
			tempR = 0.0;
		    }
		    else if(IsLoadRegular){
			tempR = Zin.Real();
		    }
		    
		    if(tempR < 1.0E3 && tempR >= 1.0E-3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR,6),"","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR,6));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("=    0.0","","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=    0.0 ");
		    }
		    else if(tempR < 1.0E6 && tempR >= 1.0E3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-3,2)+" x 10","3","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-3,2)+"x 10 3");
		    }
		    else if(tempR < 1.0E9 && tempR >= 1.0E6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-6,2)+" x 10","6","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-6,2)+"x 10 6");
		    }
		    else if(tempR < 1.0E12 && tempR >= 1.0E9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-9,2)+" x 10","9","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-9,2)+"x 10 9");
		    }
		    else if(tempR < 1.0E15 && tempR >= 1.0E12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-12,2)+" x 10","12","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-12,2)+"x 10 12");
		    }
		    else if(tempR < 1.0E18 && tempR >= 1.0E15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-15,2)+" x 10","15","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-15,2)+"x 10 15");
		    }
		    else if(tempR < 1.0E21 && tempR >= 1.0E18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-18,2)+" x 10","18","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-18,2)+"x 10 18");
		    }
		    else if(tempR < 1.0E24 && tempR >= 1.0E21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-21,2)+" x 10","21","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-21,2)+"x 10 21");
		    }
		    else if(tempR < 1.0E27 && tempR >= 1.0E24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-24,2)+" x 10","24","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-24,2)+"x 10 24");
		    }
		    else if(tempR < 1.0E30 && tempR >= 1.0E27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-27,2)+" x 10","27","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=  "+MaestroA.rounder(tempR*1.0E-27,2)+"x 10 27");
		    }
		    else if(tempR >= 1.0E30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-30,2)+" x 10","30","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-30,2)+"x 10 30");
		    }
		    else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E6,2)+" x 10","-6","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E6,2)+"x 10 -6");
		    }
		    else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E9,2)+" x 10","-9","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E9,2)+"x 10 -9");
		    }
		    else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E12,2)+" x 10","-12","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E12,2)+"x 10 -12");
		    }
		    else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E15,2)+" x 10","-15","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E15,2)+"x 10 -15");
		    }
		    else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E18,2)+" x 10","-18","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E18,2)+"x 10 -18");
		    }
		    else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E21,2)+" x 10","-21","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E21,2)+"x 10 -21");
		    }
		    else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E24,2)+" x 10","-24","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E24,2)+"x 10 -24");
		    }
                    else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E27,2)+" x 10","-27","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E27,2)+"x 10 -27");
		    }
                    else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E30,2)+" x 10","-30","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E30,2)+"x 10 -30");
		    }
                    else if(tempR < 1.0E-30 && tempR != 0.0){
			MaestroG.superscripter("=   0.0","","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   0.0");
		    }
		    
		    tempX = Math.abs(Zin.Imaginary());
		    xinit3 = xinit2+stepx;
		    
		    if(tempX < 1.0E3 && tempX >= 1.0E-3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX,6),"","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,state.font11,xinit3,vstepinit + 2*vstep);
		    }
		    else if(tempX < 1.0E6 && tempX >= 1.0E3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-3,2)+" x 10","3","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E9 && tempX >= 1.0E6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-6,2)+" x 10","6","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E12 && tempX >= 1.0E9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-9,2)+" x 10","9","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E15 && tempX >= 1.0E12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-12,2)+" x 10","12","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E18 && tempX >= 1.0E15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-15,2)+" x 10","15","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E21 && tempX >= 1.0E18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-18,2)+" x 10","18","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E24 && tempX >= 1.0E21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-21,2)+" x 10","21","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E27 && tempX >= 1.0E24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-24,2)+" x 10","24","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E30 && tempX >= 1.0E27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-27,2)+" x 10","27","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-3 && tempX >= 1.0E-6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E6,2)+" x 10","-6","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-6 && tempX >= 1.0E-9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E9,2)+" x 10","-9","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-9 && tempX >= 1.0E-12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E12,2)+" x 10","-12","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
                    
                    else if(tempX < 1.0E-12){
			MaestroG.superscripter(" + j 0.0","","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    /*
                    else if(tempX < 1.0E-12 && tempX >= 1.0E-15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E15,2)+" x 10","-15","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-15 && tempX >= 1.0E-18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E18,2)+" x 10","-18","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-18 && tempX >= 1.0E-21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E21,2)+" x 10","-21","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-21 && tempX >= 1.0E-24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
                    else if(tempX < 1.0E-24 && tempX >= 1.0E-27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E27,2)+" x 10","-27","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
                    else if(tempX < 1.0E-27 && tempX >= 1.0E-30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E30,2)+" x 10","-30","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
                    else if(tempX < 1.0E-30 && tempX != 0.0){
			MaestroG.superscripter(sign+" 0.0","","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
                    */
		}
                
                vstepinit-=1;
                MaestroG.subscripter("y","","(d)",g,state.font11,xinit+2,vstepinit + 4*vstep);
		
		if(Complex.Real(Yin)==0.0&&Complex.Imaginary(Yin)<-1.0E130){
		    MaestroG.subscripterInfinityOne("=    ","","","",g,state.font11,xinit2,vstepinit + 4*vstep);
		}
		else if(Complex.Real(Yin)==0.0&&Complex.Imaginary(Yin)==0.0){
		    MaestroG.subscripter("=    0.0 + j 0.0","","",g,state.font11,xinit2,vstepinit + 4*vstep);
		}
		else{
		    if(Complex.Imaginary(Yin) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(IsLoadImaginary || IsLoadOpen || IsLoadShort){
			tempR = 0.0;
		    }
		    else if(IsLoadRegular){
			tempR = Yin.Real();
		    }
		    
		    if(tempR < 1.0E3 && tempR >= 1.0E-3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR,6),"","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR,6));
		    }
		    else if(tempR == 0.0){
			if(Math.abs(Yin.Imaginary())<1.0e6){
                            MaestroG.superscripter("=    0.0","","",g,state.font11,xinit2,vstepinit+ 4*vstep);
                        }
                        stepx = fm.stringWidth("=    0.0 ");
		    }
		    else if(tempR < 1.0E6 && tempR >= 1.0E3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-3,2)+" x 10","3","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-3,2)+"x 10 3");
		    }
		    else if(tempR < 1.0E9 && tempR >= 1.0E6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-6,2)+" x 10","6","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-6,2)+"x 10 6");
		    }
		    else if(tempR < 1.0E12 && tempR >= 1.0E9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-9,2)+" x 10","9","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-9,2)+"x 10 9");
		    }
		    else if(tempR < 1.0E15 && tempR >= 1.0E12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-12,2)+" x 10","12","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-12,2)+"x 10 12");
		    }
		    else if(tempR < 1.0E18 && tempR >= 1.0E15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-15,2)+" x 10","15","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-15,2)+"x 10 15");
		    }
		    else if(tempR < 1.0E21 && tempR >= 1.0E18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-18,2)+" x 10","18","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-18,2)+"x 10 18");
		    }
		    else if(tempR < 1.0E24 && tempR >= 1.0E21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-21,2)+" x 10","21","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-21,2)+"x 10 21");
		    }
		    else if(tempR < 1.0E27 && tempR >= 1.0E24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-24,2)+" x 10","24","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-24,2)+"x 10 24");
		    }
		    else if(tempR < 1.0E30 && tempR >= 1.0E27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-27,2)+" x 10","27","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-27,2)+"x 10 27");
		    }
		    else if(tempR >= 1.0E30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-30,2)+" x 10","30","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-30,2)+"x 10 30");
		    }
		    else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E6,2)+" x 10","-6","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E6,2)+"x 10 -6");
		    }
		    else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E9,2)+" x 10","-9","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E9,2)+"x 10 -9");
		    }
		    else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E12,2)+" x 10","-12","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E12,2)+"x 10 -12");
		    }
		    else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E15,2)+" x 10","-15","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E15,2)+"x 10 -15");
		    }
		    else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E18,2)+" x 10","-18","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E18,2)+"x 10 -18");
		    }
		    else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E21,2)+" x 10","-21","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E21,2)+"x 10 -21");
		    }
		    else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E24,2)+" x 10","-24","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E24,2)+"x 10 -24");
		    }
                    else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E27,2)+" x 10","-27","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E27,2)+"x 10 -27");
		    }
                    else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E30,2)+" x 10","-30","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E30,2)+"x 10 -30");
		    }
                    else if(tempR < 1.0E-30 && tempR != 0.0){
			MaestroG.superscripter("=   0.0","","",g,state.font11,xinit2,vstepinit+ 4*vstep);
                        stepx = fm.stringWidth("=   0.0");
		    }
		    
		    tempX = Math.abs(Yin.Imaginary());
		    xinit3 = xinit2+stepx;
		    
		    if(tempX < 1.0E3 && tempX >= 1.0E-3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX,6),"","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,state.font11,xinit3,vstepinit + 4*vstep);
		    }
		    else if(tempX <= 1.0E6 && tempX >= 1.0E3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-3,2)+" x 10","3","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
                    else if(tempX > 1.0E6){
			MaestroG.subscripterInfinityOne("=    ","","","",g,state.font11,xinit2,vstepinit + 4*vstep);
		    }
		    /*
                    else if(tempX < 1.0E9 && tempX >= 1.0E6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-6,2)+" x 10","6","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E12 && tempX >= 1.0E9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-9,2)+" x 10","9","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E15 && tempX >= 1.0E12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-12,2)+" x 10","12","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E18 && tempX >= 1.0E15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-15,2)+" x 10","15","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E21 && tempX >= 1.0E18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-18,2)+" x 10","18","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E24 && tempX >= 1.0E21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-21,2)+" x 10","21","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E27 && tempX >= 1.0E24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-24,2)+" x 10","24","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E30 && tempX >= 1.0E27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-27,2)+" x 10","27","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
                     */
		    else if(tempX < 1.0E-3 && tempX >= 1.0E-6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E6,2)+" x 10","-6","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-6 && tempX >= 1.0E-9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E9,2)+" x 10","-9","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
                    // Alternate
		    else if(tempX < 1.0E-9 && tempX != 0.0){
			MaestroG.superscripter(sign+" 0.0","","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
                    //else if(tempX < 1.0E-9 && tempX >= 1.0E-12){
			//MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E12,2)+" x 10","-12","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    //}
		    /*
                    else if(tempX < 1.0E-12 && tempX >= 1.0E-15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E15,2)+" x 10","-15","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-15 && tempX >= 1.0E-18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E18,2)+" x 10","-18","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-18 && tempX >= 1.0E-21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E21,2)+" x 10","-21","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-21 && tempX >= 1.0E-24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
                    else if(tempX < 1.0E-24 && tempX >= 1.0E-27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E27,2)+" x 10","-27","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
                    else if(tempX < 1.0E-27 && tempX >= 1.0E-30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E30,2)+" x 10","-30","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
                    else if(tempX < 1.0E-30 && tempX != 0.0){
			MaestroG.superscripter(sign+" 0.0","","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
                     */
		}               
            }
             else if(mode == 2){
                
                if(Complex.Real(YL)==0.0 && Complex.Imaginary(YL)==0.0){
                    IsLoadShort = false;
                    IsLoadOpen = true;
                    IsLoadImaginary = false;
                    IsLoadRegular = false;
                }
                else if((Complex.Real(YL)==0.0 && Complex.Imaginary(YL)<-1.0E130)||Complex.Magnitude(YL)>1.0E100 ||
                    Complex.Magnitude(ZL)==0.0){
                    IsLoadOpen = false;
                    IsLoadShort = true;
                    IsLoadImaginary = false;
                    IsLoadRegular = false;
                }
                else if(Complex.Real(YL)==0.0 && Complex.Imaginary(YL)!=0.0){
                    IsLoadImaginary = true;
                    IsLoadShort = false;
                    IsLoadOpen = false;
                    IsLoadRegular = false;
                }
                else if((Complex.Real(YL)!=0.0 && Complex.Imaginary(YL)!=0.0) ||
                    (Complex.Real(YL)!=0.0 && Complex.Imaginary(YL)==0.0))
                {
                    IsLoadRegular = true;
                    IsLoadShort = false;
                    IsLoadOpen = false;
                    IsLoadImaginary = false;
                }
                
                //--------------------------------------------------------------------------------------------- 
                 
                g.setColor(Color.black);
		MaestroG.subscripter(" y","L","",g,state.font11,xinit,vstepinit);
		
		if(IsLoadShort){
		    MaestroG.subscripterInfinityOne("=   ","","","",g,state.font11,xinit2,vstepinit);
		}
		else if(IsLoadOpen){
		    MaestroG.subscripter("=   0.0 + j 0.0","","",g,state.font11,xinit2,vstepinit);
		}
		else{
		    if(Complex.Imaginary(YL) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(IsLoadImaginary){
			tempR = 0.0;
		    }
		    else if(IsLoadRegular){
			tempR = YL.Real();
		    }
		    
		    if(tempR < 1.0E3 && tempR >= 1.0E-3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR,6),"","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR,6));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("=   0.0","","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   0.0 ");
		    }
		    else if(tempR < 1.0E6 && tempR >= 1.0E3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-3,2)+" x 10","3","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-3,2)+"x 10 3");
		    }
		    else if(tempR < 1.0E9 && tempR >= 1.0E6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-6,2)+" x 10","6","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-6,2)+"x 10 6");
		    }
		    else if(tempR < 1.0E12 && tempR >= 1.0E9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-9,2)+" x 10","9","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-9,2)+"x 10 9");
		    }
		    else if(tempR < 1.0E15 && tempR >= 1.0E12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-12,2)+" x 10","12","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-12,2)+"x 10 12");
		    }
		    else if(tempR < 1.0E18 && tempR >= 1.0E15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-15,2)+" x 10","15","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-15,2)+"x 10 15");
		    }
		    else if(tempR < 1.0E21 && tempR >= 1.0E18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-18,2)+" x 10","18","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-18,2)+"x 10 18");
		    }
		    else if(tempR < 1.0E24 && tempR >= 1.0E21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-21,2)+" x 10","21","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-21,2)+"x 10 21");
		    }
		    else if(tempR < 1.0E27 && tempR >= 1.0E24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-24,2)+" x 10","24","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-24,2)+"x 10 24");
		    }
		    else if(tempR < 1.0E30 && tempR >= 1.0E27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-27,2)+" x 10","27","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-27,2)+"x 10 27");
		    }
		    else if(tempR >= 1.0E30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-30,2)+" x 10","30","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-30,2)+"x 10 30");
		    }
		    else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E6,2)+" x 10","-6","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E6,2)+"x 10 -6");
		    }
		    else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E9,2)+" x 10","-9","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E9,2)+"x 10 -9");
		    }
		    else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E12,2)+" x 10","-12","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E12,2)+"x 10 -12");
		    }
		    else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E15,2)+" x 10","-15","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E15,2)+"x 10 -15");
		    }
		    else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E18,2)+" x 10","-18","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E18,2)+"x 10 -18");
		    }
		    else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E21,2)+" x 10","-21","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E21,2)+"x 10 -21");
		    }
		    else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E24,2)+" x 10","-24","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E24,2)+"x 10 -24");
		    }
                    else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E27,2)+" x 10","-27","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E27,2)+"x 10 -27");
		    }
                    else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E30,2)+" x 10","-30","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E30,2)+"x 10 -30");
		    }
                    else if(tempR < 1.0E-30 && tempR != 0.0){
			MaestroG.superscripter("=   0.0","","",g,state.font11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   0.0");
		    }
		    
		    tempX = Math.abs(YL.Imaginary());
		    xinit3 = xinit2+stepx;
		    
		    if(tempX < 1.0E3 && tempX >= 1.0E-3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX,6),"","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E6 && tempX >= 1.0E3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-3,2)+" x 10","3","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E9 && tempX >= 1.0E6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-6,2)+" x 10","6","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E12 && tempX >= 1.0E9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-9,2)+" x 10","9","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E15 && tempX >= 1.0E12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-12,2)+" x 10","12","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E18 && tempX >= 1.0E15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-15,2)+" x 10","15","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E21 && tempX >= 1.0E18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-18,2)+" x 10","18","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E24 && tempX >= 1.0E21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-21,2)+" x 10","21","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E27 && tempX >= 1.0E24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-24,2)+" x 10","24","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E30 && tempX >= 1.0E27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-27,2)+" x 10","27","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-3 && tempX >= 1.0E-6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E6,2)+" x 10","-6","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-6 && tempX >= 1.0E-9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E9,2)+" x 10","-9","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-9 && tempX >= 1.0E-12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E12,2)+" x 10","-12","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-12 && tempX >= 1.0E-15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E15,2)+" x 10","-15","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-15 && tempX >= 1.0E-18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E18,2)+" x 10","-18","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-18 && tempX >= 1.0E-21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E21,2)+" x 10","-21","",g,state.font11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-21 && tempX >= 1.0E-24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,state.font11,xinit3,vstepinit);
		    }
                    else if(tempX < 1.0E-24 && tempX >= 1.0E-27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E27,2)+" x 10","-27","",g,state.font11,xinit3,vstepinit);
		    }
                    else if(tempX < 1.0E-27 && tempX >= 1.0E-30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E30,2)+" x 10","-30","",g,state.font11,xinit3,vstepinit);
		    }
                    else if(tempX < 1.0E-30 && tempX != 0.0){
			MaestroG.superscripter(sign+" 0.0","","",g,state.font11,xinit3,vstepinit);
		    }
		}

                 MaestroG.subscripterSS3(" "+Gamma,"L","",g,state.font11,xinit+1,vstepinit + vstep);
		
		MaestroG.subscripterSS3(""+Gamma,"","(d)",g,state.font11,xinit+1,vstepinit + 3*vstep);
		//-----------------------------------------------------------------------------------------------                
                //write the angle with italic L for angle symbol - modify the toString process
                double dtmp1, dtmp2;
                dtmp1=MaestroA.rounder(GammaL.Magnitude(),8);
                    if(dtmp1 == 0.0){dtmp2 = 0.0;}
                    else{dtmp2=MaestroA.rounder(GammaL.Arg2()*180/Math.PI,6);}
		//MaestroG.SansPLAIN("=   "+dtmp1,"  \u2220 ",""+dtmp2+" \u00ba",g,state.font11,xinit2,vstepinit + vstep);
		MaestroG.TxtImgTxt("=   "+dtmp1,angle_img,""+dtmp2+" \u00ba",g,state.font11,xinit2,vstepinit + vstep,this);
                
                dtmp1=MaestroA.rounder(GammaIn.Magnitude(),8);
                    if(dtmp1 == 0.0){dtmp2 = 0.0;}
                    else{dtmp2=MaestroA.rounder(GammaIn.Arg2()*180/Math.PI,6);}
		//MaestroG.SansPLAIN("=   "+dtmp1,"  \u2220 ",""+dtmp2+" \u00ba",g,state.font11,xinit2,vstepinit + 3*vstep);
		MaestroG.TxtImgTxt("=   "+dtmp1,angle_img,""+dtmp2+" \u00ba",g,state.font11,xinit2,vstepinit + 3*vstep,this);
                //---------------------------------------------------------------------------------------------- 
                 
                 
                 if(Complex.Real(GammaIn) > 0.999999 && Math.abs(Complex.Imaginary(GammaIn)) < 0.000001){
		    Gamma_plusone = true;
		    Gamma_minusone = false;
		}
		else if(Complex.Real(GammaIn) < -0.999999 && Math.abs(Complex.Imaginary(GammaIn)) < 0.000001){
		    Gamma_plusone = false;
		    Gamma_minusone = true;
		}
		else{
		    Gamma_plusone = false;
		    Gamma_minusone = false;
		}
		
		MaestroG.subscripter("y","","(d)",g,state.font11,xinit+2,vstepinit + 2*vstep);
		
		if((IsLoadOpen || IsLoadImaginary) && Gamma_minusone){
		    MaestroG.subscripterInfinityOne("=   ","","","",g,state.font11,xinit2,vstepinit + 2*vstep);
		}
		else if((IsLoadOpen || IsLoadImaginary) && Gamma_plusone){
		    MaestroG.subscripter("=   0.0 + j 0.0","","",g,state.font11,xinit2,vstepinit + 2*vstep);
		}
		else if((IsLoadShort || IsLoadImaginary) && Gamma_minusone){
		    MaestroG.subscripterInfinityOne("=   ","","","",g,state.font11,xinit2,vstepinit + 2*vstep);
		}
		else if((IsLoadShort || IsLoadImaginary) && Gamma_plusone){
		    MaestroG.subscripter("=   0.0 + j 0.0","","",g,state.font11,xinit2,vstepinit + 2*vstep);
		}
				
		//if(Complex.Real(Yinput)==0.0&&Complex.Imaginary(Yinput)<-1.0E130){
		  //  MaestroG.subscripter("=  "+infinity,"","",g,state.font11,xinit2,vstepinit + 2*vstep);
		//}
		//else if(Complex.Real(Yinput)==0.0&&Complex.Imaginary(Yinput)==0.0){
		  //  MaestroG.subscripter("=  0.0 + j 0.0","","",g,state.font11,xinit2,vstepinit + 2*vstep);
		//}
		else{
		    if(Complex.Imaginary(Yin) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(IsLoadImaginary || IsLoadOpen || IsLoadShort){
			tempR = 0.0;
		    }
		    else if(IsLoadRegular){
			tempR = Yin.Real();
		    }
		    
		    if(tempR < 1.0E3 && tempR >= 1.0E-3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR,6),"","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR,6));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("=   0.0","","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   0.0 ");
		    }
		    else if(tempR < 1.0E6 && tempR >= 1.0E3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-3,2)+" x 10","3","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-3,2)+"x 10 3");
		    }
		    else if(tempR < 1.0E9 && tempR >= 1.0E6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-6,2)+" x 10","6","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-6,2)+"x 10 6");
		    }
		    else if(tempR < 1.0E12 && tempR >= 1.0E9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-9,2)+" x 10","9","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-9,2)+"x 10 9");
		    }
		    else if(tempR < 1.0E15 && tempR >= 1.0E12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-12,2)+" x 10","12","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-12,2)+"x 10 12");
		    }
		    else if(tempR < 1.0E18 && tempR >= 1.0E15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-15,2)+" x 10","15","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-15,2)+"x 10 15");
		    }
		    else if(tempR < 1.0E21 && tempR >= 1.0E18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-18,2)+" x 10","18","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-18,2)+"x 10 18");
		    }
		    else if(tempR < 1.0E24 && tempR >= 1.0E21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-21,2)+" x 10","21","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-21,2)+"x 10 21");
		    }
		    else if(tempR < 1.0E27 && tempR >= 1.0E24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-24,2)+" x 10","24","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-24,2)+"x 10 24");
		    }
		    else if(tempR < 1.0E30 && tempR >= 1.0E27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-27,2)+" x 10","27","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-27,2)+"x 10 27");
		    }
		    else if(tempR >= 1.0E30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-30,2)+" x 10","30","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-30,2)+"x 10 30");
		    }
		    else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E6,2)+" x 10","-6","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E6,2)+"x 10 -6");
		    }
		    else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E9,2)+" x 10","-9","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E9,2)+"x 10 -9");
		    }
		    else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E12,2)+" x 10","-12","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E12,2)+"x 10 -12");
		    }
		    else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E15,2)+" x 10","-15","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E15,2)+"x 10 -15");
		    }
		    else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E18,2)+" x 10","-18","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E18,2)+"x 10 -18");
		    }
		    else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E21,2)+" x 10","-21","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E21,2)+"x 10 -21");
		    }
		    else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E24,2)+" x 10","-24","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E24,2)+"x 10 -24");
		    }
                    else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E27,2)+" x 10","-27","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E27,2)+"x 10 -27");
		    }
                    else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E30,2)+" x 10","-30","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E30,2)+"x 10 -30");
		    }
                    else if(tempR < 1.0E-30 && tempR != 0.0){
			MaestroG.superscripter("=   0.0","","",g,state.font11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   0.0");
		    }
		    
		    tempX = Math.abs(Yin.Imaginary());
		    xinit3 = xinit2+stepx;
		    
		    if(tempX < 1.0E3 && tempX >= 1.0E-3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX,6),"","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,state.font11,xinit3,vstepinit + 2*vstep);
		    }
		    else if(tempX < 1.0E6 && tempX >= 1.0E3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-3,2)+" x 10","3","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E9 && tempX >= 1.0E6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-6,2)+" x 10","6","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E12 && tempX >= 1.0E9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-9,2)+" x 10","9","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E15 && tempX >= 1.0E12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-12,2)+" x 10","12","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E18 && tempX >= 1.0E15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-15,2)+" x 10","15","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E21 && tempX >= 1.0E18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-18,2)+" x 10","18","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E24 && tempX >= 1.0E21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-21,2)+" x 10","21","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E27 && tempX >= 1.0E24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-24,2)+" x 10","24","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E30 && tempX >= 1.0E27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-27,2)+" x 10","27","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-3 && tempX >= 1.0E-6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E6,2)+" x 10","-6","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-6 && tempX >= 1.0E-9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E9,2)+" x 10","-9","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-9 && tempX >= 1.0E-12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E12,2)+" x 10","-12","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-12 && tempX >= 1.0E-15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E15,2)+" x 10","-15","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-15 && tempX >= 1.0E-18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E18,2)+" x 10","-18","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-18 && tempX >= 1.0E-21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E21,2)+" x 10","-21","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-21 && tempX >= 1.0E-24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
                    else if(tempX < 1.0E-24 && tempX >= 1.0E-27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E27,2)+" x 10","-27","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
                    else if(tempX < 1.0E-27 && tempX >= 1.0E-30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E30,2)+" x 10","-30","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
                    else if(tempX < 1.0E-30 && tempX != 0.0){
			MaestroG.superscripter(sign+" 0.0","","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		}
		
		
		MaestroG.subscripter("z","","(d)",g,state.font11,xinit,vstepinit + 4*vstep);
		
		if((IsLoadOpen || IsLoadImaginary) && Gamma_plusone){
		    MaestroG.subscripterInfinityOne("=   ","","","",g,state.font11,xinit2,vstepinit + 4*vstep);
		}
		else if((IsLoadOpen || IsLoadImaginary) && Gamma_minusone){
		    MaestroG.subscripter("=   0.0 + j 0.0","","",g,state.font11,xinit2,vstepinit + 4*vstep);
		}
		else if((IsLoadShort || IsLoadImaginary) && Gamma_plusone){
		    MaestroG.subscripterInfinityOne("=   ","","","",g,state.font11,xinit2,vstepinit + 4*vstep);
		}
		else if((IsLoadShort || IsLoadImaginary) && Gamma_minusone){
		    MaestroG.subscripter("=   0.0 + j 0.0","","",g,state.font11,xinit2,vstepinit + 4*vstep);
		}
		
		//if(Complex.Real(Zinput)==0.0&&Complex.Imaginary(Zinput)<-1.0E130){
		  //  MaestroG.subscripter("=  "+infinity,"","",g,state.font11,xinit2,vstepinit + 4*vstep);
		//}
		//else if(Complex.Real(Zinput)==0.0&&Complex.Imaginary(Zinput) == 0.0){
		  //  MaestroG.subscripter("=  0.0 + j 0.0","","",g,state.font11,xinit2,vstepinit + 4*vstep);
		//}
		else{
		    if(Complex.Imaginary(Zin) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(IsLoadImaginary || IsLoadOpen || IsLoadShort){
			tempR = 0.0;
		    }
		    else if(IsLoadRegular){
			tempR = Zin.Real();
		    }
		    
		    if(tempR < 1.0E3 && tempR >= 1.0E-3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR,6),"","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR,6));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("=   0.0","","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   0.0 ");
		    }
		    else if(tempR < 1.0E6 && tempR >= 1.0E3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-3,2)+" x 10","3","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-3,2)+"x 10 3");
		    }
		    else if(tempR < 1.0E9 && tempR >= 1.0E6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-6,2)+" x 10","6","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-6,2)+"x 10 6");
		    }
		    else if(tempR < 1.0E12 && tempR >= 1.0E9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-9,2)+" x 10","9","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-9,2)+"x 10 9");
		    }
		    else if(tempR < 1.0E15 && tempR >= 1.0E12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-12,2)+" x 10","12","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-12,2)+"x 10 12");
		    }
		    else if(tempR < 1.0E18 && tempR >= 1.0E15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-15,2)+" x 10","15","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-15,2)+"x 10 15");
		    }
		    else if(tempR < 1.0E21 && tempR >= 1.0E18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-18,2)+" x 10","18","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-18,2)+"x 10 18");
		    }
		    else if(tempR < 1.0E24 && tempR >= 1.0E21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-21,2)+" x 10","21","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-21,2)+"x 10 21");
		    }
		    else if(tempR < 1.0E27 && tempR >= 1.0E24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-24,2)+" x 10","24","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-24,2)+"x 10 24");
		    }
		    else if(tempR < 1.0E30 && tempR >= 1.0E27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-27,2)+" x 10","27","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-27,2)+"x 10 27");
		    }
		    else if(tempR >= 1.0E30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-30,2)+" x 10","30","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-30,2)+"x 10 30");
		    }
		    else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E6,2)+" x 10","-6","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E6,2)+"x 10 -6");
		    }
		    else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E9,2)+" x 10","-9","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E9,2)+"x 10 -9");
		    }
		    else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E12,2)+" x 10","-12","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E12,2)+"x 10 -12");
		    }
		    else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E15,2)+" x 10","-15","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E15,2)+"x 10 -15");
		    }
		    else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E18,2)+" x 10","-18","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E18,2)+"x 10 -18");
		    }
		    else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E21,2)+" x 10","-21","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E21,2)+"x 10 -21");
		    }
		    else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E24,2)+" x 10","-24","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E24,2)+"x 10 -24");
		    }
                    else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E27,2)+" x 10","-27","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E27,2)+"x 10 -27");
		    }
                    else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E30,2)+" x 10","-30","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E30,2)+"x 10 -30");
		    }
                    else if(tempR < 1.0E-30 && tempR != 0.0){
			MaestroG.superscripter("=   0.0","","",g,state.font11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   0.0");
		    }
		    
		    tempX = Math.abs(Zin.Imaginary());
		    xinit3 = xinit2+stepx;
		    
		    if(tempX < 1.0E3 && tempX >= 1.0E-3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX,6),"","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,state.font11,xinit3,vstepinit + 4*vstep);
		    }
		    else if(tempX < 1.0E6 && tempX >= 1.0E3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-3,2)+" x 10","3","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E9 && tempX >= 1.0E6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-6,2)+" x 10","6","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E12 && tempX >= 1.0E9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-9,2)+" x 10","9","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E15 && tempX >= 1.0E12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-12,2)+" x 10","12","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E18 && tempX >= 1.0E15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-15,2)+" x 10","15","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E21 && tempX >= 1.0E18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-18,2)+" x 10","18","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E24 && tempX >= 1.0E21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-21,2)+" x 10","21","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E27 && tempX >= 1.0E24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-24,2)+" x 10","24","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E30 && tempX >= 1.0E27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-27,2)+" x 10","27","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-3 && tempX >= 1.0E-6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E6,2)+" x 10","-6","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-6 && tempX >= 1.0E-9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E9,2)+" x 10","-9","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-9 && tempX >= 1.0E-12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E12,2)+" x 10","-12","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-12 && tempX >= 1.0E-15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E15,2)+" x 10","-15","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-15 && tempX >= 1.0E-18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E18,2)+" x 10","-18","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-18 && tempX >= 1.0E-21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E21,2)+" x 10","-21","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-21 && tempX >= 1.0E-24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
                    else if(tempX < 1.0E-24 && tempX >= 1.0E-27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E27,2)+" x 10","-27","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
                    else if(tempX < 1.0E-27 && tempX >= 1.0E-30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E30,2)+" x 10","-30","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
                    else if(tempX < 1.0E-30 && tempX != 0.0){
			MaestroG.superscripter(sign+" 0.0","","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		}
             }
	}
        
	public void setZL(Complex ZL){
		//Complex GammaL;
                this.ZL = ZL;
		if(mode==1){
		lab[0].setText("z");
		
		if(Complex.Real(ZL)==0.0&&Complex.Imaginary(ZL)<-1.0e130){
		    vlab[0].setText("=   \u221e ");}
		else{
		    vlab[0].setText("=   "+ZL.toString(Complex.CARTESIAN,5));}
		}
		
		else{
		lab[0].setText("y");
		
		if(Complex.Real(ZL)==0.0 && Complex.Imaginary(ZL)==0.0){
		    vlab[0].setText("=   \u221e ");}
		else{
		vlab[0].setText("=   "+EMF.Inv(ZL).toString(Complex.CARTESIAN,5));}
		}
		GammaL=EMF.computeGamma(ZL);
		vlab[1].setText("=   "+GammaL.toString(Complex.POLAR_DEGREE,5));
                repaint();
	}
	public void setZL(Complex ZL, double Z0){
		setZL(Complex.Divide(ZL,Z0));
	}
	public void setZL(Complex ZL, Complex Z0){
		setZL(Complex.Divide(ZL,Z0));
	}
	
	public void setYL(Complex YL){
		//Complex GammaL;
                this.YL = YL;
		if(mode==1){
		lab[0].setText("z");
		
		if(Complex.Real(YL)==0.0&&Complex.Imaginary(YL)==0.0){
		    vlab[0].setText("=   \u221e ");}
		else{
		vlab[0].setText("=   "+EMF.Inv(YL).toString(Complex.CARTESIAN,5));}
		
		}
		else{
		lab[0].setText("y");
		
		if(Complex.Real(YL)==0.0&&Complex.Imaginary(YL)<-1.0e130){
		    vlab[0].setText("=   \u221e ");}
		else{
		vlab[0].setText("=   "+YL.toString(Complex.CARTESIAN,5));}
		}
		GammaL=EMF.computeGamma(YL,false);
		vlab[1].setText("=   "+GammaL.toString(Complex.POLAR_DEGREE,5));
                repaint();
	}
	
	public void setYL(Complex YL, double Z0){
		setYL(Complex.Multiply(YL,Z0));
	}
	
	public void setYL(Complex YL, Complex Z0){
		setYL(Complex.Divide(YL,Z0));
	}
	
	public void setZin(Complex Zin){
		//Complex GammaIn, Yin;
                this.Zin = Zin;
		if(mode==1){
		    lab[4].setText("y (d)");
		    lab[2].setText("z (d)");
		    if(Complex.Real(Zin)==0.0&&Complex.Imaginary(Zin)<-1.E130)
			    {vlab[2].setText("=   \u221e");}
		    else{vlab[2].setText("=   "+Zin.toString(Complex.CARTESIAN,5));}
		
		    Yin = EMF.Inv(Zin);
		    GammaIn = EMF.computeGamma(Zin);
		    vlab[3].setText("=   "+GammaIn.toString(Complex.POLAR_DEGREE,5));
		
			if(Complex.Real(Yin)==0.0&&Complex.Imaginary(Yin)<-1.E130)
			{vlab[4].setText("=   \u221e");}
		    else{
		    vlab[4].setText("=   "+Yin.toString(Complex.CARTESIAN,5));
		    }
		}
		else{
		    lab[2].setText("y (d)");
		    lab[4].setText("z (d)");
		    if(Complex.Real(Zin)==0.0&&Complex.Imaginary(Zin)<-1.E130)
			    {vlab[4].setText("=   \u221e");}
		    else{vlab[4].setText("=   "+Zin.toString(Complex.CARTESIAN,5));}
		
		    Yin = EMF.Inv(Zin);
		    GammaIn = EMF.computeGamma(Zin);
		    vlab[3].setText("=   "+GammaIn.toString(Complex.POLAR_DEGREE,5));
		
			if(Complex.Real(Yin)==0.0&&Complex.Imaginary(Yin)<-1.E130)
			{vlab[2].setText("=   \u221e");}
		    else{
			vlab[2].setText("=   "+Yin.toString(Complex.CARTESIAN,5));
		    }
		    
		}
                repaint();
	}
	
	public void setZin(Complex Zin, double Z0){
		setZin(Complex.Divide(Zin,Z0));
	}
	public void setZin(Complex Zin, Complex Z0){
		setZin(Complex.Divide(Zin,Z0));
	}
	public void setYin(Complex Yin){
		//Complex GammaIn, Zin;
                this.Yin=Yin;
		if(mode==1){
		    lab[4].setText("y (d)");
		    lab[2].setText("z (d)");
		
		    if(Complex.Real(Yin)==0.0&&Complex.Imaginary(Yin)<-1.E130)
			    {vlab[4].setText("=   \u221e");}
		    else{vlab[4].setText("=   "+Yin.toString(Complex.CARTESIAN,5));}
		
		    Zin = EMF.Inv(Yin);
		    GammaIn = EMF.computeGamma(Zin);
		    vlab[3].setText("=   "+GammaIn.toString(Complex.POLAR_DEGREE,5));
		    if(Complex.Real(Zin)==0.0&&Complex.Imaginary(Zin)<-1.E130)
			{vlab[2].setText("=   \u221e");}
		    else{vlab[2].setText("=   "+Zin.toString(Complex.CARTESIAN,5));}
		    
		}
		else{
		    lab[2].setText("y (d)");
		    lab[4].setText("z (d)");
		
		    if(Complex.Real(Yin)==0.0&&Complex.Imaginary(Yin)<-1.E130)
			    {vlab[2].setText("=   \u221e");}
		    else{vlab[2].setText("=   "+Yin.toString(Complex.CARTESIAN,5));}
		
		    Zin = EMF.Inv(Yin);
		    GammaIn = EMF.computeGamma(Zin);
		    vlab[3].setText("=   "+GammaIn.toString(Complex.POLAR_DEGREE,5));
		    if(Complex.Real(Zin)==0.0&&Complex.Imaginary(Zin)<-1.E130)
			{vlab[4].setText("=   \u221e");}
		    else{vlab[4].setText("=   "+Zin.toString(Complex.CARTESIAN,5));}
		    
		}
                repaint();
	}
	
	public void setYin(Complex Yin, double Z0){
		setYin(Complex.Divide(Yin,Z0));
	}
	
	public void setYin(Complex Yin, Complex Z0){
		setYin(Complex.Divide(Yin,Z0));
	}
	public synchronized void setMode(int mode){
		this.mode=mode;
	}
}//End of SmithMan	


/**********************************************************************************/
class SmithProbe extends Panel{
Label[] lab;
private int mode;
//private final Color bcolor = new Color(216,216,191);
private static final Color bcolor = new Color(236,236,236);
SmithProbe(int width, int height){
	super();
	setLayout(null);
	setBackground(bcolor);
	Font labfont = new Font("SanSerif",Font.PLAIN,11);
	Panel p = new Panel();
	p.setLayout(new GridLayout(2,1));
	lab = new Label[2];
	lab[0] = new Label(" ",Label.LEFT);
	lab[1] = new Label(" ",Label.LEFT);
	lab[0].setFont(labfont);
	lab[1].setFont(labfont);
	p.add(lab[0]);
	p.add(lab[1]);
	add(p);
	p.setBounds(20,1,width-17,height-1);	
	mode=2;
}

public void paint(Graphics g){
	int width=getSize().width;
	int height=getSize().height;
	
	g.setColor(bcolor);
	g.fillRect(1,1,width-2,height-2);
	draw_icon(g);
}

public void update(Graphics g){
	draw_icon(g);
}

public void setxpos(double xpos){
	double txpos=xpos;
	
	if(xpos<=0.5){
	    lab[0].setText("d = "+MaestroA.rounder(txpos,4)+" \u03bb  \u00a6  2\u03b2 d = "+MaestroA.rounder(txpos*4*Math.PI,4)+" rad = "+MaestroA.rounder(txpos*4*180,4)+"\u00ba");
	    lab[1].setText("0.5\u03bb-d = "+MaestroA.rounder((0.5-txpos),4)+" \u03bb \u00a6  2\u03b2 (0.5\u03bb-d) = "+MaestroA.rounder((0.5-txpos)*4*Math.PI,4)+" rad = "+MaestroA.rounder((0.5-txpos)*4*180,4)+"\u00ba");
	    repaint();
	}
	else{
	    while(txpos>0.5) {txpos-=0.5;}
	    lab[0].setText("d' = "+MaestroA.rounder(txpos,4)+" \u03bb  \u00a6  2\u03b2 d' = "+MaestroA.rounder(txpos*4*Math.PI,4)+" rad = "+MaestroA.rounder(txpos*4*180,4)+"\u00ba");
	    lab[1].setText("0.5\u03bb-d' = "+MaestroA.rounder((0.5-txpos),4)+" \u03bb \u00a6 2\u03b2 (0.5\u03bb-d') = "+MaestroA.rounder((0.5-txpos)*4*Math.PI,4)+" rad = "+MaestroA.rounder((0.5-txpos)*4*180,4)+"\u00ba");
	    repaint();
	}
	
	/*
	
	if(xpos<=0.5){
	    lab[0].setText("d = "+MaestroA.rounder(txpos,4)+" \u03bb  \u00a6  2\u03b2d = "+MaestroA.rounder(txpos*4*Math.PI,4)+" rad = "+MaestroA.rounder(txpos*4*180,5)+"\u00ba");
	    lab[1].setText("0.5\u03bb-d = "+MaestroA.rounder((0.5-txpos),4)+" \u03bb  \u00a6  2\u03b2(0.5\u03bb-d) = "+MaestroA.rounder((0.5-txpos)*4*Math.PI,4)+" rad = "+MaestroA.rounder((0.5-txpos)*4*180,5)+"\u00ba");
	    repaint();
	}
	else{
	    while(txpos>0.5) {txpos-=0.5;}
	    lab[0].setText("d' = "+MaestroA.rounder(txpos,4)+" \u03bb  \u00a6  2\u03b2d' = "+MaestroA.rounder(txpos*4*Math.PI,4)+" rad = "+MaestroA.rounder(txpos*4*180,5)+"\u00ba");
	    lab[1].setText("0.5\u03bb-d' = "+MaestroA.rounder((0.5-txpos),4)+" \u03bb  \u00a6 2\u03b2(0.5\u03bb-d') = "+MaestroA.rounder((0.5-txpos)*4*Math.PI,4)+" rad = "+MaestroA.rounder((0.5-txpos)*4*180,5)+"\u00ba");
	    repaint();
	}
	*/
	/*
	while(txpos>0.5) {txpos-=0.5;}
	lab[0].setText("d' = "+MaestroA.rounder(txpos,5)+" \u03bb  \u00a6  2\u03b2d' = "+MaestroA.rounder(txpos*4*Math.PI,3)+" rad = "+MaestroA.rounder(txpos*4*180,3)+"\u00ba");
	lab[1].setText("0.5\u03bb-d' = "+MaestroA.rounder((0.5-txpos),5)+" \u03bb  \u00a6  2\u03b2(0.5\u03bb-d') = "+MaestroA.rounder((0.5-txpos)*4*Math.PI,3)+" rad = "+MaestroA.rounder((0.5-txpos)*4*180,3)+"\u00ba");
	repaint();
	*/
}


public void set(String str1, String str2){
	lab[0].setText(str1);
	lab[1].setText(str2);
}

private void draw_icon(Graphics g){
	g.clipRect(2,2,getSize().width/4,getSize().height-2);
	if(mode==1){
		g.setColor(bcolor);
		g.fillRect(1,1,20,25);
		FontMetrics fm = g.getFontMetrics();
		double sep, sep2, height;
                
                sep = 4.0; height = 10.0;
                Color newred = new Color(250,0,0);
                MaestroG.drawArcThick(g,5.0,sep,height,40.0,180.0,3,newred);

		sep = 20.0; height = 10.0;
                Color newgreen = new Color(0,220,0);
                MaestroG.drawArcThick(g,5.0,sep,height,40.0,180.0,3,newgreen);
	}
	else if(mode==2){
		int x=10;
		int y=10;
		// y=getSize().height/2;
		g.setColor(bcolor);
		g.fillRect(1,1,20,32);
		SmithCanvas.plot_red_cross(g,x,y);
	}
	else{
		g.setColor(bcolor);
		g.fillRect(1,1,20,32);
	}
	g.dispose();
}

public synchronized void setmode(int mode){
	this.mode=mode;
	repaint();
}
		
}//End of SmithProbe

/******************************************************************************************/

class SmithControls extends Panel{
public Checkbox imp, adm;
public CheckboxGroup cgrid;
public Checkbox swr, swrline;
private static final Color bgcolor = new Color(236,236,236);

SmithControls(){
	setLayout(new GridLayout(2,2));
	cgrid = new CheckboxGroup();

	imp = new Checkbox("Impedance Grid",cgrid,true);
	adm = new Checkbox("Admittance Grid",cgrid,false);
	
	swr = new Checkbox("SWR Circle",null,true);
	swrline = new Checkbox("Cursor Line",null,true);
	
	add(imp);
	add(adm);
	add(swr);
	add(swrline);
	
	imp.setBackground(bgcolor);
	adm.setBackground(bgcolor);
	swr.setBackground(bgcolor);
	swrline.setBackground(bgcolor);
}
public void paint(Graphics g){
		g.setColor(Color.white);
		//g.drawLine(0,0,0,getSize().height-1);
		//g.drawLine(0,0,getSize().width-1,0);
		g.setColor(Color.black);
		//g.drawLine(getSize().width-1,0,getSize().width-1,getSize().height-1);
		//g.drawLine(0,getSize().height-1,getSize().width-1,getSize().height-1);

}

}//End of SmithControls;
