From 2af098fb280a3ba0e4c0810b8acbe6cc52ccbc16 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 1 Aug 2020 09:54:18 +0200 Subject: [PATCH] Added ability to change the user name on the client side --- .../client/ui/settings/UserSettingsPane.java | 21 ++++++++++++++++++- .../src/main/java/envoy/server/Startup.java | 3 ++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/client/src/main/java/envoy/client/ui/settings/UserSettingsPane.java b/client/src/main/java/envoy/client/ui/settings/UserSettingsPane.java index becc699..993b6bf 100644 --- a/client/src/main/java/envoy/client/ui/settings/UserSettingsPane.java +++ b/client/src/main/java/envoy/client/ui/settings/UserSettingsPane.java @@ -1,7 +1,11 @@ package envoy.client.ui.settings; +import javafx.event.EventHandler; import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.TextField; +import javafx.scene.input.InputEvent; +import javafx.scene.layout.HBox; import envoy.client.event.SendEvent; import envoy.client.ui.SceneContext; @@ -30,7 +34,22 @@ public class UserSettingsPane extends SettingsPane { * @param user the user who wants to customize his profile * @since Envoy Client v0.2-beta */ - public UserSettingsPane(SceneContext sceneContext, User user) { super("User"); } + public UserSettingsPane(SceneContext sceneContext, User user) { + super("User"); // Display of profile picture change mechanism + final var hbox = new HBox(); + + // Displaying the username change mechanism + final var username = user.getName(); + final var usernameTextField = new TextField(username); + final EventHandler textChanged = e -> { + newUsername = usernameTextField.getText(); + usernameChanged = newUsername != username; + }; + usernameTextField.setOnInputMethodTextChanged(textChanged); + usernameTextField.setOnKeyTyped(textChanged); + hbox.getChildren().add(usernameTextField); + vbox.getChildren().add(hbox); + } /** * Saves the given input and sends the changed input to the server diff --git a/server/src/main/java/envoy/server/Startup.java b/server/src/main/java/envoy/server/Startup.java index ac24c40..bd00a66 100755 --- a/server/src/main/java/envoy/server/Startup.java +++ b/server/src/main/java/envoy/server/Startup.java @@ -70,7 +70,8 @@ public class Startup { new IDGeneratorRequestProcessor(), new UserSearchProcessor(), new ContactOperationProcessor(), - new IsTypingProcessor()))); + new IsTypingProcessor(), + new NameChangeProcessor()))); // Initialize the current message ID final PersistenceManager persistenceManager = PersistenceManager.getInstance();