Class MenuManager

java.lang.Object
edu.cnu.mdi.ui.menu.MenuManager

public final class MenuManager extends Object
Singleton registry for the application's menu bar and named menus.
  • Method Details

    • createMenuManager

      public static MenuManager createMenuManager(JMenuBar menubar)
      Public access for the singleton.

      Only the first call actually creates the instance. Once the singleton exists, subsequent calls silently ignore the passed-in menubar and return the original instance, still bound to whichever menu bar was passed the first time.

      Parameters:
      menubar - the main menu bar; only used on the first call
      Returns:
      the menu manager for the one and only BaseMDIApplication.
    • getInstance

      public static MenuManager getInstance()
      This one is used after the menu manager is created. Then you can add menus to the main frame without a reference to it.
      Returns:
      the menu manager for the one and only BaseMDIApplication.
    • addMenu

      public void addMenu(JMenu menu)
      Add a menu to the main menu bar.
      Parameters:
      menu - the menu to add.
    • getMenu

      public JMenu getMenu(String text)
      Get a menu based on its name.
      Parameters:
      text - the name of the menu, e.g., "File".
      Returns:
      the menu, if it finds it.
    • addContribution

      public void addContribution(MenuContribution contribution)
      Add a menu under a stable ID and order it relative to other contributions.

      IDs must be unique within this manager. Registration also populates the legacy text lookup, so old and new consumers can share the same menu. Legacy menus already on the bar are never reordered.

      Parameters:
      contribution - contribution to register
      Throws:
      NullPointerException - if contribution is null
      IllegalArgumentException - if its ID is already registered
    • getMenu

      public JMenu getMenu(MenuId id)
      Gets a contributed menu without depending on its display label.
      Parameters:
      id - stable menu ID
      Returns:
      registered menu, or null
    • getFileMenu

      public JMenu getFileMenu()
      Get the file menu.
      Returns:
      the file menu, if it has been set.
    • removeMenu

      public void removeMenu(JMenu menu)
      Remove an unwanted menu from the menu bar
      Parameters:
      menu - the menu to remove
    • setFileMenu

      public static void setFileMenu(JMenu menu)
      Set the file menu
      Parameters:
      menu - the file menu