From 90df62783187cf7c77defee204acc137f6305e81 Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 26 Jun 2020 23:16:03 +0200 Subject: [PATCH 1/3] Implemented notification of user if he can no longer send messages This only occurs when he is in offline mode and runs out of messageIDs to use. Additionally implemented: - automatically disabled user of posting after that condition is reached - an infoLabel used to commjunicate some events with the user - (in parts) a new UI design --- .../envoy/client/ui/controller/ChatScene.java | 39 +++++++++-- .../client/ui/controller/LoginScene.java | 8 +-- src/main/resources/fxml/ChatScene.fxml | 70 +++++++++++-------- 3 files changed, 78 insertions(+), 39 deletions(-) diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index 3f6188f..087a23d 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -16,6 +16,7 @@ import javafx.scene.image.ImageView; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; import javafx.scene.paint.Color; +import javafx.scene.paint.Paint; import envoy.client.data.Chat; import envoy.client.data.LocalDB; @@ -62,6 +63,9 @@ public final class ChatScene { @FXML private Label remainingChars; + @FXML + private Label infoLabel; + @FXML private MenuItem deleteContactMenuItem; @@ -70,6 +74,8 @@ public final class ChatScene { private WriteProxy writeProxy; private SceneContext sceneContext; + private boolean postingPermanentlyDisabled = false; + private Chat currentChat; private static final Settings settings = Settings.getInstance(); @@ -165,6 +171,7 @@ public final class ChatScene { userList.setItems(FXCollections.observableList(localDB.getChats().stream().map(Chat::getRecipient).collect(Collectors.toList()))); contactLabel.setText(localDB.getUser().getName()); MessageListCell.setUser(localDB.getUser()); + if (!client.isOnline()) updateInfoLabel("You are offline", Color.YELLOW); } /** @@ -244,10 +251,15 @@ public final class ChatScene { */ @FXML private void checkPostConditions(KeyEvent e) { - if (!postButton.isDisabled() && (settings.isEnterToSend() && e.getCode() == KeyCode.ENTER - || !settings.isEnterToSend() && e.getCode() == KeyCode.ENTER && e.isControlDown())) - postMessage(); - postButton.setDisable(messageTextArea.getText().isBlank() || currentChat == null); + if (!postingPermanentlyDisabled) { + if (!postButton.isDisabled() && (settings.isEnterToSend() && e.getCode() == KeyCode.ENTER + || !settings.isEnterToSend() && e.getCode() == KeyCode.ENTER && e.isControlDown())) + postMessage(); + postButton.setDisable(messageTextArea.getText().isBlank() || currentChat == null); + } else if (!infoLabel.getText().equals("You need to go online to send more messages")) + // Informing the user that he is a f*cking moron and should use Envoy online + // because he ran out of messageIDs to use + updateInfoLabel("You need to go online to send more messages", Color.RED); } /** @@ -286,6 +298,12 @@ public final class ChatScene { */ @FXML private void postMessage() { + postingPermanentlyDisabled = !(client.isOnline() || localDB.getIDGenerator().hasNext()); + if (postingPermanentlyDisabled) { + postButton.setDisable(true); + updateInfoLabel("You need to go online to send more messages", Color.RED); + return; + } final var text = messageTextArea.getText().strip(); if (text.isBlank()) throw new IllegalArgumentException("A message without visible text can not be sent."); try { @@ -322,6 +340,19 @@ public final class ChatScene { */ private void scrollToMessageListEnd() { messageList.scrollTo(messageList.getItems().size() - 1); } + /** + * Updates the {@code infoLabel}. + * + * @param text the text to use + * @param textfill the color in which to display information + * @since Envoy Client v0.1-beta + */ + private void updateInfoLabel(String text, Paint textfill) { + infoLabel.setText(text); + infoLabel.setTextFill(textfill); + infoLabel.setVisible(true); + } + // Context menu actions @FXML diff --git a/src/main/java/envoy/client/ui/controller/LoginScene.java b/src/main/java/envoy/client/ui/controller/LoginScene.java index b17fa81..020bd43 100644 --- a/src/main/java/envoy/client/ui/controller/LoginScene.java +++ b/src/main/java/envoy/client/ui/controller/LoginScene.java @@ -115,8 +115,7 @@ public final class LoginScene { if (registerCheckBox.isSelected() && !passwordField.getText().equals(repeatPasswordField.getText())) { new Alert(AlertType.ERROR, "The entered password is unequal to the repeated one").showAndWait(); repeatPasswordField.clear(); - } - else performHandshake( + } else performHandshake( new LoginCredentials(userTextField.getText(), passwordField.getText().toCharArray(), registerCheckBox.isSelected(), Startup.VERSION)); } @@ -190,9 +189,8 @@ public final class LoginScene { localDB.synchronize(); - if (client.isOnline()) { - writeProxy.flushCache(); - } else + if (client.isOnline()) writeProxy.flushCache(); + else // Set all contacts to offline mode localDB.getChats() .stream() diff --git a/src/main/resources/fxml/ChatScene.fxml b/src/main/resources/fxml/ChatScene.fxml index 0a65449..fa1a4ef 100644 --- a/src/main/resources/fxml/ChatScene.fxml +++ b/src/main/resources/fxml/ChatScene.fxml @@ -19,27 +19,27 @@ fx:controller="envoy.client.ui.controller.ChatScene"> - + + minHeight="10.0" percentHeight="7.0" vgrow="SOMETIMES" /> + @@ -56,7 +56,7 @@ + mnemonicParsing="false" onAction="#deleteContact" text="Delete" /> @@ -72,8 +72,8 @@ @@ -93,25 +93,25 @@ - - - - + + + + + From 3e4e7a1a4084307fdb281c7715d16816db057ea1 Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 26 Jun 2020 23:36:14 +0200 Subject: [PATCH 2/3] Cleaned up Envoy client: no more

, is now

...and some other funny mistakes found in Javadoc --- src/main/java/envoy/client/data/Chat.java | 6 +++--- src/main/java/envoy/client/data/ClientConfig.java | 4 ++-- src/main/java/envoy/client/data/LocalDB.java | 4 ++-- src/main/java/envoy/client/data/PersistentLocalDB.java | 4 ++-- src/main/java/envoy/client/data/Settings.java | 4 ++-- src/main/java/envoy/client/data/SettingsItem.java | 4 ++-- src/main/java/envoy/client/data/TransientLocalDB.java | 4 ++-- src/main/java/envoy/client/event/SendEvent.java | 1 - src/main/java/envoy/client/net/Client.java | 4 ++-- src/main/java/envoy/client/net/WriteProxy.java | 4 ++-- src/main/java/envoy/client/ui/IconUtil.java | 10 +++++----- .../java/envoy/client/ui/settings/package-info.java | 4 ++-- 12 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/main/java/envoy/client/data/Chat.java b/src/main/java/envoy/client/data/Chat.java index 022904c..7ca11ce 100644 --- a/src/main/java/envoy/client/data/Chat.java +++ b/src/main/java/envoy/client/data/Chat.java @@ -12,9 +12,9 @@ import envoy.data.Message.MessageStatus; import envoy.event.MessageStatusChange; /** - * Represents a chat between two {@link User}s
+ * Represents a chat between two {@link User}s * as a list of {@link Message} objects. - *
+ *

* Project: envoy-client
* File: Chat.java
* Created: 19 Oct 2019
@@ -32,7 +32,7 @@ public final class Chat implements Serializable { private static final long serialVersionUID = 1L; /** - * Provides the list of messages that the recipient receives.
+ * Provides the list of messages that the recipient receives.

* Saves the Messages in the corresponding chat at that Point. * * @param recipient the user who receives the messages diff --git a/src/main/java/envoy/client/data/ClientConfig.java b/src/main/java/envoy/client/data/ClientConfig.java index cde6b9a..a30dffb 100644 --- a/src/main/java/envoy/client/data/ClientConfig.java +++ b/src/main/java/envoy/client/data/ClientConfig.java @@ -11,8 +11,8 @@ import envoy.data.LoginCredentials; /** * Implements a configuration specific to the Envoy Client with default values - * and convenience methods.
- *
+ * and convenience methods. + *

* Project: envoy-client
* File: ClientConfig.java
* Created: 01.03.2020
diff --git a/src/main/java/envoy/client/data/LocalDB.java b/src/main/java/envoy/client/data/LocalDB.java index 66407fc..d8993f5 100644 --- a/src/main/java/envoy/client/data/LocalDB.java +++ b/src/main/java/envoy/client/data/LocalDB.java @@ -9,8 +9,8 @@ import envoy.event.NameChange; /** * Stores information about the current {@link User} and their {@link Chat}s. - * For message ID generation a {@link IDGenerator} is stored as well.
- *
+ * For message ID generation a {@link IDGenerator} is stored as well. + *

* Project: envoy-client
* File: LocalDB.java
* Created: 3 Feb 2020
diff --git a/src/main/java/envoy/client/data/PersistentLocalDB.java b/src/main/java/envoy/client/data/PersistentLocalDB.java index 5e13dd4..cc6cad9 100644 --- a/src/main/java/envoy/client/data/PersistentLocalDB.java +++ b/src/main/java/envoy/client/data/PersistentLocalDB.java @@ -11,8 +11,8 @@ import envoy.util.SerializationUtils; /** * Implements a {@link LocalDB} in a way that stores all information inside a - * folder on the local file system.
- *
+ * folder on the local file system. + *

* Project: envoy-client
* File: PersistentLocalDB.java
* Created: 27.10.2019
diff --git a/src/main/java/envoy/client/data/Settings.java b/src/main/java/envoy/client/data/Settings.java index c8bed6a..9d43bca 100644 --- a/src/main/java/envoy/client/data/Settings.java +++ b/src/main/java/envoy/client/data/Settings.java @@ -11,8 +11,8 @@ import envoy.util.SerializationUtils; /** * Manages all application settings, which are different objects that can be * changed during runtime and serialized them by using either the file system or - * the {@link Preferences} API.
- *
+ * the {@link Preferences} API. + *

* Project: envoy-client
* File: Settings.java
* Created: 11 Nov 2019
diff --git a/src/main/java/envoy/client/data/SettingsItem.java b/src/main/java/envoy/client/data/SettingsItem.java index 8638c05..d74e222 100644 --- a/src/main/java/envoy/client/data/SettingsItem.java +++ b/src/main/java/envoy/client/data/SettingsItem.java @@ -7,8 +7,8 @@ import javax.swing.JComponent; /** * Encapsulates a persistent value that is directly or indirectly mutable by the - * user.
- *
+ * user. + *

* Project: envoy-client
* File: SettingsItem.java
* Created: 23.12.2019
diff --git a/src/main/java/envoy/client/data/TransientLocalDB.java b/src/main/java/envoy/client/data/TransientLocalDB.java index ef592fb..5c7d2a6 100644 --- a/src/main/java/envoy/client/data/TransientLocalDB.java +++ b/src/main/java/envoy/client/data/TransientLocalDB.java @@ -2,8 +2,8 @@ package envoy.client.data; /** * Implements a {@link LocalDB} in a way that does not persist any information - * after application shutdown.
- *
+ * after application shutdown. + *

* Project: envoy-client
* File: TransientLocalDB.java
* Created: 3 Feb 2020
diff --git a/src/main/java/envoy/client/event/SendEvent.java b/src/main/java/envoy/client/event/SendEvent.java index e3c9f97..8ea650b 100644 --- a/src/main/java/envoy/client/event/SendEvent.java +++ b/src/main/java/envoy/client/event/SendEvent.java @@ -8,7 +8,6 @@ import envoy.event.Event; * Created: 11.02.2020
* * @author: Maximilian Käfer - * * @since Envoy Client v0.3-alpha */ public class SendEvent extends Event> { diff --git a/src/main/java/envoy/client/net/Client.java b/src/main/java/envoy/client/net/Client.java index 34384ec..5cf432a 100644 --- a/src/main/java/envoy/client/net/Client.java +++ b/src/main/java/envoy/client/net/Client.java @@ -20,8 +20,8 @@ import envoy.util.SerializationUtils; /** * Establishes a connection to the server, performs a handshake and delivers - * certain objects to the server.
- *
+ * certain objects to the server. + *

* Project: envoy-client
* File: Client.java
* Created: 28 Sep 2019
diff --git a/src/main/java/envoy/client/net/WriteProxy.java b/src/main/java/envoy/client/net/WriteProxy.java index 90e49e0..339f1f2 100644 --- a/src/main/java/envoy/client/net/WriteProxy.java +++ b/src/main/java/envoy/client/net/WriteProxy.java @@ -12,8 +12,8 @@ import envoy.util.EnvoyLog; /** * Implements methods to send {@link Message}s and * {@link MessageStatusChange}s to the server or cache them inside a - * {@link LocalDB} depending on the online status.
- *
+ * {@link LocalDB} depending on the online status. + *

* Project: envoy-client
* File: WriteProxy.java
* Created: 6 Feb 2020
diff --git a/src/main/java/envoy/client/ui/IconUtil.java b/src/main/java/envoy/client/ui/IconUtil.java index e2577ec..cdb99c5 100644 --- a/src/main/java/envoy/client/ui/IconUtil.java +++ b/src/main/java/envoy/client/ui/IconUtil.java @@ -8,11 +8,11 @@ import javafx.scene.image.Image; /** * Provides static utility methods for loading icons from the resource - * folder.
- *
- * Project: envoy-client - * File: IconUtil.java - * Created: 16.03.2020 + * folder. + *

+ * Project: envoy-client
+ * File: IconUtil.java
+ * Created: 16.03.2020
* * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta diff --git a/src/main/java/envoy/client/ui/settings/package-info.java b/src/main/java/envoy/client/ui/settings/package-info.java index f31317e..e908b93 100644 --- a/src/main/java/envoy/client/ui/settings/package-info.java +++ b/src/main/java/envoy/client/ui/settings/package-info.java @@ -1,7 +1,7 @@ /** * This package contains classes used for representing the settings - * visually.
- *
+ * visually. + *

* Project: envoy-client
* File: package-info.java
* Created: 19 Apr 2020
From 78b560cddd5ca60a35a51ec249f713db51c9cecc Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 27 Jun 2020 09:34:30 +0200 Subject: [PATCH 3/3] Made postingPermanentlyDisabled further idiot-proof Additionally deleted annoying alert notifying me that I'm offline. --- .../envoy/client/ui/controller/ChatScene.java | 15 ++++++++++----- .../envoy/client/ui/controller/LoginScene.java | 1 - 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index 087a23d..66d8305 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -204,7 +204,7 @@ public final class ChatScene { remainingChars .setText(String.format("remaining chars: %d/%d", MAX_MESSAGE_LENGTH - messageTextArea.getText().length(), MAX_MESSAGE_LENGTH)); } - messageTextArea.setDisable(currentChat == null); + messageTextArea.setDisable(currentChat == null || postingPermanentlyDisabled); } /** @@ -256,10 +256,13 @@ public final class ChatScene { || !settings.isEnterToSend() && e.getCode() == KeyCode.ENTER && e.isControlDown())) postMessage(); postButton.setDisable(messageTextArea.getText().isBlank() || currentChat == null); - } else if (!infoLabel.getText().equals("You need to go online to send more messages")) - // Informing the user that he is a f*cking moron and should use Envoy online - // because he ran out of messageIDs to use - updateInfoLabel("You need to go online to send more messages", Color.RED); + } else { + final var noMoreMessaging = "Go online to send messages"; + if (!infoLabel.getText().equals(noMoreMessaging)) + // Informing the user that he is a f*cking moron and should use Envoy online + // because he ran out of messageIDs to use + updateInfoLabel(noMoreMessaging, Color.RED); + } } /** @@ -301,6 +304,8 @@ public final class ChatScene { postingPermanentlyDisabled = !(client.isOnline() || localDB.getIDGenerator().hasNext()); if (postingPermanentlyDisabled) { postButton.setDisable(true); + messageTextArea.setDisable(true); + messageTextArea.clear(); updateInfoLabel("You need to go online to send more messages", Color.RED); return; } diff --git a/src/main/java/envoy/client/ui/controller/LoginScene.java b/src/main/java/envoy/client/ui/controller/LoginScene.java index 020bd43..2bae2dc 100644 --- a/src/main/java/envoy/client/ui/controller/LoginScene.java +++ b/src/main/java/envoy/client/ui/controller/LoginScene.java @@ -159,7 +159,6 @@ public final class LoginScene { final User clientUser = (User) localDB.getUsers().get(credentials.getIdentifier()); if (clientUser == null) throw new EnvoyException("Could not enter offline mode: user name unknown"); client.setSender(clientUser); - new Alert(AlertType.WARNING, "A connection to the server could not be established. Starting in offline mode.").showAndWait(); loadChatScene(); } catch (final Exception e) { new Alert(AlertType.ERROR, "Client error: " + e).showAndWait();