import java.applet.*;
import java.awt.*;
import java.lang.*;
import java.util.*;


/*
    Help class - draws hints and messages at the bottom of the applet.
*/


class Help
{
    /*
        CLASS CONSTANTS
    */

    final static int    EMPTY                           = 0;
    final static int    INITIAL                         = 1;
    final static int    NO_STATE                        = 2;
    final static int    MAX_STATES                      = 3;
    final static int    INITIAL_STATE_PRESENT           = 4;
    final static int    NO_INPUT_STRING                 = 5;
    final static int    NO_INITIAL_STATE                = 6;
    final static int    NO_ACCEPTING_STATE              = 7;
    final static int    TARGET_STATE                    = 8;
    final static int    FIRST_STATE                     = 9;
    final static int    LAST_STATE                      = 10;
    final static int    SELECT_LOCATION                 = 11;
    final static int    STRING_ACCEPTED                 = 12;
    final static int    STRING_NOT_ACCEPTED             = 13;
    final static int    BAD_TOKEN                       = 14;
    final static int    BAD_MACHINE                     = 15;
    final static int    RUN_INSTRUCTIONS                = 16;
    final static int    FILE_NOT_FOUND                  = 17;
    final static int    FILE_CREATE_ERROR               = 18;
    final static int    FILE_WRITE_ERROR                = 19;
    final static int    FILE_READ_ERROR                 = 20;
    final static int    FILE_BAD_INPUT                  = 21;
    final static int    FILE_LOADED_OK                  = 22;
    final static int    FILE_SAVED_OK                   = 23;
    final static int    NO_INPUTS                       = 24;
    final static int    NO_TOKEN_STRING                 = 25;
    final static int    RENAME_STATE                    = 26;
    final static int	MACHINE_WAITING					= 27;


    /*
        INSTANCE VARIABLES
    */


    /* current message string */

    private String      currHelp;


    /*
        PUBLIC METHODS
    */


    /*
        constructor method - set current message to empty
    */

    public Help ()
    {
        currHelp = new String ("");

    } /* end Help */


    /*
        sets current message string depending on the type of message wanted
    */

    public void setHelp (int num)
    {
        switch (num)
        {
            case INITIAL:
                currHelp = new String ("State Machine Simulator V1.2");
                break;

            case NO_STATE:
                currHelp = new String ("There is no state there");
                break;

            case MAX_STATES:
                currHelp = new String ("Maximum number of states is reached");
                break;

            case INITIAL_STATE_PRESENT:
                currHelp = new String ("No state there or already have one initial state");
                break;

            case NO_INPUT_STRING:
                currHelp = new String ("Cannot run simulation - no input string");
                break;

            case NO_INITIAL_STATE:
                currHelp = new String ("Cannot run simulation - no initial state");
                break;

            case NO_ACCEPTING_STATE:
                currHelp = new String ("Cannot run simulation - no accepting state(s)");
                break;

            case TARGET_STATE:
                currHelp = new String ("Click on the target state");
                break;

            case FIRST_STATE:
                currHelp = new String ("Click on the source state");
                break;

            case LAST_STATE:
                currHelp = new String ("Click on the destination state");
                break;

            case SELECT_LOCATION:
                currHelp = new String ("Click on desired location");
                break;

            case STRING_ACCEPTED:
                currHelp = new String ("Input string accepted by the machine");
                break;

            case STRING_NOT_ACCEPTED:
                currHelp = new String ("Input string NOT accepted by the machine");
                break;

            case BAD_TOKEN:
                currHelp = new String ("Input string contains bad token - halting");
                break;

            case BAD_MACHINE:
                currHelp = new String ("More than one transition for this token - halting");
                break;

            case RUN_INSTRUCTIONS:
                currHelp = new String ("Click to step through tokens");
                break;

            case FILE_NOT_FOUND:
                currHelp = new String ("Specified file not found");
                break;

            case FILE_CREATE_ERROR:
                currHelp = new String ("Specified file could not be created");
                break;

            case FILE_WRITE_ERROR:
                currHelp = new String ("Error writing file");
                break;

            case FILE_READ_ERROR:
                currHelp = new String ("Error reading file");
                break;

            case FILE_BAD_INPUT:
                currHelp = new String ("Bad input file");
                break;

            case FILE_LOADED_OK:
                currHelp = new String ("File loaded successfully");
                break;

            case FILE_SAVED_OK:
                currHelp = new String ("File saved successfully");
                break;

            case NO_INPUTS:
                currHelp = new String ("No input signal was selected - transition not added");
                break;

            case NO_TOKEN_STRING:
                currHelp = new String ("Empty input string was specified - not setting");
                break;

            case RENAME_STATE:
                currHelp = new String ("Select state to rename");
                break;

            case MACHINE_WAITING:
            	currHelp = new String ("Machine is waiting");
            	break;

            case EMPTY:
            default:
                currHelp = new String ("");
                break;
        }

    } /* end setHelp */


    /*
        draw the current message string at the very bottom of the screen.
    */

    public void paint (Graphics g, int height, int width)
    {
        /* remove previous message */

        remove (g, height - 4, width);

        /* draw new one */

        g.setColor (Color.red);
        g.drawString (currHelp, 4, height - 5);

    } /* end paint */


    /*
        draw a filled rectangle with the width of the screen and the height
        of the font.
    */

    public void remove (Graphics g, int height, int width)
    {
        g.setColor (Color.lightGray);
        g.fillRect (0, height - g.getFontMetrics ().getHeight () - 1,
                      width, g.getFontMetrics ().getHeight () + 1);

    } /* end remove */

} /* end Help */

