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

public class NewGuideOutputPanel13 extends Panel implements ItemListener{
	NewGuide_State state;
	private static final Color bgcolor = new Color(236,236,221);
	//private static final Color bgcolor = Color.lightGray;
	private static final Font labfont=new Font("SanSerif",Font.PLAIN,12);
	
	private static final Font titlefont=new Font("SanSerif",Font.BOLD,16);
	Label titlelabel;	
	public Choice c1;
	public TitleCanvas12 tcanvas12;
	public NewOutputCanvas6P rwoc6P; 
	public NewOutputCanvas7P rwoc7P;
	public ScrollPane pane1, pane2;
		
	public NewGuideOutputPanel13(NewGuide_State state){
	    super();
	    setLayout(null);
	    this.state = state;
	    setBackground(bgcolor);
	    state.microFlag13 = false;
	    
	    titlelabel = new Label("    Field Data",Label.LEFT);
	    //add(titlelabel);//
	    titlelabel.setBounds(5,5,95,15);    
	    titlelabel.setFont(titlefont);
	    
	    pane1 = new ScrollPane();
	    pane1.setBounds(4,29,287,263);
	    add(pane1);
	    pane2  = new ScrollPane();
	    pane2.setBounds(4,29,287,263);
	    add(pane2);
	    
	    Panel pp1 = new Panel();
	    pp1.setBackground(Color.black);
	    add(pp1);
	    pp1.setBounds(4,29,288,264);
	    	    
	    c1 = new Choice();
	    c1.addItem("  [ A/m ] ");
	    c1.addItem("  [ dB mA/m ]");
	    c1.addItem("  [ dB \u00b5A/m ]");
	    add(c1);
	    c1.setBounds(105,2,125,25);
	    //c1.setBackground(bgcolor.brighter());
	    
	    tcanvas12 = new TitleCanvas12(state);
	    add(tcanvas12);
	    tcanvas12.setBounds(0,0,295,25);
	    
	    rwoc6P = new NewOutputCanvas6P(state);
	    pane1.add(rwoc6P);
	    pane1.setBackground(Color.white);
	    rwoc6P.setBounds(0,50,260,5800);
	    
	    rwoc7P = new NewOutputCanvas7P(state);
	    pane2.add(rwoc7P);
	    rwoc7P.setBounds(0,50,260,5800);
	    pane2.setBackground(Color.white);
	    pane1.setVisible(true);
	    pane2.setVisible(false);
	    //Listeners
	    c1.addItemListener(this);
	}


    public void itemStateChanged(ItemEvent evt){
	ItemSelectable ie = evt.getItemSelectable();
	    if(evt.getSource()==c1){
		if(ie.getSelectedObjects()[0]=="  [ A/m ] "){
		    pane1.setVisible(true);
		    pane2.setVisible(false);
		}
		else if(ie.getSelectedObjects()[0]=="  [ dB mA/m ]"){
		    pane1.setVisible(false);
		    pane2.setVisible(true);
		    state.microFlag13 = false;
		    rwoc7P.repaint();
		}
		else if(ie.getSelectedObjects()[0]=="  [ dB \u00b5A/m ]"){
		    pane1.setVisible(false);
		    pane2.setVisible(true);
		    state.microFlag13 = true;
		    rwoc7P.repaint();
		}
	    }
    }	
    
}

class TitleCanvas12 extends Canvas{
	private static final Font normalfont = new Font("Serif",Font.PLAIN,12);
	private static final Font subfont    = new Font("Serif",Font.PLAIN,10);
	private static final Font normalfontB = new Font("Serif",Font.BOLD,12);
	
	private static final Font symbolfont=new Font("Serif",Font.PLAIN,16);
	private static final Font symbolfont2=new Font("Serif",Font.PLAIN,14);
	
	NewGuide_State state;
	public TitleCanvas12(NewGuide_State state){
	    super();
	    this.state = state;
	}
	
	public void paint(Graphics g){
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
	    g.setFont(symbolfont);
	    g.setColor(Color.blue);
	    g.drawString("\u03b8",20,17);
	    //g.setColor(Color.black);
	    g.drawString("\u03b8",21,17);
	    
	    g.setFont(symbolfont2);
	    //g.drawString("\u03c6",78,22);
	    g.drawString("\u03c6",80,22);
	    g.setFont(normalfontB);
	    g.drawString("| H    |",65,17);
	    
	    g.setFont(new Font("Serif",Font.PLAIN,12)); 
	    g.drawString("\u03c6",235,17);
	    g.setFont(new Font("Serif",Font.PLAIN,12)); 
	    g.drawString("= "+MaestroA.rounder(state.phi*180.0/Math.PI,1)+"\u00b0",245,17);
	
	}
}

class NewOutputCanvas6P extends Canvas{
	private static final Font normalfont = new Font("SanSerif",Font.PLAIN,12);
	private static final Font subfont    = new Font("SanSerif",Font.PLAIN,10);
	private static final Font symbolfont=new Font("Serif",Font.PLAIN,14);
	NewGuide_State state;
	public NewOutputCanvas6P(NewGuide_State state){
	    super();
	    this.state = state;
	}
	
	public void paint(Graphics g){
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
	    int x, y, dx, dxx, dy, dyy;
	    double v_normalized, f_normalized;
	    String stmp;
	    FontMetrics fm;
	    x = 10;
	    y = 15;
	    dx = 80;
	    dxx = 15;
	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    //dy = fm.getHeight();
	    dy = 14;
	    dyy = dy+2;
		    
	    g.setColor(Color.black);
	    	    
	    for(int i=0;i<361;i++){
		if(i<10){
		    g.drawString("  "+i+"\u00b0",x+1,y);
		}
		else{
		    g.drawString(""+i+"\u00b0",x,y);
		}
    		g.drawString(""+state.hphigenM[i],x+40,y);
		y+=dyy;
	    }
	}
}
class NewOutputCanvas7P extends Canvas{
	private static final Font normalfont = new Font("SanSerif",Font.PLAIN,12);
	private static final Font subfont    = new Font("SanSerif",Font.PLAIN,10);
	NewGuide_State state;
	public NewOutputCanvas7P(NewGuide_State state){
	    super();
	    this.state = state;
	}
	
	public void paint(Graphics g){
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
	    int x, y, dx, dxx, dy, dyy;
	    double v_normalized;
	    double logfactor = 20.0*0.434294481903;
	    FontMetrics fm;
	    x = 10;
	    y = 15;
	    dx = 80;
	    dxx = 15;
	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    //dy = fm.getHeight();
	    dy = 14;
	    dyy = dy+2;
	    
	    g.setColor(Color.black);
	    	    
	    for(int i=0;i<361;i++){
		if(i<10){
		    g.drawString("  "+i+"\u00b0",x+1,y);
		}
		else{
		    g.drawString(""+i+"\u00b0",x,y);
		}
		if(!state.microFlag13){
		    g.drawString(""+logfactor*Math.log(state.hphigenM[i]*1.0e3),x+40,y);
		}
		else if(state.microFlag13){
		    g.drawString(""+logfactor*Math.log(state.hphigenM[i]*1.0e6),x+40,y);
		}
		y+=dyy;
	    }
	 
	}
}
