// About.java

import java.awt.*;

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;

    public Button bupdate;
    Mod2State state;
  
    public Instructions(Mod2State state){
	super();
        this.state = state;
	setLayout(null);
	setBackground(bgcolor);
	bupdate = new Button("CLOSE");
        bupdate.setBackground(new Color(240,240,255));
	//add(bupdate);
        //  8/8/14:
        /*
        int buttonx = 410;
        int buttony = 440;
        int buttonwide = 70;
        int buttonheight = 27;
        
        bupdate.setBounds(buttonx,buttony,buttonwide,buttonheight);	
        Panel ps7 = new Panel();
	    ps7.setBackground(Color.lightGray);
	    add(ps7);  8/8/14
	    ps7.setBounds(buttonx-1,buttony-1,buttonwide+2,buttonheight+2);
	    
	Panel ps8 = new Panel();
	    ps8.setBackground(Color.black);
	    add(ps8);   8/8/14
	    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;

        int Ystart = state.s30;
        int Ystart2 = state.s70;
        int Xstart = state.s20;
        
        g.setColor(Color.red);
        //g.setFont(state.ttfFont.deriveFont(Font.BOLD,16f));
        g.setFont(new Font("Sanserif",Font.BOLD,state.font16));

        g.drawString("Demonstration of Motional EMF", Xstart,Ystart);
        g.setColor(Color.black);
        //g.setFont(state.ttfFont.deriveFont(14f));
        g.setFont(new Font("Sanserif",Font.PLAIN,state.font14));

        String s;
        int nextX;
        int deltaY = state.s20;


        s = "A rectangular wire loop of area "+STR.ITAL+"A"+
            STR.ENDITAL+" rotates at an";
        nextX = STR.displayString(s,g,Xstart,Ystart2);
        s = "angular frequency "+STR.ITAL+"\u03c9"+STR.ENDITAL+
            " in a constant magnetic flux";
        nextX = STR.displayString(s,g,Xstart,Ystart2+deltaY);
        s = "density "+STR.ITAL+"B"+STR.ENDITAL+STR.SUB+"0"+STR.ENDSUB+
            ".  The purpose of the demo is to illustrate";
        nextX = STR.displayString(s,g,Xstart,Ystart2+2*deltaY);
        s = "how the current varies in time relative to the loop's";
        nextX = STR.displayString(s,g,Xstart,Ystart2+3*deltaY);
        s = "position.";
        nextX = STR.displayString(s,g,Xstart,Ystart2+4*deltaY);

        s = "Note the direction of the current and its magnitude,";
        nextX = STR.displayString(s,g,Xstart,Ystart2+6*deltaY);
        s = "as indicated by its brightness.";
        nextX = STR.displayString(s,g,Xstart,Ystart2+7*deltaY);

        s = STR.ITAL+"I"+STR.ENDITAL+STR.SUBITAL+"max"+STR.ENDSUBITAL+
            " = "+STR.ITAL+"\u03c9B"+STR.ENDITAL+STR.SUBITAL+"0"+
            STR.ENDSUBITAL+STR.ITAL+"A"+STR.ENDITAL;
        nextX = STR.displayString(s,g,Xstart,Ystart2+9*deltaY);

        drawCopyRight(g);

        //MaestroG.useBiggerFont = saveOldFlag;

    }


    public void drawCopyRight(Graphics g) {
        int deltaY = state.s25;
        int startingY = getSize().height - state.s60;
        int startingX = 0;
        FontMetrics fm;
        g.setColor(Color.black);
        g.setColor(Color.black);
        //g.setFont(normalfont14);
        //g.setFont(state.ttfFont.deriveFont(14f));
        //g.setFont(TheFonts.sanSerif14);
        g.setFont(new Font("Sanserif",Font.PLAIN,state.font14));
        fm = g.getFontMetrics();

        startingY += deltaY;
        g.drawString(" Applet Design: Janice Richards",
                     startingX + state.s5,startingY+deltaY);
                        
        int lineLength = fm.stringWidth(" Applet Design: Janice Richards");
        lineLength+= state.s10;


        //g.setFont(state.ttfFont.deriveFont(14f));
        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+2*deltaY);
    }

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

