fixed all display bugs + captor added

multiple-captors
Nicolas FRANCO 2 years ago
parent 07f91b1b1f
commit 095602d809

@ -4,6 +4,8 @@
<?import javafx.scene.control.TreeView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ComboBox?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
prefWidth="600.0" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
@ -11,6 +13,8 @@
<Label fx:id="idLabel" layoutX="400.0" layoutY="27.0" text="ID: " />
<Label fx:id="nameLabel" layoutX="400.0" layoutY="57.0" text="Name: " />
<Label fx:id="temperatureLabel" layoutX="400.0" layoutY="87.0" text="Temperature: " />
<TextField fx:id="nameTextField" layoutX="400.0" layoutY="107.0" />
<ComboBox fx:id="strategyOptions" layoutX="400.0" layoutY="147.0"/>
</children>
</AnchorPane>

@ -53,6 +53,10 @@ public class Launch extends Application {
uc.genTemp();
}
});
capteurs.forEach(c -> {
if(c instanceof UnitCapteur uc){
uc.genTemp();
}});
});
try {
sleep(1000);

@ -5,11 +5,14 @@ import javafx.beans.property.*;
public abstract class CapteurAbstrait {
private Property<String> id;
private StringProperty nom;
private StringProperty displayNom;
private ObjectProperty<Double> temp = new SimpleObjectProperty<Double>();
CapteurAbstrait(Property<String> id, StringProperty nom){
this.id = id;
this.nom = nom;
this.displayNom = new SimpleStringProperty();
this.displayNom.bind(this.nom);
this.temp.setValue(0.0);
}
public abstract void genTemp();
@ -27,9 +30,16 @@ public abstract class CapteurAbstrait {
return this.nom;
}
public StringProperty getDisplayNom() {
return this.displayNom;
}
public void setNom(StringProperty nom) {
this.nom = nom;
}
public void setNom(String nom) {
this.nom.setValue(nom);
}
public ObjectProperty<Double> getTemp() {
return temp;

@ -3,6 +3,8 @@ package model;
import javafx.beans.property.Property;
import javafx.beans.property.StringProperty;
import java.time.temporal.ChronoUnit;
public class UnitCapteur extends CapteurAbstrait{
private StrategyCaptor strategie;

@ -28,8 +28,13 @@ public class TreeViewCtrl extends FXMLView {
@FXML
private Label nameLabel;
@FXML
private TextField nameTextField;
@FXML
private Label temperatureLabel;
@FXML
private ComboBox strategyOptions;
private ArrayList<CapteurAbstrait> capteurAbstraits;
@ -61,6 +66,8 @@ public class TreeViewCtrl extends FXMLView {
}
public void initializeCapteur() {
strategyOptions.getItems().addAll("CPU", "Random");
treeView.setCellFactory(param -> new TreeCell<CapteurAbstrait>() {
@Override
protected void updateItem(CapteurAbstrait capteur, boolean empty) {
@ -69,7 +76,7 @@ public class TreeViewCtrl extends FXMLView {
textProperty().unbind();
setText("");
} else {
textProperty().bind(capteur.getNom());
setText(capteur.getNom().getValue());
String image = "/images/random.png";
if (capteur.getClass() == CapteurVirtuel.class) {
image = "/images/virtual.png";
@ -86,13 +93,38 @@ public class TreeViewCtrl extends FXMLView {
}
}
});
strategyOptions.setVisible(false);
treeView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
if (oldValue != null) {
CapteurAbstrait capteur = oldValue.getValue();
idLabel.textProperty().unbindBidirectional(capteur.getId());
nameLabel.textProperty().unbindBidirectional(capteur.getNom());
temperatureLabel.textProperty().unbind();
if(capteur instanceof UnitCapteur){
strategyOptions.setVisible(false);
}
}
if (newValue != null) {
CapteurAbstrait capteur = newValue.getValue();
if (capteur instanceof UnitCapteur) {
strategyOptions.setVisible(true);
} else {
strategyOptions.setVisible(false);
}
idLabel.textProperty().bindBidirectional(capteur.getId());
nameLabel.textProperty().bindBidirectional(capteur.getNom());
temperatureLabel.textProperty().bind(Bindings.format("%.2f",capteur.getTemp()));
nameTextField.setOnAction(event -> {
capteur.setNom(nameTextField.getText());
});
nameTextField.setText(capteur.getNom().getValue());
capteur.getNom().addListener((obs, oldName, newName) -> {
capteur.setNom(newName);
newValue.setValue(capteur);
});
if(capteur instanceof UnitCapteur){
strategyOptions.setVisible(true);
}
}
});
}

Loading…
Cancel
Save