org.browsecode.helpers.menus
Class MenuBarHelper

java.lang.Object
  extended by org.browsecode.helpers.menus.MenuBarHelper
All Implemented Interfaces:
HasMenus.ActiveListener

public class MenuBarHelper
extends java.lang.Object
implements HasMenus.ActiveListener

Easily create platform-independent menus, where different parts of the application can manage their menus by themselves.

This does 2 major things:
1) Makes the menus cross-platform. Specifically, it handles (a) special locations for menus on Mac OS X (quit, prefs, and about are in the application menu), and on Windows, "Quit" should say "Exit", and on Unix, this makes the quit item say "Quit"
2) This allows you to component-ize your program into different chunks, each that have their own set of menus. MenuBarHelper will merge them all into one menu bar. It also makes sure there are no duplicate menu items. For example, if you use an HTML component, you can do "menuBarHelper.addHasMenus(new HTMLEditingMenus());" and suddenly you have a "Format" menu for editing in HTML components, and several items will be automatically added to "Edit". It works the same way if you use UndoHandler -- it will automatically add undo and redo items to the edit menu. In the future, this will also do some automatic Translation for your menus -- standard menu and item names will automatically be translated into languages besides english (for any languages which locale files are made), and the code will still be refer to them by the english name.


Nested Class Summary
static class MenuBarHelper.MenuItemComparator
           
static class MenuBarHelper.MenuItemComparatorStartsWith
           
 
Field Summary
 
Fields inherited from interface org.browsecode.helpers.menus.HasMenus.ActiveListener
ACTIVE, INACTIVE, INVISIBLE
 
Constructor Summary
MenuBarHelper()
          Application name is optional, but on MacOS X it is strongly recommended for the Application menu's title.
 
Method Summary
 void activeChanged(HasMenus hasMenus, int isNowActive)
          Call this whenever the HasMenus becomes active or inactive.
 void addHasMenus(HasMenus hasMenus)
           
protected  void addMenuInRightPlace(MenuJMenu menu)
           
 void addQuitListener(QuitListener quitListener)
          Add a QuitListener.
 boolean fireQuitEvent()
           
 MenuItem getAboutMenuItem()
          Get the "About ..."
protected  Menu getFileMenu()
           
 Menu getMenu(java.lang.String menuName)
           
 javax.swing.JMenuBar getMenuBar()
           
 java.util.Vector getMenuOrder()
          Get order of Menus, from left to right.
 Translator getTranslator()
           
 boolean removeQuitListener(QuitListener quitListener)
           
 void setMenuOrder(java.util.Vector newMenuOrder)
          Set the order of the Menus, from left to right.
 void setTranslator(Translator translator)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MenuBarHelper

public MenuBarHelper()
Application name is optional, but on MacOS X it is strongly recommended for the Application menu's title.

Parameters:
applicationName -
Method Detail

getMenuOrder

public java.util.Vector getMenuOrder()
Get order of Menus, from left to right. It's a Vector of String.

Returns:

getTranslator

public Translator getTranslator()

setTranslator

public void setTranslator(Translator translator)

setMenuOrder

public void setMenuOrder(java.util.Vector newMenuOrder)
Set the order of the Menus, from left to right. It should be a Vector of String. It should have, somewhere in the list, MenuBarHelper.ALL_OTHER_MENU_ITEMS, to show where any non-mentioned menus should go.

Parameters:
newMenuOrder -

addMenuInRightPlace

protected void addMenuInRightPlace(MenuJMenu menu)

getFileMenu

protected Menu getFileMenu()

getMenuBar

public javax.swing.JMenuBar getMenuBar()

getMenu

public Menu getMenu(java.lang.String menuName)

addHasMenus

public void addHasMenus(HasMenus hasMenus)

getAboutMenuItem

public MenuItem getAboutMenuItem()
Get the "About ..." MenuItem.

Returns:

addQuitListener

public void addQuitListener(QuitListener quitListener)
Add a QuitListener. This will be notificed if the user quits. Also will make sure the quit item exists in the menus. This is global -- anytime "Quit" is selected, all QuitListeners anywhere in the JVM will be notified. This is intentional (the list of QuitListeners is static).

Parameters:
quitListener -

removeQuitListener

public boolean removeQuitListener(QuitListener quitListener)

fireQuitEvent

public boolean fireQuitEvent()
Returns:
whether it successfully closed or not

activeChanged

public void activeChanged(HasMenus hasMenus,
                          int isNowActive)
Description copied from interface: HasMenus.ActiveListener
Call this whenever the HasMenus becomes active or inactive. i.e. if you have tabs, and the tabs ever are hidden (and the menus specific to that disappear), then call this. The default is assumed to be active.

Specified by:
activeChanged in interface HasMenus.ActiveListener
Parameters:
hasMenus - the HasMenus that fired this event
isNowActive - whether or not the HasMenus is currently active