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 () {
7 this.desiredLocationX = 0;
8 this.desiredLocationY = 0;
10 this.$paintBorder = true;
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",
18 javax.swing.SwingUtilities.appContextPut (javax.swing.JPopupMenu.defaultLWPopupEnabledKey, Boolean.$valueOf (aFlag));
20 c$.getDefaultLightWeightPopupEnabled = Clazz.defineMethod (c$, "getDefaultLightWeightPopupEnabled",
22 var b = javax.swing.SwingUtilities.appContextGet (javax.swing.JPopupMenu.defaultLWPopupEnabledKey);
24 javax.swing.SwingUtilities.appContextPut (javax.swing.JPopupMenu.defaultLWPopupEnabledKey, Boolean.TRUE);
26 }return b.booleanValue ();
28 Clazz.makeConstructor (c$,
30 this.construct (null);
32 Clazz.makeConstructor (c$,
34 Clazz.superConstructor (this, javax.swing.JPopupMenu, []);
36 this.lightWeightPopup = javax.swing.JPopupMenu.getDefaultLightWeightPopupEnabled ();
37 this.setSelectionModel ( new javax.swing.DefaultSingleSelectionModel ());
38 this.enableEvents (16);
41 Clazz.overrideMethod (c$, "getUI",
45 Clazz.overrideMethod (c$, "updateUI",
47 this.setUI (javax.swing.UIManager.getUI (this));
49 Clazz.overrideMethod (c$, "getUIClassID",
53 Clazz.defineMethod (c$, "processKeyEvent",
55 javax.swing.MenuSelectionManager.defaultManager ().processKeyEvent (evt);
56 if (evt.isConsumed ()) {
58 }Clazz.superCall (this, javax.swing.JPopupMenu, "processKeyEvent", [evt]);
59 }, "java.awt.event.KeyEvent");
60 Clazz.defineMethod (c$, "getSelectionModel",
62 return this.selectionModel;
64 Clazz.defineMethod (c$, "setSelectionModel",
66 this.selectionModel = model;
67 }, "javax.swing.SingleSelectionModel");
68 Clazz.defineMethod (c$, "add",
70 Clazz.superCall (this, javax.swing.JPopupMenu, "add", [menuItem]);
72 }, "javax.swing.JMenuItem");
73 Clazz.defineMethod (c$, "add",
75 return this.add ( new javax.swing.JMenuItem (s));
77 Clazz.defineMethod (c$, "add",
79 var mi = this.createActionComponent (a);
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;
90 Clazz.defineMethod (c$, "createActionComponent",
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);
96 }, "javax.swing.Action");
97 Clazz.defineMethod (c$, "createActionChangeListener",
99 return b.createActionPropertyChangeListener0 (b.getAction ());
100 }, "javax.swing.JMenuItem");
101 Clazz.defineMethod (c$, "remove",
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]);
109 Clazz.defineMethod (c$, "setLightWeightPopupEnabled",
111 this.lightWeightPopup = aFlag;
113 Clazz.defineMethod (c$, "isLightWeightPopupEnabled",
115 return this.lightWeightPopup;
117 Clazz.defineMethod (c$, "getLabel",
121 Clazz.defineMethod (c$, "setLabel",
123 var oldValue = this.label;
125 this.firePropertyChangeObject ("label", oldValue, label);
129 Clazz.defineMethod (c$, "addSeparator",
131 this.add ( new javax.swing.JPopupMenu.Separator ());
133 Clazz.defineMethod (c$, "insert",
134 function (a, index) {
135 var mi = this.createActionComponent (a);
137 this.insert (mi, index);
138 }, "javax.swing.Action,~N");
139 Clazz.defineMethod (c$, "insert",
140 function (component, index) {
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));
149 this.add (component);
150 for (var i = 0; i < tempItems.size (); i++) {
151 this.add (tempItems.elementAt (i));
153 }, "java.awt.Component,~N");
154 Clazz.defineMethod (c$, "addPopupMenuListener",
156 this.listenerList.add (javax.swing.event.PopupMenuListener, l);
157 }, "javax.swing.event.PopupMenuListener");
158 Clazz.defineMethod (c$, "removePopupMenuListener",
160 this.listenerList.remove (javax.swing.event.PopupMenuListener, l);
161 }, "javax.swing.event.PopupMenuListener");
162 Clazz.defineMethod (c$, "getPopupMenuListeners",
164 return this.listenerList.getListeners (javax.swing.event.PopupMenuListener);
166 Clazz.defineMethod (c$, "addMenuKeyListener",
168 this.listenerList.add (javax.swing.event.MenuKeyListener, l);
169 }, "javax.swing.event.MenuKeyListener");
170 Clazz.defineMethod (c$, "removeMenuKeyListener",
172 this.listenerList.remove (javax.swing.event.MenuKeyListener, l);
173 }, "javax.swing.event.MenuKeyListener");
174 Clazz.defineMethod (c$, "getMenuKeyListeners",
176 return this.listenerList.getListeners (javax.swing.event.MenuKeyListener);
178 Clazz.defineMethod (c$, "firePopupMenuWillBecomeVisible",
180 var listeners = this.listenerList.getListenerList ();
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);
188 Clazz.defineMethod (c$, "firePopupMenuWillBecomeInvisible",
190 var listeners = this.listenerList.getListenerList ();
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);
198 Clazz.defineMethod (c$, "firePopupMenuCanceled",
200 var listeners = this.listenerList.getListenerList ();
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);
208 Clazz.overrideMethod (c$, "alwaysOnTop",
212 Clazz.defineMethod (c$, "pack",
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 ();
221 Clazz.overrideMethod (c$, "setVisible",
223 if (b == this.isVisible ()) return;
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 ();
231 if (this.isPopupMenu ()) {
232 var me = new Array (1);
234 javax.swing.MenuSelectionManager.defaultManager ().setSelectedPath (me);
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 ();
243 this.firePropertyChangeObject ("visible", Boolean.TRUE, Boolean.FALSE);
244 if (this.isPopupMenu ()) {
245 javax.swing.MenuSelectionManager.defaultManager ().clearSelectedPath ();
247 Clazz.defineMethod (c$, "getPopup",
249 var oldPopup = this.popup;
250 if (oldPopup != null) {
252 }var popupFactory = javax.swing.PopupFactory.getSharedInstance ();
253 if (this.isLightWeightPopupEnabled ()) {
254 popupFactory.setPopupType (0);
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);
265 Clazz.overrideMethod (c$, "isVisible",
267 if (this.popup != null) return true;
270 Clazz.defineMethod (c$, "setLocation",
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 ();
279 Clazz.defineMethod (c$, "isPopupMenu",
281 return ((this.invoker != null) && !(Clazz.instanceOf (this.invoker, javax.swing.JMenu)));
283 Clazz.defineMethod (c$, "getInvoker",
287 Clazz.defineMethod (c$, "setInvoker",
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);
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 ();
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);
318 this.setLocation (x, y);
319 }this.setVisible (true);
320 }, "java.awt.Component,~N,~N");
321 Clazz.defineMethod (c$, "getRootPopupMenu",
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 ();
329 Clazz.defineMethod (c$, "getComponentAtIndex",
331 return this.getComponent (i);
333 Clazz.defineMethod (c$, "getComponentIndex",
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;
342 }, "java.awt.Component");
343 Clazz.defineMethod (c$, "setPopupSize",
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));
356 Clazz.defineMethod (c$, "setSelected",
358 var model = this.getSelectionModel ();
359 var index = this.getComponentIndex (sel);
360 model.setSelectedIndex (index);
361 }, "java.awt.Component");
362 Clazz.defineMethod (c$, "isBorderPainted",
364 return this.$paintBorder;
366 Clazz.defineMethod (c$, "setBorderPainted",
368 this.$paintBorder = b;
371 Clazz.defineMethod (c$, "paintBorder",
373 if (this.isBorderPainted ()) {
374 Clazz.superCall (this, javax.swing.JPopupMenu, "paintBorder", [g]);
375 }}, "java.awt.Graphics");
376 Clazz.defineMethod (c$, "getMargin",
378 if (this.margin == null) {
379 return new java.awt.Insets (0, 0, 0, 0);
383 Clazz.defineMethod (c$, "isSubPopupMenu",
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)) {
391 var subPopup = menu.getPopupMenu ();
392 if (subPopup === popup) return true;
393 if (subPopup.isSubPopupMenu (popup)) return true;
396 }, "javax.swing.JPopupMenu");
397 c$.getFrame = Clazz.defineMethod (c$, "getFrame",
400 while (!(Clazz.instanceOf (w, java.awt.Frame)) && (w != null)) {
404 }, "java.awt.Component");
405 Clazz.defineMethod (c$, "paramString",
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;
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 ()) {
422 }}, "java.awt.event.KeyEvent,~A,javax.swing.MenuSelectionManager");
423 Clazz.defineMethod (c$, "processMenuKeyEvent",
425 switch (e.getID ()) {
427 this.fireMenuKeyPressed (e);
430 this.fireMenuKeyReleased (e);
433 this.fireMenuKeyTyped (e);
438 }, "javax.swing.event.MenuKeyEvent");
439 Clazz.defineMethod (c$, "fireMenuKeyPressed",
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);
446 }, "javax.swing.event.MenuKeyEvent");
447 Clazz.defineMethod (c$, "fireMenuKeyReleased",
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);
454 }, "javax.swing.event.MenuKeyEvent");
455 Clazz.defineMethod (c$, "fireMenuKeyTyped",
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);
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);
471 Clazz.overrideMethod (c$, "getSubElements",
474 var tmp = new java.util.Vector ();
475 var c = this.getComponentCount ();
478 for (i = 0; i < c; i++) {
479 m = this.getComponent (i);
480 if (Clazz.instanceOf (m, javax.swing.MenuElement)) tmp.addElement (m);
482 result = new Array (tmp.size ());
483 for (i = 0, c = tmp.size (); i < c; i++) result[i] = tmp.elementAt (i);
487 Clazz.defineMethod (c$, "getComponent",
491 Clazz.defineMethod (c$, "isPopupTrigger",
493 return this.getUI ().isPopupTrigger (e);
494 }, "java.awt.event.MouseEvent");
495 c$.$JPopupMenu$1$ = function () {
497 c$ = Clazz.declareAnonymous (javax.swing, "JPopupMenu$1", javax.swing.JMenuItem);
498 Clazz.defineMethod (c$, "createActionPropertyChangeListener",
500 var pcl = this.b$["javax.swing.JPopupMenu"].createActionChangeListener (this);
502 pcl = Clazz.superCall (this, javax.swing.JPopupMenu$1, "createActionPropertyChangeListener", [a]);
504 }, "javax.swing.Action");
508 c$ = Clazz.declareType (javax.swing.JPopupMenu, "Separator", javax.swing.JSeparator);
509 Clazz.makeConstructor (c$,
511 Clazz.superConstructor (this, javax.swing.JPopupMenu.Separator, [0]);
513 Clazz.overrideMethod (c$, "getUIClassID",
515 return "PopupMenuSeparatorUI";
518 Clazz.defineStatics (c$,
519 "$uiClassID", "PopupMenuUI");
520 c$.defaultLWPopupEnabledKey = c$.prototype.defaultLWPopupEnabledKey = new Clazz._O ();
521 Clazz.defineStatics (c$,
522 "popupPostionFixDisabled", false);