KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > awt > MenuBar


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.openide.awt;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.EventQueue JavaDoc;
24 import java.awt.event.KeyEvent JavaDoc;
25 import java.io.Externalizable JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.io.ObjectInput JavaDoc;
28 import java.io.ObjectOutput JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Arrays JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.LinkedList JavaDoc;
33 import javax.swing.Action JavaDoc;
34 import javax.swing.BorderFactory JavaDoc;
35 import javax.swing.ImageIcon JavaDoc;
36 import javax.swing.JButton JavaDoc;
37 import javax.swing.JMenu JavaDoc;
38 import javax.swing.JMenuBar JavaDoc;
39 import javax.swing.JMenuItem JavaDoc;
40 import javax.swing.JSeparator JavaDoc;
41 import javax.swing.KeyStroke JavaDoc;
42 import javax.swing.UIManager JavaDoc;
43 import javax.swing.event.ChangeEvent JavaDoc;
44 import javax.swing.event.ChangeListener JavaDoc;
45 import org.openide.cookies.InstanceCookie;
46 import org.openide.filesystems.FileObject;
47 import org.openide.filesystems.Repository;
48 import org.openide.loaders.DataFolder;
49 import org.openide.loaders.DataObject;
50 import org.openide.loaders.FolderInstance;
51 import org.openide.loaders.InstanceSupport;
52 import org.openide.nodes.Node;
53 import org.openide.nodes.NodeEvent;
54 import org.openide.nodes.NodeListener;
55 import org.openide.nodes.NodeMemberEvent;
56 import org.openide.nodes.NodeReorderEvent;
57 import org.openide.util.Exceptions;
58 import org.openide.util.NbBundle;
59 import org.openide.util.Task;
60 import org.openide.util.Utilities;
61 import org.openide.util.actions.Presenter;
62
63 /** An extended version of swing's JMenuBar. This menubar can
64  * load its content from the folder where its "disk image" is stored.<P>
65  * Moreover, menu is <code>Externalizable</code> to restore its persistent
66  * state with minimal storage expensiveness.
67  *
68  * The MenuBar recognizes following objects in the folder: <UL>
69  * <LI>subfolders - they're turned into top-level JMenu instances
70  * <LI>instances of <CODE>Component</CODE> - they're added directly
71  * to the menubar.
72  * <LI>instances of <CODE>Presenter.Toolbar</CODE> - their toolbar presenter
73  * is added to the menubar.
74  * </UL>
75  * before OpenAPI version 3.2, only subfolders were recognized.
76  *
77  * <P>In subfolders the following objects are recognized and added to submenus:<UL>
78  * <LI>nested subfolders - they're turned into submenus
79  * <LI>instances of <CODE>Presenter.Menu</CODE>
80  * <LI>instances of <CODE>JMenuItem</CODE>
81  * <LI>instances of <CODE>JSeparator</CODE>
82  * <LI>instances of <CODE>Action</CODE>
83  * <LI>executable <CODE>DataObject</CODE>s
84  * </UL>
85  *
86  * @author David Peroutka, Dafe Simonek, Petr Nejedly
87  */

88 public class MenuBar extends JMenuBar JavaDoc implements Externalizable JavaDoc {
89
90     /** the folder which represents and loads content of the menubar */
91     private MenuBarFolder menuBarFolder;
92
93     /*
94     private static final Icon BLANK_ICON = new ImageIcon(
95         Utilities.loadImage("org/openide/loaders/empty.gif")); // NOI18N
96      */

97
98     static final long serialVersionUID =-4721949937356581268L;
99
100     /** Don't call this constructor or this class will not get
101      * initialized properly. This constructor is only for externalization.
102      */

103     public MenuBar() {
104         super();
105     }
106
107     /** Creates a new <code>MenuBar</code> from given folder.
108      * @param folder The folder from which to create the content of the menubar.
109      * If the parameter is null, default menu folder is obtained.
110      */

111     public MenuBar(DataFolder folder) {
112         this();
113         boolean GTK = "GTK".equals(UIManager.getLookAndFeel().getID());
114         if (!GTK) { //Let GTK supply some border, or mnemonic underlines
115
//will be flush and look ugly
116
setBorder (BorderFactory.createEmptyBorder());
117         }
118         DataFolder theFolder = folder;
119         if (theFolder == null) {
120             FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource("Menu");
121             if (fo == null) throw new IllegalStateException JavaDoc("No Menu/"); // NOI18N
122
theFolder = DataFolder.findFolder(fo);
123         }
124         startLoading(theFolder);
125
126         if(folder != null) {
127             getAccessibleContext().setAccessibleDescription(folder.getName());
128         }
129     }
130     
131     public void addImpl (Component JavaDoc c, Object JavaDoc constraint, int idx) {
132         //Issue 17559, Apple's screen menu bar implementation blindly casts
133
//added components as instances of JMenu. Silently ignore any non-menu
134
//items on Mac if the screen menu flag is true.
135
if (Utilities.isMac() &&
136                 Boolean.getBoolean ("apple.laf.useScreenMenuBar")) { //NOI18N
137
if (!(c instanceof JMenu JavaDoc)) {
138                 return;
139             }
140         }
141         super.addImpl (c, constraint, idx);
142     }
143     
144     /**
145      * Overridden to handle mac conversion from Alt to Ctrl and vice versa so
146      * Alt can be used as the compose character on international keyboards.
147      */

148     protected boolean processKeyBinding(KeyStroke JavaDoc ks,
149                                     KeyEvent JavaDoc e,
150                                     int condition,
151                                     boolean pressed) {
152         if (Utilities.isMac()) {
153             int mods = e.getModifiers();
154             boolean isCtrl = (mods & KeyEvent.CTRL_MASK) != 0;
155             boolean isAlt = (mods & KeyEvent.ALT_MASK) != 0;
156             if (isAlt) {
157                 return false;
158             }
159             if (isAlt && !isCtrl) {
160                 mods = mods & ~ KeyEvent.ALT_MASK;
161                 mods = mods & ~ KeyEvent.ALT_DOWN_MASK;
162                 mods |= KeyEvent.CTRL_MASK;
163                 mods |= KeyEvent.CTRL_DOWN_MASK;
164             } else if (!isAlt && isCtrl) {
165                 mods = mods & ~ KeyEvent.CTRL_MASK;
166                 mods = mods & ~ KeyEvent.CTRL_DOWN_MASK;
167                 mods |= KeyEvent.ALT_MASK;
168                 mods |= KeyEvent.ALT_DOWN_MASK;
169             } else if (!isAlt && !isCtrl) {
170                 return super.processKeyBinding (ks, e, condition, pressed);
171             }
172             
173             KeyEvent JavaDoc newEvent = new MarkedKeyEvent ((Component JavaDoc) e.getSource(), e.getID(),
174                 e.getWhen(), mods, e.getKeyCode(), e.getKeyChar(),
175                 e.getKeyLocation());
176             
177             KeyStroke JavaDoc newStroke = e.getID() == KeyEvent.KEY_TYPED ?
178                 KeyStroke.getKeyStroke (ks.getKeyChar(), mods) :
179                 KeyStroke.getKeyStroke (ks.getKeyCode(), mods,
180                 !ks.isOnKeyRelease());
181             
182             boolean result = super.processKeyBinding (newStroke, newEvent,
183                 condition, pressed);
184             
185             if (newEvent.isConsumed()) {
186                 e.consume();
187             }
188             return result;
189         } else {
190             return super.processKeyBinding (ks, e, condition, pressed);
191         }
192     }
193
194     /** Blocks until the menubar is completely created. */
195     public void waitFinished () {
196         menuBarFolder.instanceFinished();
197     }
198     
199     /** Saves the contents of this object to the specified stream.
200      *
201      * @exception IOException Includes any I/O exceptions that may occur
202      */

203     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc {
204         out.writeObject(menuBarFolder.getFolder());
205     }
206
207     /**
208      * Restores contents of this object from the specified stream.
209      *
210      * @exception ClassNotFoundException If the class for an object being
211      * restored cannot be found.
212      */

213     public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
214         startLoading((DataFolder)in.readObject());
215     }
216     
217     /** Starts loading of this menu from menu folder */
218     void startLoading (final DataFolder folder) {
219         menuBarFolder = new MenuBarFolder(folder);
220     }
221     
222     /** Convert an array of instance cookies to instances, adds them
223      * to given list.
224      * @param arr array of instance cookies
225      * @param list list to add created objects to
226      */

227     static void allInstances (InstanceCookie[] arr, java.util.List JavaDoc<Object JavaDoc> list) {
228         Exception JavaDoc ex = null;
229         
230         for (int i = 0; i < arr.length; i++) {
231             
232             Exception JavaDoc newEx = null;
233             try {
234                 Object JavaDoc o = arr[i].instanceCreate();
235                 list.add (o);
236             } catch (ClassNotFoundException JavaDoc e) {
237                 newEx = e;
238             } catch (IOException JavaDoc e) {
239                 newEx = e;
240             }
241             
242             if (newEx != null) {
243                 Throwable JavaDoc t = newEx;
244                 while (true) {
245                     if (t.getCause() == null) {
246                         t.initCause(ex);
247                         break;
248                     }
249                     t = t.getCause();
250                 }
251                 ex = newEx;
252             }
253         }
254      
255         // if there was an exception => notify it
256
if (ex != null) {
257             Exceptions.printStackTrace(ex);
258         }
259     }
260
261     /** This class can be used to fill the content of given
262      * <code>MenuBar</code> from the given <code>DataFolder</code>.
263      */

264     private final class MenuBarFolder extends FolderInstance {
265         /** List of the components this FolderInstance manages. */
266         private ArrayList JavaDoc<Component JavaDoc> managed = new ArrayList JavaDoc<Component JavaDoc>();
267
268         /** Creates a new menubar folder on the specified <code>DataFolder</code>.
269          * @param folder a <code>DataFolder</code> to work with
270          */

271         public MenuBarFolder (final DataFolder folder) {
272             super(folder);
273             recreate ();
274         }
275
276         /** Removes the components added by this FolderInstance from the MenuBar.
277          * Called when menu is refreshed. */

278         private void cleanUp() {
279             for (Iterator JavaDoc<Component JavaDoc> it = managed.iterator(); it.hasNext(); ) {
280                 MenuBar.this.remove(it.next());
281             }
282             managed.clear();
283         }
284
285         /** Adds the component to the MenuBar after the last added one */
286         private void addComponent (Component JavaDoc c) {
287             MenuBar.this.add(c, managed.size());
288             managed.add(c);
289         }
290
291         /** Full name of the data folder's primary file separated by dots.
292          * @return the name
293          */

294         public String JavaDoc instanceName () {
295             return MenuBar.class.getName();
296         }
297
298         /** Returns the root class of all objects.
299          * @return MenuBar.class
300          */

301         public Class JavaDoc instanceClass () {
302             return MenuBar.class;
303         }
304
305         /** Accepts only cookies that can provide a <code>Component</code>
306          * or a <code>Presenter.Toolbar</code>.
307          * @param cookie the instance cookie to test
308          * @return true if the cookie is accepted.
309          */

310         protected InstanceCookie acceptCookie(InstanceCookie cookie)
311                 throws IOException JavaDoc, ClassNotFoundException JavaDoc {
312             Class JavaDoc cls = cookie.instanceClass();
313             boolean is =
314                     Component JavaDoc.class.isAssignableFrom(cls) ||
315                     Presenter.Toolbar.class.isAssignableFrom(cls) ||
316                     Action JavaDoc.class.isAssignableFrom(cls);
317             return is ? cookie : null;
318         }
319
320         /** Returns an <code>InstanceCookie</code> of a JMenu
321      * for the specified <code>DataFolder</code>.
322      *
323          * @param df a <code>DataFolder</code> to create the cookie for
324          * @return an <code>InstanceCookie</code> for the specified folder
325          */

326         protected InstanceCookie acceptFolder (DataFolder df) {
327             return new LazyMenu(df, false).slave;
328         }
329
330         /** Updates the <code>MenuBar</code> represented by this folder.
331          *
332          * @param cookies array of instance cookies for the folder
333          * @return the updated <code>MenuBar</code> representee
334          */

335         protected Object JavaDoc createInstance(InstanceCookie[] cookies)
336                 throws IOException JavaDoc, ClassNotFoundException JavaDoc {
337             final LinkedList JavaDoc<Object JavaDoc> ll = new LinkedList JavaDoc<Object JavaDoc>();
338             allInstances(cookies, ll);
339
340             final MenuBar mb = MenuBar.this;
341             
342             if (ll.equals(Arrays.asList(mb.getComponents()))) {
343                 return mb;
344             }
345             
346             cleanUp(); //remove the stuff we've added last time
347
// fill with new content
348
for (Object JavaDoc o: ll) {
349                 Component JavaDoc component = convertToComponent(o);
350                 if (component != null) {
351                     addComponent(component);
352                 }
353             }
354             mb.validate();
355             mb.repaint();
356             return mb;
357         }
358
359         private Component JavaDoc convertToComponent(final Object JavaDoc obj) {
360             Component JavaDoc retVal = null;
361             if (obj instanceof Component JavaDoc) {
362                 retVal = (Component JavaDoc)obj;
363             } else {
364                 if (obj instanceof Presenter.Toolbar) {
365                     retVal = ((Presenter.Toolbar)obj).getToolbarPresenter();
366                 } else if (obj instanceof Action JavaDoc) {
367                     Action JavaDoc a = (Action JavaDoc) obj;
368                     JButton JavaDoc button = new JButton JavaDoc();
369                     Actions.connect(button, a);
370                     retVal = button;
371                 }
372             }
373             if (retVal instanceof JButton JavaDoc) { // tune the presenter a bit
374
((JButton JavaDoc)retVal).setBorderPainted(false);
375                 ((JButton JavaDoc)retVal).setMargin(new java.awt.Insets JavaDoc(0, 2, 0, 2));
376             }
377             return retVal;
378         }
379         
380         /** For outer class access to the data folder */
381         DataFolder getFolder () {
382             return folder;
383         }
384
385         /** Recreate the instance in AWT thread. */
386         protected Task postCreationTask (Runnable JavaDoc run) {
387             return new AWTTask (run);
388         }
389
390     }
391     
392     /**
393      * A marker class to allow different processing of remapped key events
394      * on mac - allows them to be recognized by LazyMenu.
395      */

396     private static final class MarkedKeyEvent extends KeyEvent JavaDoc {
397         public MarkedKeyEvent (Component JavaDoc c, int id,
398                     long when, int mods, int code, char kchar,
399                     int loc) {
400             super(c, id, when, mods, code, kchar, loc);
401         }
402     }
403
404     /** Menu based on the folder content whith lazy items creation. */
405     private static class LazyMenu extends JMenu JavaDoc implements NodeListener, Runnable JavaDoc, ChangeListener JavaDoc {
406         DataFolder master;
407         boolean icon;
408         MenuFolder slave;
409         DynaMenuModel dynaModel;
410     
411         /** Constructor. */
412         public LazyMenu(final DataFolder df, boolean icon) {
413             this.master = df;
414             this.icon = icon;
415             this.dynaModel = new DynaMenuModel();
416             this.slave = new MenuFolder();
417
418             // Listen for changes in Node's DisplayName/Icon
419
Node n = master.getNodeDelegate ();
420             n.addNodeListener (org.openide.nodes.NodeOp.weakNodeListener (this, n));
421             updateProps();
422             getModel().addChangeListener(this);
423
424         }
425         
426         protected boolean processKeyBinding(KeyStroke JavaDoc ks,
427                                         KeyEvent JavaDoc e,
428                                         int condition,
429                                         boolean pressed) {
430             if (Utilities.isMac()) {
431                 int mods = e.getModifiers();
432                 boolean isCtrl = (mods & KeyEvent.CTRL_MASK) != 0;
433                 boolean isAlt = (mods & KeyEvent.ALT_MASK) != 0;
434                 if (isAlt && (e instanceof MarkedKeyEvent)) {
435                     mods = mods & ~ KeyEvent.CTRL_MASK;
436                     mods = mods & ~ KeyEvent.CTRL_DOWN_MASK;
437                     mods |= KeyEvent.ALT_MASK;
438                     mods |= KeyEvent.ALT_DOWN_MASK;
439                     
440                     KeyEvent JavaDoc newEvent = new MarkedKeyEvent (
441                         (Component JavaDoc) e.getSource(), e.getID(),
442                         e.getWhen(), mods, e.getKeyCode(), e.getKeyChar(),
443                         e.getKeyLocation());
444                     
445                     KeyStroke JavaDoc newStroke = e.getID() == KeyEvent.KEY_TYPED ?
446                         KeyStroke.getKeyStroke (ks.getKeyChar(), mods) :
447                         KeyStroke.getKeyStroke (ks.getKeyCode(), mods,
448                         !ks.isOnKeyRelease());
449                     
450                     boolean result = super.processKeyBinding (newStroke,
451                         newEvent, condition, pressed);
452                     
453                     if (newEvent.isConsumed()) {
454                         e.consume();
455                     }
456                     return result;
457                 } else if (!isAlt) {
458                     return super.processKeyBinding (ks, e, condition, pressed);
459                 } else {
460                     return false;
461                 }
462             } else {
463                 return super.processKeyBinding (ks, e, condition, pressed);
464             }
465         }
466
467         private void updateProps() {
468             if (master.isValid()) {
469                 // set the text and be aware of mnemonics
470
Node n = master.getNodeDelegate ();
471                 Mnemonics.setLocalizedText(this, n.getDisplayName());
472                 if (icon) setIcon (new ImageIcon JavaDoc (
473                 n.getIcon (java.beans.BeanInfo.ICON_COLOR_16x16)));
474             } else {
475                 setText(master.getName());
476                 setIcon(null);
477             }
478         }
479
480         /** Update the properties. Exported via Runnable interface so it
481          * can be rescheduled. */

482         public void run() {
483             updateProps();
484         }
485
486         /** If the display name changes, than change the name of the menu.*/
487         public void propertyChange (java.beans.PropertyChangeEvent JavaDoc ev) {
488             if (
489                 Node.PROP_DISPLAY_NAME.equals (ev.getPropertyName ()) ||
490                 Node.PROP_NAME.equals (ev.getPropertyName ()) ||
491                 Node.PROP_ICON.equals (ev.getPropertyName ())
492             ) {
493                 // update the properties in AWT queue
494
if (EventQueue.isDispatchThread ()) {
495                     updateProps(); // do the update synchronously
496
} else {
497                     EventQueue.invokeLater (this);
498                 }
499             }
500         }
501
502         // The rest of the NodeListener implementation
503
public void childrenAdded (NodeMemberEvent ev) {}
504         public void childrenRemoved (NodeMemberEvent ev) {}
505         public void childrenReordered(NodeReorderEvent ev) {}
506         public void nodeDestroyed (NodeEvent ev) {}
507             
508         private boolean selected = false;
509         public void stateChanged(ChangeEvent JavaDoc event) {
510             if (selected) {
511                 selected = false;
512             } else {
513                 selected = true;
514                 doInitialize();
515                 dynaModel.checkSubmenu(this);
516
517             }
518         }
519         
520
521 // mkleint: overriding setPopupMenuVisible doesn't work on mac, replaced by listening on changes of Button model.
522

523 //
524
// /** Overriden to provide better strategy for placing the JMenu on the screen.
525
// * @param b a boolean value -- true to make the menu visible, false to hide it
526
// */
527
// public void setPopupMenuVisible(boolean b) {
528
// boolean isVisible = isPopupMenuVisible();
529
//
530
// if (b != isVisible) {
531
// if ((b == true) && isShowing()) {
532
// doInitialize();
533
// dynaModel.checkSubmenu(this);
534
// }
535
// }
536
// super.setPopupMenuVisible(b);
537
// }
538

539     private void doInitialize() {
540         slave.waitFinishedSuper();
541     }
542         
543     /** This class can be used to update a <code>JMenu</code> instance
544      * from the given <code>DataFolder</code>.
545      */

546     private class MenuFolder extends FolderInstance {
547             
548             /**
549              * Start tracking the content of the master folder.
550              * It will cause initial update of the Menu
551              */

552             public MenuFolder () {
553                 super(master);
554             }
555
556
557             /** The name of the menu
558              * @return the name
559              */

560             public String JavaDoc instanceName () {
561                 return LazyMenu.class.getName();
562             }
563
564             /** Returns the class of represented menu.
565              * @return JMenu.class
566              */

567             public Class JavaDoc instanceClass () {
568                 return JMenu JavaDoc.class;
569             }
570             
571             
572             public Object JavaDoc instanceCreate() throws IOException JavaDoc, ClassNotFoundException JavaDoc {
573                 return LazyMenu.this;
574             }
575
576             public void waitFinished() {
577 // super.waitFinished();
578
}
579             
580             void waitFinishedSuper() {
581                 super.waitFinished();
582             }
583             
584
585             /** If no instance cookie, tries to create execution action on the
586              * data object.
587              */

588             protected InstanceCookie acceptDataObject (DataObject dob) {
589                 InstanceCookie ic = super.acceptDataObject(dob);
590                 if (ic == null) {
591                     JMenuItem JavaDoc item = ExecBridge.createMenuItem(dob);
592                     return item != null ? new InstanceSupport.Instance(item) : null;
593                 } else {
594                     return ic;
595                 }
596             }
597
598             /**
599              * Accepts only cookies that can provide <code>Menu</code>.
600              * @param cookie an <code>InstanceCookie</code> to test
601              * @return true if the cookie can provide accepted instances
602              */

603             protected InstanceCookie acceptCookie(InstanceCookie cookie)
604             throws IOException JavaDoc, ClassNotFoundException JavaDoc {
605         // [pnejedly] Don't try to optimize this by InstanceCookie.Of
606
// It will load the classes few ms later from instanceCreate
607
// anyway and more instanceOf calls take longer
608
Class JavaDoc c = cookie.instanceClass();
609                 boolean is =
610                     Presenter.Menu.class.isAssignableFrom (c) ||
611                     JMenuItem JavaDoc.class.isAssignableFrom (c) ||
612                     JSeparator JavaDoc.class.isAssignableFrom (c) ||
613                     Action JavaDoc.class.isAssignableFrom (c);
614                 return is ? cookie : null;
615             }
616
617             /**
618              * Returns a <code>Menu.Folder</code> cookie for the specified
619              * <code>DataFolder</code>.
620              * @param df a <code>DataFolder</code> to create the cookie for
621              * @return a <code>Menu.Folder</code> for the specified folder
622              */

623             protected InstanceCookie acceptFolder(DataFolder df) {
624                 boolean hasIcon = df.getPrimaryFile().getAttribute("SystemFileSystem.icon") != null;
625                 return new LazyMenu(df, hasIcon).slave;
626             }
627
628             /** Updates the <code>JMenu</code> represented by this folder.
629              * @param cookies array of instance cookies for the folder
630              * @return the updated <code>JMenu</code> representee
631              */

632             protected Object JavaDoc createInstance(InstanceCookie[] cookies)
633                     throws IOException JavaDoc, ClassNotFoundException JavaDoc {
634             LazyMenu m = LazyMenu.this;
635
636             //synchronized (this) { // see #15917 - attachment from 2001/09/27
637
LinkedList JavaDoc<Object JavaDoc> cInstances = new LinkedList JavaDoc<Object JavaDoc>();
638             allInstances (cookies, cInstances);
639
640             m.removeAll();
641
642             // #11848, #13013. Enablement should be set immediatelly,
643
// popup will be created on-demand.
644
// m.setEnabled(!cInstances.isEmpty());
645
// TODO: fill it with empty sign instead
646
if(cInstances.isEmpty()) {
647             JMenuItem JavaDoc item = new JMenuItem JavaDoc(
648                             NbBundle.getMessage(DataObject.class, "CTL_EmptyMenu"));
649
650             item.setEnabled(false);
651             m.add(item);
652         }
653
654                 m.dynaModel.loadSubmenu(cInstances, m);
655                 
656             return m;
657             }
658             
659             /** Removes icons from all direct menu items of this menu.
660              * Not recursive, * /
661             private List alignVertically (List menuItems) {
662                 List result = new ArrayList(menuItems.size());
663                 JMenuItem curItem = null;
664                 for (Iterator iter = menuItems.iterator(); iter.hasNext(); ) {
665                     curItem = (JMenuItem)iter.next();
666                     if (curItem != null && curItem.getIcon() == null) {
667                         curItem.setIcon(BLANK_ICON);
668                     }
669                     result.add(curItem);
670                 }
671                 return result;
672             }
673              */

674
675             /** Recreate the instance in AWT thread.
676              */

677             protected Task postCreationTask (Runnable JavaDoc run) {
678                 return new AWTTask (run);
679             }
680     }
681     }
682     
683 }
684
Popular Tags