// About.java
/* A Java class for
 * LineImpedance.java
 * Electromagnetic Transmission Line Applet
 * Applet without Smith Chart - Prepared by Umberto Ravaioli 
 * for 6th edition of Fundamentals of Applied Electromagnetics Book
 * May 2009 - All Rights Reserved
 */   

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;

public class Instructions extends Panel {
    
    private static final Color bgcolor = new Color(255,255,245);
    //private static final Color bgcolor = Color.white;
    
    public TextField epsilon;
    private Paint paint;
    
    private Image im;
    private Graphics buf;
    public Button bupdate;
    Oblique_State state;
    
    private BufferedImage bullet;
  
    public Instructions(Oblique_State state){
	super();
        this.state = state;	
        setLayout(null);
	
	getImages();
	setBackground(bgcolor);
	bupdate = new Button("CLOSE");
        bupdate.setBackground(new Color(240,240,255));
        bupdate.setFont(new Font("SanSerif",Font.PLAIN,state.font12));
        
	add(bupdate);
        int buttonx = state.s1000+state.s85;
        int buttony = state.s200+state.s72;
        int buttonwide = state.s70;
        int buttonheight = state.s27;
        
        bupdate.setBounds(buttonx,buttony,buttonwide,buttonheight);	
        Panel ps7 = new Panel();
	    ps7.setBackground(Color.lightGray);
	    add(ps7);
	    ps7.setBounds(buttonx-1,buttony-1,buttonwide+2,buttonheight+2);
	    
	Panel ps8 = new Panel();
	    ps8.setBackground(Color.black);
	    add(ps8);
	    ps8.setBounds(buttonx-2,buttony-2,buttonwide+4,buttonheight+4);	
    }


    private void getImages() {
        // read in the bullet image, because CHEERPJ does not render this
	//  symbol in any font!  (java to javascript converter)
        try {
            //bullet = ImageIO.read(getClass().getResource("bullet.png"));
	    BufferedImage img =
		ImageIO.read(getClass().getResource("bullet.png"));
	    int targetWidth = (int) (state.sfactor * img.getWidth());
	    int targetHeight = (int) (state.sfactor * img.getHeight());
	    bullet =
		new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB);
	    Graphics2D graphics2D = bullet.createGraphics();
	    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
					RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	    graphics2D.drawImage(img, 0, 0, targetWidth, targetHeight, 0, 0,
				 img.getWidth(), img.getHeight(), null);
	    graphics2D.dispose();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    public void paint(Graphics g){
            
	    if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawCanvas(buf);
	    }
	    else{
		drawCanvas(buf);
	    }
	    g.drawImage(im,0,0,null);
    }
	
	//Addition to reduce flicker new routine
    public void update(Graphics g){		// added to avoid clearing
            paint(g);
    }
    
    public void clear(){
	    this.getGraphics().clearRect(0,0,getSize().width,getSize().height);
	    repaint();
    }
    
    public void drawCanvas(Graphics g){
        FontMetrics fm;
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);        
        g.clearRect(0,0,getSize().width-1,getSize().height-1);

        //boolean saveOldFlag = MaestroG.useBiggerFont;
        //MaestroG.useBiggerFont = false;
        
        g.setColor(Color.black);
        g.setFont(new Font("SanSerif",Font.BOLD,state.font16));
        
        g.drawString("Instructions", state.s15,state.s25);
        
        int xcolumn1 = state.s15; int xcolumn2 = state.s400+state.s60; int xcolumn3 = state.s800+state.s35;
        int ystart; int y;
        int ytext; int deltaY = state.s20;
        String s; 
        int nextX;
        ystart = state.s70;
        ytext = ystart;
        
        // ASSUMPTIONS
        g.setColor(Color.red);
        g.setFont(new Font("SanSerif",Font.BOLD,state.font15));
        g.drawString("Assumptions", xcolumn1,ytext);
        g.setColor(Color.black);
        g.setFont(new Font("SanSerif",Font.PLAIN,state.font14));
        
        ytext += deltaY;
        //INPUT
        //s = "\u2022 Step-index fiber - uniform refractive index in the core";
        //nextX = STR.displayString(s,g,xcolumn1,ytext);
	g.drawImage(bullet,xcolumn1,ytext-bullet.getHeight(),this);
        s = " Step-index fiber - uniform refractive index in the core";
	nextX = STR.displayString(s,g,xcolumn1+bullet.getWidth(),ytext);
	
        ytext += deltaY;
        //s = "\u2022 Multimode propagation ( fiber radius "+STR.ITAL+"R >> \u03bb"+STR.ENDITAL+" )";
        //nextX = STR.displayString(s,g,xcolumn1,ytext);
	g.drawImage(bullet,xcolumn1,ytext-bullet.getHeight(),this);
        s = " Multimode propagation ( fiber radius "+STR.ITAL+"R >> \u03bb"+STR.ENDITAL+" )";
        nextX = STR.displayString(s,g,xcolumn1+bullet.getWidth(),ytext);
	
        ytext += deltaY;
        //s = "\u2022 Ray optics limit - modes of propagation are characterized";
        //nextX = STR.displayString(s,g,xcolumn1,ytext);
	g.drawImage(bullet,xcolumn1,ytext-bullet.getHeight(),this);
        s = " Ray optics limit - modes of propagation are characterized";
        nextX = STR.displayString(s,g,xcolumn1+bullet.getWidth(),ytext);
	
        ytext += deltaY;
        s = "   by angles of entrance with quasi-continuum distribution";
        nextX = STR.displayString(s,g,xcolumn1,ytext);
        ytext += deltaY;
        //s = "\u2022 Simple 2D analysis is limited to rays crossing the axis";
        //nextX = STR.displayString(s,g,xcolumn1,ytext);
	g.drawImage(bullet,xcolumn1,ytext-bullet.getHeight(),this);
        s = " Simple 2D analysis is limited to rays crossing the axis";
        nextX = STR.displayString(s,g,xcolumn1+bullet.getWidth(),ytext);
	
        ytext += deltaY;
        s = "   (meridional rays). Skew rays propagating at an additional";
        nextX = STR.displayString(s,g,xcolumn1,ytext);
        ytext += deltaY;
        s = "   angle without crossing the axis, are not considered.";
        nextX = STR.displayString(s,g,xcolumn1,ytext);
        ytext += deltaY;
        s = "   (Equivalent to a symmetric slab wave guide)";
        nextX = STR.displayString(s,g,xcolumn1,ytext);
        
        ystart = state.s70;
        ytext = ystart;
        // INPUT
        g.setColor(Color.red);
        g.setFont(new Font("SanSerif",Font.BOLD,state.font15));
        
        g.drawString("Input", xcolumn2,ytext);
        g.setColor(Color.black);
        g.setFont(new Font("SanSerif",Font.PLAIN,state.font14));
        
        ytext += deltaY;
        //INPUT
        //s = "\u2022 Relative permittivity \u03b5"+STR.SUB+"r"+STR.ENDSUB+" or index of refraction "+STR.ITAL+"n"+STR.ENDITAL;
        //nextX = STR.displayString(s,g,xcolumn2,ytext);
	g.drawImage(bullet,xcolumn2,ytext-bullet.getHeight(),this);
        s = " Relative permittivity \u03b5"+STR.SUB+"r"+STR.ENDSUB+" or index of refraction "+STR.ITAL+"n"+STR.ENDITAL;
        nextX = STR.displayString(s,g,xcolumn2+bullet.getWidth(),ytext);

        ytext += deltaY;
        s = "  of dielectric media 1, 2, and 3";
        nextX = STR.displayString(s,g,xcolumn2,ytext);
        ytext += deltaY;
        //s = "\u2022 Wave frequency "+STR.ITAL+"f"+STR.ENDITAL;
        //nextX = STR.displayString(s,g,xcolumn2,ytext);
	g.drawImage(bullet,xcolumn2,ytext-bullet.getHeight(),this);
        s = " Wave frequency "+STR.ITAL+"f"+STR.ENDITAL;
        nextX = STR.displayString(s,g,xcolumn2+bullet.getWidth(),ytext);	
	
        ytext += deltaY;
        //s = "\u2022 Angle of entrance "+STR.ITAL+"\u03b8"+STR.ENDITAL+""+STR.SUB+"i"+STR.ENDSUB+"";
        //nextX = STR.displayString(s,g,xcolumn2,ytext);
	g.drawImage(bullet,xcolumn2,ytext-bullet.getHeight(),this);
        s = " Angle of entrance "+STR.ITAL+"\u03b8"+STR.ENDITAL+""+STR.SUB+"i"+STR.ENDSUB+"";
        nextX = STR.displayString(s,g,xcolumn2+bullet.getWidth(),ytext);

        ytext += deltaY;
        //s = "\u2022 Radius of the core "+STR.ITAL+"R"+STR.ENDITAL+" and length of the fiber "+STR.ITAL+"l"+STR.ENDITAL;
        //nextX = STR.displayString(s,g,xcolumn2,ytext);
	g.drawImage(bullet,xcolumn2,ytext-bullet.getHeight(),this);
        s = " Radius of the core "+STR.ITAL+"R"+STR.ENDITAL+" and length of the fiber "+STR.ITAL+"l"+STR.ENDITAL;
        nextX = STR.displayString(s,g,xcolumn2+bullet.getWidth(),ytext);
                
        g.setColor(Color.blue.darker());
        ytext += 3*deltaY;
        s = "To guide rays by total internal reflection, the index of refraction in the core of the fiber must be";
        nextX = STR.displayString(s,g,xcolumn2-state.s40,ytext);
        ytext += deltaY;
        s = "larger than in the cladding.  Larger index difference between core and cladding increases light";
        nextX = STR.displayString(s,g,xcolumn2-state.s40,ytext);
        ytext += deltaY;
        s = "acceptance  but also increases  modal  dispersion, thus  degrading the bandwidth of the  fiber.";
        nextX = STR.displayString(s,g,xcolumn2-state.s40,ytext);
        ytext += deltaY;
        s = "The bandwidth is also inversely proportional to the length of the fiber.";
        nextX = STR.displayString(s,g,xcolumn2-state.s40,ytext);
        
        ystart = state.s70;
        ytext = ystart;
        
        // OUTPUT
        g.setColor(Color.red);
        g.setFont(new Font("SanSerif",Font.BOLD,state.font15));
        g.drawString("Displayed Information", xcolumn3,ytext);
        g.setColor(Color.black);
        g.setFont(new Font("SanSerif",Font.PLAIN,state.font14));
        ytext += deltaY;
        //s = "\u2022 Angles of propagation and ray paths";
        //nextX = STR.displayString(s,g,xcolumn3,ytext);
	g.drawImage(bullet,xcolumn3,ytext-bullet.getHeight(),this);
        s = " Angles of propagation and ray paths";
        nextX = STR.displayString(s,g,xcolumn3+bullet.getWidth(),ytext);

        ytext += deltaY;
        // CHANGE ==============================================================
        //s = "\u2022 Maximum angle of acceptance for optical";
        //nextX = STR.displayString(s,g,xcolumn3,ytext);
	g.drawImage(bullet,xcolumn3,ytext-bullet.getHeight(),this);
        s = " Maximum angle of acceptance for optical";
        nextX = STR.displayString(s,g,xcolumn3+bullet.getWidth(),ytext);

        ytext += deltaY;
        s = "    guidance "+STR.ITAL+"\u03b8"+STR.ENDITAL+""+STR.SUB+"imax"+STR.ENDSUB+"";
        nextX = STR.displayString(s,g,xcolumn3,ytext);
        //======================================================================
        ytext += deltaY;
        //s = "\u2022 Numerical Aperture (NA)";
	//nextX = STR.displayString(s,g,xcolumn3,ytext);
	g.drawImage(bullet,xcolumn3,ytext-bullet.getHeight(),this);
        s = " Numerical Aperture (NA)";
        nextX = STR.displayString(s,g,xcolumn3+bullet.getWidth(),ytext);

        ytext += deltaY;
        //s = "\u2022 Properties of optical propagation";
        //nextX = STR.displayString(s,g,xcolumn3,ytext);
	g.drawImage(bullet,xcolumn3,ytext-bullet.getHeight(),this);
        s = " Properties of optical propagation";
        nextX = STR.displayString(s,g,xcolumn3+bullet.getWidth(),ytext);

        ytext += deltaY;
        //s = "\u2022 Maximum data rate limited by modal dispersion";
        //nextX = STR.displayString(s,g,xcolumn3,ytext);
	g.drawImage(bullet,xcolumn3,ytext-bullet.getHeight(),this);
        s = " Maximum data rate limited by modal dispersion";
        nextX = STR.displayString(s,g,xcolumn3+bullet.getWidth(),ytext);	
        
        drawCopyRight(g);
        //MaestroG.useBiggerFont = saveOldFlag;
    }

    public void drawCopyRight(Graphics g) {
        int deltaY = state.s20;
        int startingY = getSize().height - state.s70;
        int startingX = 0;
        FontMetrics fm;
        g.setColor(Color.black);
        g.setColor(Color.black);
        g.setFont(new Font("SanSerif",Font.PLAIN,state.font14));
        fm = g.getFontMetrics();
        g.drawString("Applet Design: Umberto Ravaioli",
                     startingX+10,startingY+deltaY);
        
        String s = "Interactive Java"+STR.SUP+"TM"+STR.ENDSUP+" platform:  www.amanogawa.com";
        int nextX = STR.displayString(s,g,startingX+10,startingY+2*deltaY);
        int lineLength = fm.stringWidth("Interactive JavaTM platform:  www.amanogawa.com");
        lineLength+= state.s10;

        g.drawString("All Rights Reserved",startingX+10,startingY+3*deltaY);
        g.drawLine(startingX,startingY+state.s5,
                   startingX+lineLength+state.s10,startingY+state.s5);
        g.drawLine(startingX+lineLength+state.s10,startingY+state.s5,
                   startingX+lineLength+state.s10,startingY+4*deltaY);
    }
//----------------------------------------------------------------------------------------    
}//End
