From 256a5ac2100d9616cf2398d73f02009a0892df34 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Sun, 21 Jun 2020 17:25:24 +0200 Subject: [PATCH] Move user status color to CSS, refactor ContactListCell --- .../java/envoy/client/ui/ContactListCell.java | 38 ++++++------------- src/main/resources/css/base.css | 16 ++++++++ 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/main/java/envoy/client/ui/ContactListCell.java b/src/main/java/envoy/client/ui/ContactListCell.java index bf9f117..e52197d 100644 --- a/src/main/java/envoy/client/ui/ContactListCell.java +++ b/src/main/java/envoy/client/ui/ContactListCell.java @@ -31,33 +31,19 @@ public class ContactListCell extends ListCell { setText(null); setGraphic(null); } else { - // the infoLabel displays specific contact info, i.e. status of a user or amount - // of members in a group - Label infoLabel = null; + // Container with contact name + final var vbox = new VBox(new Label(contact.getName())); if (contact instanceof User) { - // user specific info - infoLabel = new Label(((User) contact).getStatus().toString()); - String textColor = null; - switch (((User) contact).getStatus()) { - case ONLINE: - textColor = "limegreen"; - break; - case AWAY: - textColor = "orangered"; - break; - case BUSY: - textColor = "red"; - break; - case OFFLINE: - textColor = "gray"; - break; - } - // infoLabel.setTextFill(textColor) does not work as it gets overridden by CSS; - infoLabel.setStyle("-fx-text-fill: " + textColor); - } else - // group specific infos - infoLabel = new Label(String.valueOf(((Group) contact).getContacts().size()) + " members"); - setGraphic(new VBox(new Label(contact.getName()), infoLabel)); + // Online status + final var user = (User) contact; + 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) contact).getContacts().size() + " members")); + } + setGraphic(vbox); } } } diff --git a/src/main/resources/css/base.css b/src/main/resources/css/base.css index 43b5c3a..79cefc9 100644 --- a/src/main/resources/css/base.css +++ b/src/main/resources/css/base.css @@ -12,3 +12,19 @@ -fx-opacity: 1; -fx-background-color: transparent; } + +.online { + -fx-text-fill: limegreen; +} + +.away { + -fx-text-fill: orangered; +} + +.busy { + -fx-text-fill: red; +} + +.offline { + -fx-text-fill: gray; +} \ No newline at end of file