Ajout de capteur + Gestion et implémentation des différent type de capteur (Abstrait, Zone, Normal)master
parent
81cb9ac1dd
commit
439e8c54bb
@ -1,20 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="132.0" prefWidth="131.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.MainWindow">
|
||||
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="373.0" prefWidth="277.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.MainWindow">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="132.4" minHeight="10.0" prefHeight="89.4" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="128.4" minHeight="0.0" prefHeight="98.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="266.80000000000007" minHeight="10.0" prefHeight="93.19999999999999" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="256.0" minHeight="10.0" prefHeight="213.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="145.99999237060547" minHeight="0.0" prefHeight="43.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Button fx:id="btnImage" mnemonicParsing="false" onAction="#clickButtonImage" text="Image" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
|
||||
<Button fx:id="btnFermer" mnemonicParsing="false" onAction="#clickButtonFermer" text="Fermer" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="CENTER" />
|
||||
<Button fx:id="btnSpinner" mnemonicParsing="false" onAction="#clickButtonSpinner" text="Spinner" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" />
|
||||
<Button fx:id="btnFermer" mnemonicParsing="false" onAction="#clickButtonFermer" text="Fermer" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="BOTTOM">
|
||||
<GridPane.margin>
|
||||
<Insets bottom="10.0" />
|
||||
</GridPane.margin></Button>
|
||||
<ListView fx:id="listView" prefHeight="200.0" prefWidth="200.0" />
|
||||
<Button fx:id="btnAjouter" mnemonicParsing="false" onAction="#clickButtonAjouter" text="Ajouter" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="TOP">
|
||||
<GridPane.margin>
|
||||
<Insets top="10.0" />
|
||||
</GridPane.margin>
|
||||
</Button>
|
||||
<Button fx:id="btnAjouterZone" mnemonicParsing="false" onAction="#clickButtonAjouterZone" text="Ajouter CapteurZone" GridPane.halignment="CENTER" GridPane.rowIndex="1" />
|
||||
<!-- <Button fx:id="btnVoir" mnemonicParsing="false" onAction="#clickButtonVoir" disable="true" text="Voir" GridPane.rowIndex="1" />-->
|
||||
<!-- <Button fx:id="btnSupprimer" mnemonicParsing="false" onAction="#clickButtonVoir" text="Supprimer" GridPane.halignment="RIGHT" GridPane.rowIndex="1" />-->
|
||||
</children>
|
||||
</GridPane>
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,98 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<fx:root fx:id="DetailWindow" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="261.0" prefWidth="238.0" type="GridPane" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="50.0" minHeight="10.0" prefHeight="22.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="50.0" minHeight="10.0" prefHeight="27.2" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="50.0" minHeight="10.0" prefHeight="35.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="49.4" minHeight="30.0" prefHeight="49.4" />
|
||||
<RowConstraints maxHeight="49.4" minHeight="30.0" prefHeight="49.4" />
|
||||
<RowConstraints maxHeight="49.4" minHeight="30.0" prefHeight="49.4" />
|
||||
<RowConstraints maxHeight="49.4" minHeight="30.0" prefHeight="49.4" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Button fx:id="btnFermer" mnemonicParsing="false" onAction="#clickButtonFermer" text="Fermer" GridPane.halignment="CENTER" GridPane.rowIndex="6" GridPane.valignment="CENTER">
|
||||
<GridPane.margin>
|
||||
<Insets right="12.0" />
|
||||
</GridPane.margin>
|
||||
</Button>
|
||||
<Label text="Nom :" GridPane.halignment="CENTER" GridPane.rowIndex="1">
|
||||
<GridPane.margin>
|
||||
<Insets right="40.0" />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<Label fx:id="nom" prefHeight="18.0" prefWidth="119.0" text="Label" GridPane.halignment="RIGHT" GridPane.rowIndex="1">
|
||||
<GridPane.margin>
|
||||
<Insets left="35" />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<TextField fx:id="textFieldNom" prefHeight="18.0" prefWidth="119.0" visible="false" text="Label" GridPane.halignment="RIGHT" GridPane.rowIndex="1">
|
||||
<GridPane.margin>
|
||||
<Insets left="115.0" />
|
||||
</GridPane.margin>
|
||||
</TextField>
|
||||
<Label prefHeight="18.0" prefWidth="23.0" text="Id :" GridPane.halignment="CENTER">
|
||||
<GridPane.margin>
|
||||
<Insets right="20.0" />
|
||||
</GridPane.margin></Label>
|
||||
<Label fx:id="id" prefHeight="18.0" prefWidth="36.0" text="Label" GridPane.halignment="CENTER">
|
||||
<GridPane.margin>
|
||||
<Insets left="35" />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<Label text="Temperature :" GridPane.halignment="CENTER" GridPane.rowIndex="2">
|
||||
<GridPane.margin>
|
||||
<Insets right="80.0" />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<Label fx:id="temperature" text="Label" GridPane.halignment="CENTER" GridPane.rowIndex="2">
|
||||
<GridPane.margin>
|
||||
<Insets left="35.0" />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<Label text="°C" GridPane.halignment="CENTER" GridPane.rowIndex="2">
|
||||
<GridPane.margin>
|
||||
<Insets left="85.0" />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<Label text="Stratégie :" GridPane.halignment="CENTER" GridPane.rowIndex="3">
|
||||
<GridPane.margin>
|
||||
<Insets right="65.0" />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<Label fx:id="strategy" prefHeight="18.0" prefWidth="117.0" text="Label" GridPane.halignment="RIGHT" GridPane.rowIndex="3">
|
||||
<GridPane.margin>
|
||||
<Insets left="40.0" />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<MenuButton fx:id="menuStrategy" visible="false" prefHeight="18.0" prefWidth="117.0" text="Label" GridPane.halignment="RIGHT" GridPane.rowIndex="3">
|
||||
<items>
|
||||
<MenuItem fx:id="menuStrategyRandom" onAction="#clickMenuStrategyRandom" mnemonicParsing="false" text="GenerateurAleatoire" />
|
||||
<MenuItem fx:id="menuStrategyReal" onAction="#clickMenuStrategyReal" mnemonicParsing="false" text="GenerateurRealiste" />
|
||||
<MenuItem fx:id="menuStrategyMan" onAction="#clickMenuStrategyMan" mnemonicParsing="false" text="GenerateurManuel" />
|
||||
</items>
|
||||
</MenuButton>
|
||||
<Button fx:id="btnSpinner" mnemonicParsing="false" onAction="#clickButtonSpinner" text="Spinner" GridPane.halignment="CENTER" GridPane.rowIndex="5">
|
||||
<GridPane.margin>
|
||||
<Insets left="55.0" />
|
||||
</GridPane.margin>
|
||||
</Button>
|
||||
<Button fx:id="btnImage" mnemonicParsing="false" onAction="#clickButtonImage" text="Image" GridPane.halignment="CENTER" GridPane.rowIndex="5">
|
||||
<GridPane.margin>
|
||||
<Insets right="72.0" />
|
||||
</GridPane.margin>
|
||||
</Button>
|
||||
<Button fx:id="btnModifier" mnemonicParsing="false" onAction="#clickButtonModifier" text="Modifier" GridPane.halignment="CENTER" GridPane.rowIndex="4">
|
||||
<GridPane.margin>
|
||||
<Insets right="12.0" />
|
||||
</GridPane.margin>
|
||||
</Button>
|
||||
</children>
|
||||
</fx:root>
|
@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<fx:root fx:id="DetailZoneWindow" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="352.0" prefWidth="251.0" type="GridPane" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="59.4" minHeight="10.0" prefHeight="23.8" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="183.2" minHeight="0.0" prefHeight="25.799999999999997" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="223.4" minHeight="10.0" prefHeight="27.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="214.2" minHeight="10.0" prefHeight="30.39999618530274" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="214.2" minHeight="10.0" prefHeight="134.4" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="214.2" minHeight="8.600000000000023" prefHeight="35.599999999999994" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="214.2" minHeight="10.0" prefHeight="31.80000000000001" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="214.2" minHeight="10.0" prefHeight="34.60000000000002" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Button fx:id="btnFermer" mnemonicParsing="false" onAction="#clickButtonFermer" text="Fermer" GridPane.halignment="CENTER" GridPane.rowIndex="7" />
|
||||
<ListView fx:id="listView" prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="4" />
|
||||
<Label prefHeight="18.0" prefWidth="118.0" text="Nombre de capteurs :" GridPane.halignment="LEFT" GridPane.rowIndex="2">
|
||||
<GridPane.margin>
|
||||
<Insets left="5.0" />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<Button fx:id="btnImage" mnemonicParsing="false" onAction="#clickButtonImage" text="Image" GridPane.halignment="CENTER" GridPane.rowIndex="6">
|
||||
<GridPane.margin>
|
||||
<Insets />
|
||||
</GridPane.margin>
|
||||
</Button>
|
||||
<Button fx:id="btnAjouter" mnemonicParsing="false" onAction="#clickButtonAjouter" text="Ajouter" GridPane.halignment="CENTER" GridPane.rowIndex="5">
|
||||
<GridPane.margin>
|
||||
<Insets />
|
||||
</GridPane.margin>
|
||||
</Button>
|
||||
<Label text="Temperature :" GridPane.halignment="CENTER" GridPane.rowIndex="3">
|
||||
<GridPane.margin>
|
||||
<Insets right="80.0" />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<Label fx:id="temperature" prefHeight="18.0" prefWidth="34.0" text="Label" GridPane.halignment="CENTER" GridPane.rowIndex="3">
|
||||
<GridPane.margin>
|
||||
<Insets left="35.0" />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<Label text="°C" GridPane.halignment="CENTER" GridPane.rowIndex="3">
|
||||
<GridPane.margin>
|
||||
<Insets left="85.0" />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<Label fx:id="nbCapteurs" prefHeight="18.0" prefWidth="53.0" text="Label" GridPane.halignment="CENTER" GridPane.rowIndex="2">
|
||||
<GridPane.margin>
|
||||
<Insets left="50.0" />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<Label text="Nom :" GridPane.halignment="CENTER" GridPane.rowIndex="1">
|
||||
<GridPane.margin>
|
||||
<Insets right="40.0" />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<Label fx:id="nom" prefHeight="18.0" prefWidth="127.0" text="Label" GridPane.halignment="RIGHT" GridPane.rowIndex="1">
|
||||
<GridPane.margin>
|
||||
<Insets left="35" />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<Label prefHeight="18.0" prefWidth="23.0" text="Id :" GridPane.halignment="CENTER">
|
||||
<GridPane.margin>
|
||||
<Insets right="20.0" />
|
||||
</GridPane.margin></Label>
|
||||
<Label fx:id="id" prefHeight="18.0" prefWidth="36.0" text="Label" GridPane.halignment="CENTER">
|
||||
<GridPane.margin>
|
||||
<Insets left="35" />
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
</children>
|
||||
</fx:root>
|
@ -1,20 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="132.0" prefWidth="131.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.MainWindow">
|
||||
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="373.0" prefWidth="277.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.MainWindow">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="132.4" minHeight="10.0" prefHeight="89.4" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="128.4" minHeight="0.0" prefHeight="98.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="266.80000000000007" minHeight="10.0" prefHeight="93.19999999999999" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="256.0" minHeight="10.0" prefHeight="213.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="145.99999237060547" minHeight="0.0" prefHeight="43.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Button fx:id="btnImage" mnemonicParsing="false" onAction="#clickButtonImage" text="Image" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
|
||||
<Button fx:id="btnFermer" mnemonicParsing="false" onAction="#clickButtonFermer" text="Fermer" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="CENTER" />
|
||||
<Button fx:id="btnSpinner" mnemonicParsing="false" onAction="#clickButtonSpinner" text="Spinner" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" />
|
||||
<Button fx:id="btnFermer" mnemonicParsing="false" onAction="#clickButtonFermer" text="Fermer" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="BOTTOM">
|
||||
<GridPane.margin>
|
||||
<Insets bottom="10.0" />
|
||||
</GridPane.margin></Button>
|
||||
<ListView fx:id="listView" prefHeight="200.0" prefWidth="200.0" />
|
||||
<Button fx:id="btnAjouter" mnemonicParsing="false" onAction="#clickButtonAjouter" text="Ajouter" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="TOP">
|
||||
<GridPane.margin>
|
||||
<Insets top="10.0" />
|
||||
</GridPane.margin>
|
||||
</Button>
|
||||
<Button fx:id="btnAjouterZone" mnemonicParsing="false" onAction="#clickButtonAjouterZone" text="Ajouter CapteurZone" GridPane.halignment="CENTER" GridPane.rowIndex="1" />
|
||||
<!-- <Button fx:id="btnVoir" mnemonicParsing="false" onAction="#clickButtonVoir" disable="true" text="Voir" GridPane.rowIndex="1" />-->
|
||||
<!-- <Button fx:id="btnSupprimer" mnemonicParsing="false" onAction="#clickButtonVoir" text="Supprimer" GridPane.halignment="RIGHT" GridPane.rowIndex="1" />-->
|
||||
</children>
|
||||
</GridPane>
|
||||
|
@ -0,0 +1,38 @@
|
||||
package model;
|
||||
|
||||
import javafx.beans.property.DoubleProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class CapteurAbstrait extends Observable {
|
||||
protected static int idActuel;
|
||||
protected int id;
|
||||
protected StringProperty nom;
|
||||
protected DoubleProperty temperature;
|
||||
|
||||
public CapteurAbstrait(String nom) {
|
||||
this.id = idActuel;
|
||||
idActuel += 1;
|
||||
this.nom = new SimpleStringProperty(nom);
|
||||
this.lesObservateurs = new ArrayList<>();
|
||||
}
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public StringProperty getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public void setNom(String nom) {
|
||||
this.nom = new SimpleStringProperty(nom);
|
||||
this.notifier();
|
||||
}
|
||||
public abstract DoubleProperty getTemperature();
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package model;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.DoubleProperty;
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.SimpleDoubleProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CapteurZone extends CapteurAbstrait implements Runnable{
|
||||
private Thread thread;
|
||||
private ArrayList<Capteur> lesCapteurs;
|
||||
|
||||
public CapteurZone(String nom, ArrayList<Capteur> lesCapteurs) {
|
||||
super(nom);
|
||||
this.temperature = new SimpleDoubleProperty(0);
|
||||
this.lesCapteurs = lesCapteurs;
|
||||
thread = new Thread(this);
|
||||
thread.setDaemon(true);
|
||||
thread.start();
|
||||
calculTemperature();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(){
|
||||
while (true) {
|
||||
Platform.runLater(() -> calculTemperature());
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleProperty getTemperature() {
|
||||
return this.temperature;
|
||||
}
|
||||
private void calculTemperature(){
|
||||
double temperature = 0;
|
||||
for (Capteur capteur : lesCapteurs){
|
||||
temperature += capteur.getTemperature().get();
|
||||
}
|
||||
this.temperature.set(temperature/lesCapteurs.size());
|
||||
}
|
||||
// private void genereTemperature(){
|
||||
// for (Capteur capteur : lesCapteurs){
|
||||
// capteur.setTemperature(capteur.getStrategy().genereTemperature());
|
||||
// }
|
||||
// calculTemperature();
|
||||
// this.notifier();
|
||||
// }
|
||||
public void addCapteur(Capteur capteur){
|
||||
lesCapteurs.add(capteur);
|
||||
calculTemperature();
|
||||
}
|
||||
public void removeCapteur(Capteur capteur){
|
||||
lesCapteurs.remove(capteur);
|
||||
calculTemperature();
|
||||
}
|
||||
public ArrayList<Capteur> getLesCapteurs() {
|
||||
return lesCapteurs;
|
||||
}
|
||||
public void setLesCapteurs(ArrayList<Capteur> lesCapteurs) {
|
||||
this.lesCapteurs = lesCapteurs;
|
||||
calculTemperature();
|
||||
}
|
||||
public IntegerProperty getNbCapteurs(){
|
||||
return new SimpleIntegerProperty(lesCapteurs.size());
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package model;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class GenerateurManuel implements GenerateurStrategy{
|
||||
@Override
|
||||
public double genereTemperature() {
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package model;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class GenerateurRealiste implements GenerateurStrategy{
|
||||
private double bornInf;
|
||||
private double bornSup;
|
||||
private double temperature;
|
||||
|
||||
public GenerateurRealiste() {
|
||||
Random random = new Random();
|
||||
this.bornInf = -20;
|
||||
this.bornSup = 40;
|
||||
this.temperature = bornInf+random.nextDouble(bornSup-bornInf);
|
||||
}
|
||||
|
||||
public double getBornInf() {
|
||||
return bornInf;
|
||||
}
|
||||
|
||||
public void setBornInf(double bornInf) {
|
||||
this.bornInf = bornInf;
|
||||
}
|
||||
|
||||
public double getBornSup() {
|
||||
return bornSup;
|
||||
}
|
||||
|
||||
public void setBornSup(double bornSup) {
|
||||
this.bornSup = bornSup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double genereTemperature() {
|
||||
Random random = new Random();
|
||||
double inf, sup;
|
||||
inf = -2;
|
||||
sup = 2;
|
||||
this.temperature += inf+random.nextDouble(sup-inf);
|
||||
return this.temperature;
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package model;
|
||||
|
||||
public class Thread {
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
package view;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.converter.NumberStringConverter;
|
||||
import model.Capteur;
|
||||
import model.GenerateurAleatoire;
|
||||
import model.GenerateurManuel;
|
||||
import model.GenerateurRealiste;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class DetailWindow extends Visualisateur{
|
||||
@FXML
|
||||
private Label nom;
|
||||
@FXML
|
||||
private Label id;
|
||||
@FXML
|
||||
private Label temperature;
|
||||
@FXML
|
||||
private Label strategy;
|
||||
@FXML
|
||||
private Button btnSpinner;
|
||||
@FXML
|
||||
private Button btnImage;
|
||||
@FXML
|
||||
private Button btnModifier;
|
||||
@FXML
|
||||
private TextField textFieldNom;
|
||||
@FXML
|
||||
private MenuButton menuStrategy;
|
||||
@FXML
|
||||
private MenuItem menuStrategyRandom;
|
||||
protected Capteur capteur;
|
||||
private GridPane layout;
|
||||
|
||||
public DetailWindow(Capteur capteur) throws IOException {
|
||||
this.capteur = capteur;
|
||||
Stage stage = new Stage();
|
||||
layout = new GridPane();
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/DetailWindow.fxml"));
|
||||
loader.setRoot(this.layout);
|
||||
loader.setController(this);
|
||||
Parent root = loader.load();
|
||||
Scene scene = new Scene(root);
|
||||
stage.setScene(scene);
|
||||
stage.setTitle(this.capteur.getNom().toString());
|
||||
stage.show();
|
||||
}
|
||||
@FXML
|
||||
public void initialize(){
|
||||
id.setText(new NumberStringConverter().toString(capteur.getId()));
|
||||
nom.textProperty().bindBidirectional(this.capteur.getNom());
|
||||
String strategyName = this.capteur.getStrategy().getClass().getSimpleName();
|
||||
strategy.setText(strategyName);
|
||||
if (! strategyName.equals("GenerateurManuel")){
|
||||
btnSpinner.setDisable(true);
|
||||
}
|
||||
temperature.textProperty().bindBidirectional(this.capteur.getTemperature() , new NumberStringConverter());
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void clickButtonImage() throws Exception{
|
||||
ImageWindow Iw = new ImageWindow(this.capteur);
|
||||
}
|
||||
@FXML
|
||||
private void clickButtonSpinner() throws Exception{
|
||||
SpinnerWindow Sw = new SpinnerWindow(this.capteur);
|
||||
}
|
||||
@FXML
|
||||
private void clickButtonModifier() throws Exception{
|
||||
if (nom.isVisible() && strategy.isVisible()) {
|
||||
textFieldNom.setText(nom.getText());
|
||||
textFieldNom.setVisible(true);
|
||||
nom.setVisible(false);
|
||||
menuStrategy.setText(strategy.getText());
|
||||
menuStrategy.setVisible(true);
|
||||
} else {
|
||||
nom.setText(textFieldNom.getText());
|
||||
String strategyName = menuStrategy.getText();
|
||||
if (strategyName.equals("GenerateurAleatoire")){
|
||||
this.capteur.setStrategy(new GenerateurAleatoire(-20,40));
|
||||
strategy.setText("GenerateurAleatoire");
|
||||
} else if (strategyName.equals("GenerateurRealiste")){
|
||||
this.capteur.setStrategy(new GenerateurRealiste());
|
||||
strategy.setText("GenerateurRealiste");
|
||||
}
|
||||
else if (strategyName.equals("GenerateurManuel")){
|
||||
this.capteur.setStrategy(new GenerateurManuel());
|
||||
strategy.setText("GenerateurManuel");
|
||||
btnSpinner.setDisable(false);
|
||||
}
|
||||
textFieldNom.setVisible(false);
|
||||
menuStrategy.setVisible(false);
|
||||
nom.setVisible(true);
|
||||
}
|
||||
}
|
||||
@FXML
|
||||
private void clickMenuStrategyRandom() throws Exception{
|
||||
menuStrategy.setText("GenerateurAleatoire");
|
||||
}
|
||||
@FXML
|
||||
private void clickMenuStrategyReal() throws Exception{
|
||||
menuStrategy.setText("GenerateurRealiste");
|
||||
}
|
||||
@FXML
|
||||
private void clickMenuStrategyMan() throws Exception{
|
||||
menuStrategy.setText("GenerateurManuel");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
temperature.textProperty().bindBidirectional(this.capteur.getTemperature() , new NumberStringConverter());
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
package view;
|
||||
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.Callback;
|
||||
import javafx.util.converter.NumberStringConverter;
|
||||
import model.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class DetailZoneWindow extends Visualisateur{
|
||||
private CapteurZone capteurZone;
|
||||
private ObservableList<CapteurAbstrait> lesCapteurs;
|
||||
private GridPane layout;
|
||||
@FXML
|
||||
private Label nom;
|
||||
@FXML
|
||||
private Label id;
|
||||
@FXML
|
||||
private Label nbCapteurs;
|
||||
@FXML
|
||||
private Label temperature;
|
||||
@FXML
|
||||
private Button btnImage;
|
||||
@FXML
|
||||
private Button btnAjouter;
|
||||
@FXML
|
||||
private ListView<CapteurAbstrait> listView;
|
||||
|
||||
public DetailZoneWindow(CapteurZone capteurZone) throws IOException {
|
||||
this.capteurZone = capteurZone;
|
||||
Stage stage = new Stage();
|
||||
layout = new GridPane();
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/DetailZoneWindow.fxml"));
|
||||
loader.setRoot(this.layout);
|
||||
loader.setController(this);
|
||||
Parent root = loader.load();
|
||||
Scene scene = new Scene(root);
|
||||
stage.setScene(scene);
|
||||
stage.setTitle("this.capteur.getNom().toString()");
|
||||
stage.show();
|
||||
}
|
||||
@FXML
|
||||
public void initialize(){
|
||||
id.setText(new NumberStringConverter().toString(capteurZone.getId()));
|
||||
nom.textProperty().bindBidirectional(this.capteurZone.getNom());
|
||||
nbCapteurs.textProperty().bindBidirectional(this.capteurZone.getNbCapteurs(), new NumberStringConverter());
|
||||
temperature.textProperty().bindBidirectional(this.capteurZone.getTemperature() , new NumberStringConverter());
|
||||
|
||||
lesCapteurs = listView.getItems();
|
||||
|
||||
listView.setCellFactory(new Callback<ListView<CapteurAbstrait>, ListCell<CapteurAbstrait>>() {
|
||||
@Override
|
||||
public ListCell<CapteurAbstrait> call(ListView<CapteurAbstrait> capteurListView) {
|
||||
return new ListCell<CapteurAbstrait>(){
|
||||
@Override
|
||||
public void updateItem(CapteurAbstrait value, boolean empty) {
|
||||
super.updateItem(value, empty);
|
||||
if (value != null) {
|
||||
textProperty().bind(new SimpleStringProperty(this, "", "")
|
||||
.concat("[")
|
||||
.concat(value.getId())
|
||||
.concat("] ")
|
||||
.concat(value.getNom())
|
||||
.concat(" : ")
|
||||
.concat(value.getTemperature().asString("%.2f°C")));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
listView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
|
||||
try {
|
||||
if (lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()).getClass().getSimpleName().equals("CapteurZone")) {
|
||||
DetailZoneWindow Dzw = new DetailZoneWindow((CapteurZone) lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()));
|
||||
}
|
||||
else{
|
||||
DetailWindow Dw = new DetailWindow((Capteur) lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
lesCapteurs.addAll(capteurZone.getLesCapteurs());
|
||||
}
|
||||
@FXML
|
||||
private void clickButtonImage() throws Exception{
|
||||
ImageWindow Iw = new ImageWindow(this.capteurZone);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void clickButtonAjouter() throws Exception{
|
||||
Capteur c = new Capteur("Nouveau Capteur Réaliste", new GenerateurRealiste());
|
||||
this.capteurZone.addCapteur(c);
|
||||
lesCapteurs.add(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
}
|
||||
}
|
@ -1,39 +1,118 @@
|
||||
package view;
|
||||
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.stage.Stage;
|
||||
import model.Capteur;
|
||||
import model.GenerateurAleatoire;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.util.Callback;
|
||||
import model.*;
|
||||
|
||||
public class MainWindow {
|
||||
import java.io.IOException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MainWindow extends Visualisateur{
|
||||
@FXML
|
||||
private ListView<CapteurAbstrait> listView;
|
||||
@FXML
|
||||
private Button btnAjouter;
|
||||
@FXML
|
||||
private Button btnSpinner;
|
||||
private Button btnAjouterZone;
|
||||
@FXML
|
||||
private Button btnImage;
|
||||
private Button btnVoir;
|
||||
@FXML
|
||||
private Button btnFermer;
|
||||
protected Capteur capteur;
|
||||
private Button btnSupprimer;
|
||||
private ObservableList<CapteurAbstrait> lesCapteurs;
|
||||
private final DecimalFormat df = new DecimalFormat("#.##");
|
||||
|
||||
public void initialize(){
|
||||
this.capteur = new Capteur("a", new GenerateurAleatoire(0,12));
|
||||
}
|
||||
@FXML
|
||||
private void clickButtonFermer(){
|
||||
Stage stage = (Stage) btnFermer.getScene().getWindow();
|
||||
stage.close();
|
||||
public void initialize(){
|
||||
lesCapteurs = listView.getItems();
|
||||
|
||||
listView.setCellFactory(new Callback<ListView<CapteurAbstrait>, ListCell<CapteurAbstrait>>() {
|
||||
@Override
|
||||
public ListCell<CapteurAbstrait> call(ListView<CapteurAbstrait> capteurListView) {
|
||||
return new ListCell<CapteurAbstrait>(){
|
||||
@Override
|
||||
public void updateItem(CapteurAbstrait value, boolean empty) {
|
||||
super.updateItem(value, empty);
|
||||
if (value != null) {
|
||||
textProperty().bind(new SimpleStringProperty(this, "", "")
|
||||
.concat("[")
|
||||
.concat(value.getId())
|
||||
.concat("] ")
|
||||
.concat(value.getNom())
|
||||
.concat(" : ")
|
||||
.concat(value.getTemperature().asString("%.2f°C")));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
listView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
|
||||
// btnVoir.setDisable(false);
|
||||
// btnSupprimer.setDisable(false);
|
||||
try {
|
||||
if (lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()).getClass().getSimpleName().equals("CapteurZone")) {
|
||||
DetailZoneWindow Dzw = new DetailZoneWindow((CapteurZone) lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()));
|
||||
}
|
||||
else{
|
||||
DetailWindow Dw = new DetailWindow((Capteur) lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
Capteur capteur1 = new Capteur("Capteur Réaliste", new GenerateurRealiste());
|
||||
Capteur capteur2 = new Capteur("Capteur Aléatoire", new GenerateurAleatoire(-20, 40));
|
||||
Capteur capteur3 = new Capteur("Capteur Manuel", new GenerateurManuel());
|
||||
lesCapteurs.add(capteur1);
|
||||
lesCapteurs.add(capteur2);
|
||||
lesCapteurs.add(capteur3);
|
||||
|
||||
Capteur capteur4 = new Capteur("Capteur4", new GenerateurRealiste());
|
||||
Capteur capteur5 = new Capteur("Capteur5", new GenerateurRealiste());
|
||||
CapteurZone capteurZone = new CapteurZone("Capteur Zone", new ArrayList<Capteur>(){{add(capteur4); add(capteur5);}});
|
||||
lesCapteurs.add(capteurZone);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void clickButtonImage() throws Exception{
|
||||
ImageWindow Iw = new ImageWindow(this.capteur);
|
||||
private void clickButtonAjouter() throws Exception{
|
||||
Capteur c = new Capteur("Nouveau Capteur Réaliste", new GenerateurRealiste());
|
||||
lesCapteurs.add(c);
|
||||
}
|
||||
@FXML
|
||||
private void clickButtonSpinner() throws Exception{
|
||||
SpinnerWindow Sw = new SpinnerWindow(this.capteur);
|
||||
private void clickButtonAjouterZone() throws Exception{
|
||||
CapteurZone c = new CapteurZone("Nouveau Capteur Zone", new ArrayList<Capteur>());
|
||||
lesCapteurs.add(c);
|
||||
}
|
||||
// @FXML
|
||||
// private void clickButtonSupprimer() throws Exception{
|
||||
// CapteurAbstrait c = lesCapteurs.get(listView.getSelectionModel().getSelectedIndex());
|
||||
// lesCapteurs.remove(c);
|
||||
// listView.getItems().remove(c);
|
||||
// listView.refresh();
|
||||
// }
|
||||
// @FXML
|
||||
// private void clickButtonVoir() throws Exception{
|
||||
// try {
|
||||
// if (lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()).getClass().getSimpleName().equals("CapteurZone")) {
|
||||
// DetailZoneWindow Dzw = new DetailZoneWindow((CapteurZone) lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()));
|
||||
// }
|
||||
// else{
|
||||
// DetailWindow Dw = new DetailWindow((Capteur) lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()));
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
@Override
|
||||
public void update() {
|
||||
listView.refresh();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue