Wrapped text in userList

(as suggested by @CyB3RC0nN0R)
It is nice to see that JavaFX is less prone to shittyness than Swing is.
This commit is contained in:
delvh 2020-06-27 18:44:57 +02:00
parent 08e5fad42b
commit dee66458d9
4 changed files with 19 additions and 9 deletions

View File

@ -2,6 +2,7 @@ package envoy.client.ui;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.layout.VBox;
import envoy.data.Contact;
@ -18,6 +19,14 @@ import envoy.data.User;
*/
public class ContactListCell 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 ContactListCell(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.
@ -32,17 +41,18 @@ public class ContactListCell extends ListCell<Contact> {
setGraphic(null);
} else {
// Container with contact name
final var vbox = new VBox(new Label(contact.getName()));
final var nameLabel = new Label(contact.getName());
nameLabel.setWrapText(true);
final var vbox = new VBox(nameLabel);
if (contact instanceof User) {
// 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
} else // Member count
vbox.getChildren().add(new Label(((Group) contact).getContacts().size() + " members"));
}
prefWidthProperty().bind(listView.widthProperty().subtract(40));
setGraphic(vbox);
}
}

View File

@ -92,8 +92,8 @@ public final class ChatScene {
private void initialize() {
// Initialize message and user rendering
messageList.setCellFactory(listView -> new MessageListCell(listView));
userList.setCellFactory(listView -> new ContactListCell());
messageList.setCellFactory(MessageListCell::new);
userList.setCellFactory(ContactListCell::new);
settingsButton.setGraphic(new ImageView(IconUtil.load("/icons/settings.png", 16)));

View File

@ -67,7 +67,7 @@ public class ContactSearchScene {
@FXML
private void initialize() {
contactList.setCellFactory(e -> new ContactListCell());
contactList.setCellFactory(ContactListCell::new);
eventBus.register(ContactSearchResult.class,
response -> Platform.runLater(() -> { contactList.getItems().clear(); contactList.getItems().addAll(response.get()); }));
}

View File

@ -41,7 +41,7 @@ public class GroupCreationScene {
@FXML
private void initialize() {
contactList.setCellFactory(e -> new ContactListCell());
contactList.setCellFactory(ContactListCell::new);
contactList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
}
@ -59,7 +59,7 @@ public class GroupCreationScene {
/**
* Enables the {@code createButton} if at least one contact is selected.
*
*
* @since Envoy Client v0.1-beta
*/
@FXML