Class AbstractIntegerTextField

java.lang.Object
docking.widgets.textfield.integer.AbstractIntegerTextField
Direct Known Subclasses:
FixedSizeIntegerTextField, IntegerTextField

public class AbstractIntegerTextField extends Object
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 Details

  • 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 columns
      initialValue - the initial value
      formats - the supported InputNumberModes
  • Method Details

    • setAccessibleName

      public void setAccessibleName(String name)
      Sets the accessible name for the component of this input field.
      Parameters:
      name - the accessible name for this field
    • addChangeListener

      public void addChangeListener(ChangeListener listener)
      Adds a change listener that will be notified whenever the value changes.
      Parameters:
      listener - the change listener to add.
    • removeChangeListener

      public void removeChangeListener(ChangeListener listener)
      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

      public BigInteger 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_VALUE or 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_VALUE or 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

      public boolean setText(String text)
      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

      public void setValue(BigInteger newValue)
      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

      public void setFormat(IntegerFormat format)
      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

      public IntegerFormat getFormat()
      Returns the current format for entering numbers into this field.
      Returns:
      the current format for entering numbers into this field
    • getText

      public String getText()
      Returns the current text displayed in the field.
      Returns:
      the current text displayed in the field.
    • getMinValue

      public BigInteger getMinValue()
      Returns the current minimum allowed value. Null indicates that there is no minimum value.
      Returns:
      the current maximum value allowed.
    • getMaxValue

      public BigInteger getMaxValue()
      Returns the current maximum allowed value. Null indicates that there is no maximum value.
      Returns:
      the current maximum value allowed.
    • getComponent

      public JComponent getComponent()
      Returns the JTextField component that this class manages.
      Returns:
      the JTextField component that this class manages.
    • addActionListener

      public void addActionListener(ActionListener listener)
      Adds an ActionListener to the TextField.
      Parameters:
      listener - the ActionListener to add.
    • removeActionListener

      public void removeActionListener(ActionListener listener)
      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 in JTextField.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, typing 0x will 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

      public List<IntegerFormat> getAllFormats()
      Returns a list of all support IntegerFormats supported by this field.
      Returns:
      a list of all support number formats for this field.
    • setMinValue

      protected void setMinValue(BigInteger minValue)
      Sets the minimum value. The given value must be less than or equal to 0.
      Parameters:
      minValue - the value
    • setMaxValue

      protected void setMaxValue(BigInteger maxValue)
      Sets the maximum value. The given value must be greater than 0.
      Parameters:
      maxValue - the value
    • isInBounds

      protected boolean isInBounds(BigInteger value)