Class FixedSizeIntegerTextField
java.lang.Object
docking.widgets.textfield.integer.AbstractIntegerTextField
docking.widgets.textfield.FixedSizeIntegerTextField
TextField for entering numbers where the values are restricted to those that can be represented
by a specific number of bits. For example, if the bit size is eight, signed values
must be between -128 and 127 and unsigned values must be between 0 and 255. By
default, this class uses all the formats from the
IntegerFormat enum class except for
signed octal and signed binary.
This field does continuous checking, so you can't enter a bad value.
The bitSize can be changed on this field which will cause its min and max values to change to
the appropriate values for that bit size and signedness of the current IntegerFormat.
Also, if the current value doesn't fit in the new bit size, it will be reset to having no
value (textfield is blank).
Internally, values are maintained using BigIntegers so this class can accommodate any bit size desired. There are convenience methods for getting the value as either an int or long. You should only use these convenience methods if you know the current bit size fits in either a int or long respectively.
There are several configuration options as follows:
- Bit Size - This value must be 1 or greater and determines the minimum and maximum allowed input values when combined with the current format signedness.
- Use number prefix - If this mode is on, then non-decimal values must be typed with its prefix(i.e., 0x for hex). When requiring non-decimal prefix, the field is permitted to auto switch formats based on the prefix (or lack thereof). When the "use prefix" option is off, the only way to switch formats is to use the built-in ctrl-M action.
- Show the number mode as hint text - If showing number mode is on, the format short name
is displayed lightly in the bottom right portion of the text field.
See
AbstractIntegerTextField.setShowNumberMode(boolean)
-
Field Summary
Fields inherited from class AbstractIntegerTextField
allFormats, currentFormat -
Constructor Summary
ConstructorsConstructorDescriptionFixedSizeIntegerTextField(int columns, int bitSize) ConstructorFixedSizeIntegerTextField(int columns, int bitSize, long initialValue) ConstructorFixedSizeIntegerTextField(int columns, int bitSize, BigInteger initialValue) Constructor -
Method Summary
Modifier and TypeMethodDescriptionintReturns the current bit size for this field.voidsetBitSize(int bitSize) Sets the bit size for this field, which effectively sets the min and max values for this field when combined with the signedness of the currently selectedIntegerFormat.voidsetFormat(IntegerFormat format) Sets the format for entering an integer into this field.voidsetValue(BigInteger newValue) Sets the value of the field to the given value.Methods inherited from class AbstractIntegerTextField
addActionListener, addChangeListener, clearSelection, getAllFormats, getComponent, getFormat, getIntValue, getLongValue, getMaxValue, getMinValue, getText, getValue, isInBounds, isSelectTextOnFocusGainedEnabled, removeActionListener, removeChangeListener, requestFocus, selectAll, setAccessibleName, setAutoSwitchMode, setEditable, setEnabled, setHorizontalAlignment, setMaxValue, setMinValue, setShowNumberMode, setText, setValue, setValue
-
Constructor Details
-
FixedSizeIntegerTextField
public FixedSizeIntegerTextField(int columns, int bitSize) Constructor- Parameters:
columns- the number of character positions for the preferred size of the text fieldbitSize- the initial bit size
-
FixedSizeIntegerTextField
public FixedSizeIntegerTextField(int columns, int bitSize, long initialValue) Constructor- Parameters:
columns- the number of character positions for the preferred size of the text fieldbitSize- the initial bit sizeinitialValue- the value to initialize the field to
-
FixedSizeIntegerTextField
Constructor- Parameters:
columns- the number of character positions for the preferred size of the text fieldbitSize- the initial bit sizeinitialValue- the value to initialize the field to
-
-
Method Details
-
setBitSize
public void setBitSize(int bitSize) Sets the bit size for this field, which effectively sets the min and max values for this field when combined with the signedness of the currently selectedIntegerFormat.- Parameters:
bitSize- the number of bits that will be used to store this value, effectively determining its min and max value
-
getBitSize
public int getBitSize()Returns the current bit size for this field.- Returns:
- the current bit size for this field
-
setValue
Description copied from class:AbstractIntegerTextFieldSets the value of the field to the given value. A null value will clear the field.- Overrides:
setValuein classAbstractIntegerTextField- Parameters:
newValue- the new value or null.
-
setFormat
Description copied from class:AbstractIntegerTextFieldSets 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.- Overrides:
setFormatin classAbstractIntegerTextField- Parameters:
format- the format for entering an integer into the field.
-