From f789b8cbeb6e179cf0b0b5326eaec747216493af Mon Sep 17 00:00:00 2001 From: Matteo Hausner Date: Mon, 29 Jul 2024 20:16:33 +0200 Subject: [PATCH] Client-Server Mode: GUI improvements - Show error message if host field is empty - Multiple other UI fixes --- .../bwravencl/controllerbuddy/gui/Main.java | 62 +++++++++++++------ src/main/resources/strings.properties | 6 +- src/main/resources/strings_de_DE.properties | 6 +- 3 files changed, 50 insertions(+), 24 deletions(-) diff --git a/src/main/java/de/bwravencl/controllerbuddy/gui/Main.java b/src/main/java/de/bwravencl/controllerbuddy/gui/Main.java index 2b16ece3..b352faf7 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/gui/Main.java +++ b/src/main/java/de/bwravencl/controllerbuddy/gui/Main.java @@ -2003,7 +2003,7 @@ public void newActivation(final String[] args) { log.log(Level.SEVERE, e.getMessage(), e); } } else { - EventQueue.invokeLater(() -> GuiUtils.showMessageDialog(main, main.frame, + EventQueue.invokeLater(() -> GuiUtils.showMessageDialog(main, frame, MessageFormat.format(strings.getString("ALREADY_RUNNING_DIALOG_TEXT"), Metadata.APPLICATION_NAME), strings.getString("ERROR_DIALOG_TITLE"), JOptionPane.ERROR_MESSAGE)); } @@ -3696,9 +3696,14 @@ private ConnectionSettingsPanel(final boolean withHost) { hostLabel.setPreferredSize(CONNECTION_SETTINGS_LABEL_DIMENSION); hostPanel.add(hostLabel); - hostTextField = new JTextField(getHost(), 15); + final var host = getHost(); + hostTextField = new JTextField(host, 15); hostTextField.setCaretPosition(0); hostPanel.add(hostTextField); + + if (host == null || host.isBlank()) { + hostTextField.grabFocus(); + } } final var portPanel = new JPanel(DEFAULT_FLOW_LAYOUT); @@ -3729,19 +3734,19 @@ private ConnectionSettingsPanel(final boolean withHost) { timeoutPanel.add(timeoutSpinner); } - private void saveSettings() { + private boolean saveSettings() { if (hostTextField != null) { final var host = hostTextField.getText(); - - if (host != null && !host.isEmpty()) { - preferences.put(PREFERENCES_HOST, host); - } else { - hostTextField.setText(getHost()); + if (host == null || host.isBlank()) { + return false; } + preferences.put(PREFERENCES_HOST, host); } preferences.putInt(PREFERENCES_PORT, (int) portSpinner.getValue()); preferences.putInt(PREFERENCES_TIMEOUT, (int) timeoutSpinner.getValue()); + + return true; } } @@ -4189,14 +4194,27 @@ private StartClientAction() { @Override public void actionPerformed(final ActionEvent e) { + showConnectDialog(); + } + + private void showConnectDialog() { final var connectionSettingsPanel = new ConnectionSettingsPanel(true); - if (JOptionPane.showConfirmDialog(main.frame, connectionSettingsPanel, - strings.getString("CONNECT_DIALOG_TITLE"), JOptionPane.OK_CANCEL_OPTION, - JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) { - connectionSettingsPanel.saveSettings(); - startClient(); - } + executeWhileVisible(() -> { + if (JOptionPane.showConfirmDialog(frame, connectionSettingsPanel, + strings.getString("CONNECT_DIALOG_TITLE"), JOptionPane.OK_CANCEL_OPTION, + JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) { + if (connectionSettingsPanel.saveSettings()) { + startClient(); + } else { + GuiUtils.showMessageDialog(main, frame, strings.getString("NO_HOST_ADDRESS_ERROR_DIALOG_TEXT"), + strings.getString("ERROR_DIALOG_TITLE"), JOptionPane.ERROR_MESSAGE); + showConnectDialog(); + } + } + + return null; + }); } } @@ -4230,12 +4248,16 @@ private StartServerAction() { public void actionPerformed(final ActionEvent e) { final var connectionSettingsPanel = new ConnectionSettingsPanel(false); - if (JOptionPane.showConfirmDialog(main.frame, connectionSettingsPanel, - strings.getString("CONNECT_DIALOG_TITLE"), JOptionPane.OK_CANCEL_OPTION, - JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) { - connectionSettingsPanel.saveSettings(); - startServer(); - } + executeWhileVisible(() -> { + if (JOptionPane.showConfirmDialog(frame, connectionSettingsPanel, + strings.getString("CONNECT_DIALOG_TITLE"), JOptionPane.OK_CANCEL_OPTION, + JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) { + connectionSettingsPanel.saveSettings(); + startServer(); + } + + return null; + }); } } diff --git a/src/main/resources/strings.properties b/src/main/resources/strings.properties index da16454a..9b6c1dee 100644 --- a/src/main/resources/strings.properties +++ b/src/main/resources/strings.properties @@ -250,7 +250,9 @@ COULD_NOT_WRITE_TO_UINPUT_DEVICE_DIALOG_TEXT = Could not write to an uinput devi COULD_NOT_READ_FROM_CONTROLLER_DIALOG_TEXT = Could not read from controller!\n\nPossibly the device has been disconnected. -INVALID_HOST_ADDRESS_DIALOG_TEXT = Invalid host address!\n\n''{0}'' is not a valid host address.\nPlease verify that a valid host address has been entered in the 'Settings' tab.\nAlso ensure that the network connection to the host is working correctly. +NO_HOST_ADDRESS_ERROR_DIALOG_TEXT = No host address specified!\n\nPlease enter a valid host address in the 'Connect' dialog. + +INVALID_HOST_ADDRESS_DIALOG_TEXT = Invalid host address!\n\n''{0}'' is not a valid host address.\nPlease verify that a valid host address has been entered in the 'Connect' dialog.\nAlso ensure that the network connection to the host is working correctly. PROTOCOL_VERSION_MISMATCH_DIALOG_TEXT = Protocol version mismatch!\n\nClient protocol version: {0}\nServer protocol version: {1}\n\nPlease make sure that the client and server versions are matching. @@ -258,7 +260,7 @@ COULD_NOT_CONNECT_DIALOG_TEXT = Could not connect to server!\n\nThe connection t CONNECTION_LOST_DIALOG_TEXT = Connection lost!\n\nThe connection to the server timed out.\nPlease ensure that the server is up and running and can be reached via the network. -COULD_NOT_OPEN_SOCKET_DIALOG_TEXT = Could not open socket!\n\nPort {0,number,#} is not available.\nPlease ensure that the port selected in the 'Settings' tab is available. +COULD_NOT_OPEN_SOCKET_DIALOG_TEXT = Could not open socket!\n\nPort {0,number,#} is not available.\nPlease ensure that the port selected in the 'Connect' dialog is available. GENERAL_INPUT_OUTPUT_ERROR_DIALOG_TEXT = General input-output error! diff --git a/src/main/resources/strings_de_DE.properties b/src/main/resources/strings_de_DE.properties index 9ed7f312..9bebb514 100644 --- a/src/main/resources/strings_de_DE.properties +++ b/src/main/resources/strings_de_DE.properties @@ -226,7 +226,9 @@ COULD_NOT_WRITE_TO_UINPUT_DEVICE_DIALOG_TEXT = Ein Schreiben auf ein uinput Ger COULD_NOT_READ_FROM_CONTROLLER_DIALOG_TEXT = Lesen vom Eingabegerät nicht möglich!\n\nMöglicherweise wurde das Gerät getrennt. -INVALID_HOST_ADDRESS_DIALOG_TEXT = Ungültige Host Adresse!\n\n"{0}" ist keine gültige Host Adresse.\nBitte überprüfen Sie, dass eine gültige Host-Adresse unter dem Tab 'Einstellungen' eingegeben wurde.\nStellen Sie außerdem sicher, dass der Host über das Netzwerk erreichbar ist. +NO_HOST_ADDRESS_ERROR_DIALOG_TEXT = Keine Host Adresse angegeben!\n\nBitte geben Sie eine gültige Host-Adresse im 'Verbinden' Dialog ein. + +INVALID_HOST_ADDRESS_DIALOG_TEXT = Ungültige Host Adresse!\n\n"{0}" ist keine gültige Host Adresse.\nBitte überprüfen Sie, dass eine gültige Host-Adresse im 'Verbinden' Dialog eingegeben wurde.\nStellen Sie außerdem sicher, dass der Host über das Netzwerk erreichbar ist. PROTOCOL_VERSION_MISMATCH_DIALOG_TEXT = Protokoll Versionskonflikt!\n\nClient Protokoll Version: {0,number,integer}\nServer Protokoll Version: {1,number,integer}\n\nBitte stellen Sie sicher, dass die Client- und Server-Versionen übereinstimmen. @@ -234,7 +236,7 @@ COULD_NOT_CONNECT_DIALOG_TEXT = Verbindung zum Server nicht möglich!\n\nDie Ver CONNECTION_LOST_DIALOG_TEXT = Verbindung abgebrochen!\n\nDie Verbindung zum Server hatte einen Timeout.\nBitte überprüfen Sie, dass der Server läuft und über das Netzwerk erreichbar ist. -COULD_NOT_OPEN_SOCKET_DIALOG_TEXT = Socket konnte nicht geöffnet werden!\n\nPort {0,number,#} ist nicht verfügbar.\nBitte überprüfen Sie, dass der unter dem Tab 'Einstellungen' ausgewählte Port verfügbar ist. +COULD_NOT_OPEN_SOCKET_DIALOG_TEXT = Socket konnte nicht geöffnet werden!\n\nPort {0,number,#} ist nicht verfügbar.\nBitte überprüfen Sie, dass der im 'Verbinden' Dialog ausgewählte Port verfügbar ist. GENERAL_INPUT_OUTPUT_ERROR_DIALOG_TEXT = Allgemeiner Ein-Ausgabefehler!