package gjt; import java.awt.Event; /** * An extension of java.awt.Event, specifically designed for * ImageButton events.

* * ImageButtonEvents are constructed with 3 arguments: *

*
ImageButton in which the event occurred *
The AWT event that triggered the image button event *
The id of the event. *
* * An ImageButtonEvent's id (the constructor's 3rd argument), * must be one of the following: * *
*
ImageButtonEvent.ARM *
ImageButtonEvent.DISARM *
ImageButtonEvent.ACTIVATE *
* * ImageButtonEvent has only a constructor and a paramString() * method. Containers that contain ImageButtons should check * for ImageButtonEvents like so:

* *

 *      // handleEvent(Event) method of a container that
 *      // contains ImageButtons.
 *
 *      public boolean handleEvent(Event event) {
 *              if(event instanceof ImageButtonEvent) {
 *                  ImageButtonEvent ibevent = 
 *                  (ImageButtonEvent)event;
 *
 *                  if(ibevent.isArmed()) {
 *                      // do something for arming
 *                  }
 *                  if(ibevent.isDisarmed()) {
 *                      // do something for disarming
 *                  }
 *                  if(ibevent.isActivated()) {
 *                      // do something for activation
 *                  }
 *              }
 *      }
 * 
* * ImageButtonController is the only GJT class that creates * ImageButtonEvents. * * @version 1.0, Apr 1 1996 * @author David Geary * @see ImageButton * @see ImageButtonController * @see SpringyImageButtonController * @see StickyImageButtonController * @see gjt.test.ImageButtonTest */ public class ImageButtonEvent extends Event { public static final int ARM = 1; public static final int DISARM = 2; public static final int ACTIVATE = 3; private int eventType; public ImageButtonEvent(ImageButton button, Event event, int type) { super(button, event.when, event.id, event.x, event.y, event.key, event.modifiers, event.arg); Assert.notFalse(type == ARM || type == DISARM || type == ACTIVATE); eventType = type; id = -1; } public boolean isArmed() { return eventType == ARM; } public boolean isDisarmed() { return eventType == DISARM; } public boolean isActivated() { return eventType == ACTIVATE; } protected String paramString() { String str = new String(); if(eventType == ImageButtonEvent.ARM) str = "ARM"; else if(eventType == ImageButtonEvent.DISARM) str = "DISARM"; else if(eventType == ImageButtonEvent.ACTIVATE) str = "ACTIVATE"; return super.paramString() + str; } }