diff --git a/pom.xml b/pom.xml
index b170004..59b3bd1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,13 +34,13 @@
org.junit.jupiter
junit-jupiter-api
- 5.8.1
+ 5.8.2
test
org.junit.jupiter
junit-jupiter-engine
- 5.8.1
+ 5.8.2
test
diff --git a/src/fr/univ/lyon1/gui/controller/ConnectGuiController.java b/src/fr/univ/lyon1/gui/controller/ConnectGuiController.java
index 79d0241..5dd3286 100644
--- a/src/fr/univ/lyon1/gui/controller/ConnectGuiController.java
+++ b/src/fr/univ/lyon1/gui/controller/ConnectGuiController.java
@@ -6,8 +6,11 @@ import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import org.jetbrains.annotations.NotNull;
+import java.io.File;
+import java.io.FileWriter;
import java.io.IOException;
import java.net.Socket;
+import java.util.Properties;
public class ConnectGuiController {
public TextField addressTextField;
@@ -35,21 +38,49 @@ public class ConnectGuiController {
// Check if the connection is available
if (this.isAccessible(address, iPort)) {
+ System.out.println("Connection available, saving file...");
+ // Save server information in properties file
+ @NotNull
+ final Properties properties = new Properties();
+ properties.setProperty("address", address);
+ properties.setProperty("port", port);
+
+ try {
+ @NotNull
+ final File file = new File("connection.properties");
+ properties.store(new FileWriter(file), "Information needed to connect to the server");
+ this.showSuccessDialog("Connecté", "Vous êtes bien connecté au serveur");
+ System.out.println("File saved, next step...");
+ } catch (IOException e) {
+ this.showErrorDialog("Erreur", "Impossible de sauvegarder les informations de connexion au serveur");
+ this.connectButton.setDisable(false);
+ System.out.println("Failed to save file, error: " + e.getMessage());
+ }
} else {
System.out.println("Connection not available");
- this.showDialog("Erreur de connexion", "Impossible de se connecter au serveur, veuillez vérifier les informations saisies");
+ this.showErrorDialog("Erreur de connexion", "Impossible de se connecter au serveur, veuillez vérifier les informations saisies");
this.connectButton.setDisable(false);
}
} else {
- this.showDialog("Erreur", "Veuillez saisir un numéro de port valide");
+ this.showErrorDialog("Erreur", "Veuillez saisir un numéro de port valide");
this.connectButton.setDisable(false);
}
}
- private void showDialog(String title, String description) {
+ private void showErrorDialog(String title, String description) {
@NotNull
final Alert alert = new Alert(Alert.AlertType.WARNING);
+ extracted(title, description, alert);
+ }
+
+ private void showSuccessDialog(String title, String description) {
+ @NotNull
+ final Alert alert = new Alert(Alert.AlertType.INFORMATION);
+ extracted(title, description, alert);
+ }
+
+ private void extracted(String title, String description, @NotNull Alert alert) {
alert.setTitle(title);
alert.setContentText(description);
alert.show();