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);
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);
}
}
}

View File

@ -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;
}