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

The following examples show how to use javafx.animation.Timeline#play() . 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: GlobalTransformManager.java    From paintera with GNU General Public License v2.0 7 votes vote down vote up
public synchronized void setTransform(final AffineTransform3D affine, final Duration duration) {
	if (duration.toMillis() == 0.0) {
		setTransform(affine);
		return;
	}
	final Timeline timeline = new Timeline(60.0);
	timeline.setCycleCount(1);
	timeline.setAutoReverse(false);
	final AffineTransform3D currentState = this.affine.copy();
	final DoubleProperty progressProperty = new SimpleDoubleProperty(0.0);
	final SimilarityTransformInterpolator interpolator = new SimilarityTransformInterpolator(currentState, affine.copy());
	progressProperty.addListener((obs, oldv, newv) -> setTransform(interpolator.interpolateAt(newv.doubleValue())));
	final KeyValue kv = new KeyValue(progressProperty, 1.0, Interpolator.EASE_BOTH);
	timeline.getKeyFrames().add(new KeyFrame(duration, kv));
	timeline.play();
}
 
Example 2
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 3
Source File: SpinnerController.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void init() {
    Timeline timeline = new Timeline(
        new KeyFrame(
            Duration.ZERO,
            new KeyValue(blueSpinner.progressProperty(), 0),
            new KeyValue(greenSpinner.progressProperty(), 0)
        ),
        new KeyFrame(
            Duration.seconds(0.5),
            new KeyValue(greenSpinner.progressProperty(), 0.5)
        ),
        new KeyFrame(
            Duration.seconds(2),
            new KeyValue(blueSpinner.progressProperty(), 1),
            new KeyValue(greenSpinner.progressProperty(), 1)
        )
    );
    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.play();
}
 
Example 4
Source File: SpriteView.java    From quantumjava with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void startAnimation() {
    Timeline timeline = new Timeline(Animation.INDEFINITE,
        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))
    );
    timeline.onFinishedProperty().setValue(e -> timeline.play());
    timeline.play();
}
 
Example 5
Source File: ColorAnimationUtils.java    From graph-editor with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adds animated color properties to the given node that can be accessed from CSS.
 * 
 * @param node the node to be styled with animated colors
 * @param data a {@link AnimatedColor} object storing the animation parameters
 */
public static void animateColor(final Node node, final AnimatedColor data) {

    removeAnimation(node);

    final ObjectProperty<Color> baseColor = new SimpleObjectProperty<>();

    final KeyValue firstkeyValue = new KeyValue(baseColor, data.getFirstColor());
    final KeyValue secondKeyValue = new KeyValue(baseColor, data.getSecondColor());
    final KeyFrame firstKeyFrame = new KeyFrame(Duration.ZERO, firstkeyValue);
    final KeyFrame secondKeyFrame = new KeyFrame(data.getInterval(), secondKeyValue);
    final Timeline timeline = new Timeline(firstKeyFrame, secondKeyFrame);

    baseColor.addListener((v, o, n) -> {

        final int redValue = (int) (n.getRed() * 255);
        final int greenValue = (int) (n.getGreen() * 255);
        final int blueValue = (int) (n.getBlue() * 255);

        final String format = data.getProperty() + ": " + COLOR_FORMAT + ";";
        node.setStyle(String.format(format, redValue, greenValue, blueValue));
    });

    node.getProperties().put(TIMELINE_KEY, timeline);

    timeline.setAutoReverse(true);
    timeline.setCycleCount(Animation.INDEFINITE);
    timeline.play();
}
 
Example 6
Source File: CaptureSaveController.java    From logbook-kai with MIT License 5 votes vote down vote up
@FXML
void initialize() {
    // SplitPaneの分割サイズ
    Timeline x = new Timeline();
    x.getKeyFrames().add(new KeyFrame(Duration.millis(1), (e) -> {
        Tools.Conrtols.setSplitWidth(this.splitPane, this.getClass() + "#" + "splitPane");
    }));
    x.play();
    this.image.fitWidthProperty().bind(this.imageParent.widthProperty());
    this.image.fitHeightProperty().bind(this.imageParent.heightProperty());
}
 
Example 7
Source File: CarPane.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
/** Construct and animate a default CarPane */
CarPane() {
	drawCar();
	animation = new Timeline(
		new KeyFrame(Duration.millis(50), e -> moveCar()));
	animation.setCycleCount(Timeline.INDEFINITE);
	animation.play();
}
 
Example 8
Source File: JFXSnackbar.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
public void close() {
    if (openAnimation != null) {
        openAnimation.stop();
    }
    if (this.isVisible()) {
        if (pauseTransition != null) {
            pauseTransition.stop();
            pauseTransition = null;
        }
        Timeline closeAnimation = new Timeline(
            new KeyFrame(
                Duration.ZERO,
                e -> this.toFront(),
                new KeyValue(this.opacityProperty(), 1, easeInterpolator),
                new KeyValue(this.translateYProperty(), 0, easeInterpolator)
            ),
            new KeyFrame(
                Duration.millis(290),
                new KeyValue(this.visibleProperty(), true, Interpolator.EASE_BOTH)
            ),
            new KeyFrame(Duration.millis(300),
                e -> this.toBack(),
                new KeyValue(this.visibleProperty(), false, Interpolator.EASE_BOTH),
                new KeyValue(this.translateYProperty(),
                    this.getLayoutBounds().getHeight(),
                    easeInterpolator),
                new KeyValue(this.opacityProperty(), 0, easeInterpolator)
            )
        );
        closeAnimation.setCycleCount(1);
        closeAnimation.setOnFinished(e -> {
            resetPseudoClass();
            processSnackbar();
        });
        closeAnimation.play();
    }
}
 
Example 9
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 10
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 11
Source File: ClockSkin.java    From Enzo with Apache License 2.0 5 votes vote down vote up
private void moveMinutePointer(double newAngle) {
    final KeyValue kv = new KeyValue(currentMinuteAngle, newAngle, Interpolator.SPLINE(0.5, 0.4, 0.4, 1.0));
    final KeyFrame kf = new KeyFrame(Duration.millis(200), kv);
    timeline = new Timeline();
    timeline.getKeyFrames().add(kf);
    timeline.play();
}
 
Example 12
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 13
Source File: MarathonSplashScreen.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public Parent getContentPane() {
    VBox root = new VBox();
    root.setStyle("-fx-background-color:black");
    root.setId("marathonITESplashScreen");
    root.getStyleClass().add("marathonite-splash-screen");
    root.getChildren().addAll(FXUIUtils.getImage("marathon-splash"), createInfo());
    Timeline timeline = new Timeline(new KeyFrame(SPLASH_DISPLAY_TIME, (e) -> {
        dispose();
    }));
    timeline.play();
    return root;
}
 
Example 14
Source File: Zoomer.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
private void performZoom(Entry<Axis, ZoomState> zoomStateEntry, final boolean isZoomIn) {
    ZoomState zoomState = zoomStateEntry.getValue();
    if (zoomState.zoomRangeMax - zoomState.zoomRangeMin == 0) {
        LOGGER.atDebug().log("Cannot zoom in deeper than numerical precision");
        return;
    }

    Axis axis = zoomStateEntry.getKey();
    if (isZoomIn && ((axis.getSide().isHorizontal() && getAxisMode().allowsX()) || (axis.getSide().isVertical() && getAxisMode().allowsY()))) {
        // perform only zoom-in if axis is horizontal (or vertical) and corresponding horizontal (or vertical)
        // zooming is allowed
        axis.setAutoRanging(false);
    }

    if (isAnimated()) {
        if (!hasBoundedRange(axis)) {
            final Timeline xZoomAnimation = new Timeline();
            xZoomAnimation.getKeyFrames().setAll(
                    new KeyFrame(Duration.ZERO, new KeyValue(axis.minProperty(), axis.getMin()),
                            new KeyValue(axis.maxProperty(), axis.getMax())),
                    new KeyFrame(getZoomDuration(), new KeyValue(axis.minProperty(), zoomState.zoomRangeMin),
                            new KeyValue(axis.maxProperty(), zoomState.zoomRangeMax)));
            xZoomAnimation.play();
        }
    } else {
        if (!hasBoundedRange(axis)) {
            // only update if this axis is not bound to another (e.g. auto-range) managed axis)
            axis.set(zoomState.zoomRangeMin, zoomState.zoomRangeMax);
        }
    }

    if (!isZoomIn) {
        axis.setAutoRanging(zoomState.wasAutoRanging);
        axis.setAutoGrowRanging(zoomState.wasAutoGrowRanging);
    }
}
 
Example 15
Source File: FanPane.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
/**  Construct a FanPane */
public FanPane() {
	setPadding(new Insets(10, 10, 10, 10));
	circle.setStroke(Color.BLACK);
	circle.setFill(Color.WHITE);
	circle.centerXProperty().bind(widthProperty().divide(2));
	circle.centerYProperty().bind(heightProperty().divide(2));
	circle.radiusProperty().bind((heightProperty().divide(2)).multiply(.90));
	getBlades();
	getChildren().addAll(circle, paneForBlades);
	fan = new Timeline(
		new KeyFrame(Duration.millis(50), e -> spinFan()));
	fan.setCycleCount(Timeline.INDEFINITE);
	fan.play(); // Start animation
}
 
Example 16
Source File: DialogLoggerUtil.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * shows a message dialog just for a few given milliseconds
 *
 * @param parent
 * @param title
 * @param message
 * @param time
 */
public static void showMessageDialogForTime(String title, String message, long time) {
  Alert alert = new Alert(AlertType.INFORMATION, message);
  alert.setTitle(title);
  alert.show();
  Timeline idleTimer = new Timeline(new KeyFrame(Duration.millis(time), e -> alert.hide()));
  idleTimer.setCycleCount(1);
  idleTimer.play();
}
 
Example 17
Source File: SpriteView.java    From quantumjava with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void startValueAnimation() {
    Timeline timeline = new Timeline(Animation.INDEFINITE,
            new KeyFrame(Duration.seconds(.25), new KeyValue(value, 0)),
            new KeyFrame(Duration.seconds(.5), new KeyValue(value, 1)),
            new KeyFrame(Duration.seconds(.75), new KeyValue(value, 2)),
            new KeyFrame(Duration.seconds(1), new KeyValue(value, 1))
    );
    timeline.onFinishedProperty().setValue(e -> timeline.play());
    timeline.play();
}
 
Example 18
Source File: MissionLogController.java    From logbook-kai with MIT License 4 votes vote down vote up
@FXML
void initialize() {
    TableTool.setVisible(this.detail, this.getClass() + "#" + "detail");
    TableTool.setVisible(this.aggregate, this.getClass() + "#" + "aggregate");
    // SplitPaneの分割サイズ
    Timeline x = new Timeline();
    x.getKeyFrames().add(new KeyFrame(Duration.millis(1), (e) -> {
        Tools.Conrtols.setSplitWidth(this.splitPane1, this.getClass() + "#" + "splitPane1");
        Tools.Conrtols.setSplitWidth(this.splitPane2, this.getClass() + "#" + "splitPane2");
        Tools.Conrtols.setSplitWidth(this.splitPane3, this.getClass() + "#" + "splitPane3");
    }));
    x.play();

    // 集計
    this.collect.setShowRoot(false);
    this.collect.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    this.unit.setCellValueFactory(new TreeItemPropertyValueFactory<>("unit"));
    this.successGood.setCellValueFactory(new TreeItemPropertyValueFactory<>("successGood"));
    this.success.setCellValueFactory(new TreeItemPropertyValueFactory<>("success"));
    this.fail.setCellValueFactory(new TreeItemPropertyValueFactory<>("fail"));

    // 詳細
    SortedList<MissionLogDetail> sortedList = new SortedList<>(this.details);
    this.detail.setItems(this.details);
    sortedList.comparatorProperty().bind(this.detail.comparatorProperty());
    this.detail.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    this.detail.setOnKeyPressed(TableTool::defaultOnKeyPressedHandler);

    this.date.setCellValueFactory(new PropertyValueFactory<>("date"));
    this.name.setCellValueFactory(new PropertyValueFactory<>("name"));
    this.result.setCellValueFactory(new PropertyValueFactory<>("result"));
    this.fuel.setCellValueFactory(new PropertyValueFactory<>("fuel"));
    this.ammo.setCellValueFactory(new PropertyValueFactory<>("ammo"));
    this.metal.setCellValueFactory(new PropertyValueFactory<>("metal"));
    this.bauxite.setCellValueFactory(new PropertyValueFactory<>("bauxite"));
    this.item1name.setCellValueFactory(new PropertyValueFactory<>("item1name"));
    this.item1count.setCellValueFactory(new PropertyValueFactory<>("item1count"));
    this.item2name.setCellValueFactory(new PropertyValueFactory<>("item2name"));
    this.item2count.setCellValueFactory(new PropertyValueFactory<>("item2count"));

    // 集計
    SortedList<MissionAggregate> sortedList2 = new SortedList<>(this.aggregates);
    this.aggregate.setItems(this.aggregates);
    sortedList2.comparatorProperty().bind(this.aggregate.comparatorProperty());
    this.aggregate.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    this.aggregate.setOnKeyPressed(TableTool::defaultOnKeyPressedHandler);
    this.resource.setCellValueFactory(new PropertyValueFactory<>("resource"));
    this.count.setCellValueFactory(new PropertyValueFactory<>("count"));
    this.average.setCellValueFactory(new PropertyValueFactory<>("average"));

    this.readLog();
    this.setCollect();

    // 選択された時のリスナーを設定
    this.collect.getSelectionModel()
            .selectedItemProperty()
            .addListener(this::detail);
    this.aggregate.getSelectionModel()
            .selectedItemProperty()
            .addListener(this::chart);
}
 
Example 19
Source File: EditAxis.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
MyPopOver(final Axis axis, final boolean isHorizontal) {
    super(new AxisEditor(axis, isHorizontal));
    this.axis = axis;
    popOverShowStartTime = 0;

    super.setAutoHide(true);
    super.animatedProperty().bind(EditAxis.this.animatedProperty());
    EditAxis.this.zoomDurationProperty().addListener(fadeDurationListener);
    super.fadeInDurationProperty().set(EditAxis.this.getZoomDuration().multiply(2.0));
    super.fadeOutDurationProperty().set(EditAxis.this.getZoomDuration());

    setFadeInDuration(Duration.millis(1000));
    setFadeOutDuration(Duration.millis(500));
    switch (axis.getSide()) {
    case TOP:
        setArrowLocation(ArrowLocation.TOP_CENTER);
        break;
    case LEFT:
        setArrowLocation(ArrowLocation.LEFT_CENTER);
        break;
    case RIGHT:
        setArrowLocation(ArrowLocation.RIGHT_CENTER);
        break;
    case BOTTOM:
    default:
        setArrowLocation(ArrowLocation.BOTTOM_CENTER);
        break;
    }

    setOpacity(0.0);
    getRoot().setBackground(Background.EMPTY);
    // getRoot().setStyle("-fx-background-color: rgba(0, 255, 0, 1);");

    getScene().getStylesheets().add("plugin/editaxis.css");
    getStyleClass().add("axis-editor-view-pane");

    final Timeline checkMouseInsidePopUp = new Timeline(
            new KeyFrame(Duration.millis(EditAxis.DEFAULT_UPDATE_PERIOD), event -> {
                if (!isShowing()) {
                    return;
                }

                final long now = System.currentTimeMillis();
                if (isMouseInPopOver) {
                    popOverShowStartTime = System.currentTimeMillis();
                }
                if (Math.abs(now - popOverShowStartTime) > EditAxis.DEFAULT_SHUTDOWN_PERIOD) {
                    hide();
                }
            }));
    checkMouseInsidePopUp.play();

    registerMouseEvents();
}
 
Example 20
Source File: Clock.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void init(final ZonedDateTime TIME) {
    time                    = new ObjectPropertyBase<ZonedDateTime>(TIME) {
        @Override protected void invalidated() {
            if (!isRunning() && isAnimated()) {
                long animationDuration = getAnimationDuration();
                timeline.stop();
                final KeyValue KEY_VALUE = new KeyValue(currentTime, TIME.toEpochSecond());
                final KeyFrame KEY_FRAME = new KeyFrame(javafx.util.Duration.millis(animationDuration), KEY_VALUE);
                timeline.getKeyFrames().setAll(KEY_FRAME);
                timeline.setOnFinished(e -> fireUpdateEvent(FINISHED_EVENT));
                timeline.play();
            } else {
                currentTime.set(TIME.toEpochSecond());
                fireUpdateEvent(FINISHED_EVENT);
            }
        }
        @Override public Object getBean() { return Clock.this; }
        @Override public String getName() { return "time"; }
    };
    currentTime             = new LongPropertyBase(time.get().toEpochSecond()) {
        @Override protected void invalidated() {}
        @Override public Object getBean() { return Clock.this; }
        @Override public String getName() { return "currentTime"; }
    };
    zoneId                  = time.get().getZone();
    timeline                = new Timeline();
    timeline.setOnFinished(e -> fireUpdateEvent(FINISHED_EVENT));
    updateInterval          = LONG_INTERVAL;
    _checkSectionsForValue  = false;
    _checkAreasForValue     = false;
    sections                = FXCollections.observableArrayList();
    _secondsVisible         = false;
    _highlightSections      = false;
    areas                   = FXCollections.observableArrayList();
    _areasVisible           = false;
    _highlightAreas         = false;
    _text                   = "";
    _discreteSeconds        = true;
    _discreteMinutes        = true;
    _discreteHours          = false;
    _secondsVisible         = false;
    _titleVisible           = false;
    _textVisible            = false;
    _dateVisible            = false;
    _dayVisible             = false;
    _nightMode              = false;
    _running                = false;
    _autoNightMode          = false;
    _backgroundPaint        = Color.TRANSPARENT;
    _borderPaint            = Color.TRANSPARENT;
    _borderWidth            = 1;
    _foregroundPaint        = Color.TRANSPARENT;
    _titleColor             = DARK_COLOR;
    _textColor              = DARK_COLOR;
    _dateColor              = DARK_COLOR;
    _hourTickMarkColor      = DARK_COLOR;
    _minuteTickMarkColor    = DARK_COLOR;
    _tickLabelColor         = DARK_COLOR;
    _alarmColor             = DARK_COLOR;
    _hourTickMarksVisible   = true;
    _minuteTickMarksVisible = true;
    _tickLabelsVisible      = true;
    _hourColor              = DARK_COLOR;
    _minuteColor            = DARK_COLOR;
    _secondColor            = DARK_COLOR;
    _knobColor              = DARK_COLOR;
    _lcdDesign              = LcdDesign.STANDARD;
    _alarmsEnabled          = false;
    _alarmsVisible          = false;
    alarms                  = FXCollections.observableArrayList();
    alarmsToRemove          = new ArrayList<>();
    _lcdCrystalEnabled      = false;
    _shadowsEnabled         = false;
    _lcdFont                = LcdFont.DIGITAL_BOLD;
    _locale                 = Locale.US;
    _tickLabelLocation      = TickLabelLocation.INSIDE;
    _animated               = false;
    animationDuration       = 10000;
    _customFontEnabled      = false;
    _customFont             = Fonts.robotoRegular(12);
}