New functionalities (addition, Thermostat view, change the strategy and temp ...), improved views and README

master
Emre KARTAL 2 years ago
parent 579071960f
commit 0a70c6691d

@ -1,15 +1,29 @@
# Thermostat (via JavaFX)
:information_source: Une application qui permet de visualiser (et contrôler) un capteur de température
:information_source: Réalisation d'une application qui permet de visualiser (et contrôler) des capteurs de température
> <u>Une fenêtre avec un thermostat</u> : un spinner qui affiche et changer la température du capteur
Plus précisément, on retrouve :
> <u>La fenêtre principale</u> : affiche la liste de tous les capteurs et lorsqu'on clique sur un capteur en particulier ces informations s'affichent.
<br>
<u>Une fenêtre avec une image</u> : représentant la température du capteur (pour les valeurs < 0°c on a une image de neige/glace, entre 0°c et 25°c une image de nuageux etc.)
<u>Une fenêtre avec un thermostat</u> : un spinner qui affiche et changer la température du capteur.
<br>
<u>Une fenêtre avec une image</u> : représentant la température du capteur (pour les valeurs < 0°c on a une image de neige/glace, entre 0°c et 25°c une image de nuageux, etc.).
<br>
De plus, si la fenêtre principale se ferme, toutes les autres fenêtres se ferment.
## Fonctionnement
- ### Comment lancer le projet ?
:information_source: *Si vous ne disposez pas d'Intellij IDEA, allé sur le site [jetbrains](https://www.jetbrains.com/idea/download/#section=windows) pour pouvoir le télécharger !!!*
Comme nous allons devoir utiliser la bibliothèque JavaFX, il va falloir l'installer, pour cela rendez-vous sur le site [Download JavaFX](https://gluonhq.com/products/javafx/) et installer sur le système d'exploitation que vous souhaitez (Windows, Linux, etc.), cependant veuillez à choisir l'architecture "x64" et le type "SDK" !
Lorsque que tout est installé, cloner le dépôt et configurer l'idea (mais aussi n'oubliez de configurer le lancement de l'application via le "launcher.main").
<br>
:information_source: *Pour vous aider à la configurer, vous pouvez utiliser le site [Doc JavaFX](https://openjfx.io/openjfx-docs/) !*
Lorsque tout est bon, vous pouvez lancer et profiter de l'application. :thumbsup:
## Fonctionnement
```plantuml
@startuml
@ -43,7 +57,7 @@ class CaptorMonitorWindow {
}
class ImageWindow {
- IMAGES : NavigableMap<Double,image>
-{static}Images : NavigableMap<Double,Image>
+imageWindow(captor : Captor)
+update()
@ -57,7 +71,7 @@ class ThermostatWindow {
}
class CaptorWindow {
+openWindow(type : String, captor : Captor)
+openWindow(type : CaptorMonitorWindow)
}
}
@ -67,6 +81,8 @@ package model {
class VisitorCaptor {
+visit(captor : CaptorArea) : TreeItem<Captor>
+visit(captor : CaptorBasic) : TreeItem<Captor>
+details(captor : CaptorArea) : HBox
+details(captor : CaptorBasic) : HBox
}
class CaptorStationStub {
@ -88,6 +104,7 @@ class Captor {
+addCaptor(captor : Captor)
+getTemperature() : double
+accept(visitorCaptor : VisitorCaptor) : TreeItem<Captor>
+details(visitorCaptor VisitorCaptor) : HBox
}
interface GenerationStrategy {
@ -132,8 +149,9 @@ FXMLWindow --|> "Extends" Stage
CaptorMonitorWindow --|> FXMLWindow
CaptorMonitorWindow --> "-captor" Captor
CaptorMonitorWindow ..|> Observer
CaptorArea ..|> Observer
ImageWindow --|> CaptorMonitorWindow
ThermostaWindow --|> CaptorMonitorWindow
ThermostatWindow --|> CaptorMonitorWindow
CaptorStationStub --> "*-captors" Captor
GenBoundedRandom ..|> GenerationStrategy
GenFloatingBound ..|> GenerationStrategy
@ -151,8 +169,7 @@ Observable --> "-observers" Observer
@enduml
```
## Répartition du Gitlab
# Répartition du Gitlab
La racine de mon gitlab est composée de deux doissers essentiels au projet :
@ -162,7 +179,7 @@ La racine de mon gitlab est composée de deux doissers essentiels au projet :
## Environnement de Travail
L'environnement de travail se base sur un outil en particulier :👇
L'environnement de travail se base sur plusieurs outils :
<div align = center>

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 209 KiB

After

Width:  |  Height:  |  Size: 162 KiB

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="lib">
<CLASSES>
<root url="file://$PROJECT_DIR$/../../../../javafx-sdk-19.0.2.1/lib" />
</CLASSES>
<JAVADOC />
<SOURCES />
<jarDirectory url="file://$PROJECT_DIR$/../../../../javafx-sdk-19.0.2.1/lib" recursive="false" />
</library>
</component>

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="18" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -21,5 +21,6 @@
<jarDirectory url="file://$PATH_TO_JAVAFX$" recursive="false" />
</library>
</orderEntry>
<orderEntry type="library" name="lib" level="project" />
</component>
</module>

@ -7,15 +7,21 @@
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Text?>
<BorderPane xmlns:fx="http://javafx.com/fxml" style="-fx-background-color: skyblue;" minWidth="500" fx:controller="view.CaptorWindow">
<BorderPane xmlns:fx="http://javafx.com/fxml" style="-fx-background-color: skyblue;" minWidth="500"
fx:controller="view.CaptorWindow">
<left>
<BorderPane style="-fx-background-color: white;">
<top>
<TreeView fx:id="lvCaptors" maxWidth="200"/>
<Button style="-fx-background-color: transparent; -fx-font-weight: bold;" mnemonicParsing="false"
onAction="#buttonAdd" text="Ajouter" BorderPane.alignment="CENTER"/>
</top>
<center>
<TreeView fx:id="lvCaptors" maxWidth="200"/>
</center>
<bottom>
<Button style="-fx-background-color: transparent; -fx-font-weight: bold;" mnemonicParsing="false" onAction="#buttonExit" text="Fermer" BorderPane.alignment="CENTER" />
<Button style="-fx-background-color: transparent; -fx-font-weight: bold;" mnemonicParsing="false"
onAction="#buttonExit" text="Fermer" BorderPane.alignment="CENTER"/>
</bottom>
</BorderPane>
</left>
@ -23,21 +29,22 @@
<center>
<BorderPane fx:id="master">
<top>
<VBox>
<VBox fx:id="vBoxMaster">
<HBox>
<Text text="UUID :" style="-fx-fill: white; -fx-font-weight: bold;"/>
<Label fx:id="id" maxWidth="250"/>
</HBox>
<HBox>
<Text text="NOM :" style="-fx-fill: white; -fx-font-weight: bold;" />
<Text text="NOM :" style="-fx-fill: white; -fx-font-weight: bold;"/>
<TextField fx:id="nom" maxWidth="250"/>
<Button text="STOP" fx:id="buttonChange" onAction="#changeCaptor"/>
</HBox>
</VBox>
</top>
<bottom>
<HBox>
<Button mnemonicParsing="false" text="Image" onAction="#openWindowImage"/>
<Button mnemonicParsing="false" text="Thermostat" onAction="#openWindowThermosta"/>
<Button mnemonicParsing="false" text="Thermostat" onAction="#openWindowThermostat"/>
</HBox>
</bottom>
</BorderPane>

@ -7,19 +7,21 @@
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.StackPane?>
<BorderPane prefHeight="250.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/18"
<BorderPane prefHeight="250.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/18"
xmlns:fx="http://javafx.com/fxml/1">
<top>
<Label fx:id="nom" style="-fx-font-weight: bold; -fx-font-size: 22;" BorderPane.alignment="CENTER"/>
</top>
<center>
<StackPane>
<ImageView fx:id="image" fitHeight="350.0" fitWidth="500.0" pickOnBounds="true" preserveRatio="true" BorderPane.alignment="CENTER"/>
<ImageView fx:id="image" fitHeight="350.0" fitWidth="500.0" pickOnBounds="true" preserveRatio="true"
BorderPane.alignment="CENTER"/>
<Label fx:id="labelTemp" style="-fx-font-weight: bold;" BorderPane.alignment="CENTER"/>
</StackPane>
</center>
<bottom>
<Button style="-fx-background-color: transparent; -fx-font-weight: bold;" mnemonicParsing="false" onAction="#buttonExit" text="Fermer" BorderPane.alignment="CENTER">
<Button style="-fx-background-color: transparent; -fx-font-weight: bold;" mnemonicParsing="false"
onAction="#buttonExit" text="Fermer" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets bottom="30.0" top="50.0"/>
</BorderPane.margin>

@ -8,28 +8,18 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.control.Label?>
<BorderPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/18"
xmlns:fx="http://javafx.com/fxml/1">
<center>
<Slider orientation="VERTICAL" BorderPane.alignment="CENTER" fx:id="slider" onMouseClicked="#onChange"
onMouseDragged="#onChange" showTickLabels="true" showTickMarks="true" min="-30" max="70" value="0">
<BorderPane.margin>
<Insets/>
</BorderPane.margin>
</Slider>
onMouseDragged="#onChange" showTickLabels="true" showTickMarks="true" min="-30" max="70" value="0"/>
</center>
<bottom>
<Button style="-fx-background-color: transparent; -fx-font-weight: bold;" mnemonicParsing="false" onAction="#buttonExit" text="Fermer" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets bottom="30.0" top="50.0"/>
</BorderPane.margin>
</Button>
</bottom>
<top>
<VBox alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
prefHeight="50.0" prefWidth="100.0" BorderPane.alignment="CENTER">
prefHeight="50.0" prefWidth="130.0" BorderPane.alignment="CENTER">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Thermostat"/>
<Label fx:id="nom" style="-fx-font-weight: bold; -fx-font-size: 22;" BorderPane.alignment="CENTER"/>
<HBox prefHeight="100.0" prefWidth="200.0">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Température :">
@ -37,7 +27,7 @@
<Insets right="5.0"/>
</HBox.margin>
</Text>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="XXX" fx:id="valTemperature"/>
<Label fx:id="labelTemp" style="-fx-font-weight: bold;" BorderPane.alignment="CENTER"/>
</children>
</HBox>
</children>
@ -46,4 +36,12 @@
</BorderPane.margin>
</VBox>
</top>
<bottom>
<Button style="-fx-background-color: transparent; -fx-font-weight: bold;" mnemonicParsing="false"
onAction="#buttonExit" text="Fermer" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets bottom="30.0" top="50.0"/>
</BorderPane.margin>
</Button>
</bottom>
</BorderPane>

@ -13,8 +13,12 @@
<left>
<BorderPane style="-fx-background-color: white;">
<top>
<TreeView fx:id="lvCaptors" maxWidth="200"/>
<Button style="-fx-background-color: transparent; -fx-font-weight: bold;" mnemonicParsing="false"
onAction="#buttonAdd" text="Ajouter" BorderPane.alignment="CENTER"/>
</top>
<center>
<TreeView fx:id="lvCaptors" maxWidth="200"/>
</center>
<bottom>
<Button style="-fx-background-color: transparent; -fx-font-weight: bold;" mnemonicParsing="false"
onAction="#buttonExit" text="Fermer" BorderPane.alignment="CENTER"/>
@ -25,7 +29,7 @@
<center>
<BorderPane fx:id="master">
<top>
<VBox>
<VBox fx:id="vBoxMaster">
<HBox>
<Text text="UUID :" style="-fx-fill: white; -fx-font-weight: bold;"/>
<Label fx:id="id" maxWidth="250"/>
@ -33,13 +37,14 @@
<HBox>
<Text text="NOM :" style="-fx-fill: white; -fx-font-weight: bold;"/>
<TextField fx:id="nom" maxWidth="250"/>
<Button text="STOP" fx:id="buttonChange" onAction="#changeCaptor"/>
</HBox>
</VBox>
</top>
<bottom>
<HBox>
<Button mnemonicParsing="false" text="Image" onAction="#openWindowImage"/>
<Button mnemonicParsing="false" text="Thermostat" onAction="#openWindowThermosta"/>
<Button mnemonicParsing="false" text="Thermostat" onAction="#openWindowThermostat"/>
</HBox>
</bottom>
</BorderPane>

@ -7,14 +7,15 @@
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.StackPane?>
<BorderPane prefHeight="250.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/18"
<BorderPane prefHeight="250.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/18"
xmlns:fx="http://javafx.com/fxml/1">
<top>
<Label fx:id="nom" style="-fx-font-weight: bold; -fx-font-size: 22;" BorderPane.alignment="CENTER"/>
</top>
<center>
<StackPane>
<ImageView fx:id="image" fitHeight="350.0" fitWidth="500.0" pickOnBounds="true" preserveRatio="true" BorderPane.alignment="CENTER"/>
<ImageView fx:id="image" fitHeight="350.0" fitWidth="500.0" pickOnBounds="true" preserveRatio="true"
BorderPane.alignment="CENTER"/>
<Label fx:id="labelTemp" style="-fx-font-weight: bold;" BorderPane.alignment="CENTER"/>
</StackPane>
</center>

@ -8,29 +8,18 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.control.Label?>
<BorderPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/18"
xmlns:fx="http://javafx.com/fxml/1">
<center>
<Slider orientation="VERTICAL" BorderPane.alignment="CENTER" fx:id="slider" onMouseClicked="#onChange"
onMouseDragged="#onChange" showTickLabels="true" showTickMarks="true" min="-30" max="70" value="0">
<BorderPane.margin>
<Insets/>
</BorderPane.margin>
</Slider>
onMouseDragged="#onChange" showTickLabels="true" showTickMarks="true" min="-30" max="70" value="0"/>
</center>
<bottom>
<Button style="-fx-background-color: transparent; -fx-font-weight: bold;" mnemonicParsing="false"
onAction="#buttonExit" text="Fermer" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets bottom="30.0" top="50.0"/>
</BorderPane.margin>
</Button>
</bottom>
<top>
<VBox alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
prefHeight="50.0" prefWidth="100.0" BorderPane.alignment="CENTER">
prefHeight="50.0" prefWidth="130.0" BorderPane.alignment="CENTER">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Thermostat"/>
<Label fx:id="nom" style="-fx-font-weight: bold; -fx-font-size: 22;" BorderPane.alignment="CENTER"/>
<HBox prefHeight="100.0" prefWidth="200.0">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Température :">
@ -38,7 +27,7 @@
<Insets right="5.0"/>
</HBox.margin>
</Text>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="XXX" fx:id="valTemperature"/>
<Label fx:id="labelTemp" style="-fx-font-weight: bold;" BorderPane.alignment="CENTER"/>
</children>
</HBox>
</children>
@ -47,4 +36,12 @@
</BorderPane.margin>
</VBox>
</top>
<bottom>
<Button style="-fx-background-color: transparent; -fx-font-weight: bold;" mnemonicParsing="false"
onAction="#buttonExit" text="Fermer" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets bottom="30.0" top="50.0"/>
</BorderPane.margin>
</Button>
</bottom>
</BorderPane>

@ -18,7 +18,7 @@ public class Console {
// CaptorArea
Captor captorZone = new CaptorArea("Europe", new HashMap<>());
Captor captorZone = new CaptorArea("Europe");
captorZone.addCaptor(captor1, 20.0);
captorZone.addCaptor(captor2, 40.0);
System.out.println(captorZone.getId() + ": " + captorZone.getName() + ", temperature : " + captorZone.getTemperature());

@ -1,8 +1,11 @@
package model;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.control.TreeItem;
import javafx.scene.layout.HBox;
import java.util.List;
import java.util.UUID;
@ -11,13 +14,13 @@ public abstract class Captor extends Observable {
private UUID id;
private StringProperty name;
private double value;
private double time;
private DoubleProperty value;
private DoubleProperty time;
public Captor(String name) {
this.id = UUID.randomUUID();
this.name = new SimpleStringProperty(name);
this.time = 4;
this.time = new SimpleDoubleProperty(4);
}
public UUID getId() {
@ -32,6 +35,10 @@ public abstract class Captor extends Observable {
this.name = new SimpleStringProperty(name);
}
public final StringProperty nameProperty() {
return name;
}
public abstract double getTemperature();
public abstract List<Captor> getCaptors() throws Exception;
@ -48,21 +55,28 @@ public abstract class Captor extends Observable {
}
public double getTime() {
return time;
return time.getValue();
}
public void setTime(double time) {
this.time = time;
this.time = new SimpleDoubleProperty(time);
}
public double getValue() {
public DoubleProperty getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
this.value = new SimpleDoubleProperty(value);
this.notifyAllObservers();
}
public abstract TreeItem<Captor> accept(VisitorCaptor visitorCaptor) throws Exception;
public abstract HBox details(VisitorCaptor visitorCaptor) throws Exception;
public abstract void stop();
public abstract void start();
}

@ -2,16 +2,18 @@ package model;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.control.TreeItem;
import javafx.scene.layout.HBox;
import java.util.*;
public class CaptorArea extends Captor {
public class CaptorArea extends Captor implements Observer {
Map<Captor, Double> captors = new HashMap<>();
public CaptorArea(String name, Map<Captor, Double> captors) {
public CaptorArea(String name) {
super(name);
this.captors = captors;
captors = new HashMap<>();
setValue(10);
}
@Override
@ -33,7 +35,7 @@ public class CaptorArea extends Captor {
Captor captor = entry.getKey();
double weight = entry.getValue();
temperatureSum += captor.getTemperature() * weight;
temperatureSum += captor.getValue().doubleValue() * weight;
weightSum += weight;
}
@ -51,6 +53,7 @@ public class CaptorArea extends Captor {
@Override
public void addCaptor(Captor captor, double weight) throws Exception {
captor.attach(this);
captors.put(captor, weight);
}
@ -59,4 +62,27 @@ public class CaptorArea extends Captor {
return visitorCaptor.visit(this);
}
@Override
public HBox details(VisitorCaptor visitorCaptor) throws Exception {
return visitorCaptor.details(this);
}
@Override
public void stop() {
for (Map.Entry<Captor, Double> entry : captors.entrySet()) {
entry.getKey().stop();
}
}
@Override
public void start() {
for (Map.Entry<Captor, Double> entry : captors.entrySet()) {
entry.getKey().start();
}
}
@Override
public void update() {
setValue(getTemperature());
}
}

@ -3,8 +3,11 @@ package model;
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.control.TreeItem;
import javafx.scene.layout.HBox;
import javafx.util.Duration;
import java.util.List;
@ -12,6 +15,7 @@ import java.util.Map;
public class CaptorBasic extends Captor implements Runnable {
private Timeline time;
private GenStrategy genStrategie;
public CaptorBasic(String name, GenStrategy genStrategie) {
@ -48,18 +52,32 @@ public class CaptorBasic extends Captor implements Runnable {
@Override
public void run() {
Timeline time = new Timeline(
time = new Timeline(
new KeyFrame(Duration.seconds(this.getTime()), event -> {
if (getGenStrategy() != null) {
this.setValue(this.getGenStrategy().generate());
}
}
));
time.setCycleCount(Animation.INDEFINITE);
time.play();
}
@Override
public HBox details(VisitorCaptor visitorCaptor) {
return visitorCaptor.details(this);
}
@Override
public void stop() {
time.stop();
}
@Override
public void start() {
run();
}
@Override
public TreeItem<Captor> accept(VisitorCaptor visitorCaptor) {
return visitorCaptor.visit(this);

@ -19,7 +19,7 @@ public class CaptorStationStub {
Captor captor2 = new CaptorBasic("Italie", new GenBoundedRandom(-10, 60));
// CaptorArea
Captor captorZone = new CaptorArea("Europe", new HashMap<>()) {{
Captor captorZone = new CaptorArea("Europe") {{
addCaptor(captor1, 20.0);
addCaptor(captor2, 40.0);
}};

@ -8,7 +8,6 @@ public class GenCPU implements GenStrategy {
@Override
public double generate() {
File file = new File("/sys/class/thermal/thermal_zone2/temp");
Scanner scanner = null;
String line = null;

@ -7,11 +7,11 @@ public abstract class Observable {
private List<Observer> observers = new ArrayList<>();
public void add(Observer o) {
public void attach(Observer o) {
observers.add(o);
}
public void remove(Observer o) {
public void detach(Observer o) {
observers.remove(o);
}

@ -0,0 +1,15 @@
package model;
import java.util.HashMap;
import java.util.Map;
public class StrategyStub {
public Map<String, GenStrategy> strategies =new HashMap<String,GenStrategy>();
public StrategyStub(){
strategies.put("Cpu",new GenCPU());
strategies.put("Random",new GenBoundedRandom(-30,40));
}
}

@ -1,14 +1,19 @@
package model;
import javafx.scene.control.TreeItem;
import javafx.beans.property.StringProperty;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import java.util.Map;
public class VisitorCaptor {
public TreeItem<Captor> visit(CaptorArea captor) throws Exception {
TreeItem<Captor> itemCaptor = new TreeItem<>(captor, new ImageView(new Image(getClass().getResourceAsStream("/images/multi_captor_icon.png"))));
itemCaptor.setExpanded(true);
for (Captor c : captor.getCaptors()) {
itemCaptor.getChildren().add(c.accept(this));
}
@ -20,5 +25,66 @@ public class VisitorCaptor {
return itemCaptor;
}
public HBox details(CaptorArea captor) throws Exception {
HBox hbox = new HBox();
TableView<Captor> tableView = new TableView<>();
tableView.setPrefWidth(300);
tableView.setPrefHeight(380);
TableColumn<Captor, StringProperty> column = new TableColumn<>("Enfant");
tableView.getColumns().add(column);
column.setCellValueFactory(
new PropertyValueFactory<>("name"));
for (Captor capteur : captor.getCaptors()) {
tableView.getItems().add(capteur);
}
hbox.getChildren().add(tableView);
return hbox;
}
public HBox details(CaptorBasic captor) {
HBox hbox = new HBox();
// For the strategy
Text text = new Text();
text.setText("STRATEGIE :");
text.setStyle("-fx-font-weight: bold; -fx-fill: white;");
hbox.getChildren().add(text);
StrategyStub strategyStub = new StrategyStub();
ComboBox<String> comboBox = new ComboBox<>();
for (Map.Entry<String, GenStrategy> mesure : strategyStub.strategies.entrySet()) {
comboBox.getItems().add(mesure.getKey());
if (mesure.getValue().getClass() == captor.getGenStrategy().getClass()) {
comboBox.setValue(mesure.getKey());
}
}
comboBox.setOnAction(event -> {
String selectedStrategy = comboBox.getValue();
GenStrategy strategy = strategyStub.strategies.get(selectedStrategy);
captor.setGenStrategy(strategy);
});
comboBox.setPrefWidth(150);
hbox.getChildren().add(comboBox);
// For the time
Text text2 = new Text();
text2.setText("TEMPS :");
text2.setStyle("-fx-font-weight: bold; -fx-fill: white;");
hbox.getChildren().add(text2);
Spinner<Double> spinner = new Spinner<Double>();
spinner.setEditable(false);
spinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(1, 100, captor.getTime(), 1));
spinner.valueProperty().addListener((observable, oldValue, newValue) -> {
captor.setTime(newValue.doubleValue());
captor.stop();
captor.start();
});
hbox.getChildren().add(spinner);
return hbox;
}
}

@ -1,17 +1,22 @@
package view;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import model.Captor;
import model.Observer;
public class CaptorMonitorWindow extends FXMLWindow implements Observer {
@FXML
protected Label labelTemp;
@FXML
protected Label nom;
private Captor captor;
public CaptorMonitorWindow(String title, String pathFxmlRessource, Captor captor) {
super(title, pathFxmlRessource);
this.captor = captor;
this.captor.add(this);
this.captor.attach(this);
}
public Captor getCaptor() {
@ -25,7 +30,6 @@ public class CaptorMonitorWindow extends FXMLWindow implements Observer {
@Override
public void update() {
}
}

@ -5,9 +5,11 @@ import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import model.Captor;
import model.CaptorStationStub;
import model.VisitorCaptor;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import model.*;
import java.util.concurrent.atomic.AtomicReference;
public class CaptorWindow {
@ -19,6 +21,10 @@ public class CaptorWindow {
private TextField nom;
@FXML
private BorderPane master;
@FXML
private Button buttonChange;
@FXML
private VBox vBoxMaster;
private CaptorStationStub captors = new CaptorStationStub();
public CaptorWindow() throws Exception {
@ -26,30 +32,48 @@ public class CaptorWindow {
@FXML
private void initialize() throws Exception {
TreeItem<Captor> root = new TreeItem<>();
root.setExpanded(true);
VisitorCaptor visitorCaptor = new VisitorCaptor();
for (Captor captor : captors.getGroupe()) {
root.getChildren().add(captor.accept(visitorCaptor));
//root.getChildren().add(toTreeItem(captor));
}
lvCaptors.setRoot(root);
lvCaptors.setShowRoot(false);
genTreeView();
master.setVisible(false);
AtomicReference<HBox> hbox = new AtomicReference<>(new HBox());
VisitorCaptor visitorCaptor = new VisitorCaptor();
lvCaptors.getSelectionModel().selectedItemProperty().addListener((obs, oldV, newV) -> {
if (oldV != null) {
id.textProperty().unbind();
nom.textProperty().unbindBidirectional(oldV.getValue().getName());
master.setVisible(false);
vBoxMaster.getChildren().remove(hbox.get());
}
if (newV != null) {
id.setText(newV.getValue().getId().toString());
nom.textProperty().bindBidirectional(newV.getValue().getName());
master.setVisible(true);
try {
hbox.set(newV.getValue().details(visitorCaptor));
} catch (Exception e) {
throw new RuntimeException(e);
}
vBoxMaster.getChildren().add(hbox.get());
}
});
nom.textProperty().addListener((observable, oldValue, newValue) -> {
// This code will be executed whenever the text in the text field changes
lvCaptors.refresh();
});
}
public void genTreeView() throws Exception {
TreeItem<Captor> root = new TreeItem<>();
root.setExpanded(true);
VisitorCaptor visitorCaptor = new VisitorCaptor();
for (Captor captor : captors.getGroupe()) {
root.getChildren().add(captor.accept(visitorCaptor));
//root.getChildren().add(toTreeItem(captor));
}
lvCaptors.setRoot(root);
lvCaptors.setShowRoot(false);
}
/*
@ -65,20 +89,35 @@ public class CaptorWindow {
}*/
public void openWindowImage(ActionEvent actionEvent) {
Captor selectedCaptor = lvCaptors.getSelectionModel().getSelectedItem().getValue();
ImageWindow imageWindow = new ImageWindow(selectedCaptor);
imageWindow.setResizable(false);
imageWindow.show();
openWindow(new ImageWindow(lvCaptors.getSelectionModel().getSelectedItem().getValue()));
}
public void openWindowThermosta(ActionEvent actionEvent) {
Captor selectedCaptor = lvCaptors.getSelectionModel().getSelectedItem().getValue();
ThermostatWindow thermostaWindow = new ThermostatWindow(selectedCaptor);
thermostaWindow.setResizable(false);
thermostaWindow.show();
public void openWindowThermostat(ActionEvent actionEvent) {
openWindow(new ThermostatWindow(lvCaptors.getSelectionModel().getSelectedItem().getValue()));
}
public void openWindow(CaptorMonitorWindow type) {
type.setResizable(false);
type.show();
}
public void buttonExit(ActionEvent actionEvent) {
Platform.exit();
}
public void buttonAdd(ActionEvent actionEvent) throws Exception {
captors.getGroupe().add(new CaptorBasic("New", new GenBoundedRandom(-30, 40)));
genTreeView();
}
public void changeCaptor(ActionEvent actionEvent) {
Captor selectedCaptor = lvCaptors.getSelectionModel().getSelectedItem().getValue();
if (buttonChange.getText().equals("Start")) {
buttonChange.setText("Stop");
selectedCaptor.start();
} else {
buttonChange.setText("Start");
selectedCaptor.stop();
}
}
}

@ -15,19 +15,14 @@ public class ImageWindow extends CaptorMonitorWindow {
@FXML
private ImageView image;
@FXML
private Label nom;
@FXML
private Label labelTemp;
private static NavigableMap<Double, String> Images = new TreeMap<>();
private static NavigableMap<Double, Image> Images = new TreeMap<>();
public ImageWindow(Captor captor) {
super("Image", "/fxml/ImageWindow.fxml", captor);
Images.put(25.0, "soleil");
Images.put(0.0, "nuage");
Images.put(25.0, new Image("/images/soleil.jpg"));
Images.put(0.0, new Image("/images/nuage.jpg"));
Images.put(-Double.MAX_VALUE, new Image("/images/neige.jpg"));
nom.textProperty().bind(this.getCaptor().getName());
Images.put(-Double.MAX_VALUE, "neige");
update();
}
@ -38,11 +33,11 @@ public class ImageWindow extends CaptorMonitorWindow {
}
public void update() {
Map.Entry<Double, String> entry = Images.floorEntry(this.getCaptor().getValue());
Map.Entry<Double, Image> entry = Images.floorEntry(this.getCaptor().getValue().doubleValue());
if (entry != null && entry.getValue() != null) {
image.setImage(new Image("/images/" + entry.getValue() + ".jpg"));
image.setImage(entry.getValue());
}
labelTemp.setText(String.format("%.2f°C", this.getCaptor().getValue()));
labelTemp.setText(String.format("%.2f°C", this.getCaptor().getValue().doubleValue()));
}
}

@ -1,31 +1,34 @@
package view;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.image.Image;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import model.Captor;
public class ThermostatWindow extends CaptorMonitorWindow {
import java.util.Map;
@FXML
private Text valTemperature;
public class ThermostatWindow extends CaptorMonitorWindow {
@FXML
private Slider slider;
public ThermostatWindow(Captor captor) {
super("Thermosta", "/fxml/ThermostatWindow.fxml", captor);
super("Thermostat", "/fxml/ThermostatWindow.fxml", captor);
nom.textProperty().bind(this.getCaptor().getName());
update();
}
public void initialize() {
//slider.valueProperty().bindBidirectional(getCaptor().getValue());
//valTemperature.textProperty().bind(getCaptor().getValue().asString());
public void update() {
slider.valueProperty().bindBidirectional(getCaptor().getValue());
labelTemp.setText(String.format("%.2f°C", this.getCaptor().getValue().doubleValue()));
}
@FXML
public void onChange() {
getCaptor().setValue(slider.getValue());
}
@FXML

Loading…
Cancel
Save