Class TextFieldState

java.lang.Object
dev.boze.api.gui.util.TextFieldState

public final class TextFieldState extends Object
Text being typed: the text, a caret, a length limit and the characters the field accepts.
  • Field Details

    • PRINTABLE

      public static final IntPredicate PRINTABLE
      Any character that is not a control character.
  • Constructor Details

    • TextFieldState

      public TextFieldState(int maxLength, IntPredicate allowed)
      Parameters:
      maxLength - Most characters the field holds
      allowed - Which code points can be typed or pasted
  • Method Details

    • text

      public String text()
    • isEmpty

      public boolean isEmpty()
    • caret

      public int caret()
    • maxLength

      public int maxLength()
    • setText

      public void setText(String text)
      Replaces the text without filtering it, with the caret at the end.
    • clear

      public void clear()
    • insert

      public boolean insert(String typed)
      Inserts what the field accepts at the caret, up to its length limit.
      Returns:
      Whether anything was inserted
    • insert

      public boolean insert(int codepoint)
    • backspace

      public void backspace()
    • delete

      public void delete()
    • left

      public void left()
    • right

      public void right()
    • home

      public void home()
    • end

      public void end()
    • keyPressed

      public boolean keyPressed(GuiKeyEvent event, Supplier<String> clipboard)
      Handles the editing keys every Boze text field takes: Backspace (with Ctrl or Cmd, everything before the caret), Delete, Left, Right, Home, End and paste.
      Parameters:
      clipboard - Gives the clipboard text when pasting
      Returns:
      Whether the key was used
    • beforeCaret

      public String beforeCaret()
      Returns:
      Text before the caret
    • afterCaret

      public String afterCaret()
      Returns:
      Text after the caret