Move user status color to CSS, refactor ContactListCell

This commit is contained in:
Kai S. K. Engelbart 2020-06-21 17:25:24 +02:00
parent d389637259
commit bb81ec6042
2 changed files with 28 additions and 26 deletions

View File

@ -31,33 +31,19 @@ public class ContactListCell extends ListCell<Contact> {
setText(null); setText(null);
setGraphic(null); setGraphic(null);
} else { } else {
// the infoLabel displays specific contact info, i.e. status of a user or amount // Container with contact name
// of members in a group final var vbox = new VBox(new Label(contact.getName()));
Label infoLabel = null;
if (contact instanceof User) { if (contact instanceof User) {
// user specific info // Online status
infoLabel = new Label(((User) contact).getStatus().toString()); final var user = (User) contact;
String textColor = null; final var statusLabel = new Label(user.getStatus().toString());
switch (((User) contact).getStatus()) { statusLabel.getStyleClass().add(user.getStatus().toString().toLowerCase());
case ONLINE: vbox.getChildren().add(statusLabel);
textColor = "limegreen"; } else {
break; // Member count
case AWAY: vbox.getChildren().add(new Label(((Group) contact).getContacts().size() + " members"));
textColor = "orangered"; }
break; setGraphic(vbox);
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));
} }
} }
} }

View File

@ -12,3 +12,19 @@
-fx-opacity: 1; -fx-opacity: 1;
-fx-background-color: transparent; -fx-background-color: transparent;
} }
.online {
-fx-text-fill: limegreen;
}
.away {
-fx-text-fill: orangered;
}
.busy {
-fx-text-fill: red;
}
.offline {
-fx-text-fill: gray;
}