|
|
@ -13,32 +13,40 @@ import javafx.scene.control.*;
|
|
|
|
import javafx.scene.image.Image;
|
|
|
|
import javafx.scene.image.Image;
|
|
|
|
import javafx.scene.image.ImageView;
|
|
|
|
import javafx.scene.image.ImageView;
|
|
|
|
import javafx.scene.input.MouseEvent;
|
|
|
|
import javafx.scene.input.MouseEvent;
|
|
|
|
import model.CapteurAbstrait;
|
|
|
|
import model.*;
|
|
|
|
import model.CapteurVirtuel;
|
|
|
|
|
|
|
|
import model.TreeItemFactoryVisitor;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class TreeViewCtrl extends FXMLView {
|
|
|
|
public class TreeViewCtrl extends FXMLView {
|
|
|
|
@FXML
|
|
|
|
@FXML
|
|
|
|
private TreeView<CapteurAbstrait> treeView;
|
|
|
|
private TreeView<CapteurAbstrait> treeView;
|
|
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
|
|
|
private Spinner<Double> spinnerTemp;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ArrayList<CapteurAbstrait> capteurAbstraits;
|
|
|
|
private ArrayList<CapteurAbstrait> capteurAbstraits;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TreeViewCtrl(ArrayList<CapteurAbstrait> capteurs, String url, String title) throws IOException {
|
|
|
|
public TreeViewCtrl(ArrayList<CapteurAbstrait> capteurs, String url, String title) throws IOException {
|
|
|
|
super(url,title);
|
|
|
|
super(url,title);
|
|
|
|
this.capteurAbstraits = capteurs;;
|
|
|
|
this.capteurAbstraits = capteurs;
|
|
|
|
|
|
|
|
|
|
|
|
TreeItem<CapteurAbstrait> root = new TreeItem<>();
|
|
|
|
TreeItem<CapteurAbstrait> root = new TreeItem<>();
|
|
|
|
root.setExpanded(true);
|
|
|
|
|
|
|
|
treeView.setShowRoot(false);
|
|
|
|
treeView.setShowRoot(false);
|
|
|
|
|
|
|
|
root.setExpanded(true);
|
|
|
|
|
|
|
|
//treeView.setRoot(root);
|
|
|
|
TreeItemFactoryVisitor treeItemFactoryVisitor = new TreeItemFactoryVisitor();
|
|
|
|
TreeItemFactoryVisitor treeItemFactoryVisitor = new TreeItemFactoryVisitor();
|
|
|
|
|
|
|
|
|
|
|
|
treeView.setVisible(true);
|
|
|
|
treeView.setVisible(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (root != null && treeView != null) {
|
|
|
|
|
|
|
|
treeView.setRoot(root);
|
|
|
|
for (CapteurAbstrait capteur : capteurAbstraits) {
|
|
|
|
for (CapteurAbstrait capteur : capteurAbstraits) {
|
|
|
|
TreeItem<CapteurAbstrait> item = capteur.accept(treeItemFactoryVisitor);
|
|
|
|
TreeItem<CapteurAbstrait> item = capteur.accept(treeItemFactoryVisitor);
|
|
|
|
root.getChildren().add(item);
|
|
|
|
root.getChildren().add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// for(CapteurAbstrait capteur: capteurAbstraits){
|
|
|
|
|
|
|
|
// TreeItem<CapteurAbstrait> item = capteur.accept(treeItemFactoryVisitor);
|
|
|
|
|
|
|
|
// root.getChildren().add(item);
|
|
|
|
|
|
|
|
// }
|
|
|
|
this.initializeCapteur();
|
|
|
|
this.initializeCapteur();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void initializeCapteur() {
|
|
|
|
public void initializeCapteur() {
|
|
|
@ -46,29 +54,26 @@ public class TreeViewCtrl extends FXMLView {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void updateItem(CapteurAbstrait capteur, boolean empty) {
|
|
|
|
protected void updateItem(CapteurAbstrait capteur, boolean empty) {
|
|
|
|
super.updateItem(capteur, empty);
|
|
|
|
super.updateItem(capteur, empty);
|
|
|
|
if(empty){
|
|
|
|
if (empty || capteur == null) {
|
|
|
|
textProperty().unbind();
|
|
|
|
textProperty().unbind();
|
|
|
|
setText("");
|
|
|
|
setText("");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
textProperty().bind(capteur.getNom());
|
|
|
|
textProperty().bind(capteur.getNom());
|
|
|
|
|
|
|
|
String image = "/images/random.png";
|
|
|
|
|
|
|
|
if (capteur.getClass() == CapteurVirtuel.class) {
|
|
|
|
|
|
|
|
image = "/images/virtual.png";
|
|
|
|
|
|
|
|
} else if (capteur.getClass() == UnitCapteur.class && ((UnitCapteur) capteur).getStrategie().getClass() == StrategyCPU.class) {
|
|
|
|
|
|
|
|
image = "/images/cpu.png";
|
|
|
|
|
|
|
|
} else if (capteur.getClass() == UnitCapteur.class && ((UnitCapteur) capteur).getStrategie().getClass() == StrategyRandom.class) {
|
|
|
|
|
|
|
|
image = "/images/random.png";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spinnerTemp.setVisible(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CapteurAbstrait capteur = capteurAbstraits.get(0);
|
|
|
|
setGraphic(new ImageView(new Image(image)) {{
|
|
|
|
capteur.getTemp().addListener((observable, oldValue, newValue) -> {
|
|
|
|
setFitHeight(40);
|
|
|
|
System.out.println("Changement de température: " + oldValue + " est passé à "
|
|
|
|
setFitWidth(40);
|
|
|
|
+ newValue);
|
|
|
|
}});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
SpinnerValueFactory<Double> spinnerValueFactory = new SpinnerValueFactory.DoubleSpinnerValueFactory(-150,1000,capteur.getTemp().getValue(),0.5);
|
|
|
|
|
|
|
|
spinnerTemp.setValueFactory(spinnerValueFactory);
|
|
|
|
|
|
|
|
spinnerTemp.getValueFactory().valueProperty().bindBidirectional(capteur.getTemp());
|
|
|
|
|
|
|
|
capteur.genTemp();
|
|
|
|
|
|
|
|
capteur.setTemp(capteur.getTemp().getValue());
|
|
|
|
|
|
|
|
System.out.println("initialize spinner");
|
|
|
|
|
|
|
|
System.out.println(spinnerTemp.getValueFactory().getValue());
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|