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

public abstract class EnhancedAction extends AbstractAction
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:
  • Constructor Details

    • EnhancedAction

      public EnhancedAction()
      Creates an empty EnhancedAction with no name or icon.
    • EnhancedAction

      public EnhancedAction(String name)
      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

      public EnhancedAction(Icon icon)
      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

      public EnhancedAction(String name, Icon icon)
      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

      public EnhancedAction setName(String name)
      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

      public EnhancedAction setIcon(Icon icon)
      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

      public EnhancedAction setDescription(String description)
      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

      public EnhancedAction setTooltip(String tooltip)
      Synonym for setDescription, for improved readability when setting tooltips.
      Parameters:
      tooltip - The new tooltip text.
      Returns:
      This EnhancedAction, for method chaining.
    • setAcceleratorKey

      public EnhancedAction setAcceleratorKey(KeyStroke key)
      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

      public String getName()
      Returns the name of this action, or null if no name is set.
      Returns:
      The name of this action. Might be null.
    • getIcon

      public Icon getIcon()
      Returns the icon of this action, or null if no icon is set.
      Returns:
      The icon of this action. Might be null.
    • getDescription

      public String 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

      public String getTooltip()
      Synonym for getDescription, for improved readability when getting tooltips.
      Returns:
      The tooltip text of this action. Might be null.
    • getAcceleratorKey

      public KeyStroke 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.