//SmithPanel2.java
//author Umberto Ravaioli, 2005

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 SmithPanel2 extends Panel implements MouseListener, MouseMotionListener, ItemListener{
    public SmithCanvas2 sc;
    public SmithMan2 sm; 
    public SmithProbe2 sp;
    public SmithControls2 scon;
    public SmithAuxiliary saux;
    private static final Color bgcolor = Color.white;
    public Checkbox large;
    private Trans_State state;
    public Button colore;
    public Button about;
    public boolean colore_dark;
        	
    public SmithPanel2(Trans_State state){
        super();
        this.state = state;
        setLayout(null);

        large = new Checkbox(" Show Plots",null,false);
        large.setFont(new Font("SanSerif",Font.PLAIN,state.font10)); 
        add(large);
        large.setBackground(Color.lightGray);
        large.setBounds(state.s460,state.s567,state.s90,state.s20);

        //PANELS FOR SELECTION OF PLOTS
        Panel plarge = new Panel();
            plarge.setBackground(Color.lightGray);
            add(plarge);
            plarge.setBounds(state.s455,state.s565,state.s100,state.s24);
        Panel plarge2 = new Panel();
            plarge2.setBackground(Color.black);
            add(plarge2);
            plarge2.setBounds(state.s455-1,state.s565-1,state.s100+2,state.s24+2);

        //add button to change color scheme
        colore = new Button("Color");
        add(colore);
        colore.setBackground(Color.white);
        colore.setBounds(state.s505,state.s75,state.s50,state.s20);
        colore.setFont(new Font("SanSerif",Font.PLAIN,state.font10));
        colore_dark = false;

        //add button for About panel
        about = new Button("Instructions");
        add(about);
        about.setBackground(Color.white);
        about.setBounds(state.s475,state.s49,state.s80,state.s20);
        about.setFont(new Font("SanSerif",Font.PLAIN,state.font10));

        setBackground(bgcolor);
        sc = new SmithCanvas2(state);
        add(sc);
        sc.setBounds(state.s2,state.s38,state.s561,state.s561);

        scon = new SmithControls2(state);
        add(scon);
        scon.setBounds(state.s569,state.s5,state.s274,state.s80);

        saux = new SmithAuxiliary(state);
        add(saux);
        saux.setBounds(state.s569,state.s92,state.s274,state.s136);

        sm = new SmithMan2(state.s204,state.s85, state);
        add(sm);
        sm.setBounds(state.s569,state.s235,state.s274,state.s85);

        sp = new SmithProbe2(state.s204,state.s80, state);
        add(sp);
        sp.setBounds(state.s569,state.s327,state.s274,state.s80);

        sc.addMouseListener(this);
        sc.addMouseMotionListener(this);
        //scon.imp.addItemListener(this);
        //scon.adm.addItemListener(this);
        scon.swr.addItemListener(this);
        scon.swrline.addItemListener(this);
        scon.chart.addItemListener(this);
        scon.showcurves.addItemListener(this);
        scon.inverse.addItemListener(this);
        //scon.gensmith.addItemListener(this);
        scon.smoothplot.addItemListener(this);

        saux.show_SWR.addItemListener(this);
        saux.show_max.addItemListener(this);
        saux.show_min.addItemListener(this);
        saux.show_gamma.addItemListener(this);
        saux.gammaL.addItemListener(this);
        saux.gammaD.addItemListener(this);
        
        Panel pgraph1 = new Panel();
            pgraph1.setBackground(Color.black);
            add(pgraph1);
            pgraph1.setBounds(state.s569-1,state.s5-1,state.s274+2,state.s80+2);

        Panel pgraph2 = new Panel();
            pgraph2.setBackground(Color.black);
            add(pgraph2);
            pgraph2.setBounds(state.s569-1,state.s235-1,state.s274+2,state.s85+2);
                              
        Panel pgraph4a = new Panel();
            pgraph4a.setBackground(Color.black);
            add(pgraph4a);
            pgraph4a.setBounds(state.s569-1,state.s327-1,state.s274+2,state.s80+2);
            
        Panel pgraph4b = new Panel();
            pgraph4b.setBackground(Color.black);
            //add(pgraph4b);
            pgraph4b.setBounds(state.s261-1,state.s615-1,state.s304+2,state.s41+2);

        Panel paux = new Panel();
            paux.setBackground(Color.black);
            add(paux);
            paux.setBounds(state.s569-1,state.s92-1,state.s274+2,state.s136+2);
    }
    public void paint(Graphics g){
            // DRAW SLIGHT SHADOW AROUND RIGHT AND BOTTOM BORDERS 
            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);
            if (sm.isVisible()) sm.repaint();
    }

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

    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);
            if (sm.isVisible()) sm.repaint();
    }
    public synchronized void setalpha(double alpha){
            sc.setalpha(alpha);
    }

    public synchronized void setGammaFlag(boolean IsLargerThanOne){
            sc.setGammaFlag(IsLargerThanOne);
    }

    public synchronized void setLoadType(boolean IsLoadOpen, boolean IsLoadShort, boolean IsLoadImaginary, boolean IsLoadRegular){
            sm.setLoadType(IsLoadOpen,IsLoadShort,IsLoadImaginary,IsLoadRegular);
            sc.setLoadType(IsLoadOpen,IsLoadShort,IsLoadImaginary,IsLoadRegular);
    }


    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);
            if (sm.isVisible()) sm.repaint();
    }

    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 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 setColoreDark(boolean colore_dark){
            sc.setColoreDark(colore_dark);
    }

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

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

    private void cricket_2(ItemEvent evt){
        //if(evt.getSource()==scon.imp){
        //			sc.set_impedance(scon.imp.getState());
        //			sm.setMode(1);
        //			sm.setZL(sc.getZL());
        //			saux.setZL(sc.getZL());
        //			sm.setZin(sc.getZin());
        //			sm.repaint();
        //			state.IWantImpedance = true;
        //}
        //else if(evt.getSource()==scon.adm){
        //			sc.set_admittance(scon.adm.getState());
        //			sm.setMode(2);
        //			sm.setZL(sc.getZL());
        //			saux.setZL(sc.getZL());
        //			sm.setYin(sc.getYin());
        //			sm.repaint();
        //			state.IWantImpedance = false;
        //}

        //else if(evt.getSource()==scon.swr){
        if (evt.getSource()==scon.swr){
            sc.set_swr_circle(scon.swr.getState());
        }
        else if(evt.getSource()==scon.smoothplot){
            sc.set_smooth(scon.smoothplot.getState());
        }
        else if(evt.getSource()==scon.swrline){
            sc.set_swr_line(scon.swrline.getState());
        }
        else if(evt.getSource()==scon.chart){
            sc.set_chart(scon.chart.getState());
        }
        else if(evt.getSource()==scon.showcurves){
            sc.set_curves(scon.showcurves.getState());
        }
        else if(evt.getSource()==scon.inverse){
            sc.set_inverse(scon.inverse.getState());
        }
	/*
        else if(evt.getSource()==scon.gensmith){
            sc.set_gensmith(scon.gensmith.getState());
        }
	*/
        else if(evt.getSource()==saux.show_SWR){
            sc.set_show_SWR(saux.show_SWR.getState());
        }
        else if(evt.getSource()==saux.show_gamma){
            sc.set_show_gamma(saux.show_gamma.getState());
        }
        else if(evt.getSource()==saux.gammaL){
            saux.gammaL.setState(true);
            saux.gammaD.setState(false);
            sc.set_gammaL(saux.gammaL.getState());
            sc.set_gammaD(saux.gammaD.getState());
        }
        else if(evt.getSource()==saux.gammaD){
            saux.gammaL.setState(false);
            saux.gammaD.setState(true);
            sc.set_gammaL(saux.gammaL.getState());
            sc.set_gammaD(saux.gammaD.getState());
        }
        else if(evt.getSource()==saux.show_max){
            sc.set_show_max(saux.show_max.getState());
        }
        else if(evt.getSource()==saux.show_min){
            sc.set_show_min(saux.show_min.getState());
        }
        if (sc.isVisible()) sc.repaint();
        if (sm.isVisible()) sm.repaint();
        if (saux.isVisible()) saux.repaint();
    }
}//End of SmithPanel

//==============================================================================

class SmithCanvas2 extends Canvas implements MouseListener, MouseMotionListener{
private final Color bgcolor = new Color(236,236,236);
//private final Color bgcolor = Color.lightGray;

private int xCenter, yCenter, yCenter2, yCenter3;
private int Radius1, Diam1, Radius2, Diam2, Radius3, Diam3, Radius4;
private int width, height;
public boolean draw_impedance_chart;
public boolean draw_admittance_chart;
public boolean draw_swr_circle, draw_SWR_circle;
public boolean draw_min, draw_max;
public boolean draw_swr_line;
private boolean draw_arcs;
private boolean draw_vline;
public boolean draw_ZL, draw_Zin, draw_Yin, draw_inverse;
public Complex Zin, Yin, ZL, YL;
public Complex GammaZin, GammaYin, GammaZL;
public double VSWR, dmax, dmin;
public double xpos, Z0, alpha;
private Complex GammaProbe, ZProbe, YProbe; 
public 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 IsLargerThanOne, FullChart, show_gamma, gammaL, gammaD, ShowCurves;
private boolean IsLoadOpen, IsLoadShort, IsLoadImaginary, IsLoadRegular;
public boolean IsInside;
private boolean smoothing;
private boolean colore_dark;
Trans_State state;

public SmithCanvas2(Trans_State state){
	super();
        this.state = state;
	//setBackground(Color.black); 
	draw_impedance_chart=true;
	draw_admittance_chart=false;
	draw_swr_circle=true;
	draw_SWR_circle = false;
	draw_max = false;
	draw_min = false;
	draw_swr_line=true;
	draw_ZL=true;
	draw_Zin=true;
	draw_Yin=true;
	draw_inverse = false;
	draw_arcs=true;
	draw_vline=true;
	show_gamma = true;
	gammaL = true;
	gammaD = false;
        smoothing = true;
	
	xpos = 0.0;
	Z0 = 1.0;
	alpha = 0.0;
	ZL = new Complex(1.0,1.0);
	//ZL = state.ZL;
	YL = EMF.Inv(ZL);
	GammaZL = EMF.computeGamma(ZL);
	VSWR = (1.0+Complex.Magnitude(GammaZL))/(1-Complex.Magnitude(GammaZL));
	Zin = new Complex(0.0,0.0);
	GammaZin = EMF.computeGamma(Zin);
	Yin = EMF.Inv(Zin);
	GammaYin = EMF.computeGamma(Yin);
	ZProbe = new Complex();
	YProbe = new Complex();
	GammaProbe = new Complex();
	xProbe=399;
	yProbe=280;
	
	IsLargerThanOne = false;
        colore_dark = false;

	FullChart = true;
	ShowCurves = true;
	IsInside = true;
		
	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);
                
	    }
	    repaint();
	    g.drawImage(im,0,0,null);
}

//reduce flicker
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){
	g.setFont(new Font("Serif",Font.PLAIN,state.font12));
	String GammaSymb="\u0393";   

	int i, Ncurves1, Ncurves2;
	double rl[], xl[];
	
	if(IsLargerThanOne){
	    Ncurves1 = 14;
	    Ncurves2 = 9;
	    rl= new double[Ncurves1];
	    xl= new double[Ncurves2];
	    
	    rl[0]=-4.0; rl[1]=-2.0; rl[2]=-1.5; rl[3]=-0.999; rl[4]=-0.8; rl[5]=-0.6; rl[6]=-0.4;
	    rl[7]=-0.2; rl[8]=0.0; rl[9]=0.2; rl[10]=0.5; rl[11]=1.0; rl[12]=2.0; rl[13]=4.0;
	    
	    xl[0]=0.0; xl[1]=0.2; xl[2]=0.4; xl[3]=0.6; xl[4]=0.8; xl[5]=1.0; xl[6]=1.5; xl[7]=2.0; xl[8]=4.0;
	}
	else{
	    Ncurves1 = 17;
	    Ncurves2 = 17;
	    rl= new double[Ncurves1];
	    xl= new double[Ncurves2];
	    
	    rl[0]= 0.0; rl[1]= 0.2; rl[2]= 0.4; rl[3]= 0.6; rl[4]= 0.8; rl[5]= 1.0; rl[6]= 1.2; rl[7]= 1.4; rl[8]= 1.6; rl[9]= 1.8; rl[10]= 2.0;
	    rl[11]= 3.0; rl[12]= 4.0; rl[13]= 5.0; rl[14]= 10.0; rl[15]= 20.0; rl[16]= 50.0;
	    xl[0]= 0.0; xl[1]= 0.2; xl[2]= 0.4; xl[3]= 0.6; xl[4]= 0.8; xl[5]= 1.0; xl[6]= 1.2; xl[7]= 1.4; xl[8]= 1.6; xl[9]= 1.8; xl[10]= 2.0;
	    xl[11]= 3.0; xl[12]= 4.0; xl[13]= 5.0; xl[14]= 10.0; xl[15]= 20.0; xl[16]= 50.0;
	    
	}
	
	width=getSize().width;
	height=getSize().height;

	xCenter = width/2;
	yCenter = height/2;
	yCenter2 = yCenter - (int)(width/2/(1+Math.sqrt(2)))*85/100;
	yCenter3 = yCenter + (int)(width/2/(1+Math.sqrt(2)))*85/100;
	
	if(IsLargerThanOne){
	    Radius1 = (int)(width/2/(1+Math.sqrt(2)))*85/100+1;
            
	    Radius2 = (width/2)*95/100;
	    Radius3 = (width/2)*85/100;
	    Radius4 = (int)((double)(Radius1)*Math.sqrt(2))+1;
	    yCenter2 = yCenter - (int)(width/2/(1+Math.sqrt(2)))*85/100;
	    yCenter3 = yCenter + (int)(width/2/(1+Math.sqrt(2)))*85/100;
	}
	else{
	    Radius1 = (width/2)*85/100;
	    Radius2 = (width/2)*95/100;
	    Radius3 = Radius1;
	    Radius4 = Radius1;
	    yCenter2 = yCenter;
	    yCenter3 = yCenter;
	}
	
	Diam1 = 2*Radius1;
	Diam2 = 2*Radius2;
	Diam3 = 2*Radius3;
	
	//Draw the rectangle
	//g.setColor(Color.black);
        
	if(colore_dark){
            g.setColor(bgcolor.darker());
        }
        else{
            g.setColor(bgcolor);
        }

	g.fillRect(0,0,width,height);
	
	//Draw the background circle
	if(IsLargerThanOne){
	    g.setColor(new Color(252,252,245));
	
	    fillCircle(g,xCenter,yCenter2,Radius4);
	    fillCircle(g,xCenter,yCenter3,Radius4);
	
	    //g.setColor(Color.lightGray);
	
	    //drawCircle(g,xCenter,yCenter2,Radius4);
	    //drawCircle(g,xCenter,yCenter3,Radius4);
	}
	
	//g.setColor(bgcolor);
	//fillCircle(g,xCenter,yCenter,Radius1);
	//fillCircle(g,xCenter,yCenter2,Radius4);
	//fillCircle(g,xCenter,yCenter3,Radius4);
	
	 //Draw a small blue circle at the center
	    g.setColor(Color.blue);
	    drawCircle(g,xCenter,yCenter,(int)(Radius1*0.02));
	
        /*
	//Draw reflection coefficient
	if(show_gamma)
	{
	    draw_reflection_phase(g);
	}
	*/
            
	//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(FullChart){
	    if(draw_impedance_chart){
	    //Draw resistance and reactance circles
		for(i=0;i<Ncurves1;i++){
			draw_resistance(rl[i],g,plotchart);
		}
		for(i=0;i<Ncurves2;i++){
			draw_reactance(xl[i],g,plotchart);
		}
	    }
	    if(draw_admittance_chart){
	    //Draw conductance and susceptance circles
		for(i=0;i<Ncurves1;i++){
			draw_conductance(rl[i],g,plotchart);
		}
		for(i=0;i<Ncurves2;i++){
			draw_susceptance(xl[i],g,plotchart);
		}
	    }
	    
	    //Draw rl=1 circle
            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 resistance circle and reactance arc for ZL 
	    Color ColorZ;
            
            if(colore_dark){
                ColorZ = Color.pink;
            }
            else{
                ColorZ = Color.cyan.darker();
            }
	    if(ShowCurves){
		if(gammaL){
		    if(draw_impedance_chart){
			draw_resistanceZ(ZL.Real(),g,ColorZ);
			draw_reactanceZ(ZL.Imaginary(),g,ColorZ);
		    }
	
		    if(draw_admittance_chart){
			draw_conductanceZ(YL.Real(),g,ColorZ);
			draw_susceptanceZ(YL.Imaginary(),g,ColorZ);
		    }
		}
		else{
		    if(draw_impedance_chart){
			draw_resistanceZ(Zin.Real(),g,ColorZ);
			draw_reactanceZ(Zin.Imaginary(),g,ColorZ);
		    }
	
		    if(draw_admittance_chart){
			draw_conductanceZ(Yin.Real(),g,ColorZ);
			draw_susceptanceZ(Yin.Imaginary(),g,ColorZ);
		    }
		}
	    }
	}
	else{
	    
	    //Draw resistance circle and reactance arc for ZL
	    Color ColorZ2;
            if(colore_dark){
                ColorZ2 = Color.pink;
            }
            else{
                ColorZ2 = Color.cyan.darker();
            }
            
	    if(ShowCurves){
		if(gammaL){
		    if(draw_impedance_chart){
			draw_resistanceZ(ZL.Real(),g,ColorZ2);
			draw_reactanceZ(ZL.Imaginary(),g,ColorZ2);
		    }
	
		    if(draw_admittance_chart){
			draw_conductanceZ(YL.Real(),g,ColorZ2);
			draw_susceptanceZ(YL.Imaginary(),g,ColorZ2);
		    }
		}
		else{
		    if(draw_impedance_chart){
			draw_resistanceZ(Zin.Real(),g,ColorZ2);
			draw_reactanceZ(Zin.Imaginary(),g,ColorZ2);
		    }
	
		    if(draw_admittance_chart){
			draw_conductanceZ(Yin.Real(),g,ColorZ2);
			draw_susceptanceZ(Yin.Imaginary(),g,ColorZ2);
		    }
		}
	    }
	}

        //draw background with circular hole for chart
        //Color outer = new Color(205,195,180);
        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, Radius3, xCenter, yCenter, outer);
	
	g.setFont(new Font("SanSerif",Font.PLAIN,state.font10));
	g.setColor(Color.red.darker());
	g.drawString("Click and drag mouse",state.s10,height-state.s22);
	g.drawString("to reposition load",state.s12,height-state.s10);
	
        g.setFont(new Font("SanSerif",Font.BOLD,state.font12));
	g.drawString("Interactive Smith Chart",state.s10,state.s34);
	g.setColor(Color.black);
        g.drawString("Module 2.6",state.s10,state.s20);
	g.setColor(Color.red.darker());
		
	g.setColor(Color.blue);
	if(IsLoadOpen){
	    g.setColor(Color.magenta.darker());
	    MaestroG.subscripterB("Open","","",g,state.font12,width-state.s70,height-state.s70);
	    MaestroG.subscripterB("Circuit","","",g,state.font12,width-state.s70,height-state.s55);
	}
	else if(IsLoadShort){
	    g.setColor(Color.magenta.darker());
	    MaestroG.subscripterB("Short","","",g,state.font12,width-state.s70,height-state.s70);
	    MaestroG.subscripterB("Circuit","","",g,state.font12,width-state.s70,height-state.s55);
	}
	else if(IsLoadImaginary){
	    g.setColor(Color.blue);
	    MaestroG.subscripterB("Imaginary","","",g,state.font12,width-state.s70,height-state.s70);
	    MaestroG.subscripterB("Load","","",g,state.font12,width-state.s70,height-state.s55);
	}
	
	//draw_black_arcs(g);
	
        //Draw tick-marks in the periphery
	draw_tick_marks(g);
        
        //Draw external and internal circles
	g.setColor(Color.black);
	drawCircle(g,xCenter,yCenter,Radius1);
	drawCircle(g,xCenter,yCenter,Radius2);
		
	
	//draw swr_circle
	if(draw_swr_circle){draw_swr_circle(g);}
	
	//draw SWR_circle
	if(draw_SWR_circle){draw_SWR_circle(g);}

	
	if(draw_arcs){draw_arcs(g);}
	
        //draw swr_line
	if(draw_swr_line){draw_swr_line(g);}
        
        //Draw min max arcs
	if(draw_max){draw_max(g);}
	if(draw_min){draw_min(g);}
	if(draw_max){draw_arrow_max(g);}
                
        //Draw reflection coefficient phase
	if(show_gamma)
	{
	    draw_reflection_phase(g);
	}
        
        //Draw reflection coefficient magnitude
             
	if(show_gamma)
	{
	        draw_reflection(g);
	}
        
        //drawPoints();
	drawPoints(g);
        
        // THIN FRAME AROUND CHART CANVAS
        g.setColor(Color.black);
	g.drawRect(0,0,width-1,height-1);
}

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

private void drawCircleThick(Graphics g, double xCenter, double yCenter, double Radius, int thick, Color color){
	
        Graphics2D g2d = (Graphics2D)g;
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(thick, BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL));
        
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
        Ellipse2D.Double circle = new Ellipse2D.Double(xCenter-Radius,yCenter-Radius,2*Radius,2*Radius);
        g2d.draw(circle);
        g2d.setStroke(new BasicStroke(1));
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
}

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 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));
        
        if(smoothing){
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        }
        else{
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
        }
        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);
}

private void FillArcTransp(Graphics g, double xCenter, double yCenter, double Radius, double startangle, double endangle, Color color, double alphachan){
	int rule; float alpha;
        rule = AlphaComposite.SRC_OVER;
        alpha = (float)alphachan;
        
        Graphics2D g2d = (Graphics2D)g;
        g2d.setPaint(color);
        //g2d.setStroke(new BasicStroke(thick));
        g2d.setComposite(AlphaComposite.getInstance(rule, alpha));
        
        if(smoothing){
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        }
        else{
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
        }
        Arc2D.Double arc_one = new Arc2D.Double(xCenter,yCenter,Radius,Radius,startangle,endangle,2);
        g2d.fill(arc_one);
  
        //g2d.setStroke(new BasicStroke(1));
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
        g2d.setComposite(AlphaComposite.getInstance(rule, 1.0f));
}
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.
	
	ycen = 0.0;
	
	if(rl<-1.0){
	    raio = 1.0/(1.0+(-2.0-rl));
	    //xcen = -(rl+1)*raio;
	    g.setColor(color);
	    drawCircle(g,xCenter+Radius1+(int)(raio*Radius1),yCenter+(int)(ycen*Radius1),(int)(raio*Radius1));
	}
	else{
	    raio = 1.0/(1.0+rl);
	    xcen = (rl)/(1.0+rl);
	    g.setColor(color);
	    drawCircle(g,xCenter+(int)(xcen*Radius1),yCenter+(int)(ycen*Radius1),(int)(raio*Radius1));
	}
}

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

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

	g.setColor(color);
	if(xl < 0.0){
	    ycen = -1.0/xl;
	    raio = -1.0/xl;
	    drawCircle(g,xCenter+(int)(xcen*Radius1),xCenter+(int)(ycen*Radius1),(int)(raio*Radius1));
	}
	else if(xl > 0.0){
	    ycen = -1.0/xl;
	    drawCircle(g,xCenter+(int)(xcen*Radius1),xCenter+(int)(ycen*Radius1),(int)(raio*Radius1));
	}
	else if(xl == 0.0){
	    g.drawLine((xCenter-Radius1),yCenter,(xCenter+Radius1),yCenter);
	}
}

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

private void draw_susceptanceZ(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);
	if(xl < 0.0){
	    raio = -1.0/xl;
	    drawCircle(g,xCenter+(int)(xcen*Radius1),xCenter+(int)(ycen*Radius1),(int)(raio*Radius1));
	}
	else if(xl > 0.0){
	    drawCircle(g,xCenter+(int)(xcen*Radius1),xCenter+(int)(ycen*Radius1),(int)(raio*Radius1));
	}
	else if(xl == 0.0){
	    g.drawLine((xCenter-Radius1),yCenter,(xCenter+Radius1),yCenter);
	}
}


private void draw_conductance(double rl, Graphics g, Color color){
	double xcen, ycen, raio;
	//Microwave Engineering, David M. Pozar, Equation 3.56a, Page 86.
	
	ycen = 0.0;
	
	if(rl<-1.0){
	    raio = 1.0/(1.0+(-2.0-rl));
	    g.setColor(color);
	    drawCircle(g,xCenter-Radius1-(int)(raio*Radius1),yCenter+(int)(ycen*Radius1),(int)(raio*Radius1));
	}
	else{
	    raio = 1.0/(1.0+rl);
	    xcen = -(rl)/(1.0+rl);
	    g.setColor(color);
	    drawCircle(g,xCenter+(int)(xcen*Radius1),yCenter+(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)));
                        //g.setColor(Color.black);
		}
                if(i%10==0){
			tmpx1=(int)(xCenter+r4*Math.cos(beta*i/(Nmarks)));
			tmpy1=(int)(yCenter+r4*Math.sin(beta*i/(Nmarks)));
                        //g.setColor(Color.blue);
                }
		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 drawPoints(Graphics g){
	
	int radius, tmpx, tmpy;
	
	if(IsLargerThanOne){
	    radius = state.s3;
	}
	else{
	    radius=state.s4;
	}
	
	if(draw_impedance_chart){
	    if(xpos == 0.0){
		draw_Zin = false;
	    }
	    else{
		draw_Zin = true;
	    }
	    
	    if(draw_inverse){
		draw_Yin = true;
	    }
	    else{
		draw_Yin = false;
	    }
	}
	if(draw_admittance_chart){
	    if(xpos == 0.0){
		draw_Yin = false;
	    }
	    else{
		draw_Yin = true;
	    }
	    if(draw_inverse){
		draw_Zin = true;
	    }
	    else{
		draw_Zin = false;
	    }
	}
	
        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);
		    //g.drawLine(xCenter,yCenter,tmpx,tmpy);
		    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);
		    //g.drawLine(xCenter,yCenter,tmpx,tmpy);
		    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));
		    //g.drawLine(xCenter,yCenter,tmpx,tmpy);
		    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));
		    //g.drawLine(xCenter,yCenter,tmpx,tmpy);
		    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);
		//g.drawLine(xCenter,yCenter,tmpx,tmpy);
		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);
		//g.drawLine(xCenter,yCenter,tmpx,tmpy);
		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);
		//g.drawLine(xCenter,yCenter,tmpx,tmpy);
		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);
		//g.drawLine(xCenter,yCenter,tmpx,tmpy);
		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);
		    //g.drawLine(xCenter,yCenter,tmpx,tmpy);
		    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);
		    //g.drawLine(xCenter,yCenter,tmpx,tmpy);
		    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));
		    //g.drawLine(xCenter,yCenter,tmpx,tmpy);
		    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));
		    //g.drawLine(xCenter,yCenter,tmpx,tmpy);
		    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);
		//g.drawLine(xCenter,yCenter,tmpx,tmpy);
		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);
		//g.drawLine(xCenter,yCenter,tmpx,tmpy);
		fillCircle(g,tmpx,tmpy,radius);
		g.setColor(Color.black);
		drawCircle(g,tmpx,tmpy,radius);
		}
            }   
        }
}


public void draw_swr_circle(Graphics g){
	int xVSWR, yVSWR, RadiusGamma, RadiusVSWR;
	
	if(IsLoadOpen || IsLoadShort || IsLoadImaginary){
	    RadiusGamma = Radius1;
	}
	else{
	    RadiusGamma = (int)(Radius1*GammaZL.Magnitude());
	}
	
	if(colore_dark){
            g.setColor(Color.cyan);
        }
        else{
            g.setColor(Color.magenta);
        }  
	drawCircle(g,xCenter,yCenter,RadiusGamma);
	//g.setColor(Color.red);
	//drawCircle(g,xCenter,yCenter,RadiusGamma-1);
}

public void draw_SWR_circle(Graphics g){
	double xVSWR, yVSWR, RadiusGamma, RadiusVSWR;
	RadiusGamma = (int)(Radius1*GammaZL.Magnitude());
	RadiusVSWR = (Radius1/2 - RadiusGamma/2);
	yVSWR = yCenter;
	
	if(draw_impedance_chart){
	    xVSWR = xCenter + RadiusGamma/2 + Radius1/2 + 1;
	}
	else{
	    xVSWR = xCenter - RadiusGamma/2 - Radius1/2 - 1;
	}
        
        drawCircleThick(g,xVSWR,yVSWR,RadiusVSWR-1,state.s2,new Color(255,155,65));
}

public void draw_reflection(Graphics g){
	Color arc1_color = new Color(236,236,201);
	Color arc2_color = new Color(201,236,236);
	Color vectorcolor;
        
	int xVSWR, yVSWR, RadiusGamma, RadiusVSWR;
	RadiusGamma = (int)(Radius1*GammaZL.Magnitude());	
	
	RadiusVSWR = (Radius1/2 - RadiusGamma/2);
	yVSWR = yCenter;
	int start, raio, raio2;
	
	if(draw_impedance_chart){
	    if(xpos == 0.0 || gammaL){
		g.setColor(Color.red);
                vectorcolor = Color.red;
	    }
	    else{
		if(colore_dark){
                    g.setColor(Color.green);
                    vectorcolor = Color.green;
                }
                else{
                    g.setColor(Color.green.darker());
                    vectorcolor = Color.green.darker();
                }
	    }
	}
	else{
	    if(xpos == 0.0 || gammaL){
		g.setColor(Color.yellow);
                vectorcolor = Color.orange;
	    }
	    else{
		g.setColor(Color.blue);
                vectorcolor = Color.blue;
	    }
	}
        
    double angolo, angolo2;
    double Len = (float)(state.s14);

    int tmpx, tmpy, tmpx1, tmpy1, tmpx2, tmpy2;
    int thickline = state.s3;
    
    //For voltage        
	if(gammaL){
	    
            angolo = Math.PI*0.5-(GammaZL.Arg2()+Math.PI)-23.0*Math.PI/180.0;
            angolo2 = (GammaZL.Arg2()+Math.PI)-23.0*Math.PI/180.0;
            tmpx=xCenter+(int)(GammaZL.Real()*Radius1);
            tmpy=yCenter+(int)(-GammaZL.Imaginary()*Radius1);
            tmpx1=xCenter+(int)(GammaZL.Real()*(Radius1-10));
            tmpy1=yCenter+(int)(-GammaZL.Imaginary()*(Radius1-10));
            tmpx2=xCenter+(int)(GammaZL.Real()*(Radius1-10));
            tmpy2=yCenter+(int)(-GammaZL.Imaginary()*(Radius1-10));
            
            drawLineThick(g,tmpx1,tmpy1,xCenter,yCenter,thickline,vectorcolor);
            if(GammaZL.Magnitude()>0.1){
                drawLineThick(g,tmpx2,tmpy2,tmpx2+Len*Math.sin(angolo),tmpy2-Len*Math.cos(angolo),thickline,vectorcolor);
                drawLineThick(g,tmpx2,tmpy2,tmpx2+Len*Math.cos(angolo2),tmpy2-Len*Math.sin(angolo2),thickline,vectorcolor);
            }
	}
	if(gammaD){
	    
            angolo = Math.PI*0.5-(GammaZin.Arg2()+Math.PI)-23.0*Math.PI/180.0;
            angolo2 = (GammaZin.Arg2()+Math.PI)-23.0*Math.PI/180.0;
            tmpx=xCenter+(int)(GammaZin.Real()*Radius1);
            tmpy=yCenter+(int)(-GammaZin.Imaginary()*Radius1);
            tmpx1=xCenter+(int)(GammaZin.Real()*(Radius1-state.s10));
            tmpy1=yCenter+(int)(-GammaZin.Imaginary()*(Radius1-state.s10));
            tmpx2=xCenter+(int)(GammaZin.Real()*(Radius1-state.s10));
            tmpy2=yCenter+(int)(-GammaZin.Imaginary()*(Radius1-state.s10));
            
            drawLineThick(g,tmpx1,tmpy1,xCenter,yCenter,thickline,vectorcolor);
            if(GammaZin.Magnitude()>0.1){
                drawLineThick(g,tmpx2,tmpy2,tmpx2+Len*Math.sin(angolo),tmpy2-Len*Math.cos(angolo),thickline,vectorcolor);
                drawLineThick(g,tmpx2,tmpy2,tmpx2+Len*Math.cos(angolo2),tmpy2-Len*Math.sin(angolo2),thickline,vectorcolor);
            }
	}
}

private void drawLineThick(Graphics g, double x1, double y1, double x2, double y2, int thick, Color color){
        Graphics2D g2d = (Graphics2D)g;
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(thick,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
        Line2D.Double line = new Line2D.Double(x1,y1,x2,y2);
        g2d.draw(line);
        g2d.setStroke(new BasicStroke(1));
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
}


public void draw_reflection_phase(Graphics g){
	Color arc1_color = new Color(226,226,226);
	Color arc2_color = new Color(255,210,0);
        Color arc3_color = new Color(255,210,0);
        //Color arc3_color = new Color(255,255,210);
        Color arc_color;
	double transparency = 0.6;
	int xVSWR, yVSWR, RadiusGamma, RadiusVSWR;
	RadiusGamma = (int)(Radius1*GammaZL.Magnitude());	
	
	RadiusVSWR = (Radius1/2 - RadiusGamma/2);
	yVSWR = yCenter;
	int start, raio, raio2;
	
	if(2*RadiusGamma > Radius2/5){
	    raio = Radius2/5;
	}
	else{
	    raio = 2*RadiusGamma;
	}
	
	if(gammaL){
	    start=(int)(GammaZL.Arg2(Complex.POLAR_DEGREE));
	    
	    //----------------------------------------------------------------------------
	    if(draw_impedance_chart){
		g.setColor(arc2_color);
                arc_color = arc2_color;
	    }
	    else{
		g.setColor(arc3_color);
                arc_color = arc3_color;
	    }
	
	    if(GammaZL.Imaginary() >= 0.0){
		//g.fillArc(xCenter-raio/2+1,yCenter-raio/2+1,raio-2,raio-2,0,start);
                FillArcTransp(g,(double)(xCenter-raio/2+state.s1),(double)(yCenter-raio/2+state.s1),(double)(raio-state.s2),0.0, (double)start, arc_color, transparency);
	
	    }
	    else{
		//g.fillArc(xCenter-raio/2+1,yCenter-raio/2+1,raio-2,raio-2,0,360+start-2);
                FillArcTransp(g,(double)(xCenter-raio/2+state.s1),(double)(yCenter-raio/2+state.s1),(double)(raio-state.s2),0.0, (double)(360+start-2), arc_color, transparency);
	
	    }
            
	    //------------------------------------------------------------------------------
	    g.setColor(arc1_color);
            arc_color = arc1_color;
	    if(GammaZL.Imaginary() >= 0.0){
		FillArcTransp(g,(double)(xCenter-raio/2+state.s1),(double)(yCenter-raio/2+state.s1),(double)(raio-state.s2),(double)start, (double)(360-start), arc_color, transparency);
	
	    }
	    else{
		FillArcTransp(g,(double)(xCenter-raio/2+state.s1),(double)(yCenter-raio/2+state.s1),(double)(raio-state.s2),(double)(360+start-1), (double)(-start), arc_color, transparency);
	
	    }
	
	    g.setColor(Color.gray);
            g.drawOval(xCenter-raio/2+state.s1,yCenter-raio/2+state.s1,raio-state.s2,raio-state.s2);
	}
	
	if(gammaD){
	    start=(int)(GammaZin.Arg2(Complex.POLAR_DEGREE));
	    //----------------------------------------------------------------------------
	    if(draw_impedance_chart){
		g.setColor(arc2_color);
                arc_color = arc2_color;
	    }
	    else{
		g.setColor(arc3_color);
                arc_color = arc3_color;
	    }
	
	    if(GammaZin.Imaginary() >= 0.0){
		FillArcTransp(g,(double)(xCenter-raio/2+state.s1),(double)(yCenter-raio/2+state.s1),(double)(raio-state.s2),0.0, (double)(start), arc_color, transparency);
	
	    }
	    else{
		FillArcTransp(g,(double)(xCenter-raio/2+state.s1),(double)(yCenter-raio/2+state.s1),(double)(raio-state.s2),0.0, (double)(360+start-2), arc_color, transparency);
	
	    }
	
	    g.setColor(Color.gray);
	    if(GammaZin.Imaginary() >= 0.0){
		g.drawArc(xCenter-raio/2+state.s1,yCenter-raio/2+state.s1,raio-state.s2,raio-state.s2,0,start);
	    }
	    else{
		g.drawArc(xCenter-raio/2+state.s1,yCenter-raio/2+state.s1,raio-state.s2,raio-state.s2,0,360+start-2);
	    }
	    //------------------------------------------------------------------------------
	    g.setColor(arc1_color);
            arc_color = arc1_color;
	    if(GammaZin.Imaginary() >= 0.0){
		//g.fillArc(xCenter-raio/2+1,yCenter-raio/2+1,raio-2,raio-2,start,360-start);
                FillArcTransp(g,(double)(xCenter-raio/2+state.s1),(double)(yCenter-raio/2+state.s1),(double)(raio-state.s2),(double)start,(double)(360-start), arc_color, transparency);
	
	    }
	    else{
		//g.fillArc(xCenter-raio/2+1,yCenter-raio/2+1,raio-2,raio-2,360+start-1,-start);
                FillArcTransp(g,(double)(xCenter-raio/2+state.s1),(double)(yCenter-raio/2+state.s1),(double)(raio-state.s2),(double)(360+start-1), (double)(-start), arc1_color, transparency);
	
	    }
	
	    g.setColor(Color.gray);
            g.drawOval(xCenter-raio/2+1,yCenter-raio/2+1,raio-2,raio-2);
	}
}

public void draw_black_arcs(Graphics g){
	
	int RadiusBlack = 2*Radius1;
	
	g.setColor(Color.black);
	g.drawArc(xCenter-Radius1,yCenter-Radius1,RadiusBlack,RadiusBlack,0,360);
	g.drawArc(xCenter-Radius1-1,yCenter-Radius1-1,RadiusBlack+1,RadiusBlack+1,0,360);
	g.drawArc(xCenter-Radius1-2,yCenter-Radius1-2,RadiusBlack+2,RadiusBlack+2,0,360);
	g.drawArc(xCenter-Radius1-3,yCenter-Radius1-3,RadiusBlack+3,RadiusBlack+3,0,360);
	g.drawArc(xCenter-Radius1-4,yCenter-Radius1-4,RadiusBlack+4,RadiusBlack+4,0,360);
	g.drawArc(xCenter-Radius1-5,yCenter-Radius1-5,RadiusBlack+5,RadiusBlack+5,0,360);
	g.drawArc(xCenter-Radius1-6,yCenter-Radius1-6,RadiusBlack+6,RadiusBlack+6,0,360);
	g.drawArc(xCenter-Radius1-7,yCenter-Radius1-7,RadiusBlack+7,RadiusBlack+7,0,360);
	g.drawArc(xCenter-Radius1-8,yCenter-Radius1-8,RadiusBlack+8,RadiusBlack+8,0,360);
	g.drawArc(xCenter-Radius1-9,yCenter-Radius1-9,RadiusBlack+9,RadiusBlack+9,0,360);
	g.drawArc(xCenter-Radius1-10,yCenter-Radius1-10,RadiusBlack+10,RadiusBlack+10,0,360);
}

public void draw_max(Graphics g){
	
	int xVSWR, yVSWR, RadiusGamma, RadiusVSWR;
	
	RadiusGamma = (int)(Radius1*GammaZL.Magnitude());	
	RadiusVSWR = (Radius1/2 - RadiusGamma/2);
	yVSWR = yCenter;
	int start, raio, raio2, my_thickness;
	double startdouble;
        
	my_thickness = state.s3;
        raio = Radius2*2+state.s6;
	raio2 = Radius2*2+state.s12;
        startdouble=GammaZL.Arg2(Complex.POLAR_DEGREE);
        
        Color maxc;
        if(colore_dark){
            maxc = Color.yellow.brighter();//new Color(255,255,0);
        }
        else{
            maxc = Color.yellow;
        }
        
        if(GammaZL.Imaginary() >= 0.0 && GammaZL.Arg2()!=0.0){
	    drawArcThick(g,(double)(xCenter-raio/2),(double)(yCenter-raio/2),(double)raio,0.0,startdouble,my_thickness,maxc);
	}
	else{
	    drawArcThick(g,(double)(xCenter-raio/2),(double)(yCenter-raio/2),(double)raio,0.0,360.0+startdouble,my_thickness,maxc);
	}
}

public void draw_arrow_max(Graphics g){
	
	int xVSWR, yVSWR, RadiusGamma, RadiusVSWR;

	int start, raio, raio2, my_thickness;
	double startdouble;
        
        my_thickness = state.s3;
	raio = Radius2*2+state.s6;
	raio2 = Radius2*2+state.s12;

	startdouble=GammaZL.Arg2(Complex.POLAR_DEGREE);
        
	Color maxc;
        if(colore_dark){
            maxc = Color.yellow.brighter();//new Color(255,255,0);
        }
        else{
            maxc = Color.yellow;
        }
       
            double angolo, angolo2, tmpx, tmpy, tmpx1,tmpx2,tmpx3,tmpy1,tmpy2,tmpy3,Len,Len1;
            angolo = 70.0*Math.PI/180.0;
            angolo2 = 110.0*Math.PI/180.0;
            
            tmpx2 = xCenter + Radius2+(double)(state.s35/10);
            tmpy2 = yCenter;
            tmpx = xCenter + (Radius2+state.s3)*Math.cos(GammaZL.Arg2()); 
            tmpy = xCenter - (Radius2+state.s3)*Math.sin(GammaZL.Arg2()); 
            tmpx1 = xCenter + (Radius2-state.s3)*Math.cos(GammaZL.Arg2()); 
            tmpy1 = xCenter - (Radius2-state.s3)*Math.sin(GammaZL.Arg2()); 
            tmpx3 = xCenter + (Radius2+state.s10)*Math.cos(GammaZL.Arg2()); 
            tmpy3 = xCenter - (Radius2+state.s10)*Math.sin(GammaZL.Arg2()); 
            
            Len1 = (double)state.s14;
            if((tmpy < yCenter) &&((yCenter-tmpy) < state.s25)&&(GammaZL.Real()>0.0)){
                Len = Math.abs((yCenter - tmpy)*0.5);
            }
            else{
                Len = (double)state.s14;
            }
            
              //fixed arrow
              drawLineThick(g,tmpx2,tmpy2,tmpx2+Len*Math.cos(angolo),tmpy2-Len*Math.sin(angolo),my_thickness,maxc);
              drawLineThick(g,tmpx2,tmpy2,tmpx2+Len*Math.cos(angolo2),tmpy2-Len*Math.sin(angolo2),my_thickness,maxc);
             
              //limits
              drawLineThick(g,tmpx2-Len1/2.0,tmpy2,tmpx2+Len1/2.0,tmpy2,state.s3,maxc);
              drawLineThick(g,tmpx1,tmpy1,tmpx3,tmpy3,state.s3,maxc);
}

public void draw_min(Graphics g){
	
	int xVSWR, yVSWR, RadiusGamma, RadiusVSWR;
	
	RadiusGamma = (int)(Radius1*GammaZL.Magnitude());	
	RadiusVSWR = (Radius1/2 - RadiusGamma/2);
	yVSWR = yCenter;
	int start, raio, raio2, my_thickness;
        double startdouble;
	
        my_thickness = state.s3;
	raio = Radius2*2+state.s6;
	raio2 = Radius2*2+state.s12;

	startdouble = GammaZL.Arg2(Complex.POLAR_DEGREE);
	//Color minc = Color.cyan.darker();
        Color minc = new Color(0,80,255);
	
        if(GammaZL.Imaginary() >= 0.0){
	    drawArcThick(g,(double)(xCenter-raio/2-state.s3),(double)(yCenter-raio/2-state.s3),(double)(raio+state.s6),0.0,startdouble-0.5,my_thickness,minc);
            drawArcThick(g,(double)(xCenter-raio/2-state.s3),(double)(yCenter-raio/2-state.s3),(double)(raio+state.s6),0.0,-179.5,my_thickness,minc);
	}
	else{
	    drawArcThick(g,(double)(xCenter-raio/2-state.s3),(double)(yCenter-raio/2-state.s3),(double)(raio+state.s6),startdouble,-180.0-startdouble,my_thickness,minc);
	}
        
        double angolo, angolo2, tmpx, tmpy, tmpx1,tmpx2,tmpy1,tmpy2,tmpx3,tmpy3,Len, Len1;
            angolo = 70.0*Math.PI/180.0;
            angolo2 = 110.0*Math.PI/180.0;
            Len1 = (double)state.s14;
            tmpx = xCenter + (Radius2)*Math.cos(GammaZL.Arg2()); 
            tmpy = xCenter - (Radius2)*Math.sin(GammaZL.Arg2()); 
            tmpx2 = xCenter - Radius2 - (float)(state.s58/10);
            tmpy2 = yCenter;
           
            if((tmpy > yCenter) &&((tmpy-yCenter) < state.s25)&& (GammaZL.Real()<0.0)){
                Len = Math.abs((yCenter - tmpy)*0.5);
            }
            else{
                Len = (double)state.s14;
            }
            
            //Fixed arrow
            drawLineThick(g,tmpx2,tmpy2,tmpx2+Len*Math.cos(angolo),tmpy2+Len*Math.sin(angolo),my_thickness,minc);
            drawLineThick(g,tmpx2,tmpy2,tmpx2+Len*Math.cos(angolo2),tmpy2+Len*Math.sin(angolo2),my_thickness,minc);
            //drawLineThick(g,tmpx2-Len/2.0,tmpy2,tmpx2+Len/2.0,tmpy2,state.s3,minc);
              
            tmpx1 = xCenter + (Radius2)*Math.cos(GammaZL.Arg2()); 
            tmpy1 = xCenter - (Radius2)*Math.sin(GammaZL.Arg2()); 
            tmpx3 = xCenter + (Radius2+14)*Math.cos(GammaZL.Arg2()); 
            tmpy3 = xCenter - (Radius2+14)*Math.sin(GammaZL.Arg2()); 
            
            //limits
            drawLineThick(g,tmpx2-Len1/2.0,tmpy2,tmpx2+Len1/2.0,tmpy2,my_thickness,minc);
            drawLineThick(g,tmpx1,tmpy1,tmpx3,tmpy3,my_thickness,minc);
}

public void draw_swr_line(Graphics g){
	int xcor, ycor, xxcor, yycor;
	double theta;
	
	if(draw_impedance_chart){
	    if(xpos == 0.0 ){
		draw_Zin = false;
		draw_Yin = true;
	    }
	    else{
		draw_Zin = true;
		draw_Yin = true;
	    }
	    if(draw_inverse){
		draw_Yin = true;
	    }
	    else{
		draw_Yin = false;
	    }
	}
	if(draw_admittance_chart){
	    if(xpos == 0.0 ){
		draw_Yin = false;
		draw_Zin = true;
	    }
	    else{
		draw_Yin = true;
		draw_Zin = true;
	    }
	    if(draw_inverse){
		draw_Zin = true;
	    }
	    else{
		draw_Zin = false;
	    }
	}
	if(draw_impedance_chart){
	    
         if(xpos < 0.1){
            if(draw_Zin){
		//For Zin
		theta=-GammaZin.Arg2();	
                if(colore_dark){
                    g.setColor(Color.green);
                }
                else{
                    g.setColor(Color.green.darker());
                }
                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(Color.blue);
		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;
		g.setColor(Color.red);
		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;
		g.setColor(Color.red);
		g.drawLine(xcor,ycor,xxcor,yycor);
	    }
            if(draw_Zin){
		//For Zin
		theta=-GammaZin.Arg2();		
		if(colore_dark){
                    g.setColor(Color.green);
                }
                else{
                    g.setColor(Color.green.darker());
                }
		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(Color.blue);
		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_admittance_chart){
            if(xpos < 0.1){
	    if(draw_Yin){
		//For Yin
		theta=-GammaZin.Arg2();
		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_Zin){
		//For Zin
		theta=-GammaYin.Arg2();
		if(colore_dark){
                    g.setColor(Color.green);
                }
                else{
                    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;
		g.setColor(Color.orange);
		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;
		g.setColor(Color.orange);
		g.drawLine(xcor,ycor,xxcor,yycor);
                }
                if(draw_Yin){
		//For Yin
		theta=-GammaZin.Arg2();
		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_Zin){
		//For Zin
		theta=-GammaYin.Arg2();
		if(colore_dark){
                    g.setColor(Color.green);
                }
                else{
                    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 void setLoadType(boolean IsLoadOpen, boolean IsLoadShort, boolean IsLoadImaginary, boolean IsLoadRegular){
	    this.IsLoadOpen = IsLoadOpen;
	    this.IsLoadShort = IsLoadShort;
	    this.IsLoadImaginary = IsLoadImaginary;
	    this.IsLoadRegular = IsLoadRegular;
}

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){
	if(Complex.Real(ZL)==0.0&&Complex.Imaginary(ZL)<-1.0e130){
		    //IsOpen = true;
		    //IsShort = false;
		    this.ZL = new Complex(0.0,-1.0E135);
		    this.YL = new Complex(0.0,0.0);
		    this.GammaZL = new Complex(1.0,0.0);
		}
		else if(Complex.Real(ZL)==0.0&&Complex.Imaginary(ZL)==0.0){
		    //IsOpen = false;
		    //IsShort = true;
		    this.YL = new Complex(0.0,-1.0E135);
		    this.ZL = new Complex(0.0,0.0);
		    this.GammaZL = new Complex(-1.0,0.0);
		}
		else{
		    //IsOpen = false;
		    //IsShort = false;
		    this.ZL = ZL;
		    this.YL = EMF.Inv(ZL);
		    this.GammaZL = EMF.computeGamma(this.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){
	    if(Complex.Real(YL)==0.0&&Complex.Imaginary(YL)<-1.0e130){
		    //IsOpen = false;
		    //IsShort = true;
		    this.YL = new Complex(0.0,-1.0E135);
		    this.ZL = new Complex(0.0,0.0);
		    this.GammaZL = new Complex(-1.0,0.0);
		}
		else if(Complex.Real(YL)==0.0&&Complex.Imaginary(YL)==0.0){
		    //IsOpen = true;
		    //IsShort = false;
		    this.ZL = new Complex(0.0,-1.0E135);
		    this.YL = new Complex(0.0,0.0);
		    this.GammaZL = new Complex(1.0,0.0);
		}
		else{
		    //IsOpen = false;
		    //IsShort = false;
		    this.YL = YL;
		    this.ZL = EMF.Inv(YL);
		    this.GammaZL = EMF.computeGamma(this.YL,false);  
		}
		
	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_smooth(boolean arg){
    smoothing = arg;
    repaint();
}

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_gensmith(boolean arg){
	IsLargerThanOne=arg;
	repaint();
}

public synchronized void set_chart(boolean arg){
	FullChart=arg;
	repaint();
}

public synchronized void set_curves(boolean arg){
	ShowCurves=arg;
	repaint();
}

public synchronized void set_inverse(boolean arg){
	draw_inverse=arg;
	repaint();
}

public synchronized void set_show_SWR(boolean arg){
	draw_SWR_circle=arg;
	repaint();
}

public synchronized void set_show_gamma(boolean arg){
	show_gamma=arg;
	repaint();
}

public synchronized void set_gammaL(boolean arg){
	gammaL=arg;
	repaint();
}

public synchronized void set_gammaD(boolean arg){
	gammaD=arg;
	repaint();
}

public synchronized void set_show_max(boolean arg){
	draw_max=arg;
	repaint();
}

public synchronized void set_show_min(boolean arg){
	draw_min=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 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();
}
public synchronized void setalpha(double alpha){
	this.alpha=alpha;
	repaint();
}

public synchronized void setGammaFlag(boolean IsLargerThanOne){
	this.IsLargerThanOne = IsLargerThanOne;
	repaint();
}

private  void cricket_2(MouseEvent evt){

	int tx1, ty1, tx2, ty2, tx3, ty3, newRadius;
	int x, y, forbid1, forbid2;
	x = evt.getX();
	y = evt.getY();
	Graphics g = this.getGraphics();
	forbid1 = 10*getSize().width/100;
	forbid2 = 80*getSize().width/100;
	
	if(!IsLargerThanOne){
	    tx1 = x - xCenter;
	    ty1 = y - yCenter;	
	    //if(x == (state.s518) && y == (state.s280)){
            if((x == (int)Math.ceil(state.s518) || x == (int)Math.ceil(state.s518-1))
                    && y == (int)Math.ceil(state.sfactor*280)){// && y <= (int)Math.ceil(state.sfactor*280+1)){
		xProbe = x;
		yProbe = y;
                GammaProbe = new Complex(1.0,0.0);
                ZProbe = new Complex(0.0, -1.0E135);
                YProbe = new Complex(0.0, 0.0);
		IsInside = true;
                IsLoadOpen = true;
                IsLoadShort = false;
                //System.out.println(xProbe+"   "+yProbe+"   IsLoadOpen = "+state.IsLoadOpen);
	    }
            else if(x == (int)Math.ceil(state.s518)-1
                    && y == (int)Math.ceil(state.s280)){// && y <= (int)Math.ceil(state.sfactor*280+1)){
		xProbe = x;
		yProbe = y;
                GammaProbe = new Complex(1.0,0.0);
                ZProbe = new Complex(0.0, -1.0E135);
                YProbe = new Complex(0.0, 0.0);
		IsInside = true;
                IsLoadOpen = true;
                IsLoadShort = false;
                //System.out.println(xProbe+"   "+yProbe+"   IsLoadOpen = "+state.IsLoadOpen);
	    }
	    else if(x == state.s42 && y == (state.s80)){
		xProbe = x;
		yProbe = y;
                GammaProbe=new Complex(-1.0,0.0);
                YProbe = new Complex(0.0, -1.0E135);
                ZProbe = new Complex(0.0, 0.0);
		IsInside = true;
                IsLoadOpen = false;
                IsLoadShort = true;
                //System.out.println(xProbe+"   "+yProbe+"   IsLoadShort = "+IsLoadShort);
    	    }
	    else if(Math.pow(tx1,2.0)+Math.pow(ty1,2.0)<=Math.pow(Radius3,2.0) && (x!=(state.s518) && y!=(state.s280)) && (x!=state.s42 && y!=(state.s280))){
		xProbe = x;
		yProbe = y;
                GammaProbe = new Complex(1.0*tx1/Radius3,-1.0*ty1/Radius3);
                ZProbe = EMF.computeZ(GammaProbe);
                YProbe = Complex.Divide(new Complex(1.0,0.0),ZProbe);
		IsInside = true;
                IsLoadOpen = false;
                IsLoadShort = false;
                //System.out.println(xProbe+"   "+yProbe+"   IsLoadOpen = "+state.IsLoadOpen+"   ZProbe = "+ZProbe+"   CHECK A");
	    }
	    else if(Math.pow(tx1,2.0)+Math.pow(ty1,2.0)<=Math.pow(Radius3,2.0) && (y==(state.s280)) && x < (int)Math.ceil(state.sfactor*518-1)){
		xProbe = x;
		yProbe = y;
                //GammaProbe=new Complex(1.0*tx1/Radius3,-1.0*ty1/Radius3);
                GammaProbe = new Complex(1.0*tx1/Radius3,0.0);
                ZProbe = EMF.computeZ(GammaProbe);
                YProbe = Complex.Divide(new Complex(1.0,0.0),ZProbe);
		IsInside = true;
                IsLoadOpen = false;
                IsLoadShort = false;
                //System.out.println(xProbe+"   "+yProbe+"   IsLoadOpen = "+state.IsLoadOpen+"Gamma Probe = "+GammaProbe+"   ZProbe = "+ZProbe+"   CHECK B");
	    }
	    else{
		IsInside = false;
                IsLoadOpen = false;
                IsLoadShort = false;
                //System.out.println(xProbe+"   "+yProbe+"   IsLoadOpen = "+state.IsLoadOpen+"   ZProbe = "+ZProbe+"   CHECK C");
	    }
	}
	else{	
	    if(y <= yCenter){
		tx1=x-xCenter;
		ty1=y-yCenter;	
	    
		newRadius = 1+(int)((Radius3/(1+Math.sqrt(2.0))*Math.sqrt(2)));
		tx2=x-xCenter;
		ty2=y-(int)(newRadius)-(getSize().height/2-Radius3);	
					
		if(Math.pow(tx2,2.0)+Math.pow(ty2,2.0)<=Math.pow(newRadius,2.0)){
		    
		    xProbe=x;
		    yProbe=y;
		    if(IsLargerThanOne){
			GammaProbe=new Complex(2.4140*tx1/Radius3,-2.4140*ty1/Radius3);
		    }
		    else{
			GammaProbe=new Complex(1.0*tx1/Radius3,-1.0*ty1/Radius3);
		    }
		    if(Complex.Real(GammaProbe) == 1.0 && Complex.Imaginary(GammaProbe) == 0.0){
			ZProbe = new Complex(0.0, -1.0E135);
			YProbe = new Complex(0.0, 0.0);
		    }
		    else if(Complex.Real(GammaProbe) == -1.0 && Complex.Imaginary(GammaProbe) == 0.0){
			YProbe = new Complex(0.0, -1.0E135);
			ZProbe = new Complex(0.0, 0.0);
		    }
		    else{
			ZProbe=EMF.computeZ(GammaProbe);
			YProbe=Complex.Divide(new Complex(1.0,0.0),ZProbe);
		    }
		    
		    		
		}
		else if(Math.pow(tx1,2.0)+Math.pow(ty1,2.0)<=Math.pow(Radius3,2.0)
			&& Math.pow(tx2,2.0)+Math.pow(ty2,2.0)>Math.pow(newRadius,2.0)){
		    
		    if(x < xCenter){
			g.setColor(Color.black);
			//g.drawString("Forbidden",forbid2,getSize().height/2);
			//g.drawString("Region",forbid2,getSize().height/2+12);
						
			g.setColor(Color.white);
			//g.drawString("Forbidden",forbid1,getSize().height/2);
			//g.drawString("Region",forbid1,getSize().height/2+12);
		    }
		    if(x > xCenter){
			g.setColor(Color.black);
			//g.drawString("Forbidden",forbid1,getSize().height/2);
			//g.drawString("Region",forbid1,getSize().height/2+12);
			
			g.setColor(Color.white);
			//g.drawString("Forbidden",forbid2,getSize().height/2);
			//g.drawString("Region",forbid2,getSize().height/2+12);
		    }
		}
	    }
	    
	    else if(y >= yCenter){
		tx1=x-xCenter;
		ty1=y-yCenter;	
		
		newRadius = 1+(int)((Radius3/(1+Math.sqrt(2.0))*Math.sqrt(2)));
		tx3=x-xCenter;
				
		ty3=y-(yCenter+Radius3-newRadius);	
			
			g.setColor(Color.black);
			//g.drawString("Forbidden",forbid2,getSize().height/2);
			//g.drawString("Region",forbid2,getSize().height/2+12);
			//g.drawString("Forbidden",forbid1,getSize().height/2);
			//g.drawString("Region",forbid1,getSize().height/2+12);
				
	       if(Math.pow(tx3,2.0)+Math.pow(ty3,2.0)<=Math.pow(newRadius,2.0)){
		    
		    xProbe=x;
		    yProbe=y;
		    if(IsLargerThanOne){
			GammaProbe=new Complex(2.4140*tx1/Radius3,-2.4140*ty1/Radius3);
		    }
		    else{
			GammaProbe=new Complex(1.0*tx1/Radius3,-1.0*ty1/Radius3);
		    }
		    if(Complex.Real(GammaProbe) == 1.0 && Complex.Imaginary(GammaProbe) == 0.0){
			ZProbe = new Complex(0.0, -1.0E135);
			YProbe = new Complex(0.0, 0.0);
		    }
		    else if(Complex.Real(GammaProbe) == -1.0 && Complex.Imaginary(GammaProbe) == 0.0){
			YProbe = new Complex(0.0, -1.0E135);
			ZProbe = new Complex(0.0, 0.0);
		    }
		    else{
			ZProbe=EMF.computeZ(GammaProbe);
			YProbe=Complex.Divide(new Complex(1.0,0.0),ZProbe);
		    }		    
		}
		else if(Math.pow(tx1,2.0)+Math.pow(ty1,2.0)<=Math.pow(Radius3,2.0)
			&& Math.pow(tx3,2.0)+Math.pow(ty3,2.0)>Math.pow(newRadius,2.0)){
		    
		    if(x < xCenter){
			g.setColor(Color.black);
			//g.drawString("Forbidden",forbid2,getSize().height/2);
			//g.drawString("Region",forbid2,getSize().height/2+12);
			
			g.setColor(Color.white);
			//g.drawString("Forbidden",forbid1,getSize().height/2);
			//g.drawString("Region",forbid1,getSize().height/2+12);
		    }
		    if(x > xCenter){
			g.setColor(Color.black);
			//g.drawString("Forbidden",forbid1,getSize().height/2);
			//g.drawString("Region",forbid1,getSize().height/2+12);
			
			g.setColor(Color.white);
			//g.drawString("Forbidden",forbid2,getSize().height/2);
			//g.drawString("Region",forbid2,getSize().height/2+12);
		    }
		}
		
	    }
	}
}

public void mouseDragged(MouseEvent evt){cricket_2(evt);}
public void mouseMoved(MouseEvent evt){;}
public void mouseClicked(MouseEvent evt){cricket_2(evt);}
public void mouseEntered(MouseEvent evt){setCursor(cursorB);}
public void mouseExited(MouseEvent evt){setCursor(cursorA);}
public void mousePressed(MouseEvent evt){cricket_2(evt);}
public void mouseReleased(MouseEvent evt){cricket_2(evt);}

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,state.s3,Color.green);
        drawArcThick(g,(double)(xCenter-raio/2),(double)(yCenter-raio/2),raio+1.0,beginAngle,Angle,state.s3,Color.red);
}

public final Complex getZProbe(){
	return ZProbe;
}

public final Complex getYProbe(){
	return YProbe;
}

public final Complex getGammaProbe(){
	return GammaProbe;
}

public void plot_red_cross(Graphics g, int x, int y){
	g.setColor(Color.white);
			g.fillRect(x-state.s5, y-state.s1,state.s11,state.s3);
			g.fillRect(x-state.s1,y-state.s5,state.s3,state.s11);
		g.setColor(Color.red);
			g.drawLine(x-state.s4,y,x+state.s4,y);
			g.drawLine(x,y-state.s4,x,y+state.s4);
}

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

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

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

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

}//End SmithCanvas


class SmithMan2 extends Panel{
private Label[] vlab, lab;
//private static final Color bgcolor = new Color(216,216,191);
private static final Color bgcolor = new Color(236,236,236);
int mode;//mode=1 Impedance, mode=2 Admittance Chart
	
private int width, height;  
private double xpos;  

private Image im;
private Graphics buf;
Trans_State state; 

Complex GLoad, Ginput, ZLoad, Zinput, YLoad, Yinput, GL;
public boolean IsLoadOpen, IsLoadShort, IsLoadImaginary, IsLoadRegular, Gamma_plusone, Gamma_minusone;
    
    private BufferedImage angle_img;
      
      SmithMan2(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.font12);
                Font labfont= new Font("SanSerif",Font.PLAIN,state.font12);
                
		//Panel p = new Panel();
		//p.setLayout(new GridLayout(5,2));
		lab = new Label[5];
		vlab = new Label[5];
		lab[0] = new Label("Load Impedance = ",Label.LEFT);
		lab[1] = new Label("Load Refl. Coef. = ",Label.LEFT);
		lab[2] = new Label("Cursor Impedance = ",Label.LEFT);
		lab[3] = new Label("Cursor Refl. Coef. = ",Label.LEFT);
		lab[4] = new Label("Cursor Admittance = ",Label.LEFT);
		for(int i = 0; i<lab.length; i++){
			vlab[i] = new Label("",Label.LEFT);
			vlab[i].setFont(labelfont);
			lab[i].setFont(labelfont);
		}
				
		//input for ourwidth the number used for the smith man panel
		int ourwidth = state.s250;
		int vstep = state.s16;
		
		int vstepinit = state.s2;
		int xinit = state.s15; 
		int xinit2 = state.s18*ourwidth/100;
		
		Gamma_plusone = false;
		Gamma_minusone = false;	
	}

    private void getImages() {
        // read in character images that CHEERPJ will not render
	//   (java to javascript converter)
	double font11_factor = 11.0 * state.sfactor;
	long fontsize = Math.round(font11_factor);
	if (fontsize > 30) fontsize = 30;
	else if (fontsize < 11) fontsize = 11;
	String filename = "angle_"+String.valueOf(fontsize)+".png";
        try {
	    angle_img = ImageIO.read(getClass().getResource(filename));
            //angle_img = ImageIO.read(getClass().getResource("angle.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
      
	public void paint(Graphics g){
            //drawpanel(g);
	    if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawpanel(buf);
	    }
	    else{
		drawpanel(buf);
	    }
	    repaint();
	    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 drawpanel(Graphics g){
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);    
            
            int shiftx = state.s20;
            int shiftx2 = state.s15;

            FontMetrics fm;
            Font labfont= new Font("SanSerif",Font.PLAIN,state.font11);
            String alpha, Ohm, lambda, infinity, Gamma, plusj, minusj, sign;
            
            alpha="\u03b1";
            lambda="\u03bb";
            Ohm="\u03a9";
            infinity="\u221e";
            Gamma="\u0393";
            
            g.setFont(labfont);

            int vstep = state.s16;
            int vstepinit = state.s12;
            int xinit = state.s18 + shiftx;
            int xinit2 = xinit+state.s25;
            int xinit3 = xinit2+state.s70;
            plusj =" + j ";
            minusj=" - j ";

            double Tolerance = 1.0E-10;
	    fm = g.getFontMetrics();

	    g.setColor(bgcolor);
	    g.fillRect(0,0,getSize().width,getSize().height);
	    double tempR = 1.0, tempX = 2.0;
	    int stepx = 0;
	    
	    if(mode==1){
		g.setColor(Color.black);
		MaestroG.subscripter(" z","L","",g,state.font11,xinit,vstepinit);
		
		if(IsLoadOpen){
		    MaestroG.subscripterInfinityOne("=  ","","","",g,state.font11,xinit2,vstepinit);
                    //System.out.println("state.IsLoadOpen = "+state.IsLoadOpen+"IsLoadOpen = "+IsLoadOpen+"   IsLoadShort = "+IsLoadShort);
		}
		else if(IsLoadShort){
		    MaestroG.subscripter("=  0.0 + j 0.0","","",g,state.font11,xinit2,vstepinit);
                    //System.out.println("state.IsLoadOpen = "+state.IsLoadOpen+"IsLoadOpen = "+IsLoadOpen+"   IsLoadShort = "+IsLoadShort);
		}
		else{
		    if(Complex.Imaginary(ZLoad) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(IsLoadImaginary){
			tempR = 0.0;
		    }
		    else if(IsLoadRegular){
			tempR = ZLoad.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 != 0.0){
			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");
		    }
		    
		    tempX = Math.abs(ZLoad.Imaginary());
                    if(Math.abs(tempX) < (Math.abs(tempR)*Tolerance)){tempX = 0.0;}

		    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 != 0.0){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,state.font11,xinit3,vstepinit);
		    }
		}
		
		
		MaestroG.subscripterSS3(" "+Gamma,"L","",g,state.font11,xinit+1,vstepinit + vstep);
		
                double dtmp1, dtmp2;
                dtmp1=MaestroA.rounder(GLoad.Magnitude(),8);
                    if(dtmp1 == 0.0){dtmp2 = 0.0;}
                    else{dtmp2=MaestroA.rounder(GLoad.Arg2()*180/Math.PI,4);}
		//MaestroG.SansMiditalic("= "+dtmp1,"  \u2220 ",""+dtmp2+" \u00ba",g,state.font11,xinit2,vstepinit + vstep);
		MaestroG.TxtImgTxt("= "+dtmp1,angle_img,""+dtmp2+" \u00ba",g,state.font11,xinit2,vstepinit + vstep,this);
	
                // 1 following c/o by JANICE
		//MaestroG.subscripterSS3(""+Gamma,"","(d)",g,state.font11,xinit+1,vstepinit + 3*vstep);
		MaestroG.subscripterSS3(" "+Gamma,"d","",g,state.font11,xinit+1,vstepinit + 3*vstep);
				
                dtmp1=MaestroA.rounder(Ginput.Magnitude(),8);
                    if(dtmp1 == 0.0){dtmp2 = 0.0;}
                    else{dtmp2=MaestroA.rounder(Ginput.Arg2()*180/Math.PI,4);}
		//MaestroG.SansMiditalic("= "+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(Ginput) > 0.999999 && Math.abs(Complex.Imaginary(Ginput)) < 0.000001){
		    Gamma_plusone = true;
		    Gamma_minusone = false;
		}
		else if(Complex.Real(Ginput) < -0.999999 && Math.abs(Complex.Imaginary(Ginput)) < 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 && Gamma_plusone){
                        MaestroG.subscripterInfinityOne("=  ","","","",g,state.font11,xinit2,vstepinit + 2*vstep);
		}
                else if(IsLoadOpen && Gamma_minusone){
		    MaestroG.subscripter("=  0.0 + j 0.0","","",g,state.font11,xinit2,vstepinit + 2*vstep);
		}
		else if(IsLoadShort && Gamma_plusone){
		    MaestroG.subscripterInfinityOne("=  ","","","",g,state.font11,xinit2,vstepinit + 2*vstep);
		}
		else if(IsLoadShort && Gamma_minusone){
		    MaestroG.subscripter("=  0.0 + j 0.0","","",g,state.font11,xinit2,vstepinit + 2*vstep);
		}
		else{
		    if(Complex.Imaginary(Zinput) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(IsLoadImaginary || IsLoadOpen || IsLoadShort){
			tempR = 0.0;
		    }
		    else if(IsLoadRegular){
			tempR = Zinput.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 != 0.0){
			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");
		    }
		    
		    tempX = Math.abs(Zinput.Imaginary());
                    if(Math.abs(tempX) < (Math.abs(tempR)*Tolerance)){tempX = 0.0;}

		    xinit3 = xinit2+stepx+state.s10;
		    
		    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 != 0.0){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		}
		
		MaestroG.subscripter("y","","(d)",g,state.font11,xinit+2,vstepinit + 4*vstep);
		
		if(Complex.Real(Yinput)==0.0&&Complex.Imaginary(Yinput)<-1.0E130){
		    MaestroG.subscripterInfinityOne("=  ","","","",g,state.font11,xinit2,vstepinit + 4*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 + 4*vstep);
		}
		else{
		    if(Complex.Imaginary(Yinput) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(IsLoadImaginary || IsLoadOpen || IsLoadShort){
			tempR = 0.0;
		    }
		    else if(IsLoadRegular){
			tempR = Yinput.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 != 0.0){
			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");
		    }
		    
		    tempX = Math.abs(Yinput.Imaginary());
                    if(Math.abs(tempX) < (Math.abs(tempR)*Tolerance)){tempX = 0.0;}

		    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 != 0.0){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		}
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
		g.setColor(Color.red);
		g.fillOval(state.s4+shiftx2,state.s5,state.s8,state.s8);
		g.setColor(Color.green);
		g.fillOval(state.s4+shiftx2,44*getSize().height/100,state.s8,state.s8);
		//g.setColor(Color.blue);
                g.setColor(new Color(0,150,255));
		g.fillOval(state.s4+shiftx2,82*getSize().height/100,state.s8,state.s8);
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
    	    }
	    if(mode==2){
		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(YLoad) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(IsLoadImaginary){
			tempR = 0.0;
		    }
		    else if(IsLoadRegular){
			tempR = YLoad.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 != 0.0){
			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");
		    }
		    
		    tempX = Math.abs(YLoad.Imaginary());
                    if(Math.abs(tempX) < (Math.abs(tempR)*Tolerance)){tempX = 0.0;}

		    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 != 0.0){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,state.font11,xinit3,vstepinit);
		    }
		}
		
		MaestroG.subscripterSS3(" "+Gamma,"L","",g,state.font11,xinit+1,vstepinit + vstep);
		//MaestroG.superscripter("= "+GLoad.toString(Complex.POLAR_DEGREE,4),"","",g,state.font11,xinit2,vstepinit + vstep);
		
		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
                double dtmp1, dtmp2;
                dtmp1=MaestroA.rounder(GLoad.Magnitude(),8);
                    if(dtmp1 == 0.0){dtmp2 = 0.0;}
                    else{dtmp2=MaestroA.rounder(GLoad.Arg2()*180/Math.PI,4);}
                MaestroG.SansMiditalic("= "+dtmp1,"  L ",""+dtmp2+" \u00ba",g,state.font11,xinit2,vstepinit + vstep);
                
                dtmp1=MaestroA.rounder(Ginput.Magnitude(),8);
                    if(dtmp1 == 0.0){dtmp2 = 0.0;}
                    else{dtmp2=MaestroA.rounder(Ginput.Arg2()*180/Math.PI,4);}
                MaestroG.SansMiditalic("= "+dtmp1,"  L ",""+dtmp2+" \u00ba",g,state.font11,xinit2,vstepinit + 3*vstep);
                //----------------------------------------------------------------------------------------------                
		if(Complex.Real(Ginput) > 0.999999 && Math.abs(Complex.Imaginary(Ginput)) < 0.000001){
		    Gamma_plusone = true;
		    Gamma_minusone = false;
		}
		else if(Complex.Real(Ginput) < -0.999999 && Math.abs(Complex.Imaginary(Ginput)) < 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 && Gamma_minusone){
		    MaestroG.subscripterInfinityOne("=  ","","","",g,state.font11,xinit2,vstepinit + 2*vstep);
		}
		else if(IsLoadOpen && Gamma_plusone){
		    MaestroG.subscripter("=  0.0 + j 0.0","","",g,state.font11,xinit2,vstepinit + 2*vstep);
		}
		else if(IsLoadShort && Gamma_minusone){
		    MaestroG.subscripterInfinityOne("=  ","","","",g,state.font11,xinit2,vstepinit + 2*vstep);
		}
		else if(IsLoadShort && 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(Yinput) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(IsLoadImaginary || IsLoadOpen || IsLoadShort){
			tempR = 0.0;
		    }
		    else if(IsLoadRegular){
			tempR = Yinput.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 != 0.0){
			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");
		    }
		    
		    tempX = Math.abs(Yinput.Imaginary());
		    if(Math.abs(tempX) < (Math.abs(tempR)*Tolerance)){tempX = 0.0;}

                    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 != 0.0){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,state.font11,xinit3,vstepinit+ 2*vstep);
		    }
		}
		
		
		MaestroG.subscripter("z","","(d)",g,state.font11,xinit,vstepinit + 4*vstep);
		
		if(IsLoadOpen && Gamma_plusone){
		    MaestroG.subscripterInfinityOne("=  ","","","",g,state.font11,xinit2,vstepinit + 4*vstep);
		}
		else if(IsLoadOpen && Gamma_minusone){
		    MaestroG.subscripter("=  0.0 + j 0.0","","",g,state.font11,xinit2,vstepinit + 4*vstep);
		}
		else if(IsLoadShort && Gamma_plusone){
		    MaestroG.subscripterInfinityOne("=  ","","","",g,state.font11,xinit2,vstepinit + 4*vstep);
		}
		else if(IsLoadShort && 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(Zinput) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(IsLoadImaginary || IsLoadOpen || IsLoadShort){
			tempR = 0.0;
		    }
		    else if(IsLoadRegular){
			tempR = Zinput.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 != 0.0){
			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");
		    }
		    
		    tempX = Math.abs(Zinput.Imaginary());
                    if(Math.abs(tempX) < (Math.abs(tempR)*Tolerance)){tempX = 0.0;}

                    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 != 0.0){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,state.font11,xinit3,vstepinit+ 4*vstep);
		    }
		}
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		                
                g.setColor(Color.yellow);
		g.fillOval(state.s4+shiftx2,state.s5,state.s8,state.s8);
		//g.setColor(Color.blue);
                g.setColor(new Color(0,150,255));
		g.fillOval(state.s4+shiftx2,44*getSize().height/100,state.s8,state.s8);
		g.setColor(Color.green);
		g.fillOval(state.s4+shiftx2,82*getSize().height/100,state.s8,state.s8);
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
	    }
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                g.setColor(Color.black);
		g.drawOval(state.s4+shiftx2,state.s5,state.s8,state.s8);
		g.drawOval(state.s4+shiftx2,44*getSize().height/100,state.s8,state.s8);
		g.drawOval(state.s4+shiftx2,82*getSize().height/100,state.s8,state.s8);
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
	}
	public void setZL(Complex ZL){
		if(Complex.Real(ZL)==0.0&&Complex.Imaginary(ZL)<-1.0e130){
		    //IsOpen = true;
		    //IsShort = false;
		    ZLoad = new Complex(0.0,-1.0E135);
		    YLoad = new Complex(0.0,0.0);
		    GLoad = new Complex(1.0,0.0);
		}
		else if(Complex.Real(ZL)==0.0&&Complex.Imaginary(ZL)==0.0){
		    //IsOpen = false;
		    //IsShort = true;
		    YLoad = new Complex(0.0,-1.0E135);
		    ZLoad = new Complex(0.0,0.0);
		    GLoad = new Complex(-1.0,0.0);
		}
		else{
		    //IsOpen = false;
		    //IsShort = false;
		    ZLoad = ZL;
		    YLoad = EMF.Inv(ZLoad);
		    GLoad = EMF.computeGamma(ZLoad);  
		}
		
	}
	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){
		if(Complex.Real(YL)==0.0&&Complex.Imaginary(YL)<-1.0e130){
		    //IsOpen = false;
		    //IsShort = true;
		    YLoad = new Complex(0.0,-1.0E135);
		    ZLoad = new Complex(0.0,0.0);
		    GLoad = new Complex(-1.0,0.0);
		}
		else if(Complex.Real(YL)==0.0&&Complex.Imaginary(YL)==0.0){
		    //IsOpen = true;
		    //IsShort = false;
		    ZLoad = new Complex(0.0,-1.0E135);
		    YLoad = new Complex(0.0,0.0);
		    GLoad = new Complex(1.0,0.0);
		}
		else{
		    //IsOpen = false;
		    //IsShort = false;
		    YLoad = YL;
		    ZLoad = EMF.Inv(YLoad);
		    GLoad = EMF.computeGamma(ZLoad);  
		}
		
	}
	
	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){
		if(Complex.Real(Zin)==0.0&&Complex.Imaginary(Zin)<-1.0e130){
		    Zinput = new Complex(0.0,-1.0E135);
		    Yinput = new Complex(0.0,0.0);
		    Ginput = new Complex(1.0,0.0);
		}
		else if(Complex.Real(Zin)==0.0&&Complex.Imaginary(Zin)==0.0){
		    Yinput = new Complex(0.0,-1.0E135);
		    Zinput = new Complex(0.0,0.0);
		    Ginput = new Complex(-1.0,0.0);
		}
		else{
		    Zinput = Zin;
		    Yinput = EMF.Inv(Zinput);
		    Ginput = EMF.computeGamma(Zinput);
		}
		
	}
	public void setLoadType(boolean IsLoadOpen, boolean IsLoadShort, boolean IsLoadImaginary, boolean IsLoadRegular){
	    this.IsLoadOpen = IsLoadOpen;
	    this.IsLoadShort = IsLoadShort;
	    this.IsLoadImaginary = IsLoadImaginary;
	    this.IsLoadRegular = IsLoadRegular;
	}
	
	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){
		if(Complex.Real(Yin)==0.0&&Complex.Imaginary(Yin)<-1.0e130){
		    Yinput = new Complex(0.0,-1.0E135);
		    Zinput = new Complex(0.0,0.0);
		    Ginput = new Complex(-1.0,0.0);
		}
		else if(Complex.Real(Yin)==0.0&&Complex.Imaginary(Yin)<-1.0e130){
		    Zinput = new Complex(0.0,-1.0E135);
		    Yinput = new Complex(0.0,0.0);
		    Ginput = new Complex(1.0,0.0);
		}
		else{
		    Yinput = Yin;
		    Zinput = EMF.Inv(Yin);
		    Ginput = EMF.computeGamma(Zinput);  
		}
		
	}
	
	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;
	}
	public synchronized void setxpos(double xpos){
	    this.xpos=xpos;
	}
	public synchronized void setGL(Complex GL){
	    this.GL=GL;
	}
}


class SmithProbe2  extends Panel{
    Label[] lab;
    private int mode;
    private int shiftx, shifty, shifty2;
    private final Color bcolor = new Color(236,236,236);
    Trans_State state;
        
    SmithProbe2(int width, int height, Trans_State state){
	super();
        this.state = state;
	setLayout(null);
	setBackground(bcolor);
	//Font labfont = TheFonts.sanSerif11;
	Panel p = new Panel();
	
        Font labfont = (new Font("SanSerif",Font.PLAIN,state.font10));
        shiftx = state.s20;
        shifty = state.s5;
        shifty2 = state.s10;
        
	lab = new Label[6];
	lab[0] = new Label(" ",Label.LEFT);
	lab[1] = new Label(" ",Label.LEFT);
	lab[0].setFont(labfont);
	lab[1].setFont(labfont);
	lab[2] = new Label(" ",Label.LEFT);
	lab[3] = new Label(" ",Label.LEFT);
	lab[4] = new Label(" ",Label.LEFT);
	lab[5] = new Label(" ",Label.LEFT);
	lab[2].setFont(labfont);
	lab[3].setFont(labfont);
	lab[4].setFont(labfont);
	lab[5].setFont(labfont);
	lab[5].setForeground(Color.blue);
	add(lab[0]); add(lab[1]); add(lab[2]); add(lab[3]); add(lab[4]); add(lab[5]);
	
	//p.add(lab[0]);
	//p.add(lab[1]);
	//add(p);
	//p.setBounds(20,1,width-17,height-1);
	lab[0].setBounds(state.s20+shiftx,shifty,state.s100,state.s15);
	lab[5].setBounds(state.s120+shiftx,shifty,state.s100,state.s15);
	lab[1].setBounds(state.s20+shiftx,state.s14+shifty,state.s200,state.s15);
	lab[2].setBounds(state.s20+shiftx,state.s31+shifty2,state.s200,state.s15);
	lab[3].setBounds(state.s20+shiftx,state.s47+shifty2,state.s200,state.s15);
	//lab[4].setBounds(state.s25+shiftx,state.s61+shifty,state.s200,state.s15);
	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){
	Font symbolfont=TheFonts.symbol12;
	String beta, lambda;
	
	setFont(symbolfont);   
	beta = "\u03b2";
	lambda = "\u03bb";
	
	double txpos=xpos;
	if(xpos<=0.5){
	    lab[0].setText("d = "+MaestroA.rounder(txpos,6)+" "+lambda);
	    lab[5].setText("  ");
	    lab[1].setText("2 "+beta+" d = "+MaestroA.rounder(txpos*4*Math.PI,6)+" rad = "+MaestroA.rounder(txpos*4*180,6)+"\u00ba");
	    lab[2].setText("0.5"+lambda+" - d = "+MaestroA.rounder((0.5-txpos),6)+lambda);
	    //lab[3].setText("2 "+beta+" (0.5"+lambda+" - d) = ");
	    //lab[4].setText(" = "+MaestroA.rounder((0.5-txpos)*4*Math.PI,4)+" rad = "+MaestroA.rounder((0.5-txpos)*4*180,4)+"\u00ba");
	    lab[3].setText("2 "+beta+" (0.5"+lambda+" - 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,6)+" "+lambda);
	    lab[5].setText("d = "+MaestroA.rounder(txpos+0.5,6)+" "+lambda);
	    lab[1].setText("2 "+beta+" d' = "+MaestroA.rounder(txpos*4*Math.PI,6)+" rad = "+MaestroA.rounder(txpos*4*180,6)+"\u00ba");
	    lab[2].setText("0.5"+lambda+" - d' = "+MaestroA.rounder((0.5-txpos),6)+" "+lambda);
	    //lab[3].setText("2 "+beta+" (0.5"+lambda+" - d') = ");
	    //lab[4].setText(" = "+MaestroA.rounder((0.5-txpos)*4*Math.PI,6)+" rad = "+MaestroA.rounder((0.5-txpos)*4*180,6)+"\u00ba");
	    lab[3].setText("2 "+beta+" (0.5"+lambda+" - d') = "+MaestroA.rounder((0.5-txpos)*4*Math.PI,6)+" rad = "+MaestroA.rounder((0.5-txpos)*4*180,6)+"\u00ba");
	    
	    repaint();
	}
}


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

private void draw_icon(Graphics g){
	
}

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

class SmithAuxiliary extends Panel{
    public Checkbox show_SWR, show_max, show_min, show_gamma, gammaL, gammaD;
    public CheckboxGroup cgamma;
    private Complex ZL;
    private static final Color bgcolor = new Color(236,236,236);
    String Gamma;
    private Image im;
    private Graphics buf;
    private int shiftx;
    Trans_State state;

    SmithAuxiliary(Trans_State state){
        this.state = state;
        Gamma="\u0393";
        setLayout(null);
        setBackground(bgcolor);
        
        Label Gamma_label;
        Gamma_label = new Label(""+Gamma,Label.LEFT);
        Gamma_label.setFont(new Font("Serif",Font.BOLD,state.font14));
        
        shiftx = state.s20;
        cgamma = new CheckboxGroup();
        gammaL = new Checkbox(" Load",cgamma,true);
        gammaD = new Checkbox(" Cursor",cgamma,false);
        
        show_gamma = new Checkbox(" Show \u0393",null,true);
        show_gamma.setFont(new Font("Serif",Font.BOLD,state.font14));
        //show_gamma = new Checkbox(" Show",null,true);
        show_SWR = new Checkbox(" Tangent SWR Circle",null,false);
        show_max = new Checkbox(" Voltage Maximum",null,false);
        show_min = new Checkbox(" Voltage Minimum",null,false);
        
        gammaL.setFont(new Font("Serif",Font.BOLD,state.font13));
        gammaD.setFont(new Font("Serif",Font.BOLD,state.font13));
        //show_gamma.setFont(new Font("SanSerif",Font.BOLD,state.font14));
        show_SWR.setFont(new Font("SanSerif",Font.BOLD,state.font12));
        show_max.setFont(new Font("SanSerif",Font.BOLD,state.font12));
        show_min.setFont(new Font("SanSerif",Font.BOLD,state.font12));
        
        add(show_SWR);
        add(show_max);
        add(show_min);
        add(show_gamma);
        add(Gamma_label);
        add(gammaL);
        add(gammaD);

        show_SWR.setBackground(bgcolor);
        show_max.setBackground(bgcolor);
        show_min.setBackground(bgcolor);
        show_gamma.setBackground(bgcolor);
        gammaL.setBackground(bgcolor);
        gammaD.setBackground(bgcolor);

        show_SWR.setBounds(state.s5+shiftx,state.s5,state.s170,state.s20);
        show_max.setBounds(state.s5+shiftx,state.s40,state.s170,state.s20);
        show_min.setBounds(state.s5+shiftx,state.s75,state.s170,state.s20);
        show_gamma.setBounds(state.s5+shiftx,state.s113,state.s80,state.s20);
        //Gamma_label.setBounds(state.s70+shiftx,state.s113,state.s25,state.s20);
        gammaL.setBounds(state.s100+shiftx,state.s113,state.s70,state.s20);
        gammaD.setBounds(state.s170+shiftx,state.s113,state.s80,state.s20);
    }

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

    public void paint(Graphics g){

        if(im == null){
                im = createImage(getSize().width,getSize().height);
                buf = im.getGraphics();
                draw(buf);
        }
        else{
                draw(buf);
        }
        g.drawImage(im,0,0,null);
        repaint();
    }

    public void draw(Graphics g){
        String Gamma;

        Gamma="\uu0393"; 
        g.setFont(new Font("SanSerif",Font.BOLD,state.font14));
        g.setColor(Color.black);
        //MaestroG.subscripterSerif(""+Gamma,"","",g,state.font14,state.s80+shiftx,state.s129);

        // CHANGE - USED RECTANGLES INSTEAD OF LINES
        int shiftx2 = state.s60;
        int xstart = state.s160;
        int xend = state.s200;

        if(show_SWR.getState()){
            //g.setColor(Color.gray);
            //g.fillRect(xstart+shiftx, state.s13-1, shiftx2, state.s6+2);
            g.setColor(new Color(255,155,65));
            g.fillRect(xstart+shiftx, state.s13, shiftx2, state.s6);
        }
        else{
            g.setColor(bgcolor);
            g.fillRect(xstart+shiftx-state.s1, state.s11, shiftx2+state.s2, state.s10);
        }

        if(show_max.getState()){

            //g.setColor(Color.gray.brighter());
            //g.fillRect(xstart+shiftx, state.s48-1, shiftx2, state.s6+2);
            g.setColor(new Color(255,210,0).brighter());
            g.fillRect(xstart+shiftx, state.s48, shiftx2, state.s6);
        }
        else{
            g.setColor(bgcolor);
            g.fillRect(xstart+shiftx-state.s1, state.s46, shiftx2+2, state.s9);
        }

        if(show_min.getState()){
            g.setColor(Color.white);
            g.fillRect(xstart+shiftx, state.s83-1, shiftx2, state.s6+2);
            g.setColor(new Color(0,150,255));
            g.fillRect(xstart+shiftx, state.s83, shiftx2, state.s6);
        }
        else{
            g.setColor(bgcolor);
            g.fillRect(xstart+shiftx-state.s1, state.s81, shiftx2+state.s2, state.s10);
        }
    }
    
    public void setZL(Complex ZL){
	this.ZL = ZL;
    }
}

class SmithControls2 extends Panel implements ItemListener{
public Checkbox imp, adm;
public CheckboxGroup cgrid;
public Checkbox swr, swrline, gensmith, chart, inverse, showcurves, smoothplot;
private static final Color bgcolor = new Color(236,236,236);
private boolean doz;
private int shiftx;
private Image im;
private Graphics buf;
Trans_State state;

SmithControls2(Trans_State state){

	//setLayout(new GridLayout(2,2));
	setLayout(null);
        this.state = state;
	setBackground(bgcolor);
	cgrid = new CheckboxGroup();

	//imp = new Checkbox("Impedance",cgrid,true);
	//adm = new Checkbox("Admittance",cgrid,false);
	shiftx = state.s20;
	swr = new Checkbox(" SWR Circle",null,true);
	swrline = new Checkbox(" Cursor Lines",null,true);
	chart = new Checkbox(" Full Chart",null,true);
	showcurves = new Checkbox(" Show Curves",null,true);
	//gensmith = new Checkbox("Extended Smith chart",null,false);  //NEW
	inverse = new Checkbox(" y ( d )",null,false);
        smoothplot = new Checkbox("Smoothing",null,true);
	doz = true;
	
	//add(imp);
	//add(adm);
	add(swr);
	add(swrline);
	add(chart);
	//add(gensmith);   // NEW 7/24/22  shows up in CHEERPJ version
	add(inverse);
	add(showcurves);
        //add(smoothplot);
	
	//imp.setBackground(bgcolor);
	//adm.setBackground(bgcolor);
	swr.setBackground(bgcolor);
	swrline.setBackground(bgcolor);
	inverse.setBackground(bgcolor);
	showcurves.setBackground(bgcolor);
	chart.setBackground(bgcolor);
        smoothplot.setBackground(bgcolor);
        
        swr.setFont(new Font("SanSerif",Font.BOLD,state.font12));
        swrline.setFont(new Font("SanSerif",Font.BOLD,state.font12));
        inverse.setFont(new Font("SanSerif",Font.BOLD,state.font12));
        showcurves.setFont(new Font("SanSerif",Font.BOLD,state.font12));
        chart.setFont(new Font("SanSerif",Font.BOLD,state.font12));
                
        swr.setBounds(state.s5+shiftx,state.s11,state.s120,state.s20);
	swrline.setBounds(state.s125+shiftx,state.s11,state.s130,state.s20);
	showcurves.setBounds(state.s5+shiftx,state.s31,state.s120,state.s20);
	chart.setBounds(state.s5+shiftx,state.s51,state.s120,state.s20);
	inverse.setBounds(state.s125+shiftx,state.s31,state.s120,state.s20);
	smoothplot.setBounds(state.s125+shiftx,state.s51,state.s120,state.s20);

	//imp.addItemListener(this);
	//adm.addItemListener(this);
}

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

public void paint(Graphics g){
		
		if(im == null){
			im = createImage(getSize().width,getSize().height);
			buf = im.getGraphics();
			draw(buf);
		}
		else{
			draw(buf);
		}
		g.drawImage(im,0,0,null);
}
    
public void draw(Graphics g){
	Font labfont = TheFonts.sanSerif12;
	g.setFont(labfont);
	g.setColor(Color.black);
	
}
public void itemStateChanged(ItemEvent evt){
    //if(evt.getSource()==imp){
    //	    doz = true;
    //        inverse.setLabel(" y ( d )");
    //	    repaint();
    //}
    //if(evt.getSource()==adm){
    //	    doz = false;
    //      inverse.setLabel(" z ( d )");
    //	    repaint();
    //}
    
}

}//End of SmithControls;
