diff --git a/Source/out/production/ProjetJavaFX/console/LView$1$1.class b/Source/out/production/ProjetJavaFX/console/LView$1$1.class
deleted file mode 100644
index c00a2e7..0000000
Binary files a/Source/out/production/ProjetJavaFX/console/LView$1$1.class and /dev/null differ
diff --git a/Source/out/production/ProjetJavaFX/console/LView$1.class b/Source/out/production/ProjetJavaFX/console/LView$1.class
deleted file mode 100644
index 6be9aa3..0000000
Binary files a/Source/out/production/ProjetJavaFX/console/LView$1.class and /dev/null differ
diff --git a/Source/out/production/ProjetJavaFX/console/LView.class b/Source/out/production/ProjetJavaFX/console/LView.class
index c50afbd..e973597 100644
Binary files a/Source/out/production/ProjetJavaFX/console/LView.class and b/Source/out/production/ProjetJavaFX/console/LView.class differ
diff --git a/Source/out/production/ProjetJavaFX/fxml/MainPage.fxml b/Source/out/production/ProjetJavaFX/fxml/MainPage.fxml
index 2f94644..21b9e49 100644
--- a/Source/out/production/ProjetJavaFX/fxml/MainPage.fxml
+++ b/Source/out/production/ProjetJavaFX/fxml/MainPage.fxml
@@ -6,12 +6,11 @@
-
+
-
-
+
@@ -20,6 +19,9 @@
+
+
+
+
-
diff --git a/Source/out/production/ProjetJavaFX/model/Alea.class b/Source/out/production/ProjetJavaFX/model/Alea.class
deleted file mode 100644
index 3eb0ca2..0000000
Binary files a/Source/out/production/ProjetJavaFX/model/Alea.class and /dev/null differ
diff --git a/Source/out/production/ProjetJavaFX/model/CPUTemp.class b/Source/out/production/ProjetJavaFX/model/CPUTemp.class
index c1a06ed..db0ffc6 100644
Binary files a/Source/out/production/ProjetJavaFX/model/CPUTemp.class and b/Source/out/production/ProjetJavaFX/model/CPUTemp.class differ
diff --git a/Source/out/production/ProjetJavaFX/model/CapteurVirtuel.class b/Source/out/production/ProjetJavaFX/model/CapteurVirtuel.class
index 68a8b15..b58f427 100644
Binary files a/Source/out/production/ProjetJavaFX/model/CapteurVirtuel.class and b/Source/out/production/ProjetJavaFX/model/CapteurVirtuel.class differ
diff --git a/Source/out/production/ProjetJavaFX/model/Captor.class b/Source/out/production/ProjetJavaFX/model/Captor.class
index 1e9cfd1..f17edd0 100644
Binary files a/Source/out/production/ProjetJavaFX/model/Captor.class and b/Source/out/production/ProjetJavaFX/model/Captor.class differ
diff --git a/Source/out/production/ProjetJavaFX/model/GenererTemperature.class b/Source/out/production/ProjetJavaFX/model/GenererTemperature.class
index e86559c..941b177 100644
Binary files a/Source/out/production/ProjetJavaFX/model/GenererTemperature.class and b/Source/out/production/ProjetJavaFX/model/GenererTemperature.class differ
diff --git a/Source/out/production/ProjetJavaFX/model/Reel.class b/Source/out/production/ProjetJavaFX/model/Reel.class
deleted file mode 100644
index 9744b9b..0000000
Binary files a/Source/out/production/ProjetJavaFX/model/Reel.class and /dev/null differ
diff --git a/Source/out/production/ProjetJavaFX/view/MainPage$1$1.class b/Source/out/production/ProjetJavaFX/view/MainPage$1$1.class
new file mode 100644
index 0000000..e88f86d
Binary files /dev/null and b/Source/out/production/ProjetJavaFX/view/MainPage$1$1.class differ
diff --git a/Source/out/production/ProjetJavaFX/view/MainPage$1.class b/Source/out/production/ProjetJavaFX/view/MainPage$1.class
new file mode 100644
index 0000000..f9fa681
Binary files /dev/null and b/Source/out/production/ProjetJavaFX/view/MainPage$1.class differ
diff --git a/Source/out/production/ProjetJavaFX/view/MainPage.class b/Source/out/production/ProjetJavaFX/view/MainPage.class
index b7cbbc3..0dd6893 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/resource/fxml/MainPage.fxml b/Source/resource/fxml/MainPage.fxml
index 2f94644..21b9e49 100644
--- a/Source/resource/fxml/MainPage.fxml
+++ b/Source/resource/fxml/MainPage.fxml
@@ -6,12 +6,11 @@
-
+
-
-
+
@@ -20,6 +19,9 @@
+
+
+
+
-
diff --git a/Source/src/console/LView.java b/Source/src/console/LView.java
index 87c0211..b981fa6 100644
--- a/Source/src/console/LView.java
+++ b/Source/src/console/LView.java
@@ -2,6 +2,7 @@ package console;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
+import javafx.scene.layout.StackPane;
import model.*;
import javafx.application.Application;
import javafx.collections.ObservableList;
@@ -15,97 +16,19 @@ import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import java.io.IOException;
+import java.util.Objects;
public class LView extends Application {
@Override
public void start(Stage primaryStage) throws IOException {
- CapteurVirtuel cV1 = new CapteurVirtuel("CaptVirt1");
- CapteurVirtuel cV2 = new CapteurVirtuel("CaptVirt2");
-
-
- Captor c1 = new Captor("c1");
- Captor c2 = new Captor("c2");
- Captor c3 = new Captor("c3");
- Captor c4 = new Captor("c4");
- Captor c5 = new Captor("c5");
- Captor c6 = new Captor("c6");
-
-
- ListView listview = new ListView<>();
-
-
- ObservableList captors = FXCollections.observableArrayList(
- captor->new ObservableValue[]{
- captor.getTempMoyenneProperty()
- }
- );
-
- captors.addListener((ListChangeListener.Change extends CapteurVirtuel> c) ->{
- while (c.next()){
- if (c.wasUpdated()){
- listview.refresh();
- }
- }
- });
-
- c1.startThread();
- c2.startThread();
- c3.startThread();
- c4.startThread();
- c5.startThread();
- c6.startThread();
-
- cV1.addToLesCapteurs(c1);
- cV1.addToLesCapteurs(c2);
- cV1.addToLesCapteurs(c3);
- cV2.addToLesCapteurs(c4);
- cV2.addToLesCapteurs(c5);
- cV2.addToLesCapteurs(c6);
-
- cV1.startThread();
- cV2.startThread();
-
- captors.add(cV1);
- captors.add(cV2);
-
- listview.setCellFactory(new Callback<>() {
-
- @Override
- public ListCell call(ListView captorListView) {
- return new ListCell<>() {
- @Override
- protected void updateItem(CapteurVirtuel value, boolean empty) {
- String text = "";
- super.updateItem(value, empty);
- if (value != null) {
- text = value.getTempMoyenne().toString();
- }
- setText(text);
- String style = null;
- if (!empty) {
- assert value != null;
- if (value.isNegative()) {
- style = "-fx-text-fill : blue";
- }
- }
- if (!empty && value.isHot()) {
- style = "-fx-text-fill : red";
- }
- setStyle(style);
- }
- };
- }
- });
-
- listview.setItems(captors);
- Parent root = FXMLLoader.load(getClass().getResource("/fxml/MainPage.fxml"));
- Scene scene = new Scene(root);
+ Parent root1 = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/MainPage.fxml")));
+ Scene scene1 = new Scene(root1);
primaryStage.setTitle("Station Météo");
primaryStage.setWidth(900);
primaryStage.setHeight(500);
- primaryStage.setScene(scene);
+ primaryStage.setScene(scene1);
primaryStage.show();
diff --git a/Source/src/model/Alea.java b/Source/src/model/Alea.java
deleted file mode 100644
index c2fefd7..0000000
--- a/Source/src/model/Alea.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package model;
-
-import java.util.Random;
-
-public class Alea implements GenererTemperature{
-
- private float temperature;
- private double min;
- private double max;
-
- public Alea(){
- this.temperature = genererTemperature();
- Random rand = new Random();
- min= rand.nextDouble();
- max= rand.nextDouble(min);
- }
- @Override
- public float genererTemperature() {
-
- Random rand = new Random();
- return rand.nextFloat()+rand.nextInt();
- }
-}
diff --git a/Source/src/model/CPUTemp.java b/Source/src/model/CPUTemp.java
index 083a59c..f5dd48a 100644
--- a/Source/src/model/CPUTemp.java
+++ b/Source/src/model/CPUTemp.java
@@ -1,18 +1,67 @@
package model;
+import javafx.application.Platform;
+import javafx.beans.property.DoubleProperty;
+import javafx.beans.property.SimpleDoubleProperty;
+import javafx.beans.property.SimpleStringProperty;
+import javafx.beans.value.ObservableValue;
+
import java.io.*;
-public class CPUTemp implements GenererTemperature{
+public class CPUTemp implements GenererTemperature, Runnable {
+
+ DoubleProperty temperature = new SimpleDoubleProperty(0.0);
- float temperature ;
+ String name ;
- public CPUTemp() throws IOException {
- this.temperature = genererTemperature();
+ public CPUTemp(String nom) throws IOException {
+ this.name=nom;
+ genererTemperature();
}
@Override
- public float genererTemperature() throws IOException {
+ public void genererTemperature() throws IOException {
File temp = new File("/sys/devices/virtual/thermal/thermal_zone6/temp");
BufferedReader br = new BufferedReader(new FileReader(temp));
- return Float.parseFloat(br.readLine())/1000;
+ setTemperature((double) (Float.parseFloat(br.readLine())/1000));
+ }
+
+ public void setTemperature(Double temperature){
+ this.temperature.set(temperature);
+ }
+
+ public DoubleProperty getTemperatureProperty(){
+ return this.temperature;
+ }
+
+ public String getTemperature(){
+ return this.temperature.get()+"";
+ }
+
+ @Override
+ public void run(){
+ while (true){
+ Platform.runLater(()-> {
+ try {
+ genererTemperature();
+ } catch (IOException ignored) {
+ }
+ });
+ try{
+ Thread.sleep(100);
+ }
+ catch (InterruptedException e){
+ break;
+ }
+ }
+ }
+
+ public void startThread(){
+ Thread threadCaptor = new Thread(this);
+ threadCaptor.setDaemon(true);
+ threadCaptor.start();
+ }
+
+ public String getName() {
+ return this.name;
}
}
diff --git a/Source/src/model/CapteurVirtuel.java b/Source/src/model/CapteurVirtuel.java
index 5a89e49..42adccd 100644
--- a/Source/src/model/CapteurVirtuel.java
+++ b/Source/src/model/CapteurVirtuel.java
@@ -82,4 +82,7 @@ public class CapteurVirtuel extends Sujet implements Runnable {
threadVirtualCaptor.start();
}
+ public String getName() {
+ return this.nom.get();
+ }
}
diff --git a/Source/src/model/Captor.java b/Source/src/model/Captor.java
index ba481c9..d76b539 100644
--- a/Source/src/model/Captor.java
+++ b/Source/src/model/Captor.java
@@ -48,7 +48,7 @@ public class Captor implements Runnable{
while (true){
Platform.runLater(()->setTemperature(rand.nextDouble(80.)-20.));
try{
- Thread.sleep(2999);
+ Thread.sleep(2000);
}
catch (InterruptedException e){
break;
diff --git a/Source/src/model/GenererTemperature.java b/Source/src/model/GenererTemperature.java
index 96364c5..03d0534 100644
--- a/Source/src/model/GenererTemperature.java
+++ b/Source/src/model/GenererTemperature.java
@@ -1,10 +1,9 @@
package model;
-import java.io.FileNotFoundException;
import java.io.IOException;
public interface GenererTemperature {
- abstract float genererTemperature() throws IOException;
+ abstract void genererTemperature() throws IOException;
}
diff --git a/Source/src/model/Reel.java b/Source/src/model/Reel.java
deleted file mode 100644
index c8ccf3f..0000000
--- a/Source/src/model/Reel.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package model;
-
-import java.util.Random;
-
-public class Reel implements GenererTemperature{
-
- Random rand = new Random();
- private float min = -30;
- private double max = 60;
- private float temperature = (float) (min + rand.nextFloat() * (max - min));
-
- public Reel(){
- this.temperature = genererTemperature();
-
- }
- @Override
- public float genererTemperature() {
- this.temperature=this.temperature + (-2 + rand.nextFloat() * (2-(-2)));
- return this.temperature;
- }
-}
diff --git a/Source/src/view/MainPage.java b/Source/src/view/MainPage.java
index 675d055..d49f5a3 100644
--- a/Source/src/view/MainPage.java
+++ b/Source/src/view/MainPage.java
@@ -1,19 +1,132 @@
package view;
-import console.LView;
-import javafx.event.EventHandler;
+import javafx.beans.value.ObservableValue;
+import javafx.collections.*;
import javafx.fxml.FXML;
-
-import java.awt.event.MouseEvent;
+import javafx.geometry.Pos;
+import javafx.scene.control.*;
+import javafx.scene.layout.*;
+import javafx.scene.text.Font;
+import javafx.util.Callback;
+import model.*;
+import java.io.IOException;
public class MainPage {
+
@FXML
- private javafx.scene.control.Label labelAvecBinding;
+ private Button FirstButton;
+
@FXML
- public void initialize() {
+ private VBox vb1;
+
+ @FXML
+ public void initialize() throws IOException {
+ CapteurVirtuel cV1 = new CapteurVirtuel("CaptVirt1");
+ CPUTemp cpuTemp = new CPUTemp("CPU Captor");
+
+ Captor c1 = new Captor("c1");
+ Captor c2 = new Captor("c2");
+ Captor c3 = new Captor("c3");
+
+ ListView listview = new ListView<>();
+
+ VBox FirstCaptorCPU = new VBox();
+ FirstCaptorCPU.setMinSize(565,470);
+ // FirstCaptorCPU.setBorder(new Border(new BorderStroke(Color.BLUE, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(3))));
+
+ javafx.scene.image.Image CPUImage = new javafx.scene.image.Image("https://media.istockphoto.com/id/1204740322/fr/photo/cpu.jpg?s=612x612&w=0&k=20&c=cF154ASgimXysleBPyYsFMI9_GKkkTpDQ0kZTJnm_K0=");
+ javafx.scene.image.ImageView FirstCaptorCPUImage = new javafx.scene.image.ImageView(CPUImage);
+
+ Label FirstCaptorCPULabel = new Label("Temperature");
+ FirstCaptorCPULabel.setFont(new Font("Arial", 30));
+ FirstCaptorCPULabel.setMaxWidth(Double.MAX_VALUE);
+ FirstCaptorCPULabel.setAlignment(Pos.CENTER);
+
+ FirstCaptorCPU.getChildren().add(FirstCaptorCPUImage);
+ FirstCaptorCPU.getChildren().add(FirstCaptorCPULabel);
+
+
- labelAvecBinding.textProperty().set("CPU Temperature");
-
+ ObservableList CPUTemperature = FXCollections.observableArrayList(
+ captor-> new ObservableValue[]{
+ captor.getTemperatureProperty()
+ }
+ );
+
+ CPUTemperature.addListener((ListChangeListener.Change extends CPUTemp> c) ->{
+ while (c.next()){
+ if (c.wasUpdated()){
+ FirstCaptorCPULabel.textProperty().set("Temperature du CPU : " + cpuTemp.getTemperature() + "°C");
+ }
+ }
+ });
+
+ ObservableList captors = FXCollections.observableArrayList(
+ captor->new ObservableValue[]{
+ captor.getTempMoyenneProperty()
+ }
+ );
+
+ captors.addListener((ListChangeListener.Change extends CapteurVirtuel> c) ->{
+ while (c.next()){
+ if (c.wasUpdated()){
+ listview.refresh();
+ }
+ }
+ });
+
+ c1.startThread();
+ c2.startThread();
+ c3.startThread();
+
+ cV1.addToLesCapteurs(c1);
+ cV1.addToLesCapteurs(c2);
+ cV1.addToLesCapteurs(c3);
+
+ cV1.startThread();
+
+ cpuTemp.startThread();
+
+ captors.add(cV1);
+
+ listview.setCellFactory(new Callback<>() {
+
+ @Override
+ public ListCell call(ListView captorListView) {
+ return new ListCell<>() {
+ @Override
+ protected void updateItem(CapteurVirtuel value, boolean empty) {
+ String text = "";
+ super.updateItem(value, empty);
+ if (value != null) {
+ text = value.getTempMoyenne().toString();
+ }
+ setText(text);
+ String style = null;
+ if (!empty) {
+ assert value != null;
+ if (value.isNegative()) {
+ style = "-fx-text-fill : blue";
+ }
+ }
+ if (!empty && value.isHot()) {
+ style = "-fx-text-fill : red";
+ }
+ setStyle(style);
+ }
+ };
+ }
+ });
+
+ listview.setItems(captors);
+ FirstButton.textProperty().set(cpuTemp.getName());
+ FirstCaptorCPULabel.textProperty().set("Temperature du CPU : " + cpuTemp.getTemperature() + "°C");
+ FirstButton.setOnAction(e -> {
+ vb1.getChildren().clear();
+ vb1.getChildren().add(FirstCaptorCPU);
+ });
}
+
+
}