From 25b9103e236a179bcde20db0e6bea7cf08c596b7 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Sat, 27 Jun 2020 17:36:42 +0200 Subject: [PATCH] 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)));