From 28fe5cdb27f44ec432ff5abd19544464e8be7557 Mon Sep 17 00:00:00 2001 From: delvh Date: Sun, 28 Jun 2020 22:30:14 +0200 Subject: [PATCH] Updated UI (again) --- .../ui/controller/ContactSearchScene.java | 39 +-- .../ui/controller/GroupCreationScene.java | 22 +- .../client/ui/controller/LoginScene.java | 15 +- src/main/resources/fxml/ChatScene.fxml | 29 +-- .../resources/fxml/ContactSearchScene.fxml | 131 +++++----- .../resources/fxml/GroupCreationScene.fxml | 134 ++++++----- src/main/resources/fxml/LoginScene.fxml | 223 +++++++++++------- src/main/resources/fxml/SettingsScene.fxml | 73 +++--- 8 files changed, 369 insertions(+), 297 deletions(-) diff --git a/src/main/java/envoy/client/ui/controller/ContactSearchScene.java b/src/main/java/envoy/client/ui/controller/ContactSearchScene.java index 54c505c..743759c 100644 --- a/src/main/java/envoy/client/ui/controller/ContactSearchScene.java +++ b/src/main/java/envoy/client/ui/controller/ContactSearchScene.java @@ -5,11 +5,14 @@ import java.util.logging.Logger; import javafx.application.Platform; import javafx.fxml.FXML; -import javafx.scene.control.*; +import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.ButtonType; +import javafx.scene.control.ListView; import envoy.client.data.LocalDB; import envoy.client.event.SendEvent; +import envoy.client.ui.ClearableTextField; import envoy.client.ui.ContactListCell; import envoy.client.ui.SceneContext; import envoy.data.Contact; @@ -31,19 +34,7 @@ import envoy.util.EnvoyLog; public class ContactSearchScene { @FXML - private Button backButton; - - @FXML - private Button clearButton; - - @FXML - private Button searchButton; - - @FXML - private Button newGroupButton; - - @FXML - private TextField searchBar; + private ClearableTextField searchBar; @FXML private ListView contactList; @@ -78,20 +69,12 @@ public class ContactSearchScene { * @since Envoy Client v0.1-beta */ @FXML - private void checkClearButton() { - final var containsContent = searchBar.getText().strip().isEmpty(); - clearButton.setDisable(containsContent); - searchButton.setDisable(containsContent); + private void sendRequest() { + final var text = searchBar.getTextField().getText().strip(); + if (!text.isBlank()) eventBus.dispatch(new SendEvent(new ContactSearchRequest(text))); + else contactList.getItems().clear(); } - /** - * Sends a {@link ContactSearchRequest} to the server. - * - * @since Envoy Client v0.1-beta - */ - @FXML - private void suggestContacts() { eventBus.dispatch(new SendEvent(new ContactSearchRequest(searchBar.getText()))); } - /** * Clears the text in the search bar and the items shown in the list. * Additionally disables both clear and search button. @@ -100,10 +83,8 @@ public class ContactSearchScene { */ @FXML private void clear() { - searchBar.setText(null); + searchBar.getTextField().setText(null); contactList.getItems().clear(); - clearButton.setDisable(true); - searchButton.setDisable(true); } /** diff --git a/src/main/java/envoy/client/ui/controller/GroupCreationScene.java b/src/main/java/envoy/client/ui/controller/GroupCreationScene.java index c6d7d05..484d207 100644 --- a/src/main/java/envoy/client/ui/controller/GroupCreationScene.java +++ b/src/main/java/envoy/client/ui/controller/GroupCreationScene.java @@ -9,6 +9,7 @@ import javafx.scene.control.Alert.AlertType; import envoy.client.data.LocalDB; import envoy.client.event.SendEvent; +import envoy.client.ui.ClearableTextField; import envoy.client.ui.ContactListCell; import envoy.client.ui.SceneContext; import envoy.data.Contact; @@ -30,7 +31,7 @@ public class GroupCreationScene { private Button createButton; @FXML - private TextField groupNameField; + private ClearableTextField groupNameField; @FXML private ListView contactList; @@ -59,11 +60,22 @@ public class GroupCreationScene { /** * Enables the {@code createButton} if at least one contact is selected. - * + * * @since Envoy Client v0.1-beta */ @FXML - private void contactListClicked() { createButton.setDisable(contactList.getSelectionModel().isEmpty()); } + private void contactListClicked() { + createButton.setDisable(contactList.getSelectionModel().isEmpty() || groupNameField.getTextField().getText().isBlank()); + } + + /** + * Checks, whether the {@code createButton} can be enabled because text is + * present in the textfield. + * + * @since Envoy Client v0.1-beta + */ + @FXML + private void textUpdated() { createButton.setDisable(groupNameField.getTextField().getText().isBlank()); } /** * Sends a {@link GroupCreation} to the server and closes this scene. @@ -74,10 +86,10 @@ public class GroupCreationScene { */ @FXML private void createButtonClicked() { - final var name = groupNameField.getText(); + final var name = groupNameField.getTextField().getText(); if (!Bounds.isValidContactName(name)) { new Alert(AlertType.ERROR, "The entered group name is not valid (" + Bounds.CONTACT_NAME_PATTERN + ")").showAndWait(); - groupNameField.clear(); + groupNameField.getTextField().clear(); } else { eventBus.dispatch(new SendEvent(new GroupCreation(name, contactList.getSelectionModel().getSelectedItems().stream().map(Contact::getID).collect(Collectors.toSet())))); diff --git a/src/main/java/envoy/client/ui/controller/LoginScene.java b/src/main/java/envoy/client/ui/controller/LoginScene.java index 380842a..db75bc4 100644 --- a/src/main/java/envoy/client/ui/controller/LoginScene.java +++ b/src/main/java/envoy/client/ui/controller/LoginScene.java @@ -13,6 +13,7 @@ import javafx.scene.control.Alert.AlertType; import envoy.client.data.*; import envoy.client.net.Client; +import envoy.client.ui.ClearableTextField; import envoy.client.ui.SceneContext; import envoy.client.ui.Startup; import envoy.data.LoginCredentials; @@ -38,7 +39,7 @@ import envoy.util.EnvoyLog; public final class LoginScene { @FXML - private TextField userTextField; + private ClearableTextField userTextField; @FXML private PasswordField passwordField; @@ -116,17 +117,17 @@ public final class LoginScene { if (registerCheckBox.isSelected() && !passwordField.getText().equals(repeatPasswordField.getText())) { new Alert(AlertType.ERROR, "The entered password is unequal to the repeated one").showAndWait(); repeatPasswordField.clear(); - } else if (!Bounds.isValidContactName(userTextField.getText())) { + } else if (!Bounds.isValidContactName(userTextField.getTextField().getText())) { new Alert(AlertType.ERROR, "The entered user name is not valid (" + Bounds.CONTACT_NAME_PATTERN + ")").showAndWait(); - userTextField.clear(); - } else - performHandshake( - new LoginCredentials(userTextField.getText(), passwordField.getText().toCharArray(), registerCheckBox.isSelected(), Startup.VERSION)); + userTextField.getTextField().clear(); + } else performHandshake(new LoginCredentials(userTextField.getTextField().getText(), passwordField.getText().toCharArray(), + registerCheckBox.isSelected(), Startup.VERSION)); } @FXML private void offlineModeButtonPressed() { - attemptOfflineMode(new LoginCredentials(userTextField.getText(), passwordField.getText().toCharArray(), false, Startup.VERSION)); + attemptOfflineMode( + new LoginCredentials(userTextField.getTextField().getText(), passwordField.getText().toCharArray(), false, Startup.VERSION)); } @FXML diff --git a/src/main/resources/fxml/ChatScene.fxml b/src/main/resources/fxml/ChatScene.fxml index fa1a4ef..666a148 100644 --- a/src/main/resources/fxml/ChatScene.fxml +++ b/src/main/resources/fxml/ChatScene.fxml @@ -12,9 +12,9 @@ - @@ -47,7 +47,7 @@ prefHeight="211.0" prefWidth="300.0" GridPane.rowIndex="1" GridPane.rowSpan="2147483647"> - + @@ -64,7 +64,7 @@