Top Description Constructors Methods
com.dlsc.gemsfx.util

public Class EnumStringConverter<T extends Enum<T>>

extends SimpleStringConverter<T extends Enum<T>>
Class Inheritance
Type Parameters
<T>
the type of the Enum to be converted.
Imports
javafx.util.Callback

A specialized StringConverter implementation for Enum types. This converter provides a default mechanism to format Enum values in a title case, replacing underscores with spaces and capitalizing the first letter of each word. If the enum value is null, it returns an empty string.

This class extends SimpleStringConverter and leverages EnumUtil to provide a default formatting for enum values. It can also accept custom callbacks for more specific conversion requirements.

Usage Example:

Default usage with title case formatting:

ComboBox<MyEnum> comboBox = new ComboBox<>();
comboBox.setConverter(new EnumStringConverter<>());

Custom callback for specific formatting:

ComboBox<MyEnum> comboBox = new ComboBox<>();
comboBox.setConverter(new EnumStringConverter<>(myEnum -> "Custom format: " + myEnum.name()));

Constructor Summary

AccessConstructor and Description
public
EnumStringConverter()

Converts an enum value to title case, replacing underscores with spaces and capitalizing the first letter of each word.

public
EnumStringConverter(Callback<T, String>
The callback to convert enum value to a String.
valueToStringCallback
)

Constructor that accepts a custom callback for converting enum values to strings.

public
EnumStringConverter(Callback<T, String>
The callback to convert non-null enum value to a String.
nonNullValueCallback
,
String
The default String value to return if the enum value is null.
nullDefaultValue
)

Constructor that accepts a custom callback for converting non-null enum values to strings and a default string to return if the enum value is null.

Method Summary

Inherited from com.dlsc.gemsfx.util.SimpleStringConverter:
fromStringtoString

Constructor Detail

EnumStringConverterback to summary
public EnumStringConverter()

Converts an enum value to title case, replacing underscores with spaces and capitalizing the first letter of each word. If the enum value is null, returns an empty string.

Example: 1. null -> ""

Example: 2. MY_ENUM_VALUE -> My Enum Value

EnumStringConverterback to summary
public EnumStringConverter(Callback<T, String> valueToStringCallback)

Constructor that accepts a custom callback for converting enum values to strings. The provided callback should handle conversion from enum value to String, including any necessary null handling.

Parameters
valueToStringCallback:Callback<T, String>

The callback to convert enum value to a String.

EnumStringConverterback to summary
public EnumStringConverter(Callback<T, String> nonNullValueCallback, String nullDefaultValue)

Constructor that accepts a custom callback for converting non-null enum values to strings and a default string to return if the enum value is null.

Parameters
nonNullValueCallback:Callback<T, String>

The callback to convert non-null enum value to a String.

nullDefaultValue:String

The default String value to return if the enum value is null.