diff --git a/Source/out/production/ProjetJavaFX/view/MainPage.class b/Source/out/production/ProjetJavaFX/view/MainPage.class index 668faf3..10f410f 100644 Binary files a/Source/out/production/ProjetJavaFX/view/MainPage.class and b/Source/out/production/ProjetJavaFX/view/MainPage.class differ diff --git a/Source/src/model/CapteurVirtuel.java b/Source/src/model/CapteurVirtuel.java index b4f6ba8..6943432 100644 --- a/Source/src/model/CapteurVirtuel.java +++ b/Source/src/model/CapteurVirtuel.java @@ -8,11 +8,9 @@ import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.collections.*; import java.util.*; -import static model.Captor.rand; public class CapteurVirtuel extends Sujet implements Runnable { - private final UUID id= UUID.randomUUID(); private final StringProperty nom; private final DoubleProperty tempMoyenne = new SimpleDoubleProperty(0); @@ -34,7 +32,7 @@ public class CapteurVirtuel extends Sujet implements Runnable { public void addToLesCapteurs(Captor c){ - lesCapteurs.put((rand.nextInt()%10),c); + lesCapteurs.put(c.getCoef(),c); } private void updateData() { diff --git a/Source/src/model/Captor.java b/Source/src/model/Captor.java index ac44b6f..fb14756 100644 --- a/Source/src/model/Captor.java +++ b/Source/src/model/Captor.java @@ -13,17 +13,30 @@ public class Captor implements Runnable{ private final DoubleProperty temperature; + private Integer coef; + static final Random rand=new Random(System.currentTimeMillis()); public Captor(String name){ this.name=new SimpleStringProperty(name); this.temperature=new SimpleDoubleProperty(5.0); + this.coef =rand.nextInt()%10; } public String getName(){ return this.name.get(); } + public Integer getCoef(){ + return this.coef; + } + + public void setCoef(Integer i){ + this.coef = i; + } + + + public DoubleProperty getTemperatureProperty(){ return this.temperature; } diff --git a/Source/src/view/MainPage.java b/Source/src/view/MainPage.java index c6f5e68..f270188 100644 --- a/Source/src/view/MainPage.java +++ b/Source/src/view/MainPage.java @@ -18,6 +18,10 @@ public class MainPage { @FXML private VBox vb1; @FXML private VBox vb2; @FXML private ImageView open; + @FXML private final Button FirstCaptorButton = new Button(); + @FXML private final Button SecondCaptorButton = new Button(); + + CPUTemp cpuTemp = new CPUTemp("CPU Captor"); CapteurVirtuel cV1 = new CapteurVirtuel("CaptVirt1"); @@ -37,7 +41,7 @@ public class MainPage { FirstButton.setOnAction(e -> { vb1.getChildren().clear(); - vb1.getChildren().add(setVboxCPUCaptor()); + vb1.getChildren().add(setDisplayCPUCaptor()); }); @@ -47,20 +51,35 @@ public class MainPage { open.setImage(new Image("https://www.citypng.com/public/uploads/preview/download-black-right-triangle-png-31629764954y0662peplm.png")); vb2.getChildren().clear(); + vb1.getChildren().clear(); }else{ vb1.getChildren().clear(); vb1.getChildren().add(setDisplayVirtualCaptor()); open.setImage(new Image("https://cdn-icons-png.flaticon.com/512/0/159.png")); - vb2.getChildren().add(setHBoxFirstCaptor()); - vb2.getChildren().add(setHBoxSecondCaptor()); + vb2.getChildren().add(setDisplayFirstCaptor()); + vb2.getChildren().add(setDisplaySecondCaptor()); } }); + + FirstCaptorButton.setOnAction(e -> { + + vb1.getChildren().clear(); + vb1.getChildren().add(setDisplayCaptor(c1)); + + }); + + SecondCaptorButton.setOnAction(e -> { + + vb1.getChildren().clear(); + vb1.getChildren().add(setDisplayCaptor(c2)); + + }); } - private VBox setVboxCPUCaptor() { + private VBox setDisplayCPUCaptor() { VBox FirstCaptorCPU = new VBox(); @@ -117,7 +136,7 @@ public class MainPage { return FirstCaptorCPU; } - private HBox setHBoxFirstCaptor(){ + private HBox setDisplayFirstCaptor(){ HBox Captor1 = new HBox(); @@ -125,19 +144,19 @@ public class MainPage { FirstCaptorImage.setFitHeight(73); FirstCaptorImage.setFitWidth(73); - Button FirstCaptorButton = new Button(); FirstCaptorButton.setText(c1.getName()); FirstCaptorButton.setFont(new Font("System", 13)); FirstCaptorButton.setMaxWidth(Double.MAX_VALUE); FirstCaptorButton.setAlignment(Pos.CENTER_LEFT); + Captor1.getChildren().add(FirstCaptorImage); Captor1.getChildren().add(FirstCaptorButton); return Captor1; } - private HBox setHBoxSecondCaptor(){ + private HBox setDisplaySecondCaptor(){ HBox Captor2 = new HBox(); @@ -145,7 +164,6 @@ public class MainPage { SecondCaptorImage.setFitHeight(73); SecondCaptorImage.setFitWidth(73); - Button SecondCaptorButton = new Button(); SecondCaptorButton.setText(c2.getName()); SecondCaptorButton.setFont(new Font("System", 13)); SecondCaptorButton.setMaxWidth(Double.MAX_VALUE); @@ -162,7 +180,7 @@ public class MainPage { VBox CaptorVirtual = new VBox(); - Label ViewTempVirtualCaptor = new Label("Temperature moyenne des sous-capteurs du capteur virtuel : " + cV1.getTempMoyenne() + "°C"); + Label ViewTempVirtualCaptor = new Label("Temperature moyenne des sous-capteurs du capteur virtuel : " + Math.round(cV1.getTempMoyenne()*10.0)/10.0 + "°C"); ViewTempVirtualCaptor.setFont(new Font("Arial",20)); ViewTempVirtualCaptor.setMaxWidth(Double.MAX_VALUE); @@ -223,4 +241,61 @@ public class MainPage { return CaptorVirtual; } + private VBox setDisplayCaptor(Captor cap){ + + VBox Captor = new VBox(); + + Label ViewTempCaptor = new Label("Temperature du capteur " + cap.getName() + " : " + Math.round(cap.getTemperature()*10.0)/10.0 + "°C"); + + ViewTempCaptor.setFont(new Font("Arial",25)); + ViewTempCaptor.setMaxWidth(Double.MAX_VALUE); + ViewTempCaptor.setAlignment(Pos.CENTER); + ViewTempCaptor.setWrapText(true); + + ImageView CaptorImage = new ImageView(new Image("https://static.thenounproject.com/png/7561-200.png")); + + CaptorImage.setFitWidth(500); + CaptorImage.setFitHeight(300); + + + Captor.getChildren().add(CaptorImage); + Captor.getChildren().add(ViewTempCaptor); + + + ObservableList CaptorObs = FXCollections.observableArrayList( + TrueCaptor->new ObservableValue[]{ + TrueCaptor.getTemperatureProperty() + } + ); + + CaptorObs.addListener((ListChangeListener.Change c) ->{ + while (c.next()){ + + if (c.wasUpdated()){ + + Double temp = cap.getTemperature(); + + if (temp < 0){ + + ViewTempCaptor.setStyle("-fx-text-fill : blue"); + + } else if (temp > 30) { + + ViewTempCaptor.setStyle("-fx-text-fill : red"); + + }else { + + ViewTempCaptor.setStyle("-fx-text-fill : black"); + + } + ViewTempCaptor.textProperty().set("Temperature du capteur " + cap.getName() + " : " + Math.round(cap.getTemperature()*10.0)/10.0 + "°C"); + } + } + }); + + CaptorObs.add(cap); + + return Captor; + } + }