Update dependencies and save connection information
This commit is contained in:
parent
00effd8b55
commit
a9215ccb9a
2 changed files with 36 additions and 5 deletions
4
pom.xml
4
pom.xml
|
@ -34,13 +34,13 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-api</artifactId>
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
<version>5.8.1</version>
|
<version>5.8.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<version>5.8.1</version>
|
<version>5.8.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -6,8 +6,11 @@ import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
public class ConnectGuiController {
|
public class ConnectGuiController {
|
||||||
public TextField addressTextField;
|
public TextField addressTextField;
|
||||||
|
@ -35,21 +38,49 @@ public class ConnectGuiController {
|
||||||
|
|
||||||
// Check if the connection is available
|
// Check if the connection is available
|
||||||
if (this.isAccessible(address, iPort)) {
|
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 {
|
} else {
|
||||||
System.out.println("Connection not available");
|
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);
|
this.connectButton.setDisable(false);
|
||||||
}
|
}
|
||||||
} else {
|
} 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);
|
this.connectButton.setDisable(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDialog(String title, String description) {
|
private void showErrorDialog(String title, String description) {
|
||||||
@NotNull
|
@NotNull
|
||||||
final Alert alert = new Alert(Alert.AlertType.WARNING);
|
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.setTitle(title);
|
||||||
alert.setContentText(description);
|
alert.setContentText(description);
|
||||||
alert.show();
|
alert.show();
|
||||||
|
|
Reference in a new issue