diff --git a/Boutique/ressources/fxml/uc/UC_DetailHabit.fxml b/Boutique/ressources/fxml/uc/UC_DetailHabit.fxml
index 408c5e7..645f6d1 100644
--- a/Boutique/ressources/fxml/uc/UC_DetailHabit.fxml
+++ b/Boutique/ressources/fxml/uc/UC_DetailHabit.fxml
@@ -6,12 +6,28 @@
+
+ xmlns:fx="http://javafx.com/fxml"
+ prefHeight="400.0" prefWidth="600.0">
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Boutique/ressources/fxml/uc/UC_DetailParfum.fxml b/Boutique/ressources/fxml/uc/UC_DetailParfum.fxml
index 9b8f2fd..f90a39a 100644
--- a/Boutique/ressources/fxml/uc/UC_DetailParfum.fxml
+++ b/Boutique/ressources/fxml/uc/UC_DetailParfum.fxml
@@ -11,6 +11,7 @@
xmlns:fx="http://javafx.com/fxml"
prefHeight="400.0" prefWidth="600.0">
+
diff --git a/Boutique/src/Modele/metier/Couleur.java b/Boutique/src/Modele/metier/Couleur.java
index faf4172..a4ef19d 100644
--- a/Boutique/src/Modele/metier/Couleur.java
+++ b/Boutique/src/Modele/metier/Couleur.java
@@ -25,4 +25,14 @@ public class Couleur {
public int getBleue() {
return bleue;
}
+
+ @Override
+ public boolean equals(Object obj){
+ if(obj == null) return false;
+ if(this == obj) return true;
+ if(getClass() != obj.getClass()) return false;
+
+ Couleur other = (Couleur)obj;
+ return vert == other.getVert() && rouge == other.getRouge() && bleue == other.getBleue();
+ }
}
diff --git a/Boutique/src/Modele/metier/Habit.java b/Boutique/src/Modele/metier/Habit.java
index 2a6becf..9603456 100644
--- a/Boutique/src/Modele/metier/Habit.java
+++ b/Boutique/src/Modele/metier/Habit.java
@@ -10,6 +10,13 @@ public class Habit extends Produit{
private List couleurs;
+ public static final String PROP_ADD_COULEUR = "ajout_couleur";
+ public static final String PROP_REMOVE_COULEUR = "suppression_couleur";
+
+ public static final String PROP_ADD_TAILLE = "ajout_taille";
+
+ public static final String PROP_REMOVE_TAILLE = "suppression_taille";
+
public Habit(String nom, int prix) {
super(nom, prix);
taillesEnStock = new ArrayList<>();
@@ -18,18 +25,25 @@ public class Habit extends Produit{
public void ajouterTaille(Taille taille){
taillesEnStock.add(taille);
+ int index = taillesEnStock.size() - 1;
+ support.fireIndexedPropertyChange(PROP_ADD_TAILLE, index, null, taille);
}
public void ajouterCouleur(int vert, int rouge, int bleue){
- couleurs.add(new Couleur(vert, rouge, bleue));
+ Couleur couleur = new Couleur(vert, rouge, bleue);
+ couleurs.add(couleur);
+ int index = couleurs.size() - 1;
+ support.fireIndexedPropertyChange(PROP_ADD_COULEUR, index, null, couleur);
}
public void supprimerTaille(Taille taille){
taillesEnStock.remove(taille);
+ support.firePropertyChange(PROP_REMOVE_TAILLE, taille, null);
}
public void supprimerCouleur(Couleur couleur){
- taillesEnStock.remove(couleur);
+ couleurs.remove(couleur);
+ support.firePropertyChange(PROP_REMOVE_COULEUR, couleur, null);
}
public List getTaillesEnStock() {
diff --git a/Boutique/src/data/chargement/Stub.java b/Boutique/src/data/chargement/Stub.java
index d2def8b..7c10647 100644
--- a/Boutique/src/data/chargement/Stub.java
+++ b/Boutique/src/data/chargement/Stub.java
@@ -18,11 +18,14 @@ public class Stub implements Chargeur{
p1.ajouterTaille(Taille.XL);
p1.ajouterTaille(Taille.L);
p1.ajouterTaille(Taille.XS);
+ p1.ajouterCouleur(0,220,120);
+ p1.ajouterCouleur(50,0,5);
Habit p2 = new Habit("Gants", 15);
p2.ajouterTaille(Taille.XL);
Habit p3 = new Habit("Chemise", 22);
+ p3.ajouterCouleur(0,255,0);
Habit p4 = new Habit("Chaussure", 100);
p4.ajouterTaille(Taille.S);
diff --git a/Boutique/src/view/MainWindow.java b/Boutique/src/view/MainWindow.java
index 3d8fbbf..5ccc4be 100644
--- a/Boutique/src/view/MainWindow.java
+++ b/Boutique/src/view/MainWindow.java
@@ -1,5 +1,6 @@
package view;
+import Modele.metier.Habit;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
@@ -13,8 +14,10 @@ import javafx.util.StringConverter;
import javafx.util.converter.IntegerStringConverter;
import javafx.util.converter.NumberStringConverter;
import view.cellules.CelluleProduit;
+import view.uc.UCDetailHabit;
import view.uc.UCDetailParfum;
import view_modele.BoutiqueVM;
+import view_modele.HabitVM;
import view_modele.ParfumVM;
import view_modele.ProduitVM;
@@ -32,15 +35,21 @@ public class MainWindow {
private UCDetailParfum detailParfum;
+ private UCDetailHabit detailHabit;
+
public void initialize(){
boutiqueVM = new BoutiqueVM();
try {
detailParfum = new UCDetailParfum();
detailParfum.setVisibiliy(false);
layoutDetail.getChildren().add(detailParfum);
+ detailHabit = new UCDetailHabit();
+ detailHabit.setVisibiliy(false);
+ layoutDetail.getChildren().add(detailHabit);
} catch (IOException e) {
- new Alert(Alert.AlertType.ERROR, "Erreur lors de la sélection du parfum", ButtonType.OK);
+ new Alert(Alert.AlertType.ERROR, "Erreur", ButtonType.OK).show();
}
+
listeProduit.setItems(boutiqueVM.getListeProduits());
listeProduit.setCellFactory((__) -> new CelluleProduit());
listeProduit.getSelectionModel().selectedItemProperty().addListener((__, oldV, newV) -> {
@@ -48,11 +57,18 @@ public class MainWindow {
if(oldV instanceof ParfumVM){
detailParfum.setVisibiliy(false);
}
+ else if(oldV instanceof HabitVM){
+ detailHabit.setVisibiliy(false);
+ }
}
if(newV != null) {
if(newV instanceof ParfumVM parfumVM){
detailParfum.setVisibiliy(true);
- detailParfum.setProduit(parfumVM);
+ detailParfum.setParfumVM(parfumVM);
+ }
+ else if(newV instanceof HabitVM habitVM){
+ detailHabit.setVisibiliy(true);
+ detailHabit.setHabitVM(habitVM);
}
}
});
diff --git a/Boutique/src/view/cellules/CelluleCouleur.java b/Boutique/src/view/cellules/CelluleCouleur.java
new file mode 100644
index 0000000..b8e189c
--- /dev/null
+++ b/Boutique/src/view/cellules/CelluleCouleur.java
@@ -0,0 +1,37 @@
+package view.cellules;
+
+import javafx.beans.binding.Bindings;
+import javafx.scene.control.Label;
+import javafx.scene.control.ListCell;
+import javafx.scene.layout.BorderPane;
+import javafx.scene.layout.HBox;
+import javafx.scene.paint.Color;
+import javafx.scene.shape.Rectangle;
+import view_modele.CouleurVM;
+
+
+public class CelluleCouleur extends ListCell {
+
+ private BorderPane layout = new BorderPane();
+
+ private Rectangle rectangleCouleur;
+
+ private Label couleur = new Label();
+
+ @Override
+ protected void updateItem(CouleurVM item, boolean empty) {
+ super.updateItem(item, empty);
+ if(!empty){
+ rectangleCouleur = new Rectangle(30,10, Color.rgb(item.getRouge(), item.getVert(), item.getBleue()));
+ couleur.textProperty().bind(Bindings.concat(item.rougeProperty(), ", ", item.vertProperty(), ", ", item.bleueProperty()));
+ layout.setLeft(rectangleCouleur);
+ layout.setCenter(couleur);
+ setGraphic(layout);
+ }
+ else{
+ rectangleCouleur = null;
+ couleur.textProperty().unbind();
+ setGraphic(null);
+ }
+ }
+}
diff --git a/Boutique/src/view/cellules/CelluleTaille.java b/Boutique/src/view/cellules/CelluleTaille.java
new file mode 100644
index 0000000..143687d
--- /dev/null
+++ b/Boutique/src/view/cellules/CelluleTaille.java
@@ -0,0 +1,18 @@
+package view.cellules;
+
+import javafx.scene.control.ListCell;
+import view_modele.TailleVM;
+
+public class CelluleTaille extends ListCell {
+
+ @Override
+ protected void updateItem(TailleVM item, boolean empty) {
+ super.updateItem(item, empty);
+ if(!empty){
+ setText(item.toString());
+ }
+ else{
+ setText("");
+ }
+ }
+}
diff --git a/Boutique/src/view/uc/UCDetailHabit.java b/Boutique/src/view/uc/UCDetailHabit.java
index 2735aec..f626732 100644
--- a/Boutique/src/view/uc/UCDetailHabit.java
+++ b/Boutique/src/view/uc/UCDetailHabit.java
@@ -2,19 +2,40 @@ package view.uc;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
+import javafx.scene.control.ColorPicker;
+import javafx.scene.control.ComboBox;
import javafx.scene.control.ListView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
+import javafx.scene.paint.Color;
+import view.cellules.CelluleCouleur;
+import view.cellules.CelluleTaille;
import view_modele.CouleurVM;
+import view_modele.HabitVM;
+import view_modele.TailleVM;
import java.io.IOException;
public class UCDetailHabit extends VBox {
@FXML
- private ListView listeCouleurs;
+ private ListView listeCouleurs = new ListView<>();
- private UCCommun ucCommun;
+ @FXML
+ private HBox layout_UCCommun;
+
+ @FXML
+ private ColorPicker colorPicker;
+
+ @FXML
+ private ComboBox comboTaille;
+
+ @FXML
+ private ListView listeTailles = new ListView<>();
+
+ private UCCommun uc_commun;
+
+ private HabitVM habitVM;
public UCDetailHabit() throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/uc/UC_DetailHabit.fxml"));
@@ -22,7 +43,68 @@ public class UCDetailHabit extends VBox {
loader.setRoot(this);
loader.load();
- ucCommun = new UCCommun();
- getChildren().add(ucCommun);
+ uc_commun = new UCCommun();
+ layout_UCCommun.getChildren().add(uc_commun);
+
+ listeCouleurs.setCellFactory(__ -> new CelluleCouleur());
+ listeTailles.setCellFactory(__ -> new CelluleTaille());
+ }
+
+ public void setHabitVM(HabitVM habitVM){
+ this.habitVM = habitVM;
+ bind();
+ }
+
+ private void bind(){
+ unbind();
+ uc_commun.bind(this.habitVM);
+ listeCouleurs.itemsProperty().bind(this.habitVM.listeCouleursProperty());
+ listeTailles.itemsProperty().bind(this.habitVM.listeTaillesProperty());
+ comboTaille.setItems(habitVM.getToutesLesTailles());
+ }
+
+ private void unbind(){
+ if(this.habitVM != null){
+ uc_commun.unbind(habitVM);
+ listeCouleurs.itemsProperty().unbind();
+ listeTailles.itemsProperty().unbind();
+ comboTaille.setItems(null);
+ }
+ }
+
+ public void setVisibiliy(boolean visible){
+ if(!visible){
+ unbind();
+ }
+ super.setVisible(visible);
}
+
+ @FXML
+ private void ajouterCouleur(){
+ Color color = colorPicker.getValue();
+ habitVM.ajouterCouleur((int)(color.getGreen()*255), (int)(color.getRed()*255), (int)(color.getBlue()*255));
+ }
+
+ @FXML
+ private void supprimerCouleur(){
+ habitVM.supprimerCouleur(listeCouleurs.getSelectionModel().getSelectedItem());
+ }
+
+ @FXML
+ private void deselectionner(){
+ listeCouleurs.getSelectionModel().select(-1);
+ listeTailles.getSelectionModel().select(-1);
+ }
+
+ @FXML
+ private void ajouterTaille(){
+ habitVM.ajouterTaille(comboTaille.getValue());
+ }
+
+ @FXML
+ private void supprimerTaille(){
+ habitVM.supprimerTaille(listeTailles.getSelectionModel().getSelectedItem());
+ }
+
+
}
diff --git a/Boutique/src/view/uc/UCDetailParfum.java b/Boutique/src/view/uc/UCDetailParfum.java
index 78016b0..7656273 100644
--- a/Boutique/src/view/uc/UCDetailParfum.java
+++ b/Boutique/src/view/uc/UCDetailParfum.java
@@ -4,6 +4,7 @@ import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
+import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import view_modele.ParfumVM;
@@ -19,6 +20,9 @@ public class UCDetailParfum extends VBox {
@FXML
private TextField nouvelleFragrance;
+ @FXML
+ private HBox layout_UCCommun;
+
private UCCommun ucCommun;
public UCDetailParfum() throws IOException {
@@ -28,18 +32,18 @@ public class UCDetailParfum extends VBox {
loader.load();
ucCommun = new UCCommun();
- getChildren().add(ucCommun);
+ layout_UCCommun.getChildren().add(ucCommun);
}
- public void setProduit(ParfumVM parfum){
+ public void setParfumVM(ParfumVM parfum){
this.parfumVM = parfum;
- bind(parfum);
+ bind();
}
- private void bind(ParfumVM parfum){
+ private void bind(){
unbind();
- ucCommun.bind(parfum);
- listeFragrances.itemsProperty().bind(parfum.listeFragrancesProperty());
+ ucCommun.bind(this.parfumVM);
+ listeFragrances.itemsProperty().bind(this.parfumVM.listeFragrancesProperty());
}
private void unbind(){
@@ -70,7 +74,7 @@ public class UCDetailParfum extends VBox {
@FXML
private void deselectionner(){
- //parfum.addFragrance(nouvelleFragrance.getText());
+ listeFragrances.getSelectionModel().select(-1);
}
diff --git a/Boutique/src/view_modele/CouleurVM.java b/Boutique/src/view_modele/CouleurVM.java
new file mode 100644
index 0000000..ee05978
--- /dev/null
+++ b/Boutique/src/view_modele/CouleurVM.java
@@ -0,0 +1,52 @@
+package view_modele;
+
+import Modele.metier.Couleur;
+import javafx.beans.property.IntegerProperty;
+import javafx.beans.property.SimpleIntegerProperty;
+
+import javax.swing.plaf.IconUIResource;
+
+public class CouleurVM {
+
+ private Couleur modele;
+
+ private IntegerProperty vert = new SimpleIntegerProperty();
+ public int getVert() { return vert.get(); }
+ public IntegerProperty vertProperty() { return vert; }
+ public void setVert(int vert) { this.vert.set(vert); }
+
+ private IntegerProperty rouge = new SimpleIntegerProperty();
+ public int getRouge() { return rouge.get(); }
+ public IntegerProperty rougeProperty() { return rouge; }
+ public void setRouge(int rouge) { this.rouge.set(rouge); }
+
+ private IntegerProperty bleue = new SimpleIntegerProperty();
+ public int getBleue() { return bleue.get(); }
+ public IntegerProperty bleueProperty() { return bleue; }
+ public void setBleue(int bleue) { this.bleue.set(bleue); }
+
+ public CouleurVM(Couleur modele) {
+ this.modele = modele;
+ setVert(modele.getVert());
+ setRouge(modele.getRouge());
+ setBleue(modele.getBleue());
+ }
+
+ public CouleurVM(int vert, int rouge, int bleue){
+ this(new Couleur(vert, rouge, bleue));
+ }
+
+ public Couleur getModele() {
+ return modele;
+ }
+
+ @Override
+ public boolean equals(Object obj){
+ if(obj == null) return false;
+ if(this == obj) return true;
+ if(getClass() != obj.getClass()) return false;
+
+ CouleurVM other = (CouleurVM)obj;
+ return modele.equals(other.modele);
+ }
+}
diff --git a/Boutique/src/view_modele/HabitVM.java b/Boutique/src/view_modele/HabitVM.java
index b038fdf..4441cdf 100644
--- a/Boutique/src/view_modele/HabitVM.java
+++ b/Boutique/src/view_modele/HabitVM.java
@@ -1,12 +1,38 @@
package view_modele;
+import Modele.metier.Couleur;
import Modele.metier.Habit;
import Modele.metier.Produit;
+import Modele.metier.Taille;
+import javafx.beans.property.ListProperty;
+import javafx.beans.property.SimpleListProperty;
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+import java.beans.IndexedPropertyChangeEvent;
import java.beans.PropertyChangeEvent;
+import java.util.ArrayList;
+import java.util.List;
public class HabitVM extends ProduitVM {
+ private ObservableList couleurObs = FXCollections.observableArrayList();
+
+ private ListProperty listeCouleurs = new SimpleListProperty<>(couleurObs);
+
+ public ObservableList getListeCouleurs() { return listeCouleurs.get(); }
+ public ListProperty listeCouleursProperty() { return listeCouleurs; }
+ public void setListeCouleurs(ObservableList listeCouleurs) { this.listeCouleurs.set(listeCouleurs); }
+
+
+ private ObservableList taillesObs = FXCollections.observableArrayList();
+
+ private ListProperty listeTailles = new SimpleListProperty<>(taillesObs);
+
+ public ObservableList getListeTailles() { return listeTailles.get(); }
+ public ListProperty listeTaillesProperty() { return listeTailles; }
+ public void setListeTailles(ObservableList listeTailles) { this.listeTailles.set(listeTailles); }
+
public HabitVM(String nom, int prix){
this(new Habit(nom, prix));
@@ -16,10 +42,49 @@ public class HabitVM extends ProduitVM {
this.modele = produit;
setNom(modele.getNom());
setPrix(modele.getPrix());
+
+ for(Couleur c : ((Habit)modele).getCouleurs()){
+ couleurObs.add(new CouleurVM(c));
+ }
+ taillesObs.addAll(TailleVMTailleConverter.toTaillesVM(((Habit) modele).getTaillesEnStock()));
+
+ modele.addListener(this);
+ }
+
+ public void ajouterCouleur(int vert, int rouge, int bleue){
+ ((Habit)modele).ajouterCouleur(vert, rouge, bleue);
+ }
+
+ public void supprimerCouleur(CouleurVM couleur){
+ ((Habit)modele).supprimerCouleur(couleur.getModele());
+ }
+
+ public void ajouterTaille(TailleVM taille){
+ ((Habit)modele).ajouterTaille(TailleVMTailleConverter.toTaille(taille));
+ }
+
+ public void supprimerTaille(TailleVM taille){
+ ((Habit)modele).supprimerTaille(TailleVMTailleConverter.toTaille(taille));
}
@Override
public void propertyChange(PropertyChangeEvent evt) {
+ switch (evt.getPropertyName()){
+ case Habit.PROP_ADD_COULEUR -> couleurObs.add(((IndexedPropertyChangeEvent)evt).getIndex(), new CouleurVM((Couleur)evt.getNewValue()));
+ case Habit.PROP_REMOVE_COULEUR -> couleurObs.remove((new CouleurVM((Couleur)evt.getOldValue())));
+ case Habit.PROP_ADD_TAILLE -> taillesObs.add(((IndexedPropertyChangeEvent)evt).getIndex(),TailleVMTailleConverter.toTailleVM((Taille)evt.getNewValue()));
+ case Habit.PROP_REMOVE_TAILLE -> taillesObs.remove(TailleVMTailleConverter.toTailleVM((Taille)evt.getOldValue()));
+ }
+ }
+
+ public ObservableList getToutesLesTailles(){
+ ObservableList ans =FXCollections.observableArrayList();
+ ans.add(TailleVM.XS);
+ ans.add(TailleVM.S);
+ ans.add(TailleVM.M);
+ ans.add(TailleVM.L);;
+ ans.add(TailleVM.XL);
+ return ans;
}
}
diff --git a/Boutique/src/view_modele/TailleVM.java b/Boutique/src/view_modele/TailleVM.java
new file mode 100644
index 0000000..8841019
--- /dev/null
+++ b/Boutique/src/view_modele/TailleVM.java
@@ -0,0 +1,10 @@
+package view_modele;
+
+public enum TailleVM {
+
+ XS,
+ S,
+ M,
+ L,
+ XL
+}
diff --git a/Boutique/src/view_modele/TailleVMTailleConverter.java b/Boutique/src/view_modele/TailleVMTailleConverter.java
new file mode 100644
index 0000000..cac08b3
--- /dev/null
+++ b/Boutique/src/view_modele/TailleVMTailleConverter.java
@@ -0,0 +1,53 @@
+package view_modele;
+
+import Modele.metier.Taille;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TailleVMTailleConverter {
+
+ public static Taille toTaille(TailleVM taille){
+ Taille ans = null;
+ switch (taille){
+ case XS -> ans = Taille.XS;
+ case S -> ans = Taille.S;
+ case M -> ans = Taille.M;
+ case L -> ans = Taille.L;
+ case XL -> ans = Taille.XL;
+ }
+
+ return ans;
+ }
+
+ public static List toTailles(List tailles){
+ List ans = new ArrayList<>();
+ for(var taille : tailles){
+ ans.add(toTaille(taille));
+ }
+
+ return ans;
+ }
+
+ public static TailleVM toTailleVM(Taille taille){
+ TailleVM ans = null;
+ switch (taille){
+ case XS -> ans = TailleVM.XS;
+ case S -> ans = TailleVM.S;
+ case M -> ans = TailleVM.M;
+ case L -> ans = TailleVM.L;
+ case XL -> ans = TailleVM.XL;
+ }
+
+ return ans;
+ }
+
+ public static List toTaillesVM(List tailles){
+ List ans = new ArrayList<>();
+ for(var taille : tailles){
+ ans.add(toTailleVM(taille));
+ }
+
+ return ans;
+ }
+}