Class AbstractMenuAction

java.lang.Object
org.ka2ddo.yaac.pluginapi.AbstractMenuAction
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AbstractPopupMenuAction

public abstract class AbstractMenuAction extends Object implements Serializable
This abstract class functions more or less the same as the javax.swing.AbstractAction class, but is not subclassed from that class, so that it can be used in non-Swing environments (such as Android).
Author:
Andrew Pavlin, KA2DDO
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The key used for storing a KeyStroke to be used as the accelerator for the action.
    static final String
    The key used to determine the command String for the ActionEvent that will be created when an Action is going to be notified as the result of residing in a Keymap associated with a JComponent.
    static final String
    Identifies the ButtonGroup a radio button menu item is associated with.
    static final String
    The key used for storing an Integer that corresponds to the index in the text (identified by the NAME property) that the decoration for a mnemonic should be rendered at.
    protected boolean
    Specifies whether action is enabled; the default is true.
    static final String
    The key used for storing an Icon.
    static final String
    Identifies the hierarchy path for the menu containers of a menu item.
    static final String
    The key used for storing a longer String description for the action, could be used for context-sensitive help.
    static final String
    Identifies the sort priority on the lowest menu container for relative positioning a menu item.
    static final String
    The key used for storing an Integer that corresponds to one of the KeyEvent key codes.
    static final String
    The key used for storing the localized String name for the action, used for a menu or button.
    static final String
    Indicates that this menu action cannot be commanded by voice because it depends on context that can't be provided by speech.
    static final String
    Identifies a specific menu item in the accumulated hierarchy.
    static final String
    Identifies the ResourceBundle tags for the hierarchy path for the menu containers of a menu item.
    protected HashMap<String,Object>
    Stores any properties of the menu action that are not specially handled (such as enabled).
    static final String
    The key used for storing a Boolean that corresponds to the selected state.
    static final String
    The key used for storing a short localized String description for the action, used for tooltip text.
    static final String
    The key used for storing a small Icon, such as ImageIcon.
    static final String
    Indicates that this menu action should only be available for UI views of the specified content type.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Defines an AbstractMenuAction object with the specified description string and a default icon.
    protected
    AbstractMenuAction(String nameTag, String[] menuPositionNames)
    Construct an AbstractMenuAction with the specified ResourceBundle lookup tag for the name, and hierarchical position in the menus.
    protected
    AbstractMenuAction(String nameTag, String[] menuPositionNames, int priority)
    Construct an AbstractMenuAction with the specified ResourceBundle lookup tag for the name, and hierarchical position in the menus.
    protected
    AbstractMenuAction(String nameTag, String[] menuPositionNames, int priority, boolean initialState)
    Construct an AbstractMenuAction with the specified ResourceBundle lookup tag for the name, and hierarchical position in the menus.
    protected
    AbstractMenuAction(String nameTag, String[] menuPositionNames, int priority, String buttonGroupName)
    Construct an AbstractMenuAction with the specified ResourceBundle lookup tag for the name, and hierarchical position in the menus.
    protected
    AbstractMenuAction(String nameTag, String[] menuPositionNames, String buttonGroupName)
    Construct an AbstractMenuAction with the specified ResourceBundle lookup tag for the name, and hierarchical position in the menus.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    Invoked when an action occurs.
    protected void
    firePropertyChange(String propertyName, Object oldValue, Object newValue)
    Supports reporting bound property changes.
    Get the currently associated GUI-specific PropertyListener.
    Gets the Object associated with the specified key.
    boolean
    init(Object item, Object view)
    Additional processing to be done when the action is attached to the menu structure.
    boolean
    Returns the enabled state of the Action.
    static int[]
    Convert a localized string of mnemonic letters into an array of ints, suitable for use by the above constructors.
    void
    putValue(String key, Object newValue)
    Sets one of this object's properties using the associated key.
    void
    setEnabled(boolean newValue)
    Sets the enabled state of the Action.
    void
    Specify who should be informed of changes to properties.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PRE_LOCALIZE_MENU_TAG_NAME

      public static final String PRE_LOCALIZE_MENU_TAG_NAME
      Identifies a specific menu item in the accumulated hierarchy. Must be a String.
      See Also:
    • PRE_LOCALIZED_MENU_HIERARCHY

      public static final String PRE_LOCALIZED_MENU_HIERARCHY
      Identifies the ResourceBundle tags for the hierarchy path for the menu containers of a menu item. Must be an array of Strings containing ResourceBundle keys for localized menu names.
      See Also:
    • LOCALIZED_MENU_HIERARCHY

      public static final String LOCALIZED_MENU_HIERARCHY
      Identifies the hierarchy path for the menu containers of a menu item. Must be an array of Strings that have already been localized.
      See Also:
    • BUTTON_GROUP_NAME

      public static final String BUTTON_GROUP_NAME
      Identifies the ButtonGroup a radio button menu item is associated with. Must be a String.
      See Also:
    • NOT_VOICE_COMMAND

      public static final String NOT_VOICE_COMMAND
      Indicates that this menu action cannot be commanded by voice because it depends on context that can't be provided by speech. Must be a Boolean.
      See Also:
    • UI_TYPE

      public static final String UI_TYPE
      Indicates that this menu action should only be available for UI views of the specified content type. Value must be an EnumSet of GuiContentType enums.
      See Also:
    • NAME

      public static final String NAME
      The key used for storing the localized String name for the action, used for a menu or button.
      See Also:
    • SHORT_DESCRIPTION

      public static final String SHORT_DESCRIPTION
      The key used for storing a short localized String description for the action, used for tooltip text. This class will automatically fill this in if a ResourceBundle entry with the key name of PRE_LOCALIZE_MENU_TAG_NAME appended with ".tooltip" exists.
      See Also:
    • LONG_DESCRIPTION

      public static final String LONG_DESCRIPTION
      The key used for storing a longer String description for the action, could be used for context-sensitive help.
      See Also:
    • SMALL_ICON

      public static final String SMALL_ICON
      The key used for storing a small Icon, such as ImageIcon.
      See Also:
    • ACTION_COMMAND_KEY

      public static final String ACTION_COMMAND_KEY
      The key used to determine the command String for the ActionEvent that will be created when an Action is going to be notified as the result of residing in a Keymap associated with a JComponent.
      See Also:
    • ACCELERATOR_KEY

      public static final String ACCELERATOR_KEY
      The key used for storing a KeyStroke to be used as the accelerator for the action.
      See Also:
    • MNEMONIC_KEY

      public static final String MNEMONIC_KEY
      The key used for storing an Integer that corresponds to one of the KeyEvent key codes. The value is commonly used to specify a mnemonic. For example: myAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_A) sets the mnemonic of myAction to 'a'.
      See Also:
    • SELECTED_KEY

      public static final String SELECTED_KEY
      The key used for storing a Boolean that corresponds to the selected state. This is typically used only for components that have a meaningful selection state. For example, radio button and check box make use of this but instances of JMenu don't.

      This property differs from the others in that it is both read by the component and set by the component. For example, if an Action is attached to a check box the selected state of the check box will be set from that of the Action. If the user clicks on the check box the selected state of the check box and the Action will both be updated.

      Note: the value of this field is prefixed with 'Swing' to avoid possible collisions with existing Actions.

      Since:
      1.6
      See Also:
    • DISPLAYED_MNEMONIC_INDEX_KEY

      public static final String DISPLAYED_MNEMONIC_INDEX_KEY
      The key used for storing an Integer that corresponds to the index in the text (identified by the NAME property) that the decoration for a mnemonic should be rendered at. If the value of this property is greater than or equal to the length of the text, it will treated as -1.

      Note: the value of this field is prefixed with 'Swing' to avoid possible collisions with existing Actions.

      See Also:
    • LARGE_ICON_KEY

      public static final String LARGE_ICON_KEY
      The key used for storing an Icon. This is typically used by buttons, such as JButton and JToggleButton.

      If the same Action is used with menus and buttons you'll typically specify both a SMALL_ICON and a LARGE_ICON_KEY. The menu will use the SMALL_ICON and the button the LARGE_ICON_KEY.

      Note: the value of this field is prefixed with 'Swing' to avoid possible collisions with existing Actions.

      See Also:
    • enabled

      protected boolean enabled
      Specifies whether action is enabled; the default is true.
    • properties

      protected HashMap<String,Object> properties
      Stores any properties of the menu action that are not specially handled (such as enabled).
  • Constructor Details

    • AbstractMenuAction

      protected AbstractMenuAction(String name)
      Defines an AbstractMenuAction object with the specified description string and a default icon.
      Parameters:
      name - already localized String name of action (to appear on menu element)
    • AbstractMenuAction

      protected AbstractMenuAction(String nameTag, String[] menuPositionNames)
      Construct an AbstractMenuAction with the specified ResourceBundle lookup tag for the name, and hierarchical position in the menus.
      Parameters:
      nameTag - lookup String for the name of this action in ResourceBundles
      menuPositionNames - array of Strings identifying the ResourceBundle tags for the parent menu name strings
    • AbstractMenuAction

      protected AbstractMenuAction(String nameTag, String[] menuPositionNames, int priority)
      Construct an AbstractMenuAction with the specified ResourceBundle lookup tag for the name, and hierarchical position in the menus.
      Parameters:
      nameTag - lookup String for the above name in ResourceBundles
      menuPositionNames - array of Strings identifying the ResourceBundle tags for the menu name strings of the parent menus to contain the generated menuItem
      priority - int relative priority of this menu item relative to other
    • AbstractMenuAction

      protected AbstractMenuAction(String nameTag, String[] menuPositionNames, int priority, boolean initialState)
      Construct an AbstractMenuAction with the specified ResourceBundle lookup tag for the name, and hierarchical position in the menus.
      Parameters:
      nameTag - lookup String for the above name in ResourceBundles
      menuPositionNames - array of Strings identifying the ResourceBundle tags for the menu name strings of the parent menus to contain the generated menuItem
      priority - int relative priority of this menu item relative to other
      initialState - initial state of check box menu item to be created
    • AbstractMenuAction

      protected AbstractMenuAction(String nameTag, String[] menuPositionNames, String buttonGroupName)
      Construct an AbstractMenuAction with the specified ResourceBundle lookup tag for the name, and hierarchical position in the menus.
      Parameters:
      nameTag - lookup String for the above name in ResourceBundles
      menuPositionNames - array of Strings identifying the ResourceBundle tags for the menu name strings of the parent menus to contain the generated radio button menu item
      buttonGroupName - String name of ButtonGroup this radio button menu item
    • AbstractMenuAction

      protected AbstractMenuAction(String nameTag, String[] menuPositionNames, int priority, String buttonGroupName)
      Construct an AbstractMenuAction with the specified ResourceBundle lookup tag for the name, and hierarchical position in the menus.
      Parameters:
      nameTag - lookup String for the above name in ResourceBundles
      menuPositionNames - array of Strings identifying the ResourceBundle tags for the menu name strings of the parent menus to contain the generated radio button menu item
      priority - int relative priority of this menu item relative to other menu items on its lowest menu
      buttonGroupName - String name of ButtonGroup for this radio button menu item
  • Method Details

    • init

      public boolean init(Object item, Object view)
      Additional processing to be done when the action is attached to the menu structure. Intended to be overridden by subclasses that need to initialize state that is not available when the Providers are loaded, but only after the MainFrame is created and the collected menu hierarchy is actually being created.
      Parameters:
      item - GUI-specific menu item that is associated with the AbstractMenuAction subclass
      view - GUI window containing this menu.
      Returns:
      boolean true if menu item should be included in menus, false if it should be skipped
      See Also:
    • actionPerformed

      public abstract void actionPerformed(Object e)
      Invoked when an action occurs.
      Parameters:
      e - UI-specific Object describing the action
    • getValue

      public Object getValue(String key)
      Gets the Object associated with the specified key. This arranges for value substitution from ResourceBundles at menu creation time (after all the alternate ResourceBundle variants have been placed upon the classpath).
      Parameters:
      key - a string containing the specified key
      Returns:
      the binding Object stored with this key; if there are no keys, it will return null
    • putValue

      public void putValue(String key, Object newValue)
      Sets one of this object's properties using the associated key. If the value has changed, a PropertyChangeEvent is sent to listeners.
      Parameters:
      key - a String containing the key
      newValue - an Object value
    • isEnabled

      public boolean isEnabled()
      Returns the enabled state of the Action. When enabled, any component associated with this object is active and able to fire this object's actionPerformed method.
      Returns:
      true if this Action is enabled
    • setEnabled

      public void setEnabled(boolean newValue)
      Sets the enabled state of the Action. When enabled, any component associated with this object is active and able to fire this object's actionPerformed method. If the value has changed, a PropertyChangeEvent is sent to listeners.
      Parameters:
      newValue - true to enable this Action, false to disable it
    • setPropertyListener

      public void setPropertyListener(AbstractMenuActionPropertyListener propertyListener)
      Specify who should be informed of changes to properties. Only one listener can be associated with any given AbstractMenuAction.
      Parameters:
      propertyListener - AbstractMenuActionPropertyListener
    • getPropertyListener

      public AbstractMenuActionPropertyListener getPropertyListener()
      Get the currently associated GUI-specific PropertyListener.
      Returns:
      AbstractMenuActionPropertyListener associated with this AbstractMenuAction, or null if none associated
    • firePropertyChange

      protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)
      Supports reporting bound property changes. This method can be called when a bound property has changed and it will send the appropriate PropertyChangeEvent to any registered PropertyChangeListeners.
      Parameters:
      propertyName - String name of property that was changed
      oldValue - former value of property
      newValue - current value of property
    • parseMnemonics

      public static int[] parseMnemonics(String mnemonics)
      Convert a localized string of mnemonic letters into an array of ints, suitable for use by the above constructors.
      Parameters:
      mnemonics - String of mnemonic letters
      Returns:
      int array of mnemonic letter codes, or null if no string was provided