From aaa0cac636869ceaf8e96f08ecac1d0d51e2983f Mon Sep 17 00:00:00 2001 From: "Notmoo-PC\\Notmoo" Date: Thu, 26 Oct 2017 22:21:38 +0200 Subject: [PATCH] Module Client : ajout d'un affichage d'erreur minimaliste dans la startup frame --- .../gui/ressources/strings/GUIStringTool.java | 13 +++++++++++++ .../startup_frame/StartupFrameController.java | 19 +++++++++++-------- .../gui/startup_frame/StartupFrameView.java | 13 ++++++++++++- .../client/src/main/resources/nightmode.css | 9 ++++++--- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/ressources/strings/GUIStringTool.java b/Workspace/client/src/main/java/com/pqt/client/gui/ressources/strings/GUIStringTool.java index 698af73f..25945093 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/ressources/strings/GUIStringTool.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/ressources/strings/GUIStringTool.java @@ -340,6 +340,10 @@ public class GUIStringTool { return "Compte"; } + public static String getErrorConsoleSectionTitleLabel() { + return "Informations"; + } + public static String getServerHostLabel() { return "Host : "; } @@ -347,6 +351,15 @@ public class GUIStringTool { public static String getServerPortLabel() { return "Port : "; } + + public static IObjectStringRenderer getExceptionFormatter() { + return e->{ + if(e.getMessage()==null || e.getMessage().isEmpty()) + return String.format("%s", e.getClass().getName()); + else + return String.format("%s : %s", e.getClass().getName(), e.getMessage()); + }; + } } diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameController.java b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameController.java index 346335d4..f9bb07d1 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameController.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameController.java @@ -1,5 +1,6 @@ package com.pqt.client.gui.startup_frame; +import com.pqt.client.gui.ressources.strings.GUIStringTool; import com.pqt.client.gui.startup_frame.listeners.frame.IStartupFrameModelListener; public class StartupFrameController implements IStartupFrameModelListener { @@ -27,14 +28,16 @@ public class StartupFrameController implements IStartupFrameModelListener { public void onValidation() { if(!model.isStartupProcessRunning()){ - //TODO catch following exceptions and update GUI when needed : - //NullPointerException && IllegalArgumentException - model.beginStartupProcess( - view.getServerHostTextFieldContent(), - view.getServerPortTextFieldContent(), - view.getAccountUsernameTextFieldContent(), - view.getAccountPasswordTextFieldContent() - ); + try { + model.beginStartupProcess( + view.getServerHostTextFieldContent(), + view.getServerPortTextFieldContent(), + view.getAccountUsernameTextFieldContent(), + view.getAccountPasswordTextFieldContent() + ); + }catch(NullPointerException | IllegalArgumentException e){ + view.displayError(GUIStringTool.getExceptionFormatter().render(e)); + } } } diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameView.java b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameView.java index b2d03caa..f617423c 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameView.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrameView.java @@ -4,6 +4,7 @@ import com.pqt.client.gui.ressources.components.generics.IFXComponent; import com.pqt.client.gui.ressources.strings.GUIStringTool; import javafx.scene.control.*; import javafx.scene.layout.*; +import javafx.scene.text.Text; public class StartupFrameView implements IFXComponent{ @@ -16,6 +17,7 @@ public class StartupFrameView implements IFXComponent{ private TextField passwordTextField; private Button validationButton; + private Text infoText; public StartupFrameView(StartupFrameController ctrl) { this.ctrl = ctrl; @@ -58,7 +60,12 @@ public class StartupFrameView implements IFXComponent{ ctrl.onValidation(); }); - mainPane.getChildren().addAll(serverTitledPane, accountTitledPane, validationButton); + infoText = new Text(""); + infoText.getStyleClass().add("text-displayer"); + TitledPane errorConsoleTitledPane = new TitledPane(GUIStringTool.getErrorConsoleSectionTitleLabel(), infoText); + infoText.textProperty().addListener((obs, oldValue, newValue)->errorConsoleTitledPane.setExpanded(true)); + + mainPane.getChildren().addAll(serverTitledPane, accountTitledPane, errorConsoleTitledPane, validationButton); }catch(Exception e){ //TODO Shutdown software on exception e.printStackTrace(); @@ -101,4 +108,8 @@ public class StartupFrameView implements IFXComponent{ public void clearPasswordField() { passwordTextField.setText(""); } + + public void displayError(String errorMsg) { + infoText.setText(errorMsg); + } } diff --git a/Workspace/client/src/main/resources/nightmode.css b/Workspace/client/src/main/resources/nightmode.css index 080c1589..a4bf07ec 100644 --- a/Workspace/client/src/main/resources/nightmode.css +++ b/Workspace/client/src/main/resources/nightmode.css @@ -122,13 +122,16 @@ } .titled-pane, .titled-pane > .title, .titled-pane > *.content, .text-field, -.password-field, .choice-box, .text-area, .combo-box, .button, .label { - -fx-font-size: 12pt; - -fx-font-family: "Segoe UI Semibold"; +.password-field, .choice-box, .text-area, .combo-box, .button, .label, .text-displayer { + -fx-font: 12pt "Segoe UI Semibold"; -fx-background-color: #1d1d1d; -fx-text-fill: #d8d8d8; } +.text-displayer { + -fx-fill: #d8d8d8; +} + .titled-pane, .titled-pane > .title, .titled-pane > *.content { -fx-border-width: 0; }