// 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.*;

public class Instructions extends Panel {
    private static final Color bgcolor = new Color(255,255,250);
    
    public TextField epsilon;
    private Paint paint;
    
    private Image im;
    private Graphics buf;
    public Button bupdate;
    
    Trans_State state;
  
    public Instructions(Trans_State state){
	super();
        this.state = state;
	setLayout(null);
	setBackground(bgcolor);
        
        // update button
	bupdate = new Button("CLOSE");
        bupdate.setFont(state.ttfFont.deriveFont(Font.PLAIN,(float)state.font12));
        //bupdate.setBackground(new Color(240,240,255));
        bupdate.setBackground(Color.white);
	add(bupdate);
        int buttonx = state.s455;
        int buttony = state.s270;
        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);
    }
    
    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.drawRect(0,0,getSize().width-1,getSize().height-1);
        g.setFont(state.ttfFont.deriveFont(Font.BOLD,(float)state.font16));

        g.drawString("Instructions", state.s20,state.s25);
        g.setColor(Color.red);
        g.setFont(state.ttfFont.deriveFont(Font.BOLD,(float)state.font15));
        g.drawString("Inputs", state.s25,state.s50);
        g.drawString("Displayed Information", state.s302,state.s50);
        g.setColor(Color.black);
        g.setFont(state.ttfFont.deriveFont((float)state.font14));
        int deltaY = state.s20; int starty = state.s80;
        //INPUT
        g.drawString("Characteristic impedance", state.s25,starty);
        g.drawString("Load Parameters", state.s25,starty+deltaY);
        g.drawString("Line length", state.s25,starty+2*deltaY);
        g.drawString("Frequency", state.s25,starty+3*deltaY);
        MaestroG.subscripter("\u03b5","r"," = relative permittivity of dielectric",
                             g,state.font14,state.s25,starty+4*deltaY);

        //OUTPUT
        g.drawString("Z(d) = wave impedance at cursor location", state.s302,starty);
        //MaestroG.subscripter("Z","in"," = input impedance (@ d=l)",
        //                     g,state.font14,state.s302,starty+deltaY);
        MaestroG.subscripterSymLast("Z","in"," = input impedance (@d = ","l ",")",
                             g,state.font14,state.s302,starty+deltaY);
        g.drawString("S = SWR",state.s302,starty+2*deltaY);
        g.drawString("d(max) = distance to first voltage maximum",
                     state.s302,starty+3*deltaY);
        g.drawString("d(min) = distance to first voltage minimum",
                     state.s302,starty+4*deltaY);
        g.drawString("\u0393 = reflection coefficient of load",
                     state.s302,starty+5*deltaY);
        MaestroG.subscripter("\u0393","d"," = \u0393 exp(-j2\u03b2d)"+
                             ", phase-shifted reflection ",
                             g,state.font14,state.s302,starty+6*deltaY);
        g.drawString("coefficient",state.s322,starty+7*deltaY);
             
        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(normalfont14);
        g.setFont(state.ttfFont.deriveFont((float)state.font14));
        fm = g.getFontMetrics();
        g.drawString("Application Design: Umberto Ravaioli",
                     startingX+state.s15,startingY+deltaY);
        
        MaestroG.superscripter("Interactive Java","TM"," platform:  www.amanogawa.com",
                               g,state.font14,startingX+state.s15,startingY+2*deltaY);
        int lineLength = fm.stringWidth("Interactive JavaTM platform:  www.amanogawa.com");
        lineLength += state.s10;

        g.setFont(state.ttfFont.deriveFont((float)state.s14));
        g.drawString("All Rights Reserved",startingX+state.s15,startingY+3*deltaY);
        g.drawLine(startingX,startingY,
                   startingX+lineLength+state.s25,startingY);
        g.drawLine(startingX+lineLength+state.s25,startingY,
                   startingX+lineLength+state.s25,startingY+4*deltaY);
    }


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

