// Instructions.java


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

    Mod4State state;
    public Button closeIt;
  
    public Instructions(Mod4State state){
	super();
        this.state = state;
	setLayout(null);
	setBackground(bgcolor);
	closeIt = new Button("CLOSE");
        closeIt.setBackground(new Color(240,240,255));
	add(closeIt);

        //int buttonx = 380;
        //int buttony = 380;
        int buttonx = 410;
        int buttony = 440;
        int buttonwide = 70;
        int buttonheight = 27;
        
        closeIt.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", 10,15);
        g.setColor(Color.red);
        g.setFont(state.ttfFont.deriveFont(Font.BOLD,15f));
        g.drawString("Input", 15,50);
        //g.drawString("Output", 230,50);
        g.setColor(Color.black);
        g.setFont(state.ttfFont.deriveFont(14f));
        int deltaY = 20;
        //INPUT

        g.drawString("\u2022 Charges may be placed in either or both of the two"+
                     " adjoining dielectric half-planes", 15,70);
        g.drawString("\u2022 Use the sliders or entries in the display panel,"+
                     " to set the permittivities of the",15,70+deltaY);
        g.drawString("  two dielectrics",15,70+2*deltaY);


        g.drawString("\u2022 Use the slider or the entry, in the Input panel,"+
                     " to set a positive or negative value", 15,70+3*deltaY);
        g.drawString("  for a new charge to place in the display panel", 
                     15,70+4*deltaY);
        g.drawString("\u2022 Use \"add charge\" and click in the"+
                     " display panel to put charge there", 15,70+5*deltaY);
        g.drawString("\u2022 Select a charge and click \"edit charge"+
                     " value\" to see the effects of the change",
                     15,70+6*deltaY);
        g.drawString("\u2022 Selected charges may also be deleted or"+
                     " dragged to a new location in the display panel",
                     15,70+7*deltaY);
        
       //OUTPUT
        g.setColor(Color.red);
        g.setFont(state.ttfFont.deriveFont(Font.BOLD,15f));
        int newY = 70+9*deltaY+40;
        g.drawString("Outputs", 15,newY);
        g.setColor(Color.black);
        g.setFont(state.ttfFont.deriveFont(14f));
        newY += 20;
        g.drawString("\u2022 Electric potential V(x,y) is shown in shades"+
                     " of blue (positive) and red (negative)", 15,newY);
        g.drawString("\u2022 Contour lines of constant potential"+
                     " are displayed in black",15,newY+deltaY);
        g.drawString("\u2022 Electric field vector directions are shown"+
                     " as dark orange arrows",15,newY+2*deltaY);
        g.drawString("\u2022 The cursor can also be used to echo the"+
                     " Potential and Electric Field values",15,newY+3*deltaY);
        g.drawString("   at that position",15,newY+4*deltaY);
        /*
        String s = "\u2022 Spatial pattern of electric field "+
            STR.BOLD+"E"+STR.ENDBOLD+"(x,y)";
        int nextX = STR.displayString(s,g,15,newY+2*deltaY);
        s = "\u2022 Values of V(x,y) and "+STR.BOLD+"E"+STR.ENDBOLD+
            "(x,y) at any cursor location (x,y)";
        nextX = STR.displayString(s,g,15,newY+3*deltaY);
        */
        drawCopyRight(g);

        //MaestroG.useBiggerFont = saveOldFlag;

    }


    public void drawCopyRight(Graphics g) {
        int deltaY = 20;
        int startingY = getSize().height - 60;
        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();

        startingY += deltaY;
        g.drawString("Applet Design: Fawwaz Ulaby and Janice Richards",
                     startingX,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,startingY+2*deltaY);
        //int lineLength = fm.stringWidth("Interactive JavaTM platform:  www.amanogawa.com");
        //lineLength+= 10;

        int lineLength = fm.stringWidth("Applet Design: Fawwaz Ulaby and Janice Richards");
        lineLength+= 10;

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

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

