commit
2f8ea6f351
@ -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,9 @@
|
||||
<?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$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager">
|
||||
<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$/.idea/ProjetJavaFX.iml" filepath="$PROJECT_DIR$/.idea/ProjetJavaFX.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</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$/resource" 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>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1" />
|
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,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1" />
|
@ -0,0 +1,108 @@
|
||||
package console;
|
||||
|
||||
import model.*;
|
||||
import javafx.application.Application;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.Callback;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.scene.layout.StackPane;
|
||||
|
||||
public class LView extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) {
|
||||
CapteurVirtuel cV1 = new CapteurVirtuel("CaVirt1");
|
||||
CapteurVirtuel cV2 = new CapteurVirtuel("CaVirt2");
|
||||
|
||||
Captor c1 = new Captor("c1");
|
||||
Captor c2 = new Captor("c2");
|
||||
Captor c3 = new Captor("c3");
|
||||
Captor c4 = new Captor("c4");
|
||||
Captor c5 = new Captor("c5");
|
||||
Captor c6 = new Captor("c6");
|
||||
|
||||
|
||||
ListView<CapteurVirtuel> listview = new ListView<>();
|
||||
|
||||
|
||||
ObservableList<CapteurVirtuel> captors = FXCollections.observableArrayList(
|
||||
captor->new ObservableValue[]{
|
||||
captor.getTempMoyenneProperty()
|
||||
}
|
||||
);
|
||||
|
||||
captors.addListener((ListChangeListener.Change<? extends CapteurVirtuel> c) ->{
|
||||
while (c.next()){
|
||||
if (c.wasUpdated()){
|
||||
listview.refresh();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
c1.startThread();
|
||||
c2.startThread();
|
||||
c3.startThread();
|
||||
c4.startThread();
|
||||
c5.startThread();
|
||||
c6.startThread();
|
||||
|
||||
cV1.addToLesCapteurs(c1);
|
||||
cV1.addToLesCapteurs(c2);
|
||||
cV1.addToLesCapteurs(c3);
|
||||
cV2.addToLesCapteurs(c4);
|
||||
cV2.addToLesCapteurs(c5);
|
||||
cV2.addToLesCapteurs(c6);
|
||||
|
||||
captors.add(cV1);
|
||||
captors.add(cV2);
|
||||
|
||||
listview.setCellFactory(new Callback<>() {
|
||||
|
||||
@Override
|
||||
public ListCell<CapteurVirtuel> call(ListView<CapteurVirtuel> captorListView) {
|
||||
return new ListCell<>() {
|
||||
@Override
|
||||
protected void updateItem(CapteurVirtuel value, boolean empty) {
|
||||
String text = "";
|
||||
super.updateItem(value, empty);
|
||||
if (value != null) {
|
||||
text = value.getTempMoyenne().toString();
|
||||
}
|
||||
setText(text);
|
||||
String style = null;
|
||||
if (!empty) {
|
||||
assert value != null;
|
||||
if (value.isNegative()) {
|
||||
style = "-fx-text-fill : blue";
|
||||
}
|
||||
}
|
||||
if (!empty && value.isHot()) {
|
||||
style = "-fx-text-fill : red";
|
||||
}
|
||||
setStyle(style);
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
listview.setItems(captors);
|
||||
|
||||
final StackPane root = new StackPane();
|
||||
root.getChildren().add(listview);
|
||||
final Scene scene = new Scene(root);
|
||||
primaryStage.setTitle("ListView");
|
||||
primaryStage.setWidth(300);
|
||||
primaryStage.setHeight(350);
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package model;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Alea implements GenererTemperature{
|
||||
|
||||
private float temperature;
|
||||
private double min;
|
||||
private double max;
|
||||
|
||||
public Alea(){
|
||||
this.temperature = genererTemperature();
|
||||
Random rand = new Random();
|
||||
min= rand.nextDouble();
|
||||
max= rand.nextDouble(min);
|
||||
}
|
||||
@Override
|
||||
public float genererTemperature() {
|
||||
|
||||
Random rand = new Random();
|
||||
return rand.nextFloat()+rand.nextInt();
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package model;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class CPUTemp implements GenererTemperature{
|
||||
|
||||
float temperature ;
|
||||
|
||||
public CPUTemp() throws IOException {
|
||||
this.temperature = genererTemperature();
|
||||
}
|
||||
@Override
|
||||
public float genererTemperature() throws IOException {
|
||||
File temp = new File("/sys/devices/virtual/thermal/thermal_zone6/temp");
|
||||
BufferedReader br = new BufferedReader(new FileReader(temp));
|
||||
return Float.parseFloat(br.readLine())/1000;
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package model;
|
||||
|
||||
|
||||
import javafx.beans.property.DoubleProperty;
|
||||
import javafx.beans.property.SimpleDoubleProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.collections.*;
|
||||
import java.util.*;
|
||||
import static model.Captor.rand;
|
||||
|
||||
public class CapteurVirtuel extends Sujet{
|
||||
|
||||
private final UUID id= UUID.randomUUID();
|
||||
private final StringProperty nom;
|
||||
private final DoubleProperty tempMoyenne = new SimpleDoubleProperty(0);
|
||||
|
||||
final Map<Integer, Captor> source = new HashMap<>();
|
||||
private final ObservableMap<Integer,Captor> lesCapteurs = FXCollections.observableMap(source);
|
||||
public CapteurVirtuel(String nom){
|
||||
this.nom= new SimpleStringProperty(nom);
|
||||
this.tempMoyenne.set(0.0);
|
||||
lesCapteurs.addListener((MapChangeListener<? super Integer, ? super Captor>) c -> {
|
||||
this.tempMoyenne.set(this.updateData());
|
||||
System.out.println("HEY");
|
||||
});
|
||||
}
|
||||
|
||||
public UUID getId()
|
||||
{
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return this.nom.get();
|
||||
}
|
||||
|
||||
public DoubleProperty getTempMoyenneProperty(){
|
||||
return this.tempMoyenne;
|
||||
}
|
||||
|
||||
public Double getTempMoyenne(){
|
||||
return this.tempMoyenne.get();
|
||||
}
|
||||
|
||||
public boolean isNegative(){
|
||||
return (this.getTempMoyenne()<0);
|
||||
}
|
||||
|
||||
public boolean isHot(){
|
||||
return (this.getTempMoyenne()>30);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return Double.toString(this.getTempMoyenne());
|
||||
}
|
||||
|
||||
|
||||
public Collection<Captor> getLesCapteurs(){
|
||||
return lesCapteurs.values();
|
||||
}
|
||||
|
||||
public void addToLesCapteurs(Captor c){
|
||||
lesCapteurs.put((rand.nextInt()%10),c);
|
||||
}
|
||||
|
||||
private Double updateData() {
|
||||
int coef = 0;
|
||||
double valeurs =0;
|
||||
for (Map.Entry<Integer, Captor> entry : lesCapteurs.entrySet()){
|
||||
coef += entry.getKey();
|
||||
valeurs += entry.getKey() * entry.getValue().getTemperature();
|
||||
}
|
||||
if (coef==0 || valeurs==0){
|
||||
return 0.0;
|
||||
}else {
|
||||
return valeurs / coef;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package model;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.DoubleProperty;
|
||||
import javafx.beans.property.SimpleDoubleProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Captor implements Runnable{
|
||||
|
||||
private final UUID id= UUID.randomUUID();
|
||||
private final StringProperty name;
|
||||
|
||||
private final DoubleProperty temperature;
|
||||
|
||||
static final Random rand=new Random(System.currentTimeMillis());
|
||||
|
||||
public Captor(String name){
|
||||
this.name=new SimpleStringProperty(name);
|
||||
this.temperature=new SimpleDoubleProperty(1.0);
|
||||
}
|
||||
|
||||
public UUID getId()
|
||||
{
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return this.name.get();
|
||||
}
|
||||
|
||||
public DoubleProperty getTemperatureProperty(){
|
||||
return this.temperature;
|
||||
}
|
||||
|
||||
public Double getTemperature(){
|
||||
return this.temperature.get();
|
||||
}
|
||||
|
||||
public void setTemperature(double temperature){
|
||||
this.temperature.set(temperature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(){
|
||||
while (true){
|
||||
Platform.runLater(()->setTemperature(rand.nextDouble(80.)-20.));
|
||||
try{
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
catch (InterruptedException e){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void startThread(){
|
||||
Thread threadCaptor = new Thread(this);
|
||||
threadCaptor.setDaemon(true);
|
||||
threadCaptor.start();
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package model;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
public interface GenererTemperature {
|
||||
|
||||
abstract float genererTemperature() throws IOException;
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package model;
|
||||
|
||||
public interface Observateur {
|
||||
void update();
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package model;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Reel implements GenererTemperature{
|
||||
|
||||
Random rand = new Random();
|
||||
private float min = -30;
|
||||
private double max = 60;
|
||||
private float temperature = (float) (min + rand.nextFloat() * (max - min));
|
||||
|
||||
public Reel(){
|
||||
this.temperature = genererTemperature();
|
||||
|
||||
}
|
||||
@Override
|
||||
public float genererTemperature() {
|
||||
this.temperature=this.temperature + (-2 + rand.nextFloat() * (2-(-2)));
|
||||
return this.temperature;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class Sujet {
|
||||
|
||||
public ArrayList<Observateur> observateur = new ArrayList<Observateur>();
|
||||
|
||||
public void attacher(Observateur o){
|
||||
this.observateur.add(o);
|
||||
}
|
||||
|
||||
public void notifier(){
|
||||
for (Observateur o : observateur) {
|
||||
o.update();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package view;
|
||||
|
||||
import model.CapteurVirtuel;
|
||||
import model.Observateur;
|
||||
|
||||
public class Image implements Observateur {
|
||||
|
||||
public float temperature;
|
||||
|
||||
/*
|
||||
public void __construct(float temperature){
|
||||
this.temperature = new Capteur("Test").getTemperature();
|
||||
}
|
||||
*/
|
||||
public void initialize(){
|
||||
|
||||
}
|
||||
|
||||
public void update() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package view;
|
||||
|
||||
import model.CapteurVirtuel;
|
||||
import model.Observateur;
|
||||
|
||||
public class Spinner implements Observateur {
|
||||
|
||||
public float temperature ;
|
||||
|
||||
/*
|
||||
public void __construct(float temperature){
|
||||
this.temperature = new Capteur("Test").getTemperature();
|
||||
}
|
||||
*/
|
||||
public void initialize(){
|
||||
|
||||
}
|
||||
|
||||
public void update() {
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in new issue