package envoy.client.ui.control; import javafx.scene.control.Label; import javafx.scene.layout.VBox; import envoy.data.*; /** * 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). * * @author Kai S. K. Engelbart * @since Envoy Client v0.2-beta */ public final class ContactControl extends VBox { private final Contact contact; /** * @param contact the contact to display * @since Envoy Client v0.2-beta */ public ContactControl(Contact contact) { this.contact = contact; // Name label final var nameLabel = new Label(contact.getName()); getChildren().add(nameLabel); // Online status (user) or member count (group) getChildren().add(contact instanceof User ? new UserStatusLabel((User) contact) : new GroupSizeLabel((Group) contact)); getStyleClass().add("list-element"); } /** * Replaces the info label of this {@code ContactControl} with an updated version. *

* This method should be called when the status of the underlying user or the size of the * underlying group has changed. * * @since Envoy Client v0.3-beta * @apiNote will produce buggy results if contact control gets updated so that the info label is * no longer on index 1. */ public void replaceInfoLabel() { getChildren().set(1, contact instanceof User ? new UserStatusLabel((User) contact) : new GroupSizeLabel((Group) contact)); } }