Make the update interval configurable
This commit is contained in:
@@ -8,21 +8,39 @@
|
|||||||
<?import javafx.scene.control.TextField?>
|
<?import javafx.scene.control.TextField?>
|
||||||
<?import javafx.scene.layout.BorderPane?>
|
<?import javafx.scene.layout.BorderPane?>
|
||||||
<?import javafx.scene.control.Button?>
|
<?import javafx.scene.control.Button?>
|
||||||
<SplitPane xmlns:fx="http://javafx.com/fxml" prefHeight="400.0" prefWidth="600.0">
|
<?import javafx.scene.layout.FlowPane?>
|
||||||
<ListView fx:id="sensorsList" />
|
<?import javafx.scene.control.CheckBox?>
|
||||||
<VBox alignment="TOP_CENTER">
|
<?import javafx.scene.control.Spinner?>
|
||||||
<padding>
|
<BorderPane xmlns:fx="http://javafx.com/fxml" prefHeight="400.0" prefWidth="600.0">
|
||||||
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0"/>
|
<center>
|
||||||
</padding>
|
<SplitPane>
|
||||||
<Text fx:id="sensorId" text="Details" />
|
<ListView fx:id="sensorsList" />
|
||||||
<TextField fx:id="sensorName" />
|
<VBox alignment="TOP_CENTER">
|
||||||
<BorderPane>
|
<padding>
|
||||||
<left>
|
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0"/>
|
||||||
<Button fx:id="changeBtn" onAction="#onChangeClick" visible="false">Change</Button>
|
</padding>
|
||||||
</left>
|
<Text fx:id="sensorId" text="Details" />
|
||||||
<right>
|
<TextField fx:id="sensorName" />
|
||||||
<Button fx:id="visualizeBtn" onAction="#onVisualizeClick">Visualize</Button>
|
<BorderPane>
|
||||||
</right>
|
<left>
|
||||||
</BorderPane>
|
<Button fx:id="changeBtn" onAction="#onChangeClick" visible="false">Change</Button>
|
||||||
</VBox>
|
</left>
|
||||||
</SplitPane>
|
<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 fr.uca.iut.clfreville2.persistence.StubSensorRegistryLoader;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.CheckBox;
|
||||||
import javafx.scene.control.ListView;
|
import javafx.scene.control.ListView;
|
||||||
import javafx.scene.control.Slider;
|
import javafx.scene.control.Slider;
|
||||||
|
import javafx.scene.control.Spinner;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
@@ -40,6 +42,12 @@ public class MainWindows {
|
|||||||
@FXML
|
@FXML
|
||||||
private Button visualizeBtn;
|
private Button visualizeBtn;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Spinner<Integer> updateInterval;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private CheckBox autoUpdate;
|
||||||
|
|
||||||
public MainWindows(Stage primaryStage) {
|
public MainWindows(Stage primaryStage) {
|
||||||
this.ticker = new Ticker(registry);
|
this.ticker = new Ticker(registry);
|
||||||
this.modalFactory = new ModalFactory(primaryStage);
|
this.modalFactory = new ModalFactory(primaryStage);
|
||||||
@@ -84,6 +92,7 @@ public class MainWindows {
|
|||||||
private void initialize() {
|
private void initialize() {
|
||||||
bindSensorList();
|
bindSensorList();
|
||||||
bindActiveButtons();
|
bindActiveButtons();
|
||||||
|
bindUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@@ -113,6 +122,12 @@ public class MainWindows {
|
|||||||
visualizeBtn.visibleProperty().bind(sensorsList.getSelectionModel().selectedItemProperty().isNotNull());
|
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() {
|
private Sensor getSelectedSensor() {
|
||||||
return sensorsList.getSelectionModel().getSelectedItem();
|
return sensorsList.getSelectionModel().getSelectedItem();
|
||||||
}
|
}
|
||||||
|
@@ -2,13 +2,16 @@ package fr.uca.iut.clfreville2.gui.thread;
|
|||||||
|
|
||||||
import fr.uca.iut.clfreville2.model.shared.Tickable;
|
import fr.uca.iut.clfreville2.model.shared.Tickable;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
|
import javafx.beans.property.BooleanProperty;
|
||||||
import javafx.beans.property.IntegerProperty;
|
import javafx.beans.property.IntegerProperty;
|
||||||
|
import javafx.beans.property.SimpleBooleanProperty;
|
||||||
import javafx.beans.property.SimpleIntegerProperty;
|
import javafx.beans.property.SimpleIntegerProperty;
|
||||||
|
|
||||||
public class Ticker extends Thread {
|
public class Ticker extends Thread {
|
||||||
|
|
||||||
private final Tickable tickable;
|
private final Tickable tickable;
|
||||||
private final IntegerProperty millisPerTick = new SimpleIntegerProperty(250);
|
private final IntegerProperty millisPerTick = new SimpleIntegerProperty(250);
|
||||||
|
private final BooleanProperty running = new SimpleBooleanProperty(true);
|
||||||
|
|
||||||
public Ticker(Tickable tickable) {
|
public Ticker(Tickable tickable) {
|
||||||
this.tickable = tickable;
|
this.tickable = tickable;
|
||||||
@@ -19,7 +22,9 @@ public class Ticker extends Thread {
|
|||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(millisPerTick.getValue());
|
Thread.sleep(millisPerTick.getValue());
|
||||||
Platform.runLater(tickable::tick);
|
if (running.get()) {
|
||||||
|
Platform.runLater(tickable::tick);
|
||||||
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -37,4 +42,16 @@ public class Ticker extends Thread {
|
|||||||
public IntegerProperty millisPerTickProperty() {
|
public IntegerProperty millisPerTickProperty() {
|
||||||
return millisPerTick;
|
return millisPerTick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setRunning(boolean running) {
|
||||||
|
this.running.setValue(running);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getRunning() {
|
||||||
|
return running.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BooleanProperty runningProperty() {
|
||||||
|
return running;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user