Search in sources :

Example 26 with InvalidationListener

use of javafx.beans.InvalidationListener in project JFoenix by jfoenixadmin.

the class JFXNodeUtils method addDelayedPropertyInvalidationListener.

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;
}
Also used : EventHandler(javafx.event.EventHandler) MouseEvent(javafx.scene.input.MouseEvent) UnmodifiableListSet(com.sun.javafx.collections.UnmodifiableListSet) InvalidationListener(javafx.beans.InvalidationListener) ArrayList(java.util.ArrayList) BackgroundFill(javafx.scene.layout.BackgroundFill) Locale(java.util.Locale) BiConsumer(java.util.function.BiConsumer) Direction(com.sun.javafx.scene.traversal.Direction) KeyCode(javafx.scene.input.KeyCode) Color(javafx.scene.paint.Color) Node(javafx.scene.Node) Event(javafx.event.Event) Set(java.util.Set) KeyEvent(javafx.scene.input.KeyEvent) Background(javafx.scene.layout.Background) EventType(javafx.event.EventType) Consumer(java.util.function.Consumer) Duration(javafx.util.Duration) List(java.util.List) Region(javafx.scene.layout.Region) PauseTransition(javafx.animation.PauseTransition) Paint(javafx.scene.paint.Paint) ObservableValue(javafx.beans.value.ObservableValue) Queue(java.util.Queue) ArrayDeque(java.util.ArrayDeque) InvalidationListener(javafx.beans.InvalidationListener) PauseTransition(javafx.animation.PauseTransition)

Example 27 with InvalidationListener

use of javafx.beans.InvalidationListener in project JFoenix by jfoenixadmin.

the class PromptLinesWrapper method init.

public void init(Runnable createPromptNodeRunnable, Node... cachedNodes) {
    animatedPromptTextFill = new SimpleObjectProperty<>(promptTextFill.get());
    usePromptText = Bindings.createBooleanBinding(this::usePromptText, valueProperty, promptTextProperty, control.labelFloatProperty(), promptTextFill);
    // draw lines
    line.setManaged(false);
    line.getStyleClass().add("input-line");
    line.setBackground(new Background(new BackgroundFill(control.getUnFocusColor(), CornerRadii.EMPTY, Insets.EMPTY)));
    // focused line
    focusedLine.setManaged(false);
    focusedLine.getStyleClass().add("input-focused-line");
    focusedLine.setBackground(new Background(new BackgroundFill(control.getFocusColor(), CornerRadii.EMPTY, Insets.EMPTY)));
    focusedLine.setOpacity(0);
    focusedLine.getTransforms().add(scale);
    if (usePromptText.get()) {
        createPromptNodeRunnable.run();
    }
    usePromptText.addListener(observable -> {
        createPromptNodeRunnable.run();
        control.requestLayout();
    });
    final Supplier<WritableValue<Number>> promptTargetYSupplier = () -> promptTextSupplier.get() == null ? null : promptTextSupplier.get().translateYProperty();
    final Supplier<WritableValue<Number>> promptTargetXSupplier = () -> promptTextSupplier.get() == null ? null : promptTextSupplier.get().translateXProperty();
    focusTimer = new JFXAnimationTimer(new JFXKeyFrame(Duration.millis(1), JFXKeyValue.builder().setTarget(focusedLine.opacityProperty()).setEndValue(1).setInterpolator(Interpolator.EASE_BOTH).setAnimateCondition(() -> control.isFocused()).build()), new JFXKeyFrame(Duration.millis(160), JFXKeyValue.builder().setTarget(scale.xProperty()).setEndValue(1).setInterpolator(Interpolator.EASE_BOTH).setAnimateCondition(() -> control.isFocused()).build(), JFXKeyValue.builder().setTarget(animatedPromptTextFill).setEndValueSupplier(() -> control.getFocusColor()).setInterpolator(Interpolator.EASE_BOTH).setAnimateCondition(() -> control.isFocused() && control.isLabelFloat()).build(), JFXKeyValue.builder().setTargetSupplier(promptTargetXSupplier).setEndValueSupplier(() -> clip.getX()).setAnimateCondition(() -> control.isLabelFloat()).setInterpolator(Interpolator.EASE_BOTH).build(), JFXKeyValue.builder().setTargetSupplier(promptTargetYSupplier).setEndValueSupplier(() -> -contentHeight).setAnimateCondition(() -> control.isLabelFloat()).setInterpolator(Interpolator.EASE_BOTH).build(), JFXKeyValue.builder().setTarget(promptTextScale.xProperty()).setEndValue(0.85).setAnimateCondition(() -> control.isLabelFloat()).setInterpolator(Interpolator.EASE_BOTH).build(), JFXKeyValue.builder().setTarget(promptTextScale.yProperty()).setEndValue(0.85).setAnimateCondition(() -> control.isLabelFloat()).setInterpolator(Interpolator.EASE_BOTH).build()));
    unfocusTimer = new JFXAnimationTimer(new JFXKeyFrame(Duration.millis(160), JFXKeyValue.builder().setTargetSupplier(promptTargetXSupplier).setEndValue(0).setInterpolator(Interpolator.EASE_BOTH).build(), JFXKeyValue.builder().setTargetSupplier(promptTargetYSupplier).setEndValue(0).setInterpolator(Interpolator.EASE_BOTH).build(), JFXKeyValue.builder().setTarget(promptTextScale.xProperty()).setEndValue(1).setInterpolator(Interpolator.EASE_BOTH).build(), JFXKeyValue.builder().setTarget(promptTextScale.yProperty()).setEndValue(1).setInterpolator(Interpolator.EASE_BOTH).build()));
    promptContainer.getStyleClass().add("prompt-container");
    promptContainer.setManaged(false);
    promptContainer.setMouseTransparent(true);
    // clip prompt container
    clip.setSmooth(false);
    clip.setX(0);
    if (control instanceof JFXTextField) {
        final InvalidationListener leadingListener = obs -> {
            final Node leading = ((JFXTextField) control).getLeadingGraphic();
            if (leading == null) {
                clip.xProperty().unbind();
                clip.setX(0);
            } else {
                clip.xProperty().bind(((Region) leading).widthProperty().negate());
            }
        };
        ((JFXTextField) control).leadingGraphicProperty().addListener(leadingListener);
        leadingListener.invalidated(null);
    }
    clip.widthProperty().bind(promptContainer.widthProperty().add(clip.xProperty().negate()));
    promptContainer.setClip(clip);
    focusTimer.setOnFinished(() -> animating = false);
    unfocusTimer.setOnFinished(() -> animating = false);
    focusTimer.setCacheNodes(cachedNodes);
    unfocusTimer.setCacheNodes(cachedNodes);
    // handle animation on focus gained/lost event
    control.focusedProperty().addListener(observable -> {
        if (control.isFocused()) {
            focus();
        } else {
            unFocus();
        }
    });
    promptTextFill.addListener(observable -> {
        if (!control.isLabelFloat() || !control.isFocused()) {
            animatedPromptTextFill.set(promptTextFill.get());
        }
    });
    updateDisabled();
}
Also used : BooleanBinding(javafx.beans.binding.BooleanBinding) Control(javafx.scene.control.Control) StackPane(javafx.scene.layout.StackPane) Bindings(javafx.beans.binding.Bindings) Supplier(java.util.function.Supplier) JFXKeyFrame(com.jfoenix.transitions.JFXKeyFrame) InvalidationListener(javafx.beans.InvalidationListener) JFXKeyValue(com.jfoenix.transitions.JFXKeyValue) Insets(javafx.geometry.Insets) ComboBox(javafx.scene.control.ComboBox) BorderWidths(javafx.scene.layout.BorderWidths) BackgroundFill(javafx.scene.layout.BackgroundFill) Color(javafx.scene.paint.Color) ObjectProperty(javafx.beans.property.ObjectProperty) Node(javafx.scene.Node) Border(javafx.scene.layout.Border) Rectangle(javafx.scene.shape.Rectangle) JFXAnimationTimer(com.jfoenix.transitions.JFXAnimationTimer) Background(javafx.scene.layout.Background) BorderStrokeStyle(javafx.scene.layout.BorderStrokeStyle) BorderStroke(javafx.scene.layout.BorderStroke) Text(javafx.scene.text.Text) Duration(javafx.util.Duration) Region(javafx.scene.layout.Region) Interpolator(javafx.animation.Interpolator) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Paint(javafx.scene.paint.Paint) IFXLabelFloatControl(com.jfoenix.controls.base.IFXLabelFloatControl) Scale(javafx.scene.transform.Scale) ObservableValue(javafx.beans.value.ObservableValue) WritableValue(javafx.beans.value.WritableValue) JFXTextField(com.jfoenix.controls.JFXTextField) CornerRadii(javafx.scene.layout.CornerRadii) JFXAnimationTimer(com.jfoenix.transitions.JFXAnimationTimer) Background(javafx.scene.layout.Background) JFXKeyFrame(com.jfoenix.transitions.JFXKeyFrame) BackgroundFill(javafx.scene.layout.BackgroundFill) JFXTextField(com.jfoenix.controls.JFXTextField) Node(javafx.scene.Node) InvalidationListener(javafx.beans.InvalidationListener) WritableValue(javafx.beans.value.WritableValue)

Aggregations

InvalidationListener (javafx.beans.InvalidationListener)27 Button (javafx.scene.control.Button)14 Label (javafx.scene.control.Label)13 Node (javafx.scene.Node)12 FXCollections (javafx.collections.FXCollections)11 List (java.util.List)10 ObservableList (javafx.collections.ObservableList)10 Insets (javafx.geometry.Insets)8 Level (java.util.logging.Level)7 Image (javafx.scene.image.Image)7 ImageView (javafx.scene.image.ImageView)7 HBox (javafx.scene.layout.HBox)7 VBox (javafx.scene.layout.VBox)7 ButtonType (javafx.scene.control.ButtonType)6 Dialog (javafx.scene.control.Dialog)6 Priority (javafx.scene.layout.Priority)6 StackPane (javafx.scene.layout.StackPane)6 Widget (org.csstudio.display.builder.model.Widget)6 Collections (java.util.Collections)5 Consumer (java.util.function.Consumer)5