From 51b189e8f5b5d8fd32e306dcfc8cf6df0b6718d4 Mon Sep 17 00:00:00 2001 From: DieGurke Date: Sat, 3 Oct 2020 20:28:43 +0200 Subject: [PATCH] Implemented some requested changes --- .../client/ui/control/QuickSelectControl.java | 12 ++++++------ .../client/ui/controller/GroupCreationTab.java | 18 +++++++++++------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java b/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java index b5d95a7..92a750f 100644 --- a/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java +++ b/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java @@ -11,17 +11,18 @@ import envoy.client.util.IconUtil; import envoy.data.User; /** - * Displays a user as a quickSelectControl which is used in the quickSelectList. + * Displays an {@link User} as a quickSelectControl which is used in the + * quickSelectList. * * @author Maximilian Käfer * @since Envoy Client v0.3-beta */ public class QuickSelectControl extends VBox { - User user; + private User user; /** - * Creates an instance of the {@link QuickSelectControl}. + * Creates an instance of the {@code QuickSelectControl}. * * @param user the user whose data is used to create this instance. * @param tab the parent tab ({@link GroupCreationTab}). @@ -49,7 +50,6 @@ public class QuickSelectControl extends VBox { clip.setArcHeight(32); clip.setArcWidth(32); contactProfilePic.setClip(clip); - setAlignment(Pos.TOP_CENTER); picHold.getChildren().add(contactProfilePic); stackPane.getChildren().add(picHold); @@ -59,7 +59,7 @@ public class QuickSelectControl extends VBox { hBox.setMinHeight(12); var region = new Region(); hBox.getChildren().add(region); - hBox.setHgrow(region, Priority.ALWAYS); + HBox.setHgrow(region, Priority.ALWAYS); var removeBtn = new Button(); removeBtn.setPrefSize(12, 12); @@ -85,7 +85,7 @@ public class QuickSelectControl extends VBox { } /** - * @return the user whose data is used in this instance. + * @return the user whose data is used in this instance * @since Envoy Client v0.3-beta */ public User getUser() { return user; } diff --git a/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java index 2bd09cc..6434910 100644 --- a/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java +++ b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java @@ -7,6 +7,7 @@ import java.util.stream.Collectors; import javafx.application.Platform; import javafx.fxml.FXML; import javafx.scene.control.*; +import javafx.scene.input.MouseEvent; import javafx.scene.layout.HBox; import envoy.client.data.*; @@ -82,6 +83,7 @@ public class GroupCreationTab implements EventListener { .map(User.class::cast) .collect(Collectors.toList())); resizeQuickSelectSpace(0); + quickSelectList.addEventFilter(MouseEvent.MOUSE_PRESSED, evt -> evt.consume()); } /** @@ -91,11 +93,13 @@ public class GroupCreationTab implements EventListener { */ @FXML private void userListClicked() { - createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getText().isBlank()); - quickSelectList.getItems().add(new QuickSelectControl(userList.getSelectionModel().getSelectedItem(), this)); - resizeQuickSelectSpace(60); - userList.getItems().remove(userList.getSelectionModel().getSelectedItem()); - userList.getSelectionModel().clearSelection(); + if (userList.getSelectionModel().getSelectedItem() != null) { + quickSelectList.getItems().add(new QuickSelectControl(userList.getSelectionModel().getSelectedItem(), this)); + createButton.setDisable(quickSelectList.getItems().isEmpty() || groupNameField.getText().isBlank()); + resizeQuickSelectSpace(60); + userList.getItems().remove(userList.getSelectionModel().getSelectedItem()); + userList.getSelectionModel().clearSelection(); + } } /** @@ -105,7 +109,7 @@ public class GroupCreationTab implements EventListener { * @since Envoy Client v0.1-beta */ @FXML - private void textUpdated() { createButton.setDisable(quickSelectList.getItems().size() == 0 || groupNameField.getText().isBlank()); } + private void textUpdated() { createButton.setDisable(quickSelectList.getItems().isEmpty() || groupNameField.getText().isBlank()); } /** * Sends a {@link GroupCreation} to the server and closes this scene. @@ -173,7 +177,7 @@ public class GroupCreationTab implements EventListener { public void removeFromQuickSelection(QuickSelectControl element) { quickSelectList.getItems().remove(element); userList.getItems().add(element.getUser()); - if (quickSelectList.getItems().size() == 0) { + if (quickSelectList.getItems().isEmpty()) { resizeQuickSelectSpace(0); createButton.setDisable(true); }