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