From 94dbf0481b07ed6c6106411118ee4d230c295d20 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Mon, 30 Mar 2020 21:27:07 +0200 Subject: [PATCH] Wrapping data into ObservableList instances instead of copying it --- .../java/envoy/client/ui/ChatSceneController.java | 11 +++-------- src/main/java/module-info.java | 1 + 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/java/envoy/client/ui/ChatSceneController.java b/src/main/java/envoy/client/ui/ChatSceneController.java index 805f9f7..1b68322 100644 --- a/src/main/java/envoy/client/ui/ChatSceneController.java +++ b/src/main/java/envoy/client/ui/ChatSceneController.java @@ -95,7 +95,7 @@ public final class ChatSceneController { this.writeProxy = writeProxy; // TODO: handle offline mode - userList.getItems().addAll(client.getContacts().getContacts()); + userList.setItems(FXCollections.observableList(client.getContacts().getContacts())); // userList.getItems().addAll(localDB.getChats().stream().map(Chat::getRecipient).collect(Collectors.toList())); } @@ -105,12 +105,6 @@ public final class ChatSceneController { if (user != null && (currentChat == null || user.getID() != currentChat.getRecipient().getID())) { contactLabel.setText(user.getName()); - // Swap observable list - if (currentChat != null) { - currentChat.getMessages().clear(); - currentChat.getMessages().addAll(messageList.getItems()); - } - // LEON: JFC <===> JAVA FRIED CHICKEN <=/=> Java Foundation Classes // Load the chat or create a new one and add it to the LocalDB @@ -119,7 +113,8 @@ public final class ChatSceneController { .filter(c -> c.getRecipient().getID() == user.getID()) .findAny() .orElseGet(() -> { var chat = new Chat(user); localDB.getChats().add(chat); return chat; }); - messageList.setItems(FXCollections.observableArrayList(currentChat.getMessages())); + + messageList.setItems(FXCollections.observableList(currentChat.getMessages())); } } diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index fc96e79..2de5fa8 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -16,6 +16,7 @@ module envoy { requires transitive java.prefs; requires javafx.controls; requires javafx.fxml; + requires javafx.base; opens envoy.client.ui to javafx.graphics, javafx.fxml; }