6fb999e494e40c6f79ee2f1b8a28409db6945420
[jalviewjs.git] / site / j2s / javax / swing / JPopupMenu.js
1 Clazz.declarePackage ("javax.swing");
2 Clazz.load (["javax.swing.JComponent", "$.JSeparator", "$.MenuElement"], "javax.swing.JPopupMenu", ["java.lang.Boolean", "$.IllegalArgumentException", "java.util.Vector", "java.awt.Dimension", "$.Frame", "$.GraphicsEnvironment", "$.Insets", "$.Point", "javax.swing.DefaultSingleSelectionModel", "$.JMenu", "$.JMenuItem", "$.MenuSelectionManager", "$.PopupFactory", "$.SwingUtilities", "$.UIManager", "javax.swing.event.MenuKeyEvent", "$.MenuKeyListener", "$.PopupMenuEvent", "$.PopupMenuListener"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.invoker = null;
5 this.popup = null;
6 this.frame = null;
7 this.desiredLocationX = 0;
8 this.desiredLocationY = 0;
9 this.label = null;
10 this.$paintBorder = true;
11 this.margin = null;
12 this.lightWeightPopup = true;
13 this.selectionModel = null;
14 Clazz.instantialize (this, arguments);
15 }, javax.swing, "JPopupMenu", javax.swing.JComponent, javax.swing.MenuElement);
16 c$.setDefaultLightWeightPopupEnabled = Clazz.defineMethod (c$, "setDefaultLightWeightPopupEnabled", 
17 function (aFlag) {
18 javax.swing.SwingUtilities.appContextPut (javax.swing.JPopupMenu.defaultLWPopupEnabledKey, Boolean.$valueOf (aFlag));
19 }, "~B");
20 c$.getDefaultLightWeightPopupEnabled = Clazz.defineMethod (c$, "getDefaultLightWeightPopupEnabled", 
21 function () {
22 var b = javax.swing.SwingUtilities.appContextGet (javax.swing.JPopupMenu.defaultLWPopupEnabledKey);
23 if (b == null) {
24 javax.swing.SwingUtilities.appContextPut (javax.swing.JPopupMenu.defaultLWPopupEnabledKey, Boolean.TRUE);
25 return true;
26 }return b.booleanValue ();
27 });
28 Clazz.makeConstructor (c$, 
29 function () {
30 this.construct (null);
31 });
32 Clazz.makeConstructor (c$, 
33 function (label) {
34 Clazz.superConstructor (this, javax.swing.JPopupMenu, []);
35 this.label = label;
36 this.lightWeightPopup = javax.swing.JPopupMenu.getDefaultLightWeightPopupEnabled ();
37 this.setSelectionModel ( new javax.swing.DefaultSingleSelectionModel ());
38 this.enableEvents (16);
39 this.updateUI ();
40 }, "~S");
41 Clazz.overrideMethod (c$, "getUI", 
42 function () {
43 return this.ui;
44 });
45 Clazz.overrideMethod (c$, "updateUI", 
46 function () {
47 this.setUI (javax.swing.UIManager.getUI (this));
48 });
49 Clazz.overrideMethod (c$, "getUIClassID", 
50 function () {
51 return "PopupMenuUI";
52 });
53 Clazz.defineMethod (c$, "processKeyEvent", 
54 function (evt) {
55 javax.swing.MenuSelectionManager.defaultManager ().processKeyEvent (evt);
56 if (evt.isConsumed ()) {
57 return;
58 }Clazz.superCall (this, javax.swing.JPopupMenu, "processKeyEvent", [evt]);
59 }, "java.awt.event.KeyEvent");
60 Clazz.defineMethod (c$, "getSelectionModel", 
61 function () {
62 return this.selectionModel;
63 });
64 Clazz.defineMethod (c$, "setSelectionModel", 
65 function (model) {
66 this.selectionModel = model;
67 }, "javax.swing.SingleSelectionModel");
68 Clazz.defineMethod (c$, "add", 
69 function (menuItem) {
70 Clazz.superCall (this, javax.swing.JPopupMenu, "add", [menuItem]);
71 return menuItem;
72 }, "javax.swing.JMenuItem");
73 Clazz.defineMethod (c$, "add", 
74 function (s) {
75 return this.add ( new javax.swing.JMenuItem (s));
76 }, "~S");
77 Clazz.defineMethod (c$, "add", 
78 function (a) {
79 var mi = this.createActionComponent (a);
80 mi.setAction (a);
81 this.add (mi);
82 return mi;
83 }, "javax.swing.Action");
84 Clazz.defineMethod (c$, "adjustPopupLocationToFitScreen", 
85 function (xposition, yposition) {
86 var p =  new java.awt.Point (xposition, yposition);
87 if (javax.swing.JPopupMenu.popupPostionFixDisabled == true || java.awt.GraphicsEnvironment.isHeadless ()) return p;
88 return p;
89 }, "~N,~N");
90 Clazz.defineMethod (c$, "createActionComponent", 
91 function (a) {
92 var mi = ((Clazz.isClassDefined ("javax.swing.JPopupMenu$1") ? 0 : javax.swing.JPopupMenu.$JPopupMenu$1$ ()), Clazz.innerTypeInstance (javax.swing.JPopupMenu$1, this, null));
93 mi.setHorizontalTextPosition (11);
94 mi.setVerticalTextPosition (0);
95 return mi;
96 }, "javax.swing.Action");
97 Clazz.defineMethod (c$, "createActionChangeListener", 
98 function (b) {
99 return b.createActionPropertyChangeListener0 (b.getAction ());
100 }, "javax.swing.JMenuItem");
101 Clazz.defineMethod (c$, "remove", 
102 function (pos) {
103 if (pos < 0) {
104 throw  new IllegalArgumentException ("index less than zero.");
105 }if (pos > this.getComponentCount () - 1) {
106 throw  new IllegalArgumentException ("index greater than the number of items.");
107 }Clazz.superCall (this, javax.swing.JPopupMenu, "remove", [pos]);
108 }, "~N");
109 Clazz.defineMethod (c$, "setLightWeightPopupEnabled", 
110 function (aFlag) {
111 this.lightWeightPopup = aFlag;
112 }, "~B");
113 Clazz.defineMethod (c$, "isLightWeightPopupEnabled", 
114 function () {
115 return this.lightWeightPopup;
116 });
117 Clazz.defineMethod (c$, "getLabel", 
118 function () {
119 return this.label;
120 });
121 Clazz.defineMethod (c$, "setLabel", 
122 function (label) {
123 var oldValue = this.label;
124 this.label = label;
125 this.firePropertyChangeObject ("label", oldValue, label);
126 this.invalidate ();
127 this.repaint ();
128 }, "~S");
129 Clazz.defineMethod (c$, "addSeparator", 
130 function () {
131 this.add ( new javax.swing.JPopupMenu.Separator ());
132 });
133 Clazz.defineMethod (c$, "insert", 
134 function (a, index) {
135 var mi = this.createActionComponent (a);
136 mi.setAction (a);
137 this.insert (mi, index);
138 }, "javax.swing.Action,~N");
139 Clazz.defineMethod (c$, "insert", 
140 function (component, index) {
141 if (index < 0) {
142 throw  new IllegalArgumentException ("index less than zero.");
143 }var nitems = this.getComponentCount ();
144 var tempItems =  new java.util.Vector ();
145 for (var i = index; i < nitems; i++) {
146 tempItems.addElement (this.getComponent (index));
147 this.remove (index);
148 }
149 this.add (component);
150 for (var i = 0; i < tempItems.size (); i++) {
151 this.add (tempItems.elementAt (i));
152 }
153 }, "java.awt.Component,~N");
154 Clazz.defineMethod (c$, "addPopupMenuListener", 
155 function (l) {
156 this.listenerList.add (javax.swing.event.PopupMenuListener, l);
157 }, "javax.swing.event.PopupMenuListener");
158 Clazz.defineMethod (c$, "removePopupMenuListener", 
159 function (l) {
160 this.listenerList.remove (javax.swing.event.PopupMenuListener, l);
161 }, "javax.swing.event.PopupMenuListener");
162 Clazz.defineMethod (c$, "getPopupMenuListeners", 
163 function () {
164 return this.listenerList.getListeners (javax.swing.event.PopupMenuListener);
165 });
166 Clazz.defineMethod (c$, "addMenuKeyListener", 
167 function (l) {
168 this.listenerList.add (javax.swing.event.MenuKeyListener, l);
169 }, "javax.swing.event.MenuKeyListener");
170 Clazz.defineMethod (c$, "removeMenuKeyListener", 
171 function (l) {
172 this.listenerList.remove (javax.swing.event.MenuKeyListener, l);
173 }, "javax.swing.event.MenuKeyListener");
174 Clazz.defineMethod (c$, "getMenuKeyListeners", 
175 function () {
176 return this.listenerList.getListeners (javax.swing.event.MenuKeyListener);
177 });
178 Clazz.defineMethod (c$, "firePopupMenuWillBecomeVisible", 
179 function () {
180 var listeners = this.listenerList.getListenerList ();
181 var e = null;
182 for (var i = listeners.length - 2; i >= 0; i -= 2) {
183 if (listeners[i] === javax.swing.event.PopupMenuListener) {
184 if (e == null) e =  new javax.swing.event.PopupMenuEvent (this);
185 (listeners[i + 1]).popupMenuWillBecomeVisible (e);
186 }}
187 });
188 Clazz.defineMethod (c$, "firePopupMenuWillBecomeInvisible", 
189 function () {
190 var listeners = this.listenerList.getListenerList ();
191 var e = null;
192 for (var i = listeners.length - 2; i >= 0; i -= 2) {
193 if (listeners[i] === javax.swing.event.PopupMenuListener) {
194 if (e == null) e =  new javax.swing.event.PopupMenuEvent (this);
195 (listeners[i + 1]).popupMenuWillBecomeInvisible (e);
196 }}
197 });
198 Clazz.defineMethod (c$, "firePopupMenuCanceled", 
199 function () {
200 var listeners = this.listenerList.getListenerList ();
201 var e = null;
202 for (var i = listeners.length - 2; i >= 0; i -= 2) {
203 if (listeners[i] === javax.swing.event.PopupMenuListener) {
204 if (e == null) e =  new javax.swing.event.PopupMenuEvent (this);
205 (listeners[i + 1]).popupMenuCanceled (e);
206 }}
207 });
208 Clazz.overrideMethod (c$, "alwaysOnTop", 
209 function () {
210 return true;
211 });
212 Clazz.defineMethod (c$, "pack", 
213 function () {
214 if (this.popup != null) {
215 var pref = this.getPreferredSize ();
216 if (pref == null || pref.width != this.getWidth () || pref.height != this.getHeight ()) {
217 this.popup = this.getPopup ();
218 } else {
219 this.validate ();
220 }}});
221 Clazz.overrideMethod (c$, "setVisible", 
222 function (b) {
223 if (b == this.isVisible ()) return;
224 if (b == false) {
225 var doCanceled = this.getClientProperty ("JPopupMenu.firePopupMenuCanceled");
226 if (doCanceled != null && doCanceled === Boolean.TRUE) {
227 this.putClientProperty ("JPopupMenu.firePopupMenuCanceled", Boolean.FALSE);
228 this.firePopupMenuCanceled ();
229 }this.getSelectionModel ().clearSelection ();
230 } else {
231 if (this.isPopupMenu ()) {
232 var me =  new Array (1);
233 me[0] = this;
234 javax.swing.MenuSelectionManager.defaultManager ().setSelectedPath (me);
235 }}if (b) {
236 this.firePopupMenuWillBecomeVisible ();
237 this.popup = this.getPopup ();
238 this.firePropertyChangeObject ("visible", Boolean.FALSE, Boolean.TRUE);
239 } else if (this.popup != null) {
240 this.firePopupMenuWillBecomeInvisible ();
241 this.popup.hide ();
242 this.popup = null;
243 this.firePropertyChangeObject ("visible", Boolean.TRUE, Boolean.FALSE);
244 if (this.isPopupMenu ()) {
245 javax.swing.MenuSelectionManager.defaultManager ().clearSelectedPath ();
246 }}}, "~B");
247 Clazz.defineMethod (c$, "getPopup", 
248  function () {
249 var oldPopup = this.popup;
250 if (oldPopup != null) {
251 oldPopup.hide ();
252 }var popupFactory = javax.swing.PopupFactory.getSharedInstance ();
253 if (this.isLightWeightPopupEnabled ()) {
254 popupFactory.setPopupType (0);
255 } else {
256 popupFactory.setPopupType (1);
257 }var p = this.adjustPopupLocationToFitScreen (this.desiredLocationX, this.desiredLocationY);
258 this.desiredLocationX = p.x;
259 this.desiredLocationY = p.y;
260 var newPopup = this.getUI ().getPopup (this, this.desiredLocationX, this.desiredLocationY);
261 popupFactory.setPopupType (0);
262 newPopup.show ();
263 return newPopup;
264 });
265 Clazz.overrideMethod (c$, "isVisible", 
266 function () {
267 if (this.popup != null) return true;
268  else return false;
269 });
270 Clazz.defineMethod (c$, "setLocation", 
271 function (x, y) {
272 var oldX = this.desiredLocationX;
273 var oldY = this.desiredLocationY;
274 this.desiredLocationX = x;
275 this.desiredLocationY = y;
276 if (this.popup != null && (x != oldX || y != oldY)) {
277 this.popup = this.getPopup ();
278 }}, "~N,~N");
279 Clazz.defineMethod (c$, "isPopupMenu", 
280  function () {
281 return ((this.invoker != null) && !(Clazz.instanceOf (this.invoker, javax.swing.JMenu)));
282 });
283 Clazz.defineMethod (c$, "getInvoker", 
284 function () {
285 return this.invoker;
286 });
287 Clazz.defineMethod (c$, "setInvoker", 
288 function (invoker) {
289 var oldInvoker = this.invoker;
290 this.invoker = invoker;
291 if ((oldInvoker !== this.invoker) && (this.ui != null)) {
292 this.ui.uninstallUI (this);
293 this.ui.installUI (this);
294 }this.invalidate ();
295 }, "java.awt.Component");
296 Clazz.defineMethod (c$, "show", 
297 function (invoker, x, y) {
298 this.setInvoker (invoker);
299 var newFrame = javax.swing.JPopupMenu.getFrame (invoker);
300 if (newFrame !== this.frame) {
301 if (newFrame != null) {
302 this.frame = newFrame;
303 if (this.popup != null) {
304 this.setVisible (false);
305 }}}var invokerOrigin;
306 if (invoker != null) {
307 invokerOrigin = invoker.getLocationOnScreen ();
308 var lx;
309 var ly;
310 lx = (invokerOrigin.x) + (x);
311 ly = (invokerOrigin.y) + (y);
312 if (lx > 2147483647) lx = 2147483647;
313 if (lx < -2147483648) lx = -2147483648;
314 if (ly > 2147483647) ly = 2147483647;
315 if (ly < -2147483648) ly = -2147483648;
316 this.setLocation (lx, ly);
317 } else {
318 this.setLocation (x, y);
319 }this.setVisible (true);
320 }, "java.awt.Component,~N,~N");
321 Clazz.defineMethod (c$, "getRootPopupMenu", 
322 function () {
323 var mp = this;
324 while ((mp != null) && (mp.isPopupMenu () != true) && (mp.getInvoker () != null) && (mp.getInvoker ().getParent () != null) && (Clazz.instanceOf (mp.getInvoker ().getParent (), javax.swing.JPopupMenu))) {
325 mp = mp.getInvoker ().getParent ();
326 }
327 return mp;
328 });
329 Clazz.defineMethod (c$, "getComponentAtIndex", 
330 function (i) {
331 return this.getComponent (i);
332 }, "~N");
333 Clazz.defineMethod (c$, "getComponentIndex", 
334 function (c) {
335 var ncomponents = this.getComponentCount ();
336 var component = this.getComponents ();
337 for (var i = 0; i < ncomponents; i++) {
338 var comp = component[i];
339 if (comp === c) return i;
340 }
341 return -1;
342 }, "java.awt.Component");
343 Clazz.defineMethod (c$, "setPopupSize", 
344 function (d) {
345 var oldSize = this.getPreferredSize ();
346 this.setPreferredSize (d);
347 if (this.popup != null) {
348 var newSize = this.getPreferredSize ();
349 if (!oldSize.equals (newSize)) {
350 this.popup = this.getPopup ();
351 }}}, "java.awt.Dimension");
352 Clazz.defineMethod (c$, "setPopupSize", 
353 function (width, height) {
354 this.setPopupSize ( new java.awt.Dimension (width, height));
355 }, "~N,~N");
356 Clazz.defineMethod (c$, "setSelected", 
357 function (sel) {
358 var model = this.getSelectionModel ();
359 var index = this.getComponentIndex (sel);
360 model.setSelectedIndex (index);
361 }, "java.awt.Component");
362 Clazz.defineMethod (c$, "isBorderPainted", 
363 function () {
364 return this.$paintBorder;
365 });
366 Clazz.defineMethod (c$, "setBorderPainted", 
367 function (b) {
368 this.$paintBorder = b;
369 this.repaint ();
370 }, "~B");
371 Clazz.defineMethod (c$, "paintBorder", 
372 function (g) {
373 if (this.isBorderPainted ()) {
374 Clazz.superCall (this, javax.swing.JPopupMenu, "paintBorder", [g]);
375 }}, "java.awt.Graphics");
376 Clazz.defineMethod (c$, "getMargin", 
377 function () {
378 if (this.margin == null) {
379 return  new java.awt.Insets (0, 0, 0, 0);
380 } else {
381 return this.margin;
382 }});
383 Clazz.defineMethod (c$, "isSubPopupMenu", 
384 function (popup) {
385 var ncomponents = this.getComponentCount ();
386 var component = this.getComponents ();
387 for (var i = 0; i < ncomponents; i++) {
388 var comp = component[i];
389 if (Clazz.instanceOf (comp, javax.swing.JMenu)) {
390 var menu = comp;
391 var subPopup = menu.getPopupMenu ();
392 if (subPopup === popup) return true;
393 if (subPopup.isSubPopupMenu (popup)) return true;
394 }}
395 return false;
396 }, "javax.swing.JPopupMenu");
397 c$.getFrame = Clazz.defineMethod (c$, "getFrame", 
398  function (c) {
399 var w = c;
400 while (!(Clazz.instanceOf (w, java.awt.Frame)) && (w != null)) {
401 w = w.getParent ();
402 }
403 return w;
404 }, "java.awt.Component");
405 Clazz.defineMethod (c$, "paramString", 
406 function () {
407 var labelString = (this.label != null ? this.label : "");
408 var paintBorderString = (this.$paintBorder ? "true" : "false");
409 var marginString = (this.margin != null ? this.margin.toString () : "");
410 var lightWeightPopupEnabledString = (this.isLightWeightPopupEnabled () ? "true" : "false");
411 return Clazz.superCall (this, javax.swing.JPopupMenu, "paramString", []) + ",desiredLocationX=" + this.desiredLocationX + ",desiredLocationY=" + this.desiredLocationY + ",label=" + labelString + ",lightWeightPopupEnabled=" + lightWeightPopupEnabledString + ",margin=" + marginString + ",paintBorder=" + paintBorderString;
412 });
413 Clazz.defineMethod (c$, "processMouseEvent", 
414 function (event, path, manager) {
415 }, "java.awt.event.MouseEvent,~A,javax.swing.MenuSelectionManager");
416 Clazz.defineMethod (c$, "processKeyEvent", 
417 function (e, path, manager) {
418 var mke =  new javax.swing.event.MenuKeyEvent (e.getComponent (), e.getID (), e.getWhen (), e.getModifiers (), e.getKeyCode (), e.getKeyChar (), path, manager);
419 this.processMenuKeyEvent (mke);
420 if (mke.isConsumed ()) {
421 e.consume ();
422 }}, "java.awt.event.KeyEvent,~A,javax.swing.MenuSelectionManager");
423 Clazz.defineMethod (c$, "processMenuKeyEvent", 
424  function (e) {
425 switch (e.getID ()) {
426 case 401:
427 this.fireMenuKeyPressed (e);
428 break;
429 case 402:
430 this.fireMenuKeyReleased (e);
431 break;
432 case 400:
433 this.fireMenuKeyTyped (e);
434 break;
435 default:
436 break;
437 }
438 }, "javax.swing.event.MenuKeyEvent");
439 Clazz.defineMethod (c$, "fireMenuKeyPressed", 
440  function (event) {
441 var listeners = this.listenerList.getListenerList ();
442 for (var i = listeners.length - 2; i >= 0; i -= 2) {
443 if (listeners[i] === javax.swing.event.MenuKeyListener) {
444 (listeners[i + 1]).menuKeyPressed (event);
445 }}
446 }, "javax.swing.event.MenuKeyEvent");
447 Clazz.defineMethod (c$, "fireMenuKeyReleased", 
448  function (event) {
449 var listeners = this.listenerList.getListenerList ();
450 for (var i = listeners.length - 2; i >= 0; i -= 2) {
451 if (listeners[i] === javax.swing.event.MenuKeyListener) {
452 (listeners[i + 1]).menuKeyReleased (event);
453 }}
454 }, "javax.swing.event.MenuKeyEvent");
455 Clazz.defineMethod (c$, "fireMenuKeyTyped", 
456  function (event) {
457 var listeners = this.listenerList.getListenerList ();
458 for (var i = listeners.length - 2; i >= 0; i -= 2) {
459 if (listeners[i] === javax.swing.event.MenuKeyListener) {
460 (listeners[i + 1]).menuKeyTyped (event);
461 }}
462 }, "javax.swing.event.MenuKeyEvent");
463 Clazz.overrideMethod (c$, "menuSelectionChanged", 
464 function (isIncluded) {
465 if (Clazz.instanceOf (this.invoker, javax.swing.JMenu)) {
466 var m = this.invoker;
467 if (isIncluded) m.setPopupMenuVisible (true);
468  else m.setPopupMenuVisible (false);
469 }if (this.isPopupMenu () && !isIncluded) this.setVisible (false);
470 }, "~B");
471 Clazz.overrideMethod (c$, "getSubElements", 
472 function () {
473 var result;
474 var tmp =  new java.util.Vector ();
475 var c = this.getComponentCount ();
476 var i;
477 var m;
478 for (i = 0; i < c; i++) {
479 m = this.getComponent (i);
480 if (Clazz.instanceOf (m, javax.swing.MenuElement)) tmp.addElement (m);
481 }
482 result =  new Array (tmp.size ());
483 for (i = 0, c = tmp.size (); i < c; i++) result[i] = tmp.elementAt (i);
484
485 return result;
486 });
487 Clazz.defineMethod (c$, "getComponent", 
488 function () {
489 return this;
490 });
491 Clazz.defineMethod (c$, "isPopupTrigger", 
492 function (e) {
493 return this.getUI ().isPopupTrigger (e);
494 }, "java.awt.event.MouseEvent");
495 c$.$JPopupMenu$1$ = function () {
496 Clazz.pu$h(self.c$);
497 c$ = Clazz.declareAnonymous (javax.swing, "JPopupMenu$1", javax.swing.JMenuItem);
498 Clazz.defineMethod (c$, "createActionPropertyChangeListener", 
499 function (a) {
500 var pcl = this.b$["javax.swing.JPopupMenu"].createActionChangeListener (this);
501 if (pcl == null) {
502 pcl = Clazz.superCall (this, javax.swing.JPopupMenu$1, "createActionPropertyChangeListener", [a]);
503 }return pcl;
504 }, "javax.swing.Action");
505 c$ = Clazz.p0p ();
506 };
507 Clazz.pu$h(self.c$);
508 c$ = Clazz.declareType (javax.swing.JPopupMenu, "Separator", javax.swing.JSeparator);
509 Clazz.makeConstructor (c$, 
510 function () {
511 Clazz.superConstructor (this, javax.swing.JPopupMenu.Separator, [0]);
512 });
513 Clazz.overrideMethod (c$, "getUIClassID", 
514 function () {
515 return "PopupMenuSeparatorUI";
516 });
517 c$ = Clazz.p0p ();
518 Clazz.defineStatics (c$,
519 "$uiClassID", "PopupMenuUI");
520 c$.defaultLWPopupEnabledKey = c$.prototype.defaultLWPopupEnabledKey =  new Clazz._O ();
521 Clazz.defineStatics (c$,
522 "popupPostionFixDisabled", false);
523 });