diff --git a/resources/windows/MainWindows.fxml b/resources/windows/MainWindows.fxml index 00fe568..bd354a9 100644 --- a/resources/windows/MainWindows.fxml +++ b/resources/windows/MainWindows.fxml @@ -52,10 +52,10 @@ - Millis per tick : + Update delay : - + diff --git a/src/fr/uca/iut/clfreville2/gui/MainWindows.java b/src/fr/uca/iut/clfreville2/gui/MainWindows.java index 390c45b..611929d 100644 --- a/src/fr/uca/iut/clfreville2/gui/MainWindows.java +++ b/src/fr/uca/iut/clfreville2/gui/MainWindows.java @@ -94,7 +94,7 @@ public class MainWindows { private Button createButton; @FXML - private Spinner updateInterval; + private Spinner updateInterval; @FXML private ToggleButton autoUpdate; @@ -249,7 +249,7 @@ public class MainWindows { @FXML private void bindUpdate() { - updateInterval.getValueFactory().valueProperty().bindBidirectional(ticker.millisPerTickProperty().asObject()); + updateInterval.getValueFactory().valueProperty().bindBidirectional(ticker.delayProperty().asObject()); autoUpdate.selectedProperty().bindBidirectional(ticker.runningProperty()); } diff --git a/src/fr/uca/iut/clfreville2/gui/thread/Ticker.java b/src/fr/uca/iut/clfreville2/gui/thread/Ticker.java index ed527f9..f5eef29 100644 --- a/src/fr/uca/iut/clfreville2/gui/thread/Ticker.java +++ b/src/fr/uca/iut/clfreville2/gui/thread/Ticker.java @@ -3,14 +3,14 @@ package fr.uca.iut.clfreville2.gui.thread; import fr.uca.iut.clfreville2.model.shared.Tickable; import javafx.application.Platform; import javafx.beans.property.BooleanProperty; -import javafx.beans.property.IntegerProperty; +import javafx.beans.property.DoubleProperty; import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleDoubleProperty; public class Ticker extends Thread { private final Tickable tickable; - private final IntegerProperty millisPerTick = new SimpleIntegerProperty(500); + private final DoubleProperty delay = new SimpleDoubleProperty(1D); private final BooleanProperty running = new SimpleBooleanProperty(true); public Ticker(Tickable tickable) { @@ -21,7 +21,7 @@ public class Ticker extends Thread { public void run() { while (true) { try { - Thread.sleep(millisPerTick.getValue()); + Thread.sleep((int) (delay.getValue() * 1000)); if (running.get()) { Platform.runLater(tickable::tick); } @@ -31,18 +31,6 @@ public class Ticker extends Thread { } } - public int getMillisPerTick() { - return millisPerTick.get(); - } - - public void setMillisPerTick(int millisPerTick) { - this.millisPerTick.set(millisPerTick); - } - - public IntegerProperty millisPerTickProperty() { - return millisPerTick; - } - public void setRunning(boolean running) { this.running.setValue(running); } @@ -54,4 +42,16 @@ public class Ticker extends Thread { public BooleanProperty runningProperty() { return running; } + + public void setDelay(double delay) { + this.delay.setValue(delay); + } + + public double getDelay() { + return delay.getValue(); + } + + public DoubleProperty delayProperty() { + return delay; + } }