Compare commits

...

12 Commits

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

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,25 +1,21 @@
package launcher;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Group;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;
import javafx.application.Platform;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.control.TreeItem;
import javafx.stage.Stage;
import model.Capteur;
import model.*;
import view.CapteurView;
import view.ImageCtrlView;
import view.ThermostatView;
import view.TreeViewCtrl;
import java.io.IOException;
import java.net.URL;
import java.util.Random;
import java.util.ResourceBundle;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Launch extends Application {
public static void main(String[] args) {
@ -28,17 +24,40 @@ public class Launch extends Application {
@Override
public void start(Stage primaryStage) throws IOException, InterruptedException {
Capteur captor = new Capteur(1,"CapteurIncroyable", 15);
/*Stage thermostatStage = new Stage();
CapteurView capteurView = new ImageCtrlView(captor,"view/Image.fxml","mon titre");
ThermostatView thermostatView = new ThermostatView(captor,"view/Thermostat.fxml","mon titre");
// Creation des capteurs
UnitCapteur captorC = new UnitCapteur(new SimpleStringProperty("1"),new SimpleStringProperty("Capteur CPU"),new StrategyCPU());
UnitCapteur captorR = new UnitCapteur(new SimpleStringProperty("2"),new SimpleStringProperty("Capteur Random"),new StrategyRandom());
CapteurVirtuel captorV = new CapteurVirtuel(new SimpleStringProperty("3"),new SimpleStringProperty("Capteur Virtuel"));
Random random = new Random();
// Ajout des capteurs dans la collections du capteur virtuel
captorV.addCapteur(captorC,1);
captorV.addCapteur(captorR,1);
for (Map.Entry<CapteurAbstrait, Integer> entry : captorV.getCapteurs().entrySet()) {
CapteurAbstrait c = entry.getKey();
c.genTemp();
}
captorV.genTemp();
ArrayList<CapteurAbstrait> capteurs = new ArrayList<>();
capteurs.add(captorC);
capteurs.add(captorR);
capteurs.add(captorV);
Stage thermostatStage = new Stage();
TreeViewCtrl treeViewCtrl = new TreeViewCtrl(capteurs,"view/TreeView.fxml","treeView");
Thread t = new Thread() {
public void run() {
while (true) {
captor.setTemp(random.nextInt(30));
Platform.runLater(() -> {
capteurs.forEach(c -> {
if(c instanceof UnitCapteur uc && uc.isGenTemp()){
uc.genTemp();
}
});
capteurs.forEach(c -> {
if(c instanceof CapteurVirtuel vc){
vc.genTemp();
}});
});
try {
sleep(1000);
} catch (InterruptedException e) {
@ -47,7 +66,8 @@ public class Launch extends Application {
}
}
};
t.start();*/
t.start();
treeViewCtrl.show();
}
}

@ -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);
}

@ -1,13 +1,9 @@
package view;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import model.Capteur;
import javafx.scene.input.MouseEvent;
import javafx.event.EventHandler;
import model.CapteurAbstrait;
import model.StrategyRandom;
import java.io.IOException;
@ -16,14 +12,14 @@ public abstract class CapteurView extends FXMLView {
@FXML
Button myBtn;
protected Capteur capteur;
protected CapteurAbstrait capteur;
public CapteurView(Capteur capteur,String url, String title) throws IOException {
public CapteurView(CapteurAbstrait capteur, String url, String title) throws IOException {
super(url,title);
this.setCapteur(capteur);
}
public void setCapteur(Capteur capteur) {
public void setCapteur(CapteurAbstrait capteur) {
this.capteur = capteur;
}

@ -16,6 +16,5 @@ public class FXMLView extends Stage {
Parent root = fxmlLoader.load();
Scene scene = new Scene(root);
setScene(scene);
show();
}
}

@ -1,16 +1,11 @@
package view;
import javafx.application.Platform;
import javafx.beans.Observable;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import model.Capteur;
import model.CapteurAbstrait;
import model.StrategyRandom;
import java.io.IOException;
import java.io.InputStream;
@ -20,18 +15,18 @@ public class ImageCtrlView extends CapteurView{
Class<?> clazz = this.getClass();
InputStream input;
protected Capteur capteur;
protected CapteurAbstrait capteur;
@FXML
ImageView imageview;
public ImageCtrlView(Capteur capteur, String url, String title) throws IOException {
public ImageCtrlView(CapteurAbstrait capteur, String url, String title) throws IOException {
super(capteur,url,title);
this.capteur = capteur;
myBtn.setOnAction(e -> Platform.exit());
changeImage();
}
private void changeImage() throws IOException {
public void changeImage() throws IOException {
if (this.capteur.getTemp().getValue() > 25){
input = clazz.getResourceAsStream("/images/sun.png");
imageview.setImage(new Image(input));
@ -51,11 +46,13 @@ public class ImageCtrlView extends CapteurView{
Platform.exit();
}
public void initialize() {
/*try {
changeImage();
} catch (IOException e) {
throw new RuntimeException(e);
}*/
public void initialize(CapteurAbstrait capteur) {
/*capteur.getTemp().addListener((observable, oldValue, newValue) -> {
try {
changeImage();
} catch (IOException e) {
throw new RuntimeException(e);
}
});*/
}
}

@ -4,7 +4,8 @@ import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory;
import model.Capteur;
import model.CapteurAbstrait;
import model.StrategyRandom;
import java.io.IOException;
@ -14,18 +15,18 @@ public class ThermostatView extends CapteurView{
@FXML
Spinner<Double> spin;
protected Capteur capteur;
protected CapteurAbstrait capteur;
public ThermostatView(Capteur capteur, String url, String title) throws IOException {
public ThermostatView(CapteurAbstrait capteur, String url, String title) throws IOException {
super(capteur,url,title);
this.capteur=capteur;
this.spin.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0d,100d));
this.spin.getValueFactory().valueProperty().bindBidirectional(this.capteur.getTemp());
myBtn.setOnAction(e -> Platform.exit());
}
public void initialize() {
SpinnerValueFactory valueFactory = new SpinnerValueFactory.DoubleSpinnerValueFactory(capteur.getTemp().getValue(),capteur.getTemp().getValue(), capteur.getTemp().getValue());
spin.setValueFactory(valueFactory);
}
}

@ -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…
Cancel
Save