private boolean usePromptText() { Object txt = valueProperty.getValue(); txt = validateComboBox(txt); String promptTxt = promptTextProperty.getValue(); boolean isLabelFloat = control.isLabelFloat(); return isLabelFloat || (promptTxt != null && (txt == null || txt.toString().isEmpty()) && !promptTxt.isEmpty() && !promptTextFill.get().equals(Color.TRANSPARENT)); }
public static <T> InvalidationListener addDelayedPropertyInvalidationListener(ObservableValue<T> property, Duration delayTime, Consumer<T> consumer) { Wrapper<T> eventWrapper = new Wrapper<>(); PauseTransition holdTimer = new PauseTransition(delayTime); holdTimer.setOnFinished(event -> consumer.accept(eventWrapper.content)); final InvalidationListener invalidationListener = observable -> { eventWrapper.content = property.getValue(); holdTimer.playFromStart(); }; property.addListener(invalidationListener); return invalidationListener; }
private <T> void registerListener(ObservableValue<T> value, ChangeListener<Object> listener) { ChangeListener<Object> previous = registeredListeners.put(value, listener); if (previous != null) { value.removeListener(previous); } value.addListener(listener); }
public static <T> Observable<T> fromObservableValue(final ObservableValue<T> fxObservable) { return Observable.create((ObservableEmitter<T> emitter) -> { if (fxObservable.getValue() != null) emitter.onNext(fxObservable.getValue()); final ChangeListener<T> listener = (observableValue, prev, current) -> { if (current != null) emitter.onNext(current); }; fxObservable.addListener(listener); emitter.setDisposable(JavaFxSubscriptions.unsubscribeInEventDispatchThread(() -> fxObservable.removeListener(listener))); }); }
/** * Attaches a ChangeListener to the ObservableValue, and also stores their relationship. * <p> * Knowledge of their relationship is used when this PropertyEditor.Item is * removed from the PropertySheet, to detach the listeners again. This will avoid * memory leaks, as listeners otherwise prevent the observable from being garbage * collected. * * @param <T> type of the ObservableValue and the ChangeListener * @param observable the ObservableValue * @param listener the ChangeListener */ protected final <T> void attachListener(ObservableValue<T> observable, ChangeListener<T> listener) { @SuppressWarnings("unchecked") final ObservableValue<Object> key = (ObservableValue<Object>) observable; @SuppressWarnings("unchecked") final ChangeListener<Object> value = (ChangeListener<Object>) listener; listeners.put(key, value); observable.addListener(listener); } }
public P beforeChange(T oldSource) { P oldValue = targetObservableValue != null ? targetObservableValue.getValue() : null; if (targetObservableValue != null) { targetObservableValue.removeListener(targetChangeListener); targetObservableValue.removeListener(targetInvalidationListener); } return oldValue; }
public void shutdown() { registeredListeners.entrySet().stream() .filter(e -> e.getKey() != null) .forEach(e -> e.getKey().removeListener(e.getValue())); }
public static <T> Observable<T> fromObservableValue(final ObservableValue<T> fxObservable) { return Observable.create((ObservableEmitter<T> emitter) -> { if (fxObservable.getValue() != null) emitter.onNext(fxObservable.getValue()); final ChangeListener<T> listener = (observableValue, prev, current) -> { if (current != null) emitter.onNext(current); }; fxObservable.addListener(listener); emitter.setDisposable(JavaFxSubscriptions.unsubscribeInEventDispatchThread(() -> fxObservable.removeListener(listener))); }); }
public FlatMapBindingBase(ObservableValue<T> src, Function<? super T, O> f) { this.src = src; this.mapper = f; src.addListener(weakSrcListener); }
private void removeBackingItem(T item, ObservableValue<R> cellValue) { if (cellValue == null) { return; } removeValue(cellValue.getValue()); //remove listener from cell ChangeListener<R> listener = trackedCells.get(new CellIdentity<>(item)); cellValue.removeListener(listener); trackedCells.remove(new CellIdentity<>(item)); } private void removeValue(R value) {
@Override public void dispose() { for(int i = 0; i < chain.length; ++i) { chain[i].removeListener(weakListener); } }
private void updateLabelFloat(boolean animation) { if (control.isLabelFloat()) { if (control.isFocused()) { animateFloatingLabel(true, animation); } else { Object text = valueProperty.getValue(); text = validateComboBox(text); animateFloatingLabel(!(text == null || text.toString().isEmpty()), animation); } } }
public static <T> InvalidationListener addDelayedPropertyInvalidationListener(ObservableValue<T> property, Duration delayTime, Consumer<T> justInTimeConsumer, Consumer<T> delayedConsumer) { Wrapper<T> eventWrapper = new Wrapper<>(); PauseTransition holdTimer = new PauseTransition(delayTime); holdTimer.setOnFinished(event -> delayedConsumer.accept(eventWrapper.content)); final InvalidationListener invalidationListener = observable -> { eventWrapper.content = property.getValue(); justInTimeConsumer.accept(eventWrapper.content); holdTimer.playFromStart(); }; property.addListener(invalidationListener); return invalidationListener; }
@Override public <T> Binding to(final ObservableValue<T> observableValue, final Converter<? super T, ? extends S> converter) { if (observableValue == null) { throw new IllegalArgumentException("observableValue must not be null"); } if (converter == null) { throw new IllegalArgumentException("converter must not be null"); } final ChangeListener<T> listener = (obs, oldVal, newVal) -> property.set(converter.convert(newVal)); observableValue.addListener(listener); property.set(converter.convert(observableValue.getValue())); return () -> observableValue.removeListener(listener); }
protected Subscription observeTargetObservable(O target) { target.addListener(weakMappedListener); return () -> target.removeListener(weakMappedListener); }
@Override public void addListener(ChangeListener<? super T> listener) { delegate.addListener(listener); }
@Override public void dispose() { root.removeListener(rootInvalidationListener); nestedSelection.disconnect(); } }
private void unFocus() { focusTimer.stop(); scale.setX(initScale); focusedLine.setOpacity(0); if (control.isLabelFloat()) { animatedPromptTextFill.set(promptTextFill.get()); Object text = valueProperty.getValue(); text = validateComboBox(text); if (text == null || text.toString().isEmpty()) { animating = true; runTimer(unfocusTimer, true); } } }
public ConditionalSubscription( ObservableValue<Boolean> condition, Supplier<? extends Subscription> bindFn) { this.condition = condition; this.bindFn = bindFn; condition.addListener(conditionListener); if(condition.getValue()) { subscription = bindFn.get(); } }
@Override public <T> Binding to(final ObservableValue<T> observableValue, final Converter<? super T, ? extends S> converter) { if (observableValue == null) { throw new IllegalArgumentException("observableValue must not be null"); } if (converter == null) { throw new IllegalArgumentException("converter must not be null"); } final ChangeListener<T> listener = (obs, oldVal, newVal) -> property.set(converter.convert(newVal)); observableValue.addListener(listener); property.set(converter.convert(observableValue.getValue())); return () -> observableValue.removeListener(listener); }