diff --git a/res/stages/data-view-stage.fxml b/res/stages/data-view-stage.fxml index 315cb877303a7d975b4ac5cf5e19bf23b8e212bf..9f17a8fd5c75ee133bb950bbb475f88f00c6548f 100644 --- a/res/stages/data-view-stage.fxml +++ b/res/stages/data-view-stage.fxml @@ -1,30 +1,36 @@ <?xml version="1.0" encoding="UTF-8"?> -<?import javafx.geometry.*?> -<?import javafx.scene.*?> -<?import javafx.scene.chart.*?> -<?import javafx.scene.control.*?> -<?import javafx.scene.image.*?> -<?import javafx.scene.layout.*?> -<?import javafx.scene.text.*?> -<?import javafx.stage.*?> +<?import javafx.geometry.Insets?> +<?import javafx.scene.Scene?> +<?import javafx.scene.chart.NumberAxis?> +<?import javafx.scene.chart.ScatterChart?> +<?import javafx.scene.control.Button?> +<?import javafx.scene.control.Label?> +<?import javafx.scene.control.ListView?> +<?import javafx.scene.image.Image?> +<?import javafx.scene.image.ImageView?> +<?import javafx.scene.layout.AnchorPane?> +<?import javafx.scene.layout.HBox?> +<?import javafx.scene.layout.VBox?> +<?import javafx.scene.text.Font?> +<?import javafx.stage.Stage?> -<Stage fx:id="stage" xmlns="http://javafx.com/javafx/17.0.12" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fr.univlille.sae.classification.controller.DataStageController"> +<Stage fx:id="stage" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fr.univlille.sae.classification.controller.DataStageController"> <scene> <Scene> <AnchorPane prefHeight="502.0" prefWidth="999.0"> <children> - <VBox prefHeight="513.0" prefWidth="999.0"> + <VBox prefHeight="562.0" prefWidth="999.0"> <children> <Label alignment="CENTER" prefHeight="52.0" prefWidth="999.0" style="-fx-background-color: #105561;" text="Vue de classification de données" textFill="WHITE"> <font> <Font name="System Bold" size="20.0" /> </font></Label> - <HBox prefHeight="463.0" prefWidth="999.0"> + <HBox prefHeight="511.0" prefWidth="999.0"> <children> <VBox prefHeight="459.0" prefWidth="762.0"> <children> - <HBox alignment="TOP_CENTER" prefHeight="462.0" prefWidth="762.0" spacing="5.0"> + <HBox alignment="TOP_CENTER" prefHeight="462.0" prefWidth="760.0" spacing="5.0"> <children> <AnchorPane prefHeight="509.0" prefWidth="688.0"> <children> @@ -60,6 +66,18 @@ </Button> </children> </HBox> + <VBox prefHeight="65.0" prefWidth="801.0"> + <children> + <HBox fx:id="legend" alignment="CENTER" prefHeight="58.0" prefWidth="762.0" spacing="10.0"> + <opaqueInsets> + <Insets /> + </opaqueInsets> + <padding> + <Insets left="2.0" right="2.0" /> + </padding> + </HBox> + </children> + </VBox> </children> </VBox> <VBox prefHeight="470.0" prefWidth="238.0"> diff --git a/res/stages/main-stage.fxml b/res/stages/main-stage.fxml index e867ac83924ee95ffef3b2b01e4cf2d69183734f..37ee5a84d7934efedc54509dd693ece00867c3b5 100644 --- a/res/stages/main-stage.fxml +++ b/res/stages/main-stage.fxml @@ -1,15 +1,21 @@ <?xml version="1.0" encoding="UTF-8"?> -<?import javafx.geometry.*?> -<?import javafx.scene.*?> -<?import javafx.scene.chart.*?> -<?import javafx.scene.control.*?> -<?import javafx.scene.image.*?> -<?import javafx.scene.layout.*?> -<?import javafx.scene.text.*?> -<?import javafx.stage.*?> +<?import javafx.geometry.Insets?> +<?import javafx.scene.Scene?> +<?import javafx.scene.chart.NumberAxis?> +<?import javafx.scene.chart.ScatterChart?> +<?import javafx.scene.control.Button?> +<?import javafx.scene.control.Label?> +<?import javafx.scene.control.ListView?> +<?import javafx.scene.image.Image?> +<?import javafx.scene.image.ImageView?> +<?import javafx.scene.layout.AnchorPane?> +<?import javafx.scene.layout.HBox?> +<?import javafx.scene.layout.VBox?> +<?import javafx.scene.text.Font?> +<?import javafx.stage.Stage?> -<Stage fx:id="stage" xmlns="http://javafx.com/javafx/17.0.12" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fr.univlille.sae.classification.controller.MainStageController"> +<Stage fx:id="stage" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fr.univlille.sae.classification.controller.MainStageController"> <scene> <Scene> <AnchorPane prefHeight="535.0" prefWidth="922.0"> @@ -42,7 +48,14 @@ <Font size="21.0" /> </font> </Label> - <VBox layoutY="345.0" prefHeight="78.0" prefWidth="678.0" /> + <VBox layoutY="345.0" prefHeight="78.0" prefWidth="678.0"> + <children> + <HBox fx:id="legend" alignment="CENTER" prefHeight="100.0" prefWidth="200.0" spacing="10.0"> + <padding> + <Insets left="2.0" right="2.0" /> + </padding> + </HBox> + </children></VBox> </children> <HBox.margin> <Insets left="10.0" /> diff --git a/src/main/java/fr/univlille/sae/classification/controller/DataVisualizationController.java b/src/main/java/fr/univlille/sae/classification/controller/DataVisualizationController.java index 5f5b95e3ce18914d10520e32cc7166bebe345814..b0e8c0630c318b8edd5160cd52e72280cbdd791f 100644 --- a/src/main/java/fr/univlille/sae/classification/controller/DataVisualizationController.java +++ b/src/main/java/fr/univlille/sae/classification/controller/DataVisualizationController.java @@ -7,6 +7,7 @@ import javafx.fxml.FXML; import javafx.scene.chart.NumberAxis; import javafx.scene.chart.ScatterChart; import javafx.scene.control.Label; +import javafx.scene.layout.HBox; import javafx.stage.Stage; public abstract class DataVisualizationController { @@ -18,6 +19,9 @@ public abstract class DataVisualizationController { @FXML Label AxesSelected; + @FXML + HBox legend; + @FXML ScatterChart scatterChart; @@ -143,5 +147,12 @@ public abstract class DataVisualizationController { + public void loadLegend(HBox hbox) { + this.legend.getChildren().clear(); + this.legend.getChildren().addAll(hbox.getChildren()); + } + + + } diff --git a/src/main/java/fr/univlille/sae/classification/model/LoadableData.java b/src/main/java/fr/univlille/sae/classification/model/LoadableData.java index 4aa25be2e34b88f7db8b244d80410cc4299d6e3c..e33aa56df15fe6e6a83e71adecae981d5508889c 100644 --- a/src/main/java/fr/univlille/sae/classification/model/LoadableData.java +++ b/src/main/java/fr/univlille/sae/classification/model/LoadableData.java @@ -3,6 +3,7 @@ package fr.univlille.sae.classification.model; import javafx.scene.paint.Color; import java.util.Map; +import java.util.HashMap; import java.util.Set; /** @@ -12,6 +13,8 @@ public abstract class LoadableData { private static Set<String> classificationTypes; + private static Map<String, Color> classification = new HashMap<>() ; + /** * Constructeur par défaut. */ @@ -32,6 +35,10 @@ public abstract class LoadableData { return classificationTypes; } + public static Map<String, Color> getClassifications() { + return classification; + } + /** * Définit les types de classification disponibles. * @param classificationTypes ensemble de types de classification à définir. diff --git a/src/main/java/fr/univlille/sae/classification/utils/ViewUtil.java b/src/main/java/fr/univlille/sae/classification/utils/ViewUtil.java index b01cc53fa32108c26b3aa4b5db9d95d785b5c069..a0e92fd646fa93b58c4df0fe537e13a53da3292b 100644 --- a/src/main/java/fr/univlille/sae/classification/utils/ViewUtil.java +++ b/src/main/java/fr/univlille/sae/classification/utils/ViewUtil.java @@ -2,14 +2,23 @@ package fr.univlille.sae.classification.utils; import fr.univlille.sae.classification.controller.DataStageController; import fr.univlille.sae.classification.controller.MainStageController; +import fr.univlille.sae.classification.model.ClassificationModel; import fr.univlille.sae.classification.model.LoadableData; +import javafx.scene.chart.ScatterChart; import javafx.scene.chart.XYChart; import javafx.scene.control.ContextMenu; +import javafx.scene.control.Label; import javafx.scene.control.MenuItem; +import javafx.scene.layout.HBox; import javafx.scene.paint.Color; +import javafx.scene.shape.Circle; +import javafx.scene.shape.Rectangle; import javafx.scene.shape.Shape; import javafx.stage.Stage; +import java.util.HashMap; +import java.util.Map; + /** * Classe utilitaire pour la gestion des vues. */ @@ -23,7 +32,9 @@ public class ViewUtil { */ public static Shape getForm(LoadableData dataLoaded, Shape form, Object controller) { try { - form.setFill(dataLoaded.getColor()); + Color color = LoadableData.getClassifications().get(dataLoaded.getClassification()); + + form.setFill(color); form.setOnMouseClicked(e -> { if (controller instanceof DataStageController) { @@ -44,4 +55,31 @@ public class ViewUtil { return form; } + + public static HBox loadLegend() { + //Color + + Map<String, Color> colors = new HashMap<>(Map.copyOf(LoadableData.getClassifications())); + Rectangle rectangle = new Rectangle(10, 10); + rectangle.setFill(colors.remove("undefined")); + Label label = new Label("undefined"); + HBox hbox = new HBox(); + HBox tempHBox = new HBox(); + tempHBox.getChildren().addAll(rectangle, label); + hbox.getChildren().add(tempHBox); + + + for(String s : colors.keySet()) { + Circle c = new Circle(5); + c.setFill(colors.get(s)); + label = new Label(s); + tempHBox = new HBox(); + tempHBox.getChildren().addAll(c, label); + + hbox.getChildren().add(tempHBox); + } + + return hbox; + } + } diff --git a/src/main/java/fr/univlille/sae/classification/view/DataStageView.java b/src/main/java/fr/univlille/sae/classification/view/DataStageView.java index 81bdb882905ec531ddebe4a87e8f61e1abc0e781..f14feab96b4523782dce473455a8e8182262d75a 100644 --- a/src/main/java/fr/univlille/sae/classification/view/DataStageView.java +++ b/src/main/java/fr/univlille/sae/classification/view/DataStageView.java @@ -13,6 +13,7 @@ import javafx.fxml.FXMLLoader; import javafx.scene.Node; import javafx.scene.chart.ScatterChart; import javafx.scene.chart.XYChart; +import javafx.scene.layout.HBox; import javafx.scene.shape.Circle; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; @@ -153,6 +154,9 @@ public class DataStageView extends DataVisualizationView implements Observer { serieList.get(serie).setName(serie); } scatterChart.getData().addAll(serieList.values()); + + HBox hBox = ViewUtil.loadLegend(); + controller.loadLegend(hBox); } } catch (Exception e) { System.err.println("Erreur de mise à jour : " + e.getMessage()); @@ -195,6 +199,8 @@ public class DataStageView extends DataVisualizationView implements Observer { series4.setName("indéfini"); scatterChart.getData().add(series4); } + HBox hBox = ViewUtil.loadLegend(); + controller.loadLegend(hBox); } catch (Exception e) { System.err.println("Erreur de mise à jour : " + e.getMessage()); } diff --git a/src/main/java/fr/univlille/sae/classification/view/MainStageView.java b/src/main/java/fr/univlille/sae/classification/view/MainStageView.java index d87d6d9deccfdc8aa22aa0150bee66b6f69d0817..3c9c13400d3273d647386a4ce8aec774fbaa9c48 100644 --- a/src/main/java/fr/univlille/sae/classification/view/MainStageView.java +++ b/src/main/java/fr/univlille/sae/classification/view/MainStageView.java @@ -11,6 +11,7 @@ import javafx.scene.Node; import javafx.scene.chart.ScatterChart; import javafx.scene.chart.XYChart; import javafx.scene.control.*; +import javafx.scene.layout.HBox; import javafx.scene.shape.*; import javafx.stage.Stage; @@ -154,7 +155,13 @@ public class MainStageView extends DataVisualizationView implements Observer { serieList.get(serie).setName(serie); } scatterChart.getData().addAll(serieList.values()); + + + HBox hBox = ViewUtil.loadLegend(); + controller.loadLegend(hBox); } + + } catch (Exception e) { System.err.println("Erreur de mise à jour : " + e.getMessage()); } @@ -194,6 +201,9 @@ public class MainStageView extends DataVisualizationView implements Observer { series4.setName("indéfini"); scatterChart.getData().add(series4); } + + + controller.loadLegend(ViewUtil.loadLegend()); } catch (Exception e) { System.err.println("Erreur de mise à jour : " + e.getMessage()); }