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:Main.java

@Override
public void start(Stage stage) {
    Text msg = new Text("java2s.com");
    msg.setTextOrigin(VPos.TOP);//from ww  w  .j av a  2  s.c  om
    msg.setFont(Font.font(24));

    Pane root = new Pane(msg);
    root.setPrefSize(500, 70);
    Scene scene = new Scene(root);

    stage.setScene(scene);
    stage.setTitle("Scrolling Text");
    stage.show();

    double sceneWidth = scene.getWidth();
    double msgWidth = msg.getLayoutBounds().getWidth();

    KeyValue initKeyValue = new KeyValue(msg.translateXProperty(), sceneWidth);
    KeyFrame initFrame = new KeyFrame(Duration.ZERO, initKeyValue);

    KeyValue endKeyValue = new KeyValue(msg.translateXProperty(), -1.0 * msgWidth);
    KeyFrame endFrame = new KeyFrame(Duration.seconds(3), endKeyValue);

    Timeline timeline = new Timeline(initFrame, endFrame);

    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.play();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    stage.setTitle("Rotations");
    stage.setScene(makeScene());/*from   w  ww  . j a v  a2  s .  com*/
    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 stage) {
    DoubleProperty translate = new SimpleDoubleProperty();
    stage.setTitle("Hello JavaFX");
    Rectangle node1 = RectangleBuilder.create().x(0).y(0).width(10).height(10).fill(Color.RED).build();
    node1.translateXProperty().bind(translate);

    Parent parent = GroupBuilder.create().children(node1).translateX(250).translateY(250).build();
    stage.setScene(SceneBuilder.create().width(500).height(500).root(parent).build());
    stage.show();/*from  ww  w  .j a  v  a 2 s  .  c o  m*/

    TimelineBuilder.create().cycleCount(Timeline.INDEFINITE)
            .keyFrames(new KeyFrame(Duration.seconds(0), new KeyValue(translate, -50)),
                    new KeyFrame(Duration.seconds(2), new KeyValue(translate, 250)))
            .build().play();
}

From source file:com.sunkur.springjavafxcontroller.screen.ScreensContoller.java

private boolean swapScreen(final Parent root) {
    final Group rootGroup = getScreenRoot();
    final DoubleProperty opacity = rootGroup.opacityProperty();
    if (!isScreenEmpty()) {

        Timeline fade = new Timeline(new KeyFrame(Duration.ZERO, new KeyValue(opacity, 1.0)),
                new KeyFrame(new Duration(250), new EventHandler<ActionEvent>() {
                    @Override// w  ww .jav  a  2 s .c o m
                    public void handle(ActionEvent t) {
                        rootGroup.getChildren().remove(0);

                        rootGroup.getChildren().add(0, root);
                        Timeline fadeIn = new Timeline(new KeyFrame(Duration.ZERO, new KeyValue(opacity, 0.0)),
                                new KeyFrame(new Duration(350), new KeyValue(opacity, 1.0)));
                        fadeIn.play();
                    }
                }, new KeyValue(opacity, 0.0)));
        fade.play();
        return true;
    } else {
        opacity.set(0.0);
        rootGroup.getChildren().add(0, root);
        Timeline fadeIn = new Timeline(new KeyFrame(Duration.ZERO, new KeyValue(opacity, 0.0)),
                new KeyFrame(new Duration(350), new KeyValue(opacity, 1.0)));
        fadeIn.play();
    }

    if (!this.stage.isShowing()) {
        this.stage.show();
    }
    return true;
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Group p = new Group();
    Scene scene = new Scene(p);
    stage.setScene(scene);/* w ww  .ja v  a2  s.  c o m*/
    stage.setWidth(500);
    stage.setHeight(500);
    p.setTranslateX(80);
    p.setTranslateY(80);

    //create a circle with effect
    final Circle circle = new Circle(20, Color.rgb(156, 216, 255));
    circle.setEffect(new Lighting());
    //create a text inside a circle
    final Text text = new Text(i.toString());
    text.setStroke(Color.BLACK);
    //create a layout for circle with text inside
    final StackPane stack = new StackPane();
    stack.getChildren().addAll(circle, text);
    stack.setLayoutX(30);
    stack.setLayoutY(30);

    p.getChildren().add(stack);
    stage.show();

    //create a timeline for moving the circle
    timeline = new Timeline();
    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.setAutoReverse(true);

    //You can add a specific action when each frame is started.
    timer = new AnimationTimer() {
        @Override
        public void handle(long l) {
            text.setText(i.toString());
            i++;
        }
    };

    //create a keyValue with factory: scaling the circle 2times
    KeyValue keyValueX = new KeyValue(stack.scaleXProperty(), 2);
    KeyValue keyValueY = new KeyValue(stack.scaleYProperty(), 2);

    //create a keyFrame, the keyValue is reached at time 2s
    Duration duration = Duration.millis(2000);
    //one can add a specific action when the keyframe is reached
    EventHandler onFinished = new EventHandler<ActionEvent>() {
        public void handle(ActionEvent t) {
            stack.setTranslateX(java.lang.Math.random() * 200 - 100);
            //reset counter
            i = 0;
        }
    };

    KeyFrame keyFrame = new KeyFrame(duration, onFinished, keyValueX, keyValueY);

    //add the keyframe to the timeline
    timeline.getKeyFrames().add(keyFrame);

    timeline.play();
    timer.start();
}

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   ww w  . ja  va  2 s.  c  om*/
    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: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. j av a 2s.  c om*/
    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 a  v a2s.  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 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);
                    }/*w w w.  j a  va  2 s  .  c  om*/

                    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);
}

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);//from   ww w  . ja  v a2 s  .  co m
                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();
            }));
}