CPU Page Working
continuous-integration/drone/push Build encountered an error
Details
continuous-integration/drone/push Build encountered an error
Details
parent
97b0cd6856
commit
969606f3c8
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.
@ -1,23 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
@ -1,18 +1,67 @@
|
||||
package model;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.DoubleProperty;
|
||||
import javafx.beans.property.SimpleDoubleProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class CPUTemp implements GenererTemperature{
|
||||
public class CPUTemp implements GenererTemperature, Runnable {
|
||||
|
||||
DoubleProperty temperature = new SimpleDoubleProperty(0.0);
|
||||
|
||||
float temperature ;
|
||||
String name ;
|
||||
|
||||
public CPUTemp() throws IOException {
|
||||
this.temperature = genererTemperature();
|
||||
public CPUTemp(String nom) throws IOException {
|
||||
this.name=nom;
|
||||
genererTemperature();
|
||||
}
|
||||
@Override
|
||||
public float genererTemperature() throws IOException {
|
||||
public void 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;
|
||||
setTemperature((double) (Float.parseFloat(br.readLine())/1000));
|
||||
}
|
||||
|
||||
public void setTemperature(Double temperature){
|
||||
this.temperature.set(temperature);
|
||||
}
|
||||
|
||||
public DoubleProperty getTemperatureProperty(){
|
||||
return this.temperature;
|
||||
}
|
||||
|
||||
public String getTemperature(){
|
||||
return this.temperature.get()+"";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(){
|
||||
while (true){
|
||||
Platform.runLater(()-> {
|
||||
try {
|
||||
genererTemperature();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
});
|
||||
try{
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch (InterruptedException e){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void startThread(){
|
||||
Thread threadCaptor = new Thread(this);
|
||||
threadCaptor.setDaemon(true);
|
||||
threadCaptor.start();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
package model;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
public interface GenererTemperature {
|
||||
|
||||
abstract float genererTemperature() throws IOException;
|
||||
abstract void genererTemperature() throws IOException;
|
||||
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,19 +1,132 @@
|
||||
package view;
|
||||
|
||||
import console.LView;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.*;
|
||||
import javafx.fxml.FXML;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.util.Callback;
|
||||
import model.*;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class MainPage {
|
||||
|
||||
@FXML
|
||||
private javafx.scene.control.Label labelAvecBinding;
|
||||
private Button FirstButton;
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
private VBox vb1;
|
||||
|
||||
@FXML
|
||||
public void initialize() throws IOException {
|
||||
CapteurVirtuel cV1 = new CapteurVirtuel("CaptVirt1");
|
||||
CPUTemp cpuTemp = new CPUTemp("CPU Captor");
|
||||
|
||||
Captor c1 = new Captor("c1");
|
||||
Captor c2 = new Captor("c2");
|
||||
Captor c3 = new Captor("c3");
|
||||
|
||||
ListView<CapteurVirtuel> listview = new ListView<>();
|
||||
|
||||
VBox FirstCaptorCPU = new VBox();
|
||||
FirstCaptorCPU.setMinSize(565,470);
|
||||
// FirstCaptorCPU.setBorder(new Border(new BorderStroke(Color.BLUE, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(3))));
|
||||
|
||||
javafx.scene.image.Image CPUImage = new javafx.scene.image.Image("https://media.istockphoto.com/id/1204740322/fr/photo/cpu.jpg?s=612x612&w=0&k=20&c=cF154ASgimXysleBPyYsFMI9_GKkkTpDQ0kZTJnm_K0=");
|
||||
javafx.scene.image.ImageView FirstCaptorCPUImage = new javafx.scene.image.ImageView(CPUImage);
|
||||
|
||||
Label FirstCaptorCPULabel = new Label("Temperature");
|
||||
FirstCaptorCPULabel.setFont(new Font("Arial", 30));
|
||||
FirstCaptorCPULabel.setMaxWidth(Double.MAX_VALUE);
|
||||
FirstCaptorCPULabel.setAlignment(Pos.CENTER);
|
||||
|
||||
FirstCaptorCPU.getChildren().add(FirstCaptorCPUImage);
|
||||
FirstCaptorCPU.getChildren().add(FirstCaptorCPULabel);
|
||||
|
||||
|
||||
|
||||
labelAvecBinding.textProperty().set("CPU Temperature");
|
||||
|
||||
ObservableList<CPUTemp> CPUTemperature = FXCollections.observableArrayList(
|
||||
captor-> new ObservableValue[]{
|
||||
captor.getTemperatureProperty()
|
||||
}
|
||||
);
|
||||
|
||||
CPUTemperature.addListener((ListChangeListener.Change<? extends CPUTemp> c) ->{
|
||||
while (c.next()){
|
||||
if (c.wasUpdated()){
|
||||
FirstCaptorCPULabel.textProperty().set("Temperature du CPU : " + cpuTemp.getTemperature() + "°C");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
cV1.addToLesCapteurs(c1);
|
||||
cV1.addToLesCapteurs(c2);
|
||||
cV1.addToLesCapteurs(c3);
|
||||
|
||||
cV1.startThread();
|
||||
|
||||
cpuTemp.startThread();
|
||||
|
||||
captors.add(cV1);
|
||||
|
||||
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);
|
||||
FirstButton.textProperty().set(cpuTemp.getName());
|
||||
FirstCaptorCPULabel.textProperty().set("Temperature du CPU : " + cpuTemp.getTemperature() + "°C");
|
||||
FirstButton.setOnAction(e -> {
|
||||
vb1.getChildren().clear();
|
||||
vb1.getChildren().add(FirstCaptorCPU);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in new issue