First View and some Binding
continuous-integration/drone/push Build was killed Details

master
dohodin 3 years ago
parent 6b52aa8ac4
commit 97b0cd6856

@ -2,10 +2,6 @@ kind: pipeline
type: docker
name: javaFX
trigger:
event:
- push
steps:
- name: generate-and-deploy-docs
image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-docdeployer
@ -19,7 +15,3 @@ steps:
branch:
- master
depends_on: [ build ]
volumes:
- name: docs
temp: {}

@ -1,5 +0,0 @@
<?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,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<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">
<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">
<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>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
</SplitPane>

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

@ -1,5 +0,0 @@
<?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,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<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">
<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">
<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>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
</SplitPane>

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

@ -1,5 +1,7 @@
package console;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import model.*;
import javafx.application.Application;
import javafx.collections.ObservableList;
@ -11,14 +13,17 @@ import javafx.util.Callback;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.scene.layout.StackPane;
import java.io.IOException;
public class LView extends Application {
@Override
public void start(Stage primaryStage) {
CapteurVirtuel cV1 = new CapteurVirtuel("CaVirt1");
CapteurVirtuel cV2 = new CapteurVirtuel("CaVirt2");
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");
@ -59,6 +64,9 @@ public class LView extends Application {
cV2.addToLesCapteurs(c5);
cV2.addToLesCapteurs(c6);
cV1.startThread();
cV2.startThread();
captors.add(cV1);
captors.add(cV2);
@ -92,13 +100,11 @@ public class LView extends Application {
});
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);
Parent root = FXMLLoader.load(getClass().getResource("/fxml/MainPage.fxml"));
Scene scene = new Scene(root);
primaryStage.setTitle("Station Météo");
primaryStage.setWidth(900);
primaryStage.setHeight(500);
primaryStage.setScene(scene);
primaryStage.show();

@ -1,6 +1,7 @@
package model;
import javafx.application.Platform;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleStringProperty;
@ -9,7 +10,7 @@ import javafx.collections.*;
import java.util.*;
import static model.Captor.rand;
public class CapteurVirtuel extends Sujet{
public class CapteurVirtuel extends Sujet implements Runnable {
private final UUID id= UUID.randomUUID();
private final StringProperty nom;
@ -20,19 +21,7 @@ public class CapteurVirtuel extends Sujet{
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();
lesCapteurs.addListener((MapChangeListener<? super Integer, ? super Captor>) c -> this.updateData());
}
public DoubleProperty getTempMoyenneProperty(){
@ -56,16 +45,11 @@ public class CapteurVirtuel extends Sujet{
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() {
private void updateData() {
int coef = 0;
double valeurs =0;
for (Map.Entry<Integer, Captor> entry : lesCapteurs.entrySet()){
@ -73,10 +57,29 @@ public class CapteurVirtuel extends Sujet{
valeurs += entry.getKey() * entry.getValue().getTemperature();
}
if (coef==0 || valeurs==0){
return 0.0;
this.tempMoyenne.set(0.0);
}else {
return valeurs / coef;
this.tempMoyenne.set(valeurs/coef);
}
}
@Override
public void run(){
while (true){
Platform.runLater(this::updateData);
try{
Thread.sleep(1);
}
catch (InterruptedException e){
break;
}
}
}
public void startThread(){
Thread threadVirtualCaptor = new Thread(this);
threadVirtualCaptor.setDaemon(true);
threadVirtualCaptor.start();
}
}

@ -19,7 +19,7 @@ public class Captor implements Runnable{
public Captor(String name){
this.name=new SimpleStringProperty(name);
this.temperature=new SimpleDoubleProperty(1.0);
this.temperature=new SimpleDoubleProperty(5.0);
}
public UUID getId()
@ -48,7 +48,7 @@ public class Captor implements Runnable{
while (true){
Platform.runLater(()->setTemperature(rand.nextDouble(80.)-20.));
try{
Thread.sleep(5000);
Thread.sleep(2999);
}
catch (InterruptedException e){
break;

@ -0,0 +1,19 @@
package view;
import console.LView;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import java.awt.event.MouseEvent;
public class MainPage {
@FXML
private javafx.scene.control.Label labelAvecBinding;
@FXML
public void initialize() {
labelAvecBinding.textProperty().set("CPU Temperature");
}
}
Loading…
Cancel
Save