//Auxiliary5.java
//author Umberto Ravaioli, 2005, 2010, 2019

import java.awt.*;
import java.awt.event.*;

//import Trans_State;
public class Auxiliary5 extends Canvas implements MouseListener{
	
	private Trans_State state;
	private Image im;
	private Graphics buf;
	private static final Font labfont = TheFonts.bold10;
	private static final Color bgcolor = Color.white;
	private static final Color bgcolor2 = new Color(236,236,236);
	private static final Color ccolor1 = new Color(50,204,153);
	
        //private static final double epsilon0 = 8.8541878176E-12; // Units: F/m
        // Approximate epsilon for phase velocity 3 x 10^8 m/s
        private static final double epsilon0 = 8.841941286E-12; //8.8541878176E-12; //Units: F/m 
	
        private static final double mu0 = 1.25663706144E-6; //      Units H/m
	private static final double light_velocity = Math.sqrt(1.0/(epsilon0*mu0)); //  Units m/s
	
	private static final Font normalfont = TheFonts.serif14;
	private static final Font normalfont2 = TheFonts.sanSerif12;
        
        private static final Font subfont    = TheFonts.sanSerif10;
	private static final Font symbolfont = TheFonts.symbol14;
	private static String alpha, Ohm, lambda, infinity, Gamma, epsilon;
        private static String plusj, minusj, sign, plusr, minusr, signr;
		
	private boolean IsFocusOn, IsTopoOn, IsDark;
        
	public Auxiliary5(Trans_State state){
		super();
		this.state = state;
		setBackground(bgcolor);
		this.addMouseListener(this);
		IsFocusOn = false;
		IsDark = true;
	}

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

	public void paint(Graphics g){
		if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawZ(buf);
	    }
	    else{
		drawZ(buf);
	    }
	    g.drawImage(im,0,0,null);	
			//drawZ(g);
		
	}
	
	private void drawZ(Graphics g){ 
            Font scalefont = (new Font("SanSerif",Font.PLAIN,state.font12));
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
		int xd, yd, dx, dy, x, y, dxx, dyy, stepx;
                double tempR = 0.0; double tempX = 0.0;
                boolean Gamma_plusone, Gamma_minusone;
		
                g.clearRect(0,0,getSize().width,getSize().height);
		g.setColor(Color.black);
                //g.drawRect(0,0,getSize().width-1,getSize().height-1);
                
		FontMetrics fm = g.getFontMetrics();
		
		alpha="\u03b1";
		lambda="\u03bb";
		Ohm="\u03a9";
		infinity="\u221e";
		Gamma="\uu0393"; 
		epsilon="\u03b5";
                
                plusj =" + j ";
		minusj=" - j ";
                plusr ="";
                minusr =" - ";
                		
	    Gamma_plusone = false;
            Gamma_minusone = false;
	    Complex tempc;
	    x = state.s10;
	    y = state.s20;
	    dx = state.s15;
	    dxx = 0;
	    dy = state.s15;
	    dyy = dy;
	    
            g.setFont(scalefont);
	    fm = g.getFontMetrics();
	    
            g.clearRect(0,0,getSize().width,getSize().height);
	    
            double testmag = Complex.Magnitude(state.Zin);
            Complex Zmag = state.Zin;

            double testmag2 = Complex.Magnitude(state.Yin);
            Complex Ymag = state.Yin;
            
                if(Complex.Real(state.Gammain) > 0.999999 && Math.abs(Complex.Imaginary(state.Gammain)) < 0.000001){
		    Gamma_plusone = true;
		    Gamma_minusone = false;
		}
		else if(Complex.Real(state.Gammain) < -0.999999 && Math.abs(Complex.Imaginary(state.Gammain)) < 0.000001){
		    Gamma_plusone = false;
		    Gamma_minusone = true;
		}
		else{
		    Gamma_plusone = false;
		    Gamma_minusone = false;
		}
	    
            g.setColor(Color.black); 
            	
                if(state.use_Zchart){
                    MaestroG.subscripter("Z","","(d)",g,state.font12,x+dx,y);
                }
                else{
                    MaestroG.subscripter("Y","","(d)",g,state.font12,x+dx,y);
                }
                int xinit2, xinit3;
                xinit2 = x+dxx+state.s45;
                
                if(state.use_Zchart){
                
                    if((state.IsLoadOpen || state.IsLoadImaginary) && Gamma_plusone){
                        MaestroG.subscripterInfinityThree("= ","","","  "+Ohm,g,state.font12,xinit2,y);

                        g.drawString("(Open Circuit)  " ,xinit2+state.s60,y);
                        //y+=dy;
                    }
                    else if((state.IsLoadOpen || state.IsLoadImaginary) && Gamma_minusone){
                        MaestroG.subscripterSanSym2("= 0.0 + j 0.0","","  "+Ohm,g,state.font12,xinit2,y);
                       //y+=dy;
                    }
                    else if((state.IsLoadShort || state.IsLoadImaginary) && Gamma_plusone){
                        //MaestroG.subscripter("= ","",""+infinity,g,state.font12,xinit2,y);
                        MaestroG.subscripterInfinityThree("= ","","","  "+Ohm,g,state.font12,xinit2,y);
                        g.drawString("(Open Circuit)  " ,xinit2+state.s60,y);
                        //y+=dy;
                    }
                    else if((state.IsLoadShort || state.IsLoadImaginary) && Gamma_minusone){
                        MaestroG.subscripterSanSym2("= 0.0 + j 0.0","","  "+Ohm,g,state.font12,xinit2,y);
                        //y+=dy;
                    }

                    else{

                        tempR=0.0; tempX=0.0;
                        stepx = 0;

                        if(Complex.Imaginary(state.Zin) >= 0.0){sign = plusj;}
                        else{sign = minusj;}

                        if(state.IsLoadImaginary || state.IsLoadOpen || state.IsLoadShort){
                            tempR = 0.0;
                        }
                        else if(state.IsLoadRegular){
                            tempR = state.Zin.Real();
                        }

                        if(tempR < 1.0E3 && tempR >= 1.0E-3){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR,6),"","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR,6));
                        }
                        else if(tempR == 0.0){
                            MaestroG.superscripter2("= 0.0","","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= 0.0 ");
                        }
                        else if(tempR < 1.0E6 && tempR >= 1.0E3){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-3,2)+" x 10","3","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-3,2)+"x 10 3");
                        }
                        else if(tempR < 1.0E9 && tempR >= 1.0E6){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-6,2)+" x 10","6","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-6,2)+"x 10 6");
                        }
                        else if(tempR < 1.0E12 && tempR >= 1.0E9){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-9,2)+" x 10","9","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-9,2)+"x 10 9");
                        }
                        else if(tempR < 1.0E15 && tempR >= 1.0E12){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-12,2)+" x 10","12","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-12,2)+"x 10 12");
                        }
                        else if(tempR < 1.0E18 && tempR >= 1.0E15){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-15,2)+" x 10","15","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-15,2)+"x 10 15");
                        }
                        else if(tempR < 1.0E21 && tempR >= 1.0E18){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-18,2)+" x 10","18","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-18,2)+"x 10 18");
                        }
                        else if(tempR < 1.0E24 && tempR >= 1.0E21){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-21,2)+" x 10","21","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-21,2)+"x 10 21");
                        }
                        else if(tempR < 1.0E27 && tempR >= 1.0E24){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-24,2)+" x 10","24","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-24,2)+"x 10 24");
                        }
                        else if(tempR < 1.0E30 && tempR >= 1.0E27){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-27,2)+" x 10","27","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-27,2)+"x 10 27");
                        }
                        else if(tempR >= 1.0E30){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-30,2)+" x 10","30","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-30,2)+"x 10 30");
                        }
                        else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E6,2)+" x 10","-6","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E6,2)+"x 10 -6");
                        }
                        else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E9,2)+" x 10","-9","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E9,2)+"x 10 -9");
                        }
                        else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E12,2)+" x 10","-12","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E12,2)+"x 10 -12");
                        }
                        else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E15,2)+" x 10","-15","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E15,2)+"x 10 -15");
                        }
                        else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E18,2)+" x 10","-18","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E18,2)+"x 10 -18");
                        }
                        else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E21,2)+" x 10","-21","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E21,2)+"x 10 -21");
                        }
                        else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E24,2)+" x 10","-24","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E24,2)+"x 10 -24");
                        }
                        else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E27,2)+" x 10","-27","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E27,2)+"x 10 -27");
                        }
                        else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E30,2)+" x 10","-30","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E30,2)+"x 10 -30");
                        }
                        else if(tempR < 1.0E-30 && tempR != 0.0){
                            MaestroG.superscripter2("= 0.0","","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= 0.0");
                        }


                        if(Complex.Imaginary(state.ZL)==0.0 && (state.xpos == 0.25 || state.xpos == 0.5 || state.xpos == 0.75 || state.xpos==1.0)){
                            tempX = 0.0;
                        }
                        else if(Math.abs(Complex.Imaginary(state.Gammain)) < 1.0e-8){
                            tempX = 0.0;
                        }
                        else{
                            tempX = Math.abs(state.Zin.Imaginary());
                        }

                        xinit3 = xinit2+stepx;

                        if(tempX < 1.0E3 && tempX >= 1.0E-3){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX,6),"","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX == 0.0){
                            MaestroG.superscripter2(" + j 0.0","","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E6 && tempX >= 1.0E3){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-3,2)+" x 10","3","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E9 && tempX >= 1.0E6){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-6,2)+" x 10","6","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E12 && tempX >= 1.0E9){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-9,2)+" x 10","9","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E15 && tempX >= 1.0E12){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-12,2)+" x 10","12","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E18 && tempX >= 1.0E15){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-15,2)+" x 10","15","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E21 && tempX >= 1.0E18){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-18,2)+" x 10","18","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E24 && tempX >= 1.0E21){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-21,2)+" x 10","21","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E27 && tempX >= 1.0E24){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-24,2)+" x 10","24","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E30 && tempX >= 1.0E27){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-27,2)+" x 10","27","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX >= 1.0E30){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-3 && tempX >= 1.0E-6){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E6,2)+" x 10","-6","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-6 && tempX >= 1.0E-9){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E9,2)+" x 10","-9","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-9 && tempX >= 1.0E-12){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E12,2)+" x 10","-12","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-12 && tempX >= 1.0E-15){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E15,2)+" x 10","-15","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-15 && tempX >= 1.0E-18){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E18,2)+" x 10","-18","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-18 && tempX >= 1.0E-21){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E21,2)+" x 10","-21","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-21 && tempX >= 1.0E-24){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-24 && tempX >= 1.0E-27){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E27,2)+" x 10","-27","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-27 && tempX >= 1.0E-30){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E30,2)+" x 10","-30","  "+Ohm,g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-30 && tempX != 0.0){
                            MaestroG.superscripter2(sign+" 0.0","","  "+Ohm,g,state.font12,xinit3,y);
                        }
                    }
                }
                else{
                    if((state.IsLoadOpen || state.IsLoadImaginary) && Gamma_minusone){
                        MaestroG.subscripterInfinityThree("= ","","","  S",g,state.font12,xinit2,y);

                        g.drawString("(Short Circuit)  " ,xinit2+state.s60,y);
                        //y+=dy;
                    }
                    else if((state.IsLoadOpen || state.IsLoadImaginary) && Gamma_plusone){
                        MaestroG.subscripterSanSym2("= 0.0 + j 0.0","","  S",g,state.font12,xinit2,y);
                       //y+=dy;
                    }
                    else if((state.IsLoadShort || state.IsLoadImaginary) && Gamma_minusone){
                        //MaestroG.subscripter("= ","",""+infinity,g,state.font12,xinit2,y);
                        MaestroG.subscripterInfinityThree("= ","","","  S",g,state.font12,xinit2,y);
                        g.drawString("(Short Circuit)  " ,xinit2+state.s60,y);
                        //y+=dy;
                    }
                    else if((state.IsLoadShort || state.IsLoadImaginary) && Gamma_plusone){
                        MaestroG.subscripterSanSym2("= 0.0 + j 0.0","","  S",g,state.font12,xinit2,y);

                        //y+=dy;
                    }

                    else{

                        tempR=0.0; tempX=0.0;
                        stepx = 0;

                        if(Complex.Imaginary(state.Zin) <= 0.0){sign = plusj;}
                        else{sign = minusj;}

                        if(state.IsLoadImaginary || state.IsLoadOpen || state.IsLoadShort){
                            tempR = 0.0;
                        }
                        else if(state.IsLoadRegular){
                            tempR = state.Yin.Real();
                        }

                        if(tempR < 1.0E3 && tempR >= 1.0E-3){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR,6),"","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR,6));
                        }
                        else if(tempR == 0.0){
                            MaestroG.superscripter2("= 0.0","","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= 0.0 ");
                        }
                        else if(tempR < 1.0E6 && tempR >= 1.0E3){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-3,2)+" x 10","3","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-3,2)+"x 10 3");
                        }
                        else if(tempR < 1.0E9 && tempR >= 1.0E6){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-6,2)+" x 10","6","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-6,2)+"x 10 6");
                        }
                        else if(tempR < 1.0E12 && tempR >= 1.0E9){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-9,2)+" x 10","9","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-9,2)+"x 10 9");
                        }
                        else if(tempR < 1.0E15 && tempR >= 1.0E12){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-12,2)+" x 10","12","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-12,2)+"x 10 12");
                        }
                        else if(tempR < 1.0E18 && tempR >= 1.0E15){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-15,2)+" x 10","15","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-15,2)+"x 10 15");
                        }
                        else if(tempR < 1.0E21 && tempR >= 1.0E18){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-18,2)+" x 10","18","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-18,2)+"x 10 18");
                        }
                        else if(tempR < 1.0E24 && tempR >= 1.0E21){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-21,2)+" x 10","21","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-21,2)+"x 10 21");
                        }
                        else if(tempR < 1.0E27 && tempR >= 1.0E24){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-24,2)+" x 10","24","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-24,2)+"x 10 24");
                        }
                        else if(tempR < 1.0E30 && tempR >= 1.0E27){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-27,2)+" x 10","27","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-27,2)+"x 10 27");
                        }
                        else if(tempR >= 1.0E30){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E-30,2)+" x 10","30","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-30,2)+"x 10 30");
                        }
                        else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E6,2)+" x 10","-6","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E6,2)+"x 10 -6");
                        }
                        else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E9,2)+" x 10","-9","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E9,2)+"x 10 -9");
                        }
                        else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E12,2)+" x 10","-12","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E12,2)+"x 10 -12");
                        }
                        else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E15,2)+" x 10","-15","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E15,2)+"x 10 -15");
                        }
                        else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E18,2)+" x 10","-18","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E18,2)+"x 10 -18");
                        }
                        else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E21,2)+" x 10","-21","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E21,2)+"x 10 -21");
                        }
                        else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E24,2)+" x 10","-24","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E24,2)+"x 10 -24");
                        }
                        else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E27,2)+" x 10","-27","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E27,2)+"x 10 -27");
                        }
                        else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
                            MaestroG.superscripter2("= "+MaestroA.rounder(tempR*1.0E30,2)+" x 10","-30","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E30,2)+"x 10 -30");
                        }
                        else if(tempR < 1.0E-30 && tempR != 0.0){
                            MaestroG.superscripter2("= 0.0","","",g,state.font12,xinit2,y);
                            stepx = fm.stringWidth("= 0.0");
                        }


                        if(Complex.Imaginary(state.YL)==0.0 && (state.xpos == 0.25 || state.xpos == 0.5 || state.xpos == 0.75 || state.xpos==1.0)){
                            tempX = 0.0;
                        }
                        else if(Math.abs(Complex.Imaginary(state.Gammain)) < 1.0e-8){
                            tempX = 0.0;
                        }
                        else{
                            tempX = Math.abs(state.Yin.Imaginary());
                        }

                        xinit3 = xinit2+stepx;

                        if(tempX < 1.0E3 && tempX >= 1.0E-3){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX,6),"","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX == 0.0){
                            MaestroG.superscripter2(" + j 0.0","","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E6 && tempX >= 1.0E3){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-3,2)+" x 10","3","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E9 && tempX >= 1.0E6){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-6,2)+" x 10","6","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E12 && tempX >= 1.0E9){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-9,2)+" x 10","9","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E15 && tempX >= 1.0E12){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-12,2)+" x 10","12","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E18 && tempX >= 1.0E15){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-15,2)+" x 10","15","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E21 && tempX >= 1.0E18){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-18,2)+" x 10","18","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E24 && tempX >= 1.0E21){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-21,2)+" x 10","21","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E27 && tempX >= 1.0E24){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-24,2)+" x 10","24","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E30 && tempX >= 1.0E27){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-27,2)+" x 10","27","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX >= 1.0E30){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-3 && tempX >= 1.0E-6){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E6,2)+" x 10","-6","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-6 && tempX >= 1.0E-9){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E9,2)+" x 10","-9","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-9 && tempX >= 1.0E-12){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E12,2)+" x 10","-12","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-12 && tempX >= 1.0E-15){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E15,2)+" x 10","-15","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-15 && tempX >= 1.0E-18){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E18,2)+" x 10","-18","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-18 && tempX >= 1.0E-21){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E21,2)+" x 10","-21","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-21 && tempX >= 1.0E-24){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-24 && tempX >= 1.0E-27){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E27,2)+" x 10","-27","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-27 && tempX >= 1.0E-30){
                            MaestroG.superscripter2(sign+""+MaestroA.rounder(tempX*1.0E30,2)+" x 10","-30","  S",g,state.font12,xinit3,y);
                        }
                        else if(tempX < 1.0E-30 && tempX != 0.0){
                            MaestroG.superscripter2(sign+" 0.0","","  S",g,state.font12,xinit3,y);
                        }
                    }
                }

                y+=dyy;
                //MaestroG.subscripter("d","","",g,state.font12,x+dxx+state.s28,y);
                MaestroG.subscripterSerif("d = "+MaestroA.rounder(state.xpos,6)+" "+lambda,"","",g,state.font12,x+dx,y+state.s2);
        }
	
	public void mouseClicked(MouseEvent evt){
	    if(IsFocusOn){
		IsFocusOn = false;
		repaint();
	    }
	
	    else{
		IsFocusOn = true;
		repaint();
	    }
    
	}
	
	public void setDark(boolean IsDark){
	    this.IsDark = IsDark;
	}
    
	public void mouseEntered(MouseEvent evt){
	    IsTopoOn = true;
	    repaint();
	}
	public void mouseExited(MouseEvent evt){
	    IsTopoOn = false;
	    repaint();
	}
	public void mousePressed(MouseEvent evt){}
	public void mouseReleased(MouseEvent evt){}
    
}//End of CircuitCanvs

