Home
Categories
Dictionary
Download
Project Details
Changes Log
Tutorials
FAQ
License

Bookmarked menus



Bookmarked menus are another (simpler) way to define static menus. Bookmarked menus are created by MDIMenuFactory.bookmarkMenu(String, JMenu).

Plugins will be able to add an element under this menu by MDIMenuFactory.addToBookmarkedMenu(String, JComponent) or MDIMenuFactory.addToBookmarkedMenu(String, AbstractAction)

Usage of bookmarks in Plugins

You can bookmark a menu by calling the MDIMenuFactory.bookmarkMenu(String, JMenu) method.

You can get the menu factory through the GUIApplication. For example:
      public void register(MDIApplication app) throws Exception {
         super.register(app);
         MDIMenuFactory factory = ((GUIApplication)app).getMenuFactory();
         JMenu pluginMenu = new JMenu("My Menu");
         factory.bookmarkMenu("mymenu", pluginMenu);
      }   
You can add items to this menu by calling: Note that an AbstractMDIAction is an AbstractAction so you can easily add these kind of actions using the first method.

Taking care of the Plugins initialization ordering

Main Article: Plugins dependencies

If a Plugin use a bookmark which was created by another Plugin, you must declare your Plugin as depending on the Plugin for which you use the bookmark. It will ensure that the menu which correspond to the bookmark has been created.

Example

In this example we define an "Analyze" menu in the menu factory:
      protected void initMenus() {
        JMenubar mbar = getMenuBar();

        JMenu menu = new JMenu("Analyze");
        mbar.add(analyze);
        bookmarkMenu("analyze", menu);
      }
And we have an ImagePlugin which has an action allowing to analyse an image:
      public class ImagePlugin extends AbstractSwingMDIPlugin {
        private AbstractAction analyzeImageAction = ...

        public void register(MDIApplication app) throws Exception {
          super.register(app);
          MDIMenuFactory factory = ((GUIApplication)app).getMenuFactory();
          factory.addToBookmarkedMenu("Analyze", analyzeImageAction);
        }
      }
The action will be added to the "Analyze" menu.

See also


Categories: gui | swing

Copyright 2006-2023 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences