Virtual Captor Menu Working (button not assigned yet)
continuous-integration/drone/push Build encountered an error Details

master
dohodin 2 years ago
parent 969606f3c8
commit 472005cad5

@ -13,13 +13,12 @@
<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">
<Image url="@../img/th.png" />
</ImageView>
<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" />
<Button fx:id="SecondButton" layoutX="80.0" layoutY="140.0" mnemonicParsing="false" text="Captor2" />
<VBox fx:id="vb2" layoutX="50.0" layoutY="218.0" prefHeight="181.0" prefWidth="124.0" />
<ImageView fx:id="open" fitHeight="18.0" fitWidth="18.0" layoutX="64.0" layoutY="171.0" pickOnBounds="true" preserveRatio="true">
<Image url="@../img/close.png" />
</ImageView>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<VBox fx:id="vb1" prefHeight="398.0" prefWidth="417.0" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

@ -13,13 +13,12 @@
<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">
<Image url="@../img/th.png" />
</ImageView>
<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" />
<Button fx:id="SecondButton" layoutX="80.0" layoutY="140.0" mnemonicParsing="false" text="Captor2" />
<VBox fx:id="vb2" layoutX="50.0" layoutY="218.0" prefHeight="181.0" prefWidth="124.0" />
<ImageView fx:id="open" fitHeight="18.0" fitWidth="18.0" layoutX="64.0" layoutY="171.0" pickOnBounds="true" preserveRatio="true">
<Image url="@../img/close.png" />
</ImageView>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<VBox fx:id="vb1" prefHeight="398.0" prefWidth="417.0" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

@ -2,19 +2,9 @@ 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;
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 java.io.IOException;
import java.util.Objects;
@ -30,8 +20,6 @@ public class LView extends Application {
primaryStage.setHeight(500);
primaryStage.setScene(scene1);
primaryStage.show();
}
}

@ -3,8 +3,6 @@ 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.*;
@ -14,15 +12,19 @@ public class CPUTemp implements GenererTemperature, Runnable {
String name ;
public CPUTemp(String nom) throws IOException {
public CPUTemp(String nom) {
this.name=nom;
genererTemperature();
}
@Override
public void genererTemperature() throws IOException {
File temp = new File("/sys/devices/virtual/thermal/thermal_zone6/temp");
BufferedReader br = new BufferedReader(new FileReader(temp));
setTemperature((double) (Float.parseFloat(br.readLine())/1000));
public void genererTemperature(){
try{
File temp = new File("/sys/devices/virtual/thermal/thermal_zone6/temp");
BufferedReader br = new BufferedReader(new FileReader(temp));
setTemperature((double) (Float.parseFloat(br.readLine())/1000));
}catch (IOException e){
setTemperature(0.0);
}
}
public void setTemperature(Double temperature){
@ -33,19 +35,14 @@ public class CPUTemp implements GenererTemperature, Runnable {
return this.temperature;
}
public String getTemperature(){
return this.temperature.get()+"";
public double getTemperature(){
return this.temperature.get();
}
@Override
public void run(){
while (true){
Platform.runLater(()-> {
try {
genererTemperature();
} catch (IOException ignored) {
}
});
Platform.runLater(this::genererTemperature);
try{
Thread.sleep(100);
}

@ -6,11 +6,9 @@ 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;
@ -22,11 +20,6 @@ public class Captor implements Runnable{
this.temperature=new SimpleDoubleProperty(5.0);
}
public UUID getId()
{
return this.id;
}
public String getName(){
return this.name.get();
}

@ -5,62 +5,44 @@ import javafx.collections.*;
import javafx.fxml.FXML;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.text.Font;
import javafx.util.Callback;
import model.*;
import java.io.IOException;
public class MainPage {
@FXML
private Button FirstButton;
@FXML private Button FirstButton;
@FXML
private VBox vb1;
@FXML private Button SecondButton;
@FXML
public void initialize() throws IOException {
CapteurVirtuel cV1 = new CapteurVirtuel("CaptVirt1");
CPUTemp cpuTemp = new CPUTemp("CPU Captor");
@FXML private VBox vb1;
Captor c1 = new Captor("c1");
Captor c2 = new Captor("c2");
Captor c3 = new Captor("c3");
@FXML private VBox vb2;
ListView<CapteurVirtuel> listview = new ListView<>();
@FXML private ImageView open;
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);
CPUTemp cpuTemp = new CPUTemp("CPU Captor");
CapteurVirtuel cV1 = new CapteurVirtuel("CaptVirt1");
Captor c1 = new Captor("c1");
Captor c2 = new Captor("c2");
@FXML
public void initialize() {
Label FirstCaptorCPULabel = new Label("Temperature");
FirstCaptorCPULabel.setFont(new Font("Arial", 30));
FirstCaptorCPULabel.setMaxWidth(Double.MAX_VALUE);
FirstCaptorCPULabel.setAlignment(Pos.CENTER);
FirstButton.textProperty().set(cpuTemp.getName());
FirstCaptorCPU.getChildren().add(FirstCaptorCPUImage);
FirstCaptorCPU.getChildren().add(FirstCaptorCPULabel);
SecondButton.textProperty().set(cV1.getName());
ListView<CapteurVirtuel> listview = new ListView<>();
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[]{
@ -78,15 +60,12 @@ public class MainPage {
c1.startThread();
c2.startThread();
c3.startThread();
cV1.addToLesCapteurs(c1);
cV1.addToLesCapteurs(c2);
cV1.addToLesCapteurs(c3);
cV1.startThread();
cpuTemp.startThread();
captors.add(cV1);
@ -120,13 +99,116 @@ public class MainPage {
});
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);
try {
vb1.getChildren().add(setVboxCPUCaptor());
} catch (IOException ex) {
throw new RuntimeException(ex);
}
});
open.setFitWidth(18);
open.setFitHeight(18);
SecondButton.setOnAction(e -> {
if (!vb2.getChildren().isEmpty()){
open.setImage(new Image("https://www.citypng.com/public/uploads/preview/download-black-right-triangle-png-31629764954y0662peplm.png"));
vb2.getChildren().clear();
}else{
open.setImage(new Image("https://cdn-icons-png.flaticon.com/512/0/159.png"));
vb2.getChildren().add(setHBoxFirstCaptor());
vb2.getChildren().add(setHBoxSecondCaptor());
}
});
}
private VBox setVboxCPUCaptor() throws IOException {
VBox FirstCaptorCPU = new VBox();
FirstCaptorCPU.setMinSize(565,470);
ImageView FirstCaptorCPUImage = new ImageView(new Image("https://media.istockphoto.com/id/1204740322/fr/photo/cpu.jpg?s=612x612&w=0&k=20&c=cF154ASgimXysleBPyYsFMI9_GKkkTpDQ0kZTJnm_K0="));
Label FirstCaptorCPULabel = new Label("Temperature");
FirstCaptorCPULabel.setFont(new Font("Arial", 30));
FirstCaptorCPULabel.setMaxWidth(Double.MAX_VALUE);
FirstCaptorCPULabel.setAlignment(Pos.CENTER);
FirstCaptorCPULabel.setWrapText(true);
if (cpuTemp.getTemperature()==0.0){
FirstCaptorCPULabel.setFont(new Font("Arial", 15));
FirstCaptorCPULabel.textProperty().set("Impossible de récupérer la temperature du CPU, possiblement car le fichier qui contient cette temperature n'existe pas ou n'est pas au même endroit que celui utilisé lors du développement.");
}else{
FirstCaptorCPULabel.textProperty().set("Temperature du CPU : " + cpuTemp.getTemperature() + "°C");
}
FirstCaptorCPU.getChildren().add(FirstCaptorCPUImage);
FirstCaptorCPU.getChildren().add(FirstCaptorCPULabel);
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");
}
}
});
cpuTemp.startThread();
return FirstCaptorCPU;
}
private HBox setHBoxFirstCaptor(){
HBox Captor1 = new HBox();
ImageView FirstCaptorImage = new ImageView(new Image("https://cdn-icons-png.flaticon.com/512/70/70597.png"));
FirstCaptorImage.setFitHeight(73);
FirstCaptorImage.setFitWidth(73);
Button FirstCaptorButton = new Button();
FirstCaptorButton.setText(c1.getName());
FirstCaptorButton.setFont(new Font("System", 13));
FirstCaptorButton.setMaxWidth(Double.MAX_VALUE);
FirstCaptorButton.setAlignment(Pos.CENTER_LEFT);
Captor1.getChildren().add(FirstCaptorImage);
Captor1.getChildren().add(FirstCaptorButton);
return Captor1;
}
private HBox setHBoxSecondCaptor(){
HBox Captor2 = new HBox();
ImageView SecondCaptorImage = new ImageView(new Image("https://cdn-icons-png.flaticon.com/512/70/70597.png"));
SecondCaptorImage.setFitHeight(73);
SecondCaptorImage.setFitWidth(73);
Button SecondCaptorButton = new Button();
SecondCaptorButton.setText(c2.getName());
SecondCaptorButton.setFont(new Font("System", 13));
SecondCaptorButton.setMaxWidth(Double.MAX_VALUE);
SecondCaptorButton.setAlignment(Pos.CENTER_LEFT);
Captor2.getChildren().add(SecondCaptorImage);
Captor2.getChildren().add(SecondCaptorButton);
return Captor2;
}
}

Loading…
Cancel
Save