Move user status color to CSS, refactor ContactListCell
This commit is contained in:
parent
b23ee61506
commit
256a5ac210
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
Reference in New Issue
Block a user