Java Code Examples for javafx.animation.Timeline#setOnFinished()

The following examples show how to use javafx.animation.Timeline#setOnFinished() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Scene1Controller.java    From JavaFX-Tutorial-Codes with Apache License 2.0 7 votes vote down vote up
@FXML
private void loadSecond(ActionEvent event) throws IOException {
    Parent root = FXMLLoader.load(getClass().getResource("/javafx/scene/transition/scene2/scene2.fxml"));
    Scene scene = button.getScene();
    root.translateYProperty().set(scene.getHeight());

    parentContainer.getChildren().add(root);

    Timeline timeline = new Timeline();
    KeyValue kv = new KeyValue(root.translateYProperty(), 0, Interpolator.EASE_IN);
    KeyFrame kf = new KeyFrame(Duration.seconds(1), kv);
    timeline.getKeyFrames().add(kf);
    timeline.setOnFinished(t -> {
        parentContainer.getChildren().remove(anchorRoot);
    });
    timeline.play();
}
 
Example 2
Source File: FadeAnimation.java    From JavaFX-Chat with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 * @return a constructed instance of a dismiss fade animation
 */
private Timeline setupDismissAnimation() {

    Timeline tl = new Timeline();

    //At this stage the opacity is already at 1.0

    //Lowers the opacity to 0.0 within 2000 milliseconds
    KeyValue kv1 = new KeyValue(stage.opacityProperty(), 0.0);
    KeyFrame kf1 = new KeyFrame(Duration.millis(2000), kv1);

    tl.getKeyFrames().addAll(kf1);

    //Action to be performed when the animation has finished
    tl.setOnFinished(e -> {
        trayIsShowing = false;
        stage.close();
        stage.setLocation(stage.getBottomRight());
    });

    return tl;
}
 
Example 3
Source File: TicTacToeApp.java    From FXGLGames with MIT License 6 votes vote down vote up
private void playWinAnimation(TileCombo combo) {
    Line line = new Line();
    line.setStartX(combo.getTile1().getCenter().getX());
    line.setStartY(combo.getTile1().getCenter().getY());
    line.setEndX(combo.getTile1().getCenter().getX());
    line.setEndY(combo.getTile1().getCenter().getY());
    line.setStroke(Color.YELLOW);
    line.setStrokeWidth(3);

    getGameScene().addUINode(line);

    Timeline timeline = new Timeline();
    timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(1),
            new KeyValue(line.endXProperty(), combo.getTile3().getCenter().getX()),
            new KeyValue(line.endYProperty(), combo.getTile3().getCenter().getY())));
    timeline.setOnFinished(e -> gameOver(combo.getWinSymbol()));
    timeline.play();
}
 
Example 4
Source File: TicTacToeApp.java    From FXGLGames with MIT License 6 votes vote down vote up
private void playWinAnimation(TileCombo combo) {
    Line line = new Line();
    line.setStartX(combo.getTile1().getCenter().getX());
    line.setStartY(combo.getTile1().getCenter().getY());
    line.setEndX(combo.getTile1().getCenter().getX());
    line.setEndY(combo.getTile1().getCenter().getY());
    line.setStroke(Color.YELLOW);
    line.setStrokeWidth(3);

    getGameScene().addUINode(line);

    Timeline timeline = new Timeline();
    timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(1),
            new KeyValue(line.endXProperty(), combo.getTile3().getCenter().getX()),
            new KeyValue(line.endYProperty(), combo.getTile3().getCenter().getY())));
    timeline.setOnFinished(e -> gameOver(combo.getWinSymbol()));
    timeline.play();
}
 
Example 5
Source File: Transitions.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
private void removeEffect(Node node, int duration) {
    if (node != null) {
        node.setMouseTransparent(false);
        removeEffectTimeLine = new Timeline();
        GaussianBlur blur = (GaussianBlur) node.getEffect();
        if (blur != null) {
            KeyValue kv1 = new KeyValue(blur.radiusProperty(), 0.0);
            KeyFrame kf1 = new KeyFrame(Duration.millis(getDuration(duration)), kv1);
            removeEffectTimeLine.getKeyFrames().add(kf1);

            ColorAdjust darken = (ColorAdjust) blur.getInput();
            KeyValue kv2 = new KeyValue(darken.brightnessProperty(), 0.0);
            KeyFrame kf2 = new KeyFrame(Duration.millis(getDuration(duration)), kv2);
            removeEffectTimeLine.getKeyFrames().add(kf2);
            removeEffectTimeLine.setOnFinished(actionEvent -> {
                node.setEffect(null);
                removeEffectTimeLine = null;
            });
            removeEffectTimeLine.play();
        } else {
            node.setEffect(null);
            removeEffectTimeLine = null;
        }
    }
}
 
Example 6
Source File: ChartData.java    From OEE-Designer with MIT License 6 votes vote down vote up
public ChartData(final String NAME, final double VALUE, final Color FILL_COLOR, final Color STROKE_COLOR, final Color TEXT_COLOR, final Instant TIMESTAMP, final boolean ANIMATED, final long ANIMATION_DURATION) {
    name              = NAME;
    value             = VALUE;
    oldValue          = 0;
    fillColor         = FILL_COLOR;
    strokeColor       = STROKE_COLOR;
    textColor         = TEXT_COLOR;
    timestamp         = TIMESTAMP;
    currentValue      = new DoublePropertyBase(value) {
        @Override protected void invalidated() {
            oldValue = value;
            value    = get();
            fireChartDataEvent(UPDATE_EVENT);
        }
        @Override public Object getBean() { return ChartData.this; }
        @Override public String getName() { return "currentValue"; }
    };
    timeline          = new Timeline();
    animated          = ANIMATED;
    animationDuration = ANIMATION_DURATION;

    timeline.setOnFinished(e -> fireChartDataEvent(FINISHED_EVENT));
}
 
Example 7
Source File: Notifications.java    From yfiton with Apache License 2.0 6 votes vote down vote up
private Timeline createHideTimeline(final Popup popup, NotificationBar bar, final Pos p, Duration startDelay, Notifications notification) {
    KeyValue fadeOutBegin = new KeyValue(bar.opacityProperty(), 1.0);
    KeyValue fadeOutEnd = new KeyValue(bar.opacityProperty(), 0.0);

    KeyFrame kfBegin = new KeyFrame(Duration.ZERO, fadeOutBegin);
    KeyFrame kfEnd = new KeyFrame(Duration.millis(500), fadeOutEnd);

    Timeline timeline = new Timeline(kfBegin, kfEnd);
    timeline.setDelay(startDelay);
    timeline.setOnFinished(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            hide(popup, p);
            notification.onHideAction.handle(e);
        }
    });

    return timeline;
}
 
Example 8
Source File: Notifications.java    From oim-fx with MIT License 6 votes vote down vote up
private Timeline createHideTimeline(final Popup popup, NotificationBar bar, final Pos p, Duration startDelay) {
    KeyValue fadeOutBegin = new KeyValue(bar.opacityProperty(), 1.0);
    KeyValue fadeOutEnd = new KeyValue(bar.opacityProperty(), 0.0);

    KeyFrame kfBegin = new KeyFrame(Duration.ZERO, fadeOutBegin);
    KeyFrame kfEnd = new KeyFrame(Duration.millis(500), fadeOutEnd);

    Timeline timeline = new Timeline(kfBegin, kfEnd);
    timeline.setDelay(startDelay);
    timeline.setOnFinished(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            hide(popup, p);
        }
    });

    return timeline;
}
 
Example 9
Source File: ChartLayoutAnimator.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
/**
 * Play a animation containing the given keyframes.
 *
 * @param keyFrames The keyframes to animate
 * @return A id reference to the animation that can be used to stop the animation if needed
 */
public Object animate(KeyFrame... keyFrames) {
    Timeline t = new Timeline();
    t.setAutoReverse(false);
    t.setCycleCount(1);
    t.getKeyFrames().addAll(keyFrames);
    t.setOnFinished(this);
    // start animation timer if needed
    if (activeTimeLines.isEmpty())
        start();
    // get id and add to map
    activeTimeLines.put(t, t);
    // play animation
    t.play();
    return t;
}
 
Example 10
Source File: SpriteView.java    From quantumjava with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void moveTo(Main.Location loc) {
    walking = new Timeline(Animation.INDEFINITE,
        new KeyFrame(Duration.seconds(.001), new KeyValue(direction, location.getValue().directionTo(loc))),
        new KeyFrame(Duration.seconds(.002), new KeyValue(location, loc)),
        new KeyFrame(Duration.seconds(1), new KeyValue(translateXProperty(), loc.getX() * Main.CELL_SIZE)),
        new KeyFrame(Duration.seconds(1), new KeyValue(translateYProperty(), loc.getY() * Main.CELL_SIZE)),
        new KeyFrame(Duration.seconds(.25), new KeyValue(frame, 0)),
        new KeyFrame(Duration.seconds(.5), new KeyValue(frame, 1)),
        new KeyFrame(Duration.seconds(.75), new KeyValue(frame, 2)),
        new KeyFrame(Duration.seconds(1), new KeyValue(frame, 1))
    );
    walking.setOnFinished(e -> {
        if (arrivalHandler != null) {
            arrivalHandler.handle(e);
        }
    });
    Platform.runLater(walking::play);
}
 
Example 11
Source File: ZoneOverlay_Stage.java    From Path-of-Leveling with MIT License 5 votes vote down vote up
public void hidePanel(){



        WritableValue<Double> writableWidth = new WritableValue<Double>() {
            @Override
            public Double getValue() {

                //return getHeight();
                return getY();
            }

            @Override
            public void setValue(Double value)
            {
                //setHeight(value);
                setY(value);
            }
        };
         
        Timeline timeline = new Timeline();
        KeyFrame endFrame = new KeyFrame(Duration.millis(500), new KeyValue(writableWidth, -256d));
        timeline.getKeyFrames().add(endFrame);
        timeline.setOnFinished(e -> Platform.runLater(() -> {
            //System.out.println("Ending");
            isVisible = false; this.hide();}));
        timeline.play();
    }
 
Example 12
Source File: AddGem_Controller.java    From Path-of-Leveling with MIT License 5 votes vote down vote up
@FXML
private void toggleFilters(){
    WritableValue<Double> writableWidth = new WritableValue<Double>() {
        @Override
        public Double getValue() {

            //return getHeight();
            return AnchorPane.getTopAnchor(contentPanel);
        }

        @Override
        public void setValue(Double value)
        {
            //setHeight(value);
            AnchorPane.setTopAnchor(contentPanel, value);
        }
    };


    Timeline slideIn = new Timeline();

    KeyValue kv = new KeyValue(writableWidth, 43d);
    KeyFrame kf_slideIn = new KeyFrame(Duration.millis(400), kv);
    slideIn.getKeyFrames().addAll(kf_slideIn);

    slideIn.setOnFinished(e -> Platform.runLater(() -> {filtersPaneBig.setVisible(false);
        filtersPaneSmall.setVisible(true); setUpTabs();}));

    slideIn.play();

    bTransferringText = true;
    searchArea1.setText(searchArea.getText());
    bTransferringText = false;
}
 
Example 13
Source File: AddGem_Controller.java    From Path-of-Leveling with MIT License 5 votes vote down vote up
@FXML
private void toggleFiltersVisible(){
    WritableValue<Double> writableWidth = new WritableValue<Double>() {
        @Override
        public Double getValue() {

            //return getHeight();
            return AnchorPane.getTopAnchor(contentPanel);
        }

        @Override
        public void setValue(Double value)
        {
            //setHeight(value);
            AnchorPane.setTopAnchor(contentPanel, value);
        }
    };


    Timeline slideIn = new Timeline();

    KeyValue kv = new KeyValue(writableWidth, 153d);
    KeyFrame kf_slideIn = new KeyFrame(Duration.millis(400), kv);
    slideIn.getKeyFrames().addAll(kf_slideIn);

    slideIn.setOnFinished(e -> Platform.runLater(() -> {filtersPaneBig.setVisible(true);
        filtersPaneSmall.setVisible(false);}));

    slideIn.play();

    bTransferringText = true;
    searchArea.setText(searchArea1.getText());
    bTransferringText = false;
}
 
Example 14
Source File: Toast.java    From DevToolBox with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void doShow() {
    LOGGER.info("show toast: {}", this);
    if (window != null) {
        if (autoCenter) {
            connectAutoCenterHandler();
        }
        if (Double.isNaN(screenX) || Double.isNaN(screenY)) {
            super.show(window);
        } else {
            super.show(window, screenX, screenY);
        }
    } else { // anchor
        if (autoCenter) {
            Scene scene = anchor.getScene();
            if (scene != null) {
                window = scene.getWindow();
            }
            if (window == null) {
                throw new IllegalStateException("anchor node is not attached to a window");
            }
            connectAutoCenterHandler();
        }
        super.show(anchor, Double.isNaN(screenX) ? 0.0 : screenX, Double.isNaN(screenY) ? 0.0 : screenY);
    }
    if (isAutoHide() && !duration.isIndefinite()) {
        hideTimer = new Timeline(new KeyFrame(duration));
        hideTimer.setOnFinished((ActionEvent event) -> {
            hideTimer = null;
            Toast.this.hide();
        });
        hideTimer.playFromStart();
    }
    FadeTransition transition = new FadeTransition(fadeInDuration, content);
    transition.setFromValue(0.0);
    transition.setToValue(contentOpacity);
    transition.play();
}
 
Example 15
Source File: SlideCheckBoxSkin.java    From JFX8CustomControls with Apache License 2.0 5 votes vote down vote up
private Timeline getDeselectTimeline() {
    final KeyValue kvThumbStartTranslateDeselect = new KeyValue(thumb.translateXProperty(), 24);
    final KeyValue kvThumbEndTranslateDeselect   = new KeyValue(thumb.translateXProperty(), -24);

    final KeyValue kvMarkStartOpacityDeselect    = new KeyValue(markBox.opacityProperty(), 1);
    final KeyValue kvMarkEndOpacityDeselect      = new KeyValue(markBox.opacityProperty(), 0);

    final KeyValue kvMarkStartScaleXDeselect     = new KeyValue(markBox.scaleXProperty(), 1);
    final KeyValue kvMarkEndScaleXDeselect       = new KeyValue(markBox.scaleXProperty(), 0);

    final KeyValue kvMarkStartScaleYDeselect     = new KeyValue(markBox.scaleYProperty(), 1);
    final KeyValue kvMarkEndScaleYDeselect       = new KeyValue(markBox.scaleYProperty(), 0);

    final KeyValue kvCrossStartOpacityDeselect   = new KeyValue(crossBox.opacityProperty(), 0);
    final KeyValue kvCrossEndOpacityDeselect     = new KeyValue(crossBox.opacityProperty(), 1);

    final KeyValue kvCrossStartScaleXDeselect    = new KeyValue(crossBox.scaleXProperty(), 0);
    final KeyValue kvCrossEndScaleXDeselect      = new KeyValue(crossBox.scaleXProperty(), 1);

    final KeyValue kvCrossStartScaleYDeselect    = new KeyValue(crossBox.scaleYProperty(), 0);
    final KeyValue kvCrossEndScaleYDeselect      = new KeyValue(crossBox.scaleYProperty(), 1);

    final KeyValue kvCrossRotateStart            = new KeyValue(crossBox.rotateProperty(), 0);
    final KeyValue kvCrossRotateEnd              = new KeyValue(crossBox.rotateProperty(), 360);

    final KeyFrame kfStart       = new KeyFrame(Duration.ZERO, kvThumbStartTranslateDeselect,
                                                kvMarkStartOpacityDeselect, kvMarkStartScaleXDeselect, kvMarkStartScaleYDeselect,
                                                kvCrossStartOpacityDeselect, kvCrossStartScaleXDeselect, kvCrossStartScaleYDeselect);
    final KeyFrame kfEnd         = new KeyFrame(Duration.millis(180), kvThumbEndTranslateDeselect,
                                                kvMarkEndOpacityDeselect, kvMarkEndScaleXDeselect, kvMarkEndScaleYDeselect,
                                                kvCrossEndOpacityDeselect, kvCrossEndScaleXDeselect, kvCrossEndScaleYDeselect);
    final KeyFrame kfRotateStart = new KeyFrame(Duration.millis(250), kvCrossRotateStart);
    final KeyFrame kfRotateEnd   = new KeyFrame(Duration.millis(750), kvCrossRotateEnd);

    final Timeline timeline = new Timeline();
    timeline.getKeyFrames().setAll(kfStart, kfEnd, kfRotateStart, kfRotateEnd);
    timeline.setOnFinished(actionEvent -> crossBox.setRotate(0));
    return timeline;
}
 
Example 16
Source File: PeerInfoWithTagEditor.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void animateHide(Runnable onFinishedHandler) {
    if (GlobalSettings.getUseAnimations()) {
        double duration = getDuration(300);
        Interpolator interpolator = Interpolator.SPLINE(0.25, 0.1, 0.25, 1);

        gridPane.setRotationAxis(Rotate.X_AXIS);
        Camera camera = gridPane.getScene().getCamera();
        gridPane.getScene().setCamera(new PerspectiveCamera());

        Timeline timeline = new Timeline();
        ObservableList<KeyFrame> keyFrames = timeline.getKeyFrames();
        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)
        ));
        timeline.setOnFinished(event -> {
            gridPane.setRotate(0);
            gridPane.setRotationAxis(Rotate.Z_AXIS);
            gridPane.getScene().setCamera(camera);
            onFinishedHandler.run();
        });
        timeline.play();
    } else {
        onFinishedHandler.run();
    }
}
 
Example 17
Source File: GemOverlay_Stage.java    From Path-of-Leveling with MIT License 4 votes vote down vote up
public void fade(){
    if (betaUI) {
        controller_beta.show();
    } else {
        show();
    }
    //apply fade

    WritableValue<Double> opacity = new WritableValue<Double>() {
        @Override
        public Double getValue() {
            if (betaUI) {
                return controller_beta.getOpacity();
            } else {
                return getOpacity();
            }
        }

        @Override
        public void setValue(Double value) {
            if (betaUI) {
                controller_beta.fade(value);
            } else {
                setOpacity(value);
            }
        }
    };

    Timeline fadeIn = new Timeline();
    Timeline delay = new Timeline();
    Timeline fadeOut = new Timeline();

    KeyValue kv = new KeyValue(opacity, 1d);
    KeyFrame kf_slideIn = new KeyFrame(Duration.millis(1000), kv);

    fadeIn.getKeyFrames().add(kf_slideIn);
    fadeIn.setOnFinished(e -> Platform.runLater(() -> delay.play()));

    KeyFrame kf_delay = new KeyFrame(Duration.millis(Preferences_Controller.level_slider * 1000));
    delay.getKeyFrames().addAll(kf_delay);


    delay.setOnFinished(e -> Platform.runLater(() -> fadeOut.play()));

    KeyValue kv2 = new KeyValue(opacity, 0d);
    KeyFrame kf_slideIn2 = new KeyFrame(Duration.millis(1000), kv2);

    fadeOut.getKeyFrames().add(kf_slideIn2);
    fadeOut.setOnFinished(e -> Platform.runLater(() -> {
        //System.out.println("Ending");
        isPlaying = false;
        if (betaUI) {
            controller_beta.hide();
            controller_beta.defaultTitle();
        } else {
            this.hide();
        }
    }));

    fadeIn.play();
    isPlaying = true;
}
 
Example 18
Source File: ZoneOverlay_Stage.java    From Path-of-Leveling with MIT License 4 votes vote down vote up
public void showPanel(){
    isVisible = true;
    this.show();
    this.setX(prefX);
    //this.setY(prefY);
    //this.setHeight(0);

    this.setY(prefY-256.0);



    WritableValue<Double> writableWidth = new WritableValue<Double>() {
        @Override
        public Double getValue() {

            //return getHeight();
            return getY();
        }

        @Override
        public void setValue(Double value)
        {
            //setHeight(value);
            setY(value);
        }
    };


    Timeline slideIn = new Timeline();
   
    KeyValue kv = new KeyValue(writableWidth, 0d);
    KeyFrame kf_slideIn = new KeyFrame(Duration.millis(500), kv);
    slideIn.getKeyFrames().addAll(kf_slideIn);
    if(Preferences_Controller.zones_slider>=1){
        KeyFrame kf_delay = new KeyFrame(Duration.millis(Preferences_Controller.zones_slider * 1000));
        slideIn.getKeyFrames().addAll(kf_slideIn,kf_delay);

        slideIn.setOnFinished(e -> Platform.runLater(() -> hidePanel()));
    }else{
        slideIn.getKeyFrames().addAll(kf_slideIn);
    }
    slideIn.play();
}
 
Example 19
Source File: DoodleTrace.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Constructor taking the application's name.
 */
public DoodleTrace() {

    // Create the drawing surface
    Pane drawSurface = new Pane();
    setCenter(drawSurface);

    // Initialize draw path
    drawPath = new Path();
    drawPath.setStrokeWidth(3);
    drawPath.setStroke(Color.BLACK);
    drawSurface.getChildren().add(drawPath);

    // Initialize trace path
    tracePath = new Path();
    tracePath.setStrokeWidth(3);
    tracePath.setStroke(Color.BLACK);
    drawSurface.getChildren().add(tracePath);

    // Ball tracer
    RadialGradient gradient1 = new RadialGradient(
            0,
            0,
            .5,
            .5,
            .55,
            true,
            CycleMethod.NO_CYCLE,
            new Stop(0, Color.RED),
            new Stop(1, Color.BLACK));

    // Create a ball
    ball = new Circle(100, 100, 20, gradient1);

    // Add ball
    drawSurface.getChildren().add(ball);

    // Animation responsible for tracing the doodle
    tracerTimeline = new Timeline();

    // Flag to prevent user from doodling during animation
    tracerTimeline.setOnFinished(ae3 -> animating = false);

    if (Platform.isDesktop()) {
        applyMouseInput(drawSurface);
    } else if (Platform.isAndroid() || Platform.isIOS()) {
        applyTouchInput(drawSurface);
    }
}
 
Example 20
Source File: FadeAnimation.java    From JavaFX-Chat with GNU General Public License v3.0 4 votes vote down vote up
/**
 *
 * @return a constructed instance of a show fade animation
 */
private Timeline setupShowAnimation() {

    Timeline tl = new Timeline();

    //Sets opacity to 0.0 instantly which is pretty much invisible
    KeyValue kvOpacity = new KeyValue(stage.opacityProperty(), 0.0);
    KeyFrame frame1 = new KeyFrame(Duration.ZERO, kvOpacity);

    //Sets opacity to 1.0 (fully visible) over the time of 3000 milliseconds.
    KeyValue kvOpacity2 = new KeyValue(stage.opacityProperty(), 1.0);
    KeyFrame frame2 = new KeyFrame(Duration.millis(3000), kvOpacity2);

    tl.getKeyFrames().addAll(frame1, frame2);

    tl.setOnFinished(e -> trayIsShowing = true);

    return tl;
}