org.browsecode.helpers.menus
Class MenuItemSelectedListenerAction

java.lang.Object
  extended by org.browsecode.helpers.menus.MenuItemSelectedListenerAction

public class MenuItemSelectedListenerAction
extends java.lang.Object

Listens for menu selection events and fires the action when it occurs.
Properly handles enabling/disabling of the action, and propogates them to the MenuItem.

 Between this and MenuBarHelper and hierarchy, the former way of adding a menu item with an icon and an action is drasticly reduced.
 It was formerly this:
 JMenu fontStyle = new JMenu("Font Style");
 JMenuItem menuItem = new JMenuItem(new StyledEditorKit.BoldAction());
 menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
 menuItem.setIcon(IconLoader.getToolbarIcon("text/Bold16.gif"));
 fontStyle.add(menuItem);
 
 It has been reduced to this, in HasMenus.addMenuItems(Menu menu):
 Menu fontStyle = menu.getMenu("Font Style");
 MenuItem boldMenuItem = new fontStyle.getMenuItem("Bold", IconLoader.getToolbarIcon("text/Bold16.gif"), KeyEvent.VK_B);
 new MenuItemSelectedListenerAction(boldMenuItem, new StyledEditorKit.BoldAction());
 
 or, for example, you can do this:
 
 Menu fontColor.getMenuItem = menu.getMenu("Font Color");
 MenuItem menuItem = fontColor.getMenuItem("Black");
 new MenuItemSelectedListenerAction(menuItem, new StyledEditorKit.ForegroundAction("Black", Color.black));
 menuItem.setForegroundColor(Color.black);
 menuItem.setBackgroundColor(Color.white);
 
 or, for examule, do this:
 JTextPane textComponent = new JTextPane();               
 new MenuItemSelectedListenerAction(menu.getMenuItem("Cut"),textComponent.getActionMap().get(DefaultEditorKit.cutAction));
 
 or, in the most compressed form, for example, do this:
 
 new MenuItemSelectedListenerAction(menu.getMenuItem("Menu Item Name"),actionToExecute));
 

 


Nested Class Summary
protected  class MenuItemSelectedListenerAction.MenuItemListener
           
protected  class MenuItemSelectedListenerAction.MyPropertyChangeListener
           
 
Constructor Summary
MenuItemSelectedListenerAction(Menu menu, javax.swing.Action action)
           
MenuItemSelectedListenerAction(Menu menu, javax.swing.Action action, javax.swing.Icon icon)
           
MenuItemSelectedListenerAction(Menu menu, javax.swing.Action action, javax.swing.Icon icon, int acceleratorLetter)
           
MenuItemSelectedListenerAction(Menu menu, javax.swing.Action action, javax.swing.Icon icon, javax.swing.KeyStroke keyStroke)
           
MenuItemSelectedListenerAction(Menu menu, javax.swing.Action action, java.lang.String title, javax.swing.Icon icon, int acceleratorLetter)
           
MenuItemSelectedListenerAction(Menu menu, javax.swing.Action action, java.lang.String title, javax.swing.Icon icon, javax.swing.KeyStroke keyStroke)
           
MenuItemSelectedListenerAction(MenuItem menuItem, javax.swing.Action action)
           
 
Method Summary
 MenuItem getMenuItem()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MenuItemSelectedListenerAction

public MenuItemSelectedListenerAction(Menu menu,
                                      javax.swing.Action action)

MenuItemSelectedListenerAction

public MenuItemSelectedListenerAction(Menu menu,
                                      javax.swing.Action action,
                                      javax.swing.Icon icon)

MenuItemSelectedListenerAction

public MenuItemSelectedListenerAction(Menu menu,
                                      javax.swing.Action action,
                                      javax.swing.Icon icon,
                                      int acceleratorLetter)
Parameters:
accellerator - the key to execute this menu item on -- this should be taken from KeyEvent, anything that starts with VK_, for example: KeyEvent_VK_A;

MenuItemSelectedListenerAction

public MenuItemSelectedListenerAction(Menu menu,
                                      javax.swing.Action action,
                                      java.lang.String title,
                                      javax.swing.Icon icon,
                                      int acceleratorLetter)

MenuItemSelectedListenerAction

public MenuItemSelectedListenerAction(Menu menu,
                                      javax.swing.Action action,
                                      javax.swing.Icon icon,
                                      javax.swing.KeyStroke keyStroke)

MenuItemSelectedListenerAction

public MenuItemSelectedListenerAction(Menu menu,
                                      javax.swing.Action action,
                                      java.lang.String title,
                                      javax.swing.Icon icon,
                                      javax.swing.KeyStroke keyStroke)

MenuItemSelectedListenerAction

public MenuItemSelectedListenerAction(MenuItem menuItem,
                                      javax.swing.Action action)
Method Detail

getMenuItem

public MenuItem getMenuItem()