V
- The type of the valuepublic class TextFormatter<V>
extends java.lang.Object
TextInputControl
text by using two distinct mechanisms:
getFilter()
) that can intercept and modify user input. This helps to keep the text
in the desired format. A default text supplier can be used to provide the intial text.getValueConverter()
) and value (valueProperty()
)
can be used to provide special format that represents a value of type V
.
If the control is editable and the text is changed by the user, the value is then updated to correspond to the text.
It's possible to have a formatter with just filter or value converter. If value converter is not provided however, setting a value will
result in an IllegalStateException
and the value is always null.
Since Formatter
contains a value which represents the state of the TextInputControl
to which it is currently assigned, a single
Formatter
instance can be used only in one TextInputControl
at a time.
Type | Property and Description |
---|---|
<any> |
value
The current value for this formatter.
|
Modifier and Type | Class and Description |
---|---|
static class |
TextFormatter.Change
Contains the state representing a change in the content or selection for a
TextInputControl.
|
Modifier and Type | Field and Description |
---|---|
private java.util.function.UnaryOperator<TextFormatter.Change> |
filter |
static <any> |
IDENTITY_STRING_CONVERTER
This string converter converts the text to the same String value.
|
private java.util.function.Consumer<TextFormatter<?>> |
textUpdater |
private <any> |
value
The current value for this formatter.
|
private <any> |
valueConverter |
Constructor and Description |
---|
TextFormatter(<any> valueConverter)
Creates a new Formatter with the provided value converter.
|
TextFormatter(<any> valueConverter,
V defaultValue)
Creates a new Formatter with the provided value converter and default value.
|
TextFormatter(<any> valueConverter,
V defaultValue,
java.util.function.UnaryOperator<TextFormatter.Change> filter)
Creates a new Formatter with the provided filter, value converter and default value.
|
TextFormatter(java.util.function.UnaryOperator<TextFormatter.Change> filter)
Creates a new Formatter with the provided filter.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
bindToControl(java.util.function.Consumer<TextFormatter<?>> updater) |
java.util.function.UnaryOperator<TextFormatter.Change> |
getFilter()
Filter allows user to intercept and modify any change done to the text content.
|
V |
getValue()
Gets the value of the property value.
|
<any> |
getValueConverter()
The converter between the values and text.
|
void |
setValue(V value)
Sets the value of the property value.
|
(package private) void |
unbindFromControl() |
private void |
updateText() |
(package private) void |
updateValue(java.lang.String text) |
<any> |
valueProperty()
The current value for this formatter.
|
public final <any> valueProperty
TextInputControl
and has a
valueConverter
, the value is set by the control, when the text is commited.getValue()
,
setValue(V)
private final <any> valueConverter
private final java.util.function.UnaryOperator<TextFormatter.Change> filter
private java.util.function.Consumer<TextFormatter<?>> textUpdater
public static final <any> IDENTITY_STRING_CONVERTER
private final <any> value
TextInputControl
and has a
valueConverter
, the value is set by the control, when the text is commited.public TextFormatter(java.util.function.UnaryOperator<TextFormatter.Change> filter)
filter
- The filter to use in this formatter or nullpublic TextFormatter(<any> valueConverter, V defaultValue, java.util.function.UnaryOperator<TextFormatter.Change> filter)
valueConverter
- The value converter to use in this formatter or null.defaultValue
- the default value.filter
- The filter to use in this formatter or nullpublic TextFormatter(<any> valueConverter, V defaultValue)
valueConverter
- The value converter to use in this formatter. This must not be null.defaultValue
- the default valuepublic TextFormatter(<any> valueConverter)
valueConverter
- The value converter to use in this formatter. This must not be null.public final <any> getValueConverter()
TextInputControl.textProperty()
}
and valueProperty()
}. The value is updated when the control loses it's focus or it is commited (TextField only).
Setting the value will update the text of the control, usin the provided converter.
If it's impossible to convert text to value, an exception should be thrown.TextInputControl.commitValue()
,
TextInputControl.cancelEdit()
public final java.util.function.UnaryOperator<TextFormatter.Change> getFilter()
The filter itself is an UnaryOperator
that accepts TextFormatter.Change
object.
It should return a TextFormatter.Change
object that contains the actual (filtered)
change. Returning null rejects the change.
public final <any> valueProperty()
TextInputControl
and has a
valueConverter
, the value is set by the control, when the text is commited.getValue()
,
setValue(V)
public final void setValue(V value)
public final V getValue()
private void updateText()
void bindToControl(java.util.function.Consumer<TextFormatter<?>> updater)
void unbindFromControl()
void updateValue(java.lang.String text)