This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/src/main/java/envoy/client/ui/ContactListCell.java

64 lines
1.7 KiB
Java

package envoy.client.ui;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.layout.VBox;
import envoy.data.Contact;
import envoy.data.Group;
import envoy.data.User;
/**
* Project: <strong>envoy-client</strong><br>
* File: <strong>UserListCell.java</strong><br>
* Created: <strong>28.03.2020</strong><br>
*
* @author Kai S. K. Engelbart
* @since Envoy Client v0.1-beta
*/
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) {
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;
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));
}
}
}