Use seconds instead of milliseconds for the update interval

main
Clément FRÉVILLE 2 years ago
parent 07c1c83e5f
commit cc945e2fee

@ -52,10 +52,10 @@
</center>
<bottom>
<FlowPane>
<Text>Millis per tick :</Text>
<Text>Update delay :</Text>
<Spinner fx:id="updateInterval">
<valueFactory>
<javafx.scene.control.SpinnerValueFactory.IntegerSpinnerValueFactory min="10" max="2000" />
<javafx.scene.control.SpinnerValueFactory.DoubleSpinnerValueFactory min="0.5" max="100" amountToStepBy="0.5" />
</valueFactory>
</Spinner>
<ToggleButton fx:id="autoUpdate" text="Auto update" />

@ -94,7 +94,7 @@ public class MainWindows {
private Button createButton;
@FXML
private Spinner<Integer> updateInterval;
private Spinner<Double> 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());
}

@ -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;
}
}

Loading…
Cancel
Save