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 initial 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 a filter or a value converter. If a value converter is not provided,
setting a value will result in an IllegalStateException and the value is always null.
Since Formatter contains a value that 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.
| Modifier and Type | Class and Description |
|---|---|
| public static class | TextFormatter.
Contains the state representing a change in the content or selection for a TextInputControl. |
| Modifier and Type | Field and Description |
|---|---|
| private final UnaryOperator | |
| public static final StringConverter | IDENTITY_STRING_CONVERTER
This string converter converts the text to the same String value. |
| private Consumer | |
| private final ObjectProperty | value
The current value for this formatter. |
| private final StringConverter |
| Access | Constructor and Description |
|---|---|
| public | TextFormatter(UnaryOperator<TextFormatter.
The filter to use in this formatter or null filterCreates a new Formatter with the provided filter. |
| public | TextFormatter(StringConverter<V>
The value converter to use in this formatter or null. valueConverter, V the default value. defaultValue, UnaryOperator<TextFormatter.The filter to use in this formatter or null filterCreates a new Formatter with the provided filter, value converter and default value. |
| public | TextFormatter(StringConverter<V>
The value converter to use in this formatter. This must not be null. valueConverter, V the default value defaultValue)Creates a new Formatter with the provided value converter and default value. |
| public | TextFormatter(StringConverter<V>
The value converter to use in this formatter. This must not be null. valueConverter)Creates a new Formatter with the provided value converter. |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| public final UnaryOperator | Returns: the filter for this formatter or null if there is noneFilter allows user to intercept and modify any change done to the text content. |
| public final V | |
| public final StringConverter | Returns: StringConverter for values or null if none providedThe converter between the values and text. |
| public final void | |
| pack-priv void | |
| private void | |
| pack-priv void | |
| public final ObjectProperty |
| filter | back to summary |
|---|---|
| private final UnaryOperator<TextFormatter. | |
| IDENTITY_STRING_CONVERTER | back to summary |
|---|---|
| public static final StringConverter<String> IDENTITY_STRING_CONVERTER This string converter converts the text to the same String value. This might be useful for cases where you want to manipulate with the text through the value or you need to provide a default text value. | |
| textUpdater | back to summary |
|---|---|
| private Consumer<TextFormatter<?>> textUpdater | |
| value | back to summary |
|---|---|
| private final ObjectProperty<V> value The current value for this formatter. When the formatter is set on a | |
| valueConverter | back to summary |
|---|---|
| private final StringConverter<V> valueConverter | |
| TextFormatter | back to summary |
|---|---|
| public TextFormatter(UnaryOperator<TextFormatter. Creates a new Formatter with the provided filter.
| |
| TextFormatter | back to summary |
|---|---|
| public TextFormatter(StringConverter<V> valueConverter, V defaultValue, UnaryOperator<TextFormatter. Creates a new Formatter with the provided filter, value converter and default value.
| |
| TextFormatter | back to summary |
|---|---|
| public TextFormatter(StringConverter<V> valueConverter, V defaultValue) Creates a new Formatter with the provided value converter and default value.
| |
| TextFormatter | back to summary |
|---|---|
| public TextFormatter(StringConverter<V> valueConverter) Creates a new Formatter with the provided value converter. The default value will be null.
| |
| bindToControl | back to summary |
|---|---|
| pack-priv void bindToControl(Consumer<TextFormatter<?>> updater) | |
| getFilter | back to summary |
|---|---|
| public final UnaryOperator Filter allows user to intercept and modify any change done to the text content.
The filter itself is an
| |
| getValue | back to summary |
|---|---|
| public final V getValue() | |
| getValueConverter | back to summary |
|---|---|
| public final StringConverter The converter between the values and text.
It maintains a "binding" between the
| |
| setValue | back to summary |
|---|---|
| public final void setValue(V value) | |
| unbindFromControl | back to summary |
|---|---|
| pack-priv void unbindFromControl() | |
| updateText | back to summary |
|---|---|
| private void updateText() | |
| updateValue | back to summary |
|---|---|
| pack-priv void updateValue(String text) | |
| valueProperty | back to summary |
|---|---|
| public final ObjectProperty | |
formatter on the TextInputControl whenever the text
for the TextInputControl is modified.
This class contains state and convenience methods for determining what change occurred on the control. It also has a reference to the TextInputControl itself so that the developer may query any other state on the control. Note that you should never modify the state of the control directly from within the formatter handler.
The Change of the text is described by range (getRangeStart(), getRangeEnd()) and
text (getText(). There are 3 cases that can occur:
text is empty and range denotes the range of deleted text.
E.g. In text "Lorem ipsum dolor sit amet", removal of the second word would result in range being (6,11) and
an empty text. Similarly, if you want to delete some different or additional text, just set the range.
If you want to remove first word instead of the second, just call setRange(0,5)range is empty (means nothing was deleted), but it's value is still important.
Both the start and end of the range point to the index where the new text was added. E.g. adding "ipsum " to "Lorem dolor sit amet"
would result in a change with range of (6,6) and text containing the String "ipsum ".text and range are not empty. The text in range is deleted
and replaced by text in the Change. The new text is added instead of the old text, which is at the beginning of the range.
E.g. when some text is being deleted, you can simply replace it by some placeholder text just by setting a new text
(setText("new text"))The Change is mutable, but not observable. It should be used only for the life of a single change. It is intended that the Change will be modified from within the formatter.
| Modifier and Type | Field and Description |
|---|---|
| private final FormatterAccessor | |
| pack-priv int | |
| pack-priv int | |
| private Control | |
| pack-priv int | |
| pack-priv int | |
| pack-priv String |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv | |
| pack-priv | Change(Control control, FormatterAccessor accessor, int start, int end, String text, int anchor, int caret)
|
| Modifier and Type | Method and Description |
|---|---|
| public TextFormatter. | |
| public final int | |
| public final int | |
| public final Control | Returns: The control associated with this change. This will never be null.Gets the control associated with this change. |
| public final int | |
| public final int | Returns: The previous caret positionGets the current caret position of the control. |
| public final String | Returns: The controls proposed new text at the time of this call, according to the state set for start, end, and text properties on this Change object.Gets the complete new text which will be used on the control after this change. |
| public final String | Returns: the previous text of controlThis is the full text that control has before the change. |
| public final int | Returns: The end indexGets the end index into the |
| public final int | Returns: The start indexGets the start index into the |
| public final IndexRange | |
| public final String | Returns: The text involved in this change. This will never be null.Gets the text used in this change. |
| public final boolean | Returns: true if text was being addedGets whether this change was in response to text being added. |
| public final boolean | Returns: true if the content changedThe content change is any of add, delete or replace changes. |
| public final boolean | Returns: true if text was being deletedGets whether this change was in response to text being deleted. |
| public final boolean | Returns: true if text was being replacedGets whether this change was in response to text being replaced. |
| public final void | selectRange(int
The new anchor position newAnchor, int The new caret position newCaretPosition)Sets the selection. |
| public final void | |
| public final void | |
| public final void | setRange(int
The new start value. Must be a valid start value start, int The new end value. Must be a valid end value end)A method assigning both the start and end values together, in such a way as to ensure they are valid with respect to each other. |
| public final void | |
| public String |
| accessor | back to summary |
|---|---|
| private final FormatterAccessor accessor | |
| anchor | back to summary |
|---|---|
| pack-priv int anchor | |
| caret | back to summary |
|---|---|
| pack-priv int caret | |
| control | back to summary |
|---|---|
| private Control control | |
| end | back to summary |
|---|---|
| pack-priv int end | |
| start | back to summary |
|---|---|
| pack-priv int start | |
| text | back to summary |
|---|---|
| pack-priv String text | |
| Change | back to summary |
|---|---|
| pack-priv Change(Control control, FormatterAccessor accessor, int anchor, int caret) | |
| Change | back to summary |
|---|---|
| pack-priv Change(Control control, FormatterAccessor accessor, int start, int end, String text) | |
| Change | back to summary |
|---|---|
| pack-priv Change(Control control, FormatterAccessor accessor, int start, int end, String text, int anchor, int caret) | |
| clone | back to summary |
|---|---|
| public TextFormatter. Overrides java. Doc from java. Creates and returns a copy of this object. The precise meaning
of "copy" may depend on the class of the object. The general
intent is that, for any object will be true, and that the expression:x.clone() != x will bex.clone().getClass() == x.getClass() true, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x) true, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by
| |
| getAnchor | back to summary |
|---|---|
| public final int getAnchor() Gets the new anchor. This value will always be > 0 and
<=
| |
| getCaretPosition | back to summary |
|---|---|
| public final int getCaretPosition() Gets the new caret position. This value will always be > 0 and
<=
| |
| getControl | back to summary |
|---|---|
| public final Control getControl() Gets the control associated with this change.
| |
| getControlAnchor | back to summary |
|---|---|
| public final int getControlAnchor() Gets the current anchor position of the control.
| |
| getControlCaretPosition | back to summary |
|---|---|
| public final int getControlCaretPosition() Gets the current caret position of the control.
| |
| getControlNewText | back to summary |
|---|---|
| public final String getControlNewText() Gets the complete new text which will be used on the control after this change. Note that some controls (such as TextField) may do further filtering after the change is made (such as stripping out newlines) such that you cannot assume that the newText will be exactly the same as what is finally set as the content on the control, however it is correct to assume that this is the case for the purpose of computing the new caret position and new anchor position (as those values supplied will be modified as necessary after the control has stripped any additional characters that the control might strip).
| |
| getControlText | back to summary |
|---|---|
| public final String getControlText() This is the full text that control has before the change. To get the text
after this change, use
| |
| getRangeEnd | back to summary |
|---|---|
| public final int getRangeEnd() Gets the end index into the
| |
| getRangeStart | back to summary |
|---|---|
| public final int getRangeStart() Gets the start index into the
| |
| getSelection | back to summary |
|---|---|
| public final IndexRange getSelection() Gets the selection of this change. Note that the selection range refers to
| |
| getText | back to summary |
|---|---|
| public final String getText() Gets the text used in this change. For example, this may be new text being added, or text which is replacing all the control's text within the range of start and end. Typically it is an empty string only for cases where the range is being deleted.
| |
| isAdded | back to summary |
|---|---|
| public final boolean isAdded() Gets whether this change was in response to text being added. Note that after the Change object is modified by the formatter (by one of the setters) the return value of this method is not altered. It answers as to whether this change was fired as a result of text being added, not whether text will end up being added in the end.
| |
| isContentChange | back to summary |
|---|---|
| public final boolean isContentChange() The content change is any of add, delete or replace changes. Basically it's a shortcut for
| |
| isDeleted | back to summary |
|---|---|
| public final boolean isDeleted() Gets whether this change was in response to text being deleted. Note that after the Change object is modified by the formatter (by one of the setters) the return value of this method is not altered. It answers as to whether this change was fired as a result of text being deleted, not whether text will end up being deleted in the end.
| |
| isReplaced | back to summary |
|---|---|
| public final boolean isReplaced() Gets whether this change was in response to text being replaced. Note that after the Change object is modified by the formatter (by one of the setters) the return value of this method is not altered. It answers as to whether this change was fired as a result of text being replaced, not whether text will end up being replaced in the end.
| |
| selectRange | back to summary |
|---|---|
| public final void selectRange(int newAnchor, int newCaretPosition) Sets the selection. The anchor and caret position values must be > 0 and
<=
| |
| setAnchor | back to summary |
|---|---|
| public final void setAnchor(int newAnchor) Sets the anchor. The anchor value must be > 0 and
<=
| |
| setCaretPosition | back to summary |
|---|---|
| public final void setCaretPosition(int newCaretPosition) Sets the caret position. The caret position value must be > 0 and
<=
| |
| setRange | back to summary |
|---|---|
| public final void setRange(int start, int end) A method assigning both the start and end values together, in such a way as to ensure they are valid with respect to each other. The start must be less than or equal to the end.
| |
| setText | back to summary |
|---|---|
| public final void setText(String value) Sets the text to use in this change. This is used to replace the range from start to end, if such a range exists, or to insert text at the position represented by start == end.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non-
| |