List of usage examples for javafx.animation Timeline play
public void play()
From source file:Main.java
@Override public void start(Stage stage) { Text msg = new Text("java2s.com"); msg.setTextOrigin(VPos.TOP);//from w ww . j a va 2s . co m 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: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/* ww w .j a v a 2s.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) { final NumberAxis xAxis = new NumberAxis(); final CategoryAxis yAxis = new CategoryAxis(); final BarChart<Number, String> bc = new BarChart<Number, String>(xAxis, yAxis); bc.setTitle("Summary"); xAxis.setLabel("Value"); xAxis.setTickLabelRotation(90);// w w w. j ava2s . c om yAxis.setLabel("Item"); XYChart.Series series1 = new XYChart.Series(); series1.setName("2003"); series1.getData().add(new XYChart.Data(2, itemA)); series1.getData().add(new XYChart.Data(20, itemB)); series1.getData().add(new XYChart.Data(10, itemC)); XYChart.Series series2 = new XYChart.Series(); series2.setName("2004"); series2.getData().add(new XYChart.Data(50, itemA)); series2.getData().add(new XYChart.Data(41, itemB)); series2.getData().add(new XYChart.Data(45, itemC)); XYChart.Series series3 = new XYChart.Series(); series3.setName("2005"); series3.getData().add(new XYChart.Data(45, itemA)); series3.getData().add(new XYChart.Data(44, itemB)); series3.getData().add(new XYChart.Data(18, itemC)); Timeline tl = new Timeline(); tl.getKeyFrames().add(new KeyFrame(Duration.millis(500), new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { for (XYChart.Series<Number, String> series : bc.getData()) { for (XYChart.Data<Number, String> data : series.getData()) { data.setXValue(Math.random() * 100); } } } })); tl.setCycleCount(Animation.INDEFINITE); tl.play(); Scene scene = new Scene(bc, 800, 600); bc.getData().addAll(series1, series2, series3); stage.setScene(scene); stage.show(); }
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);// www . j a v a2 s . c o 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: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 w w.j av a 2 s . co m 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:Main.java
private void addBouncyBall(final Scene scene) { final Circle ball = new Circle(100, 100, 20); final Group root = (Group) scene.getRoot(); root.getChildren().add(ball);// ww w.ja v a2 s . c o m Timeline tl = new Timeline(); tl.setCycleCount(Animation.INDEFINITE); KeyFrame moveBall = new KeyFrame(Duration.seconds(.0200), new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { double xMin = ball.getBoundsInParent().getMinX(); double yMin = ball.getBoundsInParent().getMinY(); double xMax = ball.getBoundsInParent().getMaxX(); double yMax = ball.getBoundsInParent().getMaxY(); if (xMin < 0 || xMax > scene.getWidth()) { dx = dx * -1; } if (yMin < 0 || yMax > scene.getHeight()) { dy = dy * -1; } ball.setTranslateX(ball.getTranslateX() + dx); ball.setTranslateY(ball.getTranslateY() + dy); } }); tl.getKeyFrames().add(moveBall); tl.play(); }
From source file:mesclasses.view.RootLayoutController.java
private void displayNotification(int type, String texte) { notificationMessageLabel.setText(texte); notificationPane.getStyleClass().clear(); CssUtil.removeClass(deleteNotifBtn, "notif-warning"); CssUtil.removeClass(deleteNotifBtn, "notif-error"); Double timeDisplayed = 3.0D;//from w w w. ja va2s . c o m switch (type) { case MessageEvent.SUCCESS: CssUtil.addClass(notificationPane, "notif-success"); deleteNotifBtn.setManaged(false); deleteNotifBtn.setVisible(false); notificationTitleLabel.setText("SUCCES"); break; case MessageEvent.WARNING: CssUtil.addClass(notificationPane, "notif-warning"); CssUtil.addClass(deleteNotifBtn, "notif-warning"); notificationTitleLabel.setText("ATTENTION"); break; case MessageEvent.ERROR: CssUtil.addClass(notificationPane, "notif-error"); CssUtil.addClass(deleteNotifBtn, "notif-error"); notificationTitleLabel.setText("ERREUR"); timeDisplayed = 0.0; break; } notificationPane.setManaged(true); notificationPane.setVisible(true); if (timeDisplayed > 0.0) { FadeTransition ft = new FadeTransition(Duration.millis(150), notificationPane); ft.setFromValue(0.0); ft.setToValue(1.0); ft.setCycleCount(1); ft.play(); Timeline timeline = new Timeline(); timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(timeDisplayed), (ActionEvent event) -> { FadeTransition ft2 = new FadeTransition(Duration.millis(150), notificationPane); ft2.setFromValue(1.0); ft2.setToValue(0.0); ft2.setCycleCount(1); ft2.play(); ft2.setOnFinished((ActionEvent event1) -> { notificationPane.setManaged(false); notificationPane.setVisible(false); }); })); timeline.play(); } }
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// w ww . ja va 2 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: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. ja v a 2 s. c om 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
private void updateAILevelLabel(boolean forceUpdate) { double sliderPos = 100 * Math.round(aiLevelSlider.getValue() * 3.0 / 100.0) / 3.0; if (sliderPos != aiLevelLabelPositionProperty.get() || forceUpdate) { aiLevelLabelPositionProperty.set(sliderPos); // request focus of the current ai label for accessibility aiLevelLabelHBox.getChildren().get((int) (sliderPos * 3 / 100)).requestFocus(); updateAccessibleTexts();/*from ww w.ja v a 2s . c o m*/ // get the slider position double[] xDouble = new double[] { 0, 100.0 / 3.0, 200.0 / 3.0, 300.0 / 3.0 }; double[] translationYDouble = new double[4]; double[] widthYDouble = new double[4]; double[] trueWidthYDouble = new double[4]; for (int i = 0; i < translationYDouble.length; i++) { // {-getAILevelLabelCenter(0), -getAILevelLabelCenter(1), -getAILevelLabelCenter(2), -getAILevelLabelCenter(3)}; translationYDouble[i] = -getAILevelLabelCenter(i); widthYDouble[i] = Math.max(90, ((Label) aiLevelLabelHBox.getChildren().get(i)).getWidth() + 8 * aiLevelLabelHBox.getSpacing()); trueWidthYDouble[i] = ((Label) aiLevelLabelHBox.getChildren().get(i)).getWidth(); } SplineInterpolator splineInterpolator = new SplineInterpolator(); PolynomialSplineFunction translateFunction = splineInterpolator.interpolate(xDouble, translationYDouble); PolynomialSplineFunction widthFunction = splineInterpolator.interpolate(xDouble, widthYDouble); PolynomialSplineFunction trueWidthFunction = splineInterpolator.interpolate(xDouble, trueWidthYDouble); KeyValue hBoxLayoutXKeyValue1 = new KeyValue(aiLevelLabelHBox.layoutXProperty(), aiLevelLabelHBox.getLayoutX(), Interpolator.EASE_BOTH); KeyValue aiLevelLabelClipRectangleWidthKeyValue1 = new KeyValue( aiLevelLabelClipRectangle.widthProperty(), aiLevelLabelClipRectangle.getWidth(), Interpolator.EASE_BOTH); KeyValue aiLevelLabelClipRectangleXKeyValue1 = new KeyValue(aiLevelLabelClipRectangle.xProperty(), aiLevelLabelClipRectangle.getX(), Interpolator.EASE_BOTH); KeyValue aiLevelCenterLineStartXKeyValue1 = new KeyValue(aiLevelCenterLine.startXProperty(), aiLevelCenterLine.getStartX(), Interpolator.EASE_BOTH); KeyValue aiLevelCenterLineEndXKeyValue1 = new KeyValue(aiLevelCenterLine.endXProperty(), aiLevelCenterLine.getEndX(), Interpolator.EASE_BOTH); KeyFrame keyFrame1 = new KeyFrame(Duration.seconds(0), hBoxLayoutXKeyValue1, aiLevelLabelClipRectangleWidthKeyValue1, aiLevelLabelClipRectangleXKeyValue1, aiLevelCenterLineStartXKeyValue1, aiLevelCenterLineEndXKeyValue1); double interpolatedLabelWidth = trueWidthFunction.value(sliderPos); KeyValue hBoxLayoutXKeyValue2 = new KeyValue(aiLevelLabelHBox.layoutXProperty(), translateFunction.value(sliderPos), Interpolator.EASE_BOTH); KeyValue aiLevelLabelClipRectangleWidthKeyValue2 = new KeyValue( aiLevelLabelClipRectangle.widthProperty(), widthFunction.value(sliderPos), Interpolator.EASE_BOTH); KeyValue aiLevelLabelClipRectangleXKeyValue2 = new KeyValue(aiLevelLabelClipRectangle.xProperty(), aiLevelLabelPane.getWidth() / 2 - widthFunction.value(sliderPos) / 2, Interpolator.EASE_BOTH); KeyValue aiLevelCenterLineStartXKeyValue2 = new KeyValue(aiLevelCenterLine.startXProperty(), (aiLevelLabelPane.getWidth() - interpolatedLabelWidth) / 2, Interpolator.EASE_BOTH); KeyValue aiLevelCenterLineEndXKeyValue2 = new KeyValue(aiLevelCenterLine.endXProperty(), (aiLevelLabelPane.getWidth() + interpolatedLabelWidth) / 2, Interpolator.EASE_BOTH); KeyFrame keyFrame2 = new KeyFrame(Duration.seconds(animationSpeed * 0.9), hBoxLayoutXKeyValue2, aiLevelLabelClipRectangleWidthKeyValue2, aiLevelLabelClipRectangleXKeyValue2, aiLevelCenterLineStartXKeyValue2, aiLevelCenterLineEndXKeyValue2); Timeline timeline = new Timeline(keyFrame1, keyFrame2); timeline.play(); } }