Implemented nice UI

This commit is contained in:
DieGurke 2020-07-11 10:40:42 +02:00
parent 6cb9c41ea0
commit 022b516ceb
3 changed files with 28 additions and 12 deletions

View File

@ -1,7 +1,8 @@
package envoy.client.ui.listcell;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.scene.layout.*;
import envoy.data.Contact;
import envoy.data.Group;
@ -17,27 +18,38 @@ import envoy.data.User;
* @author Leon Hofmeister
* @since Envoy Client v0.1-beta
*/
public class ContactControl extends VBox {
public class ChatControl extends HBox {
/**
* @param contact the contact that should be formatted
* @since Envoy Client v0.1-beta
*/
public ContactControl(Contact contact, int unreadMessagesAmount) {
public ChatControl(Contact contact, int unreadMessagesAmount) {
// Container with contact name
final var vBox = new VBox();
final var nameLabel = new Label(contact.getName());
nameLabel.setWrapText(true);
getChildren().add(nameLabel);
vBox.getChildren().add(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());
getChildren().add(statusLabel);
vBox.getChildren().add(statusLabel);
} else // Member count
getChildren().add(new Label(((Group) contact).getContacts().size() + " members"));
vBox.getChildren().add(new Label(((Group) contact).getContacts().size() + " members"));
getChildren().add(vBox);
Region spacing = new Region();
setHgrow(spacing, Priority.ALWAYS);
getChildren().add(spacing);
final var unreadMessagesLabel = new Label("" + unreadMessagesAmount);
getChildren().add(unreadMessagesLabel);
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);
}
}

View File

@ -16,7 +16,6 @@ import envoy.client.data.Chat;
public class ContactListCellFactory extends ListCell<Chat> {
private final ListView<Chat> listView;
private Boolean displayUnreadMessagesAmount = false;
/**
* @param listView the list view inside which this cell is contained
@ -24,8 +23,6 @@ public class ContactListCellFactory extends ListCell<Chat> {
*/
public ContactListCellFactory(ListView<Chat> listView) { this.listView = listView; }
public void displayUnreadMessagesAmount() { displayUnreadMessagesAmount = true; }
/**
* Displays the name of a contact. If the contact is a user, their online status
* is displayed as well.
@ -39,7 +36,7 @@ public class ContactListCellFactory extends ListCell<Chat> {
setText(null);
setGraphic(null);
} else {
final var control = new ContactControl(chat.getRecipient(), chat.getUnreadAmount());
final var control = new ChatControl(chat.getRecipient(), chat.getUnreadAmount());
prefWidthProperty().bind(listView.widthProperty().subtract(40));
setGraphic(control);
}

View File

@ -58,6 +58,13 @@
-fx-text-alignment: left;
}
.unreadMessagesAmount {
-fx-alignment: center;
-fx-background-color: orange;
-fx-background-radius: 4.0em;
-fx-text-alignment: center;
}
#remainingCharsLabel {
-fx-text-fill: #00FF00;
-fx-background-color: transparent;