Java Code Examples for javafx.beans.value.ObservableValue#removeListener()
The following examples show how to use
javafx.beans.value.ObservableValue#removeListener() .
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: AbstractGesture.java From gef with Eclipse Public License 2.0 | 6 votes |
/** * This method is called when the attached {@link IDomain} is reset to * <code>null</code> so that you can unregister previously registered event * listeners. */ protected void doDeactivate() { // remove scene change listeners for (Entry<ObservableValue<Scene>, ChangeListener<? super Scene>> entry : sceneChangeListeners .entrySet()) { ObservableValue<Scene> sceneProperty = entry.getKey(); sceneProperty.removeListener(entry.getValue()); } sceneChangeListeners.clear(); // remove viewer focus change listeners for (final IViewer viewer : new ArrayList<>( viewerFocusChangeListeners.keySet())) { viewer.viewerFocusedProperty() .removeListener(viewerFocusChangeListeners.remove(viewer)); } viewerFocusChangeListeners.clear(); // unhook scenes for (Scene scene : hookedScenes) { unhookScene(scene); } }
Example 2
Source File: AbstractNumericDolphinBinder.java From dolphin-platform with Apache License 2.0 | 6 votes |
@Override public Binding toNumeric(final ObservableValue<Number> observableValue) { if (observableValue == null) { throw new IllegalArgumentException("observableValue must not be null"); } final ChangeListener<Number> listener = (obs, oldVal, newVal) -> { if (!equals(newVal, property.get())) { property.set(getConverter().convert(newVal)); } }; observableValue.addListener(listener); if (!equals(observableValue.getValue(), property.get())) { property.set(getConverter().convert(observableValue.getValue())); } return () -> observableValue.removeListener(listener); }
Example 3
Source File: EventStreams.java From ReactFX with BSD 2-Clause "Simplified" License | 6 votes |
/** * Creates an event stream that emits the value of the given * {@code ObservableValue} immediately for every subscriber and then on * every change. */ public static <T> EventStream<T> valuesOf(ObservableValue<T> observable) { return new EventStreamBase<T>() { @Override protected Subscription observeInputs() { ChangeListener<T> listener = (obs, old, val) -> emit(val); observable.addListener(listener); return () -> observable.removeListener(listener); } @Override protected void newObserver(Consumer<? super T> subscriber) { subscriber.accept(observable.getValue()); } }; }
Example 4
Source File: PropertyTracker.java From scenic-view with GNU General Public License v3.0 | 5 votes |
public void clear() { for (final ObservableValue ov : properties.keySet()) { if (ov != null && propListener != null) { ov.removeListener(propListener); } } properties.clear(); }
Example 5
Source File: FontIconTableCell.java From ikonli with Apache License 2.0 | 5 votes |
@Override public void updateItem(T item, boolean empty) { super.updateItem(item, empty); if (empty) { setGraphic(null); } else { if (subscription != null) { subscription.unsubscribe(); subscription = null; } final TableColumn<S, T> column = getTableColumn(); ObservableValue<T> observable = column == null ? null : column.getCellObservableValue(getIndex()); if (observable != null) { ChangeListener<T> listener = (v, o, n) -> setIconCode(n); observable.addListener(listener); subscription = () -> observable.removeListener(listener); setIconCode(observable.getValue()); } else if (item != null) { setIconCode(item); } setGraphic(icon); setAlignment(Pos.CENTER); } }
Example 6
Source File: DefaultDolphinBinder.java From dolphin-platform with Apache License 2.0 | 5 votes |
@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); }
Example 7
Source File: EventStreams.java From ReactFX with BSD 2-Clause "Simplified" License | 5 votes |
public static <T> EventStream<Change<T>> changesOf(ObservableValue<T> observable) { return new EventStreamBase<Change<T>>() { @Override protected Subscription observeInputs() { ChangeListener<T> listener = (obs, old, val) -> emit(new Change<>(old, val)); observable.addListener(listener); return () -> observable.removeListener(listener); } }; }
Example 8
Source File: Val.java From ReactFX with BSD 2-Clause "Simplified" License | 5 votes |
static <T> Subscription observeChanges( ObservableValue<? extends T> obs, ChangeListener<? super T> listener) { if(obs instanceof Val) { return ((Val<? extends T>) obs).observeChanges(listener); } else { obs.addListener(listener); return () -> obs.removeListener(listener); } }
Example 9
Source File: AnimatedValTest.java From ReactFX with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void changed(ObservableValue<? extends T> observable, T oldValue, T newValue) { if(pred.test(newValue)) { observable.removeListener(this); toComplete.complete(null); } }
Example 10
Source File: DesktopPane.java From desktoppanefx with Apache License 2.0 | 4 votes |
@Override public void changed(ObservableValue<? extends Bounds> observable, Bounds oldValue, Bounds newValue) { desktopPane.centerInternalWindow(this.window); observable.removeListener(this); }
Example 11
Source File: Val.java From ReactFX with BSD 2-Clause "Simplified" License | 4 votes |
static Subscription observeInvalidations( ObservableValue<?> obs, InvalidationListener listener) { obs.addListener(listener); return () -> obs.removeListener(listener); }
Example 12
Source File: EasyBind.java From EasyBind with BSD 2-Clause "Simplified" License | 3 votes |
/** * Invokes {@code subscriber} for the current and every new value of * {@code observable}. * @param observable observable value to subscribe to * @param subscriber action to invoke for values of {@code observable}. * @return a subscription that can be used to stop invoking subscriber * for any further {@code observable} changes. */ public static <T> Subscription subscribe(ObservableValue<T> observable, Consumer<? super T> subscriber) { subscriber.accept(observable.getValue()); ChangeListener<? super T> listener = (obs, oldValue, newValue) -> subscriber.accept(newValue); observable.addListener(listener); return () -> observable.removeListener(listener); }