Added color display of user statuses

This commit is contained in:
delvh 2020-06-09 20:42:17 +02:00
parent 0661838c38
commit d0d86fc0d4

View File

@ -3,8 +3,10 @@ package envoy.client.ui;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import envoy.data.Contact;
import envoy.data.Group;
import envoy.data.User;
/**
@ -20,15 +22,39 @@ public class ContactListCell extends ListCell<Contact> {
/**
* Displays the name of a contact. If the contact is a user, their online status
* is displayed as well.
*
*
* @since Envoy Client v0.1-beta
*/
@Override
protected void updateItem(Contact contact, boolean empty) {
super.updateItem(contact, empty);
if (!empty && contact != null) {
final var name = new Label(contact.getName());
setGraphic(contact instanceof User ? new VBox(name, new Label(((User) contact).getStatus().toString())) : new VBox(name));
// the infoLabel displays specific contact info, i.e. status of a user or amount
// of members in a group
Label infoLabel = null;
if (contact instanceof User) {
// user specific info
infoLabel = new Label(((User) contact).getStatus().toString());
Color textColor = null;
switch (((User) contact).getStatus()) {
case ONLINE:
textColor = Color.LIMEGREEN;
break;
case AWAY:
textColor = Color.ORANGERED;
break;
case BUSY:
textColor = Color.RED;
break;
case OFFLINE:
textColor = Color.GRAY;
break;
}
infoLabel.setTextFill(textColor);
} else
// group specific infos
infoLabel = new Label(String.valueOf(((Group) contact).getContacts().size()) + " members");
setGraphic(new VBox(new Label(contact.getName()), infoLabel));
}
}
}