/**
 * NewGuideCanvas.java
*/
/* A Java class for
 * TwoWire.java
 * Electromagnetic Transmission Line Applet
 * Applet without Smith Chart - Prepared by Umberto Ravaioli 
 * for 6th edition of Fundamentals of Applied Electromagnetics Book
 * May 2009 - All Rights Reserved
 */   

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.text.*;
import java.util.*;

//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=20, RightMargin=10, TopMargin=10, BottomMargin=10;
    //private static final Font labfont2 = new Font("SanSerif",Font.PLAIN,12);
    public static Font labfont2;
    
    private int yBottom;
    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;
    
    // Exact epsilon for exact phase velocity
    //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 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 = 10.0; // mm
	a_maximum = 11.0; //mm
	b = 0.005; //mm
	b_maximum = 0.5; //mm
	w = 1.5; //mm
	w_maximum = 11.0; //mm
	epsilon_r = 2.3;
	epsilon_r0 = 1.0;
	mu_r = 1.0;
	frequency = 1.0E9;
	sigma2 = 0.0;
	sigma_metal = 5.8E7 ;
	
    }

    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){
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
	double theta = Math.PI/4.0;
	int ArrowPos1, ArrowPos2;
	int Lsize = 30;
	        
        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);
	
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        //Draw labels for axes
	//g.setFont(new Font("SanSerif",Font.PLAIN,12));
	g.setFont(labfont2);
	FontMetrics fm = g.getFontMetrics();
	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, yCenter;
	int yTop, width, thick, widthmax, amax, thickmax;
	int slabDH;//Thickness of the slab
	int slabDepth; //Depth of the slab
	double theta = Math.PI/4.0;
	Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
	thickmax = 5;
	widthmax = 100;
	amax =100;
	if( w_maximum >= a_maximum){
	    amax = (int)(a_maximum/w_maximum*widthmax);
	    thickmax = (int)(b_maximum/a_maximum*amax);
	}
	if(w_maximum < a_maximum){
	    amax = 100;
	    widthmax = (int)(w_maximum/a_maximum*amax);
	    thickmax = (int)(b_maximum/a_maximum*amax);
	}
	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;
	}

        int movex = 0;
        int movey = 3;
        
        // draw inside bottom wall
        g.setColor(new Color(234,245,255));
        //g.fillRect(15+movex,40+movey, 260,100);
        Polygon boxbot = new Polygon();
        boxbot.addPoint(15+movex,140+movey);
        boxbot.addPoint(175+movex,movey);
        boxbot.addPoint(307+movex,movey);
        boxbot.addPoint(275+movex,40+movey);
        boxbot.addPoint(275+movex,140+movey);
        g.fillPolygon(boxbot);
        
        // draw top of box
        //Polygon boxtop = new Polygon();
        //boxtop.addPoint(15+movex,40+movey);
        //boxtop.addPoint(67+movex,movey);
        //boxtop.addPoint(287+movex,movey);
        //boxtop.addPoint(255+movex,40+movey);
        //g.fillPolygon(boxtop);
        
        // draw outside wall on right
        g.setColor(new Color(224,235,245));
        Polygon boxside = new Polygon();
        boxside.addPoint(307+movex,movey);
        boxside.addPoint(275+movex,40+movey);
        boxside.addPoint(275+movex,140+movey);
        boxside.addPoint(307+movex,100+movey);
        g.fillPolygon(boxside);
	
	Color MetalColor1 = Color.lightGray;
	Color MetalColor2 = new Color(220,220,220);
	Color MetalColor3 = new Color(235,235,235);
	
	xLeft = LeftMargin+40;
	xRight = getSize().width - RightMargin-80;
	xCenter = (xRight+xLeft)/2;
	yCenter = getSize().height/2;
	xRef = xCenter-width/2;
	yBottom = TopMargin+60+(int)(a/a_maximum*amax)+1;
	yTop = TopMargin+60;
	slabDH = 5;
	slabDepth = 90;
	// Draw waveguide
	        
           double raggio = (double)(width/2);
           int iraggio = (width/2);
           
           g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
            int x1 = xCenter+(int)(2*Math.sin(theta)*raggio);
            int y1 = yCenter-(int)(3.25*Math.sin(theta)*raggio);
            int x2 = xCenter+(int)(3.25*Math.sin(theta)*raggio);
            int y2 = yCenter-(int)(2*Math.sin(theta)*raggio);
            int far = 150;
            
            //cylinder lines for conductors
            g2d.setPaint(new GradientPaint(xCenter+iraggio-(int)(a/a_maximum*amax/2)-(int)(Math.sin(theta)*iraggio),
                            yCenter-(int)(Math.sin(theta)*iraggio),Color.white,
                            xCenter+iraggio-(int)(a/a_maximum*amax/2)+(int)(Math.sin(theta)*iraggio)-1,yCenter+(int)(Math.sin(theta)*iraggio),
                            Color.gray));
            
            //g2d.setPaint(new GradientPaint(113.0f,10.0f,Color.white,182.0f,10.0f,Color.lightGray));
            Polygon pK = new Polygon();
		pK.addPoint(xCenter+iraggio-(int)(a/a_maximum*amax/2)-(int)(Math.sin(theta)*iraggio),
                            yCenter-(int)(Math.sin(theta)*iraggio));
		pK.addPoint(xCenter+iraggio-(int)(a/a_maximum*amax/2)+(int)(Math.sin(theta)*iraggio)-1,yCenter+(int)(Math.sin(theta)*iraggio));
                pK.addPoint((x1+x2)/2+2*far,(y1+y2)/2-2*far);
		pK.addPoint((x1+x2)/2+2*far,(y1+y2)/2-2*far);
            g.fillPolygon(pK);
            
            // conductor on left
            
            g.setColor(Color.lightGray);
            g.drawLine(xCenter+iraggio-(int)(a/a_maximum*amax/2)-(int)(Math.sin(theta)*iraggio),yCenter-(int)(Math.sin(theta)*iraggio),
                       (x1+x2)/2+2*far,(y1+y2)/2-2*far);
                        
            g.setColor(Color.gray);
            g.drawLine(xCenter+iraggio-(int)(a/a_maximum*amax/2)+(int)(Math.sin(theta)*iraggio)-1,yCenter+(int)(Math.sin(theta)*iraggio),
                       (x1+x2)/2+2*far,(y1+y2)/2-2*far);
            
            
            // conductor on the right
            g.setColor(bgcolor);
            
            g2d.setPaint(new GradientPaint(xCenter+iraggio+(int)(a/a_maximum*amax/2)-(int)(Math.sin(theta)*iraggio),
                            yCenter-(int)(Math.sin(theta)*iraggio),Color.white,
                            xCenter+iraggio+(int)(a/a_maximum*amax/2)+(int)(Math.sin(theta)*iraggio)-1,yCenter+60*(int)(Math.sin(theta)*iraggio)/100,
                            Color.gray));
            
            //g2d.setPaint(new GradientPaint(193.0f,10.0f,Color.white,242.0f,10.0f,Color.lightGray));
            Polygon pH = new Polygon();
		pH.addPoint(xCenter+iraggio+(int)(a/a_maximum*amax/2)-(int)(Math.sin(theta)*iraggio),
                            yCenter-(int)(Math.sin(theta)*iraggio));
		pH.addPoint(xCenter+iraggio+(int)(a/a_maximum*amax/2)+(int)(Math.sin(theta)*iraggio)-1,yCenter+(int)(Math.sin(theta)*iraggio));
                pH.addPoint((x1+x2)/2+2*far,(y1+y2)/2-2*far);
		pH.addPoint((x1+x2)/2+2*far,(y1+y2)/2-2*far);
		
                //g.drawPolygon(pH);
            g.fillPolygon(pH);
            
            g.setColor(Color.lightGray);
            g.drawLine(xCenter+iraggio+(int)(a/a_maximum*amax/2)-(int)(Math.sin(theta)*iraggio),yCenter-(int)(Math.sin(theta)*iraggio),
                       (x1+x2)/2+2*far,(y1+y2)/2-2*far);
                        
            g.setColor(Color.gray);
            g.drawLine(xCenter+iraggio+(int)(a/a_maximum*amax/2)+(int)(Math.sin(theta)*iraggio)-1,yCenter+(int)(Math.sin(theta)*iraggio),
                       (x1+x2)/2+2*far,(y1+y2)/2-2*far);    
            
            
            
            // Border strip on top
            g.setColor(bgcolor);
            g.fillRect(getSize().width/3,0,2*getSize().width/3+10,3);
            
            // draw vertical inner wall on the left 
            g.setColor(new Color(224,235,245));
            Polygon box2 = new Polygon();
            box2.addPoint(15+movex,140+movey);
            box2.addPoint(175+movex,movey);
            box2.addPoint(65+movex,movey);
            box2.addPoint(15+movex,40+movey);
            // bottom line
            g.fillPolygon(box2);
            g.setColor(Color.lightGray);
            g.drawLine(15+movex,140+movey, 175+movex,movey);
            
            //  Make top ob box slightly transparent
            int rule; float alpha;
            rule = AlphaComposite.SRC_OVER;
            alpha = 0.90f;
        
            g2d.setComposite(AlphaComposite.getInstance(rule, alpha));
        
            g.setColor(new Color(245,245,255));
            // draw top of box to appear as if opaque
            Polygon boxtop2 = new Polygon();
            boxtop2.addPoint(15+movex,40+movey);
            boxtop2.addPoint(67+movex,movey);
            boxtop2.addPoint(307+movex,movey);
            boxtop2.addPoint(275+movex,40+movey);
            g.fillPolygon(boxtop2);
            
            alpha = 0.2f;
            g2d.setComposite(AlphaComposite.getInstance(rule, alpha));
            // draw front rectangle - semitransparent
            g.setColor(new Color(250,250,250));
            g.fillRect(15+movex,40+movey, 260,100);
            
            // return to opaque (alpha = 1.0)
            g2d.setComposite(AlphaComposite.getInstance(rule, 1.0f));
            
            
            
            
            
            
	    //g.setColor(Color.red);
	    // Draw wires	    
	    g.setColor(new Color(155,155,155));
	    
            g.fillOval(xCenter-(int)(a/a_maximum*amax/2),yCenter-(int)(iraggio),width,width);
	    g.fillOval(xCenter+(int)(a/a_maximum*amax/2),yCenter-(int)(iraggio),width,width);
	    
	    //g.setColor(new Color(225,225,225));
	    g.setColor(new Color(240,240,240));
	    
            g.fillOval(xCenter+1-(int)(a/a_maximum*amax/2),yCenter-(int)(iraggio)+1,width-2,width-2);
	    g.fillOval(xCenter+1+(int)(a/a_maximum*amax/2),yCenter-(int)(iraggio)+1,width-2,width-2);
	    
	    // Draw lines for wire diameters
	    g.setColor(Color.red);
	    g.drawLine(xCenter-(int)(a/a_maximum*amax/2),yCenter,
		       xCenter-(int)(a/a_maximum*amax/2),yCenter-(int)(iraggio)-25);
	    g.drawLine(xCenter+(int)(width)-(int)(a/a_maximum*amax/2)-1,yCenter,
		       xCenter+(int)(width)-(int)(a/a_maximum*amax/2)-1,yCenter-(int)(iraggio)-25);
	    g.drawLine(xCenter+(int)(a/a_maximum*amax/2),yCenter,
		       xCenter+(int)(a/a_maximum*amax/2),yCenter-(int)(iraggio)-25);
	    g.drawLine(xCenter+(int)(width)+(int)(a/a_maximum*amax/2)-1,yCenter,
		       xCenter+(int)(width)+(int)(a/a_maximum*amax/2)-1,yCenter-(int)(iraggio)-25);
	    
	    if((int)(iraggio) > 10){
		g.drawLine(xCenter+(int)(width)-(int)(a/a_maximum*amax/2)-1,yCenter-(int)(iraggio)-20,
		       xCenter-(int)(a/a_maximum*amax/2),yCenter-(int)(iraggio)-20);
		g.drawLine(xCenter+(int)(width)+(int)(a/a_maximum*amax/2)-1,yCenter-(int)(iraggio)-20,
		       xCenter+(int)(a/a_maximum*amax/2),yCenter-(int)(iraggio)-20);
		
		MaestroG.drawArrow(xCenter+(int)(width)-(int)(a/a_maximum*amax/2)-10,
			       yCenter-(int)(iraggio)-20,7,g);
		MaestroG.drawArrow(xCenter-(int)(a/a_maximum*amax/2)+10,
			       yCenter-(int)(iraggio)-20,8,g);
		
		MaestroG.drawArrow(xCenter+(int)(width)+(int)(a/a_maximum*amax/2)-10,
			       yCenter-(int)(iraggio)-20,7,g);
		MaestroG.drawArrow(xCenter+(int)(a/a_maximum*amax/2)+10,
			       yCenter-(int)(iraggio)-20,8,g);
	    }
	    else{
		
		g.drawLine(xCenter+(int)(width)-(int)(a/a_maximum*amax/2),yCenter-(int)(iraggio)-20,
		       xCenter-(int)(a/a_maximum*amax/2),yCenter-(int)(iraggio)-20);
		g.drawLine(xCenter+(int)(width)+(int)(a/a_maximum*amax/2),yCenter-(int)(iraggio)-20,
		       xCenter+(int)(a/a_maximum*amax/2),yCenter-(int)(iraggio)-20);
		
		if((int)(a/a_maximum*amax/2) > 15){
		    MaestroG.drawArrow(xCenter+(int)(width)-(int)(a/a_maximum*amax/2)+9,
			       yCenter-(int)(iraggio)-20,8,g);
		}
		MaestroG.drawArrow(xCenter-(int)(a/a_maximum*amax/2)-10,
			       yCenter-(int)(iraggio)-20,7,g);
		
		MaestroG.drawArrow(xCenter+(int)(width)+(int)(a/a_maximum*amax/2)+9,
			       yCenter-(int)(iraggio)-20,8,g);
		if((int)(a/a_maximum*amax/2) > 15){
		    MaestroG.drawArrow(xCenter+(int)(a/a_maximum*amax/2)-10,
			       yCenter-(int)(iraggio)-20,7,g);
		}
	    }
	    
	    // Draw lines for arrow between centers
	    g.drawLine(xCenter+(int)(iraggio)+(int)(a/a_maximum*amax/2),yCenter+(int)(iraggio),
		       xCenter+(int)(iraggio)+(int)(a/a_maximum*amax/2),yCenter+(int)(iraggio)+20);
	    g.drawLine(xCenter+(int)(iraggio)-(int)(a/a_maximum*amax/2),yCenter+(int)(iraggio),
		       xCenter+(int)(iraggio)-(int)(a/a_maximum*amax/2),yCenter+(int)(iraggio)+20);
	   
	    	    
	    if((int)(a/a_maximum*amax/2) > 10){
		g.drawLine(xCenter+(int)(iraggio)+(int)(a/a_maximum*amax/2),yCenter+(int)(iraggio)+15,
		       xCenter+(int)(iraggio)-(int)(a/a_maximum*amax/2),yCenter+(int)(iraggio)+15);
		MaestroG.drawArrow(xCenter+(int)(iraggio)+(int)(a/a_maximum*amax/2)-10,yCenter+(int)(iraggio)+15,7,g);
		MaestroG.drawArrow(xCenter+(int)(iraggio)-(int)(a/a_maximum*amax/2)+10,yCenter+(int)(iraggio)+15,8,g);
	    }
	    else{g.drawLine(xCenter+(int)(iraggio)+(int)(a/a_maximum*amax/2),yCenter+(int)(iraggio)+15,
		       xCenter+(int)(iraggio)-(int)(a/a_maximum*amax/2),yCenter+(int)(iraggio)+15);
		MaestroG.drawArrow(xCenter+(int)(iraggio)+(int)(a/a_maximum*amax/2)+10,yCenter+(int)(iraggio)+15,8,g);
		MaestroG.drawArrow(xCenter+(int)(iraggio)-(int)(a/a_maximum*amax/2)-10,yCenter+(int)(iraggio)+15,7,g);
	    }
	    
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
	    // Draw Labels
	    g.drawString("d",xCenter+(int)(iraggio)-(int)(a/a_maximum*amax/2)-3,yCenter-(int)(iraggio)-27);
	    g.drawString("d",xCenter+(int)(iraggio)+(int)(a/a_maximum*amax/2)-3,yCenter-(int)(iraggio)-27);
	    
	    g.drawString("D",xCenter+(int)(iraggio)-3,yCenter+(int)(iraggio)+30);
	    
	    g.setColor(Color.black);
            g.drawString("+",xCenter+(int)(iraggio)-(int)(a/a_maximum*amax/2)-4,yCenter+5);
	    g.drawString("+",xCenter+(int)(iraggio)+(int)(a/a_maximum*amax/2)-4,yCenter+5);
	    
	
	g.setColor(Color.black);
    	int x = 100;
	int y = getSize().height-5;
	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("\u03bc","r","  = 1.0",g,12,18,42);
        //MaestroG.subscripter("\u03b5","r","  = "+MaestroA.rounder(epsilon_r,4),g,12,18,27);
        //MaestroG.subscripter("\u03c3",""," = "+MaestroA.rounder(sigma2,6)+" S/m",g,12,23,13);
        
        g.setColor(Color.lightGray);
        g.drawLine(15+movex,40+movey, 67+movex,0+movey);
        g.drawLine(275+movex,40+movey, 307+movex,0+movey);

        g.drawLine(15+movex,40+movey, 275+movex,40+movey);
        g.drawLine(15+movex,140+movey, 275+movex,140+movey);

        g.drawLine(15+movex,40+movey, 15+movex,140+movey);
        g.drawLine(275+movex,40+movey, 275+movex,140+movey);

        g.drawLine(275+movex,140+movey, 307+movex,100+movey);
        //g.setColor(new Color(194,235,255));
        //g.fillRect(25,50, 240,100);


		//g.setFont(symbfont);
		//g.drawString("\u03bc",10,42);
		//g.drawString("\u03c3",13,13);
		//g.drawString("\u03b5",13,27);
		g.setFont(labfont2);
                
                if(w >= a){
                    g.setColor(Color.red);
                    int xstart1 = 5;
                    g.drawString("WARNING!",xstart1, 65);
                    g.drawString("Reduce ",xstart1, 80);
                    g.drawString("diameter d",xstart1, 95);
                    g.drawString("or increase",xstart1, 110);
                    g.drawString("distance D",xstart1, 125);
                }
		
		int refnew = yTop+30;
        g.setColor(Color.red);
        g.drawString("Substrate",25,165);
        g.drawString("Wires",170,165);
        g.setColor(Color.black);

        MaestroG.subscripter("\u03b5","r","  = "+MaestroA.rounder(epsilon_r,4),
                             g,12,18,180);
        MaestroG.subscripter("\u03c3",""," = "+MaestroA.rounder(sigma2,6)+
                             " [S/m]",g,12,23,195);
        DecimalFormat dec = new DecimalFormat("0.###E0");
        MaestroG.subscripter("\u03c3","c"," = "+dec.format(sigma_metal)+
                             " [S/m]",g,12,165,180);
        //MaestroG.subscripter("\u03c3","c"," = "+MaestroA.rounder(sigma_metal,6)+
        //                     " [S/m]",g,12,165,180);
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
    }
    
    
    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){}
}
