From c6e28aba10fd27b799e806d9f02ed3ab4f48e20a Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Sat, 27 Jun 2020 17:14:07 +0200 Subject: [PATCH 1/4] Display status for own messages instead of received ones --- src/main/java/envoy/client/ui/MessageListCell.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/envoy/client/ui/MessageListCell.java b/src/main/java/envoy/client/ui/MessageListCell.java index 21a094e..dbb8e1d 100644 --- a/src/main/java/envoy/client/ui/MessageListCell.java +++ b/src/main/java/envoy/client/ui/MessageListCell.java @@ -43,7 +43,7 @@ public class MessageListCell extends ListCell { setGraphic(null); } else { final var cell = new VBox(new Label(dateFormat.format(message.getCreationDate())), new Label(message.getText())); - if (message.getRecipientID() == client.getID()) { + if (message.getRecipientID() != client.getID()) { cell.getChildren().add(new Label("", new ImageView(statusImages.get(message.getStatus())))); cell.getStyleClass().add("own-message"); } else cell.getStyleClass().add("received-message"); From 25b9103e236a179bcde20db0e6bea7cf08c596b7 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Sat, 27 Jun 2020 17:36:42 +0200 Subject: [PATCH 2/4] Bind message list cell width to message list width Fixes #156 --- .../java/envoy/client/ui/MessageListCell.java | 15 ++++++++++++++- .../envoy/client/ui/controller/ChatScene.java | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/envoy/client/ui/MessageListCell.java b/src/main/java/envoy/client/ui/MessageListCell.java index dbb8e1d..a5568c1 100644 --- a/src/main/java/envoy/client/ui/MessageListCell.java +++ b/src/main/java/envoy/client/ui/MessageListCell.java @@ -6,6 +6,7 @@ import java.util.Map; import javafx.geometry.Insets; import javafx.scene.control.Label; import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.VBox; @@ -26,10 +27,18 @@ import envoy.data.User; */ public class MessageListCell extends ListCell { + private final ListView listView; + private static User client; private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm"); private static final Map statusImages = IconUtil.loadByEnum(MessageStatus.class, 16); + /** + * @param listView the list view inside which this cell is contained + * @since Envoy Client v0.1-beta + */ + public MessageListCell(ListView listView) { this.listView = listView; } + /** * Displays the text, the data of creation and the status of a message. * @@ -42,12 +51,16 @@ public class MessageListCell extends ListCell { setText(null); setGraphic(null); } else { - final var cell = new VBox(new Label(dateFormat.format(message.getCreationDate())), new Label(message.getText())); + final var cell = new VBox(new Label(dateFormat.format(message.getCreationDate()))); + final var textLabel = new Label(message.getText()); + textLabel.setWrapText(true); + cell.getChildren().add(textLabel); if (message.getRecipientID() != client.getID()) { cell.getChildren().add(new Label("", new ImageView(statusImages.get(message.getStatus())))); cell.getStyleClass().add("own-message"); } else cell.getStyleClass().add("received-message"); cell.paddingProperty().setValue(new Insets(5, 20, 5, 20)); + cell.prefWidthProperty().bind(listView.widthProperty().subtract(40)); setGraphic(cell); } } diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index 91665c8..d1a6bfa 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -92,7 +92,7 @@ public final class ChatScene { private void initialize() { // Initialize message and user rendering - messageList.setCellFactory(listView -> new MessageListCell()); + messageList.setCellFactory(listView -> new MessageListCell(listView)); userList.setCellFactory(listView -> new ContactListCell()); settingsButton.setGraphic(new ImageView(IconUtil.load("/icons/settings.png", 16))); From e6ac95ac14e8a6e6dde6e172422f85afb2c31c50 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 27 Jun 2020 18:27:13 +0200 Subject: [PATCH 3/4] Fixed padding of status icon and implemented Tooltip Additionally added commentary in MessageListCell. --- .../java/envoy/client/ui/MessageListCell.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/envoy/client/ui/MessageListCell.java b/src/main/java/envoy/client/ui/MessageListCell.java index a5568c1..e33c502 100644 --- a/src/main/java/envoy/client/ui/MessageListCell.java +++ b/src/main/java/envoy/client/ui/MessageListCell.java @@ -4,12 +4,11 @@ import java.time.format.DateTimeFormatter; import java.util.Map; import javafx.geometry.Insets; -import javafx.scene.control.Label; -import javafx.scene.control.ListCell; -import javafx.scene.control.ListView; +import javafx.scene.control.*; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.VBox; +import javafx.stage.PopupWindow.AnchorLocation; import envoy.data.Message; import envoy.data.Message.MessageStatus; @@ -51,16 +50,26 @@ public class MessageListCell extends ListCell { setText(null); setGraphic(null); } else { + // Creating the underlying VBox, the dateLabel and the textLabel final var cell = new VBox(new Label(dateFormat.format(message.getCreationDate()))); final var textLabel = new Label(message.getText()); textLabel.setWrapText(true); cell.getChildren().add(textLabel); + // Setting the message status icon and background color if (message.getRecipientID() != client.getID()) { - cell.getChildren().add(new Label("", new ImageView(statusImages.get(message.getStatus())))); + final var statusIcon = new Label("", new ImageView(statusImages.get(message.getStatus()))); + statusIcon.setPadding(new Insets(1, 0, 5, 5)); + cell.getChildren().add(statusIcon); cell.getStyleClass().add("own-message"); } else cell.getStyleClass().add("received-message"); + // Adjusting height and weight of the cell to the corresponding ListView cell.paddingProperty().setValue(new Insets(5, 20, 5, 20)); cell.prefWidthProperty().bind(listView.widthProperty().subtract(40)); + // Creating the Tooltip to deselect a message + final var tooltip = new Tooltip("You can select a message by clicking on it \nand deselect it by pressing \"ctrl\" and clicking on it"); + tooltip.setWrapText(true); + tooltip.setAnchorLocation(AnchorLocation.WINDOW_TOP_LEFT); + setTooltip(tooltip); setGraphic(cell); } } From 18819a873fe1713936ab4c5aa6aaf53999a0a8f2 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 27 Jun 2020 18:44:57 +0200 Subject: [PATCH 4/4] Wrapped text in userList (as suggested by @CyB3RC0nN0R) It is nice to see that JavaFX is less prone to shittyness than Swing is. --- .../java/envoy/client/ui/ContactListCell.java | 18 ++++++++++++++---- .../envoy/client/ui/controller/ChatScene.java | 4 ++-- .../ui/controller/ContactSearchScene.java | 2 +- .../ui/controller/GroupCreationScene.java | 4 ++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main/java/envoy/client/ui/ContactListCell.java b/src/main/java/envoy/client/ui/ContactListCell.java index 283a89a..b13543b 100644 --- a/src/main/java/envoy/client/ui/ContactListCell.java +++ b/src/main/java/envoy/client/ui/ContactListCell.java @@ -2,6 +2,7 @@ package envoy.client.ui; import javafx.scene.control.Label; import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; import javafx.scene.layout.VBox; import envoy.data.Contact; @@ -18,6 +19,14 @@ import envoy.data.User; */ public class ContactListCell extends ListCell { + private final ListView listView; + + /** + * @param listView the list view inside which this cell is contained + * @since Envoy Client v0.1-beta + */ + public ContactListCell(ListView listView) { this.listView = listView; } + /** * Displays the name of a contact. If the contact is a user, their online status * is displayed as well. @@ -32,17 +41,18 @@ public class ContactListCell extends ListCell { setGraphic(null); } else { // Container with contact name - final var vbox = new VBox(new Label(contact.getName())); + final var nameLabel = new Label(contact.getName()); + nameLabel.setWrapText(true); + final var vbox = new VBox(nameLabel); if (contact instanceof User) { // Online status final var user = (User) contact; final var statusLabel = new Label(user.getStatus().toString()); statusLabel.getStyleClass().add(user.getStatus().toString().toLowerCase()); vbox.getChildren().add(statusLabel); - } else { - // Member count + } else // Member count vbox.getChildren().add(new Label(((Group) contact).getContacts().size() + " members")); - } + prefWidthProperty().bind(listView.widthProperty().subtract(40)); setGraphic(vbox); } } diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index d1a6bfa..c27a857 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -92,8 +92,8 @@ public final class ChatScene { private void initialize() { // Initialize message and user rendering - messageList.setCellFactory(listView -> new MessageListCell(listView)); - userList.setCellFactory(listView -> new ContactListCell()); + messageList.setCellFactory(MessageListCell::new); + userList.setCellFactory(ContactListCell::new); settingsButton.setGraphic(new ImageView(IconUtil.load("/icons/settings.png", 16))); diff --git a/src/main/java/envoy/client/ui/controller/ContactSearchScene.java b/src/main/java/envoy/client/ui/controller/ContactSearchScene.java index 54c505c..7e70a80 100644 --- a/src/main/java/envoy/client/ui/controller/ContactSearchScene.java +++ b/src/main/java/envoy/client/ui/controller/ContactSearchScene.java @@ -67,7 +67,7 @@ public class ContactSearchScene { @FXML private void initialize() { - contactList.setCellFactory(e -> new ContactListCell()); + contactList.setCellFactory(ContactListCell::new); eventBus.register(ContactSearchResult.class, response -> Platform.runLater(() -> { contactList.getItems().clear(); contactList.getItems().addAll(response.get()); })); } diff --git a/src/main/java/envoy/client/ui/controller/GroupCreationScene.java b/src/main/java/envoy/client/ui/controller/GroupCreationScene.java index c6d7d05..9234fa2 100644 --- a/src/main/java/envoy/client/ui/controller/GroupCreationScene.java +++ b/src/main/java/envoy/client/ui/controller/GroupCreationScene.java @@ -41,7 +41,7 @@ public class GroupCreationScene { @FXML private void initialize() { - contactList.setCellFactory(e -> new ContactListCell()); + contactList.setCellFactory(ContactListCell::new); contactList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); } @@ -59,7 +59,7 @@ public class GroupCreationScene { /** * Enables the {@code createButton} if at least one contact is selected. - * + * * @since Envoy Client v0.1-beta */ @FXML