Package ca.corbett.extras.properties
Class KeyStrokeProperty
java.lang.Object
ca.corbett.extras.properties.AbstractProperty
ca.corbett.extras.properties.KeyStrokeProperty
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
-
Field Summary
Fields inherited from class ca.corbett.extras.properties.AbstractProperty
categoryName, DEFAULT_CATEGORY, DEFAULT_PROPERTY_NAME, extraAttributes, fullyQualifiedName, helpText, isEnabled, isExposed, isInitiallyEditable, isInitiallyVisible, marginPadding, propertyLabel, propertyName, subCategoryName -
Constructor Summary
ConstructorsConstructorDescriptionKeyStrokeProperty(String fullyQualifiedName, String label) Creates a new, blank KeyStrokeProperty with the given name and label.KeyStrokeProperty(String fullyQualifiedName, String label, Action action) Creates a new, blank KeyStrokeProperty with the given name, label, and action.KeyStrokeProperty(String fullyQualifiedName, String label, KeyStroke keyStroke) Creates a new KeyStrokeProperty with the given name, label, and initial KeyStroke value.KeyStrokeProperty(String fullyQualifiedName, String label, KeyStroke keyStroke, Action action) Creates a new KeyStrokeProperty with the given name, label, initial KeyStroke value, and action. -
Method Summary
Modifier and TypeMethodDescriptionaddReservedKeyStrokes(List<KeyStroke> additionalKeyStrokes) Adds additional reserved KeyStrokes to the list of KeyStrokes that cannot be assigned.Clears the list of reserved KeyStrokes, allowing all KeyStrokes to be assigned.protected FormFieldDescendant classes must implement this method to generate a FormField associated with this property.Gets the Action associated with this property, if any.Gets the current KeyStroke value of this property.Gets the current KeyStroke value of this property as a String.Returns the validation message that will be given if a reserved KeyStroke is assigned.Returns the list of reserved KeyStrokes that cannot be assigned to this property.booleanReports whether blank (null) KeyStroke values are allowed for this property.voidloadFromFormField(FormField field) Populates this Property's value(s) from the given form field, assuming the field is of the correct type.voidloadFromProps(Properties props) Loads the value(s) for this property from the given Properties instance, overwriting any current value.voidsaveToProps(Properties props) Saves the current value(s) of this property to the given Properties instance.setAllowBlank(boolean allowBlank) Decides whether blank (null) KeyStroke values are allowed for this property.setKeyStroke(KeyStroke keyStroke) Sets the current KeyStroke value of this property.Sets the validation message that will be given if a reserved KeyStroke is assigned.setReservedKeyStrokes(List<KeyStroke> reservedKeyStrokes) Optionally sets a list of reserved KeyStrokes that cannot be assigned to this property.Methods inherited from class ca.corbett.extras.properties.AbstractProperty
addAllExtraAttributes, addBottomPadding, addFormFieldChangeListener, addFormFieldGenerationListener, addInnerPadding, addLeftPadding, addPadding, addRightPadding, addTopPadding, clearExtraAttribute, clearExtraAttributes, equals, fireFormFieldChangedEvent, fireFormFieldGeneratedEvent, generateFormField, generateFormField, getCategoryName, getExtraAttribute, getFullyQualifiedName, getHelpText, getMarginPadding, getPropertyLabel, getPropertyName, getSubCategoryName, hashCode, isAllowsUserInput, isEnabled, isExposed, isInitiallyEditable, isInitiallyVisible, removeAllFormFieldChangeListeners, removeAllFormFieldGenerationListeners, removeFormFieldChangeListener, removeFormFieldGenerationListener, setAllExtraAttributes, setEnabled, setExposed, setExtraAttribute, setHelpText, setInitiallyEditable, setInitiallyVisible, setPropertyLabel
-
Constructor Details
-
KeyStrokeProperty
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
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
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
Decides whether blank (null) KeyStroke values are allowed for this property. -
getAction
Gets the Action associated with this property, if any.- Returns:
- The Action associated with this property, or null if none.
-
getKeyStroke
Gets the current KeyStroke value of this property. -
getKeyStrokeString
Gets the current KeyStroke value of this property as a String. -
setKeyStroke
Sets the current KeyStroke value of this property. -
setReservedKeyStrokes
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
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
Clears the list of reserved KeyStrokes, allowing all KeyStrokes to be assigned. -
getReservedKeyStrokes
Returns the list of reserved KeyStrokes that cannot be assigned to this property. -
getReservedKeyStrokeMsg
Returns the validation message that will be given if a reserved KeyStroke is assigned. -
setReservedKeyStrokeMsg
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
Description copied from class:AbstractPropertySaves the current value(s) of this property to the given Properties instance.- Specified by:
saveToPropsin classAbstractProperty- Parameters:
props- Any Properties instance which will receive the value(s) of this property.
-
loadFromProps
Description copied from class:AbstractPropertyLoads 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:
loadFromPropsin classAbstractProperty- Parameters:
props- Any Properties instance which contains value(s) for this property.
-
generateFormFieldImpl
Description copied from class:AbstractPropertyDescendant 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:
generateFormFieldImplin classAbstractProperty- Returns:
- A FormField associated with this property.
-
loadFromFormField
Description copied from class:AbstractPropertyPopulates this Property's value(s) from the given form field, assuming the field is of the correct type.- Specified by:
loadFromFormFieldin classAbstractProperty- Parameters:
field- The FormField containing a value for this property.
-