Merge branch 'develop' into f/clearable_textfield
This commit is contained in:
commit
2cccddc606
@ -2,6 +2,7 @@ package envoy.client.ui;
|
|||||||
|
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.ListCell;
|
import javafx.scene.control.ListCell;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
|
|
||||||
import envoy.data.Contact;
|
import envoy.data.Contact;
|
||||||
@ -18,6 +19,14 @@ import envoy.data.User;
|
|||||||
*/
|
*/
|
||||||
public class ContactListCell extends ListCell<Contact> {
|
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
|
* Displays the name of a contact. If the contact is a user, their online status
|
||||||
* is displayed as well.
|
* is displayed as well.
|
||||||
@ -32,17 +41,18 @@ public class ContactListCell extends ListCell<Contact> {
|
|||||||
setGraphic(null);
|
setGraphic(null);
|
||||||
} else {
|
} else {
|
||||||
// Container with contact name
|
// 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) {
|
if (contact instanceof User) {
|
||||||
// Online status
|
// Online status
|
||||||
final var user = (User) contact;
|
final var user = (User) contact;
|
||||||
final var statusLabel = new Label(user.getStatus().toString());
|
final var statusLabel = new Label(user.getStatus().toString());
|
||||||
statusLabel.getStyleClass().add(user.getStatus().toString().toLowerCase());
|
statusLabel.getStyleClass().add(user.getStatus().toString().toLowerCase());
|
||||||
vbox.getChildren().add(statusLabel);
|
vbox.getChildren().add(statusLabel);
|
||||||
} else {
|
} else // Member count
|
||||||
// Member count
|
|
||||||
vbox.getChildren().add(new Label(((Group) contact).getContacts().size() + " members"));
|
vbox.getChildren().add(new Label(((Group) contact).getContacts().size() + " members"));
|
||||||
}
|
prefWidthProperty().bind(listView.widthProperty().subtract(40));
|
||||||
setGraphic(vbox);
|
setGraphic(vbox);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,11 @@ import java.time.format.DateTimeFormatter;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.control.ListCell;
|
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.stage.PopupWindow.AnchorLocation;
|
||||||
|
|
||||||
import envoy.data.Message;
|
import envoy.data.Message;
|
||||||
import envoy.data.Message.MessageStatus;
|
import envoy.data.Message.MessageStatus;
|
||||||
@ -26,10 +26,18 @@ import envoy.data.User;
|
|||||||
*/
|
*/
|
||||||
public class MessageListCell extends ListCell<Message> {
|
public class MessageListCell extends ListCell<Message> {
|
||||||
|
|
||||||
|
private final ListView<Message> listView;
|
||||||
|
|
||||||
private static User client;
|
private static User client;
|
||||||
private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm");
|
private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm");
|
||||||
private static final Map<MessageStatus, Image> statusImages = IconUtil.loadByEnum(MessageStatus.class, 16);
|
private static final Map<MessageStatus, Image> statusImages = IconUtil.loadByEnum(MessageStatus.class, 16);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param listView the list view inside which this cell is contained
|
||||||
|
* @since Envoy Client v0.1-beta
|
||||||
|
*/
|
||||||
|
public MessageListCell(ListView<Message> listView) { this.listView = listView; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays the text, the data of creation and the status of a message.
|
* Displays the text, the data of creation and the status of a message.
|
||||||
*
|
*
|
||||||
@ -42,12 +50,26 @@ public class MessageListCell extends ListCell<Message> {
|
|||||||
setText(null);
|
setText(null);
|
||||||
setGraphic(null);
|
setGraphic(null);
|
||||||
} else {
|
} else {
|
||||||
final var cell = new VBox(new Label(dateFormat.format(message.getCreationDate())), new Label(message.getText()));
|
// Creating the underlying VBox, the dateLabel and the textLabel
|
||||||
if (message.getRecipientID() == client.getID()) {
|
final var cell = new VBox(new Label(dateFormat.format(message.getCreationDate())));
|
||||||
cell.getChildren().add(new Label("", new ImageView(statusImages.get(message.getStatus()))));
|
final var textLabel = new Label(message.getText());
|
||||||
|
textLabel.setWrapText(true);
|
||||||
|
cell.getChildren().add(textLabel);
|
||||||
|
// Setting the message status icon and background color
|
||||||
|
if (message.getRecipientID() != client.getID()) {
|
||||||
|
final var statusIcon = new Label("", new ImageView(statusImages.get(message.getStatus())));
|
||||||
|
statusIcon.setPadding(new Insets(1, 0, 5, 5));
|
||||||
|
cell.getChildren().add(statusIcon);
|
||||||
cell.getStyleClass().add("own-message");
|
cell.getStyleClass().add("own-message");
|
||||||
} else cell.getStyleClass().add("received-message");
|
} else cell.getStyleClass().add("received-message");
|
||||||
|
// Adjusting height and weight of the cell to the corresponding ListView
|
||||||
cell.paddingProperty().setValue(new Insets(5, 20, 5, 20));
|
cell.paddingProperty().setValue(new Insets(5, 20, 5, 20));
|
||||||
|
cell.prefWidthProperty().bind(listView.widthProperty().subtract(40));
|
||||||
|
// Creating the Tooltip to deselect a message
|
||||||
|
final var tooltip = new Tooltip("You can select a message by clicking on it \nand deselect it by pressing \"ctrl\" and clicking on it");
|
||||||
|
tooltip.setWrapText(true);
|
||||||
|
tooltip.setAnchorLocation(AnchorLocation.WINDOW_TOP_LEFT);
|
||||||
|
setTooltip(tooltip);
|
||||||
setGraphic(cell);
|
setGraphic(cell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,8 +92,8 @@ public final class ChatScene {
|
|||||||
private void initialize() {
|
private void initialize() {
|
||||||
|
|
||||||
// Initialize message and user rendering
|
// Initialize message and user rendering
|
||||||
messageList.setCellFactory(listView -> new MessageListCell());
|
messageList.setCellFactory(MessageListCell::new);
|
||||||
userList.setCellFactory(listView -> new ContactListCell());
|
userList.setCellFactory(ContactListCell::new);
|
||||||
|
|
||||||
settingsButton.setGraphic(new ImageView(IconUtil.load("/icons/settings.png", 16)));
|
settingsButton.setGraphic(new ImageView(IconUtil.load("/icons/settings.png", 16)));
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ public class ContactSearchScene {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
contactList.setCellFactory(e -> new ContactListCell());
|
contactList.setCellFactory(ContactListCell::new);
|
||||||
searchBar.setClearButtonListener(e -> { searchBar.getTextField().clear(); contactList.getItems().clear(); });
|
searchBar.setClearButtonListener(e -> { searchBar.getTextField().clear(); contactList.getItems().clear(); });
|
||||||
eventBus.register(ContactSearchResult.class,
|
eventBus.register(ContactSearchResult.class,
|
||||||
response -> Platform.runLater(() -> { contactList.getItems().clear(); contactList.getItems().addAll(response.get()); }));
|
response -> Platform.runLater(() -> { contactList.getItems().clear(); contactList.getItems().addAll(response.get()); }));
|
||||||
|
@ -42,7 +42,7 @@ public class GroupCreationScene {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
contactList.setCellFactory(e -> new ContactListCell());
|
contactList.setCellFactory(ContactListCell::new);
|
||||||
contactList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
contactList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
||||||
groupNameField.setClearButtonListener(e -> { groupNameField.getTextField().clear(); createButton.setDisable(true); });
|
groupNameField.setClearButtonListener(e -> { groupNameField.getTextField().clear(); createButton.setDisable(true); });
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user