commit
7baf43376f
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
@ -0,0 +1,13 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="lib">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="file://$JFX_PATH$" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<NATIVE>
|
||||||
|
<root url="file://$JFX_PATH$" />
|
||||||
|
</NATIVE>
|
||||||
|
<SOURCES />
|
||||||
|
<jarDirectory url="file://$JFX_PATH$" recursive="false" />
|
||||||
|
</library>
|
||||||
|
</component>
|
@ -0,0 +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">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/tp2.iml" filepath="$PROJECT_DIR$/tp2.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,124 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Palette2">
|
||||||
|
<group name="Swing">
|
||||||
|
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Button" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="RadioButton" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="CheckBox" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Label" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||||
|
<preferred-size width="-1" height="20" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
</group>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import java.lang.*?>
|
||||||
|
<?import java.util.*?>
|
||||||
|
<?import javafx.scene.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<AnchorPane xmlns="http://javafx.com/javafx"
|
||||||
|
xmlns:fx="http://javafx.com/fxml">
|
||||||
|
|
||||||
|
<BorderPane>
|
||||||
|
<top>
|
||||||
|
<TextArea fx:id="nomCapteur"/>
|
||||||
|
</top>
|
||||||
|
|
||||||
|
<center>
|
||||||
|
<Spinner fx:id="spinner"/>
|
||||||
|
</center>
|
||||||
|
</BorderPane>
|
||||||
|
</AnchorPane>
|
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import java.lang.*?>
|
||||||
|
<?import java.util.*?>
|
||||||
|
<?import javafx.scene.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<?import javafx.scene.image.ImageView?>
|
||||||
|
<AnchorPane xmlns="http://javafx.com/javafx"
|
||||||
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
|
prefHeight="400.0" prefWidth="600.0">
|
||||||
|
|
||||||
|
<BorderPane>
|
||||||
|
<center>
|
||||||
|
<ImageView fx:id="imageTemp"/>
|
||||||
|
</center>
|
||||||
|
</BorderPane>
|
||||||
|
</AnchorPane>
|
@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import java.lang.*?>
|
||||||
|
<?import java.util.*?>
|
||||||
|
<?import javafx.scene.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<AnchorPane xmlns="http://javafx.com/javafx"
|
||||||
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
|
prefHeight="400.0" prefWidth="600.0">
|
||||||
|
|
||||||
|
<BorderPane>
|
||||||
|
<left>
|
||||||
|
<ListView fx:id="lesCapteursAVoir"/>
|
||||||
|
</left>
|
||||||
|
</BorderPane>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</AnchorPane>
|
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 90 KiB |
After Width: | Height: | Size: 87 KiB |
@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import java.lang.*?>
|
||||||
|
<?import java.util.*?>
|
||||||
|
<?import javafx.scene.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<AnchorPane xmlns="http://javafx.com/javafx"
|
||||||
|
xmlns:fx="http://javafx.com/fxml">
|
||||||
|
|
||||||
|
<BorderPane>
|
||||||
|
<top>
|
||||||
|
<TextArea fx:id="nomCapteur"/>
|
||||||
|
</top>
|
||||||
|
|
||||||
|
<center>
|
||||||
|
<Spinner fx:id="spinner"/>
|
||||||
|
</center>
|
||||||
|
</BorderPane>
|
||||||
|
</AnchorPane>
|
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import java.lang.*?>
|
||||||
|
<?import java.util.*?>
|
||||||
|
<?import javafx.scene.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<?import javafx.scene.image.ImageView?>
|
||||||
|
<AnchorPane xmlns="http://javafx.com/javafx"
|
||||||
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
|
prefHeight="400.0" prefWidth="600.0">
|
||||||
|
|
||||||
|
<BorderPane>
|
||||||
|
<center>
|
||||||
|
<ImageView fx:id="imageTemp"/>
|
||||||
|
</center>
|
||||||
|
</BorderPane>
|
||||||
|
</AnchorPane>
|
@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import java.lang.*?>
|
||||||
|
<?import java.util.*?>
|
||||||
|
<?import javafx.scene.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<AnchorPane xmlns="http://javafx.com/javafx"
|
||||||
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
|
prefHeight="400.0" prefWidth="600.0">
|
||||||
|
|
||||||
|
<BorderPane>
|
||||||
|
<left>
|
||||||
|
<ListView fx:id="lesCapteursAVoir"/>
|
||||||
|
</left>
|
||||||
|
</BorderPane>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</AnchorPane>
|
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 90 KiB |
After Width: | Height: | Size: 87 KiB |
Binary file not shown.
@ -0,0 +1,55 @@
|
|||||||
|
package Model;
|
||||||
|
|
||||||
|
import javafx.beans.property.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class Capteur extends Observable{
|
||||||
|
private int id;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private List<Observer> observers = new ArrayList<>();
|
||||||
|
private ObjectProperty<Double> temperature = new SimpleObjectProperty<>(0.00);
|
||||||
|
|
||||||
|
public ObjectProperty<Double> temperatureProperty() {
|
||||||
|
return temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getTemperature(){
|
||||||
|
return temperature.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Modifie la température actuelle et notifie les observeurs
|
||||||
|
public void setTemperature(Double temperature){
|
||||||
|
this.temperature.set(temperature);
|
||||||
|
notifier();
|
||||||
|
}
|
||||||
|
protected GenerationStrat generator;
|
||||||
|
|
||||||
|
public Capteur(int id,String name){
|
||||||
|
this.id=id;
|
||||||
|
this.name=name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId(){
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName(){
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGenerator(GenerationStrat generator){
|
||||||
|
this.generator=generator;
|
||||||
|
}
|
||||||
|
|
||||||
|
//génère une température grâce à la stratégie de génération utilisée, la génération se fait différemment en fonction du type de capteur
|
||||||
|
public void genValue() {}
|
||||||
|
|
||||||
|
public void add(Capteur captor, Double poids){}
|
||||||
|
|
||||||
|
public String toString(){
|
||||||
|
|
||||||
|
return getId() + " : " + getName() + " : " + getTemperature();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
package Model;
|
||||||
|
|
||||||
|
import javafx.beans.property.ObjectProperty;
|
||||||
|
import javafx.beans.property.SimpleObjectProperty;
|
||||||
|
|
||||||
|
public class CapteurBasique extends Capteur implements Runnable{
|
||||||
|
|
||||||
|
//Thread du capteur
|
||||||
|
public Thread runner;
|
||||||
|
|
||||||
|
//Temps d'attente avant de générer une nouvelle valeur, par défaut, 2 secondes, soit 2000 millisecondes
|
||||||
|
private ObjectProperty<Integer> waitTime = new SimpleObjectProperty<>(2000);
|
||||||
|
|
||||||
|
public ObjectProperty<Integer> waitTimeProperty() {
|
||||||
|
return waitTime;
|
||||||
|
}
|
||||||
|
public Integer getWaitTime(){
|
||||||
|
return waitTime.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Constructeur
|
||||||
|
public CapteurBasique(int id, String name, GenerationStrat generator) {
|
||||||
|
super(id, name);
|
||||||
|
this.generator = generator;
|
||||||
|
this.startThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Démarre un nouveau thread
|
||||||
|
public void startThread(){
|
||||||
|
runner = new Thread(this);
|
||||||
|
runner.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopThread(){
|
||||||
|
runner.interrupt();
|
||||||
|
}
|
||||||
|
|
||||||
|
//génère une température grâce à la stratégie de génération utilisée
|
||||||
|
public void genValue(){
|
||||||
|
//Si la génération est manuelle, on n'utilise pas de générateur, on garde donc la valeur courante
|
||||||
|
if(generator instanceof GenManual){
|
||||||
|
setTemperature(getTemperature());
|
||||||
|
}else{
|
||||||
|
//Sinon, on change la valeur on fonction de la stratégie utilisée
|
||||||
|
setTemperature(generator.generate());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Permet d'ajouter un capteur. Cette fonctionnalité n'est utilisable que pour les capteurs de zone, c'est pourquoi elle retourne une exception pour un capteur basique
|
||||||
|
public void add(Capteur captor, Double poids){
|
||||||
|
throw new RuntimeException("Tentative d'ajout de capteur sur un capteur basique : non autorisé");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Cette méthode est appelée automatiquement avec l'utilisation du thread
|
||||||
|
@Override
|
||||||
|
public void run(){
|
||||||
|
genValue(); //On génère une valeur
|
||||||
|
try {
|
||||||
|
runner.sleep(this.getWaitTime()); //On attend le temps défini entre deux générations
|
||||||
|
run(); //On recommence
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package Model;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class CapteurZone extends Capteur implements Observer{
|
||||||
|
|
||||||
|
//Liste référençant les capteurs observés
|
||||||
|
private List<Capteur> capteurs = new ArrayList<>();
|
||||||
|
|
||||||
|
//Liste référençant le poids de chaque capteur observé
|
||||||
|
private List<Double> poids = new ArrayList<>();
|
||||||
|
|
||||||
|
private double poidTotal = 0.0;
|
||||||
|
|
||||||
|
//Constructeur
|
||||||
|
public CapteurZone(int id, String name) {
|
||||||
|
super(id, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Permet d'ajouter un capteur à la zone
|
||||||
|
public void add(Capteur captor, Double poids){
|
||||||
|
capteurs.add(captor);
|
||||||
|
this.poids.add(poids);
|
||||||
|
poidTotal = poidTotal + poids;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Retire un capteur de la zone
|
||||||
|
public void remove(int index){
|
||||||
|
capteurs.remove(index);
|
||||||
|
poidTotal = poidTotal - poids.get(index);
|
||||||
|
poids.remove(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Recalcule la température du capteur, étant la moyenne des température des capteurs, en prenant en compte leur poids
|
||||||
|
//Ce recalcul est appelé dès qu'un des capteurs change de température, car il notifie ses observateurs
|
||||||
|
// en sachant que le capteur de zone est à la fois un capteur et un observateur
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
Double sommeTemp = 0.0; //Somme des températures des capteurs
|
||||||
|
for (int i = 0; i < capteurs.size(); i++) { //On parcourt chacun des capteurs
|
||||||
|
sommeTemp = sommeTemp + (capteurs.get(i).getTemperature() * poids.get(i)); //On calcule la somme des températures
|
||||||
|
}
|
||||||
|
//On change la température du capteur en divisant le résultat par la somme des poids pour obtenir la moyenne
|
||||||
|
setTemperature(sommeTemp/poidTotal);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
package Model;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.random.RandomGenerator;
|
||||||
|
|
||||||
|
public class GenBoundedRandom implements GenerationStrat {
|
||||||
|
|
||||||
|
private double min;
|
||||||
|
private double max;
|
||||||
|
private boolean boundDefined;
|
||||||
|
|
||||||
|
private Random random;
|
||||||
|
|
||||||
|
public GenBoundedRandom(double min, double max){
|
||||||
|
if(min > max){ //Si la borne inférieure à une plus grande valeur que la borne supérieure, on les inverse
|
||||||
|
double temp = min;
|
||||||
|
min = max;
|
||||||
|
max = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.max=max;
|
||||||
|
|
||||||
|
if(min < -273.15){
|
||||||
|
min = - 273.15;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.min=min;
|
||||||
|
|
||||||
|
boundDefined = true;
|
||||||
|
random = new Random();
|
||||||
|
}
|
||||||
|
|
||||||
|
public GenBoundedRandom(){
|
||||||
|
boundDefined = false;
|
||||||
|
random = new Random();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double generate() {
|
||||||
|
if(boundDefined){
|
||||||
|
return random.nextDouble() * (max - min) + min;
|
||||||
|
}
|
||||||
|
return random.nextDouble() * 333.15 - 273.15;
|
||||||
|
//Pour calculer un double, on utilise la méthode nextDouble de Random
|
||||||
|
// On a définit notre maximum à 60°C et le minimum possible comme étant le zéro absolu (- 273.15°C)
|
||||||
|
// 60 - (- 273.15) = 333.15
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
package Model;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.random.RandomGenerator;
|
||||||
|
|
||||||
|
public class GenBoundedRealist implements GenerationStrat{
|
||||||
|
private double min;
|
||||||
|
private double max;
|
||||||
|
private double generatedValue;
|
||||||
|
|
||||||
|
private boolean boundBlocked = false;
|
||||||
|
private Random random;
|
||||||
|
private double lastValue;
|
||||||
|
private boolean firstused = false;
|
||||||
|
|
||||||
|
public GenBoundedRealist(double min, double max, double firstValue){
|
||||||
|
if(min > max){ //Si la borne inférieure à une plus grande valeur que la borne supérieure, on les inverse
|
||||||
|
double temp = min;
|
||||||
|
min = max;
|
||||||
|
max = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
//On définit le minimum possible à -50 °
|
||||||
|
if(min < -50){
|
||||||
|
min = -50;
|
||||||
|
}
|
||||||
|
this.min=min;
|
||||||
|
|
||||||
|
//En réaliste, on ne va pas au dessus de 50°C
|
||||||
|
if(max > 50){
|
||||||
|
max = 50;
|
||||||
|
}
|
||||||
|
this.max=max;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
lastValue=firstValue;
|
||||||
|
|
||||||
|
this.random = new Random();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double generate() {
|
||||||
|
//Si on a déjà utilisé la première valeur, on génère une nouvelle valeur
|
||||||
|
if(firstused){
|
||||||
|
//On génère la nouvelle valeur
|
||||||
|
generatedValue = random.nextDouble() * (max - min) + min;
|
||||||
|
lastValue = lastValue + (random.nextDouble() * (max - min) + min);
|
||||||
|
|
||||||
|
//On fait attention à ce que la valeur finale reste dans les bornes
|
||||||
|
if(lastValue + generatedValue > max){
|
||||||
|
boundBlocked = true; //On renseigne qu'on a bloqué la génération aux bornes
|
||||||
|
lastValue = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(lastValue + generatedValue < min){
|
||||||
|
boundBlocked = true; //On renseigne qu'on a bloqué la génération aux bornes
|
||||||
|
lastValue = min;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Si la valeur s'est heurtée aux bornes, on réinitialise le booleen et retourne la valeur telle quelle
|
||||||
|
if(boundBlocked){
|
||||||
|
boundBlocked = false;
|
||||||
|
return lastValue;
|
||||||
|
}
|
||||||
|
//Sinon, on retourne la nouvelle valeur
|
||||||
|
return lastValue + generatedValue;
|
||||||
|
|
||||||
|
}
|
||||||
|
//Dans la cas on l'on avait pas encore passé la première valeur, on la renvoi et on précise que la première valeur a été utilisée
|
||||||
|
firstused = true;
|
||||||
|
return lastValue;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package Model;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class GenCPU implements GenerationStrat{
|
||||||
|
|
||||||
|
private Scanner scanner;
|
||||||
|
|
||||||
|
public GenCPU(){}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double generate(){
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package Model;
|
||||||
|
|
||||||
|
public class GenManual implements GenerationStrat{
|
||||||
|
@Override
|
||||||
|
public double generate() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package Model;
|
||||||
|
|
||||||
|
public interface GenerationStrat {
|
||||||
|
public double generate();
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package Model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class Observable {
|
||||||
|
|
||||||
|
private List<Observer> observeurs = new ArrayList<>();
|
||||||
|
|
||||||
|
public Observable(){}
|
||||||
|
|
||||||
|
|
||||||
|
public void attacherObs(Observer observer){
|
||||||
|
observeurs.add(observer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dettacherObs(Observer observer){
|
||||||
|
observeurs.remove(observer);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void notifier(){
|
||||||
|
for (Observer b:observeurs) {
|
||||||
|
b.update();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
package Model;
|
||||||
|
|
||||||
|
public interface Observer {
|
||||||
|
public void update();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package Vues;
|
||||||
|
|
||||||
|
import Model.Capteur;
|
||||||
|
import Model.Observer;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Spinner;
|
||||||
|
import javafx.scene.control.SpinnerValueFactory;
|
||||||
|
|
||||||
|
|
||||||
|
public class CapteurWindow implements Observer{
|
||||||
|
|
||||||
|
SpinnerValueFactory<Double> valueFactory = new SpinnerValueFactory.DoubleSpinnerValueFactory(-273.15,60.00,0.00, 0.50);
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Spinner<Double> spinner;
|
||||||
|
|
||||||
|
private Capteur capteur;
|
||||||
|
|
||||||
|
public CapteurWindow(){}
|
||||||
|
|
||||||
|
//Permet de modifier le capteur observé et de bind la valeur du spinner avec la température du capteur
|
||||||
|
public void setCapteur(Capteur capteur) {
|
||||||
|
this.capteur = capteur;
|
||||||
|
spinner.getValueFactory().valueProperty().bindBidirectional(this.capteur.temperatureProperty());
|
||||||
|
capteur.attacherObs(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void initialize(){
|
||||||
|
this.spinner.setValueFactory(valueFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Permet de changer de capteur, on enlève le binding sur le capteur précédent, puis on set avec le nouveau capteur
|
||||||
|
public void changeCapteur(Capteur newCapteur) {
|
||||||
|
spinner.getValueFactory().valueProperty().unbindBidirectional(capteur.temperatureProperty());
|
||||||
|
capteur.dettacherObs(this);
|
||||||
|
setCapteur(newCapteur);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package Vues;
|
||||||
|
import Model.Capteur;
|
||||||
|
import Model.Observer;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.image.Image;
|
||||||
|
import javafx.scene.image.ImageView;
|
||||||
|
|
||||||
|
public class ImageWindow implements Observer {
|
||||||
|
@FXML
|
||||||
|
private ImageView imageTemp;
|
||||||
|
|
||||||
|
public void setImageTemp(String imagePath) {
|
||||||
|
this.imageTemp.setImage(new Image(imagePath));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Capteur capteur;
|
||||||
|
|
||||||
|
public ImageWindow(){}
|
||||||
|
|
||||||
|
public void setCapteur(Capteur capteur) {
|
||||||
|
this.capteur = capteur;
|
||||||
|
this.capteur.attacherObs(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ChangeCapteur(Capteur newCapteur) {
|
||||||
|
capteur.dettacherObs(this);
|
||||||
|
setCapteur(newCapteur);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void initialize(){}
|
||||||
|
|
||||||
|
//Change l'image affichée en fonction de la température du capteur observé
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
if(capteur.getTemperature() > 22){
|
||||||
|
setImageTemp("/images/sun.jpg");
|
||||||
|
return;
|
||||||
|
} else if (capteur.getTemperature() < 0 ) {
|
||||||
|
setImageTemp("/images/ice.jpg");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setImageTemp("/images/cloud.jpg");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
package Vues;
|
||||||
|
|
||||||
|
import Model.*;
|
||||||
|
import javafx.beans.property.ListProperty;
|
||||||
|
import javafx.beans.property.SimpleListProperty;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableArray;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
|
import javafx.scene.control.TreeView;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MainWindow {
|
||||||
|
|
||||||
|
|
||||||
|
private ImageWindow imgW;
|
||||||
|
|
||||||
|
private CapteurWindow captW;
|
||||||
|
|
||||||
|
private boolean firstCaptor = true;
|
||||||
|
|
||||||
|
private Capteur copie;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ListView<Capteur> lesCapteursAVoir = new ListView<>();
|
||||||
|
|
||||||
|
private ObservableList<Capteur> lesCapteurs = FXCollections.observableArrayList();
|
||||||
|
|
||||||
|
private ListProperty<Capteur> capteurs = new SimpleListProperty<>(lesCapteurs);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public ListProperty<Capteur> get(){
|
||||||
|
return capteurs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableList<Capteur> getLesCapteurs(){
|
||||||
|
return capteurs.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MainWindow(ImageWindow imgW, CapteurWindow captW){
|
||||||
|
this.imgW=imgW;
|
||||||
|
this.captW=captW;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void initialize(){
|
||||||
|
capteurs.add(new CapteurBasique(1,"capteur random", new GenBoundedRandom()));
|
||||||
|
capteurs.add(new CapteurBasique(2,"capteur manuel", new GenManual()));
|
||||||
|
capteurs.add(new CapteurBasique(3,"capteur random réaliste", new GenBoundedRealist(-20.00,60.00,0.00)));
|
||||||
|
|
||||||
|
lesCapteursAVoir.itemsProperty().bind(capteurs);
|
||||||
|
|
||||||
|
lesCapteursAVoir.setOnMouseClicked(event ->{
|
||||||
|
Capteur selectedCaptor = lesCapteursAVoir.getSelectionModel().getSelectedItem();
|
||||||
|
if(selectedCaptor != null){
|
||||||
|
if(firstCaptor){
|
||||||
|
System.out.println("Le capteur " + selectedCaptor.getName() + " est selectionné\n");
|
||||||
|
imgW.setCapteur(selectedCaptor);
|
||||||
|
captW.setCapteur(selectedCaptor);
|
||||||
|
firstCaptor = false;
|
||||||
|
}else{
|
||||||
|
imgW.ChangeCapteur(selectedCaptor);
|
||||||
|
captW.changeCapteur(selectedCaptor);
|
||||||
|
System.out.println("Le capteur " + selectedCaptor.getName() + " est selectionné\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
package launcher;
|
||||||
|
|
||||||
|
import Model.*;
|
||||||
|
import Vues.CapteurWindow;
|
||||||
|
import Vues.ImageWindow;
|
||||||
|
import Vues.MainWindow;
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Group;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.layout.BorderPane;
|
||||||
|
import javafx.scene.text.Text;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
public class Main extends Application {
|
||||||
|
//--module-path ${JFX_PATH} --add-modules javafx.controls,javafx.fxml
|
||||||
|
@Override
|
||||||
|
public void start(Stage primaryStage) throws Exception {
|
||||||
|
|
||||||
|
|
||||||
|
//Capteur pour tester les fenêtres
|
||||||
|
Capteur capteurTest = new CapteurBasique(1, "capteur Test", new GenBoundedRandom());
|
||||||
|
|
||||||
|
//Fenêtre images
|
||||||
|
FXMLLoader loaderImage = new FXMLLoader(getClass().getResource("/ImageWindow.fxml"));
|
||||||
|
ImageWindow imgW = new ImageWindow();
|
||||||
|
|
||||||
|
//imgW.setCapteur(capteurTest);
|
||||||
|
//capteurTest.attacherObs(imgW);
|
||||||
|
|
||||||
|
loaderImage.setController(imgW);
|
||||||
|
Parent image = loaderImage.load();
|
||||||
|
Stage imageStage = new Stage();
|
||||||
|
imageStage.setScene(new Scene(image));
|
||||||
|
imageStage.setTitle("Fenêtre image");
|
||||||
|
imageStage.show();
|
||||||
|
|
||||||
|
//Fenêtre Capteur
|
||||||
|
|
||||||
|
FXMLLoader loaderCapteur = new FXMLLoader(getClass().getResource("/CapteurWindow.fxml"));
|
||||||
|
CapteurWindow captW = new CapteurWindow();
|
||||||
|
|
||||||
|
//capteurTest.attacherObs(captW);
|
||||||
|
|
||||||
|
loaderCapteur.setController(captW);
|
||||||
|
Parent capteur = loaderCapteur.load();
|
||||||
|
Stage capteurStage = new Stage();
|
||||||
|
capteurStage.setScene(new Scene(capteur));
|
||||||
|
capteurStage.setTitle("Fenêtre capteur");
|
||||||
|
capteurStage.show();
|
||||||
|
|
||||||
|
//Fenêtre principale
|
||||||
|
FXMLLoader loaderMain = new FXMLLoader(getClass().getResource("/MainWindow.fxml"));
|
||||||
|
MainWindow mainWindow = new MainWindow(imgW,captW);
|
||||||
|
loaderMain.setController(mainWindow);
|
||||||
|
Parent root = loaderMain.load();
|
||||||
|
primaryStage.setScene(new Scene(root));
|
||||||
|
primaryStage.setTitle("Fenêtre principale");
|
||||||
|
primaryStage.setOnCloseRequest(e -> Platform.exit()); //Si la fenêtre principale est fermée, l'application se ferme
|
||||||
|
primaryStage.show();
|
||||||
|
|
||||||
|
//captW.setCapteur(capteurTest);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/Resources" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="lib" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
Loading…
Reference in new issue