Class Input<T,S extends Input<T,S>>

java.lang.Object
org.strassburger.tui4j.input.Input<T,S>
Type Parameters:
T - the type of the input value
S - the type of the input subclass
Direct Known Subclasses:
BooleanInput, ContinueInput, DateInput, DoubleInput, IntegerInput, MultilineTextInput, NumberInput, SelectInput, TextInput

public abstract class Input<T,S extends Input<T,S>> extends Object
Abstract class for input
  • Constructor Details

    • Input

      public Input()
      Constructor with default scanner and printer
  • Method Details

    • read

      public abstract T read() throws InputValidationException
      Read the input value
      Returns:
      the input value
      Throws:
      InputValidationException - if the input is invalid and retryOnInvalid is false
    • setLabel

      public S setLabel(String label)
      Set the label for the input
      Parameters:
      label - the label to set
      Returns:
      the input object
    • setLabel

      public S setLabel(StyledText label)
      Set the label for the input
      Parameters:
      label - the label to set
      Returns:
      the input object
    • setRetryOnInvalid

      public S setRetryOnInvalid(boolean retryOnInvalid)
      Set whether to retry on invalid input
      Parameters:
      retryOnInvalid - whether to retry on invalid input
      Returns:
      the input object
    • setErrorMessage

      public S setErrorMessage(String errorMessage)
      Set the error message for invalid input
      Parameters:
      errorMessage - the error message to set (as plain text)
      Returns:
      the input object
    • setErrorMessage

      public S setErrorMessage(StyledText errorMessage)
      Set the error message for invalid input
      Parameters:
      errorMessage - the error message to set
      Returns:
      the input object
    • addValidationRule

      public S addValidationRule(ValidationRule<T> rule)
      Add a validation rule to the input
      Parameters:
      rule - the validation rule to add
      Returns:
      the input object
    • addValidationRules

      public S addValidationRules(List<ValidationRule<T>> rules)
      Add validation rules to the input
      Parameters:
      rules - the validation rules to add
      Returns:
      the input object
    • setPrinter

      public S setPrinter(Printer printer)
    • setScanner

      public S setScanner(Scanner scanner)
    • setCursor

      public S setCursor(StyledText cursor)
    • getCursor

      public StyledText getCursor()
    • validate

      protected void validate(T value) throws InputValidationException
      Validate the input value
      Parameters:
      value - the input value to validate
      Throws:
      InputValidationException - if the input is invalid
    • getLabel

      public StyledText getLabel()
    • isRetryOnInvalid

      public boolean isRetryOnInvalid()
    • getErrorMessage

      public StyledText getErrorMessage()
    • getScanner

      protected Scanner getScanner()
    • getPrinter

      protected Printer getPrinter()