parent
dffb8a61bd
commit
be4ffc52c7
@ -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" exported="" name="lib" level="project" />
|
||||
</component>
|
||||
</module>
|
After Width: | Height: | Size: 145 KiB |
After Width: | Height: | Size: 73 KiB |
After Width: | Height: | Size: 527 KiB |
@ -0,0 +1,33 @@
|
||||
<?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?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<BorderPane xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
prefHeight="400.0" prefWidth="600.0">
|
||||
<top>
|
||||
<BorderPane>
|
||||
<center>
|
||||
<Label>
|
||||
Météo
|
||||
</Label>
|
||||
</center>
|
||||
</BorderPane>
|
||||
</top>
|
||||
<center>
|
||||
<ImageView fx:id="imageview"/>
|
||||
</center>
|
||||
<bottom>
|
||||
<BorderPane>
|
||||
<center>
|
||||
<Button fx:id="myBtn" text="Quit"/>
|
||||
</center>
|
||||
</BorderPane>
|
||||
</bottom>
|
||||
</BorderPane>
|
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import java.util.*?>
|
||||
<?import javafx.scene.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<BorderPane xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
prefHeight="400.0" prefWidth="600.0">
|
||||
<top>
|
||||
<BorderPane>
|
||||
<center>
|
||||
<Label>
|
||||
Thermostat
|
||||
</Label>
|
||||
</center>
|
||||
</BorderPane>
|
||||
</top>
|
||||
<center>
|
||||
<Spinner fx:id="spin"></Spinner>
|
||||
</center>
|
||||
<bottom>
|
||||
<BorderPane>
|
||||
<center>
|
||||
<Button fx:id="myBtn" text="Quit"/>
|
||||
</center>
|
||||
</BorderPane>
|
||||
</bottom>
|
||||
</BorderPane>
|
@ -0,0 +1,54 @@
|
||||
package launcher;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.stage.Stage;
|
||||
import model.Capteur;
|
||||
import view.CapteurView;
|
||||
import view.ImageCtrlView;
|
||||
import view.ThermostatView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Random;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class Launch extends Application {
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws IOException, InterruptedException {
|
||||
Capteur captor = new Capteur(1,"CapteurIncroyable", 15);
|
||||
|
||||
Stage thermostatStage = new Stage();
|
||||
CapteurView capteurView = new ImageCtrlView(captor,"view/Image.fxml","mon titre");
|
||||
ThermostatView thermostatView = new ThermostatView(captor,"view/Thermostat.fxml","mon titre");
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
Thread t = new Thread() {
|
||||
public void run() {
|
||||
while (true) {
|
||||
captor.setTemp(random.nextInt(30));
|
||||
try {
|
||||
sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,52 @@
|
||||
package model;
|
||||
|
||||
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Capteur implements CapteurAbstrait{
|
||||
|
||||
private int id;
|
||||
private String nom;
|
||||
private ObjectProperty<Double> temp = new SimpleObjectProperty<>();
|
||||
|
||||
public Capteur(int id, String nom, int pTemp){
|
||||
this.id = id;
|
||||
this.nom = nom;
|
||||
temp.setValue((double)pTemp);
|
||||
}
|
||||
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public void setNom(String nom) {
|
||||
this.nom = nom;
|
||||
}
|
||||
|
||||
public ObjectProperty<Double> getTemp() {
|
||||
return temp;
|
||||
}
|
||||
|
||||
public void setTemp(int pTemp) {
|
||||
this.temp.set((double)pTemp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectProperty<Double> genTemp() {
|
||||
Random random = new Random();
|
||||
this.setTemp(random.nextInt(30));
|
||||
return this.getTemp();
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package model;
|
||||
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
|
||||
public interface CapteurAbstrait {
|
||||
public ObjectProperty<Double> genTemp();
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package model;
|
||||
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CapteurVirtuel implements CapteurAbstrait{
|
||||
|
||||
private List<CapteurAbstrait> capteurs;
|
||||
|
||||
public CapteurVirtuel(List<CapteurAbstrait> cs){
|
||||
this.capteurs = cs;
|
||||
}
|
||||
public void addCapteur(CapteurAbstrait c){
|
||||
capteurs.add(c);
|
||||
}
|
||||
|
||||
public void removeCapteur(CapteurAbstrait c){
|
||||
capteurs.remove(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectProperty<Double> genTemp() {
|
||||
ObjectProperty<Double> avg = new SimpleObjectProperty<>();
|
||||
avg.setValue((double) 0);
|
||||
|
||||
for (CapteurAbstrait c: capteurs) {
|
||||
avg.setValue(c.genTemp() + avg.getValue());
|
||||
}
|
||||
avg.set(avg.getValue()/capteurs.size());
|
||||
return avg.getValue();
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package view;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.InvalidationListener;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.stage.Stage;
|
||||
import model.Capteur;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.event.EventHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public abstract class CapteurView extends FXMLView {
|
||||
@FXML
|
||||
Button myBtn;
|
||||
|
||||
protected Capteur capteur;
|
||||
|
||||
public CapteurView(Capteur capteur,String url, String title) throws IOException {
|
||||
super(url,title);
|
||||
this.setCapteur(capteur);
|
||||
}
|
||||
|
||||
public void setCapteur(Capteur capteur) {
|
||||
this.capteur = capteur;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package view;
|
||||
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FXMLView extends Stage {
|
||||
|
||||
public FXMLView(String url, String title) throws IOException {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(this.getClass().getClassLoader().getResource(url));
|
||||
fxmlLoader.setController(this);
|
||||
Parent root = fxmlLoader.load();
|
||||
Scene scene = new Scene(root);
|
||||
setScene(scene);
|
||||
show();
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package view;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.Observable;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.stage.Stage;
|
||||
import model.Capteur;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class ImageCtrlView extends CapteurView{
|
||||
private final static String fxmlfile = "view/Image.fxml";
|
||||
Class<?> clazz = this.getClass();
|
||||
InputStream input;
|
||||
|
||||
protected Capteur capteur;
|
||||
@FXML
|
||||
ImageView imageview;
|
||||
|
||||
public ImageCtrlView(Capteur capteur, String url, String title) throws IOException {
|
||||
super(capteur,url,title);
|
||||
this.capteur = capteur;
|
||||
myBtn.setOnAction(e -> Platform.exit());
|
||||
changeImage();
|
||||
}
|
||||
|
||||
private void changeImage() throws IOException {
|
||||
if (this.capteur.getTemp().getValue() > 25){
|
||||
input = clazz.getResourceAsStream("/images/sun.png");
|
||||
imageview.setImage(new Image(input));
|
||||
} else if (this.capteur.getTemp().getValue() > 10) {
|
||||
input = clazz.getResourceAsStream("/images/suncloud.png");
|
||||
imageview.setImage(new Image(input));
|
||||
}
|
||||
else{
|
||||
input = clazz.getResourceAsStream("/images/snow.png");
|
||||
imageview.setImage(new Image(input));
|
||||
}
|
||||
imageview.setFitHeight(100);
|
||||
imageview.setFitWidth(100);
|
||||
}
|
||||
|
||||
private void quit(){
|
||||
Platform.exit();
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
/*try {
|
||||
changeImage();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}*/
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package view;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.Observable;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Spinner;
|
||||
import javafx.scene.control.SpinnerValueFactory;
|
||||
import javafx.stage.Stage;
|
||||
import model.Capteur;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ThermostatView extends CapteurView{
|
||||
private final static String fxmlfile = "view/Thermostat.fxml";
|
||||
|
||||
@FXML
|
||||
Spinner<Double> spin;
|
||||
|
||||
protected Capteur capteur;
|
||||
|
||||
public ThermostatView(Capteur capteur, String url, String title) throws IOException {
|
||||
super(capteur,url,title);
|
||||
this.capteur = capteur;
|
||||
this.spin.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0d,100d));
|
||||
this.spin.getValueFactory().valueProperty().bindBidirectional(this.capteur.getTemp());
|
||||
myBtn.setOnAction(e -> Platform.exit());
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
//SpinnerValueFactory valueFactory = new SpinnerValueFactory.IntegerSpinnerValueFactory(capteur.getTemp(), capteur.getTemp(), capteur.getTemp());
|
||||
//spin.setValueFactory(valueFactory);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue