実際のサイクルをタイムラインから取得する直接的な方法はないと思います。
あなた自身のプロパティを書くことができます。 以下は、currentTimeを監視し、 "direction"を変更するたびに自己生成プロパティの値をインクリメントする例です。
例:
オートリバース= falseを
currentTime: 1s
currentTime: 2s
currentTime: 3s
currentTime: 0s <--------- increment actual cycle
currentTime: 1s
オートリバース=真
currentTime: 1s
currentTime: 2s
currentTime: 3s
currentTime: 2s <--------- increment actual cycle
currentTime: 1s
私はすでに、これは少しトリッキーであることを、認める、多分この解決しなければなりませんあなたのニーズに合っています。
コード-例:
(あなたはそれがちょうどあなたが0から1にSimpleIntegerProperty-コンストラクタに渡すのparamを変更、1で開始する場合actualCycleは、0から始まる)
@Override
public void start(Stage primaryStage) throws Exception {
SimpleStringProperty testProperty = new SimpleStringProperty();
Timeline timeline = new Timeline(new KeyFrame(Duration.millis(1000), new KeyValue(testProperty, "1234")));
timeline.setCycleCount(Timeline.INDEFINITE);
// ----------------------------------------------------------------------
// we create our own property for the actual cycle-index
// ----------------------------------------------------------------------
SimpleIntegerProperty actualCycleProperty = new SimpleIntegerProperty(0);
timeline.currentTimeProperty().addListener((observable, oldValue, newValue) -> {
boolean smaller = newValue.toMillis() < oldValue.toMillis();
boolean evenCycleCount = actualCycleProperty.get() % 2 == 0;
if ((timeline.isAutoReverse() && !evenCycleCount && !smaller)
|| ((evenCycleCount || !timeline.isAutoReverse()) && smaller)) {
actualCycleProperty.set(actualCycleProperty.get() + 1);
}
});
actualCycleProperty.addListener((observable, oldValue, newValue) -> {
System.out.println(newValue);
});
timeline.play();
}