Search in sources :

Example 11 with PauseTransition

use of javafx.animation.PauseTransition in project tilesfx by HanSolo.

the class SmoothedChart method init.

// ******************** Initialization ************************************
private void init() {
    _smoothed = true;
    _chartType = ChartType.LINE;
    _subDivisions = 16;
    _snapToTicks = false;
    _selectorFillColor = Color.WHITE;
    _selectorStrokeColor = Color.RED;
    _selectorSize = 10;
    _decimals = 2;
    _interactive = true;
    _tooltipTimeout = 2000;
    formatString = "%.2f";
    strokePaths = new ArrayList<>();
    clickHandler = e -> select(e);
    endOfTransformationHandler = e -> selectorTooltip.hide();
    seriesListener = change -> {
        while (change.next()) {
            if (change.wasAdded()) {
                change.getAddedSubList().forEach(addedItem -> {
                    final Series<X, Y> series = addedItem;
                    final Path strokePath = (Path) ((Group) series.getNode()).getChildren().get(1);
                    final Path fillPath = (Path) ((Group) series.getNode()).getChildren().get(0);
                    fillPath.addEventHandler(MouseEvent.MOUSE_PRESSED, clickHandler);
                    strokePath.addEventHandler(MouseEvent.MOUSE_PRESSED, clickHandler);
                    strokePaths.add(strokePath);
                    series.getData().forEach(data -> data.YValueProperty().addListener(o -> layoutPlotChildren()));
                });
            } else if (change.wasRemoved()) {
                change.getRemoved().forEach(removedItem -> {
                    final Series<X, Y> series = removedItem;
                    final Path strokePath = (Path) ((Group) series.getNode()).getChildren().get(1);
                    final Path fillPath = (Path) ((Group) series.getNode()).getChildren().get(0);
                    fillPath.removeEventHandler(MouseEvent.MOUSE_PRESSED, clickHandler);
                    strokePath.removeEventHandler(MouseEvent.MOUSE_PRESSED, clickHandler);
                    strokePaths.remove(strokePath);
                });
            }
        }
    };
    // Add selector to chart
    selector = new Circle();
    selector.setFill(_selectorFillColor);
    selector.setStroke(_selectorStrokeColor);
    selector.setOpacity(0);
    selectorTooltip = new Tooltip("");
    Tooltip.install(selector, selectorTooltip);
    FadeTransition fadeIn = new FadeTransition(Duration.millis(100), selector);
    fadeIn.setFromValue(0);
    fadeIn.setToValue(1);
    timeBeforeFadeOut = new PauseTransition(Duration.millis(_tooltipTimeout));
    FadeTransition fadeOut = new FadeTransition(Duration.millis(100), selector);
    fadeOut.setFromValue(1);
    fadeOut.setToValue(0);
    fadeInFadeOut = new SequentialTransition(fadeIn, timeBeforeFadeOut, fadeOut);
    fadeInFadeOut.setOnFinished(endOfTransformationHandler);
    chartPlotBackground = getChartPlotBackground();
    chartPlotBackground.widthProperty().addListener(o -> resizeSelector());
    chartPlotBackground.heightProperty().addListener(o -> resizeSelector());
    chartPlotBackground.layoutYProperty().addListener(o -> resizeSelector());
    Path horizontalGridLines = getHorizontalGridLines();
    if (null != horizontalGridLines) {
        horizontalGridLines.setMouseTransparent(true);
    }
    Path verticalGridLines = getVerticalGridLines();
    if (null != verticalGridLines) {
        verticalGridLines.setMouseTransparent(true);
    }
    getChartChildren().addAll(selector);
}
Also used : ClosePath(javafx.scene.shape.ClosePath) Path(javafx.scene.shape.Path) EventHandler(javafx.event.EventHandler) ClosePath(javafx.scene.shape.ClosePath) LineTo(javafx.scene.shape.LineTo) StackPane(javafx.scene.layout.StackPane) XYChart(javafx.scene.chart.XYChart) Side(javafx.geometry.Side) Line(javafx.scene.shape.Line) ListChangeListener(javafx.collections.ListChangeListener) Locale(java.util.Locale) MoveTo(javafx.scene.shape.MoveTo) Point2D(javafx.geometry.Point2D) Circle(javafx.scene.shape.Circle) Border(javafx.scene.layout.Border) PathElement(javafx.scene.shape.PathElement) Group(javafx.scene.Group) Collectors(java.util.stream.Collectors) BooleanPropertyBase(javafx.beans.property.BooleanPropertyBase) BorderStroke(javafx.scene.layout.BorderStroke) BooleanProperty(javafx.beans.property.BooleanProperty) Duration(javafx.util.Duration) List(java.util.List) Region(javafx.scene.layout.Region) PauseTransition(javafx.animation.PauseTransition) Paint(javafx.scene.paint.Paint) DoublePropertyBase(javafx.beans.property.DoublePropertyBase) AreaChart(javafx.scene.chart.AreaChart) ObservableList(javafx.collections.ObservableList) NumberAxis(javafx.scene.chart.NumberAxis) SmoothedChartEvent(eu.hansolo.tilesfx.events.SmoothedChartEvent) Bounds(javafx.geometry.Bounds) CornerRadii(javafx.scene.layout.CornerRadii) Path(javafx.scene.shape.Path) MouseEvent(javafx.scene.input.MouseEvent) DoubleProperty(javafx.beans.property.DoubleProperty) IntegerProperty(javafx.beans.property.IntegerProperty) ArrayList(java.util.ArrayList) FadeTransition(javafx.animation.FadeTransition) Insets(javafx.geometry.Insets) Helper(eu.hansolo.tilesfx.tools.Helper) BackgroundFill(javafx.scene.layout.BackgroundFill) Tooltip(javafx.scene.control.Tooltip) Color(javafx.scene.paint.Color) ObjectProperty(javafx.beans.property.ObjectProperty) Dimension2D(javafx.geometry.Dimension2D) Node(javafx.scene.Node) ObjectPropertyBase(javafx.beans.property.ObjectPropertyBase) IntegerPropertyBase(javafx.beans.property.IntegerPropertyBase) Background(javafx.scene.layout.Background) BorderStrokeStyle(javafx.scene.layout.BorderStrokeStyle) ActionEvent(javafx.event.ActionEvent) SequentialTransition(javafx.animation.SequentialTransition) Axis(javafx.scene.chart.Axis) Point(eu.hansolo.tilesfx.tools.Point) Group(javafx.scene.Group) Circle(javafx.scene.shape.Circle) FadeTransition(javafx.animation.FadeTransition) Tooltip(javafx.scene.control.Tooltip) SequentialTransition(javafx.animation.SequentialTransition) PauseTransition(javafx.animation.PauseTransition)

Example 12 with PauseTransition

use of javafx.animation.PauseTransition in project JFoenix by jfoenixadmin.

the class JFXSnackbar method close.

public void close() {
    if (openAnimation != null) {
        openAnimation.stop();
    }
    if (this.isVisible()) {
        if (pauseTransition != null) {
            pauseTransition.stop();
            pauseTransition = null;
        }
        Timeline closeAnimation = new Timeline(new KeyFrame(Duration.ZERO, e -> this.toFront(), new KeyValue(this.opacityProperty(), 1, easeInterpolator), new KeyValue(this.translateYProperty(), 0, easeInterpolator)), new KeyFrame(Duration.millis(290), new KeyValue(this.visibleProperty(), true, Interpolator.EASE_BOTH)), new KeyFrame(Duration.millis(300), e -> this.toBack(), new KeyValue(this.visibleProperty(), false, Interpolator.EASE_BOTH), new KeyValue(this.translateYProperty(), this.getLayoutBounds().getHeight(), easeInterpolator), new KeyValue(this.opacityProperty(), 0, easeInterpolator)));
        closeAnimation.setCycleCount(1);
        closeAnimation.setOnFinished(e -> {
            resetPseudoClass();
            processSnackbar();
        });
        closeAnimation.play();
    }
}
Also used : WeakChangeListener(javafx.beans.value.WeakChangeListener) KeyFrame(javafx.animation.KeyFrame) PseudoClass(javafx.css.PseudoClass) Node(javafx.scene.Node) Event(javafx.event.Event) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Timeline(javafx.animation.Timeline) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StackPane(javafx.scene.layout.StackPane) Group(javafx.scene.Group) EventType(javafx.event.EventType) Platform(javafx.application.Platform) Duration(javafx.util.Duration) Interpolator(javafx.animation.Interpolator) PauseTransition(javafx.animation.PauseTransition) KeyValue(javafx.animation.KeyValue) ChangeListener(javafx.beans.value.ChangeListener) Bounds(javafx.geometry.Bounds) Pane(javafx.scene.layout.Pane) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Timeline(javafx.animation.Timeline) KeyValue(javafx.animation.KeyValue) KeyFrame(javafx.animation.KeyFrame)

Example 13 with PauseTransition

use of javafx.animation.PauseTransition 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 14 with PauseTransition

use of javafx.animation.PauseTransition in project JFoenix by jfoenixadmin.

the class JFXNodeUtils method addPressAndHoldFilter.

public static void addPressAndHoldFilter(Node node, Duration holdTime, EventHandler<MouseEvent> handler) {
    Wrapper<MouseEvent> eventWrapper = new Wrapper<>();
    PauseTransition holdTimer = new PauseTransition(holdTime);
    holdTimer.setOnFinished(event -> handler.handle(eventWrapper.content));
    node.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> {
        eventWrapper.content = event;
        holdTimer.playFromStart();
    });
    node.addEventFilter(MouseEvent.MOUSE_RELEASED, event -> holdTimer.stop());
    node.addEventFilter(MouseEvent.DRAG_DETECTED, event -> holdTimer.stop());
}
Also used : MouseEvent(javafx.scene.input.MouseEvent) PauseTransition(javafx.animation.PauseTransition)

Example 15 with PauseTransition

use of javafx.animation.PauseTransition in project JFoenix by jfoenixadmin.

the class JFXNodeUtils method addDelayedPropertyInvalidationListener.

public static <T> InvalidationListener addDelayedPropertyInvalidationListener(ObservableValue<T> property, Duration delayTime, BiConsumer<T, InvalidationListener> consumer) {
    Wrapper<T> eventWrapper = new Wrapper<>();
    PauseTransition holdTimer = new PauseTransition(delayTime);
    final InvalidationListener invalidationListener = observable -> {
        eventWrapper.content = property.getValue();
        holdTimer.playFromStart();
    };
    holdTimer.setOnFinished(event -> consumer.accept(eventWrapper.content, invalidationListener));
    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)

Aggregations

PauseTransition (javafx.animation.PauseTransition)17 MouseEvent (javafx.scene.input.MouseEvent)7 SequentialTransition (javafx.animation.SequentialTransition)6 EventHandler (javafx.event.EventHandler)6 Duration (javafx.util.Duration)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 FadeTransition (javafx.animation.FadeTransition)5 ActionEvent (javafx.event.ActionEvent)5 Node (javafx.scene.Node)5 Color (javafx.scene.paint.Color)5 Locale (java.util.Locale)4 ParallelTransition (javafx.animation.ParallelTransition)4 Event (javafx.event.Event)4 EventType (javafx.event.EventType)4 Background (javafx.scene.layout.Background)4 BackgroundFill (javafx.scene.layout.BackgroundFill)4 Region (javafx.scene.layout.Region)4 Paint (javafx.scene.paint.Paint)4 UnmodifiableListSet (com.sun.javafx.collections.UnmodifiableListSet)3