00de6b77b8fc71271841d216a83d5466aefcba64
[jalviewjs.git] / site / swingjs / j2s / javax / swing / PopupFactory.js
1 Clazz.declarePackage ("javax.swing");
2 Clazz.load (["java.awt.Panel", "javax.swing.Popup", "$.SwingHeavyWeight", "java.awt.BorderLayout"], "javax.swing.PopupFactory", ["java.lang.Boolean", "$.IllegalArgumentException", "java.util.ArrayList", "$.HashMap", "java.applet.Applet", "java.awt.Container", "$.Insets", "$.Rectangle", "$.Toolkit", "$.Window", "java.awt.event.WindowAdapter", "javax.swing.ClientPropertyKey", "$.JApplet", "$.JComponent", "$.JDialog", "$.JFrame", "$.JLayeredPane", "$.JPanel", "$.JPopupMenu", "$.JRootPane", "$.JSeparator", "$.JToolTip", "$.JWindow", "$.MenuElement", "javax.swing.Popup.DefaultFrame", "$.HeavyWeightWindow", "javax.swing.RootPaneContainer", "$.SwingUtilities"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.popupType = 0;
5 Clazz.instantialize (this, arguments);
6 }, javax.swing, "PopupFactory");
7 c$.setSharedInstance = Clazz.defineMethod (c$, "setSharedInstance", 
8 function (factory) {
9 if (factory == null) {
10 throw  new IllegalArgumentException ("PopupFactory can not be null");
11 }javax.swing.SwingUtilities.appContextPut (javax.swing.PopupFactory.SharedInstanceKey, factory);
12 }, "javax.swing.PopupFactory");
13 c$.getSharedInstance = Clazz.defineMethod (c$, "getSharedInstance", 
14 function () {
15 var factory = javax.swing.SwingUtilities.appContextGet (javax.swing.PopupFactory.SharedInstanceKey);
16 if (factory == null) {
17 factory =  new javax.swing.PopupFactory ();
18 javax.swing.PopupFactory.setSharedInstance (factory);
19 }return factory;
20 });
21 Clazz.defineMethod (c$, "setPopupType", 
22 function (type) {
23 this.popupType = type;
24 }, "~N");
25 Clazz.defineMethod (c$, "getPopupType", 
26 function () {
27 return this.popupType;
28 });
29 Clazz.defineMethod (c$, "getPopup", 
30 function (owner, contents, x, y) {
31 if (contents == null) {
32 throw  new IllegalArgumentException ("Popup.getPopup must be passed non-null contents");
33 }var popupType = this.getPopupType (owner, contents, x, y);
34 var popup = this.getPopup (owner, contents, x, y, popupType);
35 if (popup == null) {
36 popup = this.getPopup (owner, contents, x, y, 2);
37 }return popup;
38 }, "java.awt.Component,java.awt.Component,~N,~N");
39 Clazz.defineMethod (c$, "getPopupType", 
40  function (owner, contents, ownerX, ownerY) {
41 var popupType = this.getPopupType ();
42 if (owner == null || this.invokerInHeavyWeightPopup (owner)) {
43 popupType = 2;
44 } else if (popupType == 0 && !(Clazz.instanceOf (contents, javax.swing.JToolTip)) && !(Clazz.instanceOf (contents, javax.swing.JPopupMenu))) {
45 popupType = 1;
46 }var c = owner;
47 while (c != null) {
48 if (Clazz.instanceOf (c, javax.swing.JComponent)) {
49 if ((c).getClientProperty (javax.swing.ClientPropertyKey.PopupFactory_FORCE_HEAVYWEIGHT_POPUP) === Boolean.TRUE) {
50 popupType = 2;
51 break;
52 }}c = c.getParent ();
53 }
54 return popupType;
55 }, "java.awt.Component,java.awt.Component,~N,~N");
56 Clazz.defineMethod (c$, "getPopup", 
57  function (owner, contents, ownerX, ownerY, popupType) {
58 switch (popupType) {
59 case 0:
60 return this.getLightWeightPopup (owner, contents, ownerX, ownerY);
61 case 1:
62 return this.getMediumWeightPopup (owner, contents, ownerX, ownerY);
63 case 2:
64 return this.getHeavyWeightPopup (owner, contents, ownerX, ownerY);
65 }
66 return null;
67 }, "java.awt.Component,java.awt.Component,~N,~N,~N");
68 Clazz.defineMethod (c$, "getLightWeightPopup", 
69  function (owner, contents, ownerX, ownerY) {
70 return javax.swing.PopupFactory.LightWeightPopup.getLightWeightPopup (owner, contents, ownerX, ownerY);
71 }, "java.awt.Component,java.awt.Component,~N,~N");
72 Clazz.defineMethod (c$, "getMediumWeightPopup", 
73  function (owner, contents, ownerX, ownerY) {
74 return javax.swing.PopupFactory.MediumWeightPopup.getMediumWeightPopup (owner, contents, ownerX, ownerY);
75 }, "java.awt.Component,java.awt.Component,~N,~N");
76 Clazz.defineMethod (c$, "getHeavyWeightPopup", 
77  function (owner, contents, ownerX, ownerY) {
78 return javax.swing.PopupFactory.HeavyWeightPopup.getHeavyWeightPopup (owner, contents, ownerX, ownerY);
79 }, "java.awt.Component,java.awt.Component,~N,~N");
80 Clazz.defineMethod (c$, "invokerInHeavyWeightPopup", 
81  function (i) {
82 if (i != null) {
83 var parent;
84 for (parent = i.getParent (); parent != null; parent = parent.getParent ()) {
85 if (Clazz.instanceOf (parent, javax.swing.Popup.HeavyWeightWindow)) {
86 return true;
87 }}
88 }return false;
89 }, "java.awt.Component");
90 Clazz.pu$h(self.c$);
91 c$ = Clazz.declareType (javax.swing.PopupFactory, "HeavyWeightPopup", javax.swing.Popup);
92 c$.getHeavyWeightPopup = Clazz.defineMethod (c$, "getHeavyWeightPopup", 
93 function (a, b, c, d) {
94 var e = (a != null) ? javax.swing.SwingUtilities.getWindowAncestor (a) : null;
95 var f = null;
96 if (e != null) {
97 f = javax.swing.PopupFactory.HeavyWeightPopup.getRecycledHeavyWeightPopup (e);
98 }var g = false;
99 if (b != null && b.isFocusable ()) {
100 if (Clazz.instanceOf (b, javax.swing.JPopupMenu)) {
101 var h = b;
102 var i = h.getComponents ();
103 for (var j = 0; j < i.length; j++) {
104 if (!(Clazz.instanceOf (i[j], javax.swing.MenuElement)) && !(Clazz.instanceOf (i[j], javax.swing.JSeparator))) {
105 g = true;
106 break;
107 }}
108 }}if (f == null || (f.getComponent ()).getFocusableWindowState () != g) {
109 if (f != null) {
110 f._dispose ();
111 }f =  new javax.swing.PopupFactory.HeavyWeightPopup ();
112 }f.reset (a, b, c, d);
113 if (g) {
114 var h = f.getComponent ();
115 h.setFocusableWindowState (true);
116 h.setName ("###focusableSwingPopup###");
117 }return f;
118 }, "java.awt.Component,java.awt.Component,~N,~N");
119 c$.getRecycledHeavyWeightPopup = Clazz.defineMethod (c$, "getRecycledHeavyWeightPopup", 
120  function (a) {
121 {
122 var b;
123 var c = javax.swing.PopupFactory.HeavyWeightPopup.getHeavyWeightPopupCache ();
124 if (c.containsKey (a)) {
125 b = c.get (a);
126 } else {
127 return null;
128 }var d;
129 if ((d = b.size ()) > 0) {
130 var e = b.get (0);
131 b.remove (0);
132 return e;
133 }return null;
134 }}, "java.awt.Window");
135 c$.getHeavyWeightPopupCache = Clazz.defineMethod (c$, "getHeavyWeightPopupCache", 
136  function () {
137 {
138 var a = javax.swing.SwingUtilities.appContextGet (javax.swing.PopupFactory.HeavyWeightPopup.heavyWeightPopupCacheKey);
139 if (a == null) {
140 a =  new java.util.HashMap (2);
141 javax.swing.SwingUtilities.appContextPut (javax.swing.PopupFactory.HeavyWeightPopup.heavyWeightPopupCacheKey, a);
142 }return a;
143 }});
144 c$.recycleHeavyWeightPopup = Clazz.defineMethod (c$, "recycleHeavyWeightPopup", 
145  function (a) {
146 {
147 var b;
148 var c = javax.swing.SwingUtilities.getWindowAncestor (a.getComponent ());
149 var d = javax.swing.PopupFactory.HeavyWeightPopup.getHeavyWeightPopupCache ();
150 if (Clazz.instanceOf (c, javax.swing.Popup.DefaultFrame) || !(c).isVisible ()) {
151 a._dispose ();
152 return;
153 } else if (d.containsKey (c)) {
154 b = d.get (c);
155 } else {
156 b =  new java.util.ArrayList ();
157 d.put (c, b);
158 var e = c;
159 e.addWindowListener (((Clazz.isClassDefined ("javax.swing.PopupFactory$HeavyWeightPopup$1") ? 0 : javax.swing.PopupFactory.HeavyWeightPopup.$PopupFactory$HeavyWeightPopup$1$ ()), Clazz.innerTypeInstance (javax.swing.PopupFactory$HeavyWeightPopup$1, this, Clazz.cloneFinals ("e", e))));
160 }if (b.size () < 5) {
161 b.add (a);
162 } else {
163 a._dispose ();
164 }}}, "javax.swing.PopupFactory.HeavyWeightPopup");
165 Clazz.defineMethod (c$, "hide", 
166 function () {
167 Clazz.superCall (this, javax.swing.PopupFactory.HeavyWeightPopup, "hide", []);
168 javax.swing.PopupFactory.HeavyWeightPopup.recycleHeavyWeightPopup (this);
169 });
170 Clazz.defineMethod (c$, "dispose", 
171 function () {
172 });
173 Clazz.defineMethod (c$, "_dispose", 
174 function () {
175 Clazz.superCall (this, javax.swing.PopupFactory.HeavyWeightPopup, "dispose", []);
176 });
177 c$.$PopupFactory$HeavyWeightPopup$1$ = function () {
178 Clazz.pu$h(self.c$);
179 c$ = Clazz.declareAnonymous (javax.swing, "PopupFactory$HeavyWeightPopup$1", java.awt.event.WindowAdapter);
180 Clazz.overrideMethod (c$, "windowClosed", 
181 function (a) {
182 var b;
183 {
184 var c = javax.swing.PopupFactory.HeavyWeightPopup.getHeavyWeightPopupCache ();
185 b = c.remove (this.f$.e);
186 }if (b != null) {
187 for (var c = b.size () - 1; c >= 0; c--) {
188 (b.get (c))._dispose ();
189 }
190 }}, "java.awt.event.WindowEvent");
191 c$ = Clazz.p0p ();
192 };
193 c$.heavyWeightPopupCacheKey = c$.prototype.heavyWeightPopupCacheKey =  new Clazz._O ();
194 c$ = Clazz.p0p ();
195 Clazz.pu$h(self.c$);
196 c$ = Clazz.decorateAsClass (function () {
197 this.owner = null;
198 this.x = 0;
199 this.y = 0;
200 Clazz.instantialize (this, arguments);
201 }, javax.swing.PopupFactory, "ContainerPopup", javax.swing.Popup);
202 Clazz.overrideMethod (c$, "hide", 
203 function () {
204 var a = this.getComponent ();
205 if (a != null) {
206 var b = a.getParent ();
207 if (b != null) {
208 var c = a.getBounds ();
209 b.remove (a);
210 b.repaint (c.x, c.y, c.width, c.height);
211 }}this.owner = null;
212 });
213 Clazz.overrideMethod (c$, "pack", 
214 function () {
215 var a = this.getComponent ();
216 if (a != null) {
217 a.setSize (a.getPreferredSize ());
218 }});
219 Clazz.defineMethod (c$, "reset", 
220 function (a, b, c, d) {
221 if ((Clazz.instanceOf (a, javax.swing.JFrame)) || (Clazz.instanceOf (a, javax.swing.JDialog)) || (Clazz.instanceOf (a, javax.swing.JWindow))) {
222 a = (a).getLayeredPane ();
223 }Clazz.superCall (this, javax.swing.PopupFactory.ContainerPopup, "reset", [a, b, c, d]);
224 this.x = c;
225 this.y = d;
226 this.owner = a;
227 }, "java.awt.Component,java.awt.Component,~N,~N");
228 Clazz.defineMethod (c$, "overlappedByOwnedWindow", 
229 function () {
230 var a = this.getComponent ();
231 if (this.owner != null && a != null) {
232 var b = javax.swing.SwingUtilities.getWindowAncestor (this.owner);
233 if (b == null) {
234 return false;
235 }var c = b.getOwnedWindows ();
236 if (c != null) {
237 var d = a.getBounds ();
238 for (var e = 0; e < c.length; e++) {
239 var f = c[e];
240 if (f.isVisible () && d.intersects (f.getBounds ())) {
241 return true;
242 }}
243 }}return false;
244 });
245 Clazz.defineMethod (c$, "fitsOnScreen", 
246 function () {
247 var a = this.getComponent ();
248 if (this.owner != null && a != null) {
249 var b;
250 var c = a.getWidth ();
251 var d = a.getHeight ();
252 for (b = this.owner.getParent (); b != null; b = b.getParent ()) {
253 if (Clazz.instanceOf (b, javax.swing.JFrame) || Clazz.instanceOf (b, javax.swing.JDialog) || Clazz.instanceOf (b, javax.swing.JWindow)) {
254 var e = b.getBounds ();
255 var f = b.getInsets ();
256 e.x += f.left;
257 e.y += f.top;
258 e.width -= (f.left + f.right);
259 e.height -= (f.top + f.bottom);
260 var g = b.getGraphicsConfiguration ();
261 var h = this.getContainerPopupArea (g);
262 return e.intersection (h).contains (this.x, this.y, c, d);
263 } else if (Clazz.instanceOf (b, javax.swing.JApplet)) {
264 var e = b.getBounds ();
265 var f = b.getLocationOnScreen ();
266 e.x = f.x;
267 e.y = f.y;
268 return e.contains (this.x, this.y, c, d);
269 } else if (Clazz.instanceOf (b, java.awt.Window) || Clazz.instanceOf (b, java.applet.Applet)) {
270 break;
271 }}
272 }return false;
273 });
274 Clazz.defineMethod (c$, "getContainerPopupArea", 
275 function (a) {
276 var b;
277 var c = java.awt.Toolkit.getDefaultToolkit ();
278 var d;
279 if (a != null) {
280 b = a.getBounds ();
281 d = c.getScreenInsets (a);
282 } else {
283 b =  new java.awt.Rectangle (c.getScreenSize ());
284 d =  new java.awt.Insets (0, 0, 0, 0);
285 }b.x += d.left;
286 b.y += d.top;
287 b.width -= (d.left + d.right);
288 b.height -= (d.top + d.bottom);
289 return b;
290 }, "java.awt.GraphicsConfiguration");
291 c$ = Clazz.p0p ();
292 Clazz.pu$h(self.c$);
293 c$ = Clazz.declareType (javax.swing.PopupFactory, "LightWeightPopup", javax.swing.PopupFactory.ContainerPopup);
294 c$.getLightWeightPopup = Clazz.defineMethod (c$, "getLightWeightPopup", 
295 function (a, b, c, d) {
296 var e = null;
297 if (e == null) {
298 e =  new javax.swing.PopupFactory.LightWeightPopup ();
299 }e.reset (a, b, c, d);
300 if (!e.fitsOnScreen () || e.overlappedByOwnedWindow ()) {
301 e.hide ();
302 return null;
303 }return e;
304 }, "java.awt.Component,java.awt.Component,~N,~N");
305 Clazz.defineMethod (c$, "hide", 
306 function () {
307 Clazz.superCall (this, javax.swing.PopupFactory.LightWeightPopup, "hide", []);
308 var a = this.getComponent ();
309 a.removeAll ();
310 });
311 Clazz.overrideMethod (c$, "show", 
312 function () {
313 var a = null;
314 if (this.owner != null) {
315 a = (Clazz.instanceOf (this.owner, java.awt.Container) ? this.owner : this.owner.getParent ());
316 }for (var b = a; b != null; b = b.getParent ()) {
317 if (Clazz.instanceOf (b, javax.swing.JRootPane)) {
318 a = (b).getLayeredPane ();
319 } else if (Clazz.instanceOf (b, java.awt.Window)) {
320 if (a == null) {
321 a = b;
322 }break;
323 } else if (Clazz.instanceOf (b, javax.swing.JApplet)) {
324 break;
325 }}
326 var c = javax.swing.SwingUtilities.convertScreenLocationToParent (a, this.x, this.y);
327 var d = this.getComponent ();
328 d.setLocation (c.x, c.y);
329 if (Clazz.instanceOf (a, javax.swing.JLayeredPane)) {
330 (a).add (d, javax.swing.JLayeredPane.POPUP_LAYER, 0);
331 } else {
332 a.add (d);
333 }});
334 Clazz.overrideMethod (c$, "createComponent", 
335 function (a) {
336 var b =  new javax.swing.JPanel ( new java.awt.BorderLayout (), true);
337 b.setOpaque (true);
338 return b;
339 }, "java.awt.Component");
340 Clazz.defineMethod (c$, "reset", 
341 function (a, b, c, d) {
342 Clazz.superCall (this, javax.swing.PopupFactory.LightWeightPopup, "reset", [a, b, c, d]);
343 var e = this.getComponent ();
344 e.setOpaque (b.isOpaque ());
345 e.setLocation (c, d);
346 e.add (b, "Center");
347 b.invalidate ();
348 this.pack ();
349 }, "java.awt.Component,java.awt.Component,~N,~N");
350 c$.lightWeightPopupCacheKey = c$.prototype.lightWeightPopupCacheKey =  new Clazz._O ();
351 c$ = Clazz.p0p ();
352 Clazz.pu$h(self.c$);
353 c$ = Clazz.decorateAsClass (function () {
354 this.rootPane = null;
355 Clazz.instantialize (this, arguments);
356 }, javax.swing.PopupFactory, "MediumWeightPopup", javax.swing.PopupFactory.ContainerPopup);
357 c$.getMediumWeightPopup = Clazz.defineMethod (c$, "getMediumWeightPopup", 
358 function (a, b, c, d) {
359 var e = javax.swing.PopupFactory.MediumWeightPopup.getRecycledMediumWeightPopup ();
360 if (e == null) {
361 e =  new javax.swing.PopupFactory.MediumWeightPopup ();
362 }e.reset (a, b, c, d);
363 if (!e.fitsOnScreen () || e.overlappedByOwnedWindow ()) {
364 e.hide ();
365 return null;
366 }return e;
367 }, "java.awt.Component,java.awt.Component,~N,~N");
368 c$.getMediumWeightPopupCache = Clazz.defineMethod (c$, "getMediumWeightPopupCache", 
369  function () {
370 var a = javax.swing.SwingUtilities.appContextGet (javax.swing.PopupFactory.MediumWeightPopup.mediumWeightPopupCacheKey);
371 if (a == null) {
372 a =  new java.util.ArrayList ();
373 javax.swing.SwingUtilities.appContextPut (javax.swing.PopupFactory.MediumWeightPopup.mediumWeightPopupCacheKey, a);
374 }return a;
375 });
376 c$.recycleMediumWeightPopup = Clazz.defineMethod (c$, "recycleMediumWeightPopup", 
377  function (a) {
378 {
379 var b = javax.swing.PopupFactory.MediumWeightPopup.getMediumWeightPopupCache ();
380 if (b.size () < 5) {
381 b.add (a);
382 }}}, "javax.swing.PopupFactory.MediumWeightPopup");
383 c$.getRecycledMediumWeightPopup = Clazz.defineMethod (c$, "getRecycledMediumWeightPopup", 
384  function () {
385 {
386 var a = javax.swing.PopupFactory.MediumWeightPopup.getMediumWeightPopupCache ();
387 var b;
388 if ((b = a.size ()) > 0) {
389 var c = a.get (0);
390 a.remove (0);
391 return c;
392 }return null;
393 }});
394 Clazz.defineMethod (c$, "hide", 
395 function () {
396 Clazz.superCall (this, javax.swing.PopupFactory.MediumWeightPopup, "hide", []);
397 this.rootPane.getContentPane ().removeAll ();
398 javax.swing.PopupFactory.MediumWeightPopup.recycleMediumWeightPopup (this);
399 });
400 Clazz.overrideMethod (c$, "show", 
401 function () {
402 var a = this.getComponent ();
403 var b = null;
404 if (this.owner != null) {
405 b = this.owner.getParent ();
406 }while (!(Clazz.instanceOf (b, java.awt.Window) || Clazz.instanceOf (b, java.applet.Applet)) && (b != null)) {
407 b = b.getParent ();
408 }
409 if (Clazz.instanceOf (b, javax.swing.RootPaneContainer)) {
410 b = (b).getLayeredPane ();
411 var c = javax.swing.SwingUtilities.convertScreenLocationToParent (b, this.x, this.y);
412 a.setVisible (false);
413 a.setLocation (c.x, c.y);
414 (b).add (a, javax.swing.JLayeredPane.POPUP_LAYER, 0);
415 } else {
416 var c = javax.swing.SwingUtilities.convertScreenLocationToParent (b, this.x, this.y);
417 a.setLocation (c.x, c.y);
418 a.setVisible (false);
419 b.add (a);
420 }a.setVisible (true);
421 });
422 Clazz.overrideMethod (c$, "createComponent", 
423 function (a) {
424 var b =  new javax.swing.PopupFactory.MediumWeightPopup.MediumWeightComponent ();
425 this.rootPane =  new javax.swing.JRootPane ();
426 this.rootPane.setOpaque (true);
427 b.add (this.rootPane, "Center");
428 return b;
429 }, "java.awt.Component");
430 Clazz.defineMethod (c$, "reset", 
431 function (a, b, c, d) {
432 Clazz.superCall (this, javax.swing.PopupFactory.MediumWeightPopup, "reset", [a, b, c, d]);
433 var e = this.getComponent ();
434 e.setLocation (c, d);
435 this.rootPane.getContentPane ().add (b, "Center");
436 b.invalidate ();
437 e.validate ();
438 this.pack ();
439 }, "java.awt.Component,java.awt.Component,~N,~N");
440 Clazz.pu$h(self.c$);
441 c$ = Clazz.declareType (javax.swing.PopupFactory.MediumWeightPopup, "MediumWeightComponent", java.awt.Panel, javax.swing.SwingHeavyWeight);
442 Clazz.makeConstructor (c$, 
443 function () {
444 Clazz.superConstructor (this, javax.swing.PopupFactory.MediumWeightPopup.MediumWeightComponent, [ new java.awt.BorderLayout ()]);
445 });
446 c$ = Clazz.p0p ();
447 c$.mediumWeightPopupCacheKey = c$.prototype.mediumWeightPopupCacheKey =  new Clazz._O ();
448 c$ = Clazz.p0p ();
449 c$.SharedInstanceKey = c$.prototype.SharedInstanceKey =  new Clazz._O ();
450 Clazz.defineStatics (c$,
451 "MAX_CACHE_SIZE", 5,
452 "LIGHT_WEIGHT_POPUP", 0,
453 "MEDIUM_WEIGHT_POPUP", 1,
454 "HEAVY_WEIGHT_POPUP", 2);
455 });