From 4b20ff1984e2807a470c7a4b76d309c16687a2c9 Mon Sep 17 00:00:00 2001
From: Hugo Desmons <hugo.desmons.etu@univ-lille.fr>
Date: Mon, 21 Oct 2024 20:58:39 +0200
Subject: [PATCH] =?UTF-8?q?Modification=20affichage=20ajout=20de=20donn?=
 =?UTF-8?q?=C3=A9e=20Ouverture=20du=20menu=20via=20le=20bouton=20ajout=20s?=
 =?UTF-8?q?pinner=20editable?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 res/stages/add-data-stage.fxml                | 22 ++------
 res/stages/main-stage.fxml                    |  2 +-
 .../controller/AddDataController.java         | 56 ++++++++++++++++++-
 .../controller/MainStageController.java       | 19 ++++++-
 .../sae/classification/view/AddDataView.java  | 45 +++++++++++++++
 5 files changed, 122 insertions(+), 22 deletions(-)
 create mode 100644 src/main/java/fr/univlille/sae/classification/view/AddDataView.java

diff --git a/res/stages/add-data-stage.fxml b/res/stages/add-data-stage.fxml
index 5664fe1..a32cefd 100644
--- a/res/stages/add-data-stage.fxml
+++ b/res/stages/add-data-stage.fxml
@@ -16,38 +16,28 @@
                             <HBox alignment="CENTER" layoutX="10.0" layoutY="109.0" prefHeight="17.0" prefWidth="335.0" spacing="20.0">
                                 <children>
                                     <Label text="Sepal Length" />
-                                    <Spinner />
+                                    <Spinner fx:id="sepalLengthSpinner"/>
                                 </children>
                             </HBox>
                             <HBox alignment="CENTER" layoutX="10.0" layoutY="102.0" prefHeight="17.0" prefWidth="335.0" spacing="20.0">
                                 <children>
                                     <Label text="Sepal Width" />
-                                    <Spinner />
+                                    <Spinner fx:id="sepalWidthSpinner"/>
                                 </children>
                             </HBox>
                             <HBox alignment="CENTER" layoutX="10.0" layoutY="102.0" prefHeight="17.0" prefWidth="335.0" spacing="20.0">
                                 <children>
                                     <Label text="Petal Length" />
-                                    <Spinner />
+                                    <Spinner fx:id="petalLengthSpinner" />
                                 </children>
                             </HBox>
                             <HBox alignment="CENTER" layoutX="10.0" layoutY="17.0" prefHeight="17.0" prefWidth="335.0" spacing="20.0">
                                 <children>
-                                    <Label text="Sepal Width" />
-                                    <Spinner />
-                                </children>
-                            </HBox>
-                            <HBox alignment="CENTER" layoutX="10.0" layoutY="102.0" prefHeight="17.0" prefWidth="335.0" spacing="20.0">
-                                <children>
-                                    <HBox alignment="CENTER" prefHeight="17.0" prefWidth="335.0" spacing="20.0">
-                                        <children>
-                                            <Label text="Variety" />
-                                            <ChoiceBox prefHeight="26.0" prefWidth="137.0" />
-                                        </children>
-                                    </HBox>
+                                    <Label text="Petal Width" />
+                                    <Spinner fx:id="petalWidthSpinner" />
                                 </children>
                             </HBox>
-                            <Button fx:id="confirmAdd" mnemonicParsing="false" text="Valider" />
+                            <Button fx:id="confirmAdd" mnemonicParsing="false" onAction="#validate" text="Valider" />
                         </children></VBox>
                 </children></AnchorPane>
         </Scene>
diff --git a/res/stages/main-stage.fxml b/res/stages/main-stage.fxml
index 89ef337..d322968 100644
--- a/res/stages/main-stage.fxml
+++ b/res/stages/main-stage.fxml
@@ -30,7 +30,7 @@
                      <HBox alignment="CENTER" prefHeight="169.0" prefWidth="691.0" spacing="50.0">
                         <children>
                            <Button fx:id="loadData" mnemonicParsing="false" onAction="#openLoadData" prefHeight="27.0" prefWidth="185.0" text="Charger un jeu de données" />
-                           <Button fx:id="addData" mnemonicParsing="false" prefHeight="26.0" prefWidth="141.0" text="Ajouter une donnée" />
+                           <Button fx:id="addData" mnemonicParsing="false" onAction="#openAddData" prefHeight="26.0" prefWidth="141.0" text="Ajouter une donnée" />
                            <Button fx:id="classifyData" disable="true" mnemonicParsing="false" prefHeight="26.0" prefWidth="157.0" text="Classifier une donnée" />
                         </children>
                      </HBox>
diff --git a/src/main/java/fr/univlille/sae/classification/controller/AddDataController.java b/src/main/java/fr/univlille/sae/classification/controller/AddDataController.java
index d025119..a8b0864 100644
--- a/src/main/java/fr/univlille/sae/classification/controller/AddDataController.java
+++ b/src/main/java/fr/univlille/sae/classification/controller/AddDataController.java
@@ -1,15 +1,67 @@
 package fr.univlille.sae.classification.controller;
 
+import fr.univlille.sae.classification.model.ClassificationModel;
 import javafx.fxml.FXML;
 import javafx.scene.control.Button;
+import javafx.scene.control.Spinner;
+import javafx.scene.control.SpinnerValueFactory;
+import javafx.scene.control.TextFormatter;
 import javafx.stage.Stage;
 
+import java.io.IOException;
+import java.util.function.UnaryOperator;
+
 public class AddDataController {
+
+    @FXML
+    private Stage stage;
+
+    @FXML
+    private Button confirmAdd;
+
+    @FXML
+    private Spinner<Double> sepalLengthSpinner;
+
+    @FXML
+    private Spinner<Double> sepalWidthSpinner;
+
     @FXML
-    Stage stage;
+    private Spinner<Double> petalLengthSpinner;
 
     @FXML
-    Button confirmAdd;
+    private Spinner<Double> petalWidthSpinner;
+
+    @FXML
+    public void initialize() {
+        sepalLengthSpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0.0, 200.0, 3.0,0.1));
+        sepalWidthSpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0.0, 200.0, 3.0, 0.1));
+        petalLengthSpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0.0, 200.0, 3.0, 0.1));
+        petalWidthSpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0.0, 200.0, 3.0, 0.1));
+
+        // Permet d'écrire dans la case du spinners
+        sepalLengthSpinner.setEditable(true);
+        sepalWidthSpinner.setEditable(true);
+        petalLengthSpinner.setEditable(true);
+        petalWidthSpinner.setEditable(true);
+
+
+        confirmAdd.setOnAction(event -> handleConfirmAdd());
+    }
+
+    private void handleConfirmAdd() {
+        double sepalLength = sepalLengthSpinner.getValue();
+        double sepalWidth = sepalWidthSpinner.getValue();
+        double petalLength = petalLengthSpinner.getValue();
+        double petalWidth = petalWidthSpinner.getValue();
+
+        stage.close();
+    }
+
+    public void validate() throws IOException {
+
 
+        ClassificationModel.getClassificationModel().ajouterDonnee(sepalLengthSpinner.getValue(), sepalWidthSpinner.getValue(), petalLengthSpinner.getValue(), petalWidthSpinner.getValue());
+        stage.close();
+    }
 
 }
diff --git a/src/main/java/fr/univlille/sae/classification/controller/MainStageController.java b/src/main/java/fr/univlille/sae/classification/controller/MainStageController.java
index 1088c4e..43599c8 100644
--- a/src/main/java/fr/univlille/sae/classification/controller/MainStageController.java
+++ b/src/main/java/fr/univlille/sae/classification/controller/MainStageController.java
@@ -2,15 +2,16 @@ package fr.univlille.sae.classification.controller;
 
 import fr.univlille.sae.classification.model.ClassificationModel;
 import fr.univlille.sae.classification.view.LoadDataView;
+import fr.univlille.sae.classification.view.AddDataView;
 import javafx.fxml.FXML;
-import javafx.fxml.FXMLLoader;
+
 import javafx.scene.chart.*;
 import javafx.scene.control.Button;
 import javafx.stage.*;
 
-import java.io.File;
+
 import java.io.IOException;
-import java.net.URL;
+
 
 public class MainStageController {
 
@@ -52,6 +53,18 @@ public class MainStageController {
         loadDataView.show();
 
 
+    }
+
+    /**
+     * Ouvre l'interface d'ajout de donnée.
+     * @throws IOException
+     */
+    public void openAddData() throws IOException {
+
+        AddDataView addDataView = new AddDataView(ClassificationModel.getClassificationModel(), stage);
+        addDataView.show();
+
+
     }
 
 
diff --git a/src/main/java/fr/univlille/sae/classification/view/AddDataView.java b/src/main/java/fr/univlille/sae/classification/view/AddDataView.java
new file mode 100644
index 0000000..9d57add
--- /dev/null
+++ b/src/main/java/fr/univlille/sae/classification/view/AddDataView.java
@@ -0,0 +1,45 @@
+package fr.univlille.sae.classification.view;
+
+import fr.univlille.sae.classification.model.ClassificationModel;
+import javafx.fxml.FXMLLoader;
+import javafx.stage.Modality;
+import javafx.stage.Stage;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+public class AddDataView {
+
+    private ClassificationModel model;
+    private Stage owner;
+
+    public AddDataView(ClassificationModel model, Stage owner) {
+        this.model = model;
+        this.owner = owner;
+    }
+
+
+
+    public void show() throws IOException {
+
+        FXMLLoader loader = new FXMLLoader();
+        URL fxmlFileUrl = new File(System.getProperty("user.dir") + File.separator + "res" + File.separator + "stages" + File.separator + "add-data-stage.fxml").toURI().toURL();
+
+        if (fxmlFileUrl == null) {
+            System.out.println("Impossible de charger le fichier fxml");
+            System.exit(-1);
+        }
+        loader.setLocation(fxmlFileUrl);
+        Stage root = loader.load();
+
+        root.setResizable(false);
+        root.initOwner(owner);
+        root.initModality(Modality.APPLICATION_MODAL);
+        root.setTitle("Ajout de donée");
+
+        root.showAndWait();
+
+    }
+
+}
-- 
GitLab