/* NewGuideCanvas.java*/
/*
 * Plots the diagram for the microstrip 
 * author: Umberto Ravaioli
 * version 1.0 - Copyright: Amanogawa.com - All Rights Reserved
 */

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.lang.*;
//import maestro.lib.math.*;
//import maestro.lib.graphics.*;

public class NewGuideCanvas extends Canvas implements MouseListener{
    //private static final Color bgcolor = new Color(236,236,221);
    private static final Color bgcolor = Color.white;
    private static final Color medium1Color = Color.yellow;
    private static final Color medium2Color = Color.cyan;
    private static final int LeftMargin=10, RightMargin=10, TopMargin=10, BottomMargin=10;
    //private static final Font labfont = new Font("SanSerif",Font.PLAIN,10);
    //private static final Font symbolfont = new Font("Serif",Font.PLAIN,12);
    public static Font labfont;
    public static Font symbolfont;
    private double frequency, a, b, w, epsilon_r, epsilon_r0, mu_r, phase_velocity, phase_velocity0;
    private double a_maximum, w_maximum, b_maximum, sigma2, sigma_metal;
    
    //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 boolean IsWarningOn1, IsWarningOn2;
    private boolean IsSafetyOn, IsPrintSafetyOn;
    
    private Image im;
    private Graphics buf;
    private String stmp;
    private double temp;
    private boolean IsFocusOn;
    
    public NewGuideCanvas(){
	super();
	IsFocusOn = false;
	setBackground(bgcolor);
	//Listeners
	this.addMouseListener(this);
	a = 0.635; // mm
	a_maximum = 2.0; //mm
	b = 0.005; //mm
	b_maximum = 0.01; //mm
	w = 0.6; //mm
	w_maximum = 5.0; //mm
	epsilon_r = 9.8;
	epsilon_r0 = 1.0;
	mu_r = 1.0;
	frequency = 1.0E9;
	sigma2 = 0.0;
	sigma_metal = 5.8E7 ;
	IsWarningOn1 = false;
	IsWarningOn2 = false;
	IsSafetyOn = false;
	IsPrintSafetyOn = false;
    }

    public void drawCanvas(Graphics g){
	g.clearRect(0,0,getSize().width,getSize().height);
	g.setColor(Color.black);
	
 	//if(IsFocusOn){drawBackLabels(g);}
	drawAxis(g);
	drawGuide(g);
    }
    
    private void drawAxis(Graphics g){
	double theta = Math.PI/4.0;
	int ArrowPos1, ArrowPos2;
	int Lsize = 30;
	Graphics2D g2d = (Graphics2D)g;
        
        g.setColor(Color.black);
	//Vertical axis
	//g.drawLine(LeftMargin,getSize().height-BottomMargin,LeftMargin,getSize().height-BottomMargin-Lsize);
	//MaestroG.drawArrow(LeftMargin,getSize().height-BottomMargin-Lsize,5,g);
	//Horizontal axis
	//g.drawLine(LeftMargin,getSize().height-BottomMargin,LeftMargin+Lsize,getSize().height-BottomMargin);
	//Draw up arrow
	//MaestroG.drawArrow(LeftMargin+Lsize,getSize().height-BottomMargin,7,g);
	//Third axis
	//g.drawLine(LeftMargin,getSize().height-BottomMargin,
	//	   LeftMargin+(int)(Lsize*Math.cos(theta)),getSize().height-BottomMargin-(int)(Lsize*Math.sin(theta)));
	
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
        //g.setColor(Color.black);
	//	// draw line
	//	int tipH = -25;
	//	int horizH = LeftMargin;
	//	int verticH = getSize().height-BottomMargin;
	//	//g.drawLine(horizH,verticH,horizH-tipH,verticH+tipH);
	//	//draw oblique arrow head
	//	Polygon pH = new Polygon();
	//	pH.addPoint(horizH - tipH,verticH + tipH);
	//	pH.addPoint(horizH - (tipH + 2),verticH +(tipH + 6));
	//	pH.addPoint(horizH - (tipH + 6),verticH + (tipH + 2));
	//	//g.drawPolygon(pH);
	//	//g.fillPolygon(pH);
        //MaestroG.drawArrow(LeftMargin+(int)(Lsize*Math.cos(theta)),getSize().height-BottomMargin-(int)(Lsize*Math.sin(theta)),9,g);
	
        //Draw labels for axes
	//g.setFont(new Font("SanSerif",Font.PLAIN,12));
        g.setFont(labfont.deriveFont(12F));
	//FontMetrics fm = g.getFontMetrics();
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        //
	//g.drawString("x",LeftMargin-fm.stringWidth("x")/2,getSize().height-BottomMargin-Lsize-10);
	//g.drawString("y",LeftMargin+Lsize+10+fm.stringWidth("y"),
	//	getSize().height-BottomMargin+fm.getHeight()/3);
	//
	//g.drawString("z",LeftMargin+(int)(Lsize*Math.cos(theta))+10,getSize().height-BottomMargin-(int)(Lsize*Math.sin(theta))+2);
    }
    
    private void drawGuide(Graphics g){    
	int xLeft, xRight, xCenter, xRef;
	int yBottom, yTop, width, thick;
	int slabDH;//Thickness of the slab
	int slabDepth; //Depth of the slab
	double theta = Math.PI/6.0;
	int widthmax = 100;
	int amax = (int)(a_maximum/w_maximum*widthmax);
	int thickmax = 5;
	
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
	width = (int)(w/w_maximum*widthmax)+1;
	if(w==0.0){
	    width = 0;
	}
	thick = (int)(b/b_maximum*thickmax)+1;
	if(b==0.0){
	    thick = 0;
	}
	
	Color MetalColor1 = Color.lightGray;
	Color MetalColor2 = new Color(220,220,220);
	Color MetalColor3 = new Color(235,235,235);
	
	xLeft = LeftMargin+20;
	xRight = getSize().width - RightMargin-80;
	xCenter = (xRight+xLeft)/2;
	xRef = xCenter-width/2;
	yBottom = TopMargin+60+(int)(a/a_maximum*amax)+1;
	yTop = TopMargin+60;
	slabDH = 5;
	slabDepth = 90;
	//System.out.println(width+"   "+w_maximum+"   "+(yBottom-yTop));
	
	int Botref = 80;
	if((yBottom - yTop)<(Botref-10) ){	  
	// Draw core of waveguide
	    g.setColor(new Color(255,255,240));
		Polygon s3 = new Polygon();
		    s3.addPoint(xRight+1,yTop);
		    s3.addPoint(xRight+1,yBottom);
		    s3.addPoint(xRight+(int)(slabDepth*Math.cos(theta)),yBottom-(int)(slabDepth*Math.sin(theta)));
		    s3.addPoint(xRight+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta)));
		    g.fillPolygon(s3);
	    g.setColor(new Color(235,235,220));
		Polygon s4 = new Polygon();
		    s4.addPoint(xLeft,yTop);
		    s4.addPoint(xLeft,yBottom);
		    s4.addPoint(xRight,yBottom);
		    s4.addPoint(xRight,yTop);
		    g.fillPolygon(s4);
		    
	    //Draw Top Waveguide Substrate
	    g.setColor(new Color(255,255,230));
		Polygon s6 = new Polygon();
		  s6.addPoint(xLeft,yTop);
		  s6.addPoint(xRight,yTop);
		  s6.addPoint(xRight+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta)));
		  s6.addPoint(xLeft+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta)));
		  g.fillPolygon(s6);
	    //Draw metals
	    g.setColor(MetalColor1);
		g.fillRect(xLeft,yBottom,xRight-xLeft,10);
	    g.setColor(MetalColor3);
		Polygon s2 = new Polygon();
		  s2.addPoint(xRight+1,yBottom);
		  s2.addPoint(xRight+1,yBottom+10);
		  s2.addPoint(xRight+(int)(slabDepth*Math.cos(theta)),yBottom-(int)(slabDepth*Math.sin(theta))+10);
		  s2.addPoint(xRight+(int)(slabDepth*Math.cos(theta)),yBottom-(int)(slabDepth*Math.sin(theta)));
		  g.fillPolygon(s2);
	    if(width > 0){
	    g.setColor(MetalColor1);
		g.fillRect(xRef,yTop-thick,width,thick);
	    g.setColor(MetalColor3);
		Polygon s1 = new Polygon();
		  s1.addPoint(xRef+width,yTop-thick);
		  s1.addPoint(xRef+width,yTop);
		  s1.addPoint(xRef+width+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta)));
		  s1.addPoint(xRef+width+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta))-thick);
		  g.fillPolygon(s1);
	    g.setColor(MetalColor2);
		Polygon s5 = new Polygon();
		  s5.addPoint(xRef,yTop-thick);
		  s5.addPoint(xRef+width,yTop-thick);
		  s5.addPoint(xRef+width+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta))-thick);
		  s5.addPoint(xRef+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta))-thick);
		  g.fillPolygon(s5);   
	    g.setColor(Color.black);
		g.drawRect(xRef,yTop-thick,width,thick);
		g.drawLine(xRef,yTop-thick,xRef+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta))-thick);
		g.drawLine(xRef+width,yTop-thick,xRef+(int)(slabDepth*Math.cos(theta))+width,yTop-(int)(slabDepth*Math.sin(theta))-thick);
		g.drawLine(xRef+width,yTop,xRef+(int)(slabDepth*Math.cos(theta))+width,yTop-(int)(slabDepth*Math.sin(theta)));
	
	}	  
	    //Draw corner vertical line
	    g.setColor(Color.black);
		g.drawLine(xRight,yTop,xRight,yBottom+10);
	    //Top plane lines
	    g.drawLine(xLeft,yTop,xRight,yTop);
	    g.drawLine(xRight,yTop,xRight+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta)));
	    //Bottom plane lines
	    g.setColor(Color.black);
	    g.drawLine(xLeft,yBottom,xRight,yBottom);
	    g.drawLine(xRight,yBottom,xRight+(int)(slabDepth*Math.cos(theta)),yBottom-(int)(slabDepth*Math.sin(theta)));
	
	    //draw red arrow for substrate thickness a	  
	    g.setColor(Color.red);  
	    g.drawLine(xRight+10,yBottom,xRight+10,yTop-5);
	    g.drawLine(xRight+10,yTop-10,xRight+10,yTop-20);
	    g.drawLine(xRight+10,yBottom+10,xRight+10,yBottom);
	    MaestroG.drawArrow(xRight+10,yBottom+3,5,g);
	    MaestroG.drawArrow(xRight+10,yTop-15,6,g);
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
	    //g.drawString("a = "+MaestroA.rounder(a,8)+" [ m ]",xLeft+30,(yTop+yBottom)/2+20);
	    if((yBottom-yTop) >=15){
		g.drawString("h",xRight+15,(yTop+yBottom)/2-5);
	    }
	    else{
		g.drawString("h",xRight+15,yTop-15);
	    }
      }
      else{
	    // Draw core of waveguide
	    g.setColor(new Color(255,255,240));

		Polygon s3 = new Polygon();
		    s3.addPoint(xRight+1,yTop);
		    s3.addPoint(xRight+1,yTop+Botref);
		    s3.addPoint(xRight+(int)(slabDepth*Math.cos(theta)),yTop+Botref-(int)(slabDepth*Math.sin(theta)));
		    s3.addPoint(xRight+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta)));
		    g.fillPolygon(s3);
	    g.setColor(new Color(235,235,220));
		Polygon s4 = new Polygon();
		    s4.addPoint(xLeft,yTop);
		    s4.addPoint(xLeft,yTop+Botref);
		    s4.addPoint(xRight,yTop+Botref);
		    s4.addPoint(xRight,yTop);
		    g.fillPolygon(s4);
	    //Draw Top Waveguide Substrate
	    g.setColor(new Color(255,255,230));
		Polygon s6 = new Polygon();
		  s6.addPoint(xLeft,yTop);
		  s6.addPoint(xRight,yTop);
		  s6.addPoint(xRight+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta)));
		  s6.addPoint(xLeft+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta)));
		  g.fillPolygon(s6);	    
	    // Draw Metals
	    if(width > 0){
		g.setColor(MetalColor1);
		g.fillRect(xRef,yTop-thick,width,thick);
		g.setColor(MetalColor3);
		    Polygon s1 = new Polygon();
		    s1.addPoint(xRef+width,yTop-thick);
		    s1.addPoint(xRef+width,yTop);
		    s1.addPoint(xRef+width+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta)));
		    s1.addPoint(xRef+width+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta))-thick);
		    g.fillPolygon(s1);
		g.setColor(MetalColor2);
		    Polygon s5 = new Polygon();
		    s5.addPoint(xRef,yTop-thick);
		    s5.addPoint(xRef+width,yTop-thick);
		    s5.addPoint(xRef+width+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta))-thick);
		    s5.addPoint(xRef+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta))-thick);
		    g.fillPolygon(s5);
		// Draw black lines of strip   
		g.setColor(Color.black);
		g.drawRect(xRef,yTop-thick,width,thick);
		g.drawLine(xRef,yTop-thick,xRef+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta))-thick);
		g.drawLine(xRef+width,yTop-thick,xRef+(int)(slabDepth*Math.cos(theta))+width,yTop-(int)(slabDepth*Math.sin(theta))-thick);
		g.drawLine(xRef+width,yTop,xRef+(int)(slabDepth*Math.cos(theta))+width,yTop-(int)(slabDepth*Math.sin(theta)));
	
	}
	
		// Draw corner vertical line
		g.setColor(Color.black);
		g.drawLine(xRight,yTop,xRight,yTop+Botref);
	    //Top plane lines
	    g.drawLine(xLeft,yTop,xRight,yTop);
	    g.drawLine(xRight,yTop,xRight+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta)));
	    //draw red arrow for substrate thickness a		
	    g.setColor(Color.red);
	    g.drawLine(xRight+10,yTop-5,xRight+10,yTop+Botref);
	    g.drawLine(xRight+10,yTop-10,xRight+10,yTop-20);
	    MaestroG.drawArrow(xRight+10,yTop-15,6,g);
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
	    g.drawString("h",xRight+15,(yTop+yTop+Botref)/2-5);
    }
	g.setColor(Color.white);
	g.fillRect(0,0,getSize().width-4,2);
	
	//Arrows for width of strip
      if((yBottom - yTop)>=15){
	
	g.setColor(Color.red);
	g.drawLine(xRef-15,yTop+5,xRef-10,yTop+5);
	MaestroG.drawArrow(xRef-10,yTop+5,7,g);
	g.drawLine(xRef+width+15,yTop+5,xRef+width+10,yTop+5);
	MaestroG.drawArrow(xRef+width+10,yTop+5,8,g);
	g.drawLine(xRef,yTop,xRef,yTop+10);
	g.drawLine(xRef+width,yTop,xRef+width,yTop+10);  
        
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
	//g.drawString("W = "+MaestroA.rounder(w,4)+" [ m ]",xRef,yTop+25);
	if(width>=15){
	    g.drawString("w",xRef+width/2-5,yTop+10);
	}
	else{
	    g.drawString("w",xRef+width+20,yTop+10);
	}
       }
       else{
	
	g.setColor(Color.red);
	int shift =(yBottom-yTop)+10;
	g.drawLine(xRef-15,yTop+5+shift,xRef-10,yTop+5+shift);
	MaestroG.drawArrow(xRef-10,yTop+5+shift,7,g);
	g.drawLine(xRef+width+15,yTop+5+shift,xRef+width+10,yTop+5+shift);
	MaestroG.drawArrow(xRef+width+10,yTop+5+shift,8,g);
	g.drawLine(xRef,yTop,xRef,yTop+10+shift);
	g.drawLine(xRef+width,yTop,xRef+width,yTop+10+shift);  
	
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
	if(width>=15){
	    g.drawString("w",xRef+width/2-5,yTop+10+shift);
	}
	else{
	    g.drawString("w",xRef+width+20,yTop+10+shift);
	}
       }
	//Arrows for thickness of strip
	//g.drawLine(xRef+width+(int)(slabDepth*Math.cos(theta))+10,yTop-(int)(slabDepth*Math.sin(theta))+5,
	//    xRef+width+(int)(slabDepth*Math.cos(theta))+10,yTop-(int)(slabDepth*Math.sin(theta))+15);
	//MaestroG.drawArrow(xRef+width+(int)(slabDepth*Math.cos(theta))+10,yTop-(int)(slabDepth*Math.sin(theta))+10,5,g);
	//g.drawLine(xRef+width+(int)(slabDepth*Math.cos(theta))+10,yTop-(int)(slabDepth*Math.sin(theta))-thick-15,
	//    xRef+width+(int)(slabDepth*Math.cos(theta))+10,yTop-(int)(slabDepth*Math.sin(theta))-thick-5);
	//MaestroG.drawArrow(xRef+width+(int)(slabDepth*Math.cos(theta))+10,yTop-(int)(slabDepth*Math.sin(theta))-thick-10,6,g);
	//g.drawLine(xRef+width+(int)(slabDepth*Math.cos(theta))+5,yTop-(int)(slabDepth*Math.sin(theta)),
	//    xRef+width+(int)(slabDepth*Math.cos(theta))+15,yTop-(int)(slabDepth*Math.sin(theta)));
	//g.drawLine(xRef+width+(int)(slabDepth*Math.cos(theta))+5,yTop-(int)(slabDepth*Math.sin(theta))-thick,
	//    xRef+width+(int)(slabDepth*Math.cos(theta))+15,yTop-(int)(slabDepth*Math.sin(theta))-thick);
	//
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        //
        //g.drawString("t",xRef+width+(int)(slabDepth*Math.cos(theta))+20,yTop-(int)(slabDepth*Math.sin(theta))-(thick/2)+5);
	/* t = 0 in this version
	g.setColor(Color.red);
	if(IsWarningOn1 && !IsWarningOn2 && !IsSafetyOn){
	g.drawString("WARNING!!! INACCURACIES for t > h",70,getSize().height -40);	
	g.drawString("Reduce Strip Thickness ( t )",80,getSize().height -25);
	}
	
	if(IsWarningOn2 && !IsWarningOn1 && !IsSafetyOn){
	g.drawString("WARNING!!! INACCURACIES for t > w/2",70,getSize().height -40);	
	g.drawString("Reduce Strip Thickness ( t )",80,getSize().height -25);
	}
	
	
	if(IsWarningOn1 && IsWarningOn2 && !IsSafetyOn){
	g.drawString("WARNING!!! INACCURACIES for t > h, w/2",60,getSize().height -40);	
	g.drawString("Reduce Strip Thickness ( t )",80,getSize().height -25);
	}
	if(IsSafetyOn && IsPrintSafetyOn){
	    g.drawString("WARNING!!! THEORY FAILS at very low w",60,getSize().height -40);	
	    g.drawString("Reduce Strip Thickness ( t )",80,getSize().height -25);
	}
	*/
      
	g.setColor(Color.black);
    	int x = 100;
	int y = getSize().height-7;
	double f_normalized;
	
	
	if(frequency < 1.0E3){
		    f_normalized = frequency;
		    g.drawString("    f =  "+MaestroA.rounder(f_normalized,6)+"   [ Hz ]",x,y);	
		}
		else if(frequency < 1.0E6 && frequency >= 1.0E3  ){
		    f_normalized = frequency/1.0E3;
		    g.drawString("    f  =  "+MaestroA.rounder(f_normalized,6)+"   [ kHz ]",x,y);	
		}
		else if(frequency < 1.0E9 && frequency >= 1.0E6 ){
		    f_normalized = frequency/1.0E6;
		    g.drawString("    f  =  "+MaestroA.rounder(f_normalized,6)+"   [ MHz ]",x,y);	
		}
		else if(frequency < 1.0E12 && frequency >= 1.0E9 ){
		    f_normalized = frequency/1.0E9;
		    g.drawString("    f  =  "+MaestroA.rounder(f_normalized,6)+"   [ GHz ]",x,y);	
		}
		else if(frequency < 1.0E15 && frequency >= 1.0E12 ){
		    f_normalized = frequency/1.0E12;
		    g.drawString("    f  =  "+MaestroA.rounder(f_normalized,6)+"   [ THz ]",x,y);	
		}
		else{
		    f_normalized = frequency/1.0E12;
		    g.drawString("    f  =  "+MaestroA.rounder(f_normalized,6)+"   [ THz ]",x,y);
		}
		
        //MaestroG.subscripter("\u03b5","r 1","  = "+MaestroA.rounder(epsilon_r0,4),g,12,10,50);
        //MaestroG.subsub("\u03bc","r 1"," = \u03bc","r 2"," = 1.0",g,12,10,32);
		
        // following 3 statements no good
        //MaestroG.subsup("\u03c3","c"," = "
        //MaestroG.subscripterInfinityThree(" =  ","","","","            [ \u03a9 ]",g,12,x+30,y);
        //MaestroG.subscripterInfinityOne("\u03c3","c"," = ","",g,12,110,12);
        MaestroG.subscripter("\u03c3","c"," = \u221e",g,12,110,12);

        //        if(sigma_metal < 1.0E3){
        //            MaestroG.subscripter("  ","s"," = "+MaestroA.rounder(sigma_metal,2)+" S/m",g,12,110,12);
        //        }
        //        else if(sigma_metal < 1.0E4 && sigma_metal >= 1.0E3){
        //            MaestroG.subsup("\u03c3","s"," = "+MaestroA.rounder(sigma_metal/1.0e3,2)+" x 10","3"," S/m",g,12,80,12); 
        //        }
        //        else if(sigma_metal < 1.0E5 && sigma_metal >= 1.0E4){
        //            MaestroG.subsup("\u03c3","s"," = "+MaestroA.rounder(sigma_metal/1.0e4,2)+" x 10","4"," S/m",g,12,80,12); 
        //        }
        //        else if(sigma_metal < 1.0E6 && sigma_metal >= 1.0E5){
        //            MaestroG.subsup("\u03c3","s"," = "+MaestroA.rounder(sigma_metal/1.0e5,2)+" x 10","5"," S/m",g,12,80,12); 
        //        }
        //        else if(sigma_metal < 1.0E7 && sigma_metal >= 1.0E6){
        //            MaestroG.subsup("\u03c3","s"," = "+MaestroA.rounder(sigma_metal/1.0e6,2)+" x 10","6"," S/m",g,12,80,12); 
        //        }
        //        else if(sigma_metal < 1.0E8 && sigma_metal >= 1.0E7){
        //            MaestroG.subsup("\u03c3","s"," = "+MaestroA.rounder(sigma_metal/1.0e7,2)+" x 10","7"," S/m",g,12,80,12); 
        //        }
        //        else if(sigma_metal < 1.0E9 && sigma_metal >= 1.0E8){
        //            MaestroG.subsup("\u03c3","s"," = "+MaestroA.rounder(sigma_metal/1.0e8,2)+" x 10","8"," S/m",g,12,80,12); 
        //        }
        //        else if(sigma_metal < 1.0E10 && sigma_metal >= 1.0E9){
        //            MaestroG.subsup("\u03c3","s"," = "+MaestroA.rounder(sigma_metal/1.0e9,2)+" x 10","9"," S/m",g,12,80,12); 
        //        }
        //        else if(sigma_metal < 1.0E11 && sigma_metal >= 1.0E10){
        //            MaestroG.subsup("\u03c3","s"," = "+MaestroA.rounder(sigma_metal/1.0e10,2)+" x 10","10"," S/m",g,12,80,12); 
        //        }
        //        else if(sigma_metal < 1.0E12 && sigma_metal >= 1.0E11){
        //            MaestroG.subsup("\u03c3","s"," = "+MaestroA.rounder(sigma_metal/1.0e11,2)+" x 10","11"," S/m",g,12,80,12); 
        //        }
        //        else if(sigma_metal >= 1.0E12){
        //            MaestroG.subsup("\u03c3","s"," = "+MaestroA.rounder(sigma_metal/1.0e12,2)+" x 10","12"," S/m",g,12,80,12); 
        //        }
                
		g.setFont(symbolfont);
		//g.drawString("\u03b5",10,40); // epsilon
		//g.drawString("\u03bc",10,22); // mu
		//g.drawString("\u03bc",45,22); // mu
		//g.drawString("\u03c3",110,12); // sigma
		g.setFont(labfont);
	
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    
		g.setColor(Color.blue);
		g.drawLine(132,14,165,40);   //x+33 y+26
                //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
    
		g.setColor(Color.black);
		int yref;
		if((yBottom - yTop)>(Botref-40) ){
		    if(yBottom > (yTop+Botref-10)){
			yref=yTop+Botref-10;
		    }
		    else{
			yref=yBottom-5;
		    }
		    //MaestroG.subscripter("\u03b5","r 2","  = "+MaestroA.rounder(epsilon_r,4),g,12,35,yref-15);
		    //MaestroG.subscripter("\u03c3","2"," = "+MaestroA.rounder(sigma2,6)+" S/m",g,12,35,yref);

		    MaestroG.subscripter("\u03b5","r","  = "+
                                         MaestroA.rounder(epsilon_r,4),
                                         g,12,35,yref-15);
		    MaestroG.subscripter("\u03c3",""," = 0",g,12,35,yref);
		    g.setFont(labfont);
		}
		else{
		    yref = yBottom+35;
		    
		    //MaestroG.subscripter("\u03b5","r 2","  = "+MaestroA.rounder(epsilon_r,4),g,12,45,yref);
		    //MaestroG.subscripter("\u03c3","2"," = "+MaestroA.rounder(sigma2,6)+" S/m",g,12,130,yref);
		    MaestroG.subscripter("\u03b5","r","  = "+
                                         MaestroA.rounder(epsilon_r,4),
                                         g,12,45,yref);
		    //MaestroG.subscripter("\u03c3",""," = 0",g,12,130,yref);
		    MaestroG.subscripter("\u03c3",""," = 0",g,12,45,yref+15);
		    g.setFont(labfont);
		    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
		    int refnew;
		    refnew = yBottom-(yBottom-yTop)/2;
		    g.setColor(Color.blue);
		    g.drawLine(10,refnew,25,refnew);
		    g.drawLine(35,yBottom+35,40,yBottom+35);
		    g.drawLine(35,yBottom+35,10,refnew);
		    MaestroG.drawArrow(20,refnew,7,g);
		    g.setColor(Color.black);
		}
                // NEW STUFF:
		//g.setColor(Color.blue);   // already did these 2 lines
		//g.drawLine(132,14,165,40);   //x+33 y+26
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		g.setColor(Color.blue);
                //g.drawLine(185,90,204,109);  //x+24 y+19
		int yrefNEW = yBottom+35;
                g.drawLine(185,yrefNEW-29,204,yrefNEW-10);  //x+24 y+19
                g.setColor(Color.black);
                MaestroG.subscripter("\u03c3","c"," = \u221e",g,12,210,yrefNEW);
                // END NEW STUFF
		
	
    }
    public synchronized void setIsWarningOn1(boolean warning){
	this.IsWarningOn1 = warning;
	repaint();
    }
    
    public synchronized void setIsWarningOn2(boolean warning){
	this.IsWarningOn2 = warning;
	repaint();
    }
    
    public synchronized void setIsSafetyOn(boolean safety){
	this.IsSafetyOn = safety;
	repaint();
    }
    
    public synchronized void setIsPrintSafetyOn(boolean print_safety){
	this.IsPrintSafetyOn = print_safety;
	repaint();
    }
    
    public synchronized void setThick(double b){
	this.b = b;
	repaint();
    }
    
    public synchronized void setThickmax(double b_maximum){
	this.b_maximum = b_maximum;
	repaint();
    }
    
    public synchronized void setStrip(double w){
	this.w = w;
	repaint();
    }
    
    public synchronized void setStripmax(double w_maximum){
	this.w_maximum = w_maximum;
	repaint();
    }
    
    public synchronized void setFrequency(double frequency){
	this.frequency = frequency;
    }
    
    public synchronized void setWidth(double a){
	this.a = a;
    }
    
    public synchronized void setWidthMax(double a_maximum){
	this.a_maximum = a_maximum;
    }
    
    public synchronized void setEpsilon(double epsilon_r){
	this.epsilon_r = epsilon_r;
	
    }
    
    public synchronized void setEpsilon0(double epsilon_r0){
	this.epsilon_r0 = epsilon_r0;
	
    }
    
    public synchronized void setMu(double mu){
	this.mu_r = mu;
    }
    
    public synchronized void setSigma2(double sigma2){
	this.sigma2 = sigma2;
    }
    
    public synchronized void setSigmaMetal(double sigma_metal){
	this.sigma_metal = sigma_metal;
    }
    
    public void paint(Graphics g){
	    if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawCanvas(buf);
	    }
	    else{
		drawCanvas(buf);
	    }
	    g.drawImage(im,0,0,null);
    }
    
    
    public void update(Graphics g){
	paint(g);
    }
    
    public void mouseClicked(MouseEvent evt){}
    public void mouseEntered(MouseEvent evt){
	IsFocusOn = true;
	repaint();
    }
    public void mouseExited(MouseEvent evt){
	IsFocusOn = false;
	repaint();
    }
    public void mousePressed(MouseEvent evt){}
    public void mouseReleased(MouseEvent evt){}
}
