org.ananas.mac.menu
Interface ApplicationItem


public interface ApplicationItem

A system-independent interface for "application-smart" menu items.

An "application-smart" menu item is a menu item that will appear in in the application menu under MacOS. It will be managed as a regular menu under other OS.

The following code sample creates a "Quit" menu, registers it on the file menu and adds an action listener:


 ApplicationItem about = ApplicationItemFactory.createQuitItem();
 quit.register("Exit",fileMenu);
 quit.addActionListener(new ActionListener()
 {
    public void actionPerformed(ActionEvent e)
    {
       doQuit();
    }
 });

Important you have to register with a menu, even on MacOS. The library automatically decides if the item should be added to a regular menu or to the application menu. Your code remains platform independent

The register() method is heavily overloaded to support AWT and Swing.

Version:
1.0
Author:
Benoît Marchal
See Also:
ApplicationItemFactory

Method Summary
 void addActionListener(java.awt.event.ActionListener listener)
          Adds the specified action listener to receive action events from this menu item.
 boolean isAddedToMenu()
          Returns true if the menu item will or has been added to application menu.
 void register(javax.swing.Icon icon, javax.swing.JMenu menu)
          Registers the "application" menu item.
 void register(javax.swing.Icon icon, javax.swing.KeyStroke accelerator, javax.swing.JMenu menu)
          Registers the "application" menu item.
 void register(java.lang.String label, javax.swing.Icon icon, javax.swing.JMenu menu)
          Registers the "application" menu item.
 void register(java.lang.String label, javax.swing.Icon icon, javax.swing.KeyStroke accelerator, javax.swing.JMenu menu)
          Registers the "application" menu item.
 void register(java.lang.String label, int mnemonic, javax.swing.JMenu menu)
          Registers the "application" menu item.
 void register(java.lang.String label, int mnemonic, javax.swing.KeyStroke accelerator, javax.swing.JMenu menu)
          Registers the "application" menu item.
 void register(java.lang.String label, javax.swing.JMenu menu)
          Registers the "application" menu item.
 void register(java.lang.String label, javax.swing.KeyStroke accelerator, javax.swing.JMenu menu)
          Registers the "application" menu item.
 void register(java.lang.String label, java.awt.Menu menu)
          Registers the "application" menu item.
 void register(java.lang.String label, java.awt.MenuShortcut shortcut, java.awt.Menu menu)
          Registers the "application" menu item.
 void removeActionListener(java.awt.event.ActionListener listener)
          Removes the specified action listener so it no longer receives action events from this menu item.
 

Method Detail

register

public void register(java.lang.String label,
                     java.awt.Menu menu)
              throws java.lang.IllegalStateException
Registers the "application" menu item. On MacOS, this method ignores its parameters and registers the menu in the application menu. On other OSes, it creates a regular menu item in the menu.
Parameters:
label - item label
menu - menu to add the item to
Throws:
java.lang.IllegalStateException - if calling register() twice or more

register

public void register(java.lang.String label,
                     java.awt.MenuShortcut shortcut,
                     java.awt.Menu menu)
              throws java.lang.IllegalStateException
Registers the "application" menu item. On MacOS, this method ignores its parameters and registers the menu in the application menu. On other OSes, it creates a regular menu item in the menu.
Parameters:
label - item label
shortcut - menu item shortcut
menu - menu to add the item to
Throws:
java.lang.IllegalStateException - if calling register() twice or more

register

public void register(java.lang.String label,
                     javax.swing.JMenu menu)
              throws java.lang.IllegalStateException
Registers the "application" menu item. On MacOS, this method ignores its parameters and registers the menu in the application menu. On other OSes, it creates a regular menu item in the menu.
Parameters:
label - item label
menu - menu to add the item to
Throws:
java.lang.IllegalStateException - if calling register() twice or more

register

public void register(javax.swing.Icon icon,
                     javax.swing.JMenu menu)
              throws java.lang.IllegalStateException
Registers the "application" menu item. On MacOS, this method ignores its parameters and registers the menu in the application menu. On other OSes, it creates a regular menu item in the menu.
Parameters:
icon - item icon
menu - menu to add the item to
Throws:
java.lang.IllegalStateException - if calling register() twice or more

register

public void register(java.lang.String label,
                     javax.swing.Icon icon,
                     javax.swing.JMenu menu)
              throws java.lang.IllegalStateException
Registers the "application" menu item. On MacOS, this method ignores its parameters and registers the menu in the application menu. On other OSes, it creates a regular menu item in the menu.
Parameters:
label - item label
icon - item icon
menu - menu to add the item to
Throws:
java.lang.IllegalStateException - if calling register() twice or more

register

public void register(java.lang.String label,
                     int mnemonic,
                     javax.swing.JMenu menu)
              throws java.lang.IllegalStateException
Registers the "application" menu item. On MacOS, this method ignores its parameters and registers the menu in the application menu. On other OSes, it creates a regular menu item in the menu.
Parameters:
label - item label
mnemonic - menu item mnemonic (underlined letter)
menu - menu to add the item to
Throws:
java.lang.IllegalStateException - if calling register() twice or more

register

public void register(java.lang.String label,
                     javax.swing.KeyStroke accelerator,
                     javax.swing.JMenu menu)
              throws java.lang.IllegalStateException
Registers the "application" menu item. On MacOS, this method ignores its parameters and registers the menu in the application menu. On other OSes, it creates a regular menu item in the menu.
Parameters:
label - item label
accelerator - accelerator (shortcut) for the menu
menu - menu to add the item to
Throws:
java.lang.IllegalStateException - if calling register() twice or more

register

public void register(javax.swing.Icon icon,
                     javax.swing.KeyStroke accelerator,
                     javax.swing.JMenu menu)
              throws java.lang.IllegalStateException
Registers the "application" menu item. On MacOS, this method ignores its parameters and registers the menu in the application menu. On other OSes, it creates a regular menu item in the menu.
Parameters:
icon - item icon
accelerator - accelerator (shortcut) for the menu
menu - menu to add the item to
Throws:
java.lang.IllegalStateException - if calling register() twice or more

register

public void register(java.lang.String label,
                     javax.swing.Icon icon,
                     javax.swing.KeyStroke accelerator,
                     javax.swing.JMenu menu)
              throws java.lang.IllegalStateException
Registers the "application" menu item. On MacOS, this method ignores its parameters and registers the menu in the application menu. On other OSes, it creates a regular menu item in the menu.
Parameters:
label - item label
icon - item icon
accelerator - accelerator (shortcut) for the menu
menu - menu to add the item to
Throws:
java.lang.IllegalStateException - if calling register() twice or more

register

public void register(java.lang.String label,
                     int mnemonic,
                     javax.swing.KeyStroke accelerator,
                     javax.swing.JMenu menu)
              throws java.lang.IllegalStateException
Registers the "application" menu item. On MacOS, this method ignores its parameters and registers the menu in the application menu. On other OSes, it creates a regular menu item in the menu.
Parameters:
label - item label
mnemonic - menu item mnemonic (underlined letter)
accelerator - accelerator (shortcut) for the menu
menu - menu to add the item to
Throws:
java.lang.IllegalStateException - if calling register() twice or more

addActionListener

public void addActionListener(java.awt.event.ActionListener listener)
                       throws java.lang.IllegalStateException
Adds the specified action listener to receive action events from this menu item. Action events occur when a user selects the menu, regardless if the menu is in the application menu or in the menu bar.
Parameters:
listener - the action listener

removeActionListener

public void removeActionListener(java.awt.event.ActionListener listener)
                          throws java.lang.IllegalStateException
Removes the specified action listener so it no longer receives action events from this menu item.
Parameters:
listener - the action listener

isAddedToMenu

public boolean isAddedToMenu()

Returns true if the menu item will or has been added to application menu. This is useful if you need to change/adapt the menu bar depending on whether the menu is in the application menu.

The following code sample adds a menu separator if the "Quit" menu will go in the menu bar.


if(quit.isAddedToMenu())
    fileMenu.addSeparator();

You can call this method before or after calling register()

Returns:
true if the menu item is added to the regular menu during registration, false if it is added to the application menu