001: package jlib;
002:
003: import jsint.*;
004: import java.awt.*;
005:
006: /**
007: * This class represents a panel which executes closures to handle
008: * events in the Java 1.0 event model.
009: * @author Timothy J. Hickey, tim@cs.brandeis.edu http://www.cs.brandeis.edu/~tim
010: **/
011:
012: public class EventPanel extends Panel {
013: public Procedure handler;
014: public Component C;
015: public final int GENERAL = 0, ACTION = 1, MOUSE = 2;
016: int eventmask = ACTION;
017:
018: public EventPanel(Component C, Procedure handler) {
019: super ();
020: this .C = C;
021: this .handler = handler;
022: this .add(C);
023: }
024:
025: public EventPanel(Component C, int eventmask, Procedure handler) {
026: super ();
027: this .C = C;
028: this .handler = handler;
029: this .add(C);
030: this .eventmask = eventmask;
031: }
032:
033: public void update(Graphics g) {
034: paint(g);
035: } // don't let Java blank the screen
036:
037: public boolean handleEvent(Event e) {
038: if (eventmask == GENERAL) {
039: Object x = handler.apply(U.list(e));
040: return !(Boolean.FALSE).equals(x);
041: } else
042: return super .handleEvent(e);
043: }
044:
045: public boolean action(Event e, Object what) {
046: if (eventmask == ACTION) {
047: Object x = handler.apply(U.list(e));
048: return !(Boolean.FALSE).equals(x);
049: } else
050: return false;
051: }
052:
053: public boolean mouseDown(Event e, int x1, int y1) {
054: if (eventmask == MOUSE) {
055: Object x = handler.apply(U.list(e));
056: return !(Boolean.FALSE).equals(x);
057: } else
058: return false;
059: }
060:
061: public boolean mouseUp(Event e, int x1, int y1) {
062: if (eventmask == MOUSE) {
063: Object x = handler.apply(U.list(e));
064: return !(Boolean.FALSE).equals(x);
065: } else
066: return false;
067: }
068:
069: public boolean mouseDrag(Event e, int x1, int y1) {
070: if (eventmask == MOUSE) {
071: Object x = handler.apply(U.list(e));
072: return !(Boolean.FALSE).equals(x);
073: } else
074: return false;
075: }
076:
077: public boolean mouseMove(Event e, int x1, int y1) {
078: if (eventmask == MOUSE) {
079: Object x = handler.apply(U.list(e));
080: return !(Boolean.FALSE).equals(x);
081: } else
082: return false;
083: }
084:
085: public boolean mouseEnter(Event e, int x1, int y1) {
086: if (eventmask == MOUSE) {
087: Object x = handler.apply(U.list(e));
088: return !(Boolean.FALSE).equals(x);
089: } else
090: return false;
091: }
092:
093: public boolean mouseExit(Event e, int x1, int y1) {
094: if (eventmask == MOUSE) {
095: Object x = handler.apply(U.list(e));
096: return !(Boolean.FALSE).equals(x);
097: } else
098: return false;
099: }
100:
101: }
|