diff --git a/src/Launcher/Launch.java b/src/Launcher/Launch.java index 3071380..b184c7e 100644 --- a/src/Launcher/Launch.java +++ b/src/Launcher/Launch.java @@ -7,6 +7,7 @@ import javafx.scene.Scene; import javafx.stage.Stage; import model.Capteur; import model.CapteurSimple; +import model.StratGenerationAleatoire; import view.FXMLwindow; import view.VueCapteur; import view.VueCapteurSimple; @@ -14,7 +15,7 @@ import view.VueCapteurSimple; public class Launch extends Application { @Override public void start(Stage stage) throws Exception { - Capteur capti = new CapteurSimple("id5","capteur1"); + Capteur capti = new CapteurSimple("id5","capteur1", new StratGenerationAleatoire()); FXMLwindow fenetre = new VueCapteurSimple(capti); } diff --git a/src/model/Capteur.java b/src/model/Capteur.java index 2f3bba6..5681a0d 100644 --- a/src/model/Capteur.java +++ b/src/model/Capteur.java @@ -7,7 +7,7 @@ import javafx.beans.property.Property; import javafx.beans.property.StringProperty; import javafx.scene.control.SpinnerValueFactory; -public abstract class Capteur { +public abstract class Capteur implements Runnable{ protected StringProperty id; public String getId() { return id.get(); @@ -50,8 +50,24 @@ public abstract class Capteur { public void setTpsGen(int t) { this.tpsGen.setValue(t); } + public boolean generer = false; + protected abstract int genererTemperature(); - abstract void start(); - abstract void stop(); + public void start(){ + generer=true; + } + public void stop(){ + generer=false; + } + public void run(){ + try { + Thread.sleep(getTpsGen()*1000); + if (generer){ + setValeur(genererTemperature()); + } + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } } diff --git a/src/model/CapteurCompose.java b/src/model/CapteurCompose.java index 07579c5..9f4a9d7 100644 --- a/src/model/CapteurCompose.java +++ b/src/model/CapteurCompose.java @@ -10,7 +10,8 @@ public class CapteurCompose extends Capteur{ private void ajoutCapteur(Capteur c, int poids){ zone.put(c,poids); } - private int genererTemperature(){ + @Override + protected int genererTemperature() { AtomicInteger temp= new AtomicInteger(); AtomicInteger poidsT= new AtomicInteger(); zone.forEach((capt,poids)->{ @@ -19,14 +20,5 @@ public class CapteurCompose extends Capteur{ }); return temp.get()/poidsT.get(); } - @Override - void start() { - - } - - @Override - void stop() { - - } } diff --git a/src/model/CapteurSimple.java b/src/model/CapteurSimple.java index 9da9fa2..61fbd58 100644 --- a/src/model/CapteurSimple.java +++ b/src/model/CapteurSimple.java @@ -14,7 +14,8 @@ public class CapteurSimple extends Capteur{ private void setStrategie(StratGeneration s){ strategie=s; } - public CapteurSimple(String i, String n){ + public CapteurSimple(String i, String n,StratGeneration s){ + setStrategie(s); id=new SimpleStringProperty(); nom=new SimpleStringProperty(); setId(i); @@ -26,14 +27,9 @@ public class CapteurSimple extends Capteur{ /* strategie=new StratGenerationCPU();*/ } - @Override - void start() { - //tant que pas stop, attendre tps gen - //puis faire valeur=strategie.generer() - } @Override - void stop() { - + protected int genererTemperature() { + return strategie.generer(); } } diff --git a/src/model/StratGenerationAleatoire.java b/src/model/StratGenerationAleatoire.java index b9e7f7d..04b75fc 100644 --- a/src/model/StratGenerationAleatoire.java +++ b/src/model/StratGenerationAleatoire.java @@ -1,4 +1,10 @@ package model; -public class StratGenerationAleatoire { +import java.util.Random; +public class StratGenerationAleatoire extends StratGeneration{ + @Override + int generer() { + Random random = new Random(); + return -5+random.nextInt(40); + } } diff --git a/src/model/StratGenerationSeuil.java b/src/model/StratGenerationSeuil.java index 5533729..d1e8250 100644 --- a/src/model/StratGenerationSeuil.java +++ b/src/model/StratGenerationSeuil.java @@ -4,7 +4,7 @@ import java.util.Random; public class StratGenerationSeuil extends StratGeneration{ private DegreKelvin min=new DegreKelvin(0); - private DegreKelvin max; + private DegreKelvin max=new DegreKelvin(40); @Override int generer() { diff --git a/src/view/VueCapteur.java b/src/view/VueCapteur.java index 7866738..a2803b4 100644 --- a/src/view/VueCapteur.java +++ b/src/view/VueCapteur.java @@ -8,8 +8,12 @@ import java.io.IOException; public abstract class VueCapteur extends FXMLwindow implements Initializable{ private Capteur capt; + private Thread thread; public VueCapteur(Capteur capteur,String url) throws IOException { super(url, capteur.getNom()); capt=capteur; + capt.start(); + thread=new Thread(capteur); + thread.start(); } } diff --git a/src/view/VueCapteurSimple.java b/src/view/VueCapteurSimple.java index b824932..00a14bf 100644 --- a/src/view/VueCapteurSimple.java +++ b/src/view/VueCapteurSimple.java @@ -29,11 +29,11 @@ public class VueCapteurSimple extends VueCapteur{ idCapteur.textProperty().bindBidirectional(capteur.idProperty()); nomCapteur.textProperty().bindBidirectional(capteur.nomProperty()); -/* + valeurCapteur.textProperty().bindBidirectional(capteur.valeurProperty()); -*/ + spinTps.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0,10,capteur.getTpsGen(),1)); - capteur.tpsGenProperty().bind(spinTps.valueProperty()); + //capteur.tpsGenProperty().bind(spinTps.valueProperty()); }