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.control.TreeView?>
<?import javafx.scene.layout.AnchorPane?> <?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" <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"> prefWidth="600.0" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children> <children>
@ -11,6 +13,8 @@
<Label fx:id="idLabel" layoutX="400.0" layoutY="27.0" text="ID: " /> <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="nameLabel" layoutX="400.0" layoutY="57.0" text="Name: " />
<Label fx:id="temperatureLabel" layoutX="400.0" layoutY="87.0" text="Temperature: " /> <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> </children>
</AnchorPane> </AnchorPane>

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

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

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

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