6208e0f55ef69da4ab4806a73ac872fc6742e8ef
[jalviewjs.git] / site / j2s / javax / swing / JMenu.js
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;
6 this.menuEvent = null;
7 this.delay = 0;
8 this.customMenuLocation = null;
9 this.popupListener = null;
10 if (!Clazz.isClassDefined ("javax.swing.JMenu.MenuChangeListener")) {
11 javax.swing.JMenu.$JMenu$MenuChangeListener$ ();
12 }
13 if (!Clazz.isClassDefined ("javax.swing.JMenu.WinListener")) {
14 javax.swing.JMenu.$JMenu$WinListener$ ();
15 }
16 Clazz.instantialize (this, arguments);
17 }, javax.swing, "JMenu", javax.swing.JMenuItem, javax.swing.MenuElement);
18 Clazz.makeConstructor (c$, 
19 function () {
20 Clazz.superConstructor (this, javax.swing.JMenu, []);
21 this.init0 ("", null, -2147483648);
22 });
23 Clazz.makeConstructor (c$, 
24 function (s) {
25 Clazz.superConstructor (this, javax.swing.JMenu, []);
26 this.init0 (s, null, -2147483648);
27 }, "~S");
28 Clazz.makeConstructor (c$, 
29 function (a) {
30 Clazz.superConstructor (this, javax.swing.JMenu, []);
31 this.init0 ("", null, -2147483648);
32 this.setAction (a);
33 }, "javax.swing.Action");
34 Clazz.makeConstructor (c$, 
35 function (s, b) {
36 Clazz.superConstructor (this, javax.swing.JMenu, []);
37 this.init0 (s, null, -2147483648);
38 }, "~S,~B");
39 Clazz.overrideMethod (c$, "initFocusability", 
40 function () {
41 });
42 Clazz.overrideMethod (c$, "updateUI", 
43 function () {
44 this.setUI (javax.swing.UIManager.getUI (this));
45 if (this.$popupMenu != null) {
46 this.$popupMenu.setUI (javax.swing.UIManager.getUI (this.$popupMenu));
47 }});
48 Clazz.overrideMethod (c$, "getUIClassID", 
49 function () {
50 return "MenuUI";
51 });
52 Clazz.defineMethod (c$, "setModel", 
53 function (newModel) {
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", 
65 function () {
66 return this.getModel ().isSelected ();
67 });
68 Clazz.overrideMethod (c$, "setSelected", 
69 function (b) {
70 var model = this.getModel ();
71 if (b != model.isSelected ()) {
72 this.getModel ().setSelected (b);
73 }}, "~B");
74 Clazz.defineMethod (c$, "isPopupMenuVisible", 
75 function () {
76 this.ensurePopupMenuCreated ();
77 return this.$popupMenu.isVisible ();
78 });
79 Clazz.defineMethod (c$, "setPopupMenuVisible", 
80 function (b) {
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 ();
86 if (p == null) {
87 p = this.getPopupMenuOrigin ();
88 }this.getPopupMenu ().show (this, p.x, p.y);
89 } else {
90 this.getPopupMenu ().setVisible (false);
91 }}}, "~B");
92 Clazz.defineMethod (c$, "getPopupMenuOrigin", 
93 function () {
94 var x = 0;
95 var y = 0;
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 ());
105 if (gc != null) {
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;
120 }} else {
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;
124 }}y = yOffset;
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;
127 }} else {
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)) {
131 x = xOffset;
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;
134 }} else {
135 x = s.width - xOffset - pmSize.width;
136 if (position.x + x < screenBounds.x && screenBounds.width - s.width > 2 * (position.x - screenBounds.x)) {
137 x = xOffset;
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);
142 });
143 Clazz.defineMethod (c$, "getDelay", 
144 function () {
145 return this.delay;
146 });
147 Clazz.defineMethod (c$, "setDelay", 
148 function (d) {
149 if (d < 0) throw  new IllegalArgumentException ("Delay must be a positive integer");
150 this.delay = d;
151 }, "~N");
152 Clazz.defineMethod (c$, "ensurePopupMenuCreated", 
153  function () {
154 if (this.$popupMenu == null) {
155 this.$popupMenu =  new javax.swing.JPopupMenu ();
156 this.$popupMenu.setInvoker (this);
157 this.popupListener = this.createWinListener (this.$popupMenu);
158 }});
159 Clazz.defineMethod (c$, "getCustomMenuLocation", 
160  function () {
161 return this.customMenuLocation;
162 });
163 Clazz.defineMethod (c$, "setMenuLocation", 
164 function (x, y) {
165 this.customMenuLocation =  new java.awt.Point (x, y);
166 if (this.$popupMenu != null) this.$popupMenu.setLocation (x, y);
167 }, "~N,~N");
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", 
174 function (c) {
175 this.ensurePopupMenuCreated ();
176 this.$popupMenu.add (c);
177 return c;
178 }, "java.awt.Component");
179 Clazz.defineMethod (c$, "add", 
180 function (c, index) {
181 this.ensurePopupMenuCreated ();
182 this.$popupMenu.add (c, index);
183 return c;
184 }, "java.awt.Component,~N");
185 Clazz.defineMethod (c$, "add", 
186 function (s) {
187 return this.add ( new javax.swing.JMenuItem (s));
188 }, "~S");
189 Clazz.defineMethod (c$, "add", 
190 function (a) {
191 var mi = this.createActionComponent (a);
192 mi.setAction (a);
193 this.add (mi);
194 return mi;
195 }, "javax.swing.Action");
196 Clazz.defineMethod (c$, "createActionComponent", 
197 function (a) {
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);
201 return mi;
202 }, "javax.swing.Action");
203 Clazz.defineMethod (c$, "createActionChangeListener", 
204 function (b) {
205 return b.createActionPropertyChangeListener0 (b.getAction ());
206 }, "javax.swing.JMenuItem");
207 Clazz.defineMethod (c$, "addSeparator", 
208 function () {
209 this.ensurePopupMenuCreated ();
210 this.$popupMenu.addSeparator ();
211 });
212 Clazz.defineMethod (c$, "insert", 
213 function (s, pos) {
214 if (pos < 0) {
215 throw  new IllegalArgumentException ("index less than zero.");
216 }this.ensurePopupMenuCreated ();
217 this.$popupMenu.insert ( new javax.swing.JMenuItem (s), pos);
218 }, "~S,~N");
219 Clazz.defineMethod (c$, "insert", 
220 function (mi, pos) {
221 if (pos < 0) {
222 throw  new IllegalArgumentException ("index less than zero.");
223 }this.ensurePopupMenuCreated ();
224 this.$popupMenu.insert (mi, pos);
225 return mi;
226 }, "javax.swing.JMenuItem,~N");
227 Clazz.defineMethod (c$, "insert", 
228 function (a, pos) {
229 if (pos < 0) {
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);
236 return mi;
237 }, "javax.swing.Action,~N");
238 Clazz.defineMethod (c$, "insertSeparator", 
239 function (index) {
240 if (index < 0) {
241 throw  new IllegalArgumentException ("index less than zero.");
242 }this.ensurePopupMenuCreated ();
243 this.$popupMenu.insert ( new javax.swing.JPopupMenu.Separator (), index);
244 }, "~N");
245 Clazz.defineMethod (c$, "getItem", 
246 function (pos) {
247 if (pos < 0) {
248 throw  new IllegalArgumentException ("index less than zero.");
249 }var c = this.getMenuComponent (pos);
250 if (Clazz.instanceOf (c, javax.swing.JMenuItem)) {
251 var mi = c;
252 return mi;
253 }return null;
254 }, "~N");
255 Clazz.defineMethod (c$, "getItemCount", 
256 function () {
257 return this.getMenuComponentCount ();
258 });
259 Clazz.defineMethod (c$, "isTearOff", 
260 function () {
261 throw  new Error ("boolean isTearOff() {} not yet implemented");
262 });
263 Clazz.defineMethod (c$, "remove", 
264 function (pos) {
265 if (pos < 0) {
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);
270 }, "~N");
271 Clazz.defineMethod (c$, "remove", 
272 function (c) {
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", 
277 function () {
278 if (this.$popupMenu != null) this.$popupMenu.removeAll ();
279 });
280 Clazz.defineMethod (c$, "getMenuComponentCount", 
281 function () {
282 var componentCount = 0;
283 if (this.$popupMenu != null) componentCount = this.$popupMenu.getComponentCount ();
284 return componentCount;
285 });
286 Clazz.defineMethod (c$, "getMenuComponent", 
287 function (n) {
288 if (this.$popupMenu != null) return this.$popupMenu.getComponent (n);
289 return null;
290 }, "~N");
291 Clazz.defineMethod (c$, "getMenuComponents", 
292 function () {
293 if (this.$popupMenu != null) return this.$popupMenu.getComponents ();
294 return  new Array (0);
295 });
296 Clazz.defineMethod (c$, "isTopLevelMenu", 
297 function () {
298 if (Clazz.instanceOf (this.getParent (), javax.swing.JMenuBar)) return true;
299 return false;
300 });
301 Clazz.defineMethod (c$, "isMenuComponent", 
302 function (c) {
303 if (c === this) return true;
304 if (Clazz.instanceOf (c, javax.swing.JPopupMenu)) {
305 var comp = c;
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)) {
313 var subMenu = comp;
314 if (subMenu.isMenuComponent (c)) return true;
315 }}
316 return false;
317 }, "java.awt.Component");
318 Clazz.defineMethod (c$, "getPopupMenu", 
319 function () {
320 this.ensurePopupMenuCreated ();
321 return this.$popupMenu;
322 });
323 Clazz.defineMethod (c$, "addMenuListener", 
324 function (l) {
325 this.listenerList.add (javax.swing.event.MenuListener, l);
326 }, "javax.swing.event.MenuListener");
327 Clazz.defineMethod (c$, "removeMenuListener", 
328 function (l) {
329 this.listenerList.remove (javax.swing.event.MenuListener, l);
330 }, "javax.swing.event.MenuListener");
331 Clazz.defineMethod (c$, "getMenuListeners", 
332 function () {
333 return this.listenerList.getListeners (javax.swing.event.MenuListener);
334 });
335 Clazz.defineMethod (c$, "fireMenuSelected", 
336 function () {
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);
342 } else {
343 if (this.menuEvent == null) this.menuEvent =  new javax.swing.event.MenuEvent (this);
344 (listeners[i + 1]).menuSelected (this.menuEvent);
345 }}}
346 });
347 Clazz.defineMethod (c$, "fireMenuDeselected", 
348 function () {
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);
354 } else {
355 if (this.menuEvent == null) this.menuEvent =  new javax.swing.event.MenuEvent (this);
356 (listeners[i + 1]).menuDeselected (this.menuEvent);
357 }}}
358 });
359 Clazz.defineMethod (c$, "fireMenuCanceled", 
360 function () {
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);
366 } else {
367 if (this.menuEvent == null) this.menuEvent =  new javax.swing.event.MenuEvent (this);
368 (listeners[i + 1]).menuCanceled (this.menuEvent);
369 }}}
370 });
371 Clazz.overrideMethod (c$, "configureAcceleratorFromAction", 
372 function (a) {
373 }, "javax.swing.Action");
374 Clazz.defineMethod (c$, "createMenuChangeListener", 
375  function () {
376 return Clazz.innerTypeInstance (javax.swing.JMenu.MenuChangeListener, this, null);
377 });
378 Clazz.defineMethod (c$, "createWinListener", 
379 function (p) {
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);
385 }, "~B");
386 Clazz.overrideMethod (c$, "getSubElements", 
387 function () {
388 if (this.$popupMenu == null) return  new Array (0);
389  else {
390 var result =  new Array (1);
391 result[0] = this.$popupMenu;
392 return result;
393 }});
394 Clazz.defineMethod (c$, "getComponent", 
395 function () {
396 return this;
397 });
398 Clazz.defineMethod (c$, "applyComponentOrientation", 
399 function (o) {
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);
405 }
406 this.$popupMenu.setComponentOrientation (o);
407 }}, "java.awt.ComponentOrientation");
408 Clazz.defineMethod (c$, "setComponentOrientation", 
409 function (o) {
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", 
419 function (evt) {
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);
428 }, "~N");
429 Clazz.defineMethod (c$, "buildMenuElementArray", 
430  function (leaf) {
431 var elements =  new java.util.Vector ();
432 var current = leaf.getPopupMenu ();
433 var pop;
434 var menu;
435 var bar;
436 while (true) {
437 if (Clazz.instanceOf (current, javax.swing.JPopupMenu)) {
438 pop = current;
439 elements.insertElementAt (pop, 0);
440 current = pop.getInvoker ();
441 } else if (Clazz.instanceOf (current, javax.swing.JMenu)) {
442 menu = current;
443 elements.insertElementAt (menu, 0);
444 current = menu.getParent ();
445 } else if (Clazz.instanceOf (current, javax.swing.JMenuBar)) {
446 bar = current;
447 elements.insertElementAt (bar, 0);
448 var me =  new Array (elements.size ());
449 elements.copyInto (me);
450 return me;
451 }}
452 }, "javax.swing.JMenu");
453 c$.$JMenu$MenuChangeListener$ = function () {
454 Clazz.pu$h(self.c$);
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", 
461 function (a) {
462 var b = a.getSource ();
463 var c = b.isSelected ();
464 if (c != this.isSelected) {
465 if (c == true) {
466 this.b$["javax.swing.JMenu"].fireMenuSelected ();
467 } else {
468 this.b$["javax.swing.JMenu"].fireMenuDeselected ();
469 }this.isSelected = c;
470 }}, "javax.swing.event.ChangeEvent");
471 c$ = Clazz.p0p ();
472 };
473 c$.$JMenu$WinListener$ = function () {
474 Clazz.pu$h(self.c$);
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$, 
481 function (a) {
482 Clazz.superConstructor (this, javax.swing.JMenu.WinListener, []);
483 this.popupMenu = a;
484 }, "javax.swing.JPopupMenu");
485 Clazz.overrideMethod (c$, "windowClosing", 
486 function (a) {
487 this.b$["javax.swing.JMenu"].setSelected (false);
488 }, "java.awt.event.WindowEvent");
489 c$ = Clazz.p0p ();
490 };
491 c$.$JMenu$1$ = function () {
492 Clazz.pu$h(self.c$);
493 c$ = Clazz.declareAnonymous (javax.swing, "JMenu$1", javax.swing.JMenuItem);
494 Clazz.defineMethod (c$, "createActionPropertyChangeListener", 
495 function (a) {
496 var pcl = this.b$["javax.swing.JMenu"].createActionChangeListener (this);
497 if (pcl == null) {
498 pcl = Clazz.superCall (this, javax.swing.JMenu$1, "createActionPropertyChangeListener", [a]);
499 }return pcl;
500 }, "javax.swing.Action");
501 c$ = Clazz.p0p ();
502 };
503 Clazz.defineStatics (c$,
504 "$$uiClassID", "MenuUI");
505 });