java.lang.Object
edu.ntnu.stud.chaosgame.controller.utility.Formatter

public class Formatter extends Object
This class sets formatting constraints for certain UI components.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static UnaryOperator<javafx.scene.control.TextFormatter.Change>
    A formatter for text fields that only allows for floating point numbers.
    static UnaryOperator<javafx.scene.control.TextFormatter.Change>
    A formatter for text fields that only allows for integers.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static javafx.scene.control.TextFormatter<javafx.scene.control.TextFormatter.Change>
    Get the float formatter as a TextFormatter.
    static javafx.scene.control.TextFormatter<javafx.scene.control.TextFormatter.Change>
    Get the integer formatter as a TextFormatter.
    static boolean
    Check if a string can be converted to a float.
    static void
    limitTextFieldSize(javafx.scene.control.TextField textField, int maxLength)
    Set up a listener for a TextField to limit its maximum size.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • floatFormatter

      public static UnaryOperator<javafx.scene.control.TextFormatter.Change> floatFormatter
      A formatter for text fields that only allows for floating point numbers.
    • integerFormatter

      public static UnaryOperator<javafx.scene.control.TextFormatter.Change> integerFormatter
      A formatter for text fields that only allows for integers.
  • Constructor Details

    • Formatter

      public Formatter()
  • Method Details

    • getFloatFormatter

      public static javafx.scene.control.TextFormatter<javafx.scene.control.TextFormatter.Change> getFloatFormatter()
      Get the float formatter as a TextFormatter.
      Returns:
      the float formatter.
    • getIntFormatter

      public static javafx.scene.control.TextFormatter<javafx.scene.control.TextFormatter.Change> getIntFormatter()
      Get the integer formatter as a TextFormatter.
      Returns:
      the integer formatter.
    • limitTextFieldSize

      public static void limitTextFieldSize(javafx.scene.control.TextField textField, int maxLength)
      Set up a listener for a TextField to limit its maximum size.
      Parameters:
      textField - the TextField to set the listener on.
      maxLength - the maximum number of characters allowed in the TextField.
    • isNotFloat

      public static boolean isNotFloat(String line)
      Check if a string can be converted to a float.
      Parameters:
      line - the string to check.
      Returns:
      true if the string can be converted to a float, false otherwise.