Skip to content
Snippets Groups Projects
Commit 2e195644 authored by Matias Mennecart's avatar Matias Mennecart
Browse files

Merge branch 'hugodebuyser' into 'master'

Configurations des axes et couleurs des points

See merge request sae302/2024/H4_SAE3.3!9
parents b798085a 6b444d01
No related branches found
No related tags found
No related merge requests found
Showing
with 322 additions and 39 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>
......
<?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.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">
<scene>
<Scene>
<AnchorPane prefHeight="363.0" prefWidth="692.0">
<children>
<VBox prefHeight="363.0" prefWidth="691.0">
<children>
<HBox prefHeight="356.0" prefWidth="691.0">
<children>
<Region prefHeight="338.0" prefWidth="65.0" />
<ScatterChart prefHeight="342.0" prefWidth="609.0">
<xAxis>
<CategoryAxis fx:id="absAxeView" prefHeight="21.0" prefWidth="498.0" side="BOTTOM" />
</xAxis>
<yAxis>
<NumberAxis fx:id="ordAxeView" side="LEFT" />
</yAxis>
</ScatterChart>
<Button fx:id="settingsView" 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>
</HBox>
</children>
</VBox>
</children></AnchorPane>
</Scene>
</scene>
</Stage>
res/stages/gear.png

49.7 KiB

<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.*?> <?import javafx.scene.*?>
<?import javafx.scene.chart.*?> <?import javafx.scene.chart.*?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.stage.*?> <?import javafx.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/17.0.12" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fr.univlille.sae.classification.controller.MainStageController">
...@@ -13,18 +16,40 @@ ...@@ -13,18 +16,40 @@
<children> <children>
<VBox prefHeight="488.0" prefWidth="691.0"> <VBox prefHeight="488.0" prefWidth="691.0">
<children> <children>
<HBox prefHeight="356.0" prefWidth="691.0"> <HBox alignment="TOP_CENTER" prefHeight="356.0" prefWidth="691.0" spacing="5.0">
<children> <children>
<Region prefHeight="338.0" prefWidth="65.0" /> <AnchorPane prefHeight="200.0" prefWidth="200.0">
<ScatterChart fx:id="scatterChart" prefHeight="342.0" prefWidth="609.0"> <children>
<xAxis> <Region prefHeight="338.0" prefWidth="65.0" />
<NumberAxis fx:id="absAxe" prefHeight="21.0" prefWidth="498.0" side="BOTTOM" /> <ScatterChart fx:id="scatterChart" prefHeight="342.0" prefWidth="609.0">
</xAxis> <xAxis>
<yAxis> <NumberAxis fx:id="absAxe" prefHeight="21.0" prefWidth="498.0" side="BOTTOM" />
<NumberAxis fx:id="ordAxe" side="LEFT" /> </xAxis>
</yAxis> <yAxis>
</ScatterChart> <NumberAxis fx:id="ordAxe" side="LEFT" />
<Button fx:id="settings" mnemonicParsing="false" text="Réglage" /> </yAxis>
</ScatterChart>
<Label fx:id="AxesSelected" alignment="CENTER" layoutX="175.0" layoutY="152.0" prefHeight="38.0" prefWidth="259.0">
<font>
<Font size="21.0" />
</font></Label>
</children>
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</AnchorPane>
<Button fx:id="settingsView" mnemonicParsing="false" onAction="#openAxesSetting">
<graphic>
<ImageView fitHeight="100.0" fitWidth="30.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@gear.png" />
</image>
</ImageView>
</graphic>
<HBox.margin>
<Insets top="40.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,29 @@ public class AxesSettingsController { ...@@ -13,4 +19,29 @@ public class AxesSettingsController {
@FXML @FXML
Button confirmAxes; Button confirmAxes;
MainStageView mainStageView;
public void setSelectOrd(String[] fields){
selectOrd.getItems().clear();
selectOrd.getItems().addAll(fields);
selectOrd.setValue(mainStageView.getActualY());
}
public void setSelectAbs(String[] fields){
selectAbs.getItems().clear();
selectAbs.getItems().addAll(fields);
selectAbs.setValue(mainStageView.getActualX());
}
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();
}
} }
package fr.univlille.sae.classification.controller;
import javafx.fxml.FXML;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.control.Button;
import javafx.stage.Stage;
public class DataViewStage {
@FXML
Stage stage;
@FXML
CategoryAxis absAxe;
@FXML
NumberAxis ordAxe;
@FXML
Button settings;
}
...@@ -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 fr.univlille.sae.classification.view.MainStageView;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.chart.*; import javafx.scene.chart.*;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.stage.*; import javafx.stage.*;
...@@ -40,19 +44,29 @@ public class MainStageController { ...@@ -40,19 +44,29 @@ public class MainStageController {
@FXML @FXML
ScatterChart scatterChart; ScatterChart scatterChart;
@FXML
Label AxesSelected;
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;
} }
/** /**
...@@ -63,6 +77,7 @@ public class MainStageController { ...@@ -63,6 +77,7 @@ public class MainStageController {
AddDataView addDataView = new AddDataView(ClassificationModel.getClassificationModel(), stage); AddDataView addDataView = new AddDataView(ClassificationModel.getClassificationModel(), stage);
addDataView.show(); addDataView.show();
}
} }
...@@ -71,4 +86,8 @@ public class MainStageController { ...@@ -71,4 +86,8 @@ public class MainStageController {
public ScatterChart getScatterChart() { public ScatterChart getScatterChart() {
return this.scatterChart; return this.scatterChart;
} }
public void setAxesSelected(String texte) {
this.AxesSelected.setText(texte);
}
} }
...@@ -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;
} }
......
package fr.univlille.sae.classification.model; package fr.univlille.sae.classification.model;
import java.util.Set;
import com.opencsv.bean.*; import com.opencsv.bean.*;
import javafx.scene.paint.Color;
import java.util.Random;
public class Iris extends LoadableData{ public class Iris extends LoadableData{
...@@ -13,6 +15,8 @@ public class Iris extends LoadableData{ ...@@ -13,6 +15,8 @@ public class Iris extends LoadableData{
private double petalWidth; private double petalWidth;
@CsvBindByName(column = "petal.length") @CsvBindByName(column = "petal.length")
private double petalLength; private double petalLength;
@CsvBindByName(column = "variety")
private String variety;
public Iris(double sepalWidth, double sepalLength, double petalWidth, double petalLength) { public Iris(double sepalWidth, double sepalLength, double petalWidth, double petalLength) {
this(sepalWidth, sepalLength, petalWidth, petalLength, "undefined"); this(sepalWidth, sepalLength, petalWidth, petalLength, "undefined");
...@@ -22,12 +26,13 @@ public class Iris extends LoadableData{ ...@@ -22,12 +26,13 @@ public class Iris extends LoadableData{
// //
} }
public Iris(double sepalWidth, double sepalLength, double petalWidth, double petalLength, String classification) { public Iris(double sepalWidth, double sepalLength, double petalWidth, double petalLength, String variety) {
super(); super();
this.sepalWidth = sepalWidth; this.sepalWidth = sepalWidth;
this.sepalLength = sepalLength; this.sepalLength = sepalLength;
this.petalWidth = petalWidth; this.petalWidth = petalWidth;
this.petalLength = petalLength; this.petalLength = petalLength;
this.variety = variety;
} }
public double getSepalWidth() { public double getSepalWidth() {
...@@ -46,6 +51,48 @@ public class Iris extends LoadableData{ ...@@ -46,6 +51,48 @@ public class Iris extends LoadableData{
return petalLength; return petalLength;
} }
public String getVariety() {
return variety;
}
public double getDataType(String axes){
switch (axes){
case "sepalWidth":
return sepalWidth;
case "sepalLength":
return sepalLength;
case "petalWidth":
return petalWidth;
case "petalLength":
return petalLength;
default:
return sepalLength;
}
}
public Color getColor(){
switch (this.variety){
case "Setosa":
return Color.RED;
case "Versicolor":
return Color.BLUE;
case "Virginica":
return Color.GREEN;
default:
return Color.BLACK;
}
}
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{" +
......
...@@ -8,13 +8,18 @@ public abstract class LoadableData { ...@@ -8,13 +8,18 @@ public abstract class LoadableData {
private String classification; private String classification;
protected LoadableData() { protected LoadableData() {
} }
public void addClassification(String classificationType) {
this.classificationTypes.add(classificationType);
}
public String getClassification() { public String getClassification() {
return this.classification; return this.classification;
} }
public static Set<String> getClassificationTypes() { public static Set<String> getClassificationTypes() {
return classificationTypes; return classificationTypes;
} }
...@@ -27,4 +32,6 @@ public abstract class LoadableData { ...@@ -27,4 +32,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();
}
}
...@@ -13,20 +13,25 @@ import javafx.fxml.FXML; ...@@ -13,20 +13,25 @@ import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.chart.ScatterChart; import javafx.scene.chart.ScatterChart;
import javafx.scene.chart.XYChart; import javafx.scene.chart.XYChart;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage; import javafx.stage.Stage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class MainStageView implements Observer { public class MainStageView implements Observer {
private ClassificationModel model; private ClassificationModel model;
private ScatterChart scatterChart; private ScatterChart scatterChart;
private MainStageController controller;
private String actualX;
private String actualY;
public MainStageView(ClassificationModel model) { public MainStageView(ClassificationModel model) {
this.model = model; this.model = model;
...@@ -49,32 +54,62 @@ public class MainStageView implements Observer { ...@@ -49,32 +54,62 @@ public class MainStageView implements Observer {
root.setTitle("SAE3.3 - Logiciel de classification"); root.setTitle("SAE3.3 - Logiciel de classification");
root.show(); root.show();
loader.getController(); loader.getController();
MainStageController controller = loader.getController(); controller = loader.getController();
controller.setMainStageView(this);
scatterChart = controller.getScatterChart(); scatterChart = controller.getScatterChart();
controller.setAxesSelected("Aucun fichier sélectionné");
} }
@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("Iris");
scatterChart.getData().add(series1); if(model.getType() == DataType.IRIS) {
for(LoadableData i : model.getDatas()) { controller.setAxesSelected("");
if(model.getType() == DataType.IRIS) { if(actualX==null && actualY==null){
series1.getData().add(new XYChart.Data<>(((Iris)i).getPetalLength(), controller.setAxesSelected("Aucuns axes sélectionnés");
((Iris)i).getPetalWidth())); }
else{
scatterChart.getData().add(series1);
for(LoadableData i : model.getDatas()) {
Iris iris = (Iris)i;
XYChart.Data<Double, Double> dataPoint = new XYChart.Data<>(iris.getDataType(actualX),
iris.getDataType(actualY));
Circle circle = new Circle(5);
circle.setFill(iris.getColor());
dataPoint.setNode(circle);
series1.getData().add(dataPoint);
}
} }
} }
} }
@Override @Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
} }
public void setActualX(String actualX) {
this.actualX = actualX;
}
public void setActualY(String actualY) {
this.actualY = actualY;
}
public String getActualX() {
return actualX;
}
public String getActualY() {
return 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