Skip to content

Commit

Permalink
Client-Server Mode: GUI improvements
Browse files Browse the repository at this point in the history
- Show error message if host field is empty
- Multiple other UI fixes
  • Loading branch information
bwRavencl committed Jul 29, 2024
1 parent e26e9f5 commit f789b8c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
62 changes: 42 additions & 20 deletions src/main/java/de/bwravencl/controllerbuddy/gui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
});
}
}

Expand Down Expand Up @@ -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;
});
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/strings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,17 @@ 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.

COULD_NOT_CONNECT_DIALOG_TEXT = Could not connect to server!\n\nThe connection to the server could not be established after {0,number,integer} repeated connection attempts.\nPlease ensure that the server is up and running and can be reached via the network.

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!

Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/strings_de_DE.properties
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,17 @@ 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.

COULD_NOT_CONNECT_DIALOG_TEXT = Verbindung zum Server nicht möglich!\n\nDie Verbindung zum Server konnte auch nach {0,number,integer} wiederholten Verbindungsversuchen nicht hergestellt werden.\nBitte überprüfen Sie ob der Server läuft und über das Netzwerk erreichbar ist.

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!

Expand Down

0 comments on commit f789b8c

Please sign in to comment.