Skip to content
Snippets Groups Projects
Commit b5812879 authored by Hugo Debuyser's avatar Hugo Debuyser Committed by Matias Mennecart
Browse files

Modifications de fichiers FXML et ajout de la fonctionnalité pour modifier les axes sur une vue

parent 070d8670
No related branches found
No related tags found
No related merge requests found
Showing
with 171 additions and 21 deletions
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<ChoiceBox fx:id="selectAbs" prefWidth="150.0" /> <ChoiceBox fx:id="selectAbs" prefWidth="150.0" />
</children> </children>
</HBox> </HBox>
<Button fx:id="confirmAxes" mnemonicParsing="false" text="Valider" /> <Button fx:id="confirmAxes" onAction="#validate" mnemonicParsing="false" text="Valider" />
</children> </children>
</VBox> </VBox>
</children></AnchorPane> </children></AnchorPane>
......
...@@ -35,7 +35,8 @@ ...@@ -35,7 +35,8 @@
</graphic> </graphic>
<HBox.margin> <HBox.margin>
<Insets right="10.0" top="30.0" /> <Insets right="10.0" top="30.0" />
</HBox.margin></Button> </HBox.margin>
</Button>
</children> </children>
</HBox> </HBox>
</children> </children>
......
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import javafx.stage.*?> <?import javafx.stage.*?>
<?import javafx.scene.image.ImageView?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.image.Image?>
<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/17.0.12" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fr.univlille.sae.classification.controller.MainStageController">
<scene> <scene>
<Scene> <Scene>
...@@ -24,7 +27,17 @@ ...@@ -24,7 +27,17 @@
<NumberAxis fx:id="ordAxe" side="LEFT" /> <NumberAxis fx:id="ordAxe" side="LEFT" />
</yAxis> </yAxis>
</ScatterChart> </ScatterChart>
<Button fx:id="settings" mnemonicParsing="false" text="Réglage" /> <Button fx:id="settingsView" onAction="#openAxesSetting" mnemonicParsing="false">
<graphic>
<ImageView fitHeight="100.0" fitWidth="30.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@gear.png" />
</image></ImageView>
</graphic>
<HBox.margin>
<Insets right="10.0" top="30.0" />
</HBox.margin>
</Button>
</children> </children>
</HBox> </HBox>
<HBox alignment="CENTER" prefHeight="169.0" prefWidth="691.0" spacing="50.0"> <HBox alignment="CENTER" prefHeight="169.0" prefWidth="691.0" spacing="50.0">
......
package fr.univlille.sae.classification.controller; package fr.univlille.sae.classification.controller;
import fr.univlille.sae.classification.view.MainStageView;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox; import javafx.scene.control.ChoiceBox;
import javafx.stage.Stage;
public class AxesSettingsController{
@FXML
Stage stage;
public class AxesSettingsController {
@FXML @FXML
ChoiceBox selectOrd; ChoiceBox selectOrd;
...@@ -13,4 +19,27 @@ public class AxesSettingsController { ...@@ -13,4 +19,27 @@ public class AxesSettingsController {
@FXML @FXML
Button confirmAxes; Button confirmAxes;
MainStageView mainStageView;
public void setSelectOrd(String[] fields){
selectOrd.getItems().clear();
selectOrd.getItems().addAll(fields);
}
public void setSelectAbs(String[] fields){
selectAbs.getItems().clear();
selectAbs.getItems().addAll(fields);
}
public void setMainStageView(MainStageView mainStageView) {
this.mainStageView = mainStageView;
}
public void validate(){
mainStageView.setActualX(selectAbs.getValue().toString());
mainStageView.setActualY(selectOrd.getValue().toString());
mainStageView.update(mainStageView.getModel());
stage.close();
}
} }
...@@ -30,15 +30,12 @@ public class LoadDataController { ...@@ -30,15 +30,12 @@ public class LoadDataController {
public void loadData() { public void loadData() {
System.out.println("Loading data"); System.out.println("Loading data");
stage.close(); stage.close();
} }
public void openFileChooser() { public void openFileChooser() {
FileChooser fileChooser = new FileChooser(); FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Choisissez le fichier à importer"); fileChooser.setTitle("Choisissez le fichier à importer");
this.file = fileChooser.showOpenDialog(stage); this.file = fileChooser.showOpenDialog(stage);
...@@ -47,8 +44,6 @@ public class LoadDataController { ...@@ -47,8 +44,6 @@ public class LoadDataController {
filePath.setText(file.getPath()); filePath.setText(file.getPath());
} }
} }
public void validate() throws IOException { public void validate() throws IOException {
......
package fr.univlille.sae.classification.controller; package fr.univlille.sae.classification.controller;
import fr.univlille.sae.classification.model.ClassificationModel; import fr.univlille.sae.classification.model.ClassificationModel;
import fr.univlille.sae.classification.view.AxesSettingsView;
import fr.univlille.sae.classification.view.LoadDataView; import fr.univlille.sae.classification.view.LoadDataView;
import fr.univlille.sae.classification.view.MainStageView;
import fr.univlille.sae.classification.view.AddDataView; import fr.univlille.sae.classification.view.AddDataView;
import javafx.fxml.FXML; import javafx.fxml.FXML;
...@@ -42,17 +44,24 @@ public class MainStageController { ...@@ -42,17 +44,24 @@ public class MainStageController {
Stage loadStage; Stage loadStage;
private MainStageView mainStageView;
/** /**
* Ouvre l'interface de chargement des données. * Ouvre l'interface de chargement des données.
* @throws IOException * @throws IOException
*/ */
public void openLoadData() throws IOException { public void openLoadData() throws IOException {
LoadDataView loadDataView = new LoadDataView(ClassificationModel.getClassificationModel(), stage); LoadDataView loadDataView = new LoadDataView(ClassificationModel.getClassificationModel(), stage);
loadDataView.show(); loadDataView.show();
}
public void openAxesSetting()throws IOException {
AxesSettingsView axesSettingsView = new AxesSettingsView(ClassificationModel.getClassificationModel(), stage, mainStageView);
axesSettingsView.show();
}
public void setMainStageView(MainStageView mainStageView) {
this.mainStageView = mainStageView;
} }
/** /**
......
...@@ -19,9 +19,9 @@ public class ClassificationModel extends Observable { ...@@ -19,9 +19,9 @@ public class ClassificationModel extends Observable {
private DataType type; private DataType type;
private static ClassificationModel model; private static ClassificationModel model;
/** /**
* Renvoie une instance unique du model. Par default le type de ce modele est Iris. * Renvoie une instance unique du model. Par default le type de ce modele est Iris.
* Modifier en .setType(DataType). * Modifier en .setType(DataType).
...@@ -102,7 +102,6 @@ public class ClassificationModel extends Observable { ...@@ -102,7 +102,6 @@ public class ClassificationModel extends Observable {
return dataToClass; return dataToClass;
} }
public DataType getType() { public DataType getType() {
return type; return type;
} }
......
...@@ -46,6 +46,34 @@ public class Iris extends LoadableData{ ...@@ -46,6 +46,34 @@ public class Iris extends LoadableData{
return petalLength; return petalLength;
} }
public double getDataType(String axes){
if(axes==null){
return sepalWidth;
}
switch (axes){
case "sepalWidth":
return sepalWidth;
case "sepalLength":
return sepalLength;
case "petalWidth":
return petalWidth;
case "petalLength":
return petalLength;
default:
return sepalLength;
}
}
public String[] getAttributesName() {
String[] names = new String[]{
"sepalWidth",
"sepalLength",
"petalWidth",
"petalLength"
};
return names;
}
@Override @Override
public String toString() { public String toString() {
return "Iris{" + return "Iris{" +
......
...@@ -27,4 +27,6 @@ public abstract class LoadableData { ...@@ -27,4 +27,6 @@ public abstract class LoadableData {
this.classification = classification; this.classification = classification;
} }
public abstract String[] getAttributesName();
} }
package fr.univlille.sae.classification.view;
import fr.univlille.sae.classification.controller.AxesSettingsController;
import fr.univlille.sae.classification.controller.MainStageController;
import fr.univlille.sae.classification.model.ClassificationModel;
import fr.univlille.sae.classification.model.LoadableData;
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 AxesSettingsView {
private ClassificationModel model;
private Stage owner;
private MainStageView mainStageView;
public AxesSettingsView(ClassificationModel model, Stage owner, MainStageView mainStageView){
this.model = model;
this.owner = owner;
this.mainStageView = mainStageView;
}
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 + "axes-settings-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("Configuration des axes");
AxesSettingsController controller = loader.getController();
LoadableData dataType = model.getDatas().get(0);
controller.setMainStageView(mainStageView);
controller.setSelectAbs(dataType.getAttributesName());
controller.setSelectOrd(dataType.getAttributesName());
root.showAndWait();
}
}
...@@ -21,13 +21,12 @@ import java.net.URL; ...@@ -21,13 +21,12 @@ import java.net.URL;
public class MainStageView implements Observer { public class MainStageView implements Observer {
private ClassificationModel model; private ClassificationModel model;
private ScatterChart scatterChart; private ScatterChart scatterChart;
private String actualX;
private String actualY;
public MainStageView(ClassificationModel model) { public MainStageView(ClassificationModel model) {
this.model = model; this.model = model;
model.attach(this); model.attach(this);
...@@ -50,6 +49,7 @@ public class MainStageView implements Observer { ...@@ -50,6 +49,7 @@ public class MainStageView implements Observer {
root.show(); root.show();
loader.getController(); loader.getController();
MainStageController controller = loader.getController(); MainStageController controller = loader.getController();
controller.setMainStageView(this);
scatterChart = controller.getScatterChart(); scatterChart = controller.getScatterChart();
} }
...@@ -58,23 +58,41 @@ public class MainStageView implements Observer { ...@@ -58,23 +58,41 @@ public class MainStageView implements Observer {
@Override @Override
public void update(Observable observable) { public void update(Observable observable) {
if(scatterChart == null) throw new IllegalStateException(); if(scatterChart == null) throw new IllegalStateException();
scatterChart.getData().clear();
if(!(observable instanceof ClassificationModel)) throw new IllegalStateException(); if(!(observable instanceof ClassificationModel)) throw new IllegalStateException();
XYChart.Series series1 = new XYChart.Series(); XYChart.Series series1 = new XYChart.Series();
series1.setName("Dice Launch"); series1.setName("Dice Launch");
scatterChart.getData().add(series1); scatterChart.getData().add(series1);
for(LoadableData i : model.getDatas()) { for(LoadableData i : model.getDatas()) {
if(model.getType() == DataType.IRIS) { if(model.getType() == DataType.IRIS) {
series1.getData().add(new XYChart.Data<>(((Iris)i).getPetalLength(), series1.getData().add(new XYChart.Data<>(((Iris)i).getDataType(actualX),
((Iris)i).getPetalWidth())); ((Iris)i).getDataType(actualY)));
} }
} }
} }
@Override @Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
} }
public String getActualX() {
return actualX;
}
public String getActualY() {
return actualY;
}
public void setActualX(String actualX) {
this.actualX = actualX;
}
public void setActualY(String actualY) {
this.actualY = actualY;
}
public Observable getModel() {
return this.model;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment