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

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

//import Trans_State;
public class Auxiliary2 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.gray;
	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
	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.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 boolean IsFocusOn, IsTopoOn, IsDark;
	public Auxiliary2(Trans_State state){
		super();
		this.state = state;
		setBackground(bgcolor2);
		this.addMouseListener(this);
		IsFocusOn = false;
		IsDark = true;
	}

	public void update(Graphics g){
		paint(g);
	}

	public void paint(Graphics g){
		
		if(im == null){
			im = createImage(getSize().width,getSize().height);
			buf = im.getGraphics();
			drawStrings(buf);
		}
		else{
			drawStrings(buf);
		}
		g.drawImage(im,0,0,null);
	}
	
	private void drawStrings(Graphics g){
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
            int xd, yd, dx, dy;
            g.clearRect(0,0,getSize().width,getSize().height);

            g.setColor(Color.white);
            FontMetrics fm = g.getFontMetrics();

            g.setFont(symbolfont);
            alpha="\u03b1";
            lambda="\u03bb";
            Ohm="\u03a9";
            infinity="\u221e";
            Gamma="\uu0393"; 
            epsilon="\u03b5";
            g.setFont(normalfont);
		
	    xd = 5;
	    yd = 12;
	    dx = 1;
	    dy = 14;
	    
	    double dmax, dmin;
	    if(state.ZL.Imaginary()>0.0){
		dmax=(double)((state.GammaL.Arg2())/(4.0*Math.PI));
		dmin=dmax+0.25;
	    }
	    else{
		dmax=(double)((state.GammaL.Arg2())/(4.0*Math.PI))+0.5;
		dmin=(double)((state.GammaL.Arg2())/(4.0*Math.PI))+0.25;
	    }

	    while(dmax>0.5) dmax=dmax-0.5;
	    while(dmin>0.5) dmin=dmin-0.5; 
	
	    g.setColor(Color.red);
	    //g.drawString("d(max) = "+MaestroA.rounder(dmax,5)+" "+lambda,xd+dx,yd);
            //MaestroG.SansNosansSymb("d(max) = "+MaestroA.rounder(dmax,5)," ",""+lambda,g,12,xd+dx,yd);
            MaestroG.subscripterSanSym2("d(max) = "+MaestroA.rounder(dmax,5)," ",""+lambda,g,12,xd+dx,yd);
        }
	
	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

