parent
c6e28aba10
commit
25b9103e23
@ -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<Message> {
|
||||
|
||||
private final ListView<Message> listView;
|
||||
|
||||
private static User client;
|
||||
private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm");
|
||||
private static final Map<MessageStatus, Image> 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<Message> 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<Message> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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)));
|
||||
|
Reference in New Issue
Block a user