Example usage for javafx.animation Timeline setOnFinished

List of usage examples for javafx.animation Timeline setOnFinished

Introduction

In this page you can find the example usage for javafx.animation Timeline setOnFinished.

Prototype

public final void setOnFinished(EventHandler<ActionEvent> value) 

Source Link

Usage

From source file:eu.over9000.skadi.ui.MainWindow.java

public void doDetailSlide(final boolean doOpen) {

    final KeyValue positionKeyValue = new KeyValue(this.sp.getDividers().get(0).positionProperty(),
            doOpen ? 0.15 : 1);//ww  w  . java 2 s . co  m
    final KeyValue opacityKeyValue = new KeyValue(this.detailPane.opacityProperty(), doOpen ? 1 : 0);
    final KeyFrame keyFrame = new KeyFrame(Duration.seconds(0.1), positionKeyValue, opacityKeyValue);
    final Timeline timeline = new Timeline(keyFrame);
    timeline.setOnFinished(evt -> {
        if (!doOpen) {
            MainWindow.this.sp.getItems().remove(MainWindow.this.detailPane);
            MainWindow.this.detailPane.setOpacity(1);
        }
    });
    timeline.play();
}

From source file:io.bitsquare.gui.main.overlays.Overlay.java

protected void animateHide(Runnable onFinishedHandler) {
    Interpolator interpolator = Interpolator.SPLINE(0.25, 0.1, 0.25, 1);
    double duration = getDuration(200);
    Timeline timeline = new Timeline();
    ObservableList<KeyFrame> keyFrames = timeline.getKeyFrames();

    if (type.animationType == AnimationType.SlideDownFromCenterTop) {
        double endY = -gridPane.getHeight();
        keyFrames//from   w ww . ja v a 2s . com
                .add(new KeyFrame(Duration.millis(0), new KeyValue(gridPane.opacityProperty(), 1, interpolator),
                        new KeyValue(gridPane.translateYProperty(), -10, interpolator)));
        keyFrames.add(new KeyFrame(Duration.millis(duration),
                new KeyValue(gridPane.opacityProperty(), 0, interpolator),
                new KeyValue(gridPane.translateYProperty(), endY, interpolator)));

        timeline.setOnFinished(e -> onFinishedHandler.run());
        timeline.play();
    } else if (type.animationType == AnimationType.ScaleFromCenter) {
        double endScale = 0.25;
        keyFrames
                .add(new KeyFrame(Duration.millis(0), new KeyValue(gridPane.opacityProperty(), 1, interpolator),
                        new KeyValue(gridPane.scaleXProperty(), 1, interpolator),
                        new KeyValue(gridPane.scaleYProperty(), 1, interpolator)));
        keyFrames.add(new KeyFrame(Duration.millis(duration),
                new KeyValue(gridPane.opacityProperty(), 0, interpolator),
                new KeyValue(gridPane.scaleXProperty(), endScale, interpolator),
                new KeyValue(gridPane.scaleYProperty(), endScale, interpolator)));
    } else if (type.animationType == AnimationType.ScaleYFromCenter) {
        gridPane.setRotationAxis(Rotate.X_AXIS);
        gridPane.getScene().setCamera(new PerspectiveCamera());
        keyFrames.add(new KeyFrame(Duration.millis(0), new KeyValue(gridPane.rotateProperty(), 0, interpolator),
                new KeyValue(gridPane.opacityProperty(), 1, interpolator)));
        keyFrames.add(new KeyFrame(Duration.millis(duration),
                new KeyValue(gridPane.rotateProperty(), -90, interpolator),
                new KeyValue(gridPane.opacityProperty(), 0, interpolator)));
    } else if (type.animationType == AnimationType.ScaleDownToCenter) {
        double endScale = 0.1;
        keyFrames
                .add(new KeyFrame(Duration.millis(0), new KeyValue(gridPane.opacityProperty(), 1, interpolator),
                        new KeyValue(gridPane.scaleXProperty(), 1, interpolator),
                        new KeyValue(gridPane.scaleYProperty(), 1, interpolator)));
        keyFrames.add(new KeyFrame(Duration.millis(duration),
                new KeyValue(gridPane.opacityProperty(), 0, interpolator),
                new KeyValue(gridPane.scaleXProperty(), endScale, interpolator),
                new KeyValue(gridPane.scaleYProperty(), endScale, interpolator)));
    } else if (type.animationType == AnimationType.FadeInAtCenter) {
        keyFrames.add(
                new KeyFrame(Duration.millis(0), new KeyValue(gridPane.opacityProperty(), 1, interpolator)));
        keyFrames.add(new KeyFrame(Duration.millis(duration),
                new KeyValue(gridPane.opacityProperty(), 0, interpolator)));
    }

    timeline.setOnFinished(e -> onFinishedHandler.run());
    timeline.play();
}

From source file:com.github.vatbub.tictactoe.view.Main.java

private void setLoadingStatusText(String textToSet, boolean noAnimation) {
    if (!loadingStatusText.getText().equals(textToSet) && !noAnimation) {
        KeyValue keyValueTranslation1 = new KeyValue(loadingStatusText.translateYProperty(),
                -loadingStatusText.getHeight());
        KeyValue keyValueOpacity1 = new KeyValue(loadingStatusText.opacityProperty(), 0);
        KeyFrame keyFrame1 = new KeyFrame(Duration.seconds(animationSpeed), keyValueOpacity1,
                keyValueTranslation1);/*from w  w w  . ja  va2s.co m*/

        Timeline timeline1 = new Timeline(keyFrame1);

        timeline1.setOnFinished((event) -> {
            loadingStatusText.setText(textToSet);
            loadingStatusText.setTranslateY(loadingStatusText.getHeight());

            KeyValue keyValueTranslation2 = new KeyValue(loadingStatusText.translateYProperty(), 0);
            KeyValue keyValueOpacity2 = new KeyValue(loadingStatusText.opacityProperty(), 1);
            KeyFrame keyFrame2 = new KeyFrame(Duration.seconds(animationSpeed), keyValueOpacity2,
                    keyValueTranslation2);

            Timeline timeline2 = new Timeline(keyFrame2);

            timeline2.play();
        });

        timeline1.play();
    } else {
        loadingStatusText.setText(textToSet);
    }
}

From source file:com.github.vatbub.tictactoe.view.Main.java

public void flashOpponentsTurnHBox() {
    KeyValue keyValue1Color = new KeyValue(((DropShadow) opponentsTurnAnchorPane.getEffect()).colorProperty(),
            Color.RED);//from  ww w .j a  va 2  s  .c  o  m
    KeyValue keyValue1Width = new KeyValue(((DropShadow) opponentsTurnAnchorPane.getEffect()).widthProperty(),
            30);
    KeyValue keyValue1Height = new KeyValue(((DropShadow) opponentsTurnAnchorPane.getEffect()).heightProperty(),
            30);
    KeyFrame keyFrame1 = new KeyFrame(Duration.seconds(animationSpeed / 2), keyValue1Color, keyValue1Width,
            keyValue1Height);

    KeyValue keyValue2Color = new KeyValue(((DropShadow) opponentsTurnAnchorPane.getEffect()).colorProperty(),
            Color.BLACK);
    KeyValue keyValue2Width = new KeyValue(((DropShadow) opponentsTurnAnchorPane.getEffect()).widthProperty(),
            12);
    KeyValue keyValue2Height = new KeyValue(((DropShadow) opponentsTurnAnchorPane.getEffect()).heightProperty(),
            12);
    KeyFrame keyFrame2 = new KeyFrame(Duration.seconds(animationSpeed), keyValue2Color, keyValue2Width,
            keyValue2Height);

    Timeline timeline = new Timeline(keyFrame1, keyFrame2);
    // play it twice
    timeline.setOnFinished((event -> new Timeline(keyFrame1, keyFrame2).play()));
    timeline.play();
}

From source file:com.github.vatbub.tictactoe.view.Main.java

public void updateOpponentsTurnHBox(boolean noAnimation, boolean isShown) {
    double destinationTranslate;
    double animationOffsetInSeconds = 0;
    if (!isShown) {
        destinationTranslate = opponentsTurnHBox.getHeight() + 3;
        double timeSinceLastShownInMillis = Calendar.getInstance().getTime().getTime()
                - opponentsTurnLabelLastShown.getTime().getTime();
        double timeSinceLastShownInSeconds = timeSinceLastShownInMillis / 1000;
        animationOffsetInSeconds = Math
                .max(opponentsTurnLabelShownForAtLeastSeconds - timeSinceLastShownInSeconds, 0);
    } else {/*  w  w w  .j a v a2  s .co  m*/
        destinationTranslate = 0;
        String opponentsName;
        if (board.getCurrentPlayer() == null || board.getOpponent(board.getCurrentPlayer()) == null) {
            opponentsName = "Opponent";
        } else {
            Player player;
            if (board.getCurrentPlayer().getPlayerMode() == PlayerMode.localHuman) {
                player = board.getOpponent(board.getCurrentPlayer());
            } else {
                player = board.getCurrentPlayer();
            }
            opponentsName = player.getName();
        }
        opponentsTurnLabel.setText(opponentsName + "'s turn...");
    }

    if (noAnimation) {
        opponentsTurnHBox.setTranslateY(destinationTranslate);
    } else {
        KeyValue keyValue1 = new KeyValue(opponentsTurnHBox.translateYProperty(),
                opponentsTurnHBox.getTranslateY());
        KeyFrame keyFrame1 = new KeyFrame(Duration.seconds(animationOffsetInSeconds), keyValue1);

        KeyValue keyValue2 = new KeyValue(opponentsTurnHBox.translateYProperty(), destinationTranslate);
        KeyFrame keyFrame2 = new KeyFrame(Duration.seconds(animationSpeed + animationOffsetInSeconds),
                keyValue2);
        Timeline timeline = new Timeline(keyFrame1, keyFrame2);
        timeline.setOnFinished((event) -> {
            if (isShown) {
                opponentsTurnLabelLastShown = Calendar.getInstance();
            }
        });
        timeline.play();
    }
}

From source file:com.github.vatbub.tictactoe.view.Main.java

private void setLowerRightAnchorPaneDimensions(Labeled nodeToShow, Labeled nodeToHide, boolean noAnimation,
        double widthOffset) {
    final double secondAnimationOffset = 0.1;
    if (widthOffset > 0) {
        nodeToShow.setPrefWidth(nodeToShow.getWidth() + widthOffset);
    }//w  w w . j  a  v  a 2  s  .  co  m

    if (noAnimation) {
        nodeToShow.setOpacity(1);
        nodeToShow.setVisible(true);
        nodeToHide.setVisible(false);
        playOnlineAnchorPane.setPrefHeight(nodeToShow.getHeight());
        playOnlineAnchorPane.setPrefWidth(nodeToShow.getWidth());
    } else {
        nodeToShow.setOpacity(0);
        nodeToShow.setVisible(true);
        nodeToShow.setPrefWidth(nodeToShow.getWidth());
        nodeToShow.setPrefHeight(nodeToShow.getHeight());

        DoubleProperty firstProperty;
        DoubleProperty secondProperty;
        double firstPropertyValue;
        double secondPropertyValue;
        double secondPropertyInitialValue;

        if (nodeToShow.getHeight() > nodeToShow.getWidth()) {
            firstProperty = playOnlineAnchorPane.prefHeightProperty();
            firstPropertyValue = nodeToShow.getHeight() + AnchorPane.getBottomAnchor(nodeToShow);
            secondProperty = playOnlineAnchorPane.prefWidthProperty();
            secondPropertyValue = nodeToShow.getWidth() + AnchorPane.getRightAnchor(nodeToShow);
            secondPropertyInitialValue = nodeToHide.getWidth();
        } else {
            firstProperty = playOnlineAnchorPane.prefWidthProperty();
            firstPropertyValue = nodeToShow.getWidth() + AnchorPane.getRightAnchor(nodeToShow);
            secondProperty = playOnlineAnchorPane.prefHeightProperty();
            secondPropertyValue = nodeToShow.getHeight() + AnchorPane.getBottomAnchor(nodeToShow);
            secondPropertyInitialValue = nodeToHide.getHeight();
        }

        KeyValue keyValueFirstProperty = new KeyValue(firstProperty, firstPropertyValue,
                Interpolator.EASE_BOTH);
        KeyValue keyValueNodeToHideOpacity1 = new KeyValue(nodeToHide.opacityProperty(), 0,
                Interpolator.EASE_IN);
        KeyFrame keyFrame1 = new KeyFrame(Duration.seconds(animationSpeed), keyValueFirstProperty,
                keyValueNodeToHideOpacity1);

        KeyValue keyValueSecondProperty1 = new KeyValue(secondProperty, secondPropertyInitialValue);
        KeyValue keyValueNodeToShowOpacity1 = new KeyValue(nodeToShow.opacityProperty(),
                nodeToShow.getOpacity());
        KeyFrame keyFrame2 = new KeyFrame(Duration.seconds(secondAnimationOffset * animationSpeed),
                keyValueSecondProperty1, keyValueNodeToShowOpacity1);

        KeyValue keyValueSecondProperty2 = new KeyValue(secondProperty, secondPropertyValue,
                Interpolator.EASE_BOTH);
        KeyValue keyValueNodeToShowOpacity2 = new KeyValue(nodeToShow.opacityProperty(), 1,
                Interpolator.EASE_OUT);
        KeyFrame keyFrame3 = new KeyFrame(Duration.seconds((1 + secondAnimationOffset) * animationSpeed),
                keyValueSecondProperty2, keyValueNodeToShowOpacity2);

        Timeline timeline = new Timeline(keyFrame1, keyFrame2, keyFrame3);
        timeline.setOnFinished((event) -> nodeToHide.setVisible(false));
        timeline.play();
    }
}

From source file:com.github.vatbub.tictactoe.view.Main.java

private void addWinLineOnWin(Board.WinnerInfo winnerInfo, Paint color, Runnable onFinished) {
    Line originLine = new Line(0, 0, 0, 0);
    winLineGroup.getChildren().add(originLine);

    WinLine winLine = new WinLine(winnerInfo);
    double winLineEndX = winLine.endArc.getCenterX();
    double winLineEndY = winLine.endArc.getCenterY();
    winLine.startArc.setFill(color);/*  ww  w  .  jav  a  2  s.  c o m*/
    winLine.startArc.setStrokeWidth(0);
    winLine.endArc.setFill(color);
    winLine.endArc.setStrokeWidth(0);
    winLine.rightLine.setStrokeWidth(0);
    winLine.leftLine.setStrokeWidth(0);
    winLine.centerLine.setStroke(color);

    winLine.centerLine.strokeWidthProperty().bind(winLine.startArc.radiusXProperty().multiply(2));
    winLineGroup.getChildren().addAll(winLine.getAll());

    blurNode(gamePane, 4);

    winLineGroup.setOpacity(0);
    GaussianBlur blur = new GaussianBlur(100);
    winLineGroup.setEffect(blur);
    winLineGroup.setBlendMode(BlendMode.DARKEN);
    winLineGroup.setVisible(true);

    double winLineAnimationX1 = 0.2;
    double winLineAnimationX2 = 0.5;

    KeyValue stretchKeyValue1x = new KeyValue(winLine.endArc.centerXProperty(), winLine.startArc.getCenterX());
    KeyValue stretchKeyValue1y = new KeyValue(winLine.endArc.centerYProperty(), winLine.startArc.getCenterY());
    KeyFrame stretchKeyFrame1 = new KeyFrame(Duration.millis(0), stretchKeyValue1x, stretchKeyValue1y);

    KeyValue stretchKeyValue2x = new KeyValue(winLine.endArc.centerXProperty(), winLine.startArc.getCenterX(),
            new CustomEaseBothInterpolator(winLineAnimationX1, winLineAnimationX2));
    KeyValue stretchKeyValue2y = new KeyValue(winLine.endArc.centerYProperty(), winLine.startArc.getCenterY(),
            new CustomEaseBothInterpolator(winLineAnimationX1, winLineAnimationX2));
    KeyFrame stretchKeyFrame2 = new KeyFrame(Duration.millis(100), stretchKeyValue2x, stretchKeyValue2y);

    KeyValue stretchKeyValue3x = new KeyValue(winLine.endArc.centerXProperty(), winLineEndX,
            new CustomEaseBothInterpolator(winLineAnimationX1, winLineAnimationX2));
    KeyValue stretchKeyValue3y = new KeyValue(winLine.endArc.centerYProperty(), winLineEndY,
            new CustomEaseBothInterpolator(winLineAnimationX1, winLineAnimationX2));
    KeyFrame stretchKeyFrame3 = new KeyFrame(Duration.millis(800), stretchKeyValue3x, stretchKeyValue3y);

    KeyValue opacityKeyValue1 = new KeyValue(winLineGroup.opacityProperty(), 0.8);
    KeyFrame opacityKeyFrame1 = new KeyFrame(Duration.millis(400), opacityKeyValue1);

    Timeline timeline = new Timeline();
    timeline.getKeyFrames().addAll(stretchKeyFrame1, stretchKeyFrame2, stretchKeyFrame3, opacityKeyFrame1);
    timeline.play();

    timeline.setOnFinished((event) -> onFinished.run());
}

From source file:com.github.vatbub.tictactoe.view.Main.java

private void blurNode(Node node, double toValue, @SuppressWarnings("SameParameterValue") Runnable onFinish) {
    guiAnimationQueue.submit(() -> {/*from  w w w  . j  a  v a2  s .c  o  m*/
        GaussianBlur blur = (GaussianBlur) node.getEffect();
        if (blur == null) {
            blur = new GaussianBlur(0);
            node.setEffect(blur);
        }
        node.setEffect(blur);
        Timeline timeline = new Timeline();
        KeyValue keyValue = new KeyValue(blur.radiusProperty(), toValue);
        KeyFrame keyFrame = new KeyFrame(Duration.seconds(animationSpeed), keyValue);
        timeline.getKeyFrames().add(keyFrame);

        timeline.setOnFinished((event) -> {
            if (toValue == 0) {
                node.setEffect(null);
            }
            if (onFinish != null) {
                onFinish.run();
            }
        });

        timeline.play();
    });
}

From source file:com.github.vatbub.tictactoe.view.Main.java

private void showTie() {
    guiAnimationQueue.submitWaitForUnlock(() -> {
        double endX = tiePane.getWidth() - 230;
        double endY = 90;

        AnchorPane.clearConstraints(bowTie);
        bowTie.setX(endX);//from   ww w .  j  a v a2s . co m
        bowTie.setY(-150);

        blurGamePane();
        tieMessage.setOpacity(0);
        tiePane.setOpacity(1);
        tiePane.setVisible(true);
        bowTie.setVisible(true);

        Timeline timeline = new Timeline();
        double S4 = 1.45;
        double x0 = 0.33;
        KeyValue keyValue1x = new KeyValue(bowTie.xProperty(), endX, new CustomEaseOutInterpolator(S4, x0));
        KeyValue keyValue1y = new KeyValue(bowTie.yProperty(), endY, new CustomEaseOutInterpolator(S4, x0));
        KeyFrame keyFrame1 = new KeyFrame(Duration.seconds(1), keyValue1x, keyValue1y);
        timeline.getKeyFrames().add(keyFrame1);

        timeline.setOnFinished((event) -> fadeNode(tieMessage, 1, () -> {
            AnchorPane.setRightAnchor(bowTie, tiePane.getWidth() - bowTie.getFitWidth() - endX);
            AnchorPane.setTopAnchor(bowTie, endY);
        }));

        timeline.play();
    });
}

From source file:com.github.vatbub.tictactoe.view.Main.java

public void updateCurrentPlayerLabel(boolean noAnimation, boolean setBlockedValueAfterAnimation) {
    Platform.runLater(() -> stage.setTitle(getWindowTitle()));
    if (board.getCurrentPlayer() != null) {
        if (!board.getCurrentPlayer().getLetter().equals(currentPlayerLabel.getText())) {
            if (noAnimation) {
                setCurrentPlayerValue();
            } else {
                guiAnimationQueue.submitWaitForUnlock(() -> {
                    guiAnimationQueue.setBlocked(true);

                    GaussianBlur blur = (GaussianBlur) currentPlayerLabel.getEffect();
                    if (blur == null) {
                        blur = new GaussianBlur(0);
                    }/*from  w w w  . j  a v a2 s.  co  m*/

                    Calendar changeLabelTextDate = Calendar.getInstance();
                    changeLabelTextDate.add(Calendar.MILLISECOND, (int) (animationSpeed * 1000));
                    runLaterTimer.schedule(new TimerTask() {
                        @Override
                        public void run() {
                            Platform.runLater(() -> setCurrentPlayerValue());
                        }
                    }, changeLabelTextDate.getTime());

                    currentPlayerLabel.setEffect(blur);
                    Timeline timeline = new Timeline();
                    KeyValue keyValue1 = new KeyValue(blur.radiusProperty(), 20);
                    KeyFrame keyFrame1 = new KeyFrame(Duration.seconds(animationSpeed), keyValue1);

                    KeyValue keyValue2 = new KeyValue(blur.radiusProperty(), 0);
                    KeyFrame keyFrame2 = new KeyFrame(Duration.seconds(2 * animationSpeed), keyValue2);

                    timeline.getKeyFrames().addAll(keyFrame1, keyFrame2);

                    timeline.setOnFinished((event) -> {
                        currentPlayerLabel.setEffect(null);
                        guiAnimationQueue.setBlocked(false);
                        setBlockedForInput(setBlockedValueAfterAnimation);
                    });

                    timeline.play();
                });
                return;
            }
        }
    }

    guiAnimationQueue.setBlocked(false);
    setBlockedForInput(setBlockedValueAfterAnimation);
}