diff --git a/src/main/java/envoy/client/ui/listcell/ContactControl.java b/src/main/java/envoy/client/ui/listcell/ChatControl.java similarity index 55% rename from src/main/java/envoy/client/ui/listcell/ContactControl.java rename to src/main/java/envoy/client/ui/listcell/ChatControl.java index b13b51e..444d3e5 100644 --- a/src/main/java/envoy/client/ui/listcell/ContactControl.java +++ b/src/main/java/envoy/client/ui/listcell/ChatControl.java @@ -1,7 +1,8 @@ package envoy.client.ui.listcell; +import javafx.geometry.Pos; import javafx.scene.control.Label; -import javafx.scene.layout.VBox; +import javafx.scene.layout.*; import envoy.data.Contact; import envoy.data.Group; @@ -17,27 +18,38 @@ import envoy.data.User; * @author Leon Hofmeister * @since Envoy Client v0.1-beta */ -public class ContactControl extends VBox { +public class ChatControl extends HBox { /** * @param contact the contact that should be formatted * @since Envoy Client v0.1-beta */ - public ContactControl(Contact contact, int unreadMessagesAmount) { + public ChatControl(Contact contact, int unreadMessagesAmount) { // Container with contact name + final var vBox = new VBox(); final var nameLabel = new Label(contact.getName()); nameLabel.setWrapText(true); - getChildren().add(nameLabel); + vBox.getChildren().add(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()); - getChildren().add(statusLabel); + vBox.getChildren().add(statusLabel); } else // Member count - getChildren().add(new Label(((Group) contact).getContacts().size() + " members")); - + vBox.getChildren().add(new Label(((Group) contact).getContacts().size() + " members")); + + getChildren().add(vBox); + Region spacing = new Region(); + setHgrow(spacing, Priority.ALWAYS); + getChildren().add(spacing); final var unreadMessagesLabel = new Label("" + unreadMessagesAmount); - getChildren().add(unreadMessagesLabel); + unreadMessagesLabel.setMinSize(15, 15); + var vBox2 = new VBox(); + vBox2.setAlignment(Pos.CENTER_RIGHT); + unreadMessagesLabel.setAlignment(Pos.CENTER); + unreadMessagesLabel.getStyleClass().add("unreadMessagesAmount"); + vBox2.getChildren().add(unreadMessagesLabel); + getChildren().add(vBox2); } } diff --git a/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java b/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java index 117a8b4..9379bfe 100644 --- a/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java +++ b/src/main/java/envoy/client/ui/listcell/ContactListCellFactory.java @@ -16,7 +16,6 @@ import envoy.client.data.Chat; public class ContactListCellFactory extends ListCell { private final ListView listView; - private Boolean displayUnreadMessagesAmount = false; /** * @param listView the list view inside which this cell is contained @@ -24,8 +23,6 @@ public class ContactListCellFactory extends ListCell { */ public ContactListCellFactory(ListView listView) { this.listView = listView; } - public void displayUnreadMessagesAmount() { displayUnreadMessagesAmount = true; } - /** * Displays the name of a contact. If the contact is a user, their online status * is displayed as well. @@ -39,7 +36,7 @@ public class ContactListCellFactory extends ListCell { setText(null); setGraphic(null); } else { - final var control = new ContactControl(chat.getRecipient(), chat.getUnreadAmount()); + final var control = new ChatControl(chat.getRecipient(), chat.getUnreadAmount()); prefWidthProperty().bind(listView.widthProperty().subtract(40)); setGraphic(control); } diff --git a/src/main/resources/css/base.css b/src/main/resources/css/base.css index 2830bc6..78fff9e 100644 --- a/src/main/resources/css/base.css +++ b/src/main/resources/css/base.css @@ -58,6 +58,13 @@ -fx-text-alignment: left; } +.unreadMessagesAmount { + -fx-alignment: center; + -fx-background-color: orange; + -fx-background-radius: 4.0em; + -fx-text-alignment: center; +} + #remainingCharsLabel { -fx-text-fill: #00FF00; -fx-background-color: transparent;