2eme commit avec la totale

master
Aurelien PINTRAND 2 years ago
parent 0f391479ea
commit 23ed455e05

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="lib">
<CLASSES>
<root url="file://$PROJECT_DIR$/../openjfx-17.0.1_windows-x64_bin-sdk/javafx-sdk-17.0.1/lib" />
</CLASSES>
<JAVADOC />
<SOURCES />
<jarDirectory url="file://$PROJECT_DIR$/../openjfx-17.0.1_windows-x64_bin-sdk/javafx-sdk-17.0.1/lib" 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_17" project-jdk-name="17" 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$/WeatherStation.iml" filepath="$PROJECT_DIR$/WeatherStation.iml" />
</modules>
</component>
</project>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/WeatherStation/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/WeatherStation/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" />
</component>
</module>

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="lib">
<CLASSES>
<root url="file:///usr/share/openjfx/javafx-sdk-18.0.2/lib" />
</CLASSES>
<JAVADOC />
<NATIVE>
<root url="file:///usr/share/openjfx/javafx-sdk-18.0.2/lib" />
</NATIVE>
<SOURCES />
<jarDirectory url="file:///usr/share/openjfx/javafx-sdk-18.0.2/lib" 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$/WeatherStation.iml" filepath="$PROJECT_DIR$/WeatherStation.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,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>

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.geometry.*?>
<?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>
<top>
<VBox alignment="CENTER" spacing="10">
<Label text="Temperature (°C)" />
<Spinner fx:id="tempSpinner" editable="true"></Spinner>
</VBox>
</top>
<bottom>
<TreeView fx:id = "tree">
</TreeView>
</bottom>
</BorderPane>
</AnchorPane>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

@ -0,0 +1,28 @@
package launch;
import javafx.application.Application;
import javafx.stage.Stage;
import modele.ConcreteSensor;
import modele.Sensor;
import modele.VirtualSensor;
import views.WeatherController;
import java.util.ArrayList;
import java.util.List;
public class Launch extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
//Create captors here
List<Sensor> sensorsList = new ArrayList<>();
VirtualSensor virtualSensor = new VirtualSensor(new ArrayList<>(), 0, "testmachin", 54);
ConcreteSensor concreteSensor1 = new ConcreteSensor(3);
ConcreteSensor concreteSensor2 = new ConcreteSensor(78);
virtualSensor.addSensor(concreteSensor1,concreteSensor1.getWeight());
virtualSensor.addSensor(concreteSensor2,concreteSensor2.getWeight());
sensorsList.add(virtualSensor);
WeatherController weatherController = new WeatherController(sensorsList,"FXML/WeatherStation.fxml","WeatherStation");
}
}

@ -0,0 +1,23 @@
package modele;
public class ConcreteSensor extends Sensor {
private double weight;
public ConcreteSensor(double weight) {
this.weight = weight;
}
public double getWeight() {
return weight;
}
public void updateTemperature() {
}
@Override
public double generateTemperature() {
double min = -273.15;
double max = 1000;
return Math.floor(Math.random() * (max - min + 1) + min); }
}

@ -0,0 +1,28 @@
package modele;
import javafx.beans.property.*;
public abstract class Sensor {
int id;
StringProperty name;
double weight;
private Property<Double> temp = new SimpleObjectProperty<>(0d);
public void setTemp(double tmp){
this.temp.setValue(tmp);
}
public double getTemp() {
return temp.getValue();
}
public StringProperty getName(){
return name;
}
public Property<Double> getTempProperty(){
return temp;
}
public abstract double generateTemperature();
}

@ -0,0 +1,49 @@
package modele;
import javafx.beans.property.SimpleStringProperty;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class VirtualSensor extends Sensor {
private List<ConcreteSensor> sensors =new ArrayList<>();
private Map<ConcreteSensor, Double> weights = new HashMap<>();
public VirtualSensor(List<Sensor> sensorsList, int id, String name, int weight) {
this.name = new SimpleStringProperty(name);
this.id = id;
this.weight = weight;
}
public void addSensor(ConcreteSensor sensor, double weight) {
sensors.add(sensor);
weights.put(sensor, weight);
sensor.getTempProperty().addListener((observable, oldValue, newValue) -> updateTemperature());
}
public void updateTemperature() {
double tempSum = 0;
double weightSum = 0;
for (ConcreteSensor sensor : sensors) {
tempSum += sensor.getTemp() * weights.get(sensor);
weightSum += weights.get(sensor);
}
setTemp(tempSum / weightSum);
}
@Override
public double generateTemperature() {
double value = 0;
double count = 0;
for (Sensor sensor:
sensors) {
value += sensor.getTemp();
count += 1;
}
value = value/count;
return value;
}
}

@ -0,0 +1,20 @@
package views;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class FXMLWindow extends Stage {
public FXMLWindow(String title, String url) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getClassLoader().getResource(url));
fxmlLoader.setController(this);
Parent group = fxmlLoader.load();
Scene scene = new Scene(group);
this.setScene(scene);
this.show();
}
}

@ -0,0 +1,74 @@
package views;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import modele.ConcreteSensor;
import modele.Sensor;
import modele.VirtualSensor;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class WeatherController extends FXMLWindow {
Sensor sensor;
List<Sensor> sensorList;
@FXML
Spinner<Double> tempSpinner;
@FXML
TreeView<Sensor> tree;
public WeatherController(List<Sensor> sensorsList, String url, String title) throws IOException {
super(title, url);
TreeItem<Sensor> root = new TreeItem<>(sensorsList.get(0));
root.setExpanded(true);
tree.setRoot(root);
sensorList = sensorsList;
tree.setVisible(true);
for (Sensor sensor : sensorsList) {
TreeItem<Sensor> sensorItem = new TreeItem<>(sensor);
root.getChildren().add(sensorItem);
}
}
public void initialize(){
//------------------------------------------------------------------------------------------------------
sensor = new ConcreteSensor(56);
tree.setCellFactory(param -> new TreeCell<Sensor>() {
protected void updateItem(Sensor item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
} else {
textProperty().bindBidirectional(item.getName());
}
}
});
//------------------------------------------------------------------------------------------------------
// SPINNER
tempSpinner.setVisible(true);
sensor.getTempProperty().addListener((observable, oldValue, newValue) -> {
System.out.println("La température a changé de " + oldValue + " à " + newValue);
});
SpinnerValueFactory<Double> spinnerValueFactory= new SpinnerValueFactory.DoubleSpinnerValueFactory(-273,10000, sensor.getTemp(), 0.5);
tempSpinner.setValueFactory(spinnerValueFactory);
tempSpinner.getValueFactory().valueProperty().bindBidirectional(sensor.getTempProperty());
sensor.setTemp(sensor.generateTemperature());
System.out.println("initialize spinner");
System.out.println(tempSpinner.getValueFactory().getValue());
};
}

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.geometry.*?>
<?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>
<top>
<VBox alignment="CENTER" spacing="10">
<Label text="Temperature (°C)" />
<Spinner fx:id="tempSpinner" editable="true"></Spinner>
</VBox>
</top>
<bottom>
<TreeView fx:id = "tree">
</TreeView>
</bottom>
</BorderPane>
</AnchorPane>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Loading…
Cancel
Save