From 095602d809e88e5e60f035a647e90ef303c1660d Mon Sep 17 00:00:00 2001 From: "nicolas.franco" Date: Sun, 22 Jan 2023 13:15:57 +0100 Subject: [PATCH] fixed all display bugs + captor added --- resources/view/TreeView.fxml | 4 ++++ src/launcher/Launch.java | 4 ++++ src/model/CapteurAbstrait.java | 10 ++++++++++ src/model/UnitCapteur.java | 2 ++ src/view/TreeViewCtrl.java | 36 ++++++++++++++++++++++++++++++++-- 5 files changed, 54 insertions(+), 2 deletions(-) diff --git a/resources/view/TreeView.fxml b/resources/view/TreeView.fxml index 2f1a918..c14543e 100644 --- a/resources/view/TreeView.fxml +++ b/resources/view/TreeView.fxml @@ -4,6 +4,8 @@ + + @@ -11,6 +13,8 @@ diff --git a/src/launcher/Launch.java b/src/launcher/Launch.java index 9c4056c..7f9d144 100644 --- a/src/launcher/Launch.java +++ b/src/launcher/Launch.java @@ -53,6 +53,10 @@ public class Launch extends Application { uc.genTemp(); } }); + capteurs.forEach(c -> { + if(c instanceof UnitCapteur uc){ + uc.genTemp(); + }}); }); try { sleep(1000); diff --git a/src/model/CapteurAbstrait.java b/src/model/CapteurAbstrait.java index 5f4f1d6..332479b 100644 --- a/src/model/CapteurAbstrait.java +++ b/src/model/CapteurAbstrait.java @@ -5,11 +5,14 @@ import javafx.beans.property.*; public abstract class CapteurAbstrait { private Property id; private StringProperty nom; + private StringProperty displayNom; private ObjectProperty temp = new SimpleObjectProperty(); CapteurAbstrait(Property id, StringProperty nom){ this.id = id; this.nom = nom; + this.displayNom = new SimpleStringProperty(); + this.displayNom.bind(this.nom); this.temp.setValue(0.0); } public abstract void genTemp(); @@ -27,9 +30,16 @@ public abstract class CapteurAbstrait { return this.nom; } + public StringProperty getDisplayNom() { + return this.displayNom; + } + public void setNom(StringProperty nom) { this.nom = nom; } + public void setNom(String nom) { + this.nom.setValue(nom); + } public ObjectProperty getTemp() { return temp; diff --git a/src/model/UnitCapteur.java b/src/model/UnitCapteur.java index 12b9d39..6e46d5b 100644 --- a/src/model/UnitCapteur.java +++ b/src/model/UnitCapteur.java @@ -3,6 +3,8 @@ package model; import javafx.beans.property.Property; import javafx.beans.property.StringProperty; +import java.time.temporal.ChronoUnit; + public class UnitCapteur extends CapteurAbstrait{ private StrategyCaptor strategie; diff --git a/src/view/TreeViewCtrl.java b/src/view/TreeViewCtrl.java index 302de3e..9790ed0 100644 --- a/src/view/TreeViewCtrl.java +++ b/src/view/TreeViewCtrl.java @@ -28,8 +28,13 @@ public class TreeViewCtrl extends FXMLView { @FXML private Label nameLabel; @FXML + private TextField nameTextField; + @FXML private Label temperatureLabel; + @FXML + private ComboBox strategyOptions; + private ArrayList capteurAbstraits; @@ -61,6 +66,8 @@ public class TreeViewCtrl extends FXMLView { } public void initializeCapteur() { + strategyOptions.getItems().addAll("CPU", "Random"); + treeView.setCellFactory(param -> new TreeCell() { @Override protected void updateItem(CapteurAbstrait capteur, boolean empty) { @@ -69,7 +76,7 @@ public class TreeViewCtrl extends FXMLView { textProperty().unbind(); setText(""); } else { - textProperty().bind(capteur.getNom()); + setText(capteur.getNom().getValue()); String image = "/images/random.png"; if (capteur.getClass() == CapteurVirtuel.class) { image = "/images/virtual.png"; @@ -86,13 +93,38 @@ public class TreeViewCtrl extends FXMLView { } } }); - + strategyOptions.setVisible(false); treeView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { + if (oldValue != null) { + CapteurAbstrait capteur = oldValue.getValue(); + idLabel.textProperty().unbindBidirectional(capteur.getId()); + nameLabel.textProperty().unbindBidirectional(capteur.getNom()); + temperatureLabel.textProperty().unbind(); + if(capteur instanceof UnitCapteur){ + strategyOptions.setVisible(false); + } + } if (newValue != null) { CapteurAbstrait capteur = newValue.getValue(); + if (capteur instanceof UnitCapteur) { + strategyOptions.setVisible(true); + } else { + strategyOptions.setVisible(false); + } idLabel.textProperty().bindBidirectional(capteur.getId()); nameLabel.textProperty().bindBidirectional(capteur.getNom()); temperatureLabel.textProperty().bind(Bindings.format("%.2f",capteur.getTemp())); + nameTextField.setOnAction(event -> { + capteur.setNom(nameTextField.getText()); + }); + nameTextField.setText(capteur.getNom().getValue()); + capteur.getNom().addListener((obs, oldName, newName) -> { + capteur.setNom(newName); + newValue.setValue(capteur); + }); + if(capteur instanceof UnitCapteur){ + strategyOptions.setVisible(true); + } } }); }