Class Formatter
java.lang.Object
edu.ntnu.stud.chaosgame.controller.utility.Formatter
This class sets formatting constraints for certain UI components.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic 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 -
Method Summary
Modifier and TypeMethodDescriptionstatic 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
isNotFloat
(String line) 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.
-
Field Details
-
floatFormatter
A formatter for text fields that only allows for floating point numbers. -
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
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.
-