Class AbstractMenuAction
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AbstractPopupMenuAction
- Author:
- Andrew Pavlin, KA2DDO
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The key used for storing aKeyStroke
to be used as the accelerator for the action.static final String
The key used to determine the commandString
for theActionEvent
that will be created when anAction
is going to be notified as the result of residing in aKeymap
associated with aJComponent
.static final String
Identifies the ButtonGroup a radio button menu item is associated with.static final String
The key used for storing anInteger
that corresponds to the index in the text (identified by theNAME
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 anIcon
.static final String
Identifies the hierarchy path for the menu containers of a menu item.static final String
The key used for storing a longerString
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 anInteger
that corresponds to one of theKeyEvent
key codes.static final String
The key used for storing the localizedString
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.Stores any properties of the menu action that are not specially handled (such asenabled
).static final String
The key used for storing aBoolean
that corresponds to the selected state.static final String
The key used for storing a short localizedString
description for the action, used for tooltip text.static final String
The key used for storing a smallIcon
, such asImageIcon
.static final String
Indicates that this menu action should only be available for UI views of the specified content type. -
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractMenuAction
(String name) Defines anAbstractMenuAction
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 TypeMethodDescriptionabstract 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 theObject
associated with the specified key.boolean
Additional processing to be done when the action is attached to the menu structure.boolean
Returns the enabled state of theAction
.static int[]
parseMnemonics
(String mnemonics) Convert a localized string of mnemonic letters into an array of ints, suitable for use by the above constructors.void
Sets one of this object's properties using the associated key.void
setEnabled
(boolean newValue) Sets the enabled state of theAction
.void
setPropertyListener
(AbstractMenuActionPropertyListener propertyListener) Specify who should be informed of changes to properties.
-
Field Details
-
PRE_LOCALIZE_MENU_TAG_NAME
Identifies a specific menu item in the accumulated hierarchy. Must be a String.- See Also:
-
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
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:
-
MENU_PRIORITY
Identifies the sort priority on the lowest menu container for relative positioning a menu item. Must be a Number, and will be treated like an int. If not specified, assumes a priority of 2. AbstractMenuActions with the same priority on the same sub-menu will be displayed in order of listing in the array returned by the Provider subclass'sProvider.getMenuItems()
method.- See Also:
-
BUTTON_GROUP_NAME
Identifies the ButtonGroup a radio button menu item is associated with. Must be a String.- See Also:
-
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
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
The key used for storing the localizedString
name for the action, used for a menu or button.- See Also:
-
SHORT_DESCRIPTION
The key used for storing a short localizedString
description for the action, used for tooltip text. This class will automatically fill this in if a ResourceBundle entry with the key name ofPRE_LOCALIZE_MENU_TAG_NAME
appended with ".tooltip" exists.- See Also:
-
LONG_DESCRIPTION
The key used for storing a longerString
description for the action, could be used for context-sensitive help.- See Also:
-
SMALL_ICON
The key used for storing a smallIcon
, such asImageIcon
.- See Also:
-
ACTION_COMMAND_KEY
The key used to determine the commandString
for theActionEvent
that will be created when anAction
is going to be notified as the result of residing in aKeymap
associated with aJComponent
.- See Also:
-
ACCELERATOR_KEY
The key used for storing aKeyStroke
to be used as the accelerator for the action.- See Also:
-
MNEMONIC_KEY
The key used for storing anInteger
that corresponds to one of theKeyEvent
key codes. The value is commonly used to specify a mnemonic. For example:myAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_A)
sets the mnemonic ofmyAction
to 'a'.- See Also:
-
SELECTED_KEY
The key used for storing aBoolean
that corresponds to the selected state. This is typically used only for components that have a meaningful selection state. For example,radio button
andcheck box
make use of this but instances ofJMenu
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 acheck box
the selected state of thecheck box
will be set from that of theAction
. If the user clicks on thecheck box
the selected state of thecheck box
and theAction
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
The key used for storing anInteger
that corresponds to the index in the text (identified by theNAME
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
The key used for storing anIcon
. This is typically used by buttons, such asJButton
andJToggleButton
.If the same
Action
is used with menus and buttons you'll typically specify both aSMALL_ICON
and aLARGE_ICON_KEY
. The menu will use theSMALL_ICON
and the button theLARGE_ICON_KEY
.Note: the value of this field is prefixed with 'Swing' to avoid possible collisions with existing
Actions
.- See Also:
-
enabled
protected boolean enabledSpecifies whether action is enabled; the default is true. -
properties
Stores any properties of the menu action that are not specially handled (such asenabled
).
-
-
Constructor Details
-
AbstractMenuAction
Defines anAbstractMenuAction
object with the specified description string and a default icon.- Parameters:
name
- already localized String name of action (to appear on menu element)
-
AbstractMenuAction
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 ResourceBundlesmenuPositionNames
- array of Strings identifying the ResourceBundle tags for the parent menu name strings
-
AbstractMenuAction
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 ResourceBundlesmenuPositionNames
- array of Strings identifying the ResourceBundle tags for the menu name strings of the parent menus to contain the generated menuItempriority
- 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 ResourceBundlesmenuPositionNames
- array of Strings identifying the ResourceBundle tags for the menu name strings of the parent menus to contain the generated menuItempriority
- int relative priority of this menu item relative to otherinitialState
- initial state of check box menu item to be created
-
AbstractMenuAction
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 ResourceBundlesmenuPositionNames
- array of Strings identifying the ResourceBundle tags for the menu name strings of the parent menus to contain the generated radio button menu itembuttonGroupName
- 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 ResourceBundlesmenuPositionNames
- array of Strings identifying the ResourceBundle tags for the menu name strings of the parent menus to contain the generated radio button menu itempriority
- int relative priority of this menu item relative to other menu items on its lowest menubuttonGroupName
- String name of ButtonGroup for this radio button menu item
-
-
Method Details
-
init
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 subclassview
- 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
Invoked when an action occurs.- Parameters:
e
- UI-specific Object describing the action
-
getValue
Gets theObject
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 specifiedkey
- Returns:
- the binding
Object
stored with this key; if there are no keys, it will returnnull
-
putValue
Sets one of this object's properties using the associated key. If the value has changed, aPropertyChangeEvent
is sent to listeners.- Parameters:
key
- aString
containing the keynewValue
- anObject
value
-
isEnabled
public boolean isEnabled()Returns the enabled state of theAction
. When enabled, any component associated with this object is active and able to fire this object'sactionPerformed
method.- Returns:
- true if this
Action
is enabled
-
setEnabled
public void setEnabled(boolean newValue) Sets the enabled state of theAction
. When enabled, any component associated with this object is active and able to fire this object'sactionPerformed
method. If the value has changed, aPropertyChangeEvent
is sent to listeners.- Parameters:
newValue
- true to enable thisAction
, false to disable it
-
setPropertyListener
Specify who should be informed of changes to properties. Only one listener can be associated with any given AbstractMenuAction.- Parameters:
propertyListener
- AbstractMenuActionPropertyListener
-
getPropertyListener
Get the currently associated GUI-specific PropertyListener.- Returns:
- AbstractMenuActionPropertyListener associated with this AbstractMenuAction, or null if none associated
-
firePropertyChange
Supports reporting bound property changes. This method can be called when a bound property has changed and it will send the appropriatePropertyChangeEvent
to any registeredPropertyChangeListeners
.- Parameters:
propertyName
- String name of property that was changedoldValue
- former value of propertynewValue
- current value of property
-
parseMnemonics
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
-