Merge pull request #33 from informatik-ag-ngl/f/new_ui

New ChatScene UI
This commit is contained in:
DieGurke 2020-08-02 15:30:06 +02:00 committed by GitHub
commit dee317c27d
23 changed files with 804 additions and 346 deletions

View File

@ -4,6 +4,7 @@ import java.io.IOException;
import java.util.Stack; import java.util.Stack;
import java.util.logging.Level; import java.util.logging.Level;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
@ -125,8 +126,12 @@ public final class SceneContext {
sceneStack.push(scene); sceneStack.push(scene);
stage.setScene(scene); stage.setScene(scene);
applyCSS(); // The LoginScene is the only scene not intended to be resized
// As strange as it seems, this is needed as otherwise the LoginScene won't be
// displayed on some OS (...Debian...)
stage.sizeToScene(); stage.sizeToScene();
Platform.runLater(() -> stage.setResizable(sceneInfo != SceneInfo.LOGIN_SCENE));
applyCSS();
stage.show(); stage.show();
} catch (final IOException e) { } catch (final IOException e) {
EnvoyLog.getLogger(SceneContext.class).log(Level.SEVERE, String.format("Could not load scene for %s: ", sceneInfo), e); EnvoyLog.getLogger(SceneContext.class).log(Level.SEVERE, String.format("Could not load scene for %s: ", sceneInfo), e);

View File

@ -17,6 +17,8 @@ import java.util.logging.Logger;
import javafx.animation.RotateTransition; import javafx.animation.RotateTransition;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.*; import javafx.scene.control.*;
@ -27,6 +29,7 @@ import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyEvent;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import javafx.util.Duration; import javafx.util.Duration;
@ -39,9 +42,7 @@ import envoy.client.event.SendEvent;
import envoy.client.net.Client; import envoy.client.net.Client;
import envoy.client.net.WriteProxy; import envoy.client.net.WriteProxy;
import envoy.client.ui.*; import envoy.client.ui.*;
import envoy.client.ui.listcell.ChatControl; import envoy.client.ui.listcell.*;
import envoy.client.ui.listcell.ListCellFactory;
import envoy.client.ui.listcell.MessageControl;
import envoy.data.*; import envoy.data.*;
import envoy.data.Attachment.AttachmentType; import envoy.data.Attachment.AttachmentType;
import envoy.event.*; import envoy.event.*;
@ -101,6 +102,24 @@ public final class ChatScene implements Restorable {
@FXML @FXML
private ImageView attachmentView; private ImageView attachmentView;
@FXML
private Label topBarContactLabel;
@FXML
private Label topBarStatusLabel;
@FXML
private Button messageSearchButton;
@FXML
private ImageView clientProfilePic;
@FXML
private ImageView recipientProfilePic;
@FXML
private TextArea contactSearch;
private LocalDB localDB; private LocalDB localDB;
private Client client; private Client client;
private WriteProxy writeProxy; private WriteProxy writeProxy;
@ -122,6 +141,8 @@ public final class ChatScene implements Restorable {
private static final int MAX_MESSAGE_LENGTH = 255; private static final int MAX_MESSAGE_LENGTH = 255;
private static final int DEFAULT_ICON_SIZE = 16; private static final int DEFAULT_ICON_SIZE = 16;
private FilteredList<Chat> chats;
/** /**
* Initializes the appearance of certain visual components. * Initializes the appearance of certain visual components.
* *
@ -129,9 +150,8 @@ public final class ChatScene implements Restorable {
*/ */
@FXML @FXML
private void initialize() { private void initialize() {
// Initialize message and user rendering // Initialize message and user rendering
messageList.setCellFactory(new ListCellFactory<>(MessageControl::new)); messageList.setCellFactory(MessageListCell::new);
chatList.setCellFactory(new ListCellFactory<>(ChatControl::new)); chatList.setCellFactory(new ListCellFactory<>(ChatControl::new));
settingsButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("settings", DEFAULT_ICON_SIZE))); settingsButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("settings", DEFAULT_ICON_SIZE)));
@ -139,6 +159,14 @@ public final class ChatScene implements Restorable {
attachmentButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("attachment", DEFAULT_ICON_SIZE))); attachmentButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("attachment", DEFAULT_ICON_SIZE)));
attachmentView.setImage(DEFAULT_ATTACHMENT_VIEW_IMAGE); attachmentView.setImage(DEFAULT_ATTACHMENT_VIEW_IMAGE);
rotateButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("rotate", (int) (DEFAULT_ICON_SIZE * 1.5)))); rotateButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("rotate", (int) (DEFAULT_ICON_SIZE * 1.5))));
messageSearchButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("search", DEFAULT_ICON_SIZE)));
clientProfilePic.setImage(IconUtil.loadIconThemeSensitive("user_icon", 43));
Rectangle clip = new Rectangle();
clip.setWidth(43);
clip.setHeight(43);
clip.setArcHeight(43);
clip.setArcWidth(43);
clientProfilePic.setClip(clip);
// Listen to received messages // Listen to received messages
eventBus.register(MessageCreationEvent.class, e -> { eventBus.register(MessageCreationEvent.class, e -> {
@ -163,8 +191,9 @@ public final class ChatScene implements Restorable {
// Move chat with most recent unread messages to the top // Move chat with most recent unread messages to the top
Platform.runLater(() -> { Platform.runLater(() -> {
chatList.getItems().remove(chat); chats.getSource().remove(chat);
chatList.getItems().add(0, chat); ((ObservableList<Chat>) chats.getSource()).add(0, chat);
if (chat.equals(currentChat)) chatList.getSelectionModel().select(0); if (chat.equals(currentChat)) chatList.getSelectionModel().select(0);
}); });
}); });
@ -187,7 +216,7 @@ public final class ChatScene implements Restorable {
// Listen to user status changes // Listen to user status changes
eventBus.register(UserStatusChange.class, eventBus.register(UserStatusChange.class,
e -> chatList.getItems() e -> chats.getSource()
.stream() .stream()
.filter(c -> c.getRecipient().getID() == e.getID()) .filter(c -> c.getRecipient().getID() == e.getID())
.findAny() .findAny()
@ -201,10 +230,11 @@ public final class ChatScene implements Restorable {
case ADD: case ADD:
if (contact instanceof User) localDB.getUsers().put(contact.getName(), (User) contact); if (contact instanceof User) localDB.getUsers().put(contact.getName(), (User) contact);
final Chat chat = contact instanceof User ? new Chat(contact) : new GroupChat(client.getSender(), contact); final Chat chat = contact instanceof User ? new Chat(contact) : new GroupChat(client.getSender(), contact);
Platform.runLater(() -> chatList.getItems().add(chat)); Platform.runLater(() -> ((ObservableList<Chat>) chats.getSource()).add(0, chat));
break; break;
case REMOVE: case REMOVE:
Platform.runLater(() -> chatList.getItems().removeIf(c -> c.getRecipient().equals(contact))); Platform.runLater(() -> chats.getSource().removeIf(c -> c.getRecipient().equals(contact)));
break; break;
} }
}); });
@ -242,10 +272,12 @@ public final class ChatScene implements Restorable {
this.client = client; this.client = client;
this.writeProxy = writeProxy; this.writeProxy = writeProxy;
MessageControl.setUser(localDB.getUser()); chats = new FilteredList<>(FXCollections.observableList(localDB.getChats()));
MessageControl.setSceneContext(sceneContext); chatList.setItems(chats);
chatList.setItems(FXCollections.observableList(localDB.getChats()));
contactLabel.setText(localDB.getUser().getName()); contactLabel.setText(localDB.getUser().getName());
MessageControl.setLocalDB(localDB);
MessageControl.setSceneContext(sceneContext);
if (!client.isOnline()) updateInfoLabel("You are offline", "infoLabel-info"); if (!client.isOnline()) updateInfoLabel("You are offline", "infoLabel-info");
recorder = new AudioRecorder(); recorder = new AudioRecorder();
@ -273,7 +305,7 @@ public final class ChatScene implements Restorable {
currentChat = localDB.getChat(user.getID()).get(); currentChat = localDB.getChat(user.getID()).get();
messageList.setItems(FXCollections.observableList(currentChat.getMessages())); messageList.setItems(FXCollections.observableList(currentChat.getMessages()));
final var scrollIndex = messageList.getItems().size() - currentChat.getUnreadAmount() - 1; final var scrollIndex = messageList.getItems().size() - currentChat.getUnreadAmount();
messageList.scrollTo(scrollIndex); messageList.scrollTo(scrollIndex);
logger.log(Level.FINEST, "Loading chat with " + user + " at index " + scrollIndex); logger.log(Level.FINEST, "Loading chat with " + user + " at index " + scrollIndex);
deleteContactMenuItem.setText("Delete " + user.getName()); deleteContactMenuItem.setText("Delete " + user.getName());
@ -301,6 +333,27 @@ public final class ChatScene implements Restorable {
voiceButton.setDisable(!recorder.isSupported()); voiceButton.setDisable(!recorder.isSupported());
attachmentButton.setDisable(false); attachmentButton.setDisable(false);
chatList.refresh(); chatList.refresh();
if (currentChat != null) {
topBarContactLabel.setText(currentChat.getRecipient().getName());
if (currentChat.getRecipient() instanceof User) {
String status = ((User) currentChat.getRecipient()).getStatus().toString();
topBarStatusLabel.setText(status);
topBarStatusLabel.getStyleClass().add(status.toLowerCase());
recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("user_icon", 43));
} else {
topBarStatusLabel.setText(currentChat.getRecipient().getContacts().size() + " members");
recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("group_icon", 43));
}
Rectangle clip = new Rectangle();
clip.setWidth(43);
clip.setHeight(43);
clip.setArcHeight(43);
clip.setArcWidth(43);
recipientProfilePic.setClip(clip);
messageSearchButton.setVisible(true);
}
} }
/** /**
@ -561,8 +614,8 @@ public final class ChatScene implements Restorable {
currentChat.insert(message); currentChat.insert(message);
// Moving currentChat to the top // Moving currentChat to the top
Platform.runLater(() -> { Platform.runLater(() -> {
chatList.getItems().remove(currentChat); chats.getSource().remove(currentChat);
chatList.getItems().add(0, currentChat); ((ObservableList<Chat>) chats.getSource()).add(0, currentChat);
chatList.getSelectionModel().select(0); chatList.getSelectionModel().select(0);
localDB.getChats().remove(currentChat); localDB.getChats().remove(currentChat);
localDB.getChats().add(0, currentChat); localDB.getChats().add(0, currentChat);
@ -638,4 +691,10 @@ public final class ChatScene implements Restorable {
if (attachmentView.getImage() != null) attachmentView.setVisible(true); if (attachmentView.getImage() != null) attachmentView.setVisible(true);
pendingAttachment = messageAttachment; pendingAttachment = messageAttachment;
} }
@FXML
private void searchContacts() {
chats.setPredicate(contactSearch.getText().isBlank() ? c -> true
: c -> c.getRecipient().getName().toLowerCase().contains(contactSearch.getText().toLowerCase()));
}
} }

View File

@ -9,8 +9,10 @@ import java.util.logging.Logger;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Alert.AlertType;
import javafx.scene.image.ImageView;
import envoy.client.data.*; import envoy.client.data.*;
import envoy.client.net.Client; import envoy.client.net.Client;
@ -37,7 +39,7 @@ import envoy.util.EnvoyLog;
public final class LoginScene { public final class LoginScene {
@FXML @FXML
private ClearableTextField userTextField; private TextField userTextField;
@FXML @FXML
private PasswordField passwordField; private PasswordField passwordField;
@ -46,19 +48,30 @@ public final class LoginScene {
private PasswordField repeatPasswordField; private PasswordField repeatPasswordField;
@FXML @FXML
private Label repeatPasswordLabel; private Button registerSwitch;
@FXML
private CheckBox registerCheckBox;
@FXML @FXML
private Label connectionLabel; private Label connectionLabel;
@FXML
private Button loginButton;
@FXML
private Button offlineModeButton;
@FXML
private Label registerTextLabel;
@FXML
private ImageView logo;
private Client client; private Client client;
private LocalDB localDB; private LocalDB localDB;
private CacheMap cacheMap; private CacheMap cacheMap;
private SceneContext sceneContext; private SceneContext sceneContext;
private boolean registration = false;
private static final Logger logger = EnvoyLog.getLogger(LoginScene.class); private static final Logger logger = EnvoyLog.getLogger(LoginScene.class);
private static final EventBus eventBus = EventBus.getInstance(); private static final EventBus eventBus = EventBus.getInstance();
private static final ClientConfig config = ClientConfig.getInstance(); private static final ClientConfig config = ClientConfig.getInstance();
@ -70,6 +83,8 @@ public final class LoginScene {
// Show an alert after an unsuccessful handshake // Show an alert after an unsuccessful handshake
eventBus.register(HandshakeRejection.class, e -> Platform.runLater(() -> { new Alert(AlertType.ERROR, e.get()).showAndWait(); })); eventBus.register(HandshakeRejection.class, e -> Platform.runLater(() -> { new Alert(AlertType.ERROR, e.get()).showAndWait(); }));
logo.setImage(IconUtil.loadIcon("envoy_logo"));
} }
/** /**
@ -102,28 +117,41 @@ public final class LoginScene {
private void loginButtonPressed() { private void loginButtonPressed() {
// Prevent registration with unequal passwords // Prevent registration with unequal passwords
if (registerCheckBox.isSelected() && !passwordField.getText().equals(repeatPasswordField.getText())) { if (registration && !passwordField.getText().equals(repeatPasswordField.getText())) {
new Alert(AlertType.ERROR, "The entered password is unequal to the repeated one").showAndWait(); new Alert(AlertType.ERROR, "The entered password is unequal to the repeated one").showAndWait();
repeatPasswordField.clear(); repeatPasswordField.clear();
} else if (!Bounds.isValidContactName(userTextField.getTextField().getText())) { } else if (!Bounds.isValidContactName(userTextField.getText())) {
new Alert(AlertType.ERROR, "The entered user name is not valid (" + Bounds.CONTACT_NAME_PATTERN + ")").showAndWait(); new Alert(AlertType.ERROR, "The entered user name is not valid (" + Bounds.CONTACT_NAME_PATTERN + ")").showAndWait();
userTextField.getTextField().clear(); userTextField.clear();
} else performHandshake(new LoginCredentials(userTextField.getTextField().getText(), passwordField.getText(), registerCheckBox.isSelected(), } else performHandshake(new LoginCredentials(userTextField.getText(), passwordField.getText(), registration,
Startup.VERSION, loadLastSync(userTextField.getTextField().getText()))); Startup.VERSION, loadLastSync(userTextField.getText())));
} }
@FXML @FXML
private void offlineModeButtonPressed() { private void offlineModeButtonPressed() {
attemptOfflineMode( attemptOfflineMode(new LoginCredentials(userTextField.getText(), passwordField.getText(), false, Startup.VERSION,
new LoginCredentials(userTextField.getTextField().getText(), passwordField.getText(), false, Startup.VERSION, localDB.getLastSync())); loadLastSync(userTextField.getText())));
} }
@FXML @FXML
private void registerCheckboxChanged() { private void registerSwitchPressed() {
if (!registration) {
// case if the current mode is login
loginButton.setText("Register");
loginButton.setPadding(new Insets(2, 116, 2, 116));
registerTextLabel.setText("Already an account?");
registerSwitch.setText("Login");
} else {
// case if the current mode is registration
loginButton.setText("Login");
loginButton.setPadding(new Insets(2, 125, 2, 125));
registerTextLabel.setText("No account yet?");
registerSwitch.setText("Register");
}
registration = !registration;
// Make repeat password field and label visible / invisible // Make repeat password field and label visible / invisible
repeatPasswordField.setVisible(registerCheckBox.isSelected()); repeatPasswordField.setVisible(registration);
repeatPasswordLabel.setVisible(registerCheckBox.isSelected()); offlineModeButton.setDisable(registration);
} }
@FXML @FXML
@ -206,9 +234,10 @@ public final class LoginScene {
// Load ChatScene // Load ChatScene
sceneContext.pop(); sceneContext.pop();
sceneContext.getStage().setMinHeight(400); sceneContext.getStage().setMinHeight(400);
sceneContext.getStage().setMinWidth(350); sceneContext.getStage().setMinWidth(843);
sceneContext.load(SceneContext.SceneInfo.CHAT_SCENE); sceneContext.load(SceneContext.SceneInfo.CHAT_SCENE);
sceneContext.<ChatScene>getController().initializeData(sceneContext, localDB, client, writeProxy); sceneContext.<ChatScene>getController().initializeData(sceneContext, localDB, client, writeProxy);
sceneContext.getStage().centerOnScreen();
if (StatusTrayIcon.isSupported()) { if (StatusTrayIcon.isSupported()) {

View File

@ -0,0 +1,61 @@
package envoy.client.ui.custom;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.shape.Rectangle;
/**
* Provides a set of convenience constructors for images that are displayed as profile pictures.
* <p>
* Project: <strong>envoy-client</strong><br>
* File: <strong>ProfilePicImageView.java</strong><br>
* Created: <strong>30.07.2020</strong><br>
*
* @author Leon Hofmeister
* @since Envoy Client v0.2-beta
*/
public final class ProfilePicImageView extends ImageView {
/**
* Creates a new {@code ProfilePicImageView} without a default image.
*
* @since Envoy Client v0.2-beta
*/
public ProfilePicImageView() { this(null); }
/**
* Creates a new {@code ProfilePicImageView}.
*
* @param image the image to display
* @since Envoy Client v0.2-beta
*/
public ProfilePicImageView(Image image) { this(image, 40); }
/**
* Creates a new {@code ProfilePicImageView}.
*
* @param image the image to display
* @param sizeAndRounding the size and rounding for a circular
* {@code ProfilePicImageView}
* @since Envoy Client v0.2-beta
*/
public ProfilePicImageView(Image image, double sizeAndRounding) { this(image, sizeAndRounding, sizeAndRounding); }
/**
* Creates a new {@code ProfilePicImageView}.
*
* @param image the image to display
* @param size the size of this {@code ProfilePicImageView}
* @param rounding how rounded this {@code ProfilePicImageView} should be
* @since Envoy Client v0.2-beta
*/
public ProfilePicImageView(Image image, double size, double rounding) {
super(image);
final var clip = new Rectangle();
clip.setWidth(size);
clip.setHeight(size);
clip.setArcHeight(rounding);
clip.setArcWidth(rounding);
setClip(clip);
}
}

View File

@ -0,0 +1,14 @@
/**
* This package stores custom components for use in JavaFX.
* These components are also expected to be used via FXML.
* <p>
* Project: <strong>envoy-client</strong><br>
* File: <strong>package-info.java</strong><br>
* Created: <strong>30.07.2020</strong><br>
*
* @author Leon Hofmeister
* @author Maximilian K&auml;fer
* @author Kai S. K. Engelbart
* @since Envoy Client v0.2-beta
*/
package envoy.client.ui.custom;

View File

@ -0,0 +1,48 @@
package envoy.client.ui.listcell;
import javafx.scene.Node;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
/**
* Provides a convenience frame for list cell creation.
* <p>
* Project: <strong>envoy-client</strong><br>
* File: <strong>AbstractListCell.java</strong><br>
* Created: <strong>18.07.2020</strong><br>
*
* @author Kai S. K. Engelbart
* @param <T> the type of element displayed by the list cell
* @param <U> the type of node as which the list element will be displayed
* @since Envoy Client v0.1-beta
*/
public abstract class AbstractListCell<T, U extends Node> extends ListCell<T> {
protected ListView<? extends T> listView;
/**
* @param listView the list view inside of which the cell will be displayed
* @since Envoy Client v0.1-beta
*/
public AbstractListCell(ListView<? extends T> listView) {
this.listView = listView;
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
getStyleClass().add("listElement");
}
@Override
protected final void updateItem(T item, boolean empty) {
super.updateItem(item, empty);
setGraphic(empty || item == null ? null : renderItem(item));
}
/**
* Converts a list item to a node. This can have side effects on the list cell.
*
* @param item the item to render
* @return a node representing the item
* @since Envoy Client v0.1-beta
*/
protected abstract U renderItem(T item);
}

View File

@ -1,10 +1,15 @@
package envoy.client.ui.listcell; package envoy.client.ui.listcell;
import javafx.geometry.Insets;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*; import javafx.scene.layout.*;
import javafx.scene.shape.Rectangle;
import envoy.client.data.Chat; import envoy.client.data.Chat;
import envoy.client.ui.IconUtil;
import envoy.data.Group;
/** /**
* Displays a chat using a contact control for the recipient and a label for the * Displays a chat using a contact control for the recipient and a label for the
@ -25,10 +30,27 @@ public class ChatControl extends HBox {
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public ChatControl(Chat chat) { public ChatControl(Chat chat) {
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);
// Contact control // Contact control
getChildren().add(new ContactControl(chat.getRecipient())); getChildren().add(new ContactControl(chat.getRecipient()));
// Unread messages // Unread messages
if (chat.getUnreadAmount() != 0) { if (chat.getUnreadAmount() != 0) {
final var spacing = new Region(); final var spacing = new Region();
@ -43,5 +65,6 @@ public class ChatControl extends HBox {
vBox2.getChildren().add(unreadMessagesLabel); vBox2.getChildren().add(unreadMessagesLabel);
getChildren().add(vBox2); getChildren().add(vBox2);
} }
getStyleClass().add("listElement");
} }
} }

View File

@ -39,5 +39,6 @@ public class ContactControl extends VBox {
} else { } else {
getChildren().add(new Label(contact.getContacts().size() + " members")); getChildren().add(new Label(contact.getContacts().size() + " members"));
} }
getStyleClass().add("listElement");
} }
} }

View File

@ -0,0 +1,36 @@
package envoy.client.ui.listcell;
import java.util.function.Function;
import javafx.scene.Node;
import javafx.scene.control.ListView;
/**
* A generic list cell rendering an item using a provided render function.
* <p>
* Project: <strong>envoy-client</strong><br>
* File: <strong>GenericListCell.java</strong><br>
* Created: <strong>18.07.2020</strong><br>
*
* @author Kai S. K. Engelbart
* @param <T> the type of element displayed by the list cell
* @param <U> the type of node as which the list element will be displayed
* @since Envoy Client v0.2-beta
*/
public final class GenericListCell<T, U extends Node> extends AbstractListCell<T, U> {
private Function<? super T, U> renderer;
/**
* @param listView the list view inside of which the cell will be displayed
* @param renderer a function converting a list item to a node
* @since Envoy Client v0.1-beta
*/
public GenericListCell(ListView<? extends T> listView, Function<? super T, U> renderer) {
super(listView);
this.renderer = renderer;
}
@Override
protected U renderItem(T item) { return renderer.apply(item); }
}

View File

@ -17,38 +17,19 @@ import javafx.util.Callback;
* *
* @author Kai S. K. Engelbart * @author Kai S. K. Engelbart
* @param <T> the type of object to display * @param <T> the type of object to display
* @param <U> the type of node displayed
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public final class ListCellFactory<T> implements Callback<ListView<T>, ListCell<T>> { public final class ListCellFactory<T, U extends Node> implements Callback<ListView<T>, ListCell<T>> {
private final class GenericListCell extends ListCell<T> { private final Function<? super T, U> renderer;
private ListView<? extends T> listView;
private GenericListCell(ListView<? extends T> listView) { this.listView = listView; }
@Override
protected void updateItem(T item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
setGraphic(null);
} else {
final var control = converter.apply(item);
prefWidthProperty().bind(listView.widthProperty().subtract(40));
setGraphic(control);
}
}
}
private final Function<? super T, ? extends Node> converter;
/** /**
* @param converter a function converting the type to display into a node * @param renderer a function converting the type to display into a node
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public ListCellFactory(Function<? super T, ? extends Node> converter) { this.converter = converter; } public ListCellFactory(Function<? super T, U> renderer) { this.renderer = renderer; }
@Override @Override
public ListCell<T> call(ListView<T> listView) { return new GenericListCell(listView); } public ListCell<T> call(ListView<T> listView) { return new GenericListCell<>(listView, renderer); }
} }

View File

@ -10,18 +10,22 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.ContextMenu; import javafx.scene.control.ContextMenu;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.MenuItem; import javafx.scene.control.MenuItem;
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.*;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import envoy.client.data.LocalDB;
import envoy.client.data.Settings; import envoy.client.data.Settings;
import envoy.client.ui.AudioControl; import envoy.client.ui.AudioControl;
import envoy.client.ui.IconUtil; import envoy.client.ui.IconUtil;
import envoy.client.ui.SceneContext; import envoy.client.ui.SceneContext;
import envoy.data.GroupMessage;
import envoy.data.Message; import envoy.data.Message;
import envoy.data.Message.MessageStatus; import envoy.data.Message.MessageStatus;
import envoy.data.User; import envoy.data.User;
@ -35,11 +39,14 @@ import envoy.util.EnvoyLog;
* Created: <strong>01.07.2020</strong><br> * Created: <strong>01.07.2020</strong><br>
* *
* @author Leon Hofmeister * @author Leon Hofmeister
* @author Maximilian K&auml;fer
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public class MessageControl extends Label { public class MessageControl extends Label {
private static User client; private boolean ownMessage;
private static LocalDB localDB;
private static SceneContext sceneContext; private static SceneContext sceneContext;
@ -56,15 +63,31 @@ public class MessageControl extends Label {
*/ */
public MessageControl(Message message) { public MessageControl(Message message) {
// Creating the underlying VBox and the dateLabel // Creating the underlying VBox and the dateLabel
final var vbox = new VBox(new Label(dateFormat.format(message.getCreationDate()))); final var hbox = new HBox();
if (message.getSenderID() != localDB.getUser().getID() && message instanceof GroupMessage) {
// Displaying the name of the sender in a group
final var label = new Label();
label.getStyleClass().add("groupMemberNames");
label.setText(localDB.getUsers()
.values()
.stream()
.filter(c -> c.getID() == message.getSenderID())
.findFirst()
.map(User::getName)
.orElse("Unknown User"));
label.setPadding(new Insets(0, 5, 0, 0));
hbox.getChildren().add(label);
}
hbox.getChildren().add(new Label(dateFormat.format(message.getCreationDate())));
final var vbox = new VBox(hbox);
// Creating the actions for the MenuItems // Creating the actions for the MenuItems
final ContextMenu contextMenu = new ContextMenu(); final var contextMenu = new ContextMenu();
final MenuItem copyMenuItem = new MenuItem("Copy"); final var copyMenuItem = new MenuItem("Copy");
final MenuItem deleteMenuItem = new MenuItem("Delete"); final var deleteMenuItem = new MenuItem("Delete");
final MenuItem forwardMenuItem = new MenuItem("Forward"); final var forwardMenuItem = new MenuItem("Forward");
final MenuItem quoteMenuItem = new MenuItem("Quote"); final var quoteMenuItem = new MenuItem("Quote");
final MenuItem infoMenuItem = new MenuItem("Info"); final var infoMenuItem = new MenuItem("Info");
copyMenuItem.setOnAction(e -> copyMessage(message)); copyMenuItem.setOnAction(e -> copyMessage(message));
deleteMenuItem.setOnAction(e -> deleteMessage(message)); deleteMenuItem.setOnAction(e -> deleteMessage(message));
forwardMenuItem.setOnAction(e -> forwardMessage(message)); forwardMenuItem.setOnAction(e -> forwardMessage(message));
@ -93,15 +116,27 @@ public class MessageControl extends Label {
} }
// Creating the textLabel // Creating the textLabel
final var textLabel = new Label(message.getText()); final var textLabel = new Label(message.getText());
textLabel.setMaxWidth(430);
textLabel.setWrapText(true); textLabel.setWrapText(true);
vbox.getChildren().add(textLabel); final var hBoxBottom = new HBox();
hBoxBottom.getChildren().add(textLabel);
// Setting the message status icon and background color // Setting the message status icon and background color
if (message.getSenderID() == client.getID()) { if (message.getSenderID() == localDB.getUser().getID()) {
final var statusIcon = new ImageView(statusImages.get(message.getStatus())); final var statusIcon = new ImageView(statusImages.get(message.getStatus()));
statusIcon.setPreserveRatio(true); statusIcon.setPreserveRatio(true);
vbox.getChildren().add(statusIcon); final var space = new Region();
HBox.setHgrow(space, Priority.ALWAYS);
hBoxBottom.getChildren().add(space);
hBoxBottom.getChildren().add(statusIcon);
hBoxBottom.setAlignment(Pos.BOTTOM_RIGHT);
getStyleClass().add("own-message"); getStyleClass().add("own-message");
} else getStyleClass().add("received-message"); ownMessage = true;
hbox.setAlignment(Pos.CENTER_RIGHT);
} else {
getStyleClass().add("received-message");
ownMessage = false;
}
vbox.getChildren().add(hBoxBottom);
// Adjusting height and weight of the cell to the corresponding ListView // Adjusting height and weight of the cell to the corresponding ListView
paddingProperty().setValue(new Insets(5, 20, 5, 20)); paddingProperty().setValue(new Insets(5, 20, 5, 20));
setContextMenu(contextMenu); setContextMenu(contextMenu);
@ -144,10 +179,17 @@ public class MessageControl extends Label {
} }
/** /**
* @param client the user who has logged in * @param localDB the localDB used by the current user
* @since Envoy Client v0.2-beta
*/
public static void setLocalDB(LocalDB localDB) { MessageControl.localDB = localDB; }
/**
* @return whether the message stored by this {@code MessageControl} has been
* sent by this user of Envoy
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public static void setUser(User client) { MessageControl.client = client; } public boolean isOwnMessage() { return ownMessage; }
/** /**
* @param sceneContext the scene context storing the stage used in Envoy * @param sceneContext the scene context storing the stage used in Envoy

View File

@ -0,0 +1,41 @@
package envoy.client.ui.listcell;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.ListView;
import envoy.data.Message;
/**
* A list cell containing messages represented as message controls.
* <p>
* Project: <strong>envoy-client</strong><br>
* File: <strong>MessageListCell.java</strong><br>
* Created: <strong>18.07.2020</strong><br>
*
* @author Kai S. K. Engelbart
* @since Envoy Client v0.1-beta
*/
public final class MessageListCell extends AbstractListCell<Message, MessageControl> {
/**
* @param listView the list view inside of which the cell will be displayed
* @since Envoy Client v0.1-beta
*/
public MessageListCell(ListView<? extends Message> listView) { super(listView); }
@Override
protected MessageControl renderItem(Message message) {
final var control = new MessageControl(message);
listView.widthProperty().addListener((observable, oldValue, newValue) -> adjustPadding(newValue.intValue(), control.isOwnMessage()));
adjustPadding((int) listView.getWidth(), control.isOwnMessage());
if (control.isOwnMessage()) setAlignment(Pos.CENTER_RIGHT);
else setAlignment(Pos.CENTER_LEFT);
return control;
}
private void adjustPadding(int listWidth, boolean ownMessage) {
int padding = 10 + Math.max((listWidth - 1000) / 2, 0);
setPadding(ownMessage ? new Insets(0, padding, 6, 0) : new Insets(0, 0, 6, padding));
}
}

View File

@ -20,4 +20,5 @@ module envoy {
opens envoy.client.ui to javafx.graphics, javafx.fxml; opens envoy.client.ui to javafx.graphics, javafx.fxml;
opens envoy.client.ui.controller to javafx.graphics, javafx.fxml; opens envoy.client.ui.controller to javafx.graphics, javafx.fxml;
opens envoy.client.ui.custom to javafx.graphics, javafx.fxml;
} }

View File

@ -1,5 +1,5 @@
.button, .list-cell, .progress-bar * { .button, .list-cell, .progress-bar * {
-fx-background-radius: 5.0em; -fx-background-radius: 0.3em;
} }
.context-menu, .context-menu > * { .context-menu, .context-menu > * {
@ -8,6 +8,28 @@
-fx-background-color: transparent; -fx-background-color: transparent;
} }
#textEnterContainer, #contact-search-enter-container {
-fx-background-radius: 5.0em;
}
#roundButton {
-fx-background-radius: 5.0em;
}
.text-area {
-fx-background-color: transparent;
}
.text-area .scroll-pane {
-fx-background-color: transparent;
}
.text-area .scroll-pane .viewport{
-fx-background-color: transparent;
}
.text-area .scroll-pane .content{
-fx-background-color: transparent;
}
.menu-item { .menu-item {
-fx-background-radius: 15.0px; -fx-background-radius: 15.0px;
} }
@ -48,13 +70,13 @@
.received-message { .received-message {
-fx-alignment: center-left; -fx-alignment: center-left;
-fx-background-radius: 4.0em; -fx-background-radius: 1.3em;
-fx-text-alignment: right; -fx-text-alignment: right;
} }
.own-message { .own-message {
-fx-alignment: center-right; -fx-alignment: center-right;
-fx-background-radius: 4.0em; -fx-background-radius: 1.3em;
-fx-text-alignment: left; -fx-text-alignment: left;
} }
@ -65,6 +87,21 @@
-fx-text-alignment: center; -fx-text-alignment: center;
} }
#loginButton {
-fx-background-radius: 1.0em;
}
#registerSwitch {
-fx-background-color: transparent;
-fx-text-fill: orange;
}
#loginInputField {
-fx-background-color: transparent;
-fx-border: solid;
-fx-border-width: 0.0 0.0 1.0 0.0;
}
#remainingCharsLabel { #remainingCharsLabel {
-fx-text-fill: #00FF00; -fx-text-fill: #00FF00;
-fx-background-color: transparent; -fx-background-color: transparent;
@ -85,3 +122,15 @@
#infoLabel-error { #infoLabel-error {
-fx-text-fill: red; -fx-text-fill: red;
} }
#transparentBackground {
-fx-background-color: transparent;
}
#profilePic {
-fx-radius: 1.0em;
}
.listElement {
-fx-background-color: transparent;
}

View File

@ -18,8 +18,8 @@
-fx-background-color: lightgray; -fx-background-color: lightgray;
} }
.list-view, .list-cell, .text-area .content, .text-field, .password-field, .tooltip, .pane, .pane .content, .vbox, .titled-pane > .title, .titled-pane > *.content, .context-menu, .menu-item { #messageList, .text-field, .password-field, .tooltip, .pane, .pane .content, .vbox, .titled-pane > .title, .titled-pane > *.content, .context-menu, .menu-item {
-fx-background-color: dimgray; -fx-background-color: #222222;
} }
.list-cell:selected, .list-cell:selected > *, .menu-item:hover { .list-cell:selected, .list-cell:selected > *, .menu-item:hover {
@ -37,3 +37,48 @@
.alert.information.dialog-pane, .alert.warning.dialog-pane, .alert.error.dialog-pane { .alert.information.dialog-pane, .alert.warning.dialog-pane, .alert.error.dialog-pane {
-fx-background-color: black; -fx-background-color: black;
} }
#loginInputField {
-fx-border-color: white;
}
#loginBackground {
-fx-background-color: rgb(25, 25, 25);
}
#chatList, #topBar, #search-panel {
-fx-background-color: #303030;
}
#textEnterContainer {
-fx-background-color: #363636;
}
#contact-search-enter-container {
-fx-background-color: #202020;
}
#underline {
-fx-border: solid;
-fx-border-width: 0.0 0.0 1.0 0.0;
-fx-border-color: #202020;
}
.groupMemberNames {
-fx-text-fill: rgb(105.0,0.0,153.0);
-fx-font-weight: bold;
}
.scroll-bar:vertical, .scroll-bar:vertical .track, .scroll-bar:vertical .increment-button , .scroll-bar:vertical .decrement-button {
-fx-background-color: transparent;
}
.scroll-bar:vertical .increment-arrow, .scroll-bar:vertical .decrement-arrow {
-fx-background-color: transparent;
}
.scroll-bar:vertical .thumb {
-fx-background-color: #707070;
-fx-background-insets : 4.0, 0.0, 0.0;
-fx-background-radius : 2.0em;
}

View File

@ -14,3 +14,7 @@
.own-message { .own-message {
-fx-background-color: lightgreen; -fx-background-color: lightgreen;
} }
#loginInputField {
-fx-border-color: black;
}

View File

@ -3,7 +3,6 @@
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.geometry.Rectangle2D?> <?import javafx.geometry.Rectangle2D?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonBar?>
<?import javafx.scene.control.ContextMenu?> <?import javafx.scene.control.ContextMenu?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?> <?import javafx.scene.control.ListView?>
@ -13,166 +12,196 @@
<?import javafx.scene.image.ImageView?> <?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.ColumnConstraints?> <?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?> <?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Region?>
<?import javafx.scene.layout.RowConstraints?> <?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<GridPane fx:id="scene" hgap="5.0" maxHeight="-Infinity" <GridPane fx:id="scene" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="400.0" minWidth="500.0" prefHeight="1152.0" prefWidth="2042.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="envoy.client.ui.controller.ChatScene">
maxWidth="-Infinity" minHeight="400.0" minWidth="350.0"
prefHeight="400.0" prefWidth="600.0" vgap="2.0"
xmlns="http://javafx.com/javafx/11.0.1"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="envoy.client.ui.controller.ChatScene">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="NEVER" minWidth="60.0" <ColumnConstraints hgrow="NEVER" maxWidth="327.99997965494794" minWidth="-Infinity" prefWidth="317.0" />
prefWidth="160.0" /> <ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" />
<ColumnConstraints hgrow="ALWAYS"
maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="357.0" />
<ColumnConstraints hgrow="ALWAYS"
maxWidth="1.7976931348623157E308" minWidth="10.0" percentWidth="7.0"
prefWidth="357.0" />
</columnConstraints> </columnConstraints>
<rowConstraints> <rowConstraints>
<RowConstraints maxHeight="-Infinity" <RowConstraints maxHeight="122.00000508626302" minHeight="-Infinity" prefHeight="96.66666158040364" vgrow="NEVER" />
minHeight="-Infinity" prefHeight="50.0" vgrow="NEVER" /> <RowConstraints maxHeight="1.7976931348623157E308" minHeight="50.0" prefHeight="949.3333384195963" vgrow="ALWAYS" />
<RowConstraints maxHeight="-Infinity" <RowConstraints maxHeight="59.3333740234375" minHeight="-Infinity" prefHeight="22.666748046875" vgrow="NEVER" />
minHeight="-Infinity" prefHeight="20.0" vgrow="NEVER" /> <RowConstraints maxHeight="120.0" minHeight="-Infinity" prefHeight="83.333251953125" vgrow="NEVER" />
<RowConstraints maxHeight="1.7976931348623157E308"
minHeight="50.0" prefHeight="155.14286150251115" vgrow="ALWAYS" />
<RowConstraints maxHeight="-Infinity"
minHeight="-Infinity" prefHeight="20.0" vgrow="NEVER" />
<RowConstraints maxHeight="120.0" minHeight="40.0"
prefHeight="60.0" vgrow="NEVER" />
<RowConstraints maxHeight="-Infinity"
minHeight="-Infinity" prefHeight="40.0" vgrow="NEVER" />
</rowConstraints> </rowConstraints>
<children> <children>
<ListView fx:id="chatList" onMouseClicked="#chatListClicked" <VBox prefWidth="316.0" GridPane.rowIndex="1" GridPane.rowSpan="2147483647">
prefHeight="211.0" prefWidth="300.0" GridPane.rowIndex="1"
GridPane.rowSpan="2147483647">
<GridPane.margin> <GridPane.margin>
<Insets bottom="5.0" left="10.0" /> <Insets right="1.0" />
</GridPane.margin> </GridPane.margin>
<children>
<VBox id="search-panel" maxHeight="-Infinity" minHeight="-Infinity" prefHeight="80.0" prefWidth="316.0">
<children>
<Label id="contact-search-enter-container" maxHeight="30.0" minHeight="30.0" prefHeight="30.0" prefWidth="325.0">
<graphic>
<TextArea id="contactSearchInput" fx:id="contactSearch" focusTraversable="false" maxHeight="30.0" minHeight="30.0" onInputMethodTextChanged="#searchContacts" onKeyTyped="#searchContacts" prefHeight="30.0" prefWidth="200.0" promptText="Search Contacts">
<font>
<Font size="14.0" />
</font>
<padding> <padding>
<Insets bottom="5.0" left="5.0" right="2.0" top="5.0" /> <Insets left="12.0" right="12.0" />
</padding> </padding>
</TextArea>
</graphic>
<VBox.margin>
<Insets left="10.0" right="10.0" top="3.0" />
</VBox.margin>
</Label>
<HBox id="underline" alignment="TOP_CENTER" prefHeight="41.0" prefWidth="296.0" spacing="5.0">
<children>
<Button mnemonicParsing="true" onAction="#addContactButtonClicked" prefHeight="27.0" prefWidth="82.0" text=" Add Contact">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<HBox.margin>
<Insets />
</HBox.margin>
</Button>
<Button mnemonicParsing="false" prefHeight="27.0" prefWidth="82.0" text="New Group">
<HBox.margin>
<Insets />
</HBox.margin></Button>
</children>
<VBox.margin>
<Insets left="10.0" right="10.0" top="5.0" />
</VBox.margin>
<padding>
<Insets top="3.0" />
</padding>
</HBox>
</children>
</VBox>
<ListView id="chatList" fx:id="chatList" focusTraversable="false" onMouseClicked="#chatListClicked" prefWidth="316.0" VBox.vgrow="ALWAYS">
<contextMenu> <contextMenu>
<ContextMenu anchorLocation="CONTENT_TOP_LEFT"> <ContextMenu anchorLocation="CONTENT_TOP_LEFT">
<items> <items>
<MenuItem fx:id="deleteContactMenuItem" <MenuItem fx:id="deleteContactMenuItem" mnemonicParsing="false" onAction="#deleteContact" text="Delete" />
mnemonicParsing="false" onAction="#deleteContact" text="Delete" />
</items> </items>
</ContextMenu> </ContextMenu>
</contextMenu> </contextMenu>
</ListView>
<Label fx:id="contactLabel" prefHeight="27.0" prefWidth="134.0"
GridPane.columnSpan="2">
<GridPane.margin>
<Insets left="10.0" />
</GridPane.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Label>
<Button fx:id="settingsButton" mnemonicParsing="true"
onAction="#settingsButtonClicked" text="_Settings"
GridPane.columnIndex="1" GridPane.columnSpan="2147483647"
GridPane.halignment="RIGHT" GridPane.valignment="CENTER">
<GridPane.margin>
<Insets bottom="10.0" right="10.0" top="10.0" />
</GridPane.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Button>
<ListView fx:id="messageList" GridPane.columnIndex="1"
GridPane.columnSpan="2147483647" GridPane.rowIndex="1"
GridPane.rowSpan="2">
<GridPane.margin>
<Insets left="5.0" right="10.0" />
</GridPane.margin>
<padding> <padding>
<Insets bottom="5.0" left="5.0" right="2.0" top="5.0" /> <Insets bottom="5.0" left="5.0" right="2.0" top="5.0" />
</padding> </padding>
</ListView> </ListView>
<ButtonBar buttonMinWidth="40.0" GridPane.columnIndex="1" </children>
GridPane.columnSpan="2147483647" GridPane.halignment="CENTER" </VBox>
GridPane.rowIndex="5" GridPane.valignment="BOTTOM"> <HBox id="topBar" alignment="CENTER_LEFT" prefHeight="100.0">
<GridPane.margin> <children>
<ImageView id="profilePic" fx:id="clientProfilePic" fitHeight="43.0" fitWidth="43.0" pickOnBounds="true" preserveRatio="true">
<HBox.margin>
<Insets left="15.0" top="5.0" />
</HBox.margin>
</ImageView>
<Label id="transparentBackground" fx:id="contactLabel" prefHeight="27.0" prefWidth="134.0">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<font>
<Font size="18.0" />
</font>
<HBox.margin>
<Insets left="10.0" top="5.0" />
</HBox.margin>
</Label>
<Region id="transparentBackground" prefHeight="77.0" prefWidth="115.0" />
<VBox id="transparentBackground" alignment="CENTER_RIGHT" prefHeight="200.0" prefWidth="100.0" spacing="5.0">
<children>
<Button fx:id="settingsButton" mnemonicParsing="true" onAction="#settingsButtonClicked" prefHeight="30.0" prefWidth="30.0" text="">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<VBox.margin>
<Insets />
</VBox.margin>
</Button>
</children>
<HBox.margin>
<Insets right="10.0" /> <Insets right="10.0" />
</HBox.margin>
<opaqueInsets>
<Insets />
</opaqueInsets>
</VBox>
</children>
<GridPane.margin>
<Insets bottom="1.0" right="1.0" />
</GridPane.margin>
</HBox>
<ListView id="messageList" fx:id="messageList" focusTraversable="false" GridPane.columnIndex="1" GridPane.columnSpan="2147483647" GridPane.rowIndex="1" GridPane.rowSpan="2">
<GridPane.margin>
<Insets />
</GridPane.margin> </GridPane.margin>
<buttons>
<Button fx:id="rotateButton" mnemonicParsing="false"
onAction="#doABarrelRoll">
<padding> <padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="5.0" top="5.0" />
</padding> </padding>
</Button> </ListView>
<Button fx:id="attachmentButton" disable="true" <HBox alignment="CENTER" GridPane.columnIndex="1" GridPane.rowIndex="3">
mnemonicParsing="false" onAction="#attachmentButtonClicked"> <children>
<Label id="textEnterContainer" alignment="CENTER" minWidth="300.0" prefHeight="100.0" prefWidth="800.0">
<graphic>
<TextArea id="messageEnter" fx:id="messageTextArea" disable="true" onInputMethodTextChanged="#messageTextUpdated" onKeyPressed="#checkPostConditions" onKeyTyped="#checkKeyCombination" prefHeight="100.0" prefWidth="1250.0" promptText="Enter Message" wrapText="true">
<opaqueInsets>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</opaqueInsets>
<padding> <padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets left="17.0" right="17.0" />
</padding> </padding>
</Button> </TextArea>
<Button fx:id="voiceButton" disable="true" </graphic>
onAction="#voiceButtonClicked"> </Label>
<padding> <HBox prefHeight="38.0" prefWidth="100.0" spacing="5.0">
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <children>
</padding> <Button id="roundButton" fx:id="postButton" defaultButton="true" disable="true" minWidth="40.0" mnemonicParsing="true" onAction="#postMessage" prefHeight="40.0" prefWidth="40.0" text="Post">
</Button>
<Button fx:id="postButton" defaultButton="true"
disable="true" mnemonicParsing="true" onAction="#postMessage"
text="_Post">
<tooltip> <tooltip>
<Tooltip anchorLocation="WINDOW_TOP_LEFT" autoHide="true" <Tooltip anchorLocation="WINDOW_TOP_LEFT" autoHide="true" maxWidth="350.0" text="Click this button to send the message. If it is disabled, you first have to select a contact to send it to. A message may automatically be sent when you press (Ctrl + ) Enter, according to your preferences. Additionally sends a message when pressing &quot;Alt&quot; + &quot;P&quot;." wrapText="true" />
maxWidth="350.0"
text="Click this button to send the message. If it is disabled, you first have to select a contact to send it to. A message may automatically be sent when you press (Ctrl + ) Enter, according to your preferences. Additionally sends a message when pressing &quot;Alt&quot; + &quot;P&quot;."
wrapText="true" />
</tooltip> </tooltip>
<contextMenu> <contextMenu>
<ContextMenu anchorLocation="CONTENT_TOP_LEFT"> <ContextMenu anchorLocation="CONTENT_TOP_LEFT">
<items> <items>
<MenuItem mnemonicParsing="false" <MenuItem mnemonicParsing="false" onAction="#copyAndPostMessage" text="Copy and Send" />
onAction="#copyAndPostMessage" text="Copy and Send" />
</items> </items>
</ContextMenu> </ContextMenu>
</contextMenu> </contextMenu>
<padding> <padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding> </padding>
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Button> </Button>
</buttons> <Button id="roundButton" fx:id="voiceButton" disable="true" minWidth="40.0" onAction="#voiceButtonClicked" prefHeight="40.0" prefWidth="40.0">
</ButtonBar>
<TextArea fx:id="messageTextArea" disable="true"
onInputMethodTextChanged="#messageTextUpdated"
onKeyPressed="#checkPostConditions" onKeyTyped="#checkKeyCombination"
prefHeight="200.0" prefWidth="200.0" wrapText="true"
GridPane.columnIndex="1" GridPane.columnSpan="2147483647"
GridPane.rowIndex="4">
<GridPane.margin>
<Insets bottom="10.0" left="5.0" right="10.0" top="3.0" />
</GridPane.margin>
<opaqueInsets>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</opaqueInsets>
</TextArea>
<Button mnemonicParsing="true"
onAction="#addContactButtonClicked" text="_Add Contacts"
GridPane.halignment="CENTER" GridPane.rowIndex="5"
GridPane.valignment="CENTER">
<padding> <padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding> </padding>
<GridPane.margin>
<Insets bottom="10.0" left="10.0" right="5.0" />
</GridPane.margin>
</Button> </Button>
<Label id="remainingCharsLabel" fx:id="remainingChars" <Button id="roundButton" fx:id="attachmentButton" disable="true" minWidth="40.0" mnemonicParsing="false" onAction="#attachmentButtonClicked" prefHeight="40.0" prefWidth="40.0">
ellipsisString="" maxHeight="30.0" maxWidth="180.0" prefHeight="30.0" <padding>
prefWidth="180.0" text="remaining chars: 0/x" textFill="LIME"
textOverrun="LEADING_WORD_ELLIPSIS" visible="false"
GridPane.columnIndex="1" GridPane.rowIndex="3">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Button>
<Button id="roundButton" fx:id="rotateButton" minWidth="40.0" mnemonicParsing="false" onAction="#doABarrelRoll" prefHeight="40.0" prefWidth="40.0">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Button>
</children>
<HBox.margin>
<Insets left="5.0" />
</HBox.margin>
</HBox>
</children>
<GridPane.margin>
<Insets bottom="40.0" left="10.0" right="10.0" top="15.0" />
</GridPane.margin> </GridPane.margin>
</HBox>
<HBox prefHeight="100.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="2">
<children>
<Label id="remainingCharsLabel" fx:id="remainingChars" ellipsisString="" maxHeight="30.0" maxWidth="180.0" prefHeight="30.0" prefWidth="180.0" text="remaining chars: 0/x" textFill="LIME" textOverrun="LEADING_WORD_ELLIPSIS" visible="false">
<padding> <padding>
<Insets bottom="5.0" top="5.0" /> <Insets bottom="5.0" top="5.0" />
</padding> </padding>
@ -180,25 +209,17 @@
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</opaqueInsets> </opaqueInsets>
<tooltip> <tooltip>
<Tooltip <Tooltip text="Shows how many chars you can still enter in this message" wrapText="true" />
text="Shows how many chars you can still enter in this message"
wrapText="true" />
</tooltip> </tooltip>
</Label> </Label>
<Label fx:id="infoLabel" text="Something happened" <Label fx:id="infoLabel" text="Something happened" textFill="#faa007" visible="false" wrapText="true">
textFill="#faa007" visible="false" wrapText="true"
GridPane.columnIndex="1">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
<padding> <padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding> </padding>
</Label> </Label>
<ImageView fx:id="attachmentView" pickOnBounds="true" </children>
preserveRatio="true" visible="false" GridPane.columnIndex="1" </HBox>
GridPane.columnSpan="2147483647" GridPane.halignment="RIGHT" <ImageView fx:id="attachmentView" pickOnBounds="true" preserveRatio="true" visible="false" GridPane.columnIndex="1" GridPane.columnSpan="2147483647" GridPane.halignment="RIGHT" GridPane.rowIndex="2">
GridPane.rowIndex="3">
<viewport> <viewport>
<Rectangle2D height="20.0" width="20.0" /> <Rectangle2D height="20.0" width="20.0" />
</viewport> </viewport>
@ -206,5 +227,33 @@
<Insets bottom="5.0" right="10.0" top="5.0" /> <Insets bottom="5.0" right="10.0" top="5.0" />
</GridPane.margin> </GridPane.margin>
</ImageView> </ImageView>
<HBox id="topBar" alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="200.0" GridPane.columnIndex="1">
<children>
<ImageView id="profilePic" fx:id="recipientProfilePic" fitHeight="43.0" fitWidth="43.0" pickOnBounds="true" preserveRatio="true">
<HBox.margin>
<Insets left="20.0" top="5.0" />
</HBox.margin>
</ImageView>
<VBox alignment="CENTER_LEFT" prefHeight="97.0" prefWidth="316.0">
<children>
<Label fx:id="topBarContactLabel" text="">
<font>
<Font size="18.0" />
</font>
</Label>
<Label fx:id="topBarStatusLabel" text="" />
</children>
<HBox.margin>
<Insets left="15.0" />
</HBox.margin>
</VBox>
<Region prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS" />
<Button id="roundButton" fx:id="messageSearchButton" contentDisplay="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="40.0" prefWidth="40.0" visible="false">
<HBox.margin>
<Insets right="20.0" />
</HBox.margin>
</Button>
</children>
</HBox>
</children> </children>
</GridPane> </GridPane>

View File

@ -1,94 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import envoy.client.ui.ClearableTextField?>
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.PasswordField?> <?import javafx.scene.control.PasswordField?>
<?import javafx.scene.layout.BorderPane?> <?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.ColumnConstraints?> <?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?> <?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?> <?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<VBox prefHeight="206.0" prefWidth="440.0" <VBox id="loginBackground" alignment="TOP_CENTER" prefHeight="500.0" prefWidth="350.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="envoy.client.ui.controller.LoginScene">
xmlns="http://javafx.com/javafx/11.0.1"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="envoy.client.ui.controller.LoginScene">
<children> <children>
<Label text="User Login"> <ImageView fx:id="logo" fitHeight="80.0" fitWidth="80.0" pickOnBounds="true" preserveRatio="true">
<VBox.margin>
<Insets bottom="10.0" top="50.0" />
</VBox.margin>
<image>
<Image url="file:@../icons/envoy_logo.png" />
</image>
</ImageView>
<Label alignment="TOP_CENTER" contentDisplay="CENTER" layoutX="142.0" layoutY="15.0" text="ENVOY MESSENGER" textAlignment="CENTER">
<font>
<Font size="14.0" />
</font>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Label>
<Label alignment="TOP_CENTER" contentDisplay="CENTER"
prefHeight="33.0" prefWidth="110.0" text="LOGIN"
textAlignment="CENTER">
<font> <font>
<Font size="26.0" /> <Font size="26.0" />
</font> </font>
<VBox.margin> <VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets left="5.0" right="5.0" top="5.0" />
</VBox.margin> </VBox.margin>
<padding> <padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding> </padding>
</Label> </Label>
<GridPane hgap="5.0" vgap="10.0"> <GridPane hgap="5.0" vgap="8.5">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
minWidth="10.0" percentWidth="40.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES"
minWidth="10.0" prefWidth="100.0" />
</columnConstraints> </columnConstraints>
<rowConstraints> <rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0"
vgrow="SOMETIMES" />
</rowConstraints> </rowConstraints>
<children> <children>
<Label text="User Name:"> <TextField id="loginInputField" fx:id="userTextField" promptText="Username">
<GridPane.margin> <GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="0.0" left="5.0" right="5.0" top="0.0" />
</GridPane.margin> </GridPane.margin>
<padding> </TextField>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" /> <PasswordField id="loginInputField" fx:id="passwordField" promptText=" Password" GridPane.rowIndex="1">
</padding>
</Label>
<Label text="Password:" GridPane.rowIndex="1">
<padding>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</padding>
<GridPane.margin> <GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="0.0" left="5.0" right="5.0" top="0.0" />
</GridPane.margin>
</Label>
<Label fx:id="repeatPasswordLabel" text="Repeat Password:"
visible="false" GridPane.rowIndex="2">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
<padding>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</padding>
</Label>
<ClearableTextField fx:id="userTextField"
GridPane.columnIndex="1">
<GridPane.margin>
<Insets bottom="10.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
</ClearableTextField>
<PasswordField fx:id="passwordField"
GridPane.columnIndex="1" GridPane.rowIndex="1">
<GridPane.margin>
<Insets bottom="10.0" left="5.0" right="5.0" top="10.0" />
</GridPane.margin> </GridPane.margin>
<padding> <padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding> </padding>
</PasswordField> </PasswordField>
<PasswordField fx:id="repeatPasswordField" <PasswordField id="loginInputField" fx:id="repeatPasswordField" promptText=" Repeat Password" visible="false" GridPane.rowIndex="2">
visible="false" GridPane.columnIndex="1" GridPane.rowIndex="2">
<GridPane.margin> <GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="10.0" /> <Insets bottom="0.0" left="5.0" right="5.0" top="0.0" />
</GridPane.margin> </GridPane.margin>
<padding> <padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
@ -96,54 +78,40 @@
</PasswordField> </PasswordField>
</children> </children>
<VBox.margin> <VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="10.0" left="25.0" right="25.0" top="10.0" />
</VBox.margin> </VBox.margin>
</GridPane> </GridPane>
<CheckBox fx:id="registerCheckBox" mnemonicParsing="true" <Button id="loginButton" fx:id="loginButton" defaultButton="true" focusTraversable="false" mnemonicParsing="false" onAction="#loginButtonPressed" text="Login" textAlignment="CENTER">
onAction="#registerCheckboxChanged" prefHeight="17.0" <font>
prefWidth="181.0" text="_Register"> <Font size="16.0" />
</font>
<opaqueInsets>
<Insets />
</opaqueInsets>
<padding>
<Insets bottom="2.0" left="125.0" right="125.0" top="2.0" />
</padding>
</Button>
<HBox alignment="CENTER" prefHeight="30.0" prefWidth="200.0">
<children>
<Label fx:id="registerTextLabel" text="No account yet?" />
<Button id="registerSwitch" fx:id="registerSwitch" accessibleRole="CHECK_BOX" focusTraversable="false" mnemonicParsing="false" onAction="#registerSwitchPressed" text="Register" />
</children>
<VBox.margin> <VBox.margin>
<Insets left="5.0" right="3.0" /> <Insets bottom="20.0" />
</VBox.margin> </VBox.margin>
</CheckBox> </HBox>
<Button fx:id="offlineModeButton" focusTraversable="false" mnemonicParsing="false" onAction="#offlineModeButtonPressed" text="Offline mode">
<VBox.margin>
<Insets bottom="5.0" top="20.0" />
</VBox.margin></Button>
<Label fx:id="connectionLabel"> <Label fx:id="connectionLabel">
<VBox.margin> <VBox.margin>
<Insets left="5.0" /> <Insets left="5.0" />
</VBox.margin> </VBox.margin>
<font>
<Font size="12.0" />
</font>
</Label> </Label>
<BorderPane prefWidth="200.0">
<left>
<Button cancelButton="true" mnemonicParsing="false"
onAction="#abortLogin" text="Close" BorderPane.alignment="CENTER">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<BorderPane.margin>
<Insets />
</BorderPane.margin>
</Button>
</left>
<center>
<Button mnemonicParsing="false"
onAction="#offlineModeButtonPressed" text="Offline mode"
BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets />
</BorderPane.margin>
</Button>
</center>
<right>
<Button defaultButton="true" mnemonicParsing="false"
onAction="#loginButtonPressed" text="Login"
BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets />
</BorderPane.margin>
</Button>
</right>
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" />
</VBox.margin>
</BorderPane>
</children> </children>
</VBox> </VBox>

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

View File

@ -23,6 +23,8 @@ public class Bounds {
*/ */
public static final Pattern CONTACT_NAME_PATTERN = Pattern.compile("^\\w[a-zA-Z0-9-]{2,15}$"); public static final Pattern CONTACT_NAME_PATTERN = Pattern.compile("^\\w[a-zA-Z0-9-]{2,15}$");
// KAI: Trust of Chain - das berühmte Konzept aus der Kryptographie
/** /**
* @param contactName the contact name to validate * @param contactName the contact name to validate
* @return {@code true} if the given contact name is valid * @return {@code true} if the given contact name is valid