2020-07-01 19:35:15 +02:00
|
|
|
package envoy.client.ui.listcell;
|
|
|
|
|
2020-07-17 13:56:36 +02:00
|
|
|
import javafx.geometry.Insets;
|
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-17 13:56:36 +02:00
|
|
|
import javafx.scene.image.ImageView;
|
2020-07-11 10:40:42 +02:00
|
|
|
import javafx.scene.layout.*;
|
2020-07-17 13:56:36 +02:00
|
|
|
import javafx.scene.shape.Rectangle;
|
2020-07-01 19:35:15 +02:00
|
|
|
|
2020-07-12 13:07:46 +02:00
|
|
|
import envoy.client.data.Chat;
|
2020-07-17 13:56:36 +02:00
|
|
|
import envoy.client.ui.IconUtil;
|
|
|
|
import envoy.data.Group;
|
2020-07-01 19:35:15 +02:00
|
|
|
|
|
|
|
/**
|
2020-07-13 17:55:00 +02:00
|
|
|
* Displays a chat using a contact control for the recipient and a label for the
|
|
|
|
* unread message count.
|
2020-07-01 19:35:15 +02:00
|
|
|
* <p>
|
|
|
|
* Project: <strong>envoy-client</strong><br>
|
|
|
|
* File: <strong>ContactControl.java</strong><br>
|
|
|
|
* Created: <strong>01.07.2020</strong><br>
|
|
|
|
*
|
2020-07-13 17:55:00 +02:00
|
|
|
* @see ContactControl
|
2020-07-01 19:35:15 +02:00
|
|
|
* @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
|
|
|
|
|
|
|
/**
|
2020-07-12 14:46:35 +02:00
|
|
|
* @param chat the chat to display
|
2020-07-01 19:35:15 +02:00
|
|
|
* @since Envoy Client v0.1-beta
|
|
|
|
*/
|
2020-07-12 14:46:35 +02:00
|
|
|
public ChatControl(Chat chat) {
|
2020-07-17 13:56:36 +02:00
|
|
|
setAlignment(Pos.CENTER_LEFT);
|
|
|
|
setPadding(new Insets(0, 0, 3, 0));
|
|
|
|
// profile pic
|
|
|
|
ImageView contactProfilePic;
|
|
|
|
if (chat.getRecipient() instanceof Group) contactProfilePic = new ImageView(IconUtil.loadIconThemeSensitive("group_icon", 32));
|
|
|
|
else contactProfilePic = new ImageView(IconUtil.loadIconThemeSensitive("user_icon", 32));
|
|
|
|
Rectangle clip = new Rectangle();
|
|
|
|
clip.setWidth(32);
|
|
|
|
clip.setHeight(32);
|
|
|
|
clip.setArcHeight(32);
|
|
|
|
clip.setArcWidth(32);
|
|
|
|
contactProfilePic.setClip(clip);
|
|
|
|
getChildren().add(contactProfilePic);
|
|
|
|
// spacing
|
|
|
|
Region leftSpacing = new Region();
|
|
|
|
leftSpacing.setPrefSize(8, 0);
|
|
|
|
leftSpacing.setMinSize(8, 0);
|
|
|
|
leftSpacing.setMaxSize(8, 0);
|
|
|
|
getChildren().add(leftSpacing);
|
2020-07-13 17:55:00 +02:00
|
|
|
// Contact control
|
|
|
|
getChildren().add(new ContactControl(chat.getRecipient()));
|
|
|
|
// Unread messages
|
2020-07-12 14:46:35 +02:00
|
|
|
if (chat.getUnreadAmount() != 0) {
|
2020-07-25 16:51:46 +02:00
|
|
|
final var spacing = new Region();
|
2020-07-11 10:46:17 +02:00
|
|
|
setHgrow(spacing, Priority.ALWAYS);
|
|
|
|
getChildren().add(spacing);
|
2020-07-12 14:46:35 +02:00
|
|
|
final var unreadMessagesLabel = new Label(Integer.toString(chat.getUnreadAmount()));
|
2020-07-11 10:46:17 +02:00
|
|
|
unreadMessagesLabel.setMinSize(15, 15);
|
2020-07-25 16:26:13 +02:00
|
|
|
final var vBox2 = new VBox();
|
2020-07-11 10:46:17 +02:00
|
|
|
vBox2.setAlignment(Pos.CENTER_RIGHT);
|
|
|
|
unreadMessagesLabel.setAlignment(Pos.CENTER);
|
|
|
|
unreadMessagesLabel.getStyleClass().add("unreadMessagesAmount");
|
|
|
|
vBox2.getChildren().add(unreadMessagesLabel);
|
|
|
|
getChildren().add(vBox2);
|
|
|
|
}
|
2020-07-16 19:07:27 +02:00
|
|
|
getStyleClass().add("listElement");
|
2020-07-01 19:35:15 +02:00
|
|
|
}
|
|
|
|
}
|