// 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.io.*;
import java.applet.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.awt.event.*;
import java.awt.font.*;
import java.net.URL;
import java.text.*;
import java.util.*;
import java.util.Map;
import java.util.Hashtable;
import java.util.jar.Attributes;


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;

    //Mod1State state;
    public Button bupdate;
  
    public Instructions(){
	super();
        //this.state = state;
	setLayout(null);
	setBackground(bgcolor);
	bupdate = new Button("CLOSE");
        bupdate.setBackground(new Color(240,240,255));
	add(bupdate);
        //int buttonx = 380;
        //int buttony = 380;
        int buttonx = 1085;
        //int buttony = 440;
        int buttony = 272;
        int buttonwide = 70;
        int buttonheight = 27;
        
        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);	
    }
    
    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);

        //g.setFont(font_one);
        //fm = g.getFontMetrics();

        //boolean saveOldFlag = MaestroG.useBiggerFont;
        //MaestroG.useBiggerFont = false;
        
        g.setColor(Color.black);
        //g.setFont(state.ttfFont.deriveFont(Font.BOLD,16f));
        g.setFont(new Font("SanSerif",Font.BOLD,16));
        
        g.drawString("Instructions", 15,25);
        
        //g.setFont(state.ttfFont.deriveFont(14f));
        //g.setFont(new Font("SanSerif",Font.PLAIN,14));
        //g.drawString("This module can accomodate linearly polarized plane "+
        //            "waves in both lossy and lossless media.",15,50);
        
        int xcolumn1 = 15; int xcolumn2 = 460; int xcolumn3 = 835;
        int ystart; int y;
        int ytext; int deltaY = 20;
        String s; int nextX;
        ystart = 70;
        ytext = ystart;
        // ASSUMPTIONS
        g.setColor(Color.red);
        //g.setFont(state.ttfFont.deriveFont(Font.BOLD,15f));
        g.setFont(new Font("SanSerif",Font.BOLD,15));
        g.drawString("Assumptions", xcolumn1,ytext);
        g.setColor(Color.black);
        //g.setFont(state.ttfFont.deriveFont(14f));
        g.setFont(new Font("SanSerif",Font.PLAIN,14));
        
        ytext += deltaY;
        //INPUT
        s = "\u2022 Step-index fiber - uniform refractive index in the core";
        nextX = STR.displayString(s,g,xcolumn1,ytext);
        ytext += deltaY;
        s = "\u2022 Multimode propagation ( fiber radius "+STR.ITAL+"R >> \u03bb"+STR.ENDITAL+" )";
        nextX = STR.displayString(s,g,xcolumn1,ytext);
        ytext += deltaY;
        s = "\u2022 Ray optics limit - modes of propagation are characterized";
        nextX = STR.displayString(s,g,xcolumn1,ytext);
        ytext += deltaY;
        s = "   by angles of entrance with quasi-continuum distribution";
        nextX = STR.displayString(s,g,xcolumn1,ytext);
        
        ystart = 70;
        ytext = ystart;
        // INPUT
        g.setColor(Color.red);
        //g.setFont(state.ttfFont.deriveFont(Font.BOLD,15f));
        g.setFont(new Font("SanSerif",Font.BOLD,15));
        
        g.drawString("Input", xcolumn2,ytext);
        g.setColor(Color.black);
        //g.setFont(state.ttfFont.deriveFont(14f));
        g.setFont(new Font("SanSerif",Font.PLAIN,14));
        
        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);
        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);
        ytext += deltaY;
        s = "\u2022 Angle of entrance "+STR.ITAL+"\u03b8"+STR.ENDITAL+""+STR.SUB+"i"+STR.ENDSUB+"";
        nextX = STR.displayString(s,g,xcolumn2,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.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-40,ytext);
        ytext += deltaY;
        s = "larger than in the cladding.  Larger index difference between core and cladding increases light";
        nextX = STR.displayString(s,g,xcolumn2-40,ytext);
        ytext += deltaY;
        s = "acceptance  but also increases  modal  dispersion, thus  degrading the bandwidth of the  fiber.";
        nextX = STR.displayString(s,g,xcolumn2-40,ytext);
        ytext += deltaY;
        s = "The bandwidth is also inversely proportional to the length of the fiber.";
        nextX = STR.displayString(s,g,xcolumn2-40,ytext);
        
        ystart = 70;
        ytext = ystart;
        
        // OUTPUT
        g.setColor(Color.red);
        //g.setFont(state.ttfFont.deriveFont(Font.BOLD,15f));
        g.setFont(new Font("SanSerif",Font.BOLD,15));
        g.drawString("Displayed Information", xcolumn3,ytext);
        g.setColor(Color.black);
        //g.setFont(state.ttfFont.deriveFont(14f));
        g.setFont(new Font("SanSerif",Font.PLAIN,14));
        ytext += deltaY;
        s = "\u2022 Angles of propagation and ray paths";
        nextX = STR.displayString(s,g,xcolumn3,ytext);
        ytext += deltaY;
        // CHANGE ==============================================================
        s = "\u2022 Maximum angle of acceptance for optical";
        nextX = STR.displayString(s,g,xcolumn3,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);
        ytext += deltaY;
        s = "\u2022 Properties of optical propagation";
        nextX = STR.displayString(s,g,xcolumn3,ytext);
        ytext += deltaY;
        s = "\u2022 Maximum data rate limited by modal dispersion";
        nextX = STR.displayString(s,g,xcolumn3,ytext);
        
        drawCopyRight(g);

        //MaestroG.useBiggerFont = saveOldFlag;

    }


    public void drawCopyRight(Graphics g) {
        int deltaY = 20;
        int startingY = getSize().height - 70;
        int startingX = 0;
        FontMetrics fm;
        g.setColor(Color.black);
        g.setColor(Color.black);
        //g.setFont(normalfont14);
        //g.setFont(state.ttfFont.deriveFont(14f));
        g.setFont(new Font("SanSerif",Font.PLAIN,14));
        fm = g.getFontMetrics();
        g.drawString("Applet Design: Umberto Ravaioli",
                     startingX+10,startingY+deltaY);
        
        //MaestroG.superscripter("Interactive Java","TM"," platform:  www.amanogawa.com",
        //                       g,14,startingX,startingY+2*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+= 10;

        //g.setFont(state.ttfFont.deriveFont(14f));
        g.drawString("All Rights Reserved",startingX+10,startingY+3*deltaY);
        g.drawLine(startingX,startingY+5,
                   startingX+lineLength+10,startingY+5);
        g.drawLine(startingX+lineLength+10,startingY+5,
                   startingX+lineLength+10,startingY+4*deltaY);
    }

//----------------------------------------------------------------------------------------    
}//End
    

