import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.lang.*;

public class PR2 extends Panel implements ActionListener{
	protected static final Color bgcolor = new Color(236,236,236);
	protected Label lab1[], lab2[];
	public Label titlelabel;
	public Button exampleA, exampleB, exampleC;
        public boolean IsExample1, IsExample2, IsExample3, IsGeneral_Input;
        public Scrollbar slider1;
        public int SCROLLMIN=750, SCROLLMAX=1001;
        private int SleepTime = 50;
        
	protected static final Font labfont=new Font("SanSerif",Font.PLAIN,12);
	protected static final Font titlefont=new Font("SanSerif",Font.BOLD,16);
        
	public PR2(){
	
		super();
		setLayout(null);
                setBackground(bgcolor);
                
                int startx = 12;
                int starty = 30;
                int y, dy;
                int textheight = 20;
                int textwidth = 100;
                dy = 68;
                y = starty;
                
                IsExample1 = true;
                IsExample2 = false;
                IsExample3 = false;
                IsGeneral_Input = false;
                
                exampleA = new Button("Example 1");
		exampleA.setBackground(Color.white);
		exampleA.setBounds(startx,starty,textwidth,textheight);
                add(exampleA);
                
                y +=dy;
                exampleB = new Button("Example 2");
		exampleB.setBackground(Color.white);
		exampleB.setBounds(startx,y,textwidth,textheight);
                add(exampleB);
                
                y +=dy;
                exampleC = new Button("Example 3");
		exampleC.setBackground(Color.white);
		exampleC.setBounds(startx,y,textwidth,textheight);
                add(exampleC);
                
                y +=dy;
                slider1 = new Scrollbar(Scrollbar.HORIZONTAL,SCROLLMAX-1-SleepTime,1,SCROLLMIN,SCROLLMAX);
                slider1.setBounds(7,238,150,15);
                slider1.setBackground(Color.white);
                add(slider1);
                Panel p1 = new Panel();
                    p1.setBackground(Color.black);
                    add(p1);
                    p1.setBounds(6,237,152,17);
                
                //Listeners
		exampleA.addActionListener(this);
                exampleB.addActionListener(this);
                exampleC.addActionListener(this);
	}
	
	public void paint(Graphics g){
            
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
	    g.clearRect(0,0,getSize().width-2,getSize().height);
	                
            int startx = 12;
            int starty = 45;
            int y, dy;
            dy = 68;
            y = starty;
                
            g.setColor(Color.gray);
            MaestroG.subscripterBold("Examples","","",g,14,startx+1,startx+6);
            g.setColor(Color.red.darker());
            MaestroG.subscripterBold("Examples","","",g,14,startx,startx+5);
            
            if(IsGeneral_Input){
                g.setColor(Color.black);
                MaestroG.subscripter("(click button to activate choice)","","",g,11,120,startx+5);
            }
            
            Color colore1 = Color.red;
            Color colore2 = Color.black; 
            Color colore3 = Color.black;
            
            if(IsExample1){
                colore1 = Color.red.darker();
                colore2 = Color.blue.darker();
                colore3 = Color.blue.darker();                
            }
            else if(IsExample2){
                colore1 = Color.blue.darker();
                colore2 = Color.red.darker();
                colore3 = Color.blue.darker();
            }
            else if(IsExample3){
                colore1 = Color.blue.darker();
                colore2 = Color.blue.darker();
                colore3 = Color.red.darker();
            }
            else if(IsGeneral_Input){
                colore1 = Color.black;
                colore2 = Color.black;
                colore3 = Color.black;
            }
            
            g.setColor(colore1);
            MaestroG.subscripter("Slightly Lossy","","",g,13,120,y);
            MaestroG.subscripter("E (z = 0) = 10.0","","[V/m]",g,12,20,y+20);
            MaestroG.subscripter("\u03c3",""," = 0.001 [S/m]",g,12,180,y+20);
            printfrequency(1.0E7,20,y+40,g);
            MaestroG.subscripter("\u03b5","r"," = 9.0",g,12,180,y+40);
            if(IsExample1){g.setColor(Color.red); g.fillRect(3,y-7,5,5);}
            
            y += dy;
            g.setColor(colore2);
            MaestroG.subscripter("Moderately Lossy","","",g,13,120,y);
            MaestroG.subscripter("E (z = 0) = 10.0","","[V/m]",g,12,20,y+20);
            MaestroG.subscripter("\u03c3",""," = 0.01 [S/m]",g,12,180,y+20);
            printfrequency(1.0E7,20,y+40,g);
            MaestroG.subscripter("\u03b5","r"," = 9.0",g,12,180,y+40);
            if(IsExample2){g.setColor(Color.red); g.fillRect(3,y-7,5,5);}
            
            y += dy;
            g.setColor(colore3);
            MaestroG.subscripter("Highly Lossy","","",g,13,120,y);
            MaestroG.subscripter("E (z = 0) = 10.0","","[V/m]",g,12,20,y+20);
            MaestroG.subscripter("\u03c3",""," = 1.0 [S/m]",g,12,180,y+20);
            printfrequency(1.0E7,20,y+40,g);
            MaestroG.subscripter("\u03b5","r"," = 9.0",g,12,180,y+40);
            if(IsExample3){g.setColor(Color.red); g.fillRect(3,y-7,5,5);}
            
            
            //------------------------------------------------------------
            g.setColor(Color.black);
            int sety = 265;
            int sety2 = 260;
            MaestroG.subscripter("Animation speed","","",g,10,40,sety);
            g.setColor(Color.blue.darker());
            MaestroG.drawArrowtip(15,sety2,8,g);
            MaestroG.drawArrowtip(22,sety2,8,g);

            g.setColor(Color.red.darker());
            MaestroG.drawArrowtip(142,sety2,7,g);
            MaestroG.drawArrowtip(149,sety2,7,g);
            //--------------------------------------------------------------
            
        }
        	
	public void actionPerformed(ActionEvent evt){
		if(evt.getSource() == exampleA){
                    IsExample1 = true;
                    IsExample2 = false;
                    IsExample3 = false;
                    IsGeneral_Input = false;
                    repaint();
		}
                else if(evt.getSource() == exampleB){
                    IsExample1 = false;
                    IsExample2 = true;
                    IsExample3 = false;
                    IsGeneral_Input = false;
                    repaint();
		}
                else if(evt.getSource() == exampleC){
                    IsExample1 = false;
                    IsExample2 = false;
                    IsExample3 = true;
                    IsGeneral_Input = false;
                    repaint();
		}
	}
        
        public void printfrequency(double frequency, int x, int y, Graphics g){
            double f_normalized = 0.0;
            int xshiftf = 0;
            if(frequency < 1.0E3){
		    f_normalized = frequency;
		    MaestroG.subscripterSansItalic2("f",""," = "+MaestroA.rounder(f_normalized,6)+"  Hz","",g,12,x+xshiftf,y);	
		}
		else if(frequency < 1.0E6 && frequency >= 1.0E3  ){
		    f_normalized = frequency/1.0E3;
                    MaestroG.subscripterSansItalic2("f",""," = "+MaestroA.rounder(f_normalized,6)+"  kHz","",g,12,x+xshiftf,y);
		    
		}
		else if(frequency < 1.0E9 && frequency >= 1.0E6 ){
		    f_normalized = frequency/1.0E6;
                    MaestroG.subscripterSansItalic2("f",""," = "+MaestroA.rounder(f_normalized,6)+"  MHz","",g,12,x+xshiftf,y);
		    
		}
		else if(frequency < 1.0E12 && frequency >= 1.0E9 ){
		    f_normalized = frequency/1.0E9;
                    MaestroG.subscripterSansItalic2("f",""," = "+MaestroA.rounder(f_normalized,6)+"  GHz","",g,12,x+xshiftf,y);
		    
		}
		else if(frequency < 1.0E15 && frequency >= 1.0E12 ){
		    f_normalized = frequency/1.0E12;
                    MaestroG.subscripterSansItalic2("f",""," = "+MaestroA.rounder(f_normalized,6)+"  THz","",g,12,x+xshiftf,y);
		    
		}
		else if(frequency < 1.0E18 && frequency >= 1.0E15 ){
		    f_normalized = frequency/1.0E15;
                    MaestroG.subsupspecial2("f",""," = "+MaestroA.rounder(f_normalized,2)+" x 10","3","  THz",g,12,x+xshiftf,y);
		    
		}
                else if(frequency < 1.0E21 && frequency >= 1.0E18 ){
		    f_normalized = frequency/1.0E18;
                    MaestroG.subsupspecial2("f",""," = "+MaestroA.rounder(f_normalized,2)+" x 10","6","  THz",g,12,x+xshiftf,y);
		    
		}
                else if(frequency < 1.0E24 && frequency >= 1.0E21 ){
		    f_normalized = frequency/1.0E21;
                    MaestroG.subsupspecial2("f",""," = "+MaestroA.rounder(f_normalized,2)+" x 10","9","  THz",g,12,x+xshiftf,y);
		    
		}
        }
}

