//ChoicePanel.java
//import java.applet.Applet;

import java.awt.*;
import java.awt.event.*;
//import java.applet.*;
//import java.lang.*;  
//import java.awt.image.*;
import java.net.*;
import java.awt.geom.*;

public class ChoicePanel extends Panel implements ItemListener{ 
	
	public Checkbox h1, h2, h3, h4, h5, h6, c1, c2, c3, c4, c5, c6, f1, f2;
        public CheckboxGroup hgrid, cgrid, cfield;

	private  Label lab1, lab2;
        
	public Button information;
	public Panel ps7 = new Panel();
        public Panel ps8 = new Panel();
        
        private double delta_lambda = 0.01;
        private boolean IsMagnetic = true;
        
        private int ypos0 = 6;
        private int ypos1 = 45; 
        private int ypos2 = 70;
        private int xpos0 = 66; 
        private int xpos1 = 26;
        private int xpos2 = 280;
        private int xpos3 = 250; 
        //private static final Color bgcolor = new Color(216,230,230);
	private static final Color bgcolor = Color.white;
	
	public ChoicePanel(){
		super();
		setLayout(null);
		setBackground(bgcolor);
		Font labelfont=new Font("SanSerif",Font.BOLD,11);
		
                cgrid = new CheckboxGroup();
                hgrid = new CheckboxGroup();
                cfield = new CheckboxGroup();
                
		//c1=new Checkbox(" E( \u03b8 ) far field",cgrid,false);
                //c2=new Checkbox(" E( \u03b8 ) near field ",cgrid,false);
                //c3=new Checkbox(" E( r ) near field ",cgrid,false);
                //c4=new Checkbox(" E( \u03b8, near ) - E( \u03b8, far )",cgrid,false);
                c1=new Checkbox("",cgrid,true);
                c2=new Checkbox("",cgrid,false);
                c3=new Checkbox("",cgrid,false);
                c4=new Checkbox("",cgrid,false);
                
                c5=new Checkbox("   Show all ",cgrid,false);
                c6=new Checkbox("   Formulas ",cgrid,false);
                                                
                f1=new Checkbox("Magnetic Field",cfield,true);
                f2=new Checkbox("Electric Field",cfield,false);
                                
		add(c1); // Far Field Approximation
		c1.setFont(new Font("SanSerif",Font.PLAIN,12));
		c1.setBackground(bgcolor);
		c1.setForeground(Color.red.darker());
		c1.setBounds(xpos1,ypos2,23,20);
                c1.setVisible(true);
                
                add(c2); // Exact Solution
		c2.setFont(new Font("SanSerif",Font.PLAIN,12));
		c2.setBackground(bgcolor);
		c2.setForeground(Color.black);
                c2.setBounds(xpos1,ypos1,23,20);
                c2.setVisible(true);
                
                add(c3); // Exact radial solution - only for Elctric Field
		c3.setFont(new Font("SanSerif",Font.PLAIN,12));
		c3.setBackground(bgcolor);
		c3.setForeground(Color.blue.darker());
		c3.setBounds(xpos3,ypos2,23,20);
                c3.setVisible(false);
                
                add(c4); // Difference: Exact - Far Field Approximation
		c4.setFont(new Font("SanSerif",Font.PLAIN,12));
		c4.setBackground(bgcolor);
		c4.setForeground(Color.black);
                c4.setBounds(xpos3,ypos1,23,20);
                c4.setVisible(true);
                
                add(f1);
		f1.setFont(new Font("SanSerif",Font.PLAIN,12));
		f1.setBackground(bgcolor);
		f1.setForeground(Color.blue.darker());
                f1.setBounds(xpos0,ypos0,120,18);
                
                add(f2);
		f2.setFont(new Font("SanSerif",Font.PLAIN,12));
		f2.setBackground(bgcolor);
		f2.setForeground(Color.red.darker());
                f2.setBounds(xpos2,ypos0,120,18);
                
                information = new Button("ABOUT");
                information.setForeground(Color.blue);
                information.setBackground(new Color(240,240,255));
                information.setBackground(Color.white);
                
                //add(information);
                information.setBounds(530,5,70,23);
                
                //Panel ps7 = new Panel();
                ps7.setBackground(Color.lightGray);
                add(ps7);
                ps7.setBounds(529,4,72,25);
	    
                //Panel ps8 = new Panel();
                ps8.setBackground(Color.black);
                add(ps8);
                ps8.setBounds(528,3,74,27);
                
                f1.addItemListener(this);
                f2.addItemListener(this);
    
	}
        
    @Override
	public void paint(Graphics g){
	    //g.clearRect(0,0,getSize().width,getSize().height);
	    //g.setColor(bgcolor.darker());
	    //g.fillRect(0,getSize().height-2,getSize().width,2);
	    //g.fillRect(getSize().width-2,0,2,getSize().height);
	    //g.setColor(bgcolor.brighter());
	    //g.fillRect(0,0,2,getSize().height-1);
	    //g.fillRect(0,0,getSize().width-2,2);
            
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
            g.clearRect(0,0,getSize().width-1,getSize().height-1);
	
		//Draw the background	
		g.setColor(Color.black);
		g.drawLine(0,getSize().height-1,getSize().width-1,getSize().height-1);
		g.drawLine(getSize().width-1,0,getSize().width-1,getSize().height-1);
		//g.setColor(Color.white);
		
		g.drawLine(0,0,getSize().width-1,0);
		g.drawLine(0,0,0,getSize().height-1);
                
                g.setColor(Color.black);
                //g.drawLine(0,25,getSize().width-1,25);
                //g.drawLine(0,50,getSize().width-1,50);
                //g.drawLine(getSize().width*9/20,0,getSize().width*9/20,50);
                
                //g.drawString("Range   L = "+delta_lambda,20,20);
                int xshift = 35;
                if(!IsMagnetic){
                    g.setColor(Color.red.darker());
                    //MaestroG.subscripterItalic("E","","(\u03b8)    [exact]",g,13,xpos1+xshift,ypos1+10);
                    //MaestroG.subscripterItalic("E","FF","(\u03b8)    [far-field]",g,13,xpos1+xshift,ypos2+10);
                    //MaestroG.subscripterItalic("E(\u03b8) \u2212 E","FF","(\u03b8)",g,13,xpos3+xshift,ypos1+10);
                    //MaestroG.subscripterItalic("E","","( r )    [exact]",g,13,xpos3+xshift,ypos2+10);
                    
                    MaestroG.subsubsupItalic("E","\u03b8","","","       [exact solution]","","",g,14,xpos1+xshift,ypos1+15);
                    MaestroG.subsubsupItalic("E","\u03b8FF","","","   [far-field approx.]","","",g,14,xpos1+xshift,ypos2+15);
                    MaestroG.subsubsupItalic("E","\u03b8"," \u2212 E","\u03b8FF","     [error]","","",g,14,xpos3+xshift,ypos1+15);
                    MaestroG.subsubsupItalic("E","R","","","    [exact solution]","","",g,14,xpos3+xshift,ypos2+15);
                }
                else{
                    g.setColor(Color.blue.darker());
                    //MaestroG.subscripterItalic("H","","(\u03b8)    [exact]",g,13,xpos1+xshift,ypos1+10);
                    //MaestroG.subscripterItalic("H","FF","(\u03b8)    [far-field]",g,13,xpos1+xshift,ypos2+10);
                    //MaestroG.subscripterItalic("H(\u03b8) \u2212 H","FF","(\u03b8)",g,13,xpos3+xshift,ypos1+10);
                    
                    MaestroG.subsubsupItalic("H","\u03c6","","","       [exact solution]","","",g,14,xpos1+xshift,ypos1+15);
                    MaestroG.subsubsupItalic("H","\u03c6FF","","","   [far-field approx.]","","",g,14,xpos1+xshift,ypos2+15);
                    MaestroG.subsubsupItalic("H","\u03c6"," \u2212 H","\u03c6FF","     [error]","","",g,14,xpos3+xshift,ypos1+15);
                    
                }
                int down = 6;
                if(IsMagnetic){
                    g.setColor(Color.black);
                    
                    // tab for H
                    g.drawLine(0,20+down,40,20+down);
                    g.drawLine(40,20+down,40,8);
                    g.drawLine(40,8,45,3);
                    g.drawLine(45,3,195,3);
                    g.drawLine(195,3,200,8);
                    g.drawLine(200,8,200,20+down);
                    g.drawLine(200,20+down,470,20+down);
                    
                    // tab for E
                    g.drawLine(240,20+down,240,8);
                    g.drawLine(240,8,245,3);
                    g.drawLine(245,3,395,3);
                    g.drawLine(395,3,400,8);
                    g.drawLine(400,8,400,20+down);
                }
                else{
                    // tab for E
                    g.setColor(Color.black);
                    g.drawLine(0,20+down,240,20+down);
                    g.drawLine(240,20+down,240,8);
                    g.drawLine(240,8,245,3);
                    g.drawLine(245,3,395,3);
                    g.drawLine(395,3,400,8);
                    g.drawLine(400,8,400,20+down);
                    g.drawLine(400,20+down,470,20+down);
                    
                    //tab for H
                    g.drawLine(40,20+down,40,8);
                    g.drawLine(40,8,45,3);
                    g.drawLine(45,3,195,3);
                    g.drawLine(195,3,200,8);
                    g.drawLine(200,8,200,20+down);
                    
                }
                
	}
	public synchronized void setDeltaLambda(double delta_lambda){
            this.delta_lambda = delta_lambda;
        }
        
        public void itemStateChanged(ItemEvent evt){
	    ItemSelectable ie = evt.getItemSelectable();
	    
            if(evt.getSource()== f1){
                IsMagnetic = true;
                c3.setVisible(false);
                repaint();
                
            }
            
            if(evt.getSource()== f2){
                IsMagnetic = false;
                c3.setVisible(true);
                repaint();
            }
        }

    
} // ChoicePanel.java
