package envoy.client.ui.listcell; import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.scene.control.Tooltip; import javafx.stage.PopupWindow.AnchorLocation; import envoy.data.Message; /** * Displays a single message inside the message list. *

* Project: envoy-client
* File: MessageListCellFactory.java
* Created: 28.03.2020
* * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta */ public class MessageListCellFactory extends ListCell { private final ListView listView; /** * @param listView the list view inside which this cell is contained * @since Envoy Client v0.1-beta */ public MessageListCellFactory(ListView listView) { this.listView = listView; } /** * Displays the text, the data of creation and the status of a message. * * @since Envoy v0.1-beta */ @Override protected void updateItem(Message message, boolean empty) { super.updateItem(message, empty); if (empty || message == null) { setText(null); setGraphic(null); } else { final var control = new MessageControl(message); control.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(control); } } }