// 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,250);
    //private static final Color bgcolor = Color.white;
    
    public TextField epsilon;
    private Paint paint;
    
    private Image im;
    private Graphics buf;
    public Button bupdate;
    
    NewGuide_State state;
  
    public Instructions(NewGuide_State state){
	super();
        this.state = state;
	setLayout(null);
	setBackground(bgcolor);
	
        // update button
	bupdate = new Button("CLOSE");
        bupdate.setBackground(new Color(240,240,255));
	add(bupdate);
        int buttonx = 450;
        int buttony = 230;
        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.drawString("Instructions", 20,25);
        g.setColor(Color.red);
        g.setFont(state.ttfFont.deriveFont(Font.BOLD,15f));
        g.drawString("Input", 25,50);
        g.drawString("Displayed Information", 325,50);
        g.setColor(Color.black);
        g.setFont(state.ttfFont.deriveFont(14f));
        int deltaY = 20;
        //INPUT
        g.drawString("a = inner conductor radius", 25,80);
        g.drawString("b = outer conductor radius", 25,80+deltaY);
        MaestroG.subscripter("\u03b5","r"," = relative permittivity of dielectric",
                             g,14,25,80+2*deltaY);
        g.drawString("\u03c3 = conductivity of dielectric",25,80+3*deltaY);
        MaestroG.subscripter("\u03c3","c"," = conductivity of conductors",
                             g,14,25,80+4*deltaY);
        MaestroG.subscripter("\u03bc = \u03bc","0"," for dielectric and conductors",
                             g,14,25,80+5*deltaY);
        //OUTPUT
        g.drawString("Line Parameters C\u00b4, L\u00b4, R\u00b4"+
                     " G\u00b4", 325,80);
        MaestroG.subscripter("Z","0"," = characteristic impedance",
                             g,14,325,80+deltaY);
        g.drawString("\u03b1 = attenuation constant",325,80+2*deltaY);
        g.drawString("\u03b2 = phase",325,80+3*deltaY);

        FontMetrics fmNormal,fmSub;
        g.setFont(state.ttfFont.deriveFont(14f));
        fmNormal = g.getFontMetrics();
        g.setFont(state.ttfFont.deriveFont(12f));
        fmSub = g.getFontMetrics();
        g.setFont(state.ttfFont.deriveFont(14f)); // reset
        int len1, len2;
        len1 = fmNormal.stringWidth("\u03bb = \u03bb");
        len1 += fmSub.stringWidth("0");
        len1 += fmNormal.stringWidth("/\u221A");
        len2 = fmNormal.stringWidth("\u03b5");
        len2 += fmSub.stringWidth("r");

        //dblsubscriptor("\u03bb = \u03bb","0","/\u221A\u03b5","r","",
        //               g,325,80+4*deltaY);
        MaestroG.subscripter("\u03bb = \u03bb","0","/\u221A",
                             g,14,325,80+4*deltaY);
        MaestroG.subscripter("\u03b5","r","",
                             g,14,325+len1+2,80+4*deltaY);


        g.drawLine(325+len1,80+4*deltaY - 14, 325+len1+len2,80+4*deltaY - 14);
        //g.drawLine(325+len1-2,80+4*deltaY - 14,325+len1+len2 ,80+4*deltaY - 14);
             
        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));
        fm = g.getFontMetrics();
        g.drawString("Applet Design: Umberto Ravaioli",
                     startingX+15,startingY+deltaY);
        
        MaestroG.superscripter("Interactive Java","TM"," platform:  www.amanogawa.com",
                               g,14,startingX+15,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+15,startingY+3*deltaY);
        g.drawLine(startingX,startingY,
                   startingX+lineLength+25,startingY);
        g.drawLine(startingX+lineLength+25,startingY,
                   startingX+lineLength+25,startingY+4*deltaY);
    }

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

