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