Make the update interval configurable

main
Clément FRÉVILLE 3 years ago
parent 448006bc34
commit ed17ebce49

@ -8,21 +8,39 @@
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.control.Button?>
<SplitPane xmlns:fx="http://javafx.com/fxml" prefHeight="400.0" prefWidth="600.0">
<ListView fx:id="sensorsList" />
<VBox alignment="TOP_CENTER">
<padding>
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0"/>
</padding>
<Text fx:id="sensorId" text="Details" />
<TextField fx:id="sensorName" />
<BorderPane>
<left>
<Button fx:id="changeBtn" onAction="#onChangeClick" visible="false">Change</Button>
</left>
<right>
<Button fx:id="visualizeBtn" onAction="#onVisualizeClick">Visualize</Button>
</right>
</BorderPane>
</VBox>
</SplitPane>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Spinner?>
<BorderPane xmlns:fx="http://javafx.com/fxml" prefHeight="400.0" prefWidth="600.0">
<center>
<SplitPane>
<ListView fx:id="sensorsList" />
<VBox alignment="TOP_CENTER">
<padding>
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0"/>
</padding>
<Text fx:id="sensorId" text="Details" />
<TextField fx:id="sensorName" />
<BorderPane>
<left>
<Button fx:id="changeBtn" onAction="#onChangeClick" visible="false">Change</Button>
</left>
<right>
<Button fx:id="visualizeBtn" onAction="#onVisualizeClick">Visualize</Button>
</right>
</BorderPane>
</VBox>
</SplitPane>
</center>
<bottom>
<FlowPane>
<Text>Millis per tick :</Text>
<Spinner fx:id="updateInterval">
<valueFactory>
<javafx.scene.control.SpinnerValueFactory.IntegerSpinnerValueFactory min="10" max="2000" />
</valueFactory>
</Spinner>
<CheckBox fx:id="autoUpdate" text="Auto update" />
</FlowPane>
</bottom>
</BorderPane>

@ -11,8 +11,10 @@ import fr.uca.iut.clfreville2.model.sensor.Sensor;
import fr.uca.iut.clfreville2.persistence.StubSensorRegistryLoader;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ListView;
import javafx.scene.control.Slider;
import javafx.scene.control.Spinner;
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
import javafx.scene.text.Text;
@ -40,6 +42,12 @@ public class MainWindows {
@FXML
private Button visualizeBtn;
@FXML
private Spinner<Integer> updateInterval;
@FXML
private CheckBox autoUpdate;
public MainWindows(Stage primaryStage) {
this.ticker = new Ticker(registry);
this.modalFactory = new ModalFactory(primaryStage);
@ -84,6 +92,7 @@ public class MainWindows {
private void initialize() {
bindSensorList();
bindActiveButtons();
bindUpdate();
}
@FXML
@ -113,6 +122,12 @@ public class MainWindows {
visualizeBtn.visibleProperty().bind(sensorsList.getSelectionModel().selectedItemProperty().isNotNull());
}
@FXML
private void bindUpdate() {
updateInterval.getValueFactory().valueProperty().bindBidirectional(ticker.millisPerTickProperty().asObject());
autoUpdate.selectedProperty().bindBidirectional(ticker.runningProperty());
}
private Sensor getSelectedSensor() {
return sensorsList.getSelectionModel().getSelectedItem();
}

@ -2,13 +2,16 @@ 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.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
public class Ticker extends Thread {
private final Tickable tickable;
private final IntegerProperty millisPerTick = new SimpleIntegerProperty(250);
private final BooleanProperty running = new SimpleBooleanProperty(true);
public Ticker(Tickable tickable) {
this.tickable = tickable;
@ -19,7 +22,9 @@ public class Ticker extends Thread {
while (true) {
try {
Thread.sleep(millisPerTick.getValue());
Platform.runLater(tickable::tick);
if (running.get()) {
Platform.runLater(tickable::tick);
}
} catch (InterruptedException e) {
break;
}
@ -37,4 +42,16 @@ public class Ticker extends Thread {
public IntegerProperty millisPerTickProperty() {
return millisPerTick;
}
public void setRunning(boolean running) {
this.running.setValue(running);
}
public boolean getRunning() {
return running.getValue();
}
public BooleanProperty runningProperty() {
return running;
}
}

Loading…
Cancel
Save