Class FXStringConverter<T>
- Type Parameters:
T- The target type for the conversion.
- All Implemented Interfaces:
Serializable,StringConverter<T>
An implementation of
org.tquadrat.foundation.lang.StringConverter
(the Foundation StringConverter) that extends
javafx.util.StringConverter
(the JavaFX StringConverter). It delegates the transformation work
to the Foundation StringConverter instance that is provided
to the
constructor.
To reuse an existing JavaFX StringConverter, you can use the
method
wrap(StringConverter).
To get just a Foundation StringConverter, you can use
this code (here BigInteger is used as an example):
final var x = new BigIntegerStringConverter();
final var c = new GenericStringConverter<BigInteger>( s -> isNull( s ) ? null : x.fromString( s.toString() ), x::toString );
If you need to build a String converter from scratch that should serve
both purposes, write your own class that extends
javafx.util.StringConverter
and implements
org.tquadrat.foundation.lang.StringConverter,
and then implement the methods accordingly. Keep in mind that the method
signature for fromString() differs for both the abstract class and
the interface because of the different argument type (String vs.
CharSequence).
When a reference to an instance of
ErrorDisplay
is provided to the constructor, an error messsage is displayed when the
fromString() conversion fails.
- Note:
-
- The method
fromString()of a JavaFXStringConvertermay always returnnull, for each and every argument, but this is not allowed for an implementation of the method with the same name for a FoundationStringConverter.
- The method
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: FXStringConverter.java 1113 2024-03-12 02:01:14Z tquadrat $
- Since:
- 0.4.3
- See Also:
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.fx.util.FXStringConverter"
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Optional<ErrorDisplay> The reference to the error display.private final UnaryOperator<String> The function that composes the error messsage.private final StringThe message id.private final StringConverter<T> The FoundationStringConverterinstance.Fields inherited from interface org.tquadrat.foundation.lang.StringConverter
METHOD_NAME_GetSubjectClass, METHOD_NAME_Provider -
Constructor Summary
ConstructorsConstructorDescriptionFXStringConverter(StringConverter<T> stringConverter) Creates a new instance ofFXStringConverter.FXStringConverter(StringConverter<T> stringConverter, ErrorDisplay errorDisplay, UnaryOperator<String> messageComposer, String messageId) Creates a new instance ofFXStringConverter. -
Method Summary
Modifier and TypeMethodDescriptionfinal TfromString(CharSequence source) final TfromString(String source) final Stringstatic final <C> FXStringConverter<C> wrap(StringConverter<C> stringConverter) Creates an instance ofFXStringConverterfrom an instance ofjavafx.util.StringConverter.
-
Field Details
-
m_ErrorDisplay
The reference to the error display. -
m_MessageComposer
The function that composes the error messsage. -
m_MessageId
The message id. -
m_StringConverter
The FoundationStringConverterinstance.
-
-
Constructor Details
-
FXStringConverter
Creates a new instance ofFXStringConverter.- Parameters:
stringConverter- The FoundationStringConverterinstance that does the work.
-
FXStringConverter
public FXStringConverter(StringConverter<T> stringConverter, ErrorDisplay errorDisplay, UnaryOperator<String> messageComposer, String messageId) Creates a new instance ofFXStringConverter.- Parameters:
stringConverter- The FoundationStringConverterinstance that does the work.errorDisplay- The reference to the error display control that should display the error messages.messageComposer- The function that creates the error message to display.messageId- The message id (refer toErrorDisplay.addMessage()).
-
-
Method Details
-
fromString
- Specified by:
fromStringin classStringConverter<T>
-
fromString
- Specified by:
fromStringin interfaceStringConverter<T>
-
toString
- Specified by:
toStringin interfaceStringConverter<T>- Specified by:
toStringin classStringConverter<T>
-
wrap
Creates an instance of
FXStringConverterfrom an instance ofjavafx.util.StringConverter.Keep in mind that the implementation of the method
javafx.util.StringConverter.fromString()may returnnullfor all input arguments, but that this behaviour is not valid for an implementation of the methodorg.tquadrat.foundation.lang.StringConverter.fromString().- Type Parameters:
C- The subject class.- Parameters:
stringConverter- The instance ofStringConverter.- Returns:
- The new instance.
-
