From 3736d7c3cd64442e5a75837c6a58f860d6ac4a55 Mon Sep 17 00:00:00 2001
From: Numbtus <Matias.mennecart@icloud.com>
Date: Wed, 27 Nov 2024 19:15:55 +0100
Subject: [PATCH] Ajout polymorphisme
---
.../controller/DataStageController.java | 121 +-------------
.../DataVisualizationController.java | 147 ++++++++++++++++++
.../controller/MainStageController.java | 104 +------------
.../classification/view/DataStageView.java | 2 +-
4 files changed, 159 insertions(+), 215 deletions(-)
create mode 100644 src/main/java/fr/univlille/sae/classification/controller/DataVisualizationController.java
diff --git a/src/main/java/fr/univlille/sae/classification/controller/DataStageController.java b/src/main/java/fr/univlille/sae/classification/controller/DataStageController.java
index 94c7e97..edc1926 100644
--- a/src/main/java/fr/univlille/sae/classification/controller/DataStageController.java
+++ b/src/main/java/fr/univlille/sae/classification/controller/DataStageController.java
@@ -15,152 +15,43 @@ import java.io.IOException;
/**
* Controlleur pour le FXML data-view-stage, pour gérer la vue supplémentaire
*/
-public class DataStageController {
+public class DataStageController extends DataVisualizationController{
@FXML
Stage stage;
- @FXML
- ScatterChart scatterChart;
- @FXML
- Label AxesSelected;
+
@FXML
ListView PointInfo;
- /**
- * DataStageView associé au controlleur
- */
- private DataStageView dataStageView;
- private double initialX;
- private double initialY;
- private double initialLowerBoundX;
- private double initialUpperBoundX;
- private double initialLowerBoundY;
- private double initialUpperBoundY;
+
public void initialize() {
setupZoom();
setupDrag();
}
- /**
- * Ouvrir les paramètres des axes de la vue
- */
- public void openAxesSetting(){
- AxesSettingsView axesSettingsView = new AxesSettingsView(ClassificationModel.getClassificationModel(), stage, dataStageView);
- axesSettingsView.show();
- }
+
/**
* Associe la dataStageView associer à la classe
* @param dataStageView
*/
public void setDataStageView (DataStageView dataStageView) {
- this.dataStageView = dataStageView;
+ this.view = dataStageView;
}
- /**
- * Renvoie la grille associé à la classe
- * @return grille de la classe
- */
- public ScatterChart getScatterChart() {
- return this.scatterChart;
- }
- /**
- * Attribut une valeur à l'axe de la grille
- * @param texte Valeur de l'axe
- */
- public void setAxesSelected(String texte) {
- this.AxesSelected.setText(texte);
- }
- public void setAxesSelectedDisable(){
- this.AxesSelected.setDisable(true);
- }
+
public ListView getPointInfo(){
return this.PointInfo;
};
- private void setupZoom() {
- NumberAxis xAxis = (NumberAxis) scatterChart.getXAxis();
- NumberAxis yAxis = (NumberAxis) scatterChart.getYAxis();
-
- scatterChart.setOnScroll(event -> {
- xAxis.setAutoRanging(false);
- yAxis.setAutoRanging(false);
-
- double delta = event.getDeltaY();
- double mouseX = event.getSceneX();
- double mouseY = event.getSceneY();
-
- double chartX = xAxis.sceneToLocal(mouseX, mouseY).getX();
- double chartY = yAxis.sceneToLocal(mouseX, mouseY).getY();
-
- double zoomFactor;
- if (delta > 0) {
- zoomFactor = 0.90;
- } else {
- zoomFactor = 1.05;
- }
-
- double xLower = xAxis.getLowerBound();
- double xUpper = xAxis.getUpperBound();
- double yLower = yAxis.getLowerBound();
- double yUpper = yAxis.getUpperBound();
- double rangeX = xUpper - xLower;
- double rangeY = yUpper - yLower;
-
- double newRangeX = rangeX * zoomFactor;
- double newRangeY = rangeY * zoomFactor;
-
- xAxis.setLowerBound(xLower + (chartX / xAxis.getWidth()) * (rangeX - newRangeX));
- xAxis.setUpperBound(xUpper - ((xAxis.getWidth() - chartX) / xAxis.getWidth()) * (rangeX - newRangeX));
-
- yAxis.setLowerBound(yLower + ((yAxis.getHeight() - chartY) / yAxis.getHeight()) * (rangeY - newRangeY));
- yAxis.setUpperBound(yUpper - (chartY / yAxis.getHeight()) * (rangeY - newRangeY));
- });
-
- xAxis.setAutoRanging(true);
- yAxis.setAutoRanging(true);
- }
-
- private void setupDrag() {
- scatterChart.setOnMousePressed(event -> {
- initialX = event.getSceneX();
- initialY = event.getSceneY();
- initialLowerBoundX = ((NumberAxis) scatterChart.getXAxis()).getLowerBound();
- initialUpperBoundX = ((NumberAxis) scatterChart.getXAxis()).getUpperBound();
- initialLowerBoundY = ((NumberAxis) scatterChart.getYAxis()).getLowerBound();
- initialUpperBoundY = ((NumberAxis) scatterChart.getYAxis()).getUpperBound();
- });
-
- NumberAxis xAxis = (NumberAxis) scatterChart.getXAxis();
- NumberAxis yAxis = (NumberAxis) scatterChart.getYAxis();
-
- scatterChart.setOnMouseDragged(event -> {
- xAxis.setAutoRanging(false);
- yAxis.setAutoRanging(false);
- double deltaX = event.getSceneX() - initialX;
- double deltaY = event.getSceneY() - initialY;
-
- double newLowerBoundX = initialLowerBoundX - deltaX * (xAxis.getUpperBound() - xAxis.getLowerBound()) / scatterChart.getWidth();
- double newUpperBoundX = initialUpperBoundX - deltaX * (xAxis.getUpperBound() - xAxis.getLowerBound()) / scatterChart.getWidth();
- double newLowerBoundY = initialLowerBoundY + deltaY * (yAxis.getUpperBound() - yAxis.getLowerBound()) / scatterChart.getHeight();
- double newUpperBoundY = initialUpperBoundY + deltaY * (yAxis.getUpperBound() - yAxis.getLowerBound()) / scatterChart.getHeight();
-
- xAxis.setLowerBound(newLowerBoundX);
- xAxis.setUpperBound(newUpperBoundX);
- yAxis.setLowerBound(newLowerBoundY);
- yAxis.setUpperBound(newUpperBoundY);
- });
- xAxis.setAutoRanging(true);
- yAxis.setAutoRanging(true);
- }
}
diff --git a/src/main/java/fr/univlille/sae/classification/controller/DataVisualizationController.java b/src/main/java/fr/univlille/sae/classification/controller/DataVisualizationController.java
new file mode 100644
index 0000000..5f5b95e
--- /dev/null
+++ b/src/main/java/fr/univlille/sae/classification/controller/DataVisualizationController.java
@@ -0,0 +1,147 @@
+package fr.univlille.sae.classification.controller;
+
+import fr.univlille.sae.classification.model.ClassificationModel;
+import fr.univlille.sae.classification.view.AxesSettingsView;
+import fr.univlille.sae.classification.view.DataVisualizationView;
+import javafx.fxml.FXML;
+import javafx.scene.chart.NumberAxis;
+import javafx.scene.chart.ScatterChart;
+import javafx.scene.control.Label;
+import javafx.stage.Stage;
+
+public abstract class DataVisualizationController {
+
+
+ @FXML
+ Stage stage;
+
+ @FXML
+ Label AxesSelected;
+
+
+ @FXML
+ ScatterChart scatterChart;
+
+ protected double initialX;
+ protected double initialY;
+ protected double initialLowerBoundX;
+ protected double initialUpperBoundX;
+ protected double initialLowerBoundY;
+ protected double initialUpperBoundY;
+
+
+ protected DataVisualizationView view;
+
+
+ protected void setupZoom() {
+ NumberAxis xAxis = (NumberAxis) scatterChart.getXAxis();
+ NumberAxis yAxis = (NumberAxis) scatterChart.getYAxis();
+
+ scatterChart.setOnScroll(event -> {
+ xAxis.setAutoRanging(false);
+ yAxis.setAutoRanging(false);
+
+ double delta = event.getDeltaY();
+ double mouseX = event.getSceneX();
+ double mouseY = event.getSceneY();
+
+ double chartX = xAxis.sceneToLocal(mouseX, mouseY).getX();
+ double chartY = yAxis.sceneToLocal(mouseX, mouseY).getY();
+
+ double zoomFactor;
+ if (delta > 0) {
+ zoomFactor = 0.90;
+ } else {
+ zoomFactor = 1.05;
+ }
+
+ double xLower = xAxis.getLowerBound();
+ double xUpper = xAxis.getUpperBound();
+ double yLower = yAxis.getLowerBound();
+ double yUpper = yAxis.getUpperBound();
+
+ double rangeX = xUpper - xLower;
+ double rangeY = yUpper - yLower;
+
+ double newRangeX = rangeX * zoomFactor;
+ double newRangeY = rangeY * zoomFactor;
+
+ xAxis.setLowerBound(xLower + (chartX / xAxis.getWidth()) * (rangeX - newRangeX));
+ xAxis.setUpperBound(xUpper - ((xAxis.getWidth() - chartX) / xAxis.getWidth()) * (rangeX - newRangeX));
+
+ yAxis.setLowerBound(yLower + ((yAxis.getHeight() - chartY) / yAxis.getHeight()) * (rangeY - newRangeY));
+ yAxis.setUpperBound(yUpper - (chartY / yAxis.getHeight()) * (rangeY - newRangeY));
+ });
+
+ xAxis.setAutoRanging(true);
+ yAxis.setAutoRanging(true);
+ }
+
+
+ protected void setupDrag() {
+ scatterChart.setOnMousePressed(event -> {
+ initialX = event.getSceneX();
+ initialY = event.getSceneY();
+ initialLowerBoundX = ((NumberAxis) scatterChart.getXAxis()).getLowerBound();
+ initialUpperBoundX = ((NumberAxis) scatterChart.getXAxis()).getUpperBound();
+ initialLowerBoundY = ((NumberAxis) scatterChart.getYAxis()).getLowerBound();
+ initialUpperBoundY = ((NumberAxis) scatterChart.getYAxis()).getUpperBound();
+ });
+
+ NumberAxis xAxis = (NumberAxis) scatterChart.getXAxis();
+ NumberAxis yAxis = (NumberAxis) scatterChart.getYAxis();
+
+ scatterChart.setOnMouseDragged(event -> {
+ xAxis.setAutoRanging(false);
+ yAxis.setAutoRanging(false);
+ double deltaX = event.getSceneX() - initialX;
+ double deltaY = event.getSceneY() - initialY;
+
+ double newLowerBoundX = initialLowerBoundX - deltaX * (xAxis.getUpperBound() - xAxis.getLowerBound()) / scatterChart.getWidth();
+ double newUpperBoundX = initialUpperBoundX - deltaX * (xAxis.getUpperBound() - xAxis.getLowerBound()) / scatterChart.getWidth();
+ double newLowerBoundY = initialLowerBoundY + deltaY * (yAxis.getUpperBound() - yAxis.getLowerBound()) / scatterChart.getHeight();
+ double newUpperBoundY = initialUpperBoundY + deltaY * (yAxis.getUpperBound() - yAxis.getLowerBound()) / scatterChart.getHeight();
+
+ xAxis.setLowerBound(newLowerBoundX);
+ xAxis.setUpperBound(newUpperBoundX);
+ yAxis.setLowerBound(newLowerBoundY);
+ yAxis.setUpperBound(newUpperBoundY);
+ });
+ xAxis.setAutoRanging(true);
+ yAxis.setAutoRanging(true);
+ }
+
+ /**
+ * Ouvrir les paramètres des axes de la vue
+ */
+ public void openAxesSetting(){
+ AxesSettingsView axesSettingsView = new AxesSettingsView(ClassificationModel.getClassificationModel(), stage, view);
+ axesSettingsView.show();
+ }
+
+
+ /**
+ * Renvoie la grille associé à la classe
+ * @return grille de la classe
+ */
+ public ScatterChart getScatterChart() {
+ return this.scatterChart;
+ }
+
+
+ /**
+ * Attribut une valeur à l'axe de la grille
+ * @param texte Valeur de l'axe
+ */
+ public void setAxesSelected(String texte) {
+ this.AxesSelected.setText(texte);
+ }
+
+ public void setAxesSelectedDisable(){
+ this.AxesSelected.setDisable(true);
+ }
+
+
+
+
+}
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 d18c02d..bed2fe9 100644
--- a/src/main/java/fr/univlille/sae/classification/controller/MainStageController.java
+++ b/src/main/java/fr/univlille/sae/classification/controller/MainStageController.java
@@ -12,31 +12,22 @@ import javafx.stage.Stage;
import java.io.IOException;
-public class MainStageController {
+public class MainStageController extends DataVisualizationController{
+
- @FXML
- Stage stage;
@FXML
Button classifyData;
- @FXML
- ScatterChart scatterChart;
- @FXML
- Label AxesSelected;
+
@FXML
ListView PointInfo;
+
private MainStageView mainStageView;
- private double initialX;
- private double initialY;
- private double initialLowerBoundX;
- private double initialUpperBoundX;
- private double initialLowerBoundY;
- private double initialUpperBoundY;
public void initialize() {
setupZoom();
@@ -81,6 +72,7 @@ public class MainStageController {
*/
public void setMainStageView(MainStageView mainStageView) {
this.mainStageView = mainStageView;
+ this.view = mainStageView;
}
/**
@@ -109,17 +101,7 @@ public class MainStageController {
return this.scatterChart;
}
- /**
- * Attribue une valeur à l'axe de la grille.
- * @param texte Valeur de l'axe à afficher sur l'interface.
- */
- public void setAxesSelected(String texte) {
- this.AxesSelected.setText(texte);
- }
- public void setAxesSelectedDisable(){
- this.AxesSelected.setDisable(true);
- }
/**
* Renvoie le bouton de classification de données.
@@ -133,82 +115,6 @@ public class MainStageController {
return this.PointInfo;
};
- private void setupZoom() {
- NumberAxis xAxis = (NumberAxis) scatterChart.getXAxis();
- NumberAxis yAxis = (NumberAxis) scatterChart.getYAxis();
-
- scatterChart.setOnScroll(event -> {
- xAxis.setAutoRanging(false);
- yAxis.setAutoRanging(false);
-
- double delta = event.getDeltaY();
- double mouseX = event.getSceneX();
- double mouseY = event.getSceneY();
- double chartX = xAxis.sceneToLocal(mouseX, mouseY).getX();
- double chartY = yAxis.sceneToLocal(mouseX, mouseY).getY();
-
- double zoomFactor;
- if (delta > 0) {
- zoomFactor = 0.90;
- } else {
- zoomFactor = 1.05;
- }
-
- double xLower = xAxis.getLowerBound();
- double xUpper = xAxis.getUpperBound();
- double yLower = yAxis.getLowerBound();
- double yUpper = yAxis.getUpperBound();
-
- double rangeX = xUpper - xLower;
- double rangeY = yUpper - yLower;
-
- double newRangeX = rangeX * zoomFactor;
- double newRangeY = rangeY * zoomFactor;
-
- xAxis.setLowerBound(xLower + (chartX / xAxis.getWidth()) * (rangeX - newRangeX));
- xAxis.setUpperBound(xUpper - ((xAxis.getWidth() - chartX) / xAxis.getWidth()) * (rangeX - newRangeX));
-
- yAxis.setLowerBound(yLower + ((yAxis.getHeight() - chartY) / yAxis.getHeight()) * (rangeY - newRangeY));
- yAxis.setUpperBound(yUpper - (chartY / yAxis.getHeight()) * (rangeY - newRangeY));
- });
-
- xAxis.setAutoRanging(true);
- yAxis.setAutoRanging(true);
- }
-
-
- private void setupDrag() {
- scatterChart.setOnMousePressed(event -> {
- initialX = event.getSceneX();
- initialY = event.getSceneY();
- initialLowerBoundX = ((NumberAxis) scatterChart.getXAxis()).getLowerBound();
- initialUpperBoundX = ((NumberAxis) scatterChart.getXAxis()).getUpperBound();
- initialLowerBoundY = ((NumberAxis) scatterChart.getYAxis()).getLowerBound();
- initialUpperBoundY = ((NumberAxis) scatterChart.getYAxis()).getUpperBound();
- });
-
- NumberAxis xAxis = (NumberAxis) scatterChart.getXAxis();
- NumberAxis yAxis = (NumberAxis) scatterChart.getYAxis();
-
- scatterChart.setOnMouseDragged(event -> {
- xAxis.setAutoRanging(false);
- yAxis.setAutoRanging(false);
- double deltaX = event.getSceneX() - initialX;
- double deltaY = event.getSceneY() - initialY;
-
- double newLowerBoundX = initialLowerBoundX - deltaX * (xAxis.getUpperBound() - xAxis.getLowerBound()) / scatterChart.getWidth();
- double newUpperBoundX = initialUpperBoundX - deltaX * (xAxis.getUpperBound() - xAxis.getLowerBound()) / scatterChart.getWidth();
- double newLowerBoundY = initialLowerBoundY + deltaY * (yAxis.getUpperBound() - yAxis.getLowerBound()) / scatterChart.getHeight();
- double newUpperBoundY = initialUpperBoundY + deltaY * (yAxis.getUpperBound() - yAxis.getLowerBound()) / scatterChart.getHeight();
-
- xAxis.setLowerBound(newLowerBoundX);
- xAxis.setUpperBound(newUpperBoundX);
- yAxis.setLowerBound(newLowerBoundY);
- yAxis.setUpperBound(newUpperBoundY);
- });
- xAxis.setAutoRanging(true);
- yAxis.setAutoRanging(true);
- }
}
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 973c208..81bdb88 100644
--- a/src/main/java/fr/univlille/sae/classification/view/DataStageView.java
+++ b/src/main/java/fr/univlille/sae/classification/view/DataStageView.java
@@ -79,7 +79,7 @@ public class DataStageView extends DataVisualizationView implements Observer {
controller = loader.getController();
controller.setDataStageView(this);
scatterChart = controller.getScatterChart();
-
+ scatterChart.setLegendVisible(false);
scatterChart.getData().addAll(series4, series1, series2, series3);
controller.setAxesSelected("Aucun fichier sélectionné");
--
GitLab