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

import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.net.*;
import java.awt.event.*;

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;
        protected static final Font buttonfont = TheFonts.sanSerif11;
	
public SmithPanel2(Trans_State state){
	super();
	this.state = state;
	setLayout(null);
        setFont(TheFonts.sanSerif14);
	 
	large = new Checkbox("Show Plots",null,false);
	add(large);
	large.setBackground(Color.lightGray);
	//large.setBounds(455,552,90,20);
	//large.setBounds(450,552,98,20);
	large.setBounds(445,552,108,20);
        
        Panel plarge = new Panel();
	    plarge.setBackground(Color.lightGray);
	    add(plarge);
	    //plarge.setBounds(445,550,105,24);
	    plarge.setBounds(445,550,110,24);
	Panel plarge2 = new Panel();
	    plarge2.setBackground(Color.black);
	    add(plarge2);
	    //plarge2.setBounds(444,549,107,26);
	    plarge2.setBounds(444,549,112,26);
	
        
        //add button to change color scheme
        colore = new Button("Color");
	add(colore);
	colore.setBackground(Color.white);
	colore.setBounds(505,75,50,20);
        //colore.setBounds(505,49,50,20);
        //colore.setBounds(35,85,50,20);
        colore.setFont(buttonfont);
        colore_dark = false;

        //add button for About panel
        about = new Button("Instructions");
	add(about);
	about.setBackground(Color.white);
	about.setBounds(475,49,80,20);
        //about.setBounds(20,85,80,20);
        about.setFont(buttonfont);
        
	setBackground(bgcolor);
	sc = new SmithCanvas2();
	add(sc);
	sc.setBounds(2,37,561,561);
	
	scon = new SmithControls2();
	add(scon);
	scon.setBounds(569,5,274,80);
	
	saux = new SmithAuxiliary();
	add(saux);
	//saux.setBounds(569,271,204,136);
	saux.setBounds(569,92,274,136);
	
	sm = new SmithMan2(204,85);
	add(sm);
	//sm.setBounds(569,92,204,85);
	sm.setBounds(569,235,274,85);

	sp = new SmithProbe2(204,80);
	add(sp);
	//sp.setBounds(569,184,204,80);
	sp.setBounds(569,327,274,80);
	
	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(568,4,276,82);
	    
	Panel pgraph2 = new Panel();
	    pgraph2.setBackground(Color.black);
	    add(pgraph2);
	    pgraph2.setBounds(568,234,276,87);
	
	Panel pgraph4a = new Panel();
	    pgraph4a.setBackground(Color.black);
	    add(pgraph4a);
	    pgraph4a.setBounds(568,326,276,82);
	
	Panel pgraph4b = new Panel();
	    pgraph4b.setBackground(Color.black);
	    //add(pgraph4b);
	    pgraph4b.setBounds(260,614,306,43);
	    
	Panel paux = new Panel();
	    paux.setBackground(Color.black);
	    add(paux);
	    paux.setBounds(568,91,276,138);
	   
}
public void paint(Graphics g){
	g.setColor(bgcolor.darker());
	g.fillRect(0,getSize().height-2,getSize().width,2);
	g.fillRect(getSize().width-2,0,2,getSize().height);
	g.setColor(bgcolor.brighter());
	g.fillRect(0,0,2,getSize().height-1);
	g.fillRect(0,0,getSize().width-2,2);
}

public  synchronized void setZin(Complex Zin){
	sc.setZin(Zin);
	sm.setZin(Zin);
        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){;}//cricket_1();}
public void mouseMoved(MouseEvent evt){;}
public void mouseClicked(MouseEvent evt){;}//cricket_1();}
public void mouseEntered(MouseEvent evt){;}
public void mouseExited(MouseEvent evt){;}
public void mousePressed(MouseEvent evt){;}//cricket_1();}
public void mouseReleased(MouseEvent evt){;}//cricket_1();}
public void itemStateChanged(ItemEvent evt){cricket_2(evt);}

private void cricket_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;

public SmithCanvas2(){
	super();
	//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);
            
    
}

/*
public void paintComponent(Graphics g){
    Graphics2D g2d = (Graphics2D)g;
    g2d.setPaint(Color.red);
    g2d.setStroke(new BasicStroke(3));
    //Arc2D.Double arc_one = new Arc2D.double(20.0,20.0,50.0,50.0,35.0,75.0,0);
    //g2d.draw(arc_one);
    
    Ellipse2D.Double circle = new Ellipse2D.Double(10.0,10.0,30.0,30.0);
    g2d.draw(circle);
}
*/

//Addition to reduce flicker new routine
public void update(Graphics g){		// added to avoid clearing
	paint(g);
}


public void clear(){
	this.getGraphics().clearRect(0,0,getSize().width,getSize().height);
	repaint();
}

public void drawSmith(Graphics g){

	Font labfont0B = TheFonts.bold12;
	Font labfont1B = TheFonts.bold11;
	Font labfont2B = TheFonts.bold10;
	
	Font labfont0 = TheFonts.sanSerif12;
	Font labfont1 = TheFonts.sanSerif11;
	Font labfont2 = TheFonts.sanSerif10;
	Font symbolfont=TheFonts.symbol12;
	
	g.setFont(symbolfont);
	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.setColor(Color.black);
	g.drawRect(1,3,width-2,height-4);
	
	g.setFont(labfont2);
	g.setColor(Color.red.darker());
	g.drawString("Click and drag mouse",10,height-22);
	g.drawString("to reposition load",12,height-10);
	g.setFont(labfont1B);
	g.drawString("Interactive Smith Chart",10,34);
	//g.setFont(labfont2B);
        g.setColor(Color.black);
        g.drawString("Module 2.6",10,20);
	g.setColor(Color.red.darker());
	//g.drawString("Lossless Transmission Line",10,20);
	g.setFont(labfont0);
	//g.drawString("\u00a9",width-125,height-7);
	g.setFont(labfont1);
	//g.drawString("Amanogawa, 2005",width-110,height-7);
	
	g.setColor(Color.blue);
	if(IsLoadOpen){
	    g.setColor(Color.magenta.darker());
	    MaestroG.subscripter("Open","","",g,12,width-70,height-70);
	    MaestroG.subscripter("Circuit","","",g,12,width-70,height-55);
	}
	else if(IsLoadShort){
	    g.setColor(Color.magenta.darker());
	    MaestroG.subscripter("Short","","",g,12,width-70,height-70);
	    MaestroG.subscripter("Circuit","","",g,12,width-70,height-55);
	}
	else if(IsLoadImaginary){
	    g.setColor(Color.blue);
	    MaestroG.subscripter("Imaginary","","",g,12,width-70,height-70);
	    MaestroG.subscripter("Load","","",g,12,width-70,height-55);
	}
	
	//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);}

	//draw_arcs()
	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);
	        
	if(IsLargerThanOne){
	    g.setFont(labfont1);
	    g.setColor(Color.white);
	    g.drawString("Extended",8,getSize().height-23);
	    g.drawString("Smith Chart",8,getSize().height-10);
	    
	    g.setColor(bgcolor.darker());
	    g.fillRect(getSize().width-65,getSize().height-28,10,10);
	    
	    g.setColor(new Color(252,252,245));
	    g.fillRect(getSize().width-65,getSize().height-13,10,10);
	    g.drawString("|    | < 1.0",getSize().width-50,getSize().height-20);
	    g.drawString("|    | > 1.0",getSize().width-50,getSize().height-5);
    
	    g.drawString(""+GammaSymb,getSize().width-45,getSize().height-20);
	    g.drawString(""+GammaSymb,getSize().width-45,getSize().height-5);
	    
	    g.setFont(labfont1);
	    // draw labels for forbidden region
	    int forbid1, forbid2;
	    forbid1 = 10*getSize().width/100;
	    forbid2 = 80*getSize().width/100;
	
	    g.setColor(Color.white);
	    g.drawString("Forbidden",forbid1,getSize().height/2);
	    g.drawString("Region",forbid1,getSize().height/2+12);
	  
	    g.drawString("Forbidden",forbid2,getSize().height/2);
	    g.drawString("Region",forbid2,getSize().height/2+12);
	}
        
}

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 = 3;
	}
	else{
	    radius=4;
	}
	
	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;
	    //g.setColor(Color.orange);
	    //drawCircle(g,xVSWR,yVSWR,RadiusVSWR);
	    //g.setColor(Color.orange);
	    //drawCircle(g,xVSWR,yVSWR,RadiusVSWR-1);
	}
	else{
	    xVSWR = xCenter - RadiusGamma/2 - Radius1/2 - 1;
	    //g.setColor(Color.orange);
	    //drawCircle(g,xVSWR,yVSWR,RadiusVSWR);
	    //g.setColor(Color.orange);
	    //drawCircle(g,xVSWR,yVSWR,RadiusVSWR-1);
	}
        
        drawCircleThick(g,xVSWR,yVSWR,RadiusVSWR-1,2,Color.orange);
        
}

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=14.0;

    int tmpx, tmpy, tmpx1, tmpy1, tmpx2, tmpy2;
   
    int thickline = 3;
    g.setFont(TheFonts.bold14);
    //For voltage
   
    
        
	if(gammaL){
	    //g.drawLine(xCenter,yCenter,xCenter+(int)(Radius1*GammaZL.Real()),yCenter-(int)(Radius1*GammaZL.Imaginary()));
            //g.drawLine(xCenter+1,yCenter,xCenter+(int)(Radius1*GammaZL.Real())+1,yCenter-(int)(Radius1*GammaZL.Imaginary()));
	    //g.drawLine(xCenter-1,yCenter,xCenter+(int)(Radius1*GammaZL.Real())-1,yCenter-(int)(Radius1*GammaZL.Imaginary()));
	    //g.drawLine(xCenter,yCenter+1,xCenter+(int)(Radius1*GammaZL.Real()),yCenter-(int)(Radius1*GammaZL.Imaginary())+1);
	    //g.drawLine(xCenter,yCenter-1,xCenter+(int)(Radius1*GammaZL.Real()),yCenter-(int)(Radius1*GammaZL.Imaginary())-1);
            
            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){
	    //g.drawLine(xCenter,yCenter,xCenter+(int)(Radius1*GammaZin.Real()),yCenter-(int)(Radius1*GammaZin.Imaginary()));
	    //g.drawLine(xCenter+1,yCenter,xCenter+(int)(Radius1*GammaZin.Real())+1,yCenter-(int)(Radius1*GammaZin.Imaginary()));
	    //g.drawLine(xCenter-1,yCenter,xCenter+(int)(Radius1*GammaZin.Real())-1,yCenter-(int)(Radius1*GammaZin.Imaginary()));
	    //g.drawLine(xCenter,yCenter+1,xCenter+(int)(Radius1*GammaZin.Real()),yCenter-(int)(Radius1*GammaZin.Imaginary())+1);
	    //g.drawLine(xCenter,yCenter-1,xCenter+(int)(Radius1*GammaZin.Real()),yCenter-(int)(Radius1*GammaZin.Imaginary())-1);
            
            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-10));
            tmpy1=yCenter+(int)(-GammaZin.Imaginary()*(Radius1-10));
            tmpx2=xCenter+(int)(GammaZin.Real()*(Radius1-10));
            tmpy2=yCenter+(int)(-GammaZin.Imaginary()*(Radius1-10));
            
            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+1),(double)(yCenter-raio/2+1),(double)(raio-2),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+1),(double)(yCenter-raio/2+1),(double)(raio-2),0.0, (double)(360+start-2), arc_color, transparency);
	
	    }
	
	    //g.setColor(Color.gray);
	    //if(GammaZL.Imaginary() >= 0.0){
		//g.drawArc(xCenter-raio/2+1,yCenter-raio/2+1,raio-2,raio-2,0,start);
	    //}
	    //else{
		//g.drawArc(xCenter-raio/2+1,yCenter-raio/2+1,raio-2,raio-2,0,360+start-2);
	    //}
            
	    //------------------------------------------------------------------------------
	    g.setColor(arc1_color);
            arc_color = arc1_color;
	    if(GammaZL.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+1),(double)(yCenter-raio/2+1),(double)(raio-2),(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+1),(double)(yCenter-raio/2+1),(double)(raio-2),(double)(360+start-1), (double)(-start), arc_color, transparency);
	
	    }
	
	    g.setColor(Color.gray);
	    //if(GammaZL.Imaginary() >= 0.0){
		//g.drawArc(xCenter-raio/2+1,yCenter-raio/2+1,raio-2,raio-2,start,360-start);
	    //}
	    //else{
		//g.drawArc(xCenter-raio/2+1,yCenter-raio/2+1,raio-2,raio-2,360+start-1,-start);
	    //}
            g.drawOval(xCenter-raio/2+1,yCenter-raio/2+1,raio-2,raio-2);
	}
	
	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){
		//g.fillArc(xCenter-raio/2+1,yCenter-raio/2+1,raio-2,raio-2,0,start);
                FillArcTransp(g,(double)(xCenter-raio/2+1),(double)(yCenter-raio/2+1),(double)(raio-2),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+1),(double)(yCenter-raio/2+1),(double)(raio-2),0.0, (double)(360+start-2), arc_color, transparency);
	
	    }
	
	    g.setColor(Color.gray);
	    if(GammaZin.Imaginary() >= 0.0){
		g.drawArc(xCenter-raio/2+1,yCenter-raio/2+1,raio-2,raio-2,0,start);
	    }
	    else{
		g.drawArc(xCenter-raio/2+1,yCenter-raio/2+1,raio-2,raio-2,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+1),(double)(yCenter-raio/2+1),(double)(raio-2),(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+1),(double)(yCenter-raio/2+1),(double)(raio-2),(double)(360+start-1), (double)(-start), arc1_color, transparency);
	
	    }
	
	    g.setColor(Color.gray);
	    //if(GammaZin.Imaginary() >= 0.0){
		//g.drawArc(xCenter-raio/2+1,yCenter-raio/2+1,raio-2,raio-2,start,360-start);
	    //}
	    //else{
		//g.drawArc(xCenter-raio/2+1,yCenter-raio/2+1,raio-2,raio-2,360+start-1,-start);
	    //}
            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;
	double startdouble;
        
	raio = Radius2*2+6;
	raio2 = Radius2*2+12;

	//start=(int)(GammaZL.Arg2(Complex.POLAR_DEGREE));

        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,3,maxc);
	}
	else{
	    drawArcThick(g,(double)(xCenter-raio/2),(double)(yCenter-raio/2),(double)raio,0.0,360.0+startdouble,3,maxc);
	}
}

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

	int start, raio, raio2;
	double startdouble;
        
	raio = Radius2*2+6;
	raio2 = Radius2*2+12;

	//start=(int)(GammaZL.Arg2(Complex.POLAR_DEGREE));

        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+3.0;
            tmpy2 = yCenter;
            tmpx = xCenter + (Radius2+3.0)*Math.cos(GammaZL.Arg2()); 
            tmpy = xCenter - (Radius2+3.0)*Math.sin(GammaZL.Arg2()); 
            tmpx1 = xCenter + (Radius2-3)*Math.cos(GammaZL.Arg2()); 
            tmpy1 = xCenter - (Radius2-3)*Math.sin(GammaZL.Arg2()); 
            tmpx3 = xCenter + (Radius2+10)*Math.cos(GammaZL.Arg2()); 
            tmpy3 = xCenter - (Radius2+10)*Math.sin(GammaZL.Arg2()); 
            
            Len1 = 14.0;
            if((tmpy < yCenter) &&((yCenter-tmpy) < 25)&&(GammaZL.Real()>0.0)){
                Len = Math.abs((yCenter - tmpy)*0.5);
            }
            else{
                Len = 14.0;
            }
            
              //fixed arrow
              drawLineThick(g,tmpx2,tmpy2,tmpx2+Len*Math.cos(angolo),tmpy2-Len*Math.sin(angolo),3,maxc);
              drawLineThick(g,tmpx2,tmpy2,tmpx2+Len*Math.cos(angolo2),tmpy2-Len*Math.sin(angolo2),3,maxc);
             
              //limits
              drawLineThick(g,tmpx2-Len1/2.0,tmpy2,tmpx2+Len1/2.0,tmpy2,3,maxc);
              drawLineThick(g,tmpx1,tmpy1,tmpx3,tmpy3,3,maxc);
              
              //moving arrow - NOT USED - Incomplete
              //drawLineThick(g,tmpx,tmpy,tmpx+Len*Math.cos(angolo-GammaZL.Arg2()),tmpy+Len*Math.sin(angolo),3,maxc);
              //drawLineThick(g,tmpx,tmpy,tmpx+Len*Math.cos(angolo2-GammaZL.Arg2()),tmpy+Len*Math.sin(angolo2),3,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;
        double startdouble;
	
	raio = Radius2*2+6;
	raio2 = Radius2*2+12;

	startdouble = GammaZL.Arg2(Complex.POLAR_DEGREE);
	//Color minc = Color.cyan.darker();
        Color minc = new Color(115,80,255);
	
        if(GammaZL.Imaginary() >= 0.0){
	    drawArcThick(g,(double)(xCenter-raio/2-3),(double)(yCenter-raio/2-3),(double)(raio+6),0.0,startdouble-0.5,3,minc);
            drawArcThick(g,(double)(xCenter-raio/2-3),(double)(yCenter-raio/2-3),(double)(raio+6),0.0,-179.5,3,minc);
	}
	else{
	    drawArcThick(g,(double)(xCenter-raio/2-3),(double)(yCenter-raio/2-3),(double)(raio+6),startdouble,-180.0-startdouble,3,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 = 14.0;
            tmpx = xCenter + (Radius2+3.0)*Math.cos(GammaZL.Arg2()); 
            tmpy = xCenter - (Radius2+3.0)*Math.sin(GammaZL.Arg2()); 
            tmpx2 = xCenter - Radius2 - 5.5;
            tmpy2 = yCenter;
           
            if((tmpy > yCenter) &&((tmpy-yCenter) < 25)&& (GammaZL.Real()<0.0)){
                Len = Math.abs((yCenter - tmpy)*0.5);
            }
            else{
                Len = 14.0;
            }
            
              //Fixed arrow
              drawLineThick(g,tmpx2,tmpy2,tmpx2+Len*Math.cos(angolo),tmpy2+Len*Math.sin(angolo),3,minc);
              drawLineThick(g,tmpx2,tmpy2,tmpx2+Len*Math.cos(angolo2),tmpy2+Len*Math.sin(angolo2),3,minc);
              drawLineThick(g,tmpx2-Len/2.0,tmpy2,tmpx2+Len/2.0,tmpy2,3,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,3,minc);
            drawLineThick(g,tmpx1,tmpy1,tmpx3,tmpy3,3,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 == 518 && y == 280){
		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;
	    }
	    else if(x == 42 && y == 280){
		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;
    	    }
	    else if(Math.pow(tx1,2.0)+Math.pow(ty1,2.0)<=Math.pow(Radius3,2.0) && (x!=518 && y!=280) && (x!=42 && y!=280)){
		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;
	    }
	    else if(Math.pow(tx1,2.0)+Math.pow(ty1,2.0)<=Math.pow(Radius3,2.0) && (y==280)){
		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;
	    }
	    else{
		IsInside = false;
	    }
	}
	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,3,Color.green);
        drawArcThick(g,(double)(xCenter-raio/2),(double)(yCenter-raio/2),raio+1.0,beginAngle,Angle,3,Color.red);
}

public final Complex getZProbe(){
	return ZProbe;
}

public final Complex getYProbe(){
	return YProbe;
}

public final Complex getGammaProbe(){
	return GammaProbe;
}

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

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

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

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

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
public Font symbolfont=TheFonts.symbol12;
public Font labfont=TheFonts.sanSerif12;	
private int width, height;  
private double xpos;  

private Image im;
private Graphics buf;
  
Complex GLoad, Ginput, ZLoad, Zinput, YLoad, Yinput, GL;
public boolean IsLoadOpen, IsLoadShort, IsLoadImaginary, IsLoadRegular, Gamma_plusone, Gamma_minusone;
      
      SmithMan2(int width, int height){
		super();
		setLayout(null);
		mode=1;
		setBackground(bgcolor);
		Font labelfont=TheFonts.sanSerif11;
		//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);
			//p.add(lab[i]);
			//p.add(vlab[i]);
		}
		//add(p);
		//p.setBounds(20,2,width-22,height-2);
		
		//input for ourwidth the number used for the smith man panel
		int ourwidth = 250;
		//80 is 5 pixels smaller than the width of the panel (85)
		int vstep = 80/5;
		
		int vstepinit = 2;
		int xinit = 15; 
		int xinit2 = 18*ourwidth/100;
		
		//lab[0].setBounds(xinit,vstepinit,100,vstep+2);
		////add(lab[0]);
		//lab[1].setBounds(xinit,vstepinit+vstep,100,vstep+2);
		////add(lab[1]);
		//lab[2].setBounds(xinit,vstepinit+2*vstep,100,vstep+2);
		////add(lab[2]);
		//lab[3].setBounds(xinit,vstepinit+3*vstep,100,vstep+2);
		////add(lab[3]);
		//lab[4].setBounds(xinit,vstepinit+4*vstep,100,vstep+2);
		////add(lab[4]);
		
		//vlab[0].setBounds(xinit2,vstepinit,160,vstep+2);
		//add(vlab[0]);
		//vlab[1].setBounds(xinit2,vstepinit+vstep,160,vstep+2);
		//add(vlab[1]);
		//vlab[2].setBounds(xinit2,vstepinit+2*vstep,160,vstep+2);
		//add(vlab[2]);
		//vlab[3].setBounds(xinit2,vstepinit+3*vstep,160,vstep+2);
		//add(vlab[3]);
		//vlab[4].setBounds(xinit2,vstepinit+4*vstep,160,vstep+2);
		//add(vlab[4]);
		Gamma_plusone = false;
		Gamma_minusone = false;
		
	}
	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 = 20;
            int shiftx2 = 15;

            FontMetrics fm;
            g.setFont(TheFonts.serif12);

            String alpha, Ohm, lambda, infinity, Gamma, plusj, minusj, sign;
            g.setFont(symbolfont);
            alpha="\u03b1";
            lambda="\u03bb";
            Ohm="\u03a9";
            infinity="\u221e";
            Gamma="\u0393";
            g.setFont(labfont);

            int vstep = 80/5;
            int vstepinit = 15;
            int xinit = 18 + shiftx;
            int xinit2 = xinit+25;
            int xinit3 = xinit2+70;
            plusj =" + j ";
            minusj=" - j ";

            double Tolerance = 1.0E-10;

	    g.setFont(TheFonts.sanSerif11);
	    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,11,xinit,vstepinit);
		
		if(IsLoadOpen){
		    MaestroG.subscripterInfinityOne("=  ","","","",g,11,xinit2,vstepinit);
		}
		else if(IsLoadShort){
		    MaestroG.subscripter("=  0.0 + j 0.0","","",g,11,xinit2,vstepinit);
		}
		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,11,xinit2,vstepinit);
			stepx = fm.stringWidth("= "+MaestroA.rounder(tempR,6));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("=  0.0","","",g,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,xinit3,vstepinit);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E6 && tempX >= 1.0E3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-3,2)+" x 10","3","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E9 && tempX >= 1.0E6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-6,2)+" x 10","6","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E12 && tempX >= 1.0E9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-9,2)+" x 10","9","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E15 && tempX >= 1.0E12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-12,2)+" x 10","12","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E18 && tempX >= 1.0E15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-15,2)+" x 10","15","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E21 && tempX >= 1.0E18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-18,2)+" x 10","18","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E24 && tempX >= 1.0E21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-21,2)+" x 10","21","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E27 && tempX >= 1.0E24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-24,2)+" x 10","24","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E30 && tempX >= 1.0E27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-27,2)+" x 10","27","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","",g,11,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,11,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,11,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,11,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,11,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,11,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,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-21 && tempX != 0.0){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,11,xinit3,vstepinit);
		    }
		}
		
		
		MaestroG.subscripterSS3(" "+Gamma,"L","",g,11,xinit+1,vstepinit + vstep);
		//MaestroG.superscripter("= "+GLoad.toString(Complex.POLAR_DEGREE,4),"","",g,11,xinit2,vstepinit + 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,"  \u2220 ",""+dtmp2+" \u00ba",g,11,xinit2,vstepinit + vstep);
	
                // 1 following c/o by JANICE
		//MaestroG.subscripterSS3(""+Gamma,"","(d)",g,11,xinit+1,vstepinit + 3*vstep);
		MaestroG.subscripterSS3(" "+Gamma,"d","",g,11,xinit+1,vstepinit + 3*vstep);
		//MaestroG.superscripter("= "+Ginput.toString(Complex.POLAR_DEGREE,4),"","",g,11,xinit2,vstepinit + 3*vstep);
		
                //write the angle with italic L for angle symbol - modify the toString process
                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,11,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("z","","(d)",g,11,xinit,vstepinit + 2*vstep);
		
		/*
		if(Complex.Real(Zinput)==0.0&&Complex.Imaginary(Zinput)< -1.0E130){
		    MaestroG.subscripter("=  "+infinity,"","",g,11,xinit2,vstepinit + 2*vstep);
		}
		else if(Complex.Real(Zinput)==0.0&&Complex.Imaginary(Zinput)==0.0){
		    MaestroG.subscripter("=  0.0 + j 0.0","","",g,11,xinit2,vstepinit + 2*vstep);
		}
		*/
		
		
		if(IsLoadOpen && Gamma_plusone){
		    MaestroG.subscripterInfinityOne("=  ","","","",g,11,xinit2,vstepinit + 2*vstep);
		}
		else if(IsLoadOpen && Gamma_minusone){
		    MaestroG.subscripter("=  0.0 + j 0.0","","",g,11,xinit2,vstepinit + 2*vstep);
		}
		else if(IsLoadShort && Gamma_plusone){
		    MaestroG.subscripterInfinityOne("=  ","","","",g,11,xinit2,vstepinit + 2*vstep);
		}
		else if(IsLoadShort && Gamma_minusone){
		    MaestroG.subscripter("=  0.0 + j 0.0","","",g,11,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,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("= "+MaestroA.rounder(tempR,6));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("=  0.0","","",g,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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;
		    
		    if(tempX < 1.0E3 && tempX >= 1.0E-3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX,6),"","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","",g,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,xinit3,vstepinit+ 2*vstep);
		    }
		}
		
		
		MaestroG.subscripter("y","","(d)",g,11,xinit+2,vstepinit + 4*vstep);
		
		if(Complex.Real(Yinput)==0.0&&Complex.Imaginary(Yinput)<-1.0E130){
		    MaestroG.subscripterInfinityOne("=  ","","","",g,11,xinit2,vstepinit + 4*vstep);
		}
		else if(Complex.Real(Yinput)==0.0&&Complex.Imaginary(Yinput)==0.0){
		    MaestroG.subscripter("=  0.0 + j 0.0","","",g,11,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,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("= "+MaestroA.rounder(tempR,6));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("=  0.0","","",g,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","",g,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,xinit3,vstepinit+ 4*vstep);
		    }
		}
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
		g.setColor(Color.red);
		g.fillOval(4+shiftx2,5,8,8);
		g.setColor(Color.green);
		g.fillOval(4+shiftx2,44*getSize().height/100,8,8);
		//g.setColor(Color.blue);
                g.setColor(new Color(0,150,255));
		g.fillOval(4+shiftx2,82*getSize().height/100,8,8);
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
    	    }
	    if(mode==2){
		g.setColor(Color.black);
		MaestroG.subscripter(" y","L","",g,11,xinit,vstepinit);
		
		if(IsLoadShort){
		    MaestroG.subscripterInfinityOne("=  ","","","",g,11,xinit2,vstepinit);
		}
		else if(IsLoadOpen){
		    MaestroG.subscripter("=  0.0 + j 0.0","","",g,11,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,11,xinit2,vstepinit);
			stepx = fm.stringWidth("= "+MaestroA.rounder(tempR,6));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("=  0.0","","",g,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,xinit3,vstepinit);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E6 && tempX >= 1.0E3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-3,2)+" x 10","3","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E9 && tempX >= 1.0E6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-6,2)+" x 10","6","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E12 && tempX >= 1.0E9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-9,2)+" x 10","9","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E15 && tempX >= 1.0E12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-12,2)+" x 10","12","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E18 && tempX >= 1.0E15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-15,2)+" x 10","15","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E21 && tempX >= 1.0E18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-18,2)+" x 10","18","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E24 && tempX >= 1.0E21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-21,2)+" x 10","21","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E27 && tempX >= 1.0E24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-24,2)+" x 10","24","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E30 && tempX >= 1.0E27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-27,2)+" x 10","27","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","",g,11,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,11,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,11,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,11,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,11,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,11,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,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-21 && tempX != 0.0){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,11,xinit3,vstepinit);
		    }
		}
		
		MaestroG.subscripterSS3(" "+Gamma,"L","",g,11,xinit+1,vstepinit + vstep);
		//MaestroG.superscripter("= "+GLoad.toString(Complex.POLAR_DEGREE,4),"","",g,11,xinit2,vstepinit + vstep);
		
		MaestroG.subscripterSS3(""+Gamma,"","(d)",g,11,xinit+1,vstepinit + 3*vstep);
		//MaestroG.superscripter("= "+Ginput.toString(Complex.POLAR_DEGREE,4),"","",g,11,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,11,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,11,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,11,xinit+2,vstepinit + 2*vstep);
		
		if(IsLoadOpen && Gamma_minusone){
		    MaestroG.subscripterInfinityOne("=  ","","","",g,11,xinit2,vstepinit + 2*vstep);
		}
		else if(IsLoadOpen && Gamma_plusone){
		    MaestroG.subscripter("=  0.0 + j 0.0","","",g,11,xinit2,vstepinit + 2*vstep);
		}
		else if(IsLoadShort && Gamma_minusone){
		    MaestroG.subscripterInfinityOne("=  ","","","",g,11,xinit2,vstepinit + 2*vstep);
		}
		else if(IsLoadShort && Gamma_plusone){
		    MaestroG.subscripter("=  0.0 + j 0.0","","",g,11,xinit2,vstepinit + 2*vstep);
		}
				
		//if(Complex.Real(Yinput)==0.0&&Complex.Imaginary(Yinput)<-1.0E130){
		  //  MaestroG.subscripter("=  "+infinity,"","",g,11,xinit2,vstepinit + 2*vstep);
		//}
		//else if(Complex.Real(Yinput)==0.0&&Complex.Imaginary(Yinput)==0.0){
		  //  MaestroG.subscripter("=  0.0 + j 0.0","","",g,11,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,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("= "+MaestroA.rounder(tempR,6));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("=  0.0","","",g,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","",g,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,xinit3,vstepinit+ 2*vstep);
		    }
		}
		
		
		MaestroG.subscripter("z","","(d)",g,11,xinit,vstepinit + 4*vstep);
		
		if(IsLoadOpen && Gamma_plusone){
		    MaestroG.subscripterInfinityOne("=  ","","","",g,11,xinit2,vstepinit + 4*vstep);
		}
		else if(IsLoadOpen && Gamma_minusone){
		    MaestroG.subscripter("=  0.0 + j 0.0","","",g,11,xinit2,vstepinit + 4*vstep);
		}
		else if(IsLoadShort && Gamma_plusone){
		    MaestroG.subscripterInfinityOne("=  ","","","",g,11,xinit2,vstepinit + 4*vstep);
		}
		else if(IsLoadShort && Gamma_minusone){
		    MaestroG.subscripter("=  0.0 + j 0.0","","",g,11,xinit2,vstepinit + 4*vstep);
		}
		
		//if(Complex.Real(Zinput)==0.0&&Complex.Imaginary(Zinput)<-1.0E130){
		  //  MaestroG.subscripter("=  "+infinity,"","",g,11,xinit2,vstepinit + 4*vstep);
		//}
		//else if(Complex.Real(Zinput)==0.0&&Complex.Imaginary(Zinput) == 0.0){
		  //  MaestroG.subscripter("=  0.0 + j 0.0","","",g,11,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,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("= "+MaestroA.rounder(tempR,6));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("=  0.0","","",g,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","",g,11,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,11,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,11,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,11,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,11,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,11,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,11,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,11,xinit3,vstepinit+ 4*vstep);
		    }
		}
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		                
                g.setColor(Color.yellow);
		g.fillOval(4+shiftx2,5,8,8);
		//g.setColor(Color.blue);
                g.setColor(new Color(0,150,255));
		g.fillOval(4+shiftx2,44*getSize().height/100,8,8);
		g.setColor(Color.green);
		g.fillOval(4+shiftx2,82*getSize().height/100,8,8);
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
	    }
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                g.setColor(Color.black);
		g.drawOval(4+shiftx2,5,8,8);
		g.drawOval(4+shiftx2,44*getSize().height/100,8,8);
		g.drawOval(4+shiftx2,82*getSize().height/100,8,8);
                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 = 20;
//private final Color bcolor = new Color(216,216,191);
private final Color bcolor = new Color(236,236,236);

    SmithProbe2(int width, int height){
	super();
	setLayout(null);
	setBackground(bcolor);
	Font labfont = TheFonts.sanSerif11;
	Panel p = new Panel();
	//p.setLayout(new GridLayout(2,1));
	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(20+shiftx,0,100,15);
	lab[5].setBounds(120+shiftx,0,100,15);
	lab[1].setBounds(20+shiftx,14,200,15);
	lab[2].setBounds(20+shiftx,31,200,15);
	lab[3].setBounds(20+shiftx,47,200,15);
	lab[4].setBounds(25+shiftx,61,200,15);
	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");
	    
	    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");
	    
	    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;
Font symbolfont=TheFonts.symbol12;
private Image im;
private Graphics buf;
private int shiftx = 20;
SmithAuxiliary(){
    
    Gamma="\u0393";
    setLayout(null);
    setBackground(bgcolor);
	
    cgamma = new CheckboxGroup();
    gammaL = new Checkbox("Load",cgamma,true);
    gammaD = new Checkbox("Cursor",cgamma,false);
	
    //show_gamma = new Checkbox("Show "+Gamma,null,true);
    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);
		
    add(show_SWR);
    add(show_max);
    add(show_min);
    add(show_gamma);
    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(5+shiftx,5,170,20);
    show_max.setBounds(5+shiftx,40,170,20);
    show_min.setBounds(5+shiftx,75,170,20);
    show_gamma.setBounds(5+shiftx,113,75,20);
    gammaL.setBounds(100+shiftx,113,70,20);
    gammaD.setBounds(170+shiftx,113,80,20);
    
    /*
    show_SWR.setBounds(5+shiftx,5,170,20);
    show_max.setBounds(5+shiftx,40,170,20);
    show_min.setBounds(5+shiftx,75,170,20);
    show_gamma.setBounds(5+shiftx,133,60,20);
    gammaL.setBounds(100+shiftx,133,60,20);
    gammaD.setBounds(170+shiftx,133,70,20);
    */

}

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;
	Font symbolfont=TheFonts.symbol14;
        Font normalfont = TheFonts.sanSerif14;
        Font normalfontSerif = TheFonts.serif14;
        g.setFont(symbolfont);
		Gamma="\uu0393"; 
	g.setFont(normalfont);
	g.setColor(Color.black);
	//g.drawString(""+Gamma,60,127);
	MaestroG.subscripterSerif(""+Gamma,"","",g,14,80+shiftx,129);
        
        // CHANGE - USED RECTANGLES INSTEAD OF LINES
        int shiftx2 = 60;
        int xstart = 160;
        int xend = 200;
        
	if(show_SWR.getState()){
	    g.setColor(Color.white);
            g.fillRect(xstart+shiftx, 12, shiftx2, 8);
	    g.setColor(Color.orange);
            g.fillRect(xstart+shiftx, 13, shiftx2, 6);
	}
	else{
	    g.setColor(bgcolor);
            g.fillRect(xstart+shiftx-1, 11, shiftx2+2, 10);
	}
	
	if(show_max.getState()){
	    
            g.setColor(Color.gray.brighter());
            g.fillRect(xstart+shiftx, 47, shiftx2, 7);
	    
            g.setColor(new Color(255,210,0).brighter());
	    g.fillRect(xstart+shiftx, 48, shiftx2, 5);
	}
	else{
	    g.setColor(bgcolor);
	    g.fillRect(xstart+shiftx-1, 46, shiftx2+2, 9);
	}
	
	
	if(show_min.getState()){
	    //g.setColor(Color.cyan.darker());
            
	    g.setColor(Color.white);
            g.fillRect(xstart+shiftx, 82, shiftx2, 8);
	    g.setColor(new Color(115,80,255));
	    g.fillRect(xstart+shiftx, 83, shiftx2, 6);
	}
	else{
	    g.setColor(bgcolor);
            g.fillRect(xstart+shiftx-1, 81, shiftx2+2, 10);
	}
}
    
    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 = 20;

private Image im;
private Graphics buf;

SmithControls2(){

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

	//imp = new Checkbox("Impedance",cgrid,true);
	//adm = new Checkbox("Admittance",cgrid,false);
	
	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);
	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);
	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);

        /*        
	//imp.setBounds(5+shiftx,1,100,20);
	//adm.setBounds(125+shiftx,1,100,20);
	swr.setBounds(5+shiftx,21-10,100,20);
	//swrline.setBounds(125+shiftx,21-10,100,20);
	swrline.setBounds(125+shiftx,21-10,110,20);
	showcurves.setBounds(5+shiftx,41-10,100,20);
	chart.setBounds(5+shiftx,61-10,100,20);
	//gensmith.setBounds(5,55,150,20);
	inverse.setBounds(125+shiftx,41-10,100,20);
	smoothplot.setBounds(125+shiftx,61-10,100,20);
        */

	swr.setBounds(5+shiftx,21-10,120,20);
	swrline.setBounds(125+shiftx,21-10,130,20);
	showcurves.setBounds(5+shiftx,41-10,120,20);
	chart.setBounds(5+shiftx,61-10,120,20);
	inverse.setBounds(125+shiftx,41-10,120,20);
	smoothplot.setBounds(125+shiftx,61-10,120,20);

	
	//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;
