Implemented nice UI

This commit is contained in:
DieGurke 2020-07-11 10:40:42 +02:00
parent 70da595a49
commit d675349c71
3 changed files with 28 additions and 12 deletions

View File

@ -1,7 +1,8 @@
package envoy.client.ui.listcell; package envoy.client.ui.listcell;
import javafx.geometry.Pos;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.layout.VBox; import javafx.scene.layout.*;
import envoy.data.Contact; import envoy.data.Contact;
import envoy.data.Group; import envoy.data.Group;
@ -17,27 +18,38 @@ import envoy.data.User;
* @author Leon Hofmeister * @author Leon Hofmeister
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public class ContactControl extends VBox { public class ChatControl extends HBox {
/** /**
* @param contact the contact that should be formatted * @param contact the contact that should be formatted
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public ContactControl(Contact contact, int unreadMessagesAmount) { public ChatControl(Contact contact, int unreadMessagesAmount) {
// Container with contact name // Container with contact name
final var vBox = new VBox();
final var nameLabel = new Label(contact.getName()); final var nameLabel = new Label(contact.getName());
nameLabel.setWrapText(true); nameLabel.setWrapText(true);
getChildren().add(nameLabel); vBox.getChildren().add(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());
getChildren().add(statusLabel); vBox.getChildren().add(statusLabel);
} else // Member count } 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); 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> { public class ContactListCellFactory extends ListCell<Chat> {
private final ListView<Chat> listView; private final ListView<Chat> listView;
private Boolean displayUnreadMessagesAmount = false;
/** /**
* @param listView the list view inside which this cell is contained * @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 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 * Displays the name of a contact. If the contact is a user, their online status
* is displayed as well. * is displayed as well.
@ -39,7 +36,7 @@ public class ContactListCellFactory extends ListCell<Chat> {
setText(null); setText(null);
setGraphic(null); setGraphic(null);
} else { } 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)); prefWidthProperty().bind(listView.widthProperty().subtract(40));
setGraphic(control); setGraphic(control);
} }

View File

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