Helper class to create a custom editor for a type T. The example "how to do" will be found for the Font Editor
in the class
Editors#createFontEditor(org.controlsfx.control.PropertySheet.Item).
See also {@link DefaultPropertyEditorFactory how to integrate a custom type editor in the PropertySheet.
public static final PropertyEditor<?> createFontEditor( Item property ) {
return new AbstractPropertyEditor<Font, AbstractObjectField<Font>>(property, new AbstractObjectField<Font>() {
{@literal @}Override protected Class<Font> getType() {
return Font.class;
}
{@literal @}Override protected String objectToString(Font font) {
return font == null? "": String.format("%s, %.1f", font.getName(), font.getSize()); //$NON-NLS-1$ //$NON-NLS-2$
}
{@literal @}Override protected Font edit(Font font) {
FontSelectorDialog dlg = new FontSelectorDialog(font);
Optional<Font> optionalFont = dlg.showAndWait();
return optionalFont.orElse(null);
}
}) {
{@literal @}Override protected ObservableValue<Font> getObservableValue() {
return getEditor().getObjectProperty();
}
{@literal @}Override public void setValue(Font value) {
getEditor().getObjectProperty().set(value);
}
};
}