// 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;
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(236,236,236);
    private static final Color bgcolor = Color.white;
    
    public TextField epsilon;
    private Paint paint;
    
    private Image im;
    private Graphics buf;
    private BufferedImage figure;

    //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 = 410;
        //int buttony = 440;
        int buttonx = 650;
        int buttony = 245;
        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));
        

        try {
            figure = ImageIO.read(getClass().getResource("mod9.4.gif"));
        } catch (IOException e) {
            e.printStackTrace();
        }


        g.drawString("Instructions", 20,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);
        String s;
        int nextX;

        g.setColor(Color.red);
        //g.setFont(state.ttfFont.deriveFont(Font.BOLD,15f));
        g.setFont(new Font("SanSerif",Font.BOLD,15));

        g.drawString("Input", 25,60);
        g.setColor(Color.black);
        //g.setFont(state.ttfFont.deriveFont(14f));
        g.setFont(new Font("SanSerif",Font.PLAIN,14));
        int deltaY = 20;
        //INPUT
        s = "\u2022 Antenna diameter "+STR.ITAL+"d"+STR.ENDITAL+
            " = 2"+STR.ITAL+"a"+STR.ENDITAL;
        nextX = STR.displayString(s,g,25,80);
        s = "\u2022 Taper factor"+STR.ITAL+"\u03b1"+STR.ENDITAL;
        nextX = STR.displayString(s,g,25,80+deltaY);


        s = "   The small horn illuminates the dish antenna with:";
        nextX = STR.displayString(s,g,350,2*deltaY);

        g.setFont(new Font("Serif",Font.PLAIN,14));
        s = "        ~";               //"\u007e";
        nextX = STR.displayString(s,g,350+2,4*deltaY-10);
        g.setFont(new Font("SanSerif",Font.PLAIN,14));

        s = "        "+STR.ITAL+"E"+STR.ENDITAL+STR.SUBITAL+"a"+STR.ENDSUBITAL+
            "("+STR.ITAL+"r"+STR.ENDITAL+STR.SUBITAL+"a"+STR.ENDSUBITAL+
            ") = "+STR.ITAL+"E"+STR.ENDITAL+STR.SUB+"0"+STR.ENDSUB;
        nextX = STR.displayString(s,g,350,4*deltaY);

        //s = "(";
        //nextX  = STR.displayString(s,g,nextX,4*deltaY+5);

        
        Arc2D.Double arc_one = new Arc2D.Double(nextX,
                                                (3*deltaY)-5,
                                                14,2*deltaY,
                                                90,180,0);

        g2d.draw(arc_one);


        s = "1 - "+STR.ITAL+"\u03b1"+STR.ENDITAL;
        nextX  = STR.displayString(s,g,nextX+5,4*deltaY);

        int saveNextX = nextX;
        //s = "_";
        //nextX  = STR.displayString(s,g,nextX,4*deltaY-10);
        g.drawLine(nextX,4*deltaY-5,nextX+18,4*deltaY-5);

        s = STR.ITAL+"a"+STR.ENDITAL;
        nextX  = STR.displayString(s,g,saveNextX+4,5*deltaY-13);
        s = STR.ITAL+"r"+STR.ENDITAL+STR.SUBITAL+"a"+STR.ENDSUBITAL;
        nextX  = STR.displayString(s,g,saveNextX,3*deltaY+7);

        //s = ")";
        //nextX  = STR.displayString(s,g,nextX,4*deltaY+5);



        arc_one = new Arc2D.Double(nextX-5,(3*deltaY)-5,14,2*deltaY,
                                   -90,180,0);

        g2d.draw(arc_one);


        
        s = ",          0 \u2264 "+STR.ITAL+"\u03b1"+STR.ENDITAL+" \u2264 1.";
        nextX  = STR.displayString(s,g,nextX+15,4*deltaY);

        s = "   Uniform illumination (no taper): "+STR.ITAL+"\u03b1"+
            STR.ENDITAL+" = 0";
        nextX = STR.displayString(s,g,350,6*deltaY);
        s = "   Steepest taper: "+STR.ITAL+"\u03b1"+STR.ENDITAL+" = 1";
        nextX = STR.displayString(s,g,350,7*deltaY);


       //OUTPUT
        g.setColor(Color.red);
        //g.setFont(state.ttfFont.deriveFont(Font.BOLD,15f));
        g.setFont(new Font("SanSerif",Font.BOLD,15));
        int newY = 90+2*deltaY+10;
        g.drawString("Displayed Information", 25,newY);
        g.setColor(Color.black);
        //g.setFont(state.ttfFont.deriveFont(14f));
        g.setFont(new Font("SanSerif",Font.PLAIN,14));
        newY += 20;
        s = "\u2022 Radiation pattern";
        nextX = STR.displayString(s,g,25,newY);
        s = "\u2022 Antenna directivity "+STR.ITAL+"D"+STR.ENDITAL;
        nextX = STR.displayString(s,g,25,newY+deltaY);
        s = "\u2022 Antenna beamwidth "+STR.ITAL+"\u03b2"+STR.ENDITAL;
        nextX = STR.displayString(s,g,25,newY+2*deltaY);

        g.drawImage(figure,435,8*deltaY,this);

        s = STR.ITAL+"r"+STR.ENDITAL+STR.SUBITAL+"a"+STR.ENDSUBITAL;
        nextX = STR.displayString(s,g,440,165);
        s = STR.ITAL+"a"+STR.ENDITAL;
        nextX = STR.displayString(s,g,430,185);
        s = "0";
        nextX = STR.displayString(s,g,430,215);


        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+15,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+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+5,
                   startingX+15+lineLength+10,startingY+5);
        g.drawLine(startingX+15+lineLength+10,startingY+5,
                   startingX+15+lineLength+10,startingY+4*deltaY);
    }

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

