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:com.github.vatbub.tictactoe.view.Main.java

private void showWinnerWithTwoHumanPlayers(Board.WinnerInfo winnerInfo) {
    guiAnimationQueue.submitWaitForUnlock(() -> addWinLineOnWin(winnerInfo, Color.YELLOW, () -> {
        twoHumansWinnerText.setText(winnerInfo.winningPlayer.getName() + " won :)");
        double endX = twoHumansWinnerImage.getX();
        double endY = twoHumansWinnerImage.getY();

        AnchorPane.clearConstraints(twoHumansWinnerImage);
        twoHumansWinnerImage.setX(endX);
        twoHumansWinnerImage.setY(twoHumansWinnerImage.getY() + 300);

        // blurGamePane();
        blurGamePane(10.0);/* w w  w  . ja  v  a 2  s.  c o  m*/
        twoHumansWinMessage.setOpacity(0);
        twoHumansWinnerImage.setOpacity(0);
        twoHumansWinnerPane.setOpacity(1);
        twoHumansWinnerPane.setVisible(true);
        twoHumansWinnerImage.setVisible(true);

        Timeline timeline = new Timeline();
        double S4 = 1.45;
        double x0 = 0.33;

        KeyValue twoHumansWinnerImageKeyValue1x = new KeyValue(twoHumansWinnerImage.xProperty(), endX,
                new CustomEaseOutInterpolator(S4, x0));
        KeyValue twoHumansWinnerImageKeyValue1y = new KeyValue(twoHumansWinnerImage.yProperty(), endY,
                new CustomEaseOutInterpolator(S4, x0));
        KeyValue twoHumansWinnerImageKeyValue1Opacity = new KeyValue(twoHumansWinnerImage.opacityProperty(), 1);
        KeyFrame twoHumansWinnerImageKeyFrame1 = new KeyFrame(Duration.millis(600),
                twoHumansWinnerImageKeyValue1x, twoHumansWinnerImageKeyValue1y,
                twoHumansWinnerImageKeyValue1Opacity);
        timeline.getKeyFrames().addAll(twoHumansWinnerImageKeyFrame1);

        timeline.setOnFinished((event) -> fadeNode(twoHumansWinMessage, 1, () -> {
            AnchorPane.setLeftAnchor(twoHumansWinnerImage, 0.0);
            AnchorPane.setBottomAnchor(twoHumansWinnerImage, 0.0);
        }));

        timeline.play();
    }));
}

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

private void showLooser(Board.WinnerInfo winnerInfo) {
    String looserName = board.getOpponent(winnerInfo.winningPlayer).getName();
    guiAnimationQueue.submitWaitForUnlock(() -> {
        ShakeTransition anim = new ShakeTransition(gamePane, null);
        anim.playFromStart();//  w ww  . j a  va2  s  .  c  om

        Timeline timeline = new Timeline();

        Circle c1 = new Circle((452 / 600.0) * looserPane.getWidth(), (323 / 640.0) * looserPane.getHeight(),
                0);
        GaussianBlur circleBlur = new GaussianBlur(30);
        c1.setEffect(circleBlur);
        looseImage.setClip(c1);
        addWinLineOnLoose(winnerInfo);

        KeyValue keyValue1 = new KeyValue(c1.radiusProperty(), 0);
        KeyFrame keyFrame1 = new KeyFrame(Duration.millis(800), keyValue1);
        KeyValue keyValue2 = new KeyValue(c1.radiusProperty(), (500 / 640.0) * looserPane.getHeight());
        KeyFrame keyFrame2 = new KeyFrame(Duration.millis(900), keyValue2);

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

        looseMessage.setOpacity(0);
        looserText.setText(looserName + " lost :(");
        looserPane.setVisible(true);
        looserPane.setOpacity(1);

        timeline.setOnFinished((event) -> {
            looseImage.setClip(null);
            winLineGroup.setClip(null);
            blurGamePane();
            PauseTransition wait = new PauseTransition();
            wait.setDuration(Duration.seconds(1));
            wait.setOnFinished((event2) -> {
                FadeTransition looseMessageTransition = new FadeTransition();
                looseMessageTransition.setNode(looseMessage);
                looseMessageTransition.setFromValue(0);
                looseMessageTransition.setToValue(1);
                looseMessageTransition.setDuration(Duration.millis(500));
                looseMessageTransition.setAutoReverse(false);
                looseMessageTransition.play();
            });

            wait.play();
        });

        timeline.play();
    });

}

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

private void showWinner(Board.WinnerInfo winnerInfo) {
    guiAnimationQueue.submitWaitForUnlock(
            () -> addWinLineOnWin(winnerInfo, new Color(1.0, 145.0 / 255.0, 30.0 / 255.0, 1.0), () -> {
                winnerText.setText(winnerInfo.winningPlayer.getName() + " won :)");
                double endX = winningGirl.getX();
                double endY = winningGirl.getY();

                double confettiOffset = 30;

                double confettiX = confetti.getX();
                double confettiY = confetti.getY();

                AnchorPane.clearConstraints(winningGirl);
                winningGirl.setX(endX);/*  www  . j ava2 s.  com*/
                winningGirl.setY(root.getHeight() + 140);

                blurGamePane();
                winMessage.setOpacity(0);
                confetti.setOpacity(0);
                winPane.setOpacity(1);
                winPane.setVisible(true);
                winningGirl.setVisible(true);

                Timeline timeline = new Timeline();
                double S4 = 1.45;
                double x0 = 0.33;
                KeyValue confettiKeyValue1x = new KeyValue(confetti.xProperty(), confettiX);
                KeyValue confettiKeyValue1y = new KeyValue(confetti.yProperty(), confettiY - confettiOffset);
                KeyValue confettiKeyValue1opacity = new KeyValue(confetti.opacityProperty(), 0);
                KeyFrame confettiKeyFrame1 = new KeyFrame(Duration.seconds(0), confettiKeyValue1x,
                        confettiKeyValue1y, confettiKeyValue1opacity);

                KeyValue confettiKeyValue2x = new KeyValue(confetti.xProperty(), confettiX);
                KeyValue confettiKeyValue2y = new KeyValue(confetti.yProperty(), confettiY - confettiOffset);
                KeyValue confettiKeyValue2opacity = new KeyValue(confetti.opacityProperty(), 0);
                KeyFrame confettiKeyFrame2 = new KeyFrame(Duration.millis(500), confettiKeyValue2x,
                        confettiKeyValue2y, confettiKeyValue2opacity);

                KeyValue confettiKeyValue3x = new KeyValue(confetti.xProperty(), confettiX,
                        new CustomEaseOutInterpolator(S4, x0));
                KeyValue confettiKeyValue3y = new KeyValue(confetti.yProperty(), confettiY,
                        new CustomEaseOutInterpolator(S4, x0));
                KeyValue confettiKeyValue3opacity = new KeyValue(confetti.opacityProperty(), 1);
                KeyFrame confettiKeyFrame3 = new KeyFrame(Duration.millis(1100), confettiKeyValue3x,
                        confettiKeyValue3y, confettiKeyValue3opacity);

                KeyValue winningGirlKeyValue1x = new KeyValue(winningGirl.xProperty(), endX,
                        new CustomEaseOutInterpolator(S4, x0));
                KeyValue winningGirlKeyValue1y = new KeyValue(winningGirl.yProperty(), endY,
                        new CustomEaseOutInterpolator(S4, x0));
                KeyFrame winningGirlKeyFrame1 = new KeyFrame(Duration.seconds(1), winningGirlKeyValue1x,
                        winningGirlKeyValue1y);
                timeline.getKeyFrames().addAll(winningGirlKeyFrame1, confettiKeyFrame1, confettiKeyFrame2,
                        confettiKeyFrame3);

                timeline.setOnFinished((event) -> fadeNode(winMessage, 1, () -> {
                    AnchorPane.setRightAnchor(winningGirl, 0.0);
                    AnchorPane.setBottomAnchor(winningGirl, 0.0);
                }));

                timeline.play();
            }));
}

From source file:org.sleuthkit.autopsy.timeline.ui.detailview.EventDetailsChart.java

/**
 * layout the nodes in the given list, starting form the given minimum y
 * coordinate.//from w  w  w. ja va2s  .  c o  m
 *
 * Layout the nodes representing events via the following algorithm.
 *
 * we start with a list of nodes (each representing an event) - sort the
 * list of nodes by span start time of the underlying event - initialize
 * empty map (maxXatY) from y-position to max used x-value - for each node:
 *
 * -- size the node based on its children (recursively)
 *
 * -- get the event's start position from the dateaxis
 *
 * -- to position node (1)check if maxXatY is to the left of the left x
 * coord: if maxXatY is less than the left x coord, good, put the current
 * node here, mark right x coord as maxXatY, go to next node ; if maxXatY
 * greater than start position, increment y position, do check(1) again
 * until maxXatY less than start position
 *
 * @param nodes collection of nodes to layout
 * @param minY  the minimum y coordinate to position the nodes at.
 */
double layoutEventBundleNodes(final Collection<? extends EventBundleNodeBase<?, ?, ?>> nodes,
        final double minY) {

    TreeRangeMap<Double, Double> treeRangeMap = TreeRangeMap.create();
    // maximum y values occupied by any of the given nodes,  updated as nodes are layed out.
    double localMax = minY;

    Set<String> activeQuickHidefilters = getController().getQuickHideFilters().stream()
            .filter(AbstractFilter::isActive).map(DescriptionFilter::getDescription)
            .collect(Collectors.toSet());
    //for each node do a recursive layout to size it and then position it in first available slot
    for (EventBundleNodeBase<?, ?, ?> bundleNode : nodes) {
        //is the node hiden by a quick hide filter?
        boolean quickHide = activeQuickHidefilters.contains(bundleNode.getDescription());
        if (quickHide) {
            //hide it and skip layout
            bundleNode.setVisible(false);
            bundleNode.setManaged(false);
        } else {
            bundleLayoutHelper(bundleNode);
            //get computed height and width
            double h = bundleNode.getBoundsInLocal().getHeight();
            double w = bundleNode.getBoundsInLocal().getWidth();
            //get left and right x coords from axis plus computed width
            double xLeft = getXForEpochMillis(bundleNode.getStartMillis())
                    - bundleNode.getLayoutXCompensation();
            double xRight = xLeft + w + MINIMUM_EVENT_NODE_GAP;

            //initial test position
            double yTop = minY;

            if (oneEventPerRow.get()) {
                // if onePerRow, just put it at end
                yTop = (localMax + MINIMUM_EVENT_NODE_GAP);
            } else {
                double yBottom = yTop + h;

                //until the node is not overlapping any others try moving it down.
                boolean overlapping = true;
                while (overlapping) {
                    overlapping = false;
                    //check each pixel from bottom to top.
                    for (double y = yBottom; y >= yTop; y--) {
                        final Double maxX = treeRangeMap.get(y);
                        if (maxX != null && maxX >= xLeft - MINIMUM_EVENT_NODE_GAP) {
                            //if that pixel is already used
                            //jump top to this y value and repeat until free slot is found.
                            overlapping = true;
                            yTop = y + MINIMUM_EVENT_NODE_GAP;
                            yBottom = yTop + h;
                            break;
                        }
                    }
                }
                treeRangeMap.put(Range.closed(yTop, yBottom), xRight);
            }

            localMax = Math.max(yTop + h, localMax);

            if ((xLeft != bundleNode.getLayoutX()) || (yTop != bundleNode.getLayoutY())) {

                //animate node to new position
                Timeline timeline = new Timeline(
                        new KeyFrame(Duration.millis(100), new KeyValue(bundleNode.layoutXProperty(), xLeft),
                                new KeyValue(bundleNode.layoutYProperty(), yTop)));
                timeline.setOnFinished((ActionEvent event) -> {
                    requestChartLayout();
                });
                timeline.play();
            }
        }
    }
    return localMax; //return new max
}