Compare commits
12 Commits
Author | SHA1 | Date |
---|---|---|
|
7ab49665f7 | 3 years ago |
|
095602d809 | 3 years ago |
|
07f91b1b1f | 3 years ago |
|
bcce3deeac | 3 years ago |
|
bc6c5596ea | 3 years ago |
|
ac4ab8f5ba | 3 years ago |
|
ae9c27128c | 3 years ago |
|
041f038b70 | 3 years ago |
|
553ac6d1e9 | 3 years ago |
|
dd7357ee49 | 3 years ago |
|
9b4b0e7180 | 3 years ago |
|
1ff0612e7a | 3 years ago |
After Width: | Height: | Size: 9.4 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 3.7 KiB |
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TreeView?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.control.ComboBox?>
|
||||
<?import javafx.collections.FXCollections?>
|
||||
<?import java.lang.String?>
|
||||
<?import javafx.scene.control.TableView?>
|
||||
<?import javafx.scene.control.ToggleButton?>
|
||||
<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>
|
||||
<TreeView fx:id="treeView" layoutX="20.0" layoutY="27.0" prefHeight="347.0" prefWidth="343.0" />
|
||||
<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" />
|
||||
<ToggleButton fx:id="arretGenTemp" text="On/Off" visible="false" layoutX="400.0" layoutY="147.0"/>
|
||||
<ComboBox fx:id="strategyOptions" layoutX="400.0" layoutY="177.0">
|
||||
<items>
|
||||
<FXCollections fx:factory="observableArrayList">
|
||||
<String fx:value="CPU"></String>
|
||||
<String fx:value="Random"></String>
|
||||
</FXCollections>
|
||||
</items>
|
||||
</ComboBox>
|
||||
<TableView fx:id="sousCapteurs" visible="false" prefHeight="300" prefWidth="300" layoutY="200.0" layoutX="400.0"
|
||||
/>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
@ -1,21 +0,0 @@
|
||||
package model;
|
||||
|
||||
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Capteur extends CapteurAbstrait {
|
||||
|
||||
public Capteur(int id, String nom, double pTemp){
|
||||
super(id,nom,pTemp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectProperty<Double> genTemp() {
|
||||
Random random = new Random();
|
||||
this.setTemp(random.nextInt(30));
|
||||
return this.getTemp();
|
||||
}
|
||||
}
|
@ -1,41 +1,65 @@
|
||||
package model;
|
||||
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class CapteurAbstrait {
|
||||
private int id;
|
||||
private String nom;
|
||||
private ObjectProperty<Double> temp = new SimpleObjectProperty<>();
|
||||
private Property<String> id;
|
||||
private StringProperty nom;
|
||||
private StringProperty displayNom;
|
||||
private ObjectProperty<Double> temp = new SimpleObjectProperty<Double>();
|
||||
private Boolean isGenTemp;
|
||||
|
||||
CapteurAbstrait(int id, String nom, Double temp){
|
||||
CapteurAbstrait(Property<String> id, StringProperty nom){
|
||||
this.id = id;
|
||||
this.nom = nom;
|
||||
this.temp.setValue(temp);
|
||||
this.displayNom = new SimpleStringProperty();
|
||||
this.displayNom.bind(this.nom);
|
||||
this.temp.setValue(0.0);
|
||||
this.isGenTemp = true;
|
||||
}
|
||||
public abstract ObjectProperty<Double> genTemp();
|
||||
public abstract void genTemp();
|
||||
|
||||
public int getId() {
|
||||
/* Getters - Setters */
|
||||
public Property<String> getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
public void setId(Property<String> id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
public StringProperty getNom() {
|
||||
return this.nom;
|
||||
}
|
||||
|
||||
public void setNom(String 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;
|
||||
}
|
||||
|
||||
public void setTemp(int pTemp) {
|
||||
this.temp.set((double)pTemp);
|
||||
public void setTemp(double pTemp) {
|
||||
this.temp.setValue(pTemp);
|
||||
}
|
||||
|
||||
public abstract <T> T accept (Visitor<T> v);
|
||||
|
||||
public Map<CapteurAbstrait, Integer> getCapteurs(){
|
||||
return new HashMap<>();
|
||||
};
|
||||
|
||||
public Boolean isGenTemp() {return this.isGenTemp;};
|
||||
public void setIsGenTemp(boolean b) {this.isGenTemp = b;};
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
GENERATE PARAMETER STRATEGY
|
||||
package model;
|
||||
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class CapteurIntervalle extends CapteurAbstrait{
|
||||
|
||||
Un capteur peut générer une température dont la valeur est aléatoire;
|
||||
Les températures ne pouvant descendre sous un certain seuil, on veut
|
||||
aussi un capteur plus réaliste qui génère des températures dont la valeur
|
||||
est comprise dans un certain intervalle défini à la création (et dont le
|
||||
minimum ne peut être inférieur à 0°K);
|
||||
|
||||
public CapteurIntervalle(int id, String nom, Double minVal, Double maxVal){
|
||||
super(id,nom);
|
||||
// si min inférieur a zero, alors passe a 0
|
||||
if(minVal < 0){
|
||||
minVal = (double) 0;
|
||||
}
|
||||
this.minVal = minVal;
|
||||
this.maxVal = maxVal;
|
||||
}
|
||||
|
||||
private Double minVal;
|
||||
private Double maxVal;
|
||||
@Override
|
||||
public void genTemp() {
|
||||
Random rand = new Random();
|
||||
double randomValue = rand.nextDouble(this.maxVal - this.minVal) + minVal;
|
||||
this.setTemp(randomValue);
|
||||
}
|
||||
}
|
||||
*/
|
@ -0,0 +1,40 @@
|
||||
/*package model;
|
||||
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class CapteurRealiste extends CapteurAbstrait{
|
||||
/*
|
||||
Pour rendre les variations plus réalistes on veut un capteur qui génère des
|
||||
températures dont la variation est bornée en fonction d'un intervalle [-d;+d]
|
||||
et d'une température initiale T (tous deux définis à la création)
|
||||
|
||||
t0 = T
|
||||
ti+1 = ti + random(-d,+d)
|
||||
|
||||
public CapteurRealiste(int id, String nom, double tZero, double borne) {
|
||||
super(id, nom);
|
||||
this.borne = borne;
|
||||
this.tZero = tZero;
|
||||
this.setTemp(tZero);
|
||||
}
|
||||
|
||||
private Double borne;
|
||||
private Double tZero;
|
||||
|
||||
@Override
|
||||
public void genTemp() {
|
||||
Random rand = new Random();
|
||||
|
||||
double randomValue = rand.nextDouble() * 2 * this.borne - this.borne;*/
|
||||
/* rand.nextDouble fait un double entre 0 et 1.
|
||||
* Ensuite on fait * 2*borne pour que l'intervale soit entre 0 et 2*borne.
|
||||
* On soustrait borne après comme ça on a un nombre entre -borne et borne.
|
||||
*/
|
||||
/*
|
||||
double newTemp = this.getTemp().getValue() + randomValue; //tzero + random entre -borne et borne
|
||||
this.setTemp(newTemp);
|
||||
}
|
||||
}
|
||||
*/
|
@ -1,35 +1,47 @@
|
||||
package model;
|
||||
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.Property;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CapteurVirtuel extends CapteurAbstrait {
|
||||
|
||||
private List<CapteurAbstrait> capteurs;
|
||||
private Map<CapteurAbstrait, Integer> capteurs;
|
||||
|
||||
CapteurVirtuel(List<CapteurAbstrait> cs, int id, String nom, Double temp){
|
||||
super(id, nom, temp);
|
||||
this.capteurs = cs;
|
||||
public CapteurVirtuel(Property<String> id, StringProperty nom){
|
||||
super(id, nom);
|
||||
this.capteurs = new HashMap<>();
|
||||
}
|
||||
public void addCapteur(CapteurAbstrait c){
|
||||
capteurs.add(c);
|
||||
public void addCapteur(UnitCapteur c, int p){
|
||||
this.capteurs.put(c,p);
|
||||
}
|
||||
|
||||
public void removeCapteur(CapteurAbstrait c){
|
||||
capteurs.remove(c);
|
||||
public void removeCapteur(UnitCapteur c){
|
||||
this.capteurs.remove(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectProperty<Double> genTemp() {
|
||||
ObjectProperty<Double> avg = new SimpleObjectProperty<>();
|
||||
avg.setValue((double) 0);
|
||||
public <T> T accept(Visitor<T> v){
|
||||
return v.visit(this);
|
||||
}
|
||||
|
||||
for (CapteurAbstrait c: capteurs) {
|
||||
avg.setValue(c.genTemp().getValue() + avg.getValue());
|
||||
public Map<CapteurAbstrait, Integer> getCapteurs(){return this.capteurs;}
|
||||
|
||||
// calcule la temperature moyenne des capteurs sa collection de capteurs
|
||||
public void genTemp() {
|
||||
double sum = 0;
|
||||
int count = 0;
|
||||
for (Map.Entry<CapteurAbstrait, Integer> entry : capteurs.entrySet()) {
|
||||
CapteurAbstrait c = entry.getKey();
|
||||
int p = entry.getValue();
|
||||
sum += c.getTemp().getValue() * p;
|
||||
count += p;
|
||||
}
|
||||
avg.set(avg.getValue()/capteurs.size());
|
||||
return avg;
|
||||
double avg = sum / count;
|
||||
this.setTemp(avg);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package model;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
|
||||
public class StrategyCPU implements StrategyCaptor {
|
||||
|
||||
@Override
|
||||
public double genTemp() {
|
||||
try{
|
||||
String temp = new String(Files.readAllBytes(Paths.get("/sys/class/thermal/thermal_zone0/temp")));
|
||||
double tempCelsius = Double.parseDouble(temp)/1000.0;
|
||||
return tempCelsius;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package model;
|
||||
|
||||
public interface StrategyCaptor {
|
||||
public double genTemp();
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package model;
|
||||
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class StrategyRandom implements StrategyCaptor {
|
||||
|
||||
@Override
|
||||
public double genTemp() {
|
||||
Random random = new Random();
|
||||
return random.nextDouble(30) - 30;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package model;
|
||||
|
||||
import com.sun.source.tree.Tree;
|
||||
import javafx.scene.control.TreeItem;
|
||||
|
||||
public class TreeItemFactoryVisitor implements Visitor<TreeItem<CapteurAbstrait>>{
|
||||
@Override
|
||||
public TreeItem<CapteurAbstrait> visit(UnitCapteur c) {
|
||||
return new TreeItem<>(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeItem<CapteurAbstrait> visit(CapteurVirtuel cv) {
|
||||
TreeItem<CapteurAbstrait> root = new TreeItem<>(cv);
|
||||
root.setExpanded(true);
|
||||
|
||||
for(CapteurAbstrait c : cv.getCapteurs().keySet()){
|
||||
TreeItem<CapteurAbstrait> item = new TreeItem<>(c);
|
||||
if(c.getClass() == CapteurVirtuel.class){
|
||||
item = c.accept(this);
|
||||
} else {
|
||||
item = new TreeItem<>(c);
|
||||
}
|
||||
root.getChildren().add(item);
|
||||
}
|
||||
return root;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
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;
|
||||
|
||||
public UnitCapteur(Property<String> id, StringProperty nom, StrategyCaptor st) {
|
||||
super(id, nom);
|
||||
this.strategie = st;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void genTemp() {
|
||||
this.setTemp(strategie.genTemp());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T accept(Visitor<T> v) {
|
||||
return v.visit(this);
|
||||
}
|
||||
|
||||
public StrategyCaptor getStrategie() {
|
||||
return strategie;
|
||||
}
|
||||
|
||||
public void setStrategy(StrategyCaptor strategie) {
|
||||
this.strategie = strategie;
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package model;
|
||||
|
||||
public interface Visitor<T> {
|
||||
public T visit(UnitCapteur c);
|
||||
public T visit(CapteurVirtuel cv);
|
||||
}
|
@ -0,0 +1,235 @@
|
||||
package view;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import javafx.scene.control.cell.TextFieldTableCell;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.util.converter.IntegerStringConverter;
|
||||
import javafx.util.converter.NumberStringConverter;
|
||||
import model.*;
|
||||
|
||||
import javax.swing.text.LabelView;
|
||||
|
||||
public class TreeViewCtrl extends FXMLView {
|
||||
@FXML
|
||||
private TreeView<CapteurAbstrait> treeView;
|
||||
|
||||
@FXML
|
||||
private Label idLabel;
|
||||
@FXML
|
||||
private Label nameLabel;
|
||||
@FXML
|
||||
private TextField nameTextField;
|
||||
@FXML
|
||||
private Label temperatureLabel;
|
||||
|
||||
@FXML private TableView sousCapteurs;
|
||||
@FXML
|
||||
private ComboBox strategyOptions;
|
||||
@FXML
|
||||
private ToggleButton arretGenTemp;
|
||||
|
||||
private ArrayList<CapteurAbstrait> capteurAbstraits;
|
||||
|
||||
|
||||
public TreeViewCtrl(ArrayList<CapteurAbstrait> capteurs, String url, String title) throws IOException {
|
||||
super(url,title);
|
||||
this.capteurAbstraits = capteurs;
|
||||
|
||||
TreeItem<CapteurAbstrait> root = new TreeItem<>();
|
||||
treeView.setShowRoot(false);
|
||||
root.setExpanded(true);
|
||||
//treeView.setRoot(root);
|
||||
TreeItemFactoryVisitor treeItemFactoryVisitor = new TreeItemFactoryVisitor();
|
||||
|
||||
treeView.setVisible(true);
|
||||
|
||||
if (root != null && treeView != null) {
|
||||
treeView.setRoot(root);
|
||||
for (CapteurAbstrait capteur : capteurAbstraits) {
|
||||
TreeItem<CapteurAbstrait> item = capteur.accept(treeItemFactoryVisitor);
|
||||
root.getChildren().add(item);
|
||||
}
|
||||
}
|
||||
// for(CapteurAbstrait capteur: capteurAbstraits){
|
||||
// TreeItem<CapteurAbstrait> item = capteur.accept(treeItemFactoryVisitor);
|
||||
// root.getChildren().add(item);
|
||||
// }
|
||||
this.initializeCapteur();
|
||||
|
||||
}
|
||||
|
||||
public void initializeCapteur() {
|
||||
treeView.setCellFactory(param -> new TreeCell<CapteurAbstrait>() {
|
||||
@Override
|
||||
protected void updateItem(CapteurAbstrait capteur, boolean empty) {
|
||||
super.updateItem(capteur, empty);
|
||||
if (empty || capteur == null) {
|
||||
textProperty().unbind();
|
||||
setText("");
|
||||
} else {
|
||||
setText(capteur.getNom().getValue());
|
||||
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";
|
||||
}
|
||||
|
||||
setGraphic(new ImageView(new Image(image)) {{
|
||||
setFitHeight(40);
|
||||
setFitWidth(40);
|
||||
}});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void initialize(){
|
||||
strategyOptions.setVisible(false);
|
||||
sousCapteurs.setVisible(false);
|
||||
arretGenTemp.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);
|
||||
}
|
||||
sousCapteurs.getItems().clear();
|
||||
sousCapteurs.getColumns().clear();
|
||||
}
|
||||
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);
|
||||
sousCapteurs.setVisible(false);
|
||||
arretGenTemp.setVisible(true);
|
||||
strategyOptions.setOnAction(event ->{
|
||||
if(strategyOptions.getValue().equals("CPU")){
|
||||
((UnitCapteur) newValue.getValue()).setStrategy(new StrategyCPU());
|
||||
}
|
||||
else if (strategyOptions.getValue().equals("Random")){
|
||||
((UnitCapteur) newValue.getValue()).setStrategy(new StrategyRandom());
|
||||
}
|
||||
if(!newValue.getValue().isGenTemp()){
|
||||
arretGenTemp.setSelected(true);
|
||||
};
|
||||
initializeCapteur();
|
||||
});
|
||||
arretGenTemp.setOnAction(event -> {
|
||||
newValue.getValue().setIsGenTemp(!arretGenTemp.isSelected());
|
||||
});
|
||||
} else if(capteur instanceof CapteurVirtuel){
|
||||
strategyOptions.setVisible(false);
|
||||
sousCapteurs.setVisible(true);
|
||||
arretGenTemp.setVisible(false);
|
||||
ObservableList<CapteurAbstrait> capteurs = FXCollections.observableArrayList(newValue.getValue().getCapteurs().keySet());
|
||||
sousCapteurs.setItems(capteurs);
|
||||
TableColumn<CapteurAbstrait, Object> iconColumn = new TableColumn<>("Icone");
|
||||
iconColumn.setCellFactory(column -> {
|
||||
return new TableCell<CapteurAbstrait, Object>() {
|
||||
@Override
|
||||
protected void updateItem(Object item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (empty) {
|
||||
setGraphic(null);
|
||||
} else {
|
||||
if (getTableRow() != null){
|
||||
CapteurAbstrait capteur = (CapteurAbstrait) getTableRow().getItem();
|
||||
if (capteur instanceof CapteurVirtuel) {
|
||||
ImageView capVirt = new ImageView("images/virtual.png");
|
||||
capVirt.setFitWidth(25);
|
||||
capVirt.setFitHeight(25);
|
||||
setGraphic(capVirt);
|
||||
} else if (capteur instanceof UnitCapteur) {
|
||||
UnitCapteur unitCaptor = (UnitCapteur) capteur;
|
||||
if (unitCaptor.getStrategie() instanceof StrategyCPU) {
|
||||
ImageView capCpu = new ImageView("images/cpu.png");
|
||||
capCpu.setFitWidth(25);
|
||||
capCpu.setFitHeight(25);
|
||||
setGraphic(capCpu);
|
||||
} else if (unitCaptor.getStrategie() instanceof StrategyRandom) {
|
||||
ImageView capRand = new ImageView("images/random.png");
|
||||
capRand.setFitWidth(25);
|
||||
capRand.setFitHeight(25);
|
||||
setGraphic(capRand);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
sousCapteurs.getColumns().add(iconColumn);
|
||||
TableColumn<CapteurAbstrait, Integer> idColumn = new TableColumn<>("id");
|
||||
idColumn.setCellValueFactory(cellData -> new SimpleIntegerProperty(Integer.parseInt(cellData.getValue().getId().getValue())).asObject());
|
||||
sousCapteurs.getColumns().add(idColumn);
|
||||
TableColumn<CapteurAbstrait, String> NameColumn = new TableColumn<>("Nom");
|
||||
NameColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getNom().getValue()));
|
||||
sousCapteurs.getColumns().add(NameColumn);
|
||||
NameColumn.setEditable(true);
|
||||
|
||||
TableColumn<CapteurAbstrait, Integer> poidsColumn = new TableColumn<>("Poids");
|
||||
poidsColumn.setCellValueFactory(cellData -> {
|
||||
CapteurAbstrait captor = cellData.getValue();
|
||||
if (captor != null && newValue.getValue().getCapteurs().get(captor) != null) {
|
||||
return new SimpleIntegerProperty(newValue.getValue().getCapteurs().get(captor)).asObject();
|
||||
} else {
|
||||
return new SimpleObjectProperty<>(null);
|
||||
}
|
||||
});
|
||||
sousCapteurs.getColumns().add(poidsColumn);
|
||||
poidsColumn.setEditable(true);
|
||||
poidsColumn.setCellFactory(TextFieldTableCell.forTableColumn(new IntegerStringConverter()));
|
||||
|
||||
poidsColumn.setOnEditCommit(event -> {
|
||||
CapteurAbstrait capteur2 = event.getRowValue();
|
||||
newValue.getValue().getCapteurs().put(capteur2, event.getNewValue());
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public TreeView<CapteurAbstrait> getTreeView() {
|
||||
return treeView;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue