From 08e5fad42be48ca80e53a6d39c7afa32364c1492 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 27 Jun 2020 18:27:13 +0200 Subject: [PATCH] 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); } }