From 2934812ae70072b390afb1c5f13368598bcb93a2 Mon Sep 17 00:00:00 2001 From: thchazot1 Date: Sun, 22 Jan 2023 18:55:51 +0100 Subject: [PATCH] =?UTF-8?q?Fin=20de=20la=20partie=20des=20bouttons=20pour?= =?UTF-8?q?=20voir=20avec=20les=20diff=C3=A9rentes=20vues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fxml/{Capteur.fxml => CapteurText.fxml} | 6 ++++-- projet/src/view/TreeViewCapteur.java | 14 +------------- projet/src/view/ViewCapteurImage.java | 13 ++++++++++--- 3 files changed, 15 insertions(+), 18 deletions(-) rename projet/ressources/fxml/{Capteur.fxml => CapteurText.fxml} (67%) diff --git a/projet/ressources/fxml/Capteur.fxml b/projet/ressources/fxml/CapteurText.fxml similarity index 67% rename from projet/ressources/fxml/Capteur.fxml rename to projet/ressources/fxml/CapteurText.fxml index 6ba0049..c6c0af0 100644 --- a/projet/ressources/fxml/Capteur.fxml +++ b/projet/ressources/fxml/CapteurText.fxml @@ -7,6 +7,8 @@ - - + +
+ +
\ No newline at end of file diff --git a/projet/src/view/TreeViewCapteur.java b/projet/src/view/TreeViewCapteur.java index 2e14209..e87274c 100644 --- a/projet/src/view/TreeViewCapteur.java +++ b/projet/src/view/TreeViewCapteur.java @@ -1,16 +1,8 @@ package view; -import javafx.beans.property.ListProperty; -import javafx.beans.property.Property; -import javafx.beans.property.SimpleListProperty; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; -import javafx.event.Event; import javafx.event.EventHandler; -import javafx.event.EventType; import javafx.fxml.FXML; import javafx.scene.control.*; import javafx.scene.control.cell.PropertyValueFactory; @@ -20,10 +12,6 @@ import javafx.util.converter.NumberStringConverter; import modele.*; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import static java.lang.Float.parseFloat; public class TreeViewCapteur extends FxmlWindow { @@ -111,7 +99,7 @@ public class TreeViewCapteur extends FxmlWindow { EventHandler eventTextView = e -> { try { - new ViewCapteurText(newV.getValue(), "/fxml/Capteur.fxml", "TextView"); + new ViewCapteurText(newV.getValue(), "/fxml/CapteurText.fxml", "TextView"); } catch (IOException ex) { throw new RuntimeException(ex); } diff --git a/projet/src/view/ViewCapteurImage.java b/projet/src/view/ViewCapteurImage.java index a7eaced..cc1789c 100644 --- a/projet/src/view/ViewCapteurImage.java +++ b/projet/src/view/ViewCapteurImage.java @@ -22,12 +22,19 @@ public class ViewCapteurImage extends FxmlWindow { public ViewCapteurImage(Capteur leCapteur, String url, String title) throws IOException { super(url, title); - temperature.textProperty().bindBidirectional(leCapteur.temperatureProperty(), new NumberStringConverter()); - if (leCapteur.getTemperature()<0){ + chooseImage((int) leCapteur.getTemperature()); + leCapteur.temperatureProperty().addListener(((observableValue, oldV, newV) -> { + chooseImage(newV.intValue()); + })); + + } + + private void chooseImage(int value){ + if (value<0){ image.setImage(new Image("/Assets/hilarious-snow-memes.jpg")); } - else if (leCapteur.getTemperature()<20){ + else if (value<20){ image.setImage(new Image("https://www.francetvinfo.fr/pictures/sbviI2swQTsA1oabZGCUO9wWajQ/1200x900/2017/08/30/phppmKyIc_1.jpg")); } else {