Package ca.corbett.extras
Class EnhancedAction
java.lang.Object
javax.swing.AbstractAction
ca.corbett.extras.EnhancedAction
- All Implemented Interfaces:
ActionListener,Serializable,Cloneable,EventListener,Action
- Direct Known Subclasses:
CardAction,ListFieldPanel.ListItemAddAction,ListFieldPanel.ListItemHelpAction,ListItemClearAction,ListItemMoveAction,ListItemRemoveAction,ListItemSelectAllAction,ToolBarAction
Extends the AbstractAction class to provide convenient wrappers around setting
the name, icon, short description, and accelerator. This saves a small amount of annoying
code having to interact with an obtuse Map of String to Object provided
by the Action and AbstractAction classes.
- Since:
- swing-extras 2.7
- Author:
- scorbo2
- See Also:
-
Field Summary
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabledFields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty EnhancedAction with no name or icon.EnhancedAction(String name) Creates a new EnhancedAction with the specified name and no icon.EnhancedAction(String name, Icon icon) Creates a new EnhancedAction with the specified name and icon.EnhancedAction(Icon icon) Creates a new EnhancedAction with the specified icon and no name. -
Method Summary
Modifier and TypeMethodDescriptionReturns the accelerator key of this action, or null if no accelerator key is set.Returns the short description of this action, or null if no description is set.getIcon()Returns the icon of this action, or null if no icon is set.getName()Returns the name of this action, or null if no name is set.Synonym for getDescription, for improved readability when getting tooltips.Sets a new accelerator key for this action.setDescription(String description) Sets a new short description for this action.Sets a new icon for this action.Sets a new name for this action.setTooltip(String tooltip) Synonym for setDescription, for improved readability when setting tooltips.Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabledMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.awt.event.ActionListener
actionPerformed
-
Constructor Details
-
EnhancedAction
public EnhancedAction()Creates an empty EnhancedAction with no name or icon. -
EnhancedAction
Creates a new EnhancedAction with the specified name and no icon. This is useful for an undecorated button or menu item.- Parameters:
name- The text to use as button or menu item label.
-
EnhancedAction
Creates a new EnhancedAction with the specified icon and no name. This is useful for an icon-only button.- Parameters:
icon- The icon to use for the button or menu item.
-
EnhancedAction
Creates a new EnhancedAction with the specified name and icon.- Parameters:
name- The text to use as button or menu item label.icon- The icon to use for the button or menu item.
-
-
Method Details
-
setName
Sets a new name for this action. This will update any existing button or menu item using this action.- Parameters:
name- The new text to use as button or menu item label.- Returns:
- This EnhancedAction, for method chaining.
-
setIcon
Sets a new icon for this action. This will update any existing button or menu item using this action.- Parameters:
icon- The new icon to use for the button or menu item.- Returns:
- This EnhancedAction, for method chaining.
-
setDescription
Sets a new short description for this action. This will update any existing button or menu item using this action. The short description is typically used as the tooltip text for buttons.- Parameters:
description- The new short description / tooltip text.- Returns:
- This EnhancedAction, for method chaining.
-
setTooltip
Synonym for setDescription, for improved readability when setting tooltips.- Parameters:
tooltip- The new tooltip text.- Returns:
- This EnhancedAction, for method chaining.
-
setAcceleratorKey
Sets a new accelerator key for this action. This will update any existing menu item using this action. The accelerator key is the keyboard shortcut that activates the action when the menu item is focused.- Parameters:
key- The new accelerator key.- Returns:
- This EnhancedAction, for method chaining.
-
getName
Returns the name of this action, or null if no name is set.- Returns:
- The name of this action. Might be null.
-
getIcon
Returns the icon of this action, or null if no icon is set.- Returns:
- The icon of this action. Might be null.
-
getDescription
Returns the short description of this action, or null if no description is set.- Returns:
- The short description of this action. Might be null.
-
getTooltip
Synonym for getDescription, for improved readability when getting tooltips.- Returns:
- The tooltip text of this action. Might be null.
-
getAcceleratorKey
Returns the accelerator key of this action, or null if no accelerator key is set. Since the grandparent Action class uses a generic Object map, it's possible that our accelerator key is not actually a KeyStroke, so we check the type before returning it. If not recognized, we return null.- Returns:
- The accelerator key of this action. Might be null.
-