From a9215ccb9a08bf4496110b4728bea88e547eb6e3 Mon Sep 17 00:00:00 2001 From: Ziedelth Date: Wed, 8 Dec 2021 09:25:21 +0100 Subject: [PATCH] Update dependencies and save connection information --- pom.xml | 4 +- .../gui/controller/ConnectGuiController.java | 37 +++++++++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) 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();