commit 4c9e9ccc9446219064b5ca534f22dbf8093da294 Author: Theo DUPIN Date: Sun Jan 22 23:47:07 2023 +0100 first commit diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/libraries/lib.xml b/.idea/libraries/lib.xml new file mode 100644 index 0000000..fb1be37 --- /dev/null +++ b/.idea/libraries/lib.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a346fd7 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..8fa7630 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/TP2.iml b/TP2.iml new file mode 100644 index 0000000..59b3af2 --- /dev/null +++ b/TP2.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/TP2/fxml/CaptorMonitorWindow.fxml b/out/production/TP2/fxml/CaptorMonitorWindow.fxml new file mode 100644 index 0000000..14cfb6e --- /dev/null +++ b/out/production/TP2/fxml/CaptorMonitorWindow.fxml @@ -0,0 +1,36 @@ + + + + + + + +
+ + + + + +
+ + + + +
diff --git a/out/production/TP2/fxml/ImageWindow.fxml b/out/production/TP2/fxml/ImageWindow.fxml new file mode 100644 index 0000000..b292977 --- /dev/null +++ b/out/production/TP2/fxml/ImageWindow.fxml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + diff --git a/out/production/TP2/fxml/SpinnerWindow.fxml b/out/production/TP2/fxml/SpinnerWindow.fxml new file mode 100644 index 0000000..6edc77f --- /dev/null +++ b/out/production/TP2/fxml/SpinnerWindow.fxml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + diff --git a/out/production/TP2/img/chaud.png b/out/production/TP2/img/chaud.png new file mode 100644 index 0000000..0038870 Binary files /dev/null and b/out/production/TP2/img/chaud.png differ diff --git a/out/production/TP2/img/froid.png b/out/production/TP2/img/froid.png new file mode 100644 index 0000000..ec10873 Binary files /dev/null and b/out/production/TP2/img/froid.png differ diff --git a/out/production/TP2/img/moyen.png b/out/production/TP2/img/moyen.png new file mode 100644 index 0000000..adb6544 Binary files /dev/null and b/out/production/TP2/img/moyen.png differ diff --git a/out/production/TP2/launcher/Main.class b/out/production/TP2/launcher/Main.class new file mode 100644 index 0000000..3d1bfad Binary files /dev/null and b/out/production/TP2/launcher/Main.class differ diff --git a/out/production/TP2/model/Captor.class b/out/production/TP2/model/Captor.class new file mode 100644 index 0000000..7e99ded Binary files /dev/null and b/out/production/TP2/model/Captor.class differ diff --git a/out/production/TP2/model/CaptorBasique.class b/out/production/TP2/model/CaptorBasique.class new file mode 100644 index 0000000..494637b Binary files /dev/null and b/out/production/TP2/model/CaptorBasique.class differ diff --git a/out/production/TP2/model/CaptorZone.class b/out/production/TP2/model/CaptorZone.class new file mode 100644 index 0000000..ae6ef4b Binary files /dev/null and b/out/production/TP2/model/CaptorZone.class differ diff --git a/out/production/TP2/model/GenerationCPU.class b/out/production/TP2/model/GenerationCPU.class new file mode 100644 index 0000000..113dbb0 Binary files /dev/null and b/out/production/TP2/model/GenerationCPU.class differ diff --git a/out/production/TP2/model/GenerationRandom.class b/out/production/TP2/model/GenerationRandom.class new file mode 100644 index 0000000..269a7b9 Binary files /dev/null and b/out/production/TP2/model/GenerationRandom.class differ diff --git a/out/production/TP2/model/GenerationStrategy.class b/out/production/TP2/model/GenerationStrategy.class new file mode 100644 index 0000000..b2b51f1 Binary files /dev/null and b/out/production/TP2/model/GenerationStrategy.class differ diff --git a/out/production/TP2/model/Observable.class b/out/production/TP2/model/Observable.class new file mode 100644 index 0000000..72306c4 Binary files /dev/null and b/out/production/TP2/model/Observable.class differ diff --git a/out/production/TP2/model/Observer.class b/out/production/TP2/model/Observer.class new file mode 100644 index 0000000..2ddbb37 Binary files /dev/null and b/out/production/TP2/model/Observer.class differ diff --git a/out/production/TP2/view/CaptorMonitorWindow.class b/out/production/TP2/view/CaptorMonitorWindow.class new file mode 100644 index 0000000..f05570b Binary files /dev/null and b/out/production/TP2/view/CaptorMonitorWindow.class differ diff --git a/out/production/TP2/view/ControlWindow.class b/out/production/TP2/view/ControlWindow.class new file mode 100644 index 0000000..ae077db Binary files /dev/null and b/out/production/TP2/view/ControlWindow.class differ diff --git a/out/production/TP2/view/ImageWindow.class b/out/production/TP2/view/ImageWindow.class new file mode 100644 index 0000000..d61a1d8 Binary files /dev/null and b/out/production/TP2/view/ImageWindow.class differ diff --git a/out/production/TP2/view/SpinnerWindow.class b/out/production/TP2/view/SpinnerWindow.class new file mode 100644 index 0000000..0744d01 Binary files /dev/null and b/out/production/TP2/view/SpinnerWindow.class differ diff --git a/res/fxml/CaptorMonitorWindow.fxml b/res/fxml/CaptorMonitorWindow.fxml new file mode 100644 index 0000000..b91312c --- /dev/null +++ b/res/fxml/CaptorMonitorWindow.fxml @@ -0,0 +1,57 @@ + + + + + + + + + +
+ + +
+ + + Id : + + + + + Nom du capteur : + + + + +
+
+ +
+ + + + + + + + +
+ + +
+ +
+
+
+
+
+ +
+ + + + +
diff --git a/res/fxml/ImageWindow.fxml b/res/fxml/ImageWindow.fxml new file mode 100644 index 0000000..b292977 --- /dev/null +++ b/res/fxml/ImageWindow.fxml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + diff --git a/res/fxml/SpinnerWindow.fxml b/res/fxml/SpinnerWindow.fxml new file mode 100644 index 0000000..51efe97 --- /dev/null +++ b/res/fxml/SpinnerWindow.fxml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + diff --git a/res/img/chaud.png b/res/img/chaud.png new file mode 100644 index 0000000..0038870 Binary files /dev/null and b/res/img/chaud.png differ diff --git a/res/img/froid.png b/res/img/froid.png new file mode 100644 index 0000000..ec10873 Binary files /dev/null and b/res/img/froid.png differ diff --git a/res/img/moyen.png b/res/img/moyen.png new file mode 100644 index 0000000..adb6544 Binary files /dev/null and b/res/img/moyen.png differ diff --git a/src/launcher/Main.java b/src/launcher/Main.java new file mode 100644 index 0000000..fb81735 --- /dev/null +++ b/src/launcher/Main.java @@ -0,0 +1,48 @@ +package launcher; + +import javafx.application.Application; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.TextField; +import javafx.scene.control.TreeItem; +import javafx.scene.control.TreeView; +import javafx.stage.Stage; +import model.Captor; + +public class Main extends Application { + + @FXML + private TreeView treeView; + @FXML + private TreeItem root; + + @FXML + private TextField texte; + + + @Override + public void start(Stage stage) throws Exception { + // Fenêtre Principale + Parent monitorWindow = FXMLLoader.load(getClass().getResource("/fxml/CaptorMonitorWindow.fxml")); + Stage monitorWindowStage = new Stage(); + monitorWindowStage.setScene(new Scene(monitorWindow)); + monitorWindowStage.setTitle("CaptorMonitorWindow"); + monitorWindowStage.show(); + + // Fenêtre Image + Parent image = FXMLLoader.load(getClass().getResource("/fxml/ImageWindow.fxml")); + Stage imageStage = new Stage(); + imageStage.setScene(new Scene(image)); + imageStage.setTitle("ImageWindow"); + imageStage.show(); + + // Fenêtre Spinner + /*Parent spinner = FXMLLoader.load(getClass().getResource("/fxml/SpinnerWindow.fxml")); + Stage spinnerStage = new Stage(); + spinnerStage.setScene(new Scene(spinner)); + spinnerStage.setTitle("SpinnerWindow"); + spinnerStage.show();*/ + } +} diff --git a/src/model/Captor.java b/src/model/Captor.java new file mode 100644 index 0000000..4517bc1 --- /dev/null +++ b/src/model/Captor.java @@ -0,0 +1,70 @@ +package model; + +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +import java.util.UUID; + +public abstract class Captor extends Observable { + // Id Property + private StringProperty id = new SimpleStringProperty(); + public String getId(){ + return id.get(); + } + public void setId(String newId){ + id.set(newId); + } + public StringProperty idProperty(){ + return id; + } + + // Name property + private StringProperty name = new SimpleStringProperty(); + public String getName(){ + return name.get(); + } + public void setName(String newName){ + name.set(newName); + } + public StringProperty nameProperty(){ + return name; + } + + // Temperature property + private DoubleProperty temp = new SimpleDoubleProperty(); + public double getTemp(){ + return temp.get(); + } + public void setTemp(double newTemp){ + temp.set(newTemp); + } + public DoubleProperty tempProperty(){ + return temp; + } + // Generation + private String generationStrategy; + + Captor(String name){ + this.setName(name); + this.setId(UUID.randomUUID().toString()); + this.setTemp(0); + } + + public void setStrategie(String s){ + this.generationStrategy = s; + } + + public String getGenerationStrategy() { + return this.generationStrategy; + } + + public void add(Captor captor,double coef){} + + public abstract void run(); + + public String toString(){ + return getName(); + } +} diff --git a/src/model/CaptorBasique.java b/src/model/CaptorBasique.java new file mode 100644 index 0000000..1cebb71 --- /dev/null +++ b/src/model/CaptorBasique.java @@ -0,0 +1,61 @@ +package model; + +import javafx.application.Platform; + +public class CaptorBasique extends Captor { + private GenerationStrategy generationStrategy; + private int poids = 0; + private int delay = 1000; + public CaptorBasique(String nom, GenerationStrategy generation) { + super(nom); + this.generationStrategy = generation; + if(!(generationStrategy instanceof GenerationRandom)){ + Thread t = new Thread((Runnable) this); + t.setDaemon(true); + t.start(); + } + + } + + @Override + public void run(){ + while (true){ + try{ + Platform.runLater( () -> this.setTemp(generationStrategy.generator())); + Thread.sleep(this.delay); + } + catch (InterruptedException e){ + break; + } + } + } + + @Override + public String toString() { + return "[" + super.getId() + "] " + super.getName() + ": " + generationStrategy.toString(); + } + + public int getPoids() { + return poids; + } + + public void setPoids(int poids) { + this.poids = poids; + } + + public GenerationStrategy getGenStrat() { + return generationStrategy; + } + + public void setGenStrat(GenerationStrategy generationStrategy) { + this.generationStrategy = generationStrategy; + } + + public int getDelay() { + return delay; + } + + public void setDelay(int delay) { + this.delay = delay; + } +} diff --git a/src/model/CaptorZone.java b/src/model/CaptorZone.java new file mode 100644 index 0000000..88f340b --- /dev/null +++ b/src/model/CaptorZone.java @@ -0,0 +1,75 @@ +package model; + +import javafx.application.Platform; + +import java.util.ArrayList; +import java.util.List; + +public class CaptorZone extends Captor{ + private List listeCapteurs = new ArrayList(); + + private int poids = 0; + + private String generationStrategy = "Capteur Virtuel"; + + public CaptorZone(String nom) { + super(nom); + Thread t = new Thread((Runnable) this); + t.setDaemon(true); + t.start(); + } + + public int getPoids() { + return poids; + } + + public void setPoids(int poids) { + this.poids = poids; + } + + public String getGenerateurStrategique() { + return generationStrategy; + } + + @Override + public String toString() { + return "[" + super.getId() + "] " + super.getName() + ": Virtuel"; + } + + public void addToList(Captor c){ + this.listeCapteurs.add(c); + } + + public void removeToList(Captor c){ + listeCapteurs.remove(c); + } + + public List getListeCapteurs() { + return listeCapteurs; + } + + @Override + public void run(){ + while (true){ + try{ + Platform.runLater(() -> { + if(listeCapteurs.isEmpty()) return; + double temperatureMoyenne = 0; + int err = 0; + for(Captor c : listeCapteurs){ + if(c == null){ + err++; + break; + } + temperatureMoyenne += c.getTemp(); + } + this.setTemp(temperatureMoyenne/(listeCapteurs.size()-err)); + } ); + Thread.sleep(1000); + } + catch (InterruptedException e){ + break; + } + } + } +} diff --git a/src/model/GenerationCPU.java b/src/model/GenerationCPU.java new file mode 100644 index 0000000..643719c --- /dev/null +++ b/src/model/GenerationCPU.java @@ -0,0 +1,20 @@ +package model; + +import com.sun.management.OperatingSystemMXBean; + +import java.lang.management.ManagementFactory; + +public class GenerationCPU implements GenerationStrategy { + + public GenerationCPU() { + generator(); + } + + @Override + public double generator() { + OperatingSystemMXBean sysBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); + double temperature = sysBean.getSystemCpuLoad() * 100; + System.out.println("La température du CPU est de " + temperature + "°C"); + return temperature; + } +} diff --git a/src/model/GenerationRandom.java b/src/model/GenerationRandom.java new file mode 100644 index 0000000..fa0f389 --- /dev/null +++ b/src/model/GenerationRandom.java @@ -0,0 +1,9 @@ +package model; + +public class GenerationRandom implements GenerationStrategy{ + @Override + public double generator() { + double tmp = Math.random()/Math.nextDown(1); + return 0*(1 - tmp) + 50 * tmp; + } +} diff --git a/src/model/GenerationStrategy.java b/src/model/GenerationStrategy.java new file mode 100644 index 0000000..048f735 --- /dev/null +++ b/src/model/GenerationStrategy.java @@ -0,0 +1,6 @@ +package model; + +public interface GenerationStrategy { + + public abstract double generator(); +} diff --git a/src/model/Observable.java b/src/model/Observable.java new file mode 100644 index 0000000..711cbc0 --- /dev/null +++ b/src/model/Observable.java @@ -0,0 +1,21 @@ +package model; + +import java.util.List; + +public class Observable { + protected List observers; + + public void attach(Observer o) { + observers.add(o); + } + + public void detach(Observer o) { + observers.remove(o); + } + + public void notifyObserver() { + for(Observer o : observers) { + o.update(); + } + } +} diff --git a/src/model/Observer.java b/src/model/Observer.java new file mode 100644 index 0000000..8d8c7b8 --- /dev/null +++ b/src/model/Observer.java @@ -0,0 +1,5 @@ +package model; + +public interface Observer { + public abstract void update(); +} diff --git a/src/view/CaptorMonitorWindow.java b/src/view/CaptorMonitorWindow.java new file mode 100644 index 0000000..dc0e2dc --- /dev/null +++ b/src/view/CaptorMonitorWindow.java @@ -0,0 +1,35 @@ +package view; + +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.control.*; +import javafx.scene.layout.VBox; +import model.CaptorBasique; + +import java.io.IOException; + +public class CaptorMonitorWindow extends VBox { + @FXML + private Label idCapteur; + @FXML + private TextField nomCapteur; + + CaptorBasique captorBasique; + + + public void CaptorMonitorWindow(CaptorBasique c){ + FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/CaptorMonitorWindow.fxml")); + loader.setRoot(this); + loader.setController(this); + try { + loader.load(); + } catch (IOException e) { + throw new RuntimeException(e); + } + + this.captorBasique = c; + + idCapteur.setText("ID: " + captorBasique.getId()); + nomCapteur.setText(captorBasique.getName()); + } +} diff --git a/src/view/ControlWindow.java b/src/view/ControlWindow.java new file mode 100644 index 0000000..66f8b17 --- /dev/null +++ b/src/view/ControlWindow.java @@ -0,0 +1,33 @@ +package view; + +import javafx.stage.Stage; + +public class ControlWindow extends Stage { + + private String title; + private String pathToFXMLRessource; + + + public ControlWindow(){} + public ControlWindow(String title,String pathToFXMLRessource){ + this.title = title; + this.pathToFXMLRessource = pathToFXMLRessource; + } + + public String getTitleFXMLWindow() { + return this.title; + } + + public void setTitleFXMLWindow(String title) { + this.title = title; + } + + public String getPathToFXMLRessource(){ + return this.pathToFXMLRessource; + } + + public void setPathToFXMLRessource(String pathToFXMLRessource) { + this.pathToFXMLRessource = pathToFXMLRessource; + } + +} diff --git a/src/view/ImageWindow.java b/src/view/ImageWindow.java new file mode 100644 index 0000000..5c9e17a --- /dev/null +++ b/src/view/ImageWindow.java @@ -0,0 +1,45 @@ +package view; + +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.stage.Stage; +import model.Captor; + +import java.util.List; + +public class ImageWindow extends CaptorMonitorWindow { + + @FXML + private Button buttonExit; + @FXML + private ImageView imageView; + private Captor capteur; + private List listeCapteurs; + + + public ImageWindow(List liste){ + this.listeCapteurs = liste; + } + + public void update() { + if (capteur.getTemp() <= 0) { + this.imageView.setImage(new javafx.scene.image.Image("/img/froid.png")); + } else if (capteur.getTemp() >= 40) { + this.imageView.setImage(new javafx.scene.image.Image("/img/chaud.png")); + } else { + this.imageView.setImage(new javafx.scene.image.Image("/img/moyen.png")); + } + } + + public void initialize(){ + this.imageView.setImage(new Image("/img/chaud.png")); + this.update(); + } + + public void exit(){ + Stage stage = (Stage) buttonExit.getScene().getWindow(); + stage.close(); + } +} diff --git a/src/view/SpinnerWindow.java b/src/view/SpinnerWindow.java new file mode 100644 index 0000000..00a61a4 --- /dev/null +++ b/src/view/SpinnerWindow.java @@ -0,0 +1,26 @@ +package view; + +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.Spinner; +import javafx.scene.control.TextField; +import javafx.stage.Stage; +import model.Captor; + +import java.util.ArrayList; +import java.util.List; + +public class SpinnerWindow extends CaptorMonitorWindow { + @FXML + private Button buttonExit; + @FXML + private Spinner spinner; + @FXML + private TextField textField; + private List captorList = new ArrayList<>(); + + public void exit(){ + Stage stage = (Stage) buttonExit.getScene().getWindow(); + stage.close(); + } +}