Package ca.corbett.forms.fields
Class KeyStrokeField
java.lang.Object
ca.corbett.forms.fields.FormField
ca.corbett.forms.fields.KeyStrokeField
- All Implemented Interfaces:
EventListener,DocumentListener
A custom FormField implementation that allows editing of a single
KeyStroke assignment. Intended to be used with KeyStrokeManager,
but can be used standalone as well.
Internally, this field is very similar to ShortTextField with some default values and a custom FieldValidator to ensure that the given shortcut string is valid. You can optionally allow blank input to indicate "no shortcut assigned". This is disabled by default (i.e. the given shortcut string must always be a valid keystroke).
You can optionally specify a list of reserved KeyStrokes that should not be allowed to be entered in this field. This is useful if you want to prevent users from assigning certain system-wide shortcuts that your application uses. This list is blank by default, meaning that any valid KeyStroke is allowed.
- Since:
- swing-extras 2.7
- Author:
- scorbo2
-
Field Summary
FieldsFields inherited from class ca.corbett.forms.fields.FormField
DEFAULT_FONT, defaultFont, extraAttributes, fieldComponent, fieldLabel, fieldValidators, helpLabel, ICON_SIZE, identifier, isEnabled, isVisible, margins, validationLabel, valueChangedListeners -
Constructor Summary
ConstructorsConstructorDescriptionKeyStrokeField(String label, KeyStroke keyStroke) Creates a new KeyStrokeField to represent the given KeyStroke, which can be null to start with an initial blank value. -
Method Summary
Modifier and TypeMethodDescriptionaddReservedKeyStrokes(List<KeyStroke> additionalKeyStrokes) Adds additional reserved KeyStrokes to the list of KeyStrokes that cannot be assigned.voidClears the list of reserved KeyStrokes, allowing all KeyStrokes to be assigned.intReturns the number of columns in the underlying JTextField.Returns the KeyStroke currently represented by this field, or null if the field is blank or contains an invalid KeyStroke string.Returns the raw KeyStroke string currently in this field.Returns the validation message that will be given if a reserved KeyStroke is entered.Returns a copy of the list of reserved KeyStrokes that cannot be assignedvoidbooleanReports whether this field allows blank input (no keystroke assigned).voidsetAllowBlank(boolean allowBlank) Decides whether this field allows blank input (no keystroke assigned).setColumns(int cols) Sets the number of columns in the underlying JTextField.setKeyStroke(KeyStroke keyStroke) Sets the KeyStroke represented by this field.setReservedKeyStrokeMsg(String reservedKeyStrokeMsg) Sets the validation message that will be given if a reserved KeyStroke is entered.setReservedKeyStrokes(List<KeyStroke> reservedKeyStrokes) Optionally set a list of reserved KeyStrokes that cannot be assigned using this field.setReservedKeyStrokes(List<KeyStroke> reservedKeyStrokes, String reservedMsg) Optionally set a list of reserved KeyStrokes that cannot be assigned, and also sets a custom message to be used when validation fails because a reserved KeyStroke was entered.Methods inherited from class ca.corbett.forms.fields.FormField
addAllExtraAttributes, addFieldValidator, addValueChangedListener, clearExtraAttribute, clearExtraAttributes, clearValidationResults, equals, fireValueChangedEvent, getDefaultFont, getExtraAttribute, getFieldComponent, getFieldLabel, getHelpLabel, getHelpText, getIdentifier, getMargins, getValidationLabel, hasFieldLabel, hashCode, hasHelpLabel, hasValidationLabel, isEnabled, isMultiLine, isValid, isVisible, preRender, removeAllFieldValidators, removeFieldValidator, removeValueChangedListener, setAllExtraAttributes, setDefaultFont, setEnabled, setExtraAttribute, setFieldLabelFont, setHelpText, setIdentifier, setMargins, setVisible, shouldExpand, validate
-
Field Details
-
RESERVED_MSG
- See Also:
-
DEFAULT_COLS
public static final int DEFAULT_COLS- See Also:
-
-
Constructor Details
-
KeyStrokeField
Creates a new KeyStrokeField to represent the given KeyStroke, which can be null to start with an initial blank value. This will fail validation by default, unless you invoke setAllowBlank(true).
-
-
Method Details
-
getKeyStroke
Returns the KeyStroke currently represented by this field, or null if the field is blank or contains an invalid KeyStroke string. -
setKeyStroke
Sets the KeyStroke represented by this field. Setting null or blank string is allowed, even if allowBlank is false, but the field will fail validation in that case. -
getKeyStrokeString
Returns the raw KeyStroke string currently in this field. If the current text does not represent a valid KeyStroke, this method will still return empty string. -
getColumns
public int getColumns()Returns the number of columns in the underlying JTextField. -
setColumns
Sets the number of columns in the underlying JTextField. -
isAllowBlank
public boolean isAllowBlank()Reports whether this field allows blank input (no keystroke assigned). -
setAllowBlank
Decides whether this field allows blank input (no keystroke assigned). The default is false, meaning a valid KeyStroke string must always be entered. -
setReservedKeyStrokes
Optionally set a list of reserved KeyStrokes that cannot be assigned using this field. By default, no KeyStrokes are reserved. The given list will replace any previously set reserved KeyStrokes. -
setReservedKeyStrokes
Optionally set a list of reserved KeyStrokes that cannot be assigned, and also sets a custom message to be used when validation fails because a reserved KeyStroke was entered. 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 a copy of the list of reserved KeyStrokes that cannot be assigned -
getReservedKeyStrokeMsg
Returns the validation message that will be given if a reserved KeyStroke is entered. -
setReservedKeyStrokeMsg
Sets the validation message that will be given if a reserved KeyStroke is entered. -
insertUpdate
- Specified by:
insertUpdatein interfaceDocumentListener
-
removeUpdate
- Specified by:
removeUpdatein interfaceDocumentListener
-
changedUpdate
- Specified by:
changedUpdatein interfaceDocumentListener
-