|
|
@ -7,19 +7,23 @@ import javafx.beans.value.ChangeListener;
|
|
|
|
import javafx.beans.value.ObservableValue;
|
|
|
|
import javafx.beans.value.ObservableValue;
|
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
import javafx.collections.ObservableList;
|
|
|
|
import javafx.collections.ObservableList;
|
|
|
|
|
|
|
|
import javafx.event.ActionEvent;
|
|
|
|
import javafx.event.Event;
|
|
|
|
import javafx.event.Event;
|
|
|
|
import javafx.event.EventHandler;
|
|
|
|
import javafx.event.EventHandler;
|
|
|
|
import javafx.event.EventType;
|
|
|
|
import javafx.event.EventType;
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
import javafx.scene.control.*;
|
|
|
|
import javafx.scene.control.*;
|
|
|
|
|
|
|
|
import javafx.scene.control.cell.PropertyValueFactory;
|
|
|
|
|
|
|
|
import javafx.scene.layout.VBox;
|
|
|
|
import javafx.scene.text.Text;
|
|
|
|
import javafx.scene.text.Text;
|
|
|
|
import javafx.util.converter.NumberStringConverter;
|
|
|
|
import javafx.util.converter.NumberStringConverter;
|
|
|
|
import modele.Capteur;
|
|
|
|
import modele.*;
|
|
|
|
import modele.CapteurVirtuel;
|
|
|
|
|
|
|
|
import modele.CpuCapteur;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static java.lang.Float.parseFloat;
|
|
|
|
|
|
|
|
|
|
|
|
public class TreeViewCapteur extends FxmlWindow {
|
|
|
|
public class TreeViewCapteur extends FxmlWindow {
|
|
|
|
|
|
|
|
|
|
|
@ -31,61 +35,85 @@ public class TreeViewCapteur extends FxmlWindow {
|
|
|
|
private Text id;
|
|
|
|
private Text id;
|
|
|
|
@FXML
|
|
|
|
@FXML
|
|
|
|
private TextField temperature;
|
|
|
|
private TextField temperature;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
|
|
|
private VBox vBox;
|
|
|
|
|
|
|
|
private TableView<Capteur> tableView;
|
|
|
|
|
|
|
|
private Button changeToCpu;
|
|
|
|
|
|
|
|
private Button changeToRandom;
|
|
|
|
private ObservableList<Capteur> lesCapteurs;
|
|
|
|
private ObservableList<Capteur> lesCapteurs;
|
|
|
|
|
|
|
|
|
|
|
|
public TreeViewCapteur(ObservableList<Capteur> lesCapteurs, String url, String title) throws IOException {
|
|
|
|
public TreeViewCapteur(ObservableList<Capteur> lesCapteurs, String url, String title) throws IOException {
|
|
|
|
super(url, title);
|
|
|
|
super(url, title);
|
|
|
|
this.lesCapteurs = lesCapteurs;
|
|
|
|
this.lesCapteurs = lesCapteurs;
|
|
|
|
|
|
|
|
changeToCpu = new Button("Change to CPU");
|
|
|
|
|
|
|
|
changeToRandom = new Button("Change to Random");
|
|
|
|
|
|
|
|
|
|
|
|
TreeItem<Capteur> root = new TreeItem<>();
|
|
|
|
TreeItem<Capteur> root = new TreeItem<>();
|
|
|
|
tree.setRoot(root);
|
|
|
|
tree.setRoot(root);
|
|
|
|
tree.setShowRoot(false);
|
|
|
|
tree.setShowRoot(false);
|
|
|
|
for (Capteur capteur : lesCapteurs) {
|
|
|
|
tree.setCellFactory(capteurTreeView -> new TreeCell<>() {
|
|
|
|
TreeItem<Capteur> item = new TreeItem<>(capteur);
|
|
|
|
|
|
|
|
addTreeItem(item);
|
|
|
|
|
|
|
|
root.getChildren().add(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void addTreeItem(TreeItem<Capteur> cap) {
|
|
|
|
|
|
|
|
if (cap.getValue() instanceof CapteurVirtuel) {
|
|
|
|
|
|
|
|
for (Capteur capteur : ((CapteurVirtuel) cap.getValue()).getLesCapteurs().values()) {
|
|
|
|
|
|
|
|
TreeItem<Capteur> item = new TreeItem<>(capteur);
|
|
|
|
|
|
|
|
addTreeItem(item);
|
|
|
|
|
|
|
|
cap.getChildren().add(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void initialize() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tree.setCellFactory(capteurTreeView -> {
|
|
|
|
|
|
|
|
TreeCell<Capteur> tc = new TreeCell<>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void updateItem(Capteur item, boolean empty) {
|
|
|
|
protected void updateItem(Capteur item, boolean empty) {
|
|
|
|
super.updateItem(item, empty);
|
|
|
|
super.updateItem(item, empty);
|
|
|
|
if (!empty && item!=null) {
|
|
|
|
if (!empty) {
|
|
|
|
textProperty().bindBidirectional(item.nomProperty());
|
|
|
|
textProperty().bind(item.nomProperty());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
textProperty().unbind();
|
|
|
|
textProperty().unbind();
|
|
|
|
//setText("");
|
|
|
|
setText("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return tc;
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
for (Capteur capteur : lesCapteurs) {
|
|
|
|
|
|
|
|
root.getChildren().add(capteur.accept(new TreeViewVisitor()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tableView = new TableView<>();
|
|
|
|
|
|
|
|
TableColumn<Capteur, String> nameCol = new TableColumn<>("Nom");
|
|
|
|
|
|
|
|
TableColumn<Capteur, Float> tempCol = new TableColumn<>("Température");
|
|
|
|
|
|
|
|
nameCol.setCellValueFactory(new PropertyValueFactory<>("nom"));
|
|
|
|
|
|
|
|
tempCol.setCellValueFactory(new PropertyValueFactory<>("temperature"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tableView.getColumns().addAll(nameCol, tempCol);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void initialize() {
|
|
|
|
|
|
|
|
|
|
|
|
tree.getSelectionModel().selectedItemProperty().addListener((observableValue, old, newV) -> {
|
|
|
|
tree.getSelectionModel().selectedItemProperty().addListener((observableValue, old, newV) -> {
|
|
|
|
if (old != null) {
|
|
|
|
if (old != null) {
|
|
|
|
name.textProperty().unbindBidirectional(old.getValue().nomProperty());
|
|
|
|
name.textProperty().unbindBidirectional(old.getValue().nomProperty());
|
|
|
|
id.textProperty().unbindBidirectional(old.getValue().idProperty());
|
|
|
|
id.textProperty().unbindBidirectional(old.getValue().idProperty());
|
|
|
|
temperature.textProperty().unbindBidirectional(old.getValue().temperatureProperty());
|
|
|
|
temperature.textProperty().unbindBidirectional(old.getValue().temperatureProperty());
|
|
|
|
|
|
|
|
if (old.getValue() instanceof CapteurVirtuel) {
|
|
|
|
|
|
|
|
tableView.getItems().removeAll(((CapteurVirtuel) old.getValue()).getLesCapteurs().values());
|
|
|
|
|
|
|
|
vBox.getChildren().remove(tableView);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
changeToCpu.setOnAction(null);
|
|
|
|
|
|
|
|
changeToRandom.setOnAction(null);
|
|
|
|
|
|
|
|
vBox.getChildren().removeAll(changeToCpu, changeToRandom);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (newV != null) {
|
|
|
|
if (newV != null) {
|
|
|
|
name.textProperty().bindBidirectional(newV.getValue().nomProperty());
|
|
|
|
name.textProperty().bindBidirectional(newV.getValue().nomProperty());
|
|
|
|
id.textProperty().bindBidirectional(newV.getValue().idProperty());
|
|
|
|
id.textProperty().bindBidirectional(newV.getValue().idProperty());
|
|
|
|
temperature.textProperty().bindBidirectional(newV.getValue().temperatureProperty(), new NumberStringConverter());
|
|
|
|
temperature.textProperty().bindBidirectional(newV.getValue().temperatureProperty(), new NumberStringConverter());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (newV.getValue() instanceof CapteurVirtuel) {
|
|
|
|
|
|
|
|
tableView.getItems().addAll(((CapteurVirtuel) newV.getValue()).getLesCapteurs().values());
|
|
|
|
|
|
|
|
vBox.getChildren().add(tableView);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
EventHandler<ActionEvent> eventCpu = e -> {
|
|
|
|
|
|
|
|
((UnitCapteur) newV.getValue()).setCaptorGeneratorStrategy(new CpuGenerator());
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
EventHandler<ActionEvent> eventRandom = e -> {
|
|
|
|
|
|
|
|
((UnitCapteur) newV.getValue()).setCaptorGeneratorStrategy(new RandomGenerator());
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
changeToCpu.setOnAction(eventCpu);
|
|
|
|
|
|
|
|
changeToRandom.setOnAction(eventRandom);
|
|
|
|
|
|
|
|
vBox.getChildren().addAll(changeToCpu, changeToRandom);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|