Skip to content
Snippets Groups Projects
Commit 3736d7c3 authored by Numbtus's avatar Numbtus Committed by Matias Mennecart
Browse files

Ajout polymorphisme

parent 82e950ec
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
}
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);
}
}
......@@ -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);
}
}
......@@ -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é");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment