//Auxiliary.java
//author Umberto Ravaioli, 2005
// Prints SWR value under "Tangent SWR Circle" on left panel

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

//import Trans_State;
public class Auxiliary 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 Auxiliary(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);
            Font myfont = new Font("SanSerif",Font.PLAIN,state.font12);
            FontMetrics fm = g.getFontMetrics();
            g.setFont(myfont);
            
            alpha="\u03b1";
            lambda="\u03bb";
            Ohm="\u03a9";
            infinity="\u221e";
            Gamma="\uu0393"; 
            epsilon="\u03b5";
            	
	    xd = state.s5;
	    yd = state.s12;
	    dx = state.s1;
	    dy = state.s14;
	
	    g.setColor(Color.blue);
	    
	    if(state.VSWR > 0.0){
		if(state.IsLoadOpen || state.IsLoadShort || state.IsLoadImaginary || state.VSWR > 1.0e16){
		    //g.drawString("VSWR = "+infinity,xd+dx,yd);
                    MaestroG.subscripterInfinityOne("SWR = ","","","",g,state.font11,xd+dx,yd);
		}
		else if(state.VSWR >=100.0 && state.VSWR <= 1.0e16){
		    g.drawString("SWR = "+MaestroA.rounder(state.VSWR,2),xd+dx,yd);
		}
		else{	
		    g.drawString("SWR = "+MaestroA.rounder(state.VSWR,4),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

