2020-07-01 19:35:15 +02:00
|
|
|
package envoy.client.ui.listcell;
|
|
|
|
|
2020-07-11 10:40:42 +02:00
|
|
|
import javafx.geometry.Pos;
|
2020-07-01 19:35:15 +02:00
|
|
|
import javafx.scene.control.Label;
|
2020-07-11 10:40:42 +02:00
|
|
|
import javafx.scene.layout.*;
|
2020-07-01 19:35:15 +02:00
|
|
|
|
2020-07-12 13:07:46 +02:00
|
|
|
import envoy.client.data.Chat;
|
2020-07-01 19:35:15 +02:00
|
|
|
import envoy.data.Contact;
|
|
|
|
import envoy.data.Group;
|
|
|
|
import envoy.data.User;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class formats a single {@link Contact} into a UI component.
|
|
|
|
* <p>
|
|
|
|
* Project: <strong>envoy-client</strong><br>
|
|
|
|
* File: <strong>ContactControl.java</strong><br>
|
|
|
|
* Created: <strong>01.07.2020</strong><br>
|
|
|
|
*
|
|
|
|
* @author Leon Hofmeister
|
|
|
|
* @since Envoy Client v0.1-beta
|
|
|
|
*/
|
2020-07-11 10:40:42 +02:00
|
|
|
public class ChatControl extends HBox {
|
2020-07-01 19:35:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param contact the contact that should be formatted
|
|
|
|
* @since Envoy Client v0.1-beta
|
|
|
|
*/
|
2020-07-12 13:07:46 +02:00
|
|
|
public ChatControl(Chat chat, int unreadMessagesAmount) {
|
2020-07-01 19:35:15 +02:00
|
|
|
// Container with contact name
|
2020-07-11 10:40:42 +02:00
|
|
|
final var vBox = new VBox();
|
2020-07-12 13:07:46 +02:00
|
|
|
final var nameLabel = new Label(chat.getRecipient().getName());
|
2020-07-01 19:35:15 +02:00
|
|
|
nameLabel.setWrapText(true);
|
2020-07-11 10:40:42 +02:00
|
|
|
vBox.getChildren().add(nameLabel);
|
2020-07-12 13:07:46 +02:00
|
|
|
if (chat.getRecipient() instanceof User) {
|
2020-07-01 19:35:15 +02:00
|
|
|
// Online status
|
2020-07-12 13:07:46 +02:00
|
|
|
final var user = (User) chat.getRecipient();
|
2020-07-01 19:35:15 +02:00
|
|
|
final var statusLabel = new Label(user.getStatus().toString());
|
|
|
|
statusLabel.getStyleClass().add(user.getStatus().toString().toLowerCase());
|
2020-07-11 10:40:42 +02:00
|
|
|
vBox.getChildren().add(statusLabel);
|
2020-07-01 19:35:15 +02:00
|
|
|
} else // Member count
|
2020-07-12 13:07:46 +02:00
|
|
|
vBox.getChildren().add(new Label(((Group) chat.getRecipient()).getContacts().size() + " members"));
|
2020-07-11 10:40:42 +02:00
|
|
|
|
|
|
|
getChildren().add(vBox);
|
2020-07-11 10:46:17 +02:00
|
|
|
if (unreadMessagesAmount != 0) {
|
|
|
|
Region spacing = new Region();
|
|
|
|
setHgrow(spacing, Priority.ALWAYS);
|
|
|
|
getChildren().add(spacing);
|
|
|
|
final var unreadMessagesLabel = new Label("" + unreadMessagesAmount);
|
|
|
|
unreadMessagesLabel.setMinSize(15, 15);
|
|
|
|
var vBox2 = new VBox();
|
|
|
|
vBox2.setAlignment(Pos.CENTER_RIGHT);
|
|
|
|
unreadMessagesLabel.setAlignment(Pos.CENTER);
|
|
|
|
unreadMessagesLabel.getStyleClass().add("unreadMessagesAmount");
|
|
|
|
vBox2.getChildren().add(unreadMessagesLabel);
|
|
|
|
getChildren().add(vBox2);
|
|
|
|
}
|
2020-07-01 19:35:15 +02:00
|
|
|
}
|
|
|
|
}
|