diff --git a/resources/view/TreeView.fxml b/resources/view/TreeView.fxml
index 364d79e..2f1a918 100644
--- a/resources/view/TreeView.fxml
+++ b/resources/view/TreeView.fxml
@@ -1,12 +1,16 @@
+
-
-
+
+
+
+
+
diff --git a/src/launcher/Launch.java b/src/launcher/Launch.java
index c689d77..9c4056c 100644
--- a/src/launcher/Launch.java
+++ b/src/launcher/Launch.java
@@ -1,8 +1,10 @@
package launcher;
import javafx.application.Application;
+import javafx.application.Platform;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
+import javafx.scene.control.TreeItem;
import javafx.stage.Stage;
import model.*;
import view.CapteurView;
@@ -23,9 +25,9 @@ public class Launch extends Application {
@Override
public void start(Stage primaryStage) throws IOException, InterruptedException {
// Creation des capteurs
- UnitCapteur captorC = new UnitCapteur(1,new SimpleStringProperty("Capteur CPU"),new StrategyCPU());
- UnitCapteur captorR = new UnitCapteur(2,new SimpleStringProperty("Capteur Random"),new StrategyRandom());
- CapteurVirtuel captorV = new CapteurVirtuel(5,new SimpleStringProperty("Capteur Virtuel"));
+ UnitCapteur captorC = new UnitCapteur(new SimpleStringProperty("1"),new SimpleStringProperty("Capteur CPU"),new StrategyCPU());
+ UnitCapteur captorR = new UnitCapteur(new SimpleStringProperty("2"),new SimpleStringProperty("Capteur Random"),new StrategyRandom());
+ CapteurVirtuel captorV = new CapteurVirtuel(new SimpleStringProperty("3"),new SimpleStringProperty("Capteur Virtuel"));
// Ajout des capteurs dans la collections du capteur virtuel
captorV.addCapteur(captorC,1);
@@ -40,26 +42,20 @@ public class Launch extends Application {
capteurs.add(captorR);
capteurs.add(captorV);
- // FXML NOT WORKING
Stage thermostatStage = new Stage();
TreeViewCtrl treeViewCtrl = new TreeViewCtrl(capteurs,"view/TreeView.fxml","treeView");
- treeViewCtrl.show();
Thread t = new Thread() {
public void run() {
while (true) {
- for (Map.Entry entry : captorV.getCapteurs().entrySet()) {
- CapteurAbstrait c = entry.getKey();
- c.genTemp();
- }
- captorV.genTemp();
+ Platform.runLater(() -> {
+ capteurs.forEach(c -> {
+ if(c instanceof UnitCapteur uc){
+ uc.genTemp();
+ }
+ });
+ });
try {
- /*((ImageCtrlView) capteurView).changeImage();
- System.out.println(captorV.getNom() + ": " + captorV.getTemp().getValue() + " °C");
- for (Map.Entry entry : captorV.getCapteurs().entrySet()) {
- CapteurAbstrait c = entry.getKey();
- System.out.println(c.getNom() + ": " + c.getTemp().getValue() + " °C");
- }*/
- sleep(4000);
+ sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
@@ -67,6 +63,7 @@ public class Launch extends Application {
}
};
t.start();
+ treeViewCtrl.show();
}
}
diff --git a/src/model/CapteurAbstrait.java b/src/model/CapteurAbstrait.java
index 0633683..5f4f1d6 100644
--- a/src/model/CapteurAbstrait.java
+++ b/src/model/CapteurAbstrait.java
@@ -1,16 +1,13 @@
package model;
-import javafx.beans.property.ObjectProperty;
-import javafx.beans.property.SimpleObjectProperty;
-import javafx.beans.property.SimpleStringProperty;
-import javafx.beans.property.StringProperty;
+import javafx.beans.property.*;
public abstract class CapteurAbstrait {
- private int id;
+ private Property id;
private StringProperty nom;
- private ObjectProperty temp = new SimpleObjectProperty<>();
+ private ObjectProperty temp = new SimpleObjectProperty();
- CapteurAbstrait(int id, StringProperty nom){
+ CapteurAbstrait(Property id, StringProperty nom){
this.id = id;
this.nom = nom;
this.temp.setValue(0.0);
@@ -18,11 +15,11 @@ public abstract class CapteurAbstrait {
public abstract void genTemp();
/* Getters - Setters */
- public int getId() {
+ public Property getId() {
return id;
}
- public void setId(int id) {
+ public void setId(Property id) {
this.id = id;
}
diff --git a/src/model/CapteurVirtuel.java b/src/model/CapteurVirtuel.java
index 29f15f8..16bdaa0 100644
--- a/src/model/CapteurVirtuel.java
+++ b/src/model/CapteurVirtuel.java
@@ -1,6 +1,7 @@
package model;
import javafx.beans.property.ObjectProperty;
+import javafx.beans.property.Property;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.StringProperty;
@@ -12,7 +13,7 @@ public class CapteurVirtuel extends CapteurAbstrait {
private Map capteurs;
- public CapteurVirtuel(int id, StringProperty nom){
+ public CapteurVirtuel(Property id, StringProperty nom){
super(id, nom);
this.capteurs = new HashMap<>();
}
diff --git a/src/model/TreeItemFactoryVisitor.java b/src/model/TreeItemFactoryVisitor.java
index 9700a59..301fe0f 100644
--- a/src/model/TreeItemFactoryVisitor.java
+++ b/src/model/TreeItemFactoryVisitor.java
@@ -15,10 +15,14 @@ public class TreeItemFactoryVisitor implements Visitor
root.setExpanded(true);
for(CapteurAbstrait c : cv.getCapteurs().keySet()){
- TreeItem item = new TreeItem<>();
+ TreeItem item = new TreeItem<>(c);
+ if(c.getClass() == CapteurVirtuel.class){
+ item = c.accept(this);
+ } else {
+ item = new TreeItem<>(c);
+ }
root.getChildren().add(item);
}
-
return root;
}
}
diff --git a/src/model/UnitCapteur.java b/src/model/UnitCapteur.java
index 5beb4d5..12b9d39 100644
--- a/src/model/UnitCapteur.java
+++ b/src/model/UnitCapteur.java
@@ -1,11 +1,12 @@
package model;
+import javafx.beans.property.Property;
import javafx.beans.property.StringProperty;
public class UnitCapteur extends CapteurAbstrait{
private StrategyCaptor strategie;
- public UnitCapteur(int id, StringProperty nom, StrategyCaptor st) {
+ public UnitCapteur(Property id, StringProperty nom, StrategyCaptor st) {
super(id, nom);
this.strategie = st;
}
diff --git a/src/view/TreeViewCtrl.java b/src/view/TreeViewCtrl.java
index edb9c43..302de3e 100644
--- a/src/view/TreeViewCtrl.java
+++ b/src/view/TreeViewCtrl.java
@@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
+import javafx.beans.binding.Bindings;
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
@@ -13,12 +14,22 @@ import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
+import javafx.util.converter.NumberStringConverter;
import model.*;
+import javax.swing.text.LabelView;
+
public class TreeViewCtrl extends FXMLView {
@FXML
private TreeView treeView;
+ @FXML
+ private Label idLabel;
+ @FXML
+ private Label nameLabel;
+ @FXML
+ private Label temperatureLabel;
+
private ArrayList capteurAbstraits;
@@ -75,5 +86,18 @@ public class TreeViewCtrl extends FXMLView {
}
}
});
+
+ treeView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
+ if (newValue != null) {
+ CapteurAbstrait capteur = newValue.getValue();
+ idLabel.textProperty().bindBidirectional(capteur.getId());
+ nameLabel.textProperty().bindBidirectional(capteur.getNom());
+ temperatureLabel.textProperty().bind(Bindings.format("%.2f",capteur.getTemp()));
+ }
+ });
+ }
+
+ public TreeView getTreeView() {
+ return treeView;
}
}