// ApplicationEvent.java
// By Ned Etcode
// Copyright 1996 Netscape Communications Corp.  All rights reserved.

package netscape.application;

import netscape.util.*;
import java.awt.Graphics;
import java.awt.Rectangle;

class ApplicationEvent extends Event {
    /* application events */
    static final int GOT_FOCUS = -21,
                  LOST_FOCUS = -22,
                  UPDATE = -23,
                  RESIZE = -24,
                  STOP = -25,
                  APPLET_STOPPED = -26,
                  APPLET_STARTED = -27;
    Rect rect;

    static ApplicationEvent newResizeEvent(int width, int height) {
        ApplicationEvent event = new ApplicationEvent();

        event.type = RESIZE;
        event.rect = new Rect(0, 0, width, height);
        return event;
    }

    static ApplicationEvent newUpdateEvent(java.awt.Graphics g) {
        ApplicationEvent event = new ApplicationEvent();
        Rectangle r = g.getClipRect();

        event.type = UPDATE;
        event.rect = new Rect(r.x, r.y, r.width, r.height);
        return event;
    }

    static ApplicationEvent newFocusEvent(boolean gotFocus) {
        ApplicationEvent event = new ApplicationEvent();

        event.type = gotFocus ? GOT_FOCUS : LOST_FOCUS;
        return event;
    }

    public String toString() {
        String typeString;

        switch (type) {
        case GOT_FOCUS:
            typeString = "GotFocus";
            break;
        case LOST_FOCUS:
            typeString = "LostFocus";
            break;
        case UPDATE:
            typeString = "Update";
            break;
        case RESIZE:
            typeString = "Resize";
            break;
        case STOP:
            typeString = "Stop";
            break;
        case APPLET_STOPPED:
            typeString = "AppletStopped";
            break;
        case APPLET_STARTED:
            typeString = "AppletStarted";
            break;
        default:
            typeString = "Unknown Type";
            break;
        }

        return "ApplicationEvent: " + typeString;
    }
}


