/* 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.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;

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 int LeftMargin=10, RightMargin=10, TopMargin=10, BottomMargin=10;
    public Font labfont;
    public 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;
    private NewGuide_State state;
    
    private BufferedImage infinity;
    
    public NewGuideCanvas(NewGuide_State state){
	super();
        this.state = state;
	getImages();
        
        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;
        
        LeftMargin = state.s10;
        RightMargin = state.s10;
        TopMargin = state.s10;
        BottomMargin = state.s10;
    }


    private void getImages() {
        // read in the nabla images, because CHEERPJ does not render this
	//  symbol in any font!  (java to javascript converter)
        try {
            //infinity = ImageIO.read(getClass().getResource("infinity.png"));
	    BufferedImage img =
		ImageIO.read(getClass().getResource("infinity.png"));
	    int targetWidth = (int) (state.sfactor * img.getWidth());
	    int targetHeight = (int) (state.sfactor * img.getHeight());
	    infinity =
		new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB);
	    Graphics2D graphics2D = infinity.createGraphics();
	    graphics2D.drawImage(img, 0, 0, targetWidth, targetHeight, null);
	    graphics2D.dispose();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    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);
        
        g.setColor(Color.black);
        g.drawRect(0,0,getSize().width-1,getSize().height-1);
    }
    
    private void drawAxis(Graphics g){
	double theta = Math.PI/4.0;
	int ArrowPos1, ArrowPos2;
	int Lsize = state.s30;
	Graphics2D g2d = (Graphics2D)g;
        
        g.setColor(Color.black);
    }
    
    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 = state.s100;
	int amax = (int)(a_maximum/w_maximum*widthmax);
	int thickmax = state.s5;
	
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
        g.setColor(Color.black);
        g.drawRect(0,0,getSize().width-1,getSize().height-1);
        
	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+state.s20;
	xRight = getSize().width - RightMargin-state.s80;
	xCenter = (xRight+xLeft)/2;
	xRef = xCenter-width/2;
	yBottom = TopMargin+state.s60+(int)(a/a_maximum*amax)+state.s1;
	yTop = TopMargin+state.s60;
	slabDH = state.s5;
	slabDepth = state.s90;
	
	int Botref = state.s80;
	if((yBottom - yTop)<(Botref-state.s10) ){	  
	// Draw core of waveguide
	    g.setColor(new Color(255,255,240));
		Polygon sp3 = new Polygon();
		    sp3.addPoint(xRight+1,yTop);
		    sp3.addPoint(xRight+1,yBottom);
		    sp3.addPoint(xRight+(int)(slabDepth*Math.cos(theta)),yBottom-(int)(slabDepth*Math.sin(theta)));
		    sp3.addPoint(xRight+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta)));
		    g.fillPolygon(sp3);
	    g.setColor(new Color(235,235,220));
		Polygon sp4 = new Polygon();
		    sp4.addPoint(xLeft,yTop);
		    sp4.addPoint(xLeft,yBottom);
		    sp4.addPoint(xRight,yBottom);
		    sp4.addPoint(xRight,yTop);
		    g.fillPolygon(sp4);
		    
	    //Draw Top Waveguide Substrate
	    g.setColor(new Color(255,255,230));
		Polygon sp6 = new Polygon();
		  sp6.addPoint(xLeft,yTop);
		  sp6.addPoint(xRight,yTop);
		  sp6.addPoint(xRight+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta)));
		  sp6.addPoint(xLeft+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta)));
		  g.fillPolygon(sp6);
	    //Draw metals
	    g.setColor(MetalColor1);
		g.fillRect(xLeft,yBottom,xRight-xLeft,state.s10);
	    g.setColor(MetalColor3);
		Polygon sp2 = new Polygon();
		  sp2.addPoint(xRight+1,yBottom);
		  sp2.addPoint(xRight+1,yBottom+state.s10);
		  sp2.addPoint(xRight+(int)(slabDepth*Math.cos(theta)),yBottom-(int)(slabDepth*Math.sin(theta))+state.s10);
		  sp2.addPoint(xRight+(int)(slabDepth*Math.cos(theta)),yBottom-(int)(slabDepth*Math.sin(theta)));
		  g.fillPolygon(sp2);
	    if(width > 0){
	    g.setColor(MetalColor1);
		g.fillRect(xRef,yTop-thick,width,thick);
	    g.setColor(MetalColor3);
		Polygon sp1 = new Polygon();
		  sp1.addPoint(xRef+width,yTop-thick);
		  sp1.addPoint(xRef+width,yTop);
		  sp1.addPoint(xRef+width+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta)));
		  sp1.addPoint(xRef+width+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta))-thick);
		  g.fillPolygon(sp1);
	    g.setColor(MetalColor2);
		Polygon sp5 = new Polygon();
		  sp5.addPoint(xRef,yTop-thick);
		  sp5.addPoint(xRef+width,yTop-thick);
		  sp5.addPoint(xRef+width+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta))-thick);
		  sp5.addPoint(xRef+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta))-thick);
		  g.fillPolygon(sp5);   
	    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+state.s10);
	    //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+state.s10,yBottom,xRight+state.s10,yTop-state.s5);
	    g.drawLine(xRight+state.s10,yTop-state.s10,xRight+state.s10,yTop-state.s20);
	    g.drawLine(xRight+state.s10,yBottom+state.s10,xRight+state.s10,yBottom);
	    //MaestroG.drawArrow(xRight+state.s10,yBottom+state.s3,5,g);
	    //MaestroG.drawArrow(xRight+state.s10,yTop-state.s15,6,g);
            MaestroG.drawArrowScaled(xRight+state.s10,yBottom+state.s3,1,state.sfactor,g);
	    MaestroG.drawArrowScaled(xRight+state.s10,yTop-state.s15,2,state.sfactor,g);
            
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
	    if((yBottom-yTop) >= state.s15){
		//g.drawString("h",xRight+state.s15,(yTop+yBottom)/2 - state.s5);
                MaestroG.subscripter("h","","",g,state.font12,xRight+state.s15,(yTop+yBottom)/2 - state.s5);
	    }
	    else{
		//g.drawString("h",xRight+state.s15,yTop-state.s15);
                MaestroG.subscripter("h","","",g,state.font12,xRight+state.s15,yTop-state.s15);
	    }
      }
      else{
	    // Draw core of waveguide
	    g.setColor(new Color(255,255,240));

		Polygon sp3 = new Polygon();
		    sp3.addPoint(xRight+state.s1,yTop);
		    sp3.addPoint(xRight+state.s1,yTop+Botref);
		    sp3.addPoint(xRight+(int)(slabDepth*Math.cos(theta)),yTop+Botref-(int)(slabDepth*Math.sin(theta)));
		    sp3.addPoint(xRight+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta)));
		    g.fillPolygon(sp3);
	    g.setColor(new Color(235,235,220));
		Polygon sp4 = new Polygon();
		    sp4.addPoint(xLeft,yTop);
		    sp4.addPoint(xLeft,yTop+Botref);
		    sp4.addPoint(xRight,yTop+Botref);
		    sp4.addPoint(xRight,yTop);
		    g.fillPolygon(sp4);
	    //Draw Top Waveguide Substrate
	    g.setColor(new Color(255,255,230));
		Polygon sp6 = new Polygon();
		  sp6.addPoint(xLeft,yTop);
		  sp6.addPoint(xRight,yTop);
		  sp6.addPoint(xRight+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta)));
		  sp6.addPoint(xLeft+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta)));
		  g.fillPolygon(sp6);	    
	    // Draw Metals
	    if(width > 0){
		g.setColor(MetalColor1);
		g.fillRect(xRef,yTop-thick,width,thick);
		g.setColor(MetalColor3);
		    Polygon sp1 = new Polygon();
		    sp1.addPoint(xRef+width,yTop-thick);
		    sp1.addPoint(xRef+width,yTop);
		    sp1.addPoint(xRef+width+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta)));
		    sp1.addPoint(xRef+width+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta))-thick);
		    g.fillPolygon(sp1);
		g.setColor(MetalColor2);
		    Polygon sp5 = new Polygon();
		    sp5.addPoint(xRef,yTop-thick);
		    sp5.addPoint(xRef+width,yTop-thick);
		    sp5.addPoint(xRef+width+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta))-thick);
		    sp5.addPoint(xRef+(int)(slabDepth*Math.cos(theta)),yTop-(int)(slabDepth*Math.sin(theta))-thick);
		    g.fillPolygon(sp5);
		// 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+state.s10,yTop-state.s5,xRight+state.s10,yTop+Botref);
	    g.drawLine(xRight+state.s10,yTop-state.s10,xRight+state.s10,yTop-state.s20);
	    MaestroG.drawArrow(xRight+state.s10,yTop-state.s15,6,g);
            
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
	    //g.drawString("h",xRight+state.s15,(yTop+yTop+Botref)/2-state.s5);
            MaestroG.subscripter("h","","",g,state.font12,xRight+state.s15,(yTop+yTop+Botref)/2-state.s5);
    }
    g.setColor(Color.white);
    g.fillRect(0,0,getSize().width-state.s4,state.s2);
	
    //Arrows for width of strip
    if((yBottom - yTop) >= state.s15){
	
            g.setColor(Color.red);
            g.drawLine(xRef-state.s15,yTop+state.s5,xRef-state.s10,yTop+state.s5);
            //MaestroG.drawArrow(xRef-state.s10,yTop+state.s5,7,g);
            MaestroG.drawArrowScaled(xRef-state.s10,yTop+state.s5,3,state.sfactor,g);
            
            g.drawLine(xRef+width+state.s15,yTop+state.s5,xRef+width+state.s10,yTop+state.s5);
            //MaestroG.drawArrow(xRef+width+state.s10,yTop+state.s5,8,g);
            MaestroG.drawArrowScaled(xRef+width+state.s10,yTop+state.s5,4,state.sfactor,g);
            
            g.drawLine(xRef,yTop,xRef,yTop+state.s10);
            g.drawLine(xRef+width,yTop,xRef+width,yTop+state.s10);  

            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);

            if(width>=state.s15){
                //g.drawString("w",xRef+width/2-state.s5,yTop+state.s10);
                MaestroG.subscripter("w","","",g,state.font12,xRef+width/2-state.s3,yTop+state.s10);
            }
            else{
                //g.drawString("w",xRef+width+state.s20,yTop+state.s10);
                MaestroG.subscripter("w","","",g,state.font12,xRef+width+state.s20,yTop+state.s10);
            }
    }
    else{
            g.setColor(Color.red);
            int shift =(yBottom-yTop)+state.s10;
            g.drawLine(xRef-state.s15,yTop+state.s5+shift,xRef-state.s10,yTop+state.s5+shift);
            //MaestroG.drawArrow(xRef-state.s10,yTop+state.s5+shift,7,g);
            MaestroG.drawArrowScaled(xRef-state.s10,yTop+state.s5+shift,3,state.sfactor,g);
            
            g.drawLine(xRef+width+state.s15,yTop+state.s5+shift,xRef+width+state.s10,yTop+state.s5+shift);
            //MaestroG.drawArrow(xRef+width+state.s10,yTop+state.s5+shift,8,g);
            MaestroG.drawArrowScaled(xRef+width+state.s10,yTop+state.s5+shift,4,state.sfactor,g);
            
            g.drawLine(xRef,yTop,xRef,yTop+state.s10+shift);
            g.drawLine(xRef+width,yTop,xRef+width,yTop+state.s10+shift);  

            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);

            if(width >= state.s15){
                //g.drawString("w",xRef+width/2-state.s5,yTop+state.s10+shift);
                MaestroG.subscripter("w","","",g,state.font12,xRef+width/2-state.s3,yTop+state.s10+shift);
            }
            else{
                //g.drawString("w",xRef+width+state.s20,yTop+state.s10+shift);
                MaestroG.subscripter("w","","",g,state.font12,xRef+width+state.s20,yTop+state.s10+shift);
            }
    }
	g.setColor(Color.black);
    	int x = state.s100;
	int y = getSize().height-state.s7;
	double f_normalized;
                
        if(frequency < 1.0E3){
            f_normalized = frequency;
            MaestroG.subscripter("    f =  "+MaestroA.rounder(f_normalized,6)+"   [ Hz ]","","",g,state.font12,x,y);	
        }
        else if(frequency < 1.0E6 && frequency >= 1.0E3  ){
            f_normalized = frequency/1.0E3;
            MaestroG.subscripter("    f =  "+MaestroA.rounder(f_normalized,6)+"   [ kHz ]","","",g,state.font12,x,y);
        }
        else if(frequency < 1.0E9 && frequency >= 1.0E6 ){
            f_normalized = frequency/1.0E6;
            MaestroG.subscripter("    f =  "+MaestroA.rounder(f_normalized,6)+"   [ MHz ]","","",g,state.font12,x,y);
        }
        else if(frequency < 1.0E12 && frequency >= 1.0E9 ){
            f_normalized = frequency/1.0E9;
            MaestroG.subscripter("    f =  "+MaestroA.rounder(f_normalized,6)+"   [ GHz ]","","",g,state.font12,x,y);
        }
        else if(frequency < 1.0E15 && frequency >= 1.0E12 ){
            f_normalized = frequency/1.0E12;
            MaestroG.subscripter("    f =  "+MaestroA.rounder(f_normalized,6)+"   [ THz ]","","",g,state.font12,x,y);
        }
        else{
            f_normalized = frequency/1.0E12;
            MaestroG.subscripter("    f =  "+MaestroA.rounder(f_normalized,6)+"   [ THz ]","","",g,state.font12,x,y);
        }

	//MaestroG.subscripter("\u03c3","c"," = \u221e",g,state.font12,state.s110,state.s12);
	MaestroG.SubTxtTxtImg("\u03c3","c"," = ",infinity,g,state.font12,state.s110,state.s12,this);
                
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                
		g.setColor(Color.blue);
		g.drawLine(state.s132,state.s14,state.s165,state.s40);
                //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
                
		g.setColor(Color.black);
		int yref;
		if((yBottom - yTop)>(Botref-state.s40) ){
		    if(yBottom > (yTop+Botref-state.s10)){
			yref=yTop+Botref-state.s10;
		    }
		    else{
			yref=yBottom-state.s5;
		    }
		    
		    MaestroG.subscripter("\u03b5","r","  = "+MaestroA.rounder(epsilon_r,4),
                            g,state.font12,state.s35,yref-state.s15);
		    MaestroG.subscripter("\u03c3",""," = 0",g,state.font12,state.s35,yref);
		    g.setFont(labfont);
		}
		else{
		    yref = yBottom+state.s35;
		    
		    MaestroG.subscripter("\u03b5","r","  = "+MaestroA.rounder(epsilon_r,4),
                                         g,state.font12,state.s45,yref);
		    MaestroG.subscripter("\u03c3",""," = 0",g,state.font12,state.s45,yref+state.s15);
		    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(state.s10,refnew,state.s25,refnew);
		    g.drawLine(state.s35,yBottom+state.s35,state.s40,yBottom+state.s35);
		    g.drawLine(state.s35,yBottom+state.s35,state.s10,refnew);
		    //MaestroG.drawArrow(state.s20,refnew,7,g);
                    MaestroG.drawArrowScaled(state.s20,refnew,3,state.sfactor,g);
                    
		    g.setColor(Color.black);
		}
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		g.setColor(Color.blue);
                int yrefNEW = yBottom+state.s35;
                
                if((yBottom - yTop)<(Botref-state.s10) ){
                //if(yrefNEW < state.s175){
                    g.drawLine(state.s185,yrefNEW-state.s29,state.s204,yrefNEW-state.s10);
                    g.setColor(Color.black);
                    //MaestroG.subscripter("\u03c3","c"," = \u221e",g,state.font12,state.s210,yrefNEW);
		    MaestroG.SubTxtTxtImg("\u03c3","c"," = ",infinity,g,state.font12,state.s210,yrefNEW,this);
                }
    }
    
    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){}
}
