Class AbstractIntegerTextField
java.lang.Object
docking.widgets.textfield.integer.AbstractIntegerTextField
- Direct Known Subclasses:
FixedSizeIntegerTextField, IntegerTextField
Base class for IntegerTextFields that allow entering integer values based on some
integer format (i.e., hex, decimal, unsigned hex, binary, etc.). This field does input
validation, so only valid text for the current format can be typed.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAbstractIntegerTextField(int columns, BigInteger initialValue, IntegerFormat... formats) Creates a new IntegerTextField with the specified number of columns and initial value -
Method Summary
Modifier and TypeMethodDescriptionvoidaddActionListener(ActionListener listener) Adds an ActionListener to the TextField.voidaddChangeListener(ChangeListener listener) Adds a change listener that will be notified whenever the value changes.voidClears the current selection and places the caret at the end of the text.Returns a list of all supportIntegerFormats supported by this field.Returns the JTextField component that this class manages.Returns the current format for entering numbers into this field.intReturns the current value as an int.longReturns the current value as a long.Returns the current maximum allowed value.Returns the current minimum allowed value.getText()Returns the current text displayed in the field.getValue()Returns the current value of the field or null if the field has no current value.protected booleanisInBounds(BigInteger value) booleanReturns true if the text field will select the text when it initially gains focus..voidremoveActionListener(ActionListener listener) Removes an ActionListener from the TextField.voidremoveChangeListener(ChangeListener listener) Removes the changes listener.voidRequests focus to the JTextFieldvoidSelects the text in the JTextFieldvoidsetAccessibleName(String name) Sets the accessible name for the component of this input field.voidsetAutoSwitchMode(boolean newAutoSwitch) Sets whether this text field will switch the input mode format when typing a matching prefix.voidsetEditable(boolean editable) Sets the editable mode for the JTextField componentvoidsetEnabled(boolean enabled) Sets the enablement on the JTextField component;voidsetFormat(IntegerFormat format) Sets the format for entering an integer into this field.voidsetHorizontalAlignment(int alignment) Sets the horizontal alignment of the JTextFieldprotected voidsetMaxValue(BigInteger maxValue) Sets the maximum value.protected voidsetMinValue(BigInteger minValue) Sets the minimum value.voidsetShowNumberMode(boolean show) Turns on or off the faded text that displays the field's radix mode (hex or decimal).booleanSets the field to the given text.voidsetValue(int newValue) Convenience method for setting the value to an int value;voidsetValue(long newValue) Convenience method for setting the value to a long value;voidsetValue(BigInteger newValue) Sets the value of the field to the given value.
-
Field Details
-
allFormats
-
currentFormat
-
-
Constructor Details
-
AbstractIntegerTextField
@SafeVarargs public AbstractIntegerTextField(int columns, BigInteger initialValue, IntegerFormat... formats) Creates a new IntegerTextField with the specified number of columns and initial value- Parameters:
columns- the number of columnsinitialValue- the initial valueformats- the supported InputNumberModes
-
-
Method Details
-
setAccessibleName
Sets the accessible name for the component of this input field.- Parameters:
name- the accessible name for this field
-
addChangeListener
Adds a change listener that will be notified whenever the value changes.- Parameters:
listener- the change listener to add.
-
removeChangeListener
Removes the changes listener.- Parameters:
listener- the listener to be removed.
-
isSelectTextOnFocusGainedEnabled
public boolean isSelectTextOnFocusGainedEnabled()Returns true if the text field will select the text when it initially gains focus..- Returns:
- true if the text field will select the text when it initially gains focus.
-
getValue
Returns the current value of the field or null if the field has no current value.- Returns:
- the current value of the field or null if the field has no current value.
-
getIntValue
public int getIntValue()Returns the current value as an int.If the field has no current value, 0 will be returned. If the value is bigger (or smaller) than an int, it will be cast to an int.
If using this method, it is highly recommended that you set the max value to
Integer.MAX_VALUEor lower.- Returns:
- the current value as an int. Or 0 if there is no value
- Throws:
ArithmeticException- if the value in this field will not fit into an int
-
getLongValue
public long getLongValue()Returns the current value as a long.If the field has no current value, 0 will be returned. If the value is bigger (or smaller) than an long, it will be cast to a long.
If using this method, it is highly recommended that you set the max value to
Long.MAX_VALUEor lower.- Returns:
- the current value as a long. Or 0 if there is no value
- Throws:
ArithmeticException- if the value in this field will not fit into a long
-
setValue
public void setValue(long newValue) Convenience method for setting the value to a long value;- Parameters:
newValue- the new value for the field.
-
setValue
public void setValue(int newValue) Convenience method for setting the value to an int value;- Parameters:
newValue- the new value for the field.
-
setText
Sets the field to the given text. The text must be a properly formated string that is a valid value for this field. If the field is set to not allow "0x" prefixes, then the input string cannot start with 0x and furthermore, if the field is in decimal mode, then input string cannot take in hex digits a-f. On the other hand, if "0x" prefixes are allowed, then the input string can be either a decimal number or a hex number depending on if the input string starts with "0x". In this case, the field's hex mode will be set to match the input text. If the text is not valid, the field will not change.- Parameters:
text- the value as text to set on this field- Returns:
- true if the set was successful
-
setValue
Sets the value of the field to the given value. A null value will clear the field.- Parameters:
newValue- the new value or null.
-
setShowNumberMode
public void setShowNumberMode(boolean show) Turns on or off the faded text that displays the field's radix mode (hex or decimal).- Parameters:
show- true to show the radix mode.
-
setFormat
Sets the format for entering an integer into this field. The current text in the field will change to keep the same numeric value, but in the new input format.- Parameters:
format- the format for entering an integer into the field.
-
getFormat
Returns the current format for entering numbers into this field.- Returns:
- the current format for entering numbers into this field
-
getText
Returns the current text displayed in the field.- Returns:
- the current text displayed in the field.
-
getMinValue
Returns the current minimum allowed value. Null indicates that there is no minimum value.- Returns:
- the current maximum value allowed.
-
getMaxValue
Returns the current maximum allowed value. Null indicates that there is no maximum value.- Returns:
- the current maximum value allowed.
-
getComponent
Returns the JTextField component that this class manages.- Returns:
- the JTextField component that this class manages.
-
addActionListener
Adds an ActionListener to the TextField.- Parameters:
listener- the ActionListener to add.
-
removeActionListener
Removes an ActionListener from the TextField.- Parameters:
listener- the ActionListener to remove.
-
setEnabled
public void setEnabled(boolean enabled) Sets the enablement on the JTextField component;- Parameters:
enabled- true for enabled, false for disabled.
-
setEditable
public void setEditable(boolean editable) Sets the editable mode for the JTextField component- Parameters:
editable- boolean flag, if true component is editable
-
requestFocus
public void requestFocus()Requests focus to the JTextField -
selectAll
public void selectAll()Selects the text in the JTextField -
clearSelection
public void clearSelection()Clears the current selection and places the caret at the end of the text. -
setHorizontalAlignment
public void setHorizontalAlignment(int alignment) Sets the horizontal alignment of the JTextField- Parameters:
alignment- the alignment as inJTextField.setHorizontalAlignment(int)
-
setAutoSwitchMode
public void setAutoSwitchMode(boolean newAutoSwitch) Sets whether this text field will switch the input mode format when typing a matching prefix. For example, assuming DEC and HEX modes are available, while in DEC mode, typing0xwill switch the mode format to HEX.Auto-switching is on by default.
- Parameters:
newAutoSwitch- true to auto-switch; false requires user to change modes manually
-
getAllFormats
Returns a list of all supportIntegerFormats supported by this field.- Returns:
- a list of all support number formats for this field.
-
setMinValue
Sets the minimum value. The given value must be less than or equal to 0.- Parameters:
minValue- the value
-
setMaxValue
Sets the maximum value. The given value must be greater than 0.- Parameters:
maxValue- the value
-
isInBounds
-