CPU Page Working
continuous-integration/drone/push Build encountered an error Details

master
dohodin 3 years ago
parent 97b0cd6856
commit 969606f3c8

@ -6,12 +6,11 @@
<SplitPane dividerPositions="0.29797979797979796" 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" fx:controller="view.MainPage">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<ImageView fx:id="th1" fitHeight="73.0" fitWidth="73.0" layoutX="8.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="311.0" AnchorPane.leftAnchor="8.0" AnchorPane.rightAnchor="94.0" AnchorPane.topAnchor="14.0">
<ImageView fitHeight="73.0" fitWidth="73.0" layoutX="8.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="311.0" AnchorPane.leftAnchor="8.0" AnchorPane.rightAnchor="94.0" AnchorPane.topAnchor="14.0">
<Image url="@../img/th.png" />
</ImageView>
<Label fx:id="labelAvecBinding" layoutX="71.0" layoutY="42.0" text="CPU Temp" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<ImageView fx:id="th2" fitHeight="73.0" fitWidth="73.0" layoutX="8.0" layoutY="116.0" pickOnBounds="true" preserveRatio="true">
<ImageView fitHeight="73.0" fitWidth="73.0" layoutX="8.0" layoutY="116.0" pickOnBounds="true" preserveRatio="true">
<Image url="@../img/th.png" />
</ImageView>
<ImageView fitHeight="73.0" fitWidth="73.0" layoutX="8.0" layoutY="225.0" pickOnBounds="true" preserveRatio="true">
@ -20,6 +19,9 @@
<ImageView fitHeight="73.0" fitWidth="73.0" layoutX="8.0" layoutY="324.0" pickOnBounds="true" preserveRatio="true">
<Image url="@../img/th.png" />
</ImageView>
<Button fx:id="FirstButton" layoutX="80.0" layoutY="38.0" mnemonicParsing="false" text="Captor1" />
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<VBox fx:id="vb1" prefHeight="398.0" prefWidth="417.0" />
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
</SplitPane>

@ -6,12 +6,11 @@
<SplitPane dividerPositions="0.29797979797979796" 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" fx:controller="view.MainPage">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<ImageView fx:id="th1" fitHeight="73.0" fitWidth="73.0" layoutX="8.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="311.0" AnchorPane.leftAnchor="8.0" AnchorPane.rightAnchor="94.0" AnchorPane.topAnchor="14.0">
<ImageView fitHeight="73.0" fitWidth="73.0" layoutX="8.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="311.0" AnchorPane.leftAnchor="8.0" AnchorPane.rightAnchor="94.0" AnchorPane.topAnchor="14.0">
<Image url="@../img/th.png" />
</ImageView>
<Label fx:id="labelAvecBinding" layoutX="71.0" layoutY="42.0" text="CPU Temp" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<ImageView fx:id="th2" fitHeight="73.0" fitWidth="73.0" layoutX="8.0" layoutY="116.0" pickOnBounds="true" preserveRatio="true">
<ImageView fitHeight="73.0" fitWidth="73.0" layoutX="8.0" layoutY="116.0" pickOnBounds="true" preserveRatio="true">
<Image url="@../img/th.png" />
</ImageView>
<ImageView fitHeight="73.0" fitWidth="73.0" layoutX="8.0" layoutY="225.0" pickOnBounds="true" preserveRatio="true">
@ -20,6 +19,9 @@
<ImageView fitHeight="73.0" fitWidth="73.0" layoutX="8.0" layoutY="324.0" pickOnBounds="true" preserveRatio="true">
<Image url="@../img/th.png" />
</ImageView>
<Button fx:id="FirstButton" layoutX="80.0" layoutY="38.0" mnemonicParsing="false" text="Captor1" />
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<VBox fx:id="vb1" prefHeight="398.0" prefWidth="417.0" />
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
</SplitPane>

@ -2,6 +2,7 @@ package console;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.layout.StackPane;
import model.*;
import javafx.application.Application;
import javafx.collections.ObservableList;
@ -15,97 +16,19 @@ import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import java.io.IOException;
import java.util.Objects;
public class LView extends Application {
@Override
public void start(Stage primaryStage) throws IOException {
CapteurVirtuel cV1 = new CapteurVirtuel("CaptVirt1");
CapteurVirtuel cV2 = new CapteurVirtuel("CaptVirt2");
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);
cV1.startThread();
cV2.startThread();
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);
Parent root = FXMLLoader.load(getClass().getResource("/fxml/MainPage.fxml"));
Scene scene = new Scene(root);
Parent root1 = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/MainPage.fxml")));
Scene scene1 = new Scene(root1);
primaryStage.setTitle("Station Météo");
primaryStage.setWidth(900);
primaryStage.setHeight(500);
primaryStage.setScene(scene);
primaryStage.setScene(scene1);
primaryStage.show();

@ -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;
}
}

@ -82,4 +82,7 @@ public class CapteurVirtuel extends Sujet implements Runnable {
threadVirtualCaptor.start();
}
public String getName() {
return this.nom.get();
}
}

@ -48,7 +48,7 @@ public class Captor implements Runnable{
while (true){
Platform.runLater(()->setTemperature(rand.nextDouble(80.)-20.));
try{
Thread.sleep(2999);
Thread.sleep(2000);
}
catch (InterruptedException e){
break;

@ -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…
Cancel
Save