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
* Project: envoy-client
* Project: envoy-client
+ * Project: envoy-client
* 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
- *
+ * certain objects to the server.
+ *
* 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.
+ *
* 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 201fdbc..b477e53 100644
--- a/src/main/java/envoy/client/ui/IconUtil.java
+++ b/src/main/java/envoy/client/ui/IconUtil.java
@@ -7,11 +7,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.
+ *
+ * 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/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java
index b6da87c..91665c8 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();
@@ -161,6 +167,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);
}
/**
@@ -193,7 +200,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);
}
/**
@@ -240,10 +247,18 @@ 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 {
+ 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);
+ }
}
/**
@@ -282,6 +297,14 @@ public final class ChatScene {
*/
@FXML
private void postMessage() {
+ 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;
+ }
final var text = messageTextArea.getText().strip();
if (text.isBlank()) throw new IllegalArgumentException("A message without visible text can not be sent.");
try {
@@ -318,6 +341,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 01e456d..380842a 100644
--- a/src/main/java/envoy/client/ui/controller/LoginScene.java
+++ b/src/main/java/envoy/client/ui/controller/LoginScene.java
@@ -164,7 +164,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();
@@ -194,9 +193,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/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.
+ *
* File: package-info.java
* Created: 19 Apr 2020
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">