import java.util.EventObject;

/**
 * This class contains the set of possible PopFetcherEvents, and
 * text messages describing them.
 *
 * @author      Simon Pollard
 */

public class PopFetcherEvent extends EventObject
{
  /** The 'idle' message - waiting for the timeout */
  public static final int PFEWAITING = 1;
  /** The message used to indicate mail is being checked */
  public static final int PFECHECKING = 2;
  /** The message used to indicate how many messages are available */
  public static final int PFEMESSAGES = 3;
  /** The message used to indicate the server is being disconnected from */
  public static final int PFEDISCONNECTING = 4;
  /** The message used to indicate mail information is being fetched */
  public static final int PFEFETCHING = 5;
  /** The message used to indicate mail fetching is complete */
  public static final int PFEFETCHDONE = 6;
  /** The message used to indicate how far through a fetch is */
  public static final int PFEFETCHPERCENT = 7;

  /** The error message caused by a logon failure */
  public static final int PFEERRORLOGON = 101;
  /** The error message caused by a failure to read mail information */
  public static final int PFEERRORFOLDER = 102;
  /** The error message caused when logging off the server fails */
  public static final int PFEERRORCLOSE = 103;

  private int myEventNum = 0;
  private int myNumMessages = 0;

  /**
   * The constructor creates a PopFetcherEvent from the calling Object,
   * the event number, and the number of messages applying to the event
   * (if any)
   *
   * @param     source the calling Object
   * @param     eventNum the number representing the event
   * @param     numMessages the number of messages (where applicable)
   */
  public PopFetcherEvent(Object source, int eventNum, int numMessages)
  {
    super(source);

    myEventNum = eventNum;
    myNumMessages = numMessages;
  }

  /**
   * Returns a String describing the event
   *
   * @return    the description for this event
   */
   public String getMessage() {
    switch(myEventNum) {
                   default: return "(none)";
           case PFEWAITING: return "Waiting";
          case PFECHECKING: return "Checking for new mail...";
        case PFEERRORLOGON: return "Failed to log on to server";
       case PFEERRORFOLDER: return "Couldn't read mail folder information";
          case PFEMESSAGES: return myNumMessages + " messages waiting";
        case PFEERRORCLOSE: return "Failed to log off properly";
     case PFEDISCONNECTING: return "Disconnecting from server...";
          case PFEFETCHING: return "Fetching mail...";
         case PFEFETCHDONE: return "Fetch complete";
      case PFEFETCHPERCENT: return "Fetching messages - " + myNumMessages + "%";
    }
  }

  /**
   * Returns the number representing the event
   *
   * @return    the event number for this event
   */
  public int getEventNum() { return myEventNum; }

  /**
   * Returns the number of messages applying to this event, in the
   * case of PFEMESSAGES
   *
   * @return    the number of messages waiting
   * @see       #PFEMESSAGES
   */
  public int getNumMessages() { return myNumMessages; }
}
