From 46f8b1e76732b231a129ef527253bad99909d3e7 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Wed, 10 Jun 2020 10:05:25 +0200 Subject: [PATCH 1/3] Adjust stage size after changing the scene --- src/main/java/envoy/client/ui/SceneContext.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/envoy/client/ui/SceneContext.java b/src/main/java/envoy/client/ui/SceneContext.java index 0c40bf3..c191d8e 100644 --- a/src/main/java/envoy/client/ui/SceneContext.java +++ b/src/main/java/envoy/client/ui/SceneContext.java @@ -108,6 +108,7 @@ public final class SceneContext { sceneStack.push(scene); stage.setScene(scene); applyCSS(); + stage.sizeToScene(); stage.show(); } catch (IOException e) { throw new RuntimeException(e); @@ -124,6 +125,7 @@ public final class SceneContext { if (!sceneStack.isEmpty()) { stage.setScene(sceneStack.peek()); applyCSS(); + stage.sizeToScene(); } stage.show(); } From 367a690dc88fd1d0dd7cfcbd5a93d00021280680 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Wed, 10 Jun 2020 11:05:28 +0200 Subject: [PATCH 2/3] Replace UserStatusChangeProcessor with inline code in ChatScene --- src/main/java/envoy/client/net/Client.java | 2 +- .../client/net/UserStatusChangeProcessor.java | 33 ------------------- .../envoy/client/ui/controller/ChatScene.java | 15 ++++++--- 3 files changed, 12 insertions(+), 38 deletions(-) delete mode 100644 src/main/java/envoy/client/net/UserStatusChangeProcessor.java diff --git a/src/main/java/envoy/client/net/Client.java b/src/main/java/envoy/client/net/Client.java index 0d09780..7aaf28b 100644 --- a/src/main/java/envoy/client/net/Client.java +++ b/src/main/java/envoy/client/net/Client.java @@ -141,7 +141,7 @@ public class Client implements Closeable { receiver.registerProcessor(MessageStatusChangeEvent.class, new MessageStatusChangeEventProcessor()); // Process user status changes - receiver.registerProcessor(UserStatusChangeEvent.class, new UserStatusChangeProcessor(localDB)); + receiver.registerProcessor(UserStatusChangeEvent.class, eventBus::dispatch); // Process message ID generation receiver.registerProcessor(IDGenerator.class, localDB::setIDGenerator); diff --git a/src/main/java/envoy/client/net/UserStatusChangeProcessor.java b/src/main/java/envoy/client/net/UserStatusChangeProcessor.java deleted file mode 100644 index 9120662..0000000 --- a/src/main/java/envoy/client/net/UserStatusChangeProcessor.java +++ /dev/null @@ -1,33 +0,0 @@ -package envoy.client.net; - -import java.util.function.Consumer; - -import envoy.client.data.LocalDB; -import envoy.data.User; -import envoy.event.EventBus; -import envoy.event.UserStatusChangeEvent; - -/** - * Project: envoy-client
- * File: UserStatusChangeProcessor.java
- * Created: 2 Feb 2020
- * - * @author Leon Hofmeister - * @since Envoy Client v0.3-alpha - */ -public class UserStatusChangeProcessor implements Consumer { - - private final LocalDB localDB; - - /** - * @param localDB the local database in which status updates will by applied - * @since Envoy Client v0.3-alpha - */ - public UserStatusChangeProcessor(LocalDB localDB) { this.localDB = localDB; } - - @Override - public void accept(UserStatusChangeEvent evt) { - localDB.getUsers().values().stream().filter(u -> u.getID() == evt.getID()).map(User.class::cast).findFirst().get().setStatus(evt.get()); - EventBus.getInstance().dispatch(evt); - } -} diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index 6fdbd2f..e57dedf 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -22,9 +22,7 @@ import envoy.client.net.WriteProxy; import envoy.client.ui.ContactListCell; import envoy.client.ui.MessageListCell; import envoy.client.ui.SceneContext; -import envoy.data.Contact; -import envoy.data.Message; -import envoy.data.MessageBuilder; +import envoy.data.*; import envoy.event.EventBus; import envoy.event.MessageStatusChangeEvent; import envoy.event.UserStatusChangeEvent; @@ -105,7 +103,16 @@ public final class ChatScene { }); // Listen to user status changes - eventBus.register(UserStatusChangeEvent.class, e -> Platform.runLater(userList::refresh)); + eventBus.register(UserStatusChangeEvent.class, e -> + userList.getItems() + .stream() + .filter(c -> c.getID() == e.getID()) + .findAny() + .ifPresent(u -> { + ((User) u).setStatus(e.get()); + Platform.runLater(userList::refresh); + }) + ); // Listen to contacts changes eventBus.register(ContactOperationEvent.class, e -> { From 9dade2cf77aebb723a7a43db63edcc9129bac3fd Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Wed, 10 Jun 2020 11:33:49 +0200 Subject: [PATCH 3/3] Properly override updateItem method of list cells --- src/main/java/envoy/client/ui/ContactListCell.java | 7 +++++-- src/main/java/envoy/client/ui/MessageListCell.java | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/envoy/client/ui/ContactListCell.java b/src/main/java/envoy/client/ui/ContactListCell.java index c3c51d4..5cb04ca 100644 --- a/src/main/java/envoy/client/ui/ContactListCell.java +++ b/src/main/java/envoy/client/ui/ContactListCell.java @@ -28,7 +28,10 @@ public class ContactListCell extends ListCell { @Override protected void updateItem(Contact contact, boolean empty) { super.updateItem(contact, empty); - if (!empty && contact != null) { + if (empty || contact == null) { + setText(null); + setGraphic(null); + } else { // the infoLabel displays specific contact info, i.e. status of a user or amount // of members in a group Label infoLabel = null; @@ -51,7 +54,7 @@ public class ContactListCell extends ListCell { break; } infoLabel.setTextFill(textColor); - } else + } else // group specific infos infoLabel = new Label(String.valueOf(((Group) contact).getContacts().size()) + " members"); setGraphic(new VBox(new Label(contact.getName()), infoLabel)); diff --git a/src/main/java/envoy/client/ui/MessageListCell.java b/src/main/java/envoy/client/ui/MessageListCell.java index 60a2ada..7b7a479 100644 --- a/src/main/java/envoy/client/ui/MessageListCell.java +++ b/src/main/java/envoy/client/ui/MessageListCell.java @@ -45,10 +45,15 @@ public class MessageListCell extends ListCell { @Override protected void updateItem(Message message, boolean empty) { super.updateItem(message, empty); - setGraphic(!empty && message != null ? new HBox( + if(empty || message == null) { + setText(null); + setGraphic(null); + } else { + setGraphic(new HBox( new VBox( new Label(dateFormat.format(message.getCreationDate())), new Label(message.getText())), - new Label("", new ImageView(statusImages.get(message.getStatus())))) : null); + new Label("", new ImageView(statusImages.get(message.getStatus()))))); + } } }