Example usage for javafx.animation KeyFrame KeyFrame

List of usage examples for javafx.animation KeyFrame KeyFrame

Introduction

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

Prototype

public KeyFrame(@NamedArg("time") Duration time, @NamedArg("name") String name,
        @NamedArg("values") KeyValue... values) 

Source Link

Document

Constructor of KeyFrame

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    stage.setTitle("Rotations");
    stage.setScene(makeScene());/*from  ww w.j  a  v a 2s . c o m*/
    stage.show();
    TimelineBuilder.create().cycleCount(Timeline.INDEFINITE).keyFrames(
            new KeyFrame(Duration.seconds(0), new KeyValue(translateZForNode1, -100), new KeyValue(angle, 0)),
            new KeyFrame(Duration.seconds(2), new KeyValue(translateZForNode1, 100), new KeyValue(angle, 180)),
            new KeyFrame(Duration.seconds(4), new KeyValue(translateZForNode1, -100), new KeyValue(angle, 360))

    ).build().play();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 800, 600, Color.BLACK);
    primaryStage.setScene(scene);//from w  w  w .j a  v a 2s .co m
    Group circles = new Group();
    for (int i = 0; i < 30; i++) {
        Circle circle = new Circle(150, Color.web("white", 0.05));
        circle.setStrokeType(StrokeType.OUTSIDE);
        circle.setStroke(Color.web("white", 0.16));
        circle.setStrokeWidth(4);
        circles.getChildren().add(circle);
    }
    Rectangle colors = new Rectangle(scene.getWidth(), scene.getHeight(),
            new LinearGradient(0f, 1f, 1f, 0f, true, CycleMethod.NO_CYCLE,
                    new Stop[] { new Stop(0, Color.web("#f8bd55")), new Stop(0.14, Color.web("#c0fe56")),
                            new Stop(0.28, Color.web("#5dfbc1")), new Stop(0.43, Color.web("#64c2f8")),
                            new Stop(0.57, Color.web("#be4af7")), new Stop(0.71, Color.web("#ed5fc2")),
                            new Stop(0.85, Color.web("#ef504c")), new Stop(1, Color.web("#f2660f")), }));
    Group blendModeGroup = new Group(
            new Group(new Rectangle(scene.getWidth(), scene.getHeight(), Color.BLACK), circles), colors);
    colors.setBlendMode(BlendMode.OVERLAY);
    root.getChildren().add(blendModeGroup);
    circles.setEffect(new BoxBlur(10, 10, 3));
    Timeline timeline = new Timeline();
    for (Node circle : circles.getChildren()) {
        timeline.getKeyFrames().addAll(new KeyFrame(Duration.ZERO, // set start position at 0
                new KeyValue(circle.translateXProperty(), random() * 800),
                new KeyValue(circle.translateYProperty(), random() * 600)),
                new KeyFrame(new Duration(40000), // set end position at 40s
                        new KeyValue(circle.translateXProperty(), random() * 800),
                        new KeyValue(circle.translateYProperty(), random() * 600)));
    }
    // play 40s of animation
    timeline.play();

    primaryStage.show();
}

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

protected void animateDisplay() {
    gridPane.setOpacity(0);/*from   ww  w  . ja v a 2  s.com*/
    Interpolator interpolator = Interpolator.SPLINE(0.25, 0.1, 0.25, 1);
    double duration = getDuration(400);
    Timeline timeline = new Timeline();
    ObservableList<KeyFrame> keyFrames = timeline.getKeyFrames();

    if (type.animationType == AnimationType.SlideDownFromCenterTop) {
        double startY = -gridPane.getHeight();
        keyFrames
                .add(new KeyFrame(Duration.millis(0), new KeyValue(gridPane.opacityProperty(), 0, interpolator),
                        new KeyValue(gridPane.translateYProperty(), startY, interpolator)));
        keyFrames.add(new KeyFrame(Duration.millis(duration),
                new KeyValue(gridPane.opacityProperty(), 1, interpolator),
                new KeyValue(gridPane.translateYProperty(), -10, interpolator)));
    } else if (type.animationType == AnimationType.ScaleFromCenter) {
        double startScale = 0.25;
        keyFrames
                .add(new KeyFrame(Duration.millis(0), new KeyValue(gridPane.opacityProperty(), 0, interpolator),
                        new KeyValue(gridPane.scaleXProperty(), startScale, interpolator),
                        new KeyValue(gridPane.scaleYProperty(), startScale, interpolator)

        ));
        keyFrames.add(new KeyFrame(Duration.millis(duration),
                new KeyValue(gridPane.opacityProperty(), 1, interpolator),
                new KeyValue(gridPane.scaleXProperty(), 1, interpolator),
                new KeyValue(gridPane.scaleYProperty(), 1, interpolator)));
    } else if (type.animationType == AnimationType.ScaleYFromCenter) {
        double startYScale = 0.25;
        keyFrames
                .add(new KeyFrame(Duration.millis(0), new KeyValue(gridPane.opacityProperty(), 0, interpolator),
                        new KeyValue(gridPane.scaleYProperty(), startYScale, interpolator)

        ));
        keyFrames.add(new KeyFrame(Duration.millis(duration),
                new KeyValue(gridPane.opacityProperty(), 1, interpolator),
                new KeyValue(gridPane.scaleYProperty(), 1, interpolator)));
    } else if (type.animationType == AnimationType.ScaleDownToCenter) {
        double startScale = 1.1;
        keyFrames
                .add(new KeyFrame(Duration.millis(0), new KeyValue(gridPane.opacityProperty(), 0, interpolator),
                        new KeyValue(gridPane.scaleXProperty(), startScale, interpolator),
                        new KeyValue(gridPane.scaleYProperty(), startScale, interpolator)

        ));
        keyFrames.add(new KeyFrame(Duration.millis(duration),
                new KeyValue(gridPane.opacityProperty(), 1, interpolator),
                new KeyValue(gridPane.scaleXProperty(), 1, interpolator),
                new KeyValue(gridPane.scaleYProperty(), 1, interpolator)));
    } else if (type.animationType == AnimationType.FadeInAtCenter) {
        keyFrames.add(new KeyFrame(Duration.millis(0), new KeyValue(gridPane.opacityProperty(), 0, interpolator)

        ));
        keyFrames.add(new KeyFrame(Duration.millis(duration),
                new KeyValue(gridPane.opacityProperty(), 1, interpolator)));
    }

    timeline.play();
}

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

void animateTo(double xLeft, double yTop) {
    if (timeline != null) {
        timeline.stop();//ww  w . j a  va2s .  c o m
        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();
}

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);//from  w  ww.  j ava2  s .com
    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: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);/*  ww  w .  j av a  2s  .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: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  w w .  ja  v  a2 s .c o m
                .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:org.sleuthkit.autopsy.timeline.ui.detailview.EventDetailsChart.java

/**
 * layout the nodes in the given list, starting form the given minimum y
 * coordinate.//from w  ww . j  a  v a 2 s  .  co 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
}

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);
    }/* www  . j a  v  a 2 s.  c  o 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);//from ww w  . j a  v a 2  s  . c  om
    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());
}