diff --git a/src/main/java/envoy/client/ui/ChatSceneController.java b/src/main/java/envoy/client/ui/ChatSceneController.java
index bcf8a19..14b1a7e 100644
--- a/src/main/java/envoy/client/ui/ChatSceneController.java
+++ b/src/main/java/envoy/client/ui/ChatSceneController.java
@@ -11,6 +11,7 @@ import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
+import javafx.scene.paint.Color;
import envoy.client.data.Chat;
import envoy.client.data.LocalDB;
@@ -56,6 +57,9 @@ public final class ChatSceneController {
@FXML
private TextArea messageTextArea;
+ @FXML
+ private Label remainingChars;
+
private LocalDB localDB;
private Client client;
private WriteProxy writeProxy;
@@ -63,9 +67,10 @@ public final class ChatSceneController {
private Chat currentChat;
- private static final Settings settings = Settings.getInstance();
- private static final EventBus eventBus = EventBus.getInstance();
- private static final Logger logger = EnvoyLog.getLogger(ChatSceneController.class);
+ private static final Settings settings = Settings.getInstance();
+ private static final EventBus eventBus = EventBus.getInstance();
+ private static final Logger logger = EnvoyLog.getLogger(ChatSceneController.class);
+ private static final int MAX_MESSAGE_LENGTH = 255;
@FXML
private void initialize() {
@@ -138,6 +143,10 @@ public final class ChatSceneController {
.orElseGet(() -> { final var chat = new Chat(user); localDB.getChats().add(chat); return chat; });
messageList.setItems(FXCollections.observableList(currentChat.getMessages()));
+
+ remainingChars.setVisible(true);
+ remainingChars
+ .setText(String.format("remaining chars: %d/%d", MAX_MESSAGE_LENGTH - messageTextArea.getText().length(), MAX_MESSAGE_LENGTH));
}
messageTextArea.setDisable(currentChat == null);
}
@@ -167,10 +176,27 @@ public final class ChatSceneController {
@FXML
private void messageTextUpdated(KeyEvent e) {
+ // TODO: Letting go of ctrl automatically posts a message. Needs to be fixed
+ // soon.
+
+ // Automatic sending of messages via (ctrl +) enter
if (!postButton.isDisabled() && settings.isEnterToSend() && e.getCode() == KeyCode.ENTER
|| !settings.isEnterToSend() && e.getCode() == KeyCode.CONTROL)
postMessage();
else postButton.setDisable(messageTextArea.getText().isBlank() || currentChat == null);
+
+ // Truncating messages that are too long and staying at the same position
+ if (messageTextArea.getText().length() >= MAX_MESSAGE_LENGTH) {
+ messageTextArea.setText(messageTextArea.getText().substring(0, MAX_MESSAGE_LENGTH));
+ messageTextArea.positionCaret(MAX_MESSAGE_LENGTH);
+ messageTextArea.setScrollTop(Double.MAX_VALUE);
+ }
+
+ // Redesigning the remainingChars - Label
+ final int currentLength = messageTextArea.getText().length();
+ final int remainingLength = MAX_MESSAGE_LENGTH - currentLength;
+ remainingChars.setText(String.format("remaining chars: %d/%d", remainingLength, MAX_MESSAGE_LENGTH));
+ remainingChars.setTextFill(Color.rgb(currentLength, remainingLength, 0, 1));
}
/**
diff --git a/src/main/resources/fxml/ChatScene.fxml b/src/main/resources/fxml/ChatScene.fxml
index cd18dd8..6f2b0b8 100644
--- a/src/main/resources/fxml/ChatScene.fxml
+++ b/src/main/resources/fxml/ChatScene.fxml
@@ -17,8 +17,8 @@
-
-
+
+
@@ -27,7 +27,7 @@
-
+
+