diff --git a/client/src/main/java/envoy/client/ui/listcell/ChatControl.java b/client/src/main/java/envoy/client/ui/listcell/ChatControl.java index 98294a7..c2e942c 100644 --- a/client/src/main/java/envoy/client/ui/listcell/ChatControl.java +++ b/client/src/main/java/envoy/client/ui/listcell/ChatControl.java @@ -5,17 +5,16 @@ import javafx.scene.control.Label; import javafx.scene.layout.*; import envoy.client.data.Chat; -import envoy.data.Contact; -import envoy.data.Group; -import envoy.data.User; /** - * This class formats a single {@link Contact} into a UI component. + * Displays a chat using a contact control for the recipient and a label for the + * unread message count. *
* Project: envoy-client
* File: ContactControl.java
* Created: 01.07.2020
*
+ * @see ContactControl
* @author Leon Hofmeister
* @since Envoy Client v0.1-beta
*/
@@ -26,21 +25,11 @@ public class ChatControl extends HBox {
* @since Envoy Client v0.1-beta
*/
public ChatControl(Chat chat) {
- // Container with contact name
- final var vBox = new VBox();
- final var nameLabel = new Label(chat.getRecipient().getName());
- nameLabel.setWrapText(true);
- vBox.getChildren().add(nameLabel);
- if (chat.getRecipient() instanceof User) {
- // Online status
- final var user = (User) chat.getRecipient();
- final var statusLabel = new Label(user.getStatus().toString());
- statusLabel.getStyleClass().add(user.getStatus().toString().toLowerCase());
- vBox.getChildren().add(statusLabel);
- } else // Member count
- vBox.getChildren().add(new Label(((Group) chat.getRecipient()).getContacts().size() + " members"));
-
- getChildren().add(vBox);
+
+ // Contact control
+ getChildren().add(new ContactControl(chat.getRecipient()));
+
+ // Unread messages
if (chat.getUnreadAmount() != 0) {
Region spacing = new Region();
setHgrow(spacing, Priority.ALWAYS);
diff --git a/client/src/main/java/envoy/client/ui/listcell/ContactControl.java b/client/src/main/java/envoy/client/ui/listcell/ContactControl.java
new file mode 100644
index 0000000..c573e69
--- /dev/null
+++ b/client/src/main/java/envoy/client/ui/listcell/ContactControl.java
@@ -0,0 +1,44 @@
+package envoy.client.ui.listcell;
+
+import javafx.scene.control.Label;
+import javafx.scene.layout.VBox;
+
+import envoy.data.Contact;
+import envoy.data.User;
+
+/**
+ * Displays information about a contact in two rows. The first row contains the
+ * name. The second row contains the online status (user) or the member count
+ * (group).
+ *
+ * Project: envoy-client
+ * File: ContactControl.java
+ * Created: 13.07.2020
+ *
+ * @author Kai S. K. Engelbart
+ * @since Envoy Client v0.2-beta
+ */
+public class ContactControl extends VBox {
+
+ /**
+ * @param contact the contact to display
+ * @since Envoy Client v0.2-beta
+ */
+ public ContactControl(Contact contact) {
+
+ // Name label
+ final var nameLabel = new Label(contact.getName());
+ nameLabel.setWrapText(true);
+ getChildren().add(nameLabel);
+
+ // Online status (user) or member count (group)
+ if (contact instanceof User) {
+ final var status = ((User) contact).getStatus().toString();
+ final var statusLabel = new Label(status);
+ statusLabel.getStyleClass().add(status.toLowerCase());
+ getChildren().add(statusLabel);
+ } else {
+ getChildren().add(new Label(contact.getContacts().size() + " members"));
+ }
+ }
+}