1 Clazz.declarePackage ("javax.swing");
2 Clazz.load (["java.awt.event.WindowAdapter", "javax.swing.JMenuItem", "$.MenuElement", "javax.swing.event.ChangeListener"], "javax.swing.JMenu", ["java.lang.Error", "$.IllegalArgumentException", "java.util.Vector", "java.awt.Point", "$.Rectangle", "$.Toolkit", "javax.swing.JMenuBar", "$.JPopupMenu", "$.MenuSelectionManager", "$.SwingUtilities", "$.UIManager", "javax.swing.event.MenuEvent", "$.MenuListener"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.$popupMenu = null;
5 this.menuChangeListener = null;
8 this.customMenuLocation = null;
9 this.popupListener = null;
10 if (!Clazz.isClassDefined ("javax.swing.JMenu.MenuChangeListener")) {
11 javax.swing.JMenu.$JMenu$MenuChangeListener$ ();
13 if (!Clazz.isClassDefined ("javax.swing.JMenu.WinListener")) {
14 javax.swing.JMenu.$JMenu$WinListener$ ();
16 Clazz.instantialize (this, arguments);
17 }, javax.swing, "JMenu", javax.swing.JMenuItem, javax.swing.MenuElement);
18 Clazz.makeConstructor (c$,
20 Clazz.superConstructor (this, javax.swing.JMenu, []);
21 this.init0 ("", null, -2147483648);
23 Clazz.makeConstructor (c$,
25 Clazz.superConstructor (this, javax.swing.JMenu, []);
26 this.init0 (s, null, -2147483648);
28 Clazz.makeConstructor (c$,
30 Clazz.superConstructor (this, javax.swing.JMenu, []);
31 this.init0 ("", null, -2147483648);
33 }, "javax.swing.Action");
34 Clazz.makeConstructor (c$,
36 Clazz.superConstructor (this, javax.swing.JMenu, []);
37 this.init0 (s, null, -2147483648);
39 Clazz.overrideMethod (c$, "initFocusability",
42 Clazz.overrideMethod (c$, "updateUI",
44 this.setUI (javax.swing.UIManager.getUI (this));
45 if (this.$popupMenu != null) {
46 this.$popupMenu.setUI (javax.swing.UIManager.getUI (this.$popupMenu));
48 Clazz.overrideMethod (c$, "getUIClassID",
52 Clazz.defineMethod (c$, "setModel",
54 var oldModel = this.getModel ();
55 Clazz.superCall (this, javax.swing.JMenu, "setModel", [newModel]);
56 if (oldModel != null && this.menuChangeListener != null) {
57 oldModel.removeChangeListener (this.menuChangeListener);
58 this.menuChangeListener = null;
59 }this.model = newModel;
60 if (newModel != null) {
61 this.menuChangeListener = this.createMenuChangeListener ();
62 newModel.addChangeListener (this.menuChangeListener);
63 }}, "javax.swing.ButtonModel");
64 Clazz.overrideMethod (c$, "isSelected",
66 return this.getModel ().isSelected ();
68 Clazz.overrideMethod (c$, "setSelected",
70 var model = this.getModel ();
71 if (b != model.isSelected ()) {
72 this.getModel ().setSelected (b);
74 Clazz.defineMethod (c$, "isPopupMenuVisible",
76 this.ensurePopupMenuCreated ();
77 return this.$popupMenu.isVisible ();
79 Clazz.defineMethod (c$, "setPopupMenuVisible",
81 var isVisible = this.isPopupMenuVisible ();
82 if (b != isVisible && (this.isEnabled () || !b)) {
83 this.ensurePopupMenuCreated ();
84 if ((b == true) && this.isShowing ()) {
85 var p = this.getCustomMenuLocation ();
87 p = this.getPopupMenuOrigin ();
88 }this.getPopupMenu ().show (this, p.x, p.y);
90 this.getPopupMenu ().setVisible (false);
92 Clazz.defineMethod (c$, "getPopupMenuOrigin",
96 var pm = this.getPopupMenu ();
97 var s = this.getSize ();
98 var pmSize = pm.getSize ();
99 if (pmSize.width == 0) {
100 pmSize = pm.getPreferredSize ();
101 }var position = this.getLocationOnScreen ();
102 var toolkit = java.awt.Toolkit.getDefaultToolkit ();
103 var gc = this.getGraphicsConfiguration ();
104 var screenBounds = new java.awt.Rectangle (toolkit.getScreenSize ());
106 screenBounds = gc.getBounds ();
107 var screenInsets = toolkit.getScreenInsets (gc);
108 screenBounds.width -= Math.abs (screenInsets.left + screenInsets.right);
109 screenBounds.height -= Math.abs (screenInsets.top + screenInsets.bottom);
110 position.x -= Math.abs (screenInsets.left);
111 position.y -= Math.abs (screenInsets.top);
112 }var parent = this.getParent ();
113 if (Clazz.instanceOf (parent, javax.swing.JPopupMenu)) {
114 var xOffset = javax.swing.UIManager.getInt ("Menu.submenuPopupOffsetX");
115 var yOffset = javax.swing.UIManager.getInt ("Menu.submenuPopupOffsetY");
116 if (javax.swing.SwingUtilities.isLeftToRight (this)) {
117 x = s.width + xOffset;
118 if (position.x + x + pmSize.width >= screenBounds.width + screenBounds.x && screenBounds.width - s.width < 2 * (position.x - screenBounds.x)) {
119 x = 0 - xOffset - pmSize.width;
121 x = 0 - xOffset - pmSize.width;
122 if (position.x + x < screenBounds.x && screenBounds.width - s.width > 2 * (position.x - screenBounds.x)) {
123 x = s.width + xOffset;
125 if (position.y + y + pmSize.height >= screenBounds.height + screenBounds.y && screenBounds.height - s.height < 2 * (position.y - screenBounds.y)) {
126 y = s.height - yOffset - pmSize.height;
128 var xOffset = javax.swing.UIManager.getInt ("Menu.menuPopupOffsetX");
129 var yOffset = javax.swing.UIManager.getInt ("Menu.menuPopupOffsetY");
130 if (javax.swing.SwingUtilities.isLeftToRight (this)) {
132 if (position.x + x + pmSize.width >= screenBounds.width + screenBounds.x && screenBounds.width - s.width < 2 * (position.x - screenBounds.x)) {
133 x = s.width - xOffset - pmSize.width;
135 x = s.width - xOffset - pmSize.width;
136 if (position.x + x < screenBounds.x && screenBounds.width - s.width > 2 * (position.x - screenBounds.x)) {
138 }}y = s.height + yOffset;
139 if (position.y + y + pmSize.height >= screenBounds.height && screenBounds.height - s.height < 2 * (position.y - screenBounds.y)) {
140 y = 0 - yOffset - pmSize.height;
141 }}return new java.awt.Point (x, y);
143 Clazz.defineMethod (c$, "getDelay",
147 Clazz.defineMethod (c$, "setDelay",
149 if (d < 0) throw new IllegalArgumentException ("Delay must be a positive integer");
152 Clazz.defineMethod (c$, "ensurePopupMenuCreated",
154 if (this.$popupMenu == null) {
155 this.$popupMenu = new javax.swing.JPopupMenu ();
156 this.$popupMenu.setInvoker (this);
157 this.popupListener = this.createWinListener (this.$popupMenu);
159 Clazz.defineMethod (c$, "getCustomMenuLocation",
161 return this.customMenuLocation;
163 Clazz.defineMethod (c$, "setMenuLocation",
165 this.customMenuLocation = new java.awt.Point (x, y);
166 if (this.$popupMenu != null) this.$popupMenu.setLocation (x, y);
168 Clazz.defineMethod (c$, "add",
169 function (menuItem) {
170 this.ensurePopupMenuCreated ();
171 return this.$popupMenu.add (menuItem);
172 }, "javax.swing.JMenuItem");
173 Clazz.defineMethod (c$, "add",
175 this.ensurePopupMenuCreated ();
176 this.$popupMenu.add (c);
178 }, "java.awt.Component");
179 Clazz.defineMethod (c$, "add",
180 function (c, index) {
181 this.ensurePopupMenuCreated ();
182 this.$popupMenu.add (c, index);
184 }, "java.awt.Component,~N");
185 Clazz.defineMethod (c$, "add",
187 return this.add ( new javax.swing.JMenuItem (s));
189 Clazz.defineMethod (c$, "add",
191 var mi = this.createActionComponent (a);
195 }, "javax.swing.Action");
196 Clazz.defineMethod (c$, "createActionComponent",
198 var mi = ((Clazz.isClassDefined ("javax.swing.JMenu$1") ? 0 : javax.swing.JMenu.$JMenu$1$ ()), Clazz.innerTypeInstance (javax.swing.JMenu$1, this, null));
199 mi.setHorizontalTextPosition (11);
200 mi.setVerticalTextPosition (0);
202 }, "javax.swing.Action");
203 Clazz.defineMethod (c$, "createActionChangeListener",
205 return b.createActionPropertyChangeListener0 (b.getAction ());
206 }, "javax.swing.JMenuItem");
207 Clazz.defineMethod (c$, "addSeparator",
209 this.ensurePopupMenuCreated ();
210 this.$popupMenu.addSeparator ();
212 Clazz.defineMethod (c$, "insert",
215 throw new IllegalArgumentException ("index less than zero.");
216 }this.ensurePopupMenuCreated ();
217 this.$popupMenu.insert ( new javax.swing.JMenuItem (s), pos);
219 Clazz.defineMethod (c$, "insert",
222 throw new IllegalArgumentException ("index less than zero.");
223 }this.ensurePopupMenuCreated ();
224 this.$popupMenu.insert (mi, pos);
226 }, "javax.swing.JMenuItem,~N");
227 Clazz.defineMethod (c$, "insert",
230 throw new IllegalArgumentException ("index less than zero.");
231 }this.ensurePopupMenuCreated ();
232 var mi = new javax.swing.JMenuItem (a);
233 mi.setHorizontalTextPosition (11);
234 mi.setVerticalTextPosition (0);
235 this.$popupMenu.insert (mi, pos);
237 }, "javax.swing.Action,~N");
238 Clazz.defineMethod (c$, "insertSeparator",
241 throw new IllegalArgumentException ("index less than zero.");
242 }this.ensurePopupMenuCreated ();
243 this.$popupMenu.insert ( new javax.swing.JPopupMenu.Separator (), index);
245 Clazz.defineMethod (c$, "getItem",
248 throw new IllegalArgumentException ("index less than zero.");
249 }var c = this.getMenuComponent (pos);
250 if (Clazz.instanceOf (c, javax.swing.JMenuItem)) {
255 Clazz.defineMethod (c$, "getItemCount",
257 return this.getMenuComponentCount ();
259 Clazz.defineMethod (c$, "isTearOff",
261 throw new Error ("boolean isTearOff() {} not yet implemented");
263 Clazz.defineMethod (c$, "remove",
266 throw new IllegalArgumentException ("index less than zero.");
267 }if (pos > this.getItemCount ()) {
268 throw new IllegalArgumentException ("index greater than the number of items.");
269 }if (this.$popupMenu != null) this.$popupMenu.remove (pos);
271 Clazz.defineMethod (c$, "remove",
273 if (Clazz.instanceOf (c, javax.swing.JMenuItem)) if (this.$popupMenu != null) this.$popupMenu.remove (c);
274 if (this.$popupMenu != null) this.$popupMenu.remove (c);
275 }, "java.awt.Component");
276 Clazz.defineMethod (c$, "removeAll",
278 if (this.$popupMenu != null) this.$popupMenu.removeAll ();
280 Clazz.defineMethod (c$, "getMenuComponentCount",
282 var componentCount = 0;
283 if (this.$popupMenu != null) componentCount = this.$popupMenu.getComponentCount ();
284 return componentCount;
286 Clazz.defineMethod (c$, "getMenuComponent",
288 if (this.$popupMenu != null) return this.$popupMenu.getComponent (n);
291 Clazz.defineMethod (c$, "getMenuComponents",
293 if (this.$popupMenu != null) return this.$popupMenu.getComponents ();
294 return new Array (0);
296 Clazz.defineMethod (c$, "isTopLevelMenu",
298 if (Clazz.instanceOf (this.getParent (), javax.swing.JMenuBar)) return true;
301 Clazz.defineMethod (c$, "isMenuComponent",
303 if (c === this) return true;
304 if (Clazz.instanceOf (c, javax.swing.JPopupMenu)) {
306 if (comp === this.getPopupMenu ()) return true;
307 }var ncomponents = this.getMenuComponentCount ();
308 var component = this.getMenuComponents ();
309 for (var i = 0; i < ncomponents; i++) {
310 var comp = component[i];
311 if (comp === c) return true;
312 if (Clazz.instanceOf (comp, javax.swing.JMenu)) {
314 if (subMenu.isMenuComponent (c)) return true;
317 }, "java.awt.Component");
318 Clazz.defineMethod (c$, "getPopupMenu",
320 this.ensurePopupMenuCreated ();
321 return this.$popupMenu;
323 Clazz.defineMethod (c$, "addMenuListener",
325 this.listenerList.add (javax.swing.event.MenuListener, l);
326 }, "javax.swing.event.MenuListener");
327 Clazz.defineMethod (c$, "removeMenuListener",
329 this.listenerList.remove (javax.swing.event.MenuListener, l);
330 }, "javax.swing.event.MenuListener");
331 Clazz.defineMethod (c$, "getMenuListeners",
333 return this.listenerList.getListeners (javax.swing.event.MenuListener);
335 Clazz.defineMethod (c$, "fireMenuSelected",
337 var listeners = this.listenerList.getListenerList ();
338 for (var i = listeners.length - 2; i >= 0; i -= 2) {
339 if (listeners[i] === javax.swing.event.MenuListener) {
340 if (listeners[i + 1] == null) {
341 throw new Error (this.getText () + " has a NULL Listener!! " + i);
343 if (this.menuEvent == null) this.menuEvent = new javax.swing.event.MenuEvent (this);
344 (listeners[i + 1]).menuSelected (this.menuEvent);
347 Clazz.defineMethod (c$, "fireMenuDeselected",
349 var listeners = this.listenerList.getListenerList ();
350 for (var i = listeners.length - 2; i >= 0; i -= 2) {
351 if (listeners[i] === javax.swing.event.MenuListener) {
352 if (listeners[i + 1] == null) {
353 throw new Error (this.getText () + " has a NULL Listener!! " + i);
355 if (this.menuEvent == null) this.menuEvent = new javax.swing.event.MenuEvent (this);
356 (listeners[i + 1]).menuDeselected (this.menuEvent);
359 Clazz.defineMethod (c$, "fireMenuCanceled",
361 var listeners = this.listenerList.getListenerList ();
362 for (var i = listeners.length - 2; i >= 0; i -= 2) {
363 if (listeners[i] === javax.swing.event.MenuListener) {
364 if (listeners[i + 1] == null) {
365 throw new Error (this.getText () + " has a NULL Listener!! " + i);
367 if (this.menuEvent == null) this.menuEvent = new javax.swing.event.MenuEvent (this);
368 (listeners[i + 1]).menuCanceled (this.menuEvent);
371 Clazz.overrideMethod (c$, "configureAcceleratorFromAction",
373 }, "javax.swing.Action");
374 Clazz.defineMethod (c$, "createMenuChangeListener",
376 return Clazz.innerTypeInstance (javax.swing.JMenu.MenuChangeListener, this, null);
378 Clazz.defineMethod (c$, "createWinListener",
380 return Clazz.innerTypeInstance (javax.swing.JMenu.WinListener, this, null, p);
381 }, "javax.swing.JPopupMenu");
382 Clazz.overrideMethod (c$, "menuSelectionChanged",
383 function (isIncluded) {
384 this.setSelected (isIncluded);
386 Clazz.overrideMethod (c$, "getSubElements",
388 if (this.$popupMenu == null) return new Array (0);
390 var result = new Array (1);
391 result[0] = this.$popupMenu;
394 Clazz.defineMethod (c$, "getComponent",
398 Clazz.defineMethod (c$, "applyComponentOrientation",
400 Clazz.superCall (this, javax.swing.JMenu, "applyComponentOrientation", [o]);
401 if (this.$popupMenu != null) {
402 var ncomponents = this.getMenuComponentCount ();
403 for (var i = 0; i < ncomponents; ++i) {
404 this.getMenuComponent (i).applyComponentOrientation (o);
406 this.$popupMenu.setComponentOrientation (o);
407 }}, "java.awt.ComponentOrientation");
408 Clazz.defineMethod (c$, "setComponentOrientation",
410 Clazz.superCall (this, javax.swing.JMenu, "setComponentOrientation", [o]);
411 if (this.$popupMenu != null) {
412 this.$popupMenu.setComponentOrientation (o);
413 }}, "java.awt.ComponentOrientation");
414 Clazz.overrideMethod (c$, "setAccelerator",
415 function (keyStroke) {
416 throw new Error ("setAccelerator() is not defined for JMenu. Use setMnemonic() instead.");
417 }, "javax.swing.KeyStroke");
418 Clazz.defineMethod (c$, "processKeyEvent",
420 javax.swing.MenuSelectionManager.defaultManager ().processKeyEvent (evt);
421 if (evt.isConsumed ()) return;
422 Clazz.superCall (this, javax.swing.JMenu, "processKeyEvent", [evt]);
423 }, "java.awt.event.KeyEvent");
424 Clazz.defineMethod (c$, "doClick",
425 function (pressTime) {
426 var me = this.buildMenuElementArray (this);
427 javax.swing.MenuSelectionManager.defaultManager ().setSelectedPath (me);
429 Clazz.defineMethod (c$, "buildMenuElementArray",
431 var elements = new java.util.Vector ();
432 var current = leaf.getPopupMenu ();
437 if (Clazz.instanceOf (current, javax.swing.JPopupMenu)) {
439 elements.insertElementAt (pop, 0);
440 current = pop.getInvoker ();
441 } else if (Clazz.instanceOf (current, javax.swing.JMenu)) {
443 elements.insertElementAt (menu, 0);
444 current = menu.getParent ();
445 } else if (Clazz.instanceOf (current, javax.swing.JMenuBar)) {
447 elements.insertElementAt (bar, 0);
448 var me = new Array (elements.size ());
449 elements.copyInto (me);
452 }, "javax.swing.JMenu");
453 c$.$JMenu$MenuChangeListener$ = function () {
455 c$ = Clazz.decorateAsClass (function () {
456 Clazz.prepareCallback (this, arguments);
457 this.isSelected = false;
458 Clazz.instantialize (this, arguments);
459 }, javax.swing.JMenu, "MenuChangeListener", null, javax.swing.event.ChangeListener);
460 Clazz.overrideMethod (c$, "stateChanged",
462 var b = a.getSource ();
463 var c = b.isSelected ();
464 if (c != this.isSelected) {
466 this.b$["javax.swing.JMenu"].fireMenuSelected ();
468 this.b$["javax.swing.JMenu"].fireMenuDeselected ();
469 }this.isSelected = c;
470 }}, "javax.swing.event.ChangeEvent");
473 c$.$JMenu$WinListener$ = function () {
475 c$ = Clazz.decorateAsClass (function () {
476 Clazz.prepareCallback (this, arguments);
477 this.popupMenu = null;
478 Clazz.instantialize (this, arguments);
479 }, javax.swing.JMenu, "WinListener", java.awt.event.WindowAdapter);
480 Clazz.makeConstructor (c$,
482 Clazz.superConstructor (this, javax.swing.JMenu.WinListener, []);
484 }, "javax.swing.JPopupMenu");
485 Clazz.overrideMethod (c$, "windowClosing",
487 this.b$["javax.swing.JMenu"].setSelected (false);
488 }, "java.awt.event.WindowEvent");
491 c$.$JMenu$1$ = function () {
493 c$ = Clazz.declareAnonymous (javax.swing, "JMenu$1", javax.swing.JMenuItem);
494 Clazz.defineMethod (c$, "createActionPropertyChangeListener",
496 var pcl = this.b$["javax.swing.JMenu"].createActionChangeListener (this);
498 pcl = Clazz.superCall (this, javax.swing.JMenu$1, "createActionPropertyChangeListener", [a]);
500 }, "javax.swing.Action");
503 Clazz.defineStatics (c$,
504 "$$uiClassID", "MenuUI");