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