JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / java / awt / EventDispatchThread.js
1 Clazz.declarePackage ("java.awt");\r
2 Clazz.load (["java.awt.AWTEvent", "$.ActiveEvent", "$.EventFilter", "swingjs.JSThread", "java.util.Vector"], "java.awt.EventDispatchThread", ["java.lang.Error", "$.RuntimeException", "$.Thread", "java.awt.Component", "$.Container", "$.ModalEventFilter", "$.Window", "jssun.awt.AWTAutoShutdown", "$.ModalExclude", "$.SunToolkit", "swingjs.JSToolkit"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.theQueue = null;\r
5 this.eventFilters = null;\r
6 this.modalFiltersCount = 0;\r
7 this.filter = null;\r
8 this.cond = null;\r
9 this.id = 0;\r
10 this.doDispatch = true;\r
11 if (!Clazz.isClassDefined ("java.awt.EventDispatchThread.StopDispatchEvent")) {\r
12 java.awt.EventDispatchThread.$EventDispatchThread$StopDispatchEvent$ ();\r
13 }\r
14 Clazz.instantialize (this, arguments);\r
15 }, java.awt, "EventDispatchThread", swingjs.JSThread);\r
16 Clazz.prepareFields (c$, function () {\r
17 this.eventFilters =  new java.util.Vector ();\r
18 });\r
19 Clazz.makeConstructor (c$, \r
20 function (group, name, queue) {\r
21 Clazz.superConstructor (this, java.awt.EventDispatchThread, [group, name]);\r
22 this.theQueue = queue;\r
23 }, "ThreadGroup,~S,java.awt.EventQueue");\r
24 Clazz.defineMethod (c$, "stopDispatchingImpl", \r
25 function (wait) {\r
26 var stopEvent = Clazz.innerTypeInstance (java.awt.EventDispatchThread.StopDispatchEvent, this, null);\r
27 if (Thread.currentThread () !== this) {\r
28 this.theQueue.postEventPrivate (stopEvent);\r
29 if (wait) {\r
30 try {\r
31 this.join ();\r
32 } catch (e) {\r
33 if (Clazz.exceptionOf (e, InterruptedException)) {\r
34 } else {\r
35 throw e;\r
36 }\r
37 }\r
38 }} else {\r
39 stopEvent.dispatch ();\r
40 }{\r
41 if (this.theQueue.getDispatchThread () === this) {\r
42 this.theQueue.detachDispatchThread ();\r
43 }}}, "~B");\r
44 Clazz.defineMethod (c$, "stopDispatching", \r
45 function () {\r
46 this.stopDispatchingImpl (true);\r
47 });\r
48 Clazz.defineMethod (c$, "stopDispatchingLater", \r
49 function () {\r
50 this.stopDispatchingImpl (false);\r
51 });\r
52 Clazz.overrideMethod (c$, "run", \r
53 function () {\r
54 this.pumpEvents (-1, null);\r
55 });\r
56 Clazz.defineMethod (c$, "pumpEvents", \r
57 function (id, cond) {\r
58 this.pumpEventsForHierarchy (id, cond, null);\r
59 }, "~N,java.awt.Conditional");\r
60 Clazz.defineMethod (c$, "pumpEventsForHierarchy", \r
61 function (id, cond, modalComponent) {\r
62 this.pumpEventsForFilter (id, cond,  new java.awt.EventDispatchThread.HierarchyEventFilter (modalComponent));\r
63 }, "~N,java.awt.Conditional,java.awt.Component");\r
64 Clazz.defineMethod (c$, "pumpEventsForFilter", \r
65 function (id, cond, filter) {\r
66 this.filter = filter;\r
67 this.cond = cond;\r
68 this.id = id;\r
69 this.run1 (0);\r
70 }, "~N,java.awt.Conditional,java.awt.EventFilter");\r
71 Clazz.overrideMethod (c$, "run1", \r
72 function (mode) {\r
73 try {\r
74 while (true) switch (mode) {\r
75 case 0:\r
76 this.addEventFilter (this.filter);\r
77 mode = 1;\r
78 case 1:\r
79 if (!this.doDispatch || this.cond != null && !this.cond.evaluate () || this.isInterrupted ()) {\r
80 this.doDispatch = false;\r
81 return;\r
82 }var myid = this.id;\r
83 var r = ((Clazz.isClassDefined ("java.awt.EventDispatchThread$1") ? 0 : java.awt.EventDispatchThread.$EventDispatchThread$1$ ()), Clazz.innerTypeInstance (java.awt.EventDispatchThread$1, this, Clazz.cloneFinals ("myid", myid)));\r
84 this.dispatchAndReturn (r, mode);\r
85 if (this.isJS) return;\r
86 break;\r
87 case 2:\r
88 this.doDispatch = false;\r
89 return;\r
90 }\r
91 \r
92 } finally {\r
93 if (!this.doDispatch) this.finish ();\r
94 }\r
95 }, "~N");\r
96 Clazz.defineMethod (c$, "dispatchAndReturn", \r
97 function (r, mode) {\r
98 var f = null;\r
99 var me = this;\r
100 {\r
101 f = function() {r.run();me.run1(mode)\r
102 };\r
103 }swingjs.JSToolkit.setTimeout (f, 0, 0);\r
104 }, "Runnable,~N");\r
105 Clazz.defineMethod (c$, "finish", \r
106  function () {\r
107 this.doDispatch = false;\r
108 this.removeEventFilter (this.filter);\r
109 {\r
110 if (this.theQueue.getDispatchThread () === this) {\r
111 this.theQueue.detachDispatchThread ();\r
112 }if (this.theQueue.peekEvent () != null || !jssun.awt.SunToolkit.isPostEventQueueEmpty ()) {\r
113 this.theQueue.initDispatchThread ();\r
114 }jssun.awt.AWTAutoShutdown.getInstance ().notifyThreadFree (this);\r
115 }});\r
116 Clazz.defineMethod (c$, "addEventFilter", \r
117 function (filter) {\r
118 {\r
119 if (!this.eventFilters.contains (filter)) {\r
120 if (Clazz.instanceOf (filter, java.awt.ModalEventFilter)) {\r
121 var newFilter = filter;\r
122 var k = 0;\r
123 for (k = 0; k < this.eventFilters.size (); k++) {\r
124 var f = this.eventFilters.get (k);\r
125 if (Clazz.instanceOf (f, java.awt.ModalEventFilter)) {\r
126 var cf = f;\r
127 if (cf.compareTo (newFilter) > 0) {\r
128 break;\r
129 }}}\r
130 this.eventFilters.add (k, filter);\r
131 this.modalFiltersCount++;\r
132 } else {\r
133 this.eventFilters.add (filter);\r
134 }}}}, "java.awt.EventFilter");\r
135 Clazz.defineMethod (c$, "removeEventFilter", \r
136 function (filter) {\r
137 {\r
138 if (this.eventFilters.contains (filter)) {\r
139 if (Clazz.instanceOf (filter, java.awt.ModalEventFilter)) {\r
140 this.modalFiltersCount--;\r
141 }this.eventFilters.remove (filter);\r
142 }}}, "java.awt.EventFilter");\r
143 Clazz.defineMethod (c$, "pumpOneEventForFilters", \r
144 function (id) {\r
145 try {\r
146 var event;\r
147 var eventOK;\r
148 do {\r
149 event = (id == -1) ? this.theQueue.getNextEvent () : this.theQueue.getNextEventForID (id);\r
150 if (event == null) return (this.doDispatch = false);\r
151 eventOK = true;\r
152 {\r
153 for (var i = this.eventFilters.size () - 1; i >= 0; i--) {\r
154 var f = this.eventFilters.get (i);\r
155 var accept = f.acceptEvent (event);\r
156 if (accept === java.awt.EventFilter.FilterAction.REJECT) {\r
157 eventOK = false;\r
158 break;\r
159 } else if (accept === java.awt.EventFilter.FilterAction.ACCEPT_IMMEDIATELY) {\r
160 break;\r
161 }}\r
162 }if (!eventOK) {\r
163 event.consume ();\r
164 }} while (eventOK == false);\r
165 this.theQueue.dispatchEvent (event);\r
166 return this.doDispatch = true;\r
167 } catch (e$$) {\r
168 if (Clazz.exceptionOf (e$$, ThreadDeath)) {\r
169 var death = e$$;\r
170 {\r
171 return this.doDispatch = false;\r
172 }\r
173 } else if (Clazz.exceptionOf (e$$, InterruptedException)) {\r
174 var interruptedException = e$$;\r
175 {\r
176 return this.doDispatch = false;\r
177 }\r
178 } else {\r
179 var e = e$$;\r
180 {\r
181 this.processException (e, this.modalFiltersCount > 0);\r
182 }\r
183 }\r
184 }\r
185 return this.doDispatch = true;\r
186 }, "~N");\r
187 Clazz.defineMethod (c$, "processException", \r
188  function (e, isModal) {\r
189 if (!this.handleException (e)) {\r
190 if (isModal) {\r
191 System.err.println ("Exception occurred during event dispatching:");\r
192 e.printStackTrace ();\r
193 } else if (Clazz.instanceOf (e, RuntimeException)) {\r
194 throw e;\r
195 } else if (Clazz.instanceOf (e, Error)) {\r
196 throw e;\r
197 }}}, "Throwable,~B");\r
198 Clazz.defineMethod (c$, "handleException", \r
199  function (thrown) {\r
200 return false;\r
201 }, "Throwable");\r
202 Clazz.defineMethod (c$, "isDispatching", \r
203 function (eq) {\r
204 return this.theQueue.equals (eq);\r
205 }, "java.awt.EventQueue");\r
206 Clazz.defineMethod (c$, "getEventQueue", \r
207 function () {\r
208 return this.theQueue;\r
209 });\r
210 c$.$EventDispatchThread$StopDispatchEvent$ = function () {\r
211 Clazz.pu$h(self.c$);\r
212 c$ = Clazz.decorateAsClass (function () {\r
213 Clazz.prepareCallback (this, arguments);\r
214 Clazz.instantialize (this, arguments);\r
215 }, java.awt.EventDispatchThread, "StopDispatchEvent", java.awt.AWTEvent, java.awt.ActiveEvent);\r
216 Clazz.makeConstructor (c$, \r
217 function () {\r
218 Clazz.superConstructor (this, java.awt.EventDispatchThread.StopDispatchEvent, [this.b$["java.awt.EventDispatchThread"], 0]);\r
219 });\r
220 Clazz.overrideMethod (c$, "dispatch", \r
221 function () {\r
222 this.b$["java.awt.EventDispatchThread"].doDispatch = false;\r
223 });\r
224 c$ = Clazz.p0p ();\r
225 };\r
226 c$.$EventDispatchThread$1$ = function () {\r
227 Clazz.pu$h(self.c$);\r
228 c$ = Clazz.declareAnonymous (java.awt, "EventDispatchThread$1", null, Runnable);\r
229 Clazz.overrideMethod (c$, "run", \r
230 function () {\r
231 this.b$["java.awt.EventDispatchThread"].pumpOneEventForFilters (this.f$.myid);\r
232 });\r
233 c$ = Clazz.p0p ();\r
234 };\r
235 Clazz.pu$h(self.c$);\r
236 c$ = Clazz.decorateAsClass (function () {\r
237 this.modalComponent = null;\r
238 Clazz.instantialize (this, arguments);\r
239 }, java.awt.EventDispatchThread, "HierarchyEventFilter", null, java.awt.EventFilter);\r
240 Clazz.makeConstructor (c$, \r
241 function (a) {\r
242 this.modalComponent = a;\r
243 }, "java.awt.Component");\r
244 Clazz.overrideMethod (c$, "acceptEvent", \r
245 function (a) {\r
246 if (this.modalComponent != null) {\r
247 var b = a.getID ();\r
248 var c = (b >= 500) && (b <= 507);\r
249 var d = (b >= 1001) && (b <= 1001);\r
250 var e = (b == 201);\r
251 if (java.awt.Component.isInstanceOf (this.modalComponent, "javax.swing.JInternalFrame")) {\r
252 return e ? java.awt.EventFilter.FilterAction.REJECT : java.awt.EventFilter.FilterAction.ACCEPT;\r
253 }if (c || d || e) {\r
254 var f = a.getSource ();\r
255 if (Clazz.instanceOf (f, jssun.awt.ModalExclude)) {\r
256 return java.awt.EventFilter.FilterAction.ACCEPT;\r
257 } else if (Clazz.instanceOf (f, java.awt.Component)) {\r
258 var g = f;\r
259 var h = false;\r
260 if (Clazz.instanceOf (this.modalComponent, java.awt.Container)) {\r
261 while (g !== this.modalComponent && g != null) {\r
262 if ((Clazz.instanceOf (g, java.awt.Window)) && (jssun.awt.SunToolkit.isModalExcluded (g))) {\r
263 h = true;\r
264 break;\r
265 }g = g.getParent ();\r
266 }\r
267 }if (!h && (g !== this.modalComponent)) {\r
268 return java.awt.EventFilter.FilterAction.REJECT;\r
269 }}}}return java.awt.EventFilter.FilterAction.ACCEPT;\r
270 }, "java.awt.AWTEvent");\r
271 c$ = Clazz.p0p ();\r
272 Clazz.defineStatics (c$,\r
273 "ANY_EVENT", -1);\r
274 });\r