Java Code Examples for javafx.beans.property.ReadOnlyBooleanProperty#addListener()

The following examples show how to use javafx.beans.property.ReadOnlyBooleanProperty#addListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SettingsController.java    From VocabHunter with Apache License 2.0 5 votes vote down vote up
private void initialiseField(final TextField field, final Supplier<Object> settingGetter) {
    StringProperty textProperty = field.textProperty();
    ReadOnlyBooleanProperty focusedProperty = field.focusedProperty();

    field.setText(settingGetter.get().toString());
    textProperty.addListener((o, oldValue, newValue) -> cleanNonNegativeInteger(field::setText, newValue, oldValue));
    focusedProperty.addListener((o, old, isFocused) -> applyDefaultIfEmpty(field::setText, field::getText, settingGetter));
}
 
Example 2
Source File: DynamicIconSupport.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@FxThread
private static void updateListener(@NotNull final Node node, @NotNull final ImageView imageView,
                                   @NotNull final ReadOnlyBooleanProperty condition,
                                   @NotNull final Object listenerKey, @NotNull final Object notSelectedKey,
                                   @NotNull final Object selectedKey) {

    final EditorConfig editorConfig = EditorConfig.getInstance();
    final CssColorTheme theme = editorConfig.getEnum(PREF_UI_THEME, PREF_DEFAULT_THEME);

    if (!theme.needRepaintIcons()) {
        return;
    }

    final ObservableMap<Object, Object> properties = node.getProperties();
    final Image newImage = imageView.getImage();

    if (newImage == null) {
        properties.remove(listenerKey);
        return;
    }

    final Image original = FILE_ICON_MANAGER.getOriginal(newImage);

    properties.put(notSelectedKey, newImage);
    properties.put(selectedKey, original);

    final ChangeListener<Boolean> listener = (observable, oldValue, newValue) -> {
        if (newValue) {
            imageView.setImage((Image) properties.get(selectedKey));
        } else {
            imageView.setImage((Image) properties.get(notSelectedKey));
        }
    };

    condition.addListener(listener);

    properties.put(listenerKey, listener);

    if (condition.get()) {
        imageView.setImage(original);
    } else {
        imageView.setImage(newImage);
    }
}