Example usage for javafx.animation KeyValue KeyValue

List of usage examples for javafx.animation KeyValue KeyValue

Introduction

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

Prototype

public <T> KeyValue(@NamedArg("target") WritableValue<T> target, @NamedArg("endValue") T endValue) 

Source Link

Document

Creates a KeyValue that uses Interpolator#LINEAR .

Usage

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);//from   w ww  . java2s  . co  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 showLooser(Board.WinnerInfo winnerInfo) {
    String looserName = board.getOpponent(winnerInfo.winningPlayer).getName();
    guiAnimationQueue.submitWaitForUnlock(() -> {
        ShakeTransition anim = new ShakeTransition(gamePane, null);
        anim.playFromStart();//w w  w.  ja  v a2 s .c  o m

        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 addWinLineOnLoose(Board.WinnerInfo winnerInfo) {
    final double strokeWidth = 2;

    Line originLine = new Line(0, 0, 0, 0);
    winLineGroup.getChildren().add(originLine);

    WinLine winLine = new WinLine(winnerInfo);
    winLine.startArc.setFill(Color.TRANSPARENT);
    winLine.startArc.setStroke(Color.BLACK);
    winLine.startArc.setStrokeWidth(strokeWidth);
    winLine.endArc.setFill(Color.TRANSPARENT);
    winLine.endArc.setStroke(Color.BLACK);
    winLine.endArc.setStrokeWidth(strokeWidth);
    winLine.rightLine.setStrokeWidth(strokeWidth);
    winLine.leftLine.setStrokeWidth(strokeWidth);

    winLine.centerLine.setStrokeWidth(0);
    winLineGroup.getChildren().addAll(winLine.getAll());

    winLineGroup.setOpacity(0);//from w  w w. ja v a2 s  .  c o  m
    GaussianBlur blur = new GaussianBlur(7);
    winLineGroup.setEffect(blur);
    winLineGroup.setVisible(true);
    KeyValue keyValue1 = new KeyValue(winLineGroup.opacityProperty(), 0);
    KeyFrame keyFrame1 = new KeyFrame(Duration.millis(900), keyValue1);
    KeyValue keyValue2 = new KeyValue(winLineGroup.opacityProperty(), 1);
    KeyFrame keyFrame2 = new KeyFrame(Duration.millis(950), keyValue2);

    Timeline timeline = new Timeline();
    timeline.getKeyFrames().addAll(keyFrame1, keyFrame2);
    timeline.play();
}

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

private void blurNode(Node node, double toValue, @SuppressWarnings("SameParameterValue") Runnable onFinish) {
    guiAnimationQueue.submit(() -> {/*from  www  .j a  va 2s  . 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

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 {//from  ww w .ja v  a 2 s  .c  om
        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

public void flashOpponentsTurnHBox() {
    KeyValue keyValue1Color = new KeyValue(((DropShadow) opponentsTurnAnchorPane.getEffect()).colorProperty(),
            Color.RED);//from  ww w . j av a  2s . c om
    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:net.sourceforge.pmd.util.fxdesigner.MainDesignerController.java

private void initializeViewAnimation() {

    // gets captured in the closure
    final double defaultMainHorizontalSplitPaneDividerPosition = mainHorizontalSplitPane
            .getDividerPositions()[0];// w w w.  j  a va 2  s.  c  o  m

    // show/ hide bottom pane
    bottomTabsToggle.selectedProperty().addListener((observable, wasExpanded, isNowExpanded) -> {
        KeyValue keyValue = null;
        DoubleProperty divPosition = mainHorizontalSplitPane.getDividers().get(0).positionProperty();
        if (wasExpanded && !isNowExpanded) {
            keyValue = new KeyValue(divPosition, 1);
        } else if (!wasExpanded && isNowExpanded) {
            keyValue = new KeyValue(divPosition, defaultMainHorizontalSplitPaneDividerPosition);
        }

        if (keyValue != null) {
            Timeline timeline = new Timeline(new KeyFrame(Duration.millis(200), keyValue));
            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./*  w w  w . j  a v  a  2  s  .  c om*/
 *
 * 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
}

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

void animateTo(double xLeft, double yTop) {
    if (timeline != null) {
        timeline.stop();//w w w  .  ja  v  a 2s .c om
        Platform.runLater(this::requestChartLayout);
    }
    timeline = new Timeline(new KeyFrame(Duration.millis(100), new KeyValue(layoutXProperty(), xLeft),
            new KeyValue(layoutYProperty(), yTop)));
    timeline.setOnFinished(finished -> Platform.runLater(this::requestChartLayout));
    timeline.play();
}