Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jlib/EventPanel.java


1   package jlib;
2   import silk.*;
3   import java.awt.*;
4   
5   /**
6    *   This class represents a panel which executes closures to handle
7    *   events in the Java 1.0 event model. 
8    *   @author Timothy J. Hickey, tim@cs.brandeis.edu http://www.cs.brandeis.edu/~tim 
9    **/
10  
11  
12  public class EventPanel extends Panel {
13      public Procedure handler;
14      public Component C;
15      public final int GENERAL=0,ACTION=1,MOUSE=2;
16      int eventmask=ACTION;
17  
18      public EventPanel(Component C, Procedure handler) {
19    super();
20          this.C=C; this.handler=handler;
21          this.add(C);
22      }
23  
24      public EventPanel(Component C, int eventmask, Procedure handler) {
25    super();
26          this.C=C; this.handler=handler;
27          this.add(C);
28          this.eventmask=eventmask;
29      }
30  
31      public void update(Graphics g) { paint(g); } // don't let Java blank the screen
32  
33      public boolean handleEvent(Event e) {
34          if (eventmask==GENERAL) {
35              Object x = handler.apply(U.list(e));
36              return !(Boolean.FALSE).equals(x);
37    }else return super.handleEvent(e);
38      }
39  
40      public boolean action(Event e, Object what) {
41          if (eventmask==ACTION) {
42              Object x = handler.apply(U.list(e));
43              return !(Boolean.FALSE).equals(x);
44    }else return false;
45      }
46  
47      public boolean mouseDown(Event e, int x1, int y1) {
48          if (eventmask==MOUSE) {
49              Object x = handler.apply(U.list(e));
50              return !(Boolean.FALSE).equals(x);
51    }else return false;
52      }
53  
54      public boolean mouseUp(Event e, int x1, int y1) {
55          if (eventmask==MOUSE) {
56              Object x = handler.apply(U.list(e));
57              return !(Boolean.FALSE).equals(x);
58    }else return false;
59      }
60  
61      public boolean mouseDrag(Event e, int x1, int y1) {
62          if (eventmask==MOUSE) {
63              Object x = handler.apply(U.list(e));
64              return !(Boolean.FALSE).equals(x);
65    }else return false;
66      }
67  
68      public boolean mouseMove(Event e, int x1, int y1) {
69          if (eventmask==MOUSE) {
70              Object x = handler.apply(U.list(e));
71              return !(Boolean.FALSE).equals(x);
72    }else return false;
73      }
74  
75      public boolean mouseEnter(Event e, int x1, int y1) {
76          if (eventmask==MOUSE) {
77              Object x = handler.apply(U.list(e));
78              return !(Boolean.FALSE).equals(x);
79    }else return false;
80      }
81  
82      public boolean mouseExit(Event e, int x1, int y1) {
83          if (eventmask==MOUSE) {
84              Object x = handler.apply(U.list(e));
85              return !(Boolean.FALSE).equals(x);
86    }else return false;
87      }
88  
89  }
90  
91  
92  
93