Class KeyStrokeProperty

java.lang.Object
ca.corbett.extras.properties.AbstractProperty
ca.corbett.extras.properties.KeyStrokeProperty

public class KeyStrokeProperty extends AbstractProperty
A property implementation for storing KeyStroke values. This allows your application to expose keyboard shortcuts to the user for customization, and then persist them to application settings, rather than hard-coding them.

The Action to associate with the KeyStroke is also stored here, though it will be ignored when persisting/loading the property. This allows applications or extensions to associate functionality with the KeyStrokeProperty for convenience.

Since:
swing-extras 2.7
Author:
scorbo2
  • Constructor Details

    • KeyStrokeProperty

      public KeyStrokeProperty(String fullyQualifiedName, String label)
      Creates a new, blank KeyStrokeProperty with the given name and label. The initial KeyStroke value will be null to indicate no shortcut assigned, and "allowBlank" will be implicitly enabled. The associated Action will be null.
    • KeyStrokeProperty

      public KeyStrokeProperty(String fullyQualifiedName, String label, Action action)
      Creates a new, blank KeyStrokeProperty with the given name, label, and action. The initial KeyStroke value will be null to indicate no shortcut assigned, and "allowBlank" will be implicitly enabled.
    • KeyStrokeProperty

      public KeyStrokeProperty(String fullyQualifiedName, String label, KeyStroke keyStroke)
      Creates a new KeyStrokeProperty with the given name, label, and initial KeyStroke value. The initial KeyStroke value can be null to indicate no shortcut assigned. If so, "allowBlank" will be implicitly enabled. The associated Action will be null.
    • KeyStrokeProperty

      public KeyStrokeProperty(String fullyQualifiedName, String label, KeyStroke keyStroke, Action action)
      Creates a new KeyStrokeProperty with the given name, label, initial KeyStroke value, and action. The initial KeyStroke value can be null to indicate no shortcut assigned. If so, "allowBlank" will be implicitly enabled.
  • Method Details

    • isAllowBlank

      public boolean isAllowBlank()
      Reports whether blank (null) KeyStroke values are allowed for this property. The default is false, unless a null KeyStroke was supplied to the constructor.
    • setAllowBlank

      public KeyStrokeProperty setAllowBlank(boolean allowBlank)
      Decides whether blank (null) KeyStroke values are allowed for this property.
    • getAction

      public Action getAction()
      Gets the Action associated with this property, if any.
      Returns:
      The Action associated with this property, or null if none.
    • getKeyStroke

      public KeyStroke getKeyStroke()
      Gets the current KeyStroke value of this property.
    • getKeyStrokeString

      public String getKeyStrokeString()
      Gets the current KeyStroke value of this property as a String.
    • setKeyStroke

      public KeyStrokeProperty setKeyStroke(KeyStroke keyStroke)
      Sets the current KeyStroke value of this property.
    • setReservedKeyStrokes

      public KeyStrokeProperty setReservedKeyStrokes(List<KeyStroke> reservedKeyStrokes)
      Optionally sets a list of reserved KeyStrokes that cannot be assigned to this property. By default, no KeyStrokes are reserved. The given list will replace any previously set reserved KeyStrokes.
    • addReservedKeyStrokes

      public KeyStrokeProperty addReservedKeyStrokes(List<KeyStroke> additionalKeyStrokes)
      Adds additional reserved KeyStrokes to the list of KeyStrokes that cannot be assigned. Duplicates are automatically pruned. This method does not affect the reserved KeyStroke message.
    • clearReservedKeyStrokes

      public KeyStrokeProperty clearReservedKeyStrokes()
      Clears the list of reserved KeyStrokes, allowing all KeyStrokes to be assigned.
    • getReservedKeyStrokes

      public List<KeyStroke> getReservedKeyStrokes()
      Returns the list of reserved KeyStrokes that cannot be assigned to this property.
    • getReservedKeyStrokeMsg

      public String getReservedKeyStrokeMsg()
      Returns the validation message that will be given if a reserved KeyStroke is assigned.
    • setReservedKeyStrokeMsg

      public KeyStrokeProperty setReservedKeyStrokeMsg(String msg)
      Sets the validation message that will be given if a reserved KeyStroke is assigned. The message cannot be null or blank. If so, the previous message is retained.
    • saveToProps

      public void saveToProps(Properties props)
      Description copied from class: AbstractProperty
      Saves the current value(s) of this property to the given Properties instance.
      Specified by:
      saveToProps in class AbstractProperty
      Parameters:
      props - Any Properties instance which will receive the value(s) of this property.
    • loadFromProps

      public void loadFromProps(Properties props)
      Description copied from class: AbstractProperty
      Loads the value(s) for this property from the given Properties instance, overwriting any current value. The current value of this property will be used as a default value in the event that this property does not exist in the given Properties instance.
      Specified by:
      loadFromProps in class AbstractProperty
      Parameters:
      props - Any Properties instance which contains value(s) for this property.
    • generateFormFieldImpl

      protected FormField generateFormFieldImpl()
      Description copied from class: AbstractProperty
      Descendant classes must implement this method to generate a FormField associated with this property. The generateFormField() method in this class will call this abstract method to create the FormField, which will then be augmented with our fully qualified name, read-only state, help text, and extra attributes.
      Specified by:
      generateFormFieldImpl in class AbstractProperty
      Returns:
      A FormField associated with this property.
    • loadFromFormField

      public void loadFromFormField(FormField field)
      Description copied from class: AbstractProperty
      Populates this Property's value(s) from the given form field, assuming the field is of the correct type.
      Specified by:
      loadFromFormField in class AbstractProperty
      Parameters:
      field - The FormField containing a value for this property.