Class AbstractCommand

  • All Implemented Interfaces:
    java.awt.event.ActionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action
    Direct Known Subclasses:
    AbstractToggleCommand, DelegatedCommand

    public abstract class AbstractCommand
    extends javax.swing.AbstractAction
    The abstract base class for main application commands in Strange Eons.

    Because this class is descended from Swing Actions, it includes a property map that can be used to set its name, icon, and so forth. However, this class also defines several convenience methods for setting these properties (all of which are final). Some of these perform additional processing on the input before setting it as the value for the relevant property (see, for example, setName(java.lang.String). In these cases you can bypass the additional processing by setting the relevant property value directly.

    Since:
    3.0
    Author:
    Chris Jennings
    See Also:
    AbstractAction.putValue(java.lang.String, java.lang.Object), Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String BUTTON_ID_KEY
      The key used for storing the ID string to use for this command when it is added to a context bar using ContextBar.CommandButton.
      • Fields inherited from class javax.swing.AbstractAction

        changeSupport, enabled
      • Fields 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

      Constructors 
      Constructor Description
      AbstractCommand()
      Creates a command with no predefined name or icon.
      AbstractCommand​(java.lang.String nameKey)
      Defines a command using a name determined by the specified string key.
      AbstractCommand​(java.lang.String nameKey, java.lang.String iconResource)
      Defines a command using a name determined by the specified string key and an icon loaded from the given icon resource.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      javax.swing.KeyStroke getAccelerator()
      Returns the accelerator key for this command, or null if the command has no accelerator key.
      protected java.lang.String getCommandString​(java.awt.event.ActionEvent e)
      If the action event contains a special command string, returns that string.
      javax.swing.Icon getIcon()
      Returns the command's icon.
      java.lang.String getName()
      Returns the name of the command, or null.
      void setAccelerator​(javax.swing.KeyStroke ks)
      Sets the accelerator key for this command.
      void setIcon​(java.lang.String iconResource)
      Sets the command's icon from an icon resource identifier.
      void setIcon​(javax.swing.Icon icon)
      Sets the command's icon.
      void setName​(java.lang.String name)
      Sets the name of the action.
      void setNameKey​(java.lang.String nameKey)
      Sets the name of the command by looking up nameKey in the global interface Language.
      java.lang.String toString()
      Returns a string including the command's ID and whether or not it is enabled, suitable for debugging purposes.
      void update()
      Updates the command's state.
      • Methods inherited from class javax.swing.AbstractAction

        addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface javax.swing.Action

        accept
      • Methods inherited from interface java.awt.event.ActionListener

        actionPerformed
    • Field Detail

      • BUTTON_ID_KEY

        public static final java.lang.String BUTTON_ID_KEY
        The key used for storing the ID string to use for this command when it is added to a context bar using ContextBar.CommandButton. If this is null, then a non-null ID must be provided when creating the button.
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractCommand

        public AbstractCommand()
        Creates a command with no predefined name or icon.
      • AbstractCommand

        public AbstractCommand​(java.lang.String nameKey)
        Defines a command using a name determined by the specified string key.
        Parameters:
        nameKey - the localized text key for the command name
        See Also:
        setNameKey(java.lang.String)
      • AbstractCommand

        public AbstractCommand​(java.lang.String nameKey,
                               java.lang.String iconResource)
        Defines a command using a name determined by the specified string key and an icon loaded from the given icon resource.
        Parameters:
        nameKey - the localized text key for the command name
        iconResource - the resource file to load an icon from
        See Also:
        setNameKey(java.lang.String), setIcon(javax.swing.Icon)
    • Method Detail

      • update

        public void update()
        Updates the command's state. This method is called to update the command's internal state. It is typically called just before a menu containing the a menu item whose action is set to the command is displayed. (The default implementation does nothing.)
      • setName

        public final void setName​(java.lang.String name)
        Sets the name of the action. If the name contains an ampersand (&), the following character will be used to set the mnemonic letter for the action.
        Parameters:
        name - the new action name
        See Also:
        PlatformSupport.getKeyStroke(java.lang.String)
      • setNameKey

        public final void setNameKey​(java.lang.String nameKey)
        Sets the name of the command by looking up nameKey in the global interface Language. The localized text for the key will be used to set the name as if by calling setName(java.lang.String). Before using the value of the key, platform-specific variants will be checked for by appending "-win", "-mac", or "-other" to the key name, depending on the platform. If the platform-specific key exists, it is used instead.

        The name key will also be used to set the ID to use when the command is added to a ContextBar. The ID is generated automatically by: removing "app-" from the start of the key if present, replacing hyphens with underscores, and converting the key to uppercase. To change the default ID, use putValue( BUTTON_ID_KEY, customID ).

        Parameters:
        nameKey - the name of the string key to use to set the name
      • getName

        public final java.lang.String getName()
        Returns the name of the command, or null.
        Returns:
        the command name
      • setIcon

        public final void setIcon​(javax.swing.Icon icon)
        Sets the command's icon.
        Parameters:
        icon - the icon to use for the command
      • setIcon

        public final void setIcon​(java.lang.String iconResource)
        Sets the command's icon from an icon resource identifier. The icon is loaded as if by ResourceKit.getIcon(java.lang.String).
        Parameters:
        iconResource - the name of the icon resource to load
      • getIcon

        public final javax.swing.Icon getIcon()
        Returns the command's icon.
        Returns:
        the icon associated with the command, if any
      • setAccelerator

        public final void setAccelerator​(javax.swing.KeyStroke ks)
        Sets the accelerator key for this command. If null, no accelerator key is assigned.
        Parameters:
        ks - the key stroke to use as the accelerator for this action
      • getAccelerator

        public final javax.swing.KeyStroke getAccelerator()
        Returns the accelerator key for this command, or null if the command has no accelerator key.
        Returns:
        the accelerator key for the command, or null
      • toString

        public java.lang.String toString()
        Returns a string including the command's ID and whether or not it is enabled, suitable for debugging purposes.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a debugging string for the command
      • getCommandString

        protected java.lang.String getCommandString​(java.awt.event.ActionEvent e)
        If the action event contains a special command string, returns that string. Otherwise, returns null.
        Parameters:
        e - the action event that fired the command
        Returns:
        null if the event's action command is null, empty, or the default value for this command; otherwise, the value of the action command