45 lines
1.1 KiB
Java
45 lines
1.1 KiB
Java
package envoy.client.ui.listcell;
|
|
|
|
import javafx.scene.control.ListCell;
|
|
import javafx.scene.control.ListView;
|
|
|
|
import envoy.data.Contact;
|
|
|
|
/**
|
|
* 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 ContactListCellFactory extends ListCell<Contact> {
|
|
|
|
private final ListView<Contact> listView;
|
|
|
|
/**
|
|
* @param listView the list view inside which this cell is contained
|
|
* @since Envoy Client v0.1-beta
|
|
*/
|
|
public ContactListCellFactory(ListView<Contact> listView) { this.listView = listView; }
|
|
|
|
/**
|
|
* 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 {
|
|
final var control = new ContactControl(contact);
|
|
prefWidthProperty().bind(listView.widthProperty().subtract(40));
|
|
setGraphic(control);
|
|
}
|
|
}
|
|
}
|