/** Like rewireInit, with no initialisation. */ public static <T> void rewire(Property<T> underlying, ObservableValue<? extends T> source) { underlying.unbind(); underlying.bind(source); // Bindings are garbage collected after the popup dies }
@Override public void bind(ObservableValue<? extends Number> observable) { wrapped.bind(observable); }
@Override public void bind(ObservableValue<? extends T> observable) { delegate.bind(observable); }
@Override public void bind(ObservableValue<? extends U> other) { Property<U> target = getTargetObservable(); if(target != null) { target.bind(other); } boundTo = other; resetOnUnbind = false; resetTo = null; }
@Override public void bind(ObservableValue<? extends U> other, U resetToOnUnbind) { Property<U> target = getTargetObservable(); if(target != null) { target.bind(other); } boundTo = other; resetOnUnbind = true; resetTo = resetToOnUnbind; }
@Override public void bind(ObservableValue<? extends Double> observable) { getDelegate().bind(observable); }
@Override public void bind(ObservableValue<? extends String> observable) { getDelegate().bind(observable); }
@Override public void bind(ObservableValue<? extends Integer> observable) { getDelegate().bind(observable); }
@Override public void bind(ObservableValue<? extends Long> observable) { getDelegate().bind(observable); }
@Override public void bind(ObservableValue<? extends Float> observable) { getDelegate().bind(observable); }
@Override public void bind(ObservableValue<? extends Boolean> observable) { getDelegate().bind(observable); }
@Override public void changed(ObservableValue<? extends Boolean> cond, Boolean wasTrue, Boolean isTrue) { Property<T> tgt = this.target.get(); if(tgt == null) { condition.removeListener((ChangeListener<Boolean>) this); } else if(isTrue) { tgt.bind(source); } else { tgt.unbind(); } }
/** * Sets up automatic binding and unbinding of {@code target} to/from * {@code source}, based on the changing value of the encapsulated * condition. In other words, whenever the encapsulated condition is * {@code true}, {@code target} is bound to {@code source}. Whenever the * encapsulated condition is {@code false}, {@code target} is unbound. * This keeps happening until {@code unsubscribe()} is called on the * returned subscription. Unsubscribing the returned subscription may be * skipped safely only when the lifetimes of all the encapsulated condition, * {@code source} and {@code target} are the same. * @param target target of the conditional binding * @param source source of the conditional binding * @return a subscription that can be used to dispose the conditional * binding set up by this method, i.e. to stop observing the encapsulated * condition and, if the last observed value of the encapsulated condition * was {@code true}, unbind {@code target} from {@code source}. */ public <T> Subscription bind( Property<T> target, ObservableValue<? extends T> source) { return bind(() -> { target.bind(source); return target::unbind; }); }
public ConditionalBinding( Property<T> target, ObservableValue<? extends T> source, ObservableValue<Boolean> condition) { this.target = new WeakReference<>(target); this.source = source; this.condition = condition; // add an empty listener to target just to maintain a strong reference // to this object for the lifetime of target target.addListener(this); condition.addListener((ChangeListener<Boolean>) this); if(condition.getValue()) { target.bind(source); } }
@Override protected Subscription observeTargetObservable(Property<U> mapped) { if(boundTo != null) { mapped.bind(boundTo); } Subscription s1 = super.observeTargetObservable(mapped); Subscription s2 = () -> { if(boundTo != null) { mapped.unbind(); if(resetOnUnbind) { mapped.setValue(resetTo); } } }; return s1.and(s2); }
private void setUpInteractionButtons() { interactionBox.visibleProperty().bind(embeddedProperty.not()); interactionBox.managedProperty().bind(embeddedProperty.not()); easyFxml.loadNode(TWEET_INTERACTION_BOX, Pane.class, TweetInteractionPaneController.class) .afterControllerLoaded(tipc -> tipc.targetStatusProperty().bind(currentStatus)) .getNode() .recover(ExceptionHandler::fromThrowable) .onSuccess(interactionBox::setCenter); }
box.highlightTextFillProperty().bind(highlightTextFill); box.wrapTextProperty().bind(wrapTextProperty()); box.graphicFactoryProperty().bind(paragraphGraphicFactoryProperty());