From 7fffa0da8307d15a34d412fa9ddcb2eb28a575a1 Mon Sep 17 00:00:00 2001 From: DieGurke Date: Wed, 30 Sep 2020 21:44:02 +0200 Subject: [PATCH 1/9] implemented basic architecture --- .../client/ui/control/QuickSelectControl.java | 21 +++++++++++++++++++ .../ui/controller/GroupCreationTab.java | 10 +++++++-- client/src/main/resources/css/dark.css | 4 ++++ .../main/resources/fxml/GroupCreationTab.fxml | 1 + 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 client/src/main/java/envoy/client/ui/control/QuickSelectControl.java diff --git a/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java b/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java new file mode 100644 index 0000000..d7e7bfe --- /dev/null +++ b/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java @@ -0,0 +1,21 @@ +package envoy.client.ui.control; + +import javafx.scene.control.Label; + +import envoy.data.User; + +/** + * @author Maximilian Käfer + * @since Envoy Client v0.3-beta + */ +public class QuickSelectControl extends Label { + + public QuickSelectControl(User user) { + setPrefSize(35, 35); + setMaxSize(35, 35); + setMinSize(35, 35); + setText(user.getName()); + getStyleClass().add("quick-select"); + } + +} 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 4243ce4..7970c5d 100644 --- a/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java +++ b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java @@ -11,7 +11,7 @@ import javafx.scene.layout.HBox; import envoy.client.data.*; import envoy.client.event.BackEvent; -import envoy.client.ui.control.ContactControl; +import envoy.client.ui.control.*; import envoy.client.ui.listcell.ListCellFactory; import envoy.data.*; import envoy.event.GroupCreation; @@ -58,6 +58,9 @@ public class GroupCreationTab implements EventListener { @FXML private HBox errorProceedBox; + @FXML + private ListView quickSelectList; + private String name; private final LocalDB localDB = Context.getInstance().getLocalDB(); @@ -86,7 +89,10 @@ public class GroupCreationTab implements EventListener { * @since Envoy Client v0.1-beta */ @FXML - private void userListClicked() { createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getText().isBlank()); } + private void userListClicked() { + createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getText().isBlank()); + quickSelectList.getItems().add(new QuickSelectControl(userList.getSelectionModel().getSelectedItem())); + } /** * Checks, whether the {@code createButton} can be enabled because text is diff --git a/client/src/main/resources/css/dark.css b/client/src/main/resources/css/dark.css index 7ab6a59..df7527a 100644 --- a/client/src/main/resources/css/dark.css +++ b/client/src/main/resources/css/dark.css @@ -83,3 +83,7 @@ -fx-text-fill: white; -fx-background-color: transparent; } + +.quick-select { + -fx-background-color: black; +} diff --git a/client/src/main/resources/fxml/GroupCreationTab.fxml b/client/src/main/resources/fxml/GroupCreationTab.fxml index cb4dbad..f954324 100644 --- a/client/src/main/resources/fxml/GroupCreationTab.fxml +++ b/client/src/main/resources/fxml/GroupCreationTab.fxml @@ -64,6 +64,7 @@ + From 8592839156a047619c18a45ff51eca107f04a246 Mon Sep 17 00:00:00 2001 From: DieGurke Date: Thu, 1 Oct 2020 22:29:40 +0200 Subject: [PATCH 2/9] Worked on quickMessageList and corresponding control --- .../client/ui/control/QuickSelectControl.java | 31 ++++++++++++++++--- client/src/main/resources/css/dark.css | 8 ++--- .../main/resources/fxml/GroupCreationTab.fxml | 2 +- 3 files changed, 29 insertions(+), 12 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 d7e7bfe..f8b286e 100644 --- a/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java +++ b/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java @@ -1,20 +1,41 @@ package envoy.client.ui.control; +import javafx.geometry.Pos; import javafx.scene.control.Label; +import javafx.scene.image.ImageView; +import javafx.scene.layout.VBox; +import javafx.scene.shape.Rectangle; +import envoy.client.util.IconUtil; import envoy.data.User; /** * @author Maximilian Käfer * @since Envoy Client v0.3-beta */ -public class QuickSelectControl extends Label { +public class QuickSelectControl extends VBox { public QuickSelectControl(User user) { - setPrefSize(35, 35); - setMaxSize(35, 35); - setMinSize(35, 35); - setText(user.getName()); + + // Profile picture + ImageView contactProfilePic = new ImageView(IconUtil.loadIconThemeSensitive("user_icon", 32)); + final var clip = new Rectangle(); + clip.setWidth(32); + clip.setHeight(32); + clip.setArcHeight(32); + clip.setArcWidth(32); + contactProfilePic.setClip(clip); + setAlignment(Pos.TOP_CENTER); + getChildren().add(contactProfilePic); + + Label nameLabel = new Label(); + nameLabel.setPrefSize(35, 20); + nameLabel.setMaxSize(35, 20); + nameLabel.setMinSize(35, 20); + nameLabel.setText(user.getName()); + nameLabel.setAlignment(Pos.TOP_CENTER); + getChildren().add(nameLabel); + getStyleClass().add("quick-select"); } diff --git a/client/src/main/resources/css/dark.css b/client/src/main/resources/css/dark.css index df7527a..eb52eed 100644 --- a/client/src/main/resources/css/dark.css +++ b/client/src/main/resources/css/dark.css @@ -42,7 +42,7 @@ -fx-background-color: #191919; } -#chat-list, #top-bar, #search-panel, #note-background { +#chat-list, #top-bar, #search-panel, #note-background, .quick-select { -fx-background-color: #303030; } @@ -69,7 +69,7 @@ -fx-background-color: transparent; } -.scroll-bar:vertical .increment-arrow, .scroll-bar:vertical .decrement-arrow { +.scroll-bar:vertical .increment-arrow, .scroll-bar:vertical .decrement-arrow, #quick-select-list, .list-cell { -fx-background-color: transparent; } @@ -83,7 +83,3 @@ -fx-text-fill: white; -fx-background-color: transparent; } - -.quick-select { - -fx-background-color: black; -} diff --git a/client/src/main/resources/fxml/GroupCreationTab.fxml b/client/src/main/resources/fxml/GroupCreationTab.fxml index f954324..19699dc 100644 --- a/client/src/main/resources/fxml/GroupCreationTab.fxml +++ b/client/src/main/resources/fxml/GroupCreationTab.fxml @@ -64,7 +64,7 @@ - + From 8543e94040ab012390ab9c743dbcf5eecd466964 Mon Sep 17 00:00:00 2001 From: DieGurke Date: Thu, 1 Oct 2020 22:59:07 +0200 Subject: [PATCH 3/9] Added ability to remove users from quick select list --- .../client/ui/control/QuickSelectControl.java | 16 +++++++++++++--- .../client/ui/controller/GroupCreationTab.java | 4 +++- client/src/main/resources/css/dark.css | 5 +++++ 3 files changed, 21 insertions(+), 4 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 f8b286e..6585ff5 100644 --- a/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java +++ b/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java @@ -1,11 +1,12 @@ package envoy.client.ui.control; import javafx.geometry.Pos; -import javafx.scene.control.Label; +import javafx.scene.control.*; import javafx.scene.image.ImageView; import javafx.scene.layout.VBox; import javafx.scene.shape.Rectangle; +import envoy.client.ui.controller.GroupCreationTab; import envoy.client.util.IconUtil; import envoy.data.User; @@ -15,7 +16,17 @@ import envoy.data.User; */ public class QuickSelectControl extends VBox { - public QuickSelectControl(User user) { + public QuickSelectControl(User user, GroupCreationTab tab) { + Button removeBtn = new Button(); + removeBtn.setPrefSize(10, 10); + removeBtn.setMaxSize(10, 10); + removeBtn.setMinSize(10, 10); + removeBtn.setAlignment(Pos.TOP_RIGHT); + removeBtn.setOnMouseClicked(evt -> { + tab.removeFromQuickSelection(this); + }); + removeBtn.setId("remove-button"); + getChildren().add(removeBtn); // Profile picture ImageView contactProfilePic = new ImageView(IconUtil.loadIconThemeSensitive("user_icon", 32)); @@ -38,5 +49,4 @@ public class QuickSelectControl extends VBox { getStyleClass().add("quick-select"); } - } 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 7970c5d..8f055dd 100644 --- a/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java +++ b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java @@ -91,7 +91,7 @@ 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())); + quickSelectList.getItems().add(new QuickSelectControl(userList.getSelectionModel().getSelectedItem(), this)); } /** @@ -157,6 +157,8 @@ public class GroupCreationTab implements EventListener { return localDB.getChats().stream().map(Chat::getRecipient).filter(Group.class::isInstance).map(Contact::getName).anyMatch(newName::equals); } + public void removeFromQuickSelection(QuickSelectControl element) { quickSelectList.getItems().remove(element); } + @FXML private void backButtonClicked() { eventBus.dispatch(new BackEvent()); diff --git a/client/src/main/resources/css/dark.css b/client/src/main/resources/css/dark.css index eb52eed..e2ef2e7 100644 --- a/client/src/main/resources/css/dark.css +++ b/client/src/main/resources/css/dark.css @@ -83,3 +83,8 @@ -fx-text-fill: white; -fx-background-color: transparent; } + +#remove-button { + -fx-background-color: red; + -fx-background-radius: 1em; +} From 434d577c1554ed81509ca540501a88553127b9f3 Mon Sep 17 00:00:00 2001 From: DieGurke Date: Sat, 3 Oct 2020 14:47:50 +0200 Subject: [PATCH 4/9] Worked on displaying the quickSelect correctly --- .../client/ui/control/QuickSelectControl.java | 51 +++++++++++++------ .../ui/controller/GroupCreationTab.java | 15 +++++- client/src/main/resources/css/base.css | 14 ++++- client/src/main/resources/css/dark.css | 6 +-- .../main/resources/fxml/GroupCreationTab.fxml | 2 +- 5 files changed, 67 insertions(+), 21 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 6585ff5..9097d1b 100644 --- a/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java +++ b/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java @@ -1,9 +1,9 @@ package envoy.client.ui.control; -import javafx.geometry.Pos; +import javafx.geometry.*; import javafx.scene.control.*; import javafx.scene.image.ImageView; -import javafx.scene.layout.VBox; +import javafx.scene.layout.*; import javafx.scene.shape.Rectangle; import envoy.client.ui.controller.GroupCreationTab; @@ -17,19 +17,19 @@ import envoy.data.User; public class QuickSelectControl extends VBox { public QuickSelectControl(User user, GroupCreationTab tab) { - Button removeBtn = new Button(); - removeBtn.setPrefSize(10, 10); - removeBtn.setMaxSize(10, 10); - removeBtn.setMinSize(10, 10); - removeBtn.setAlignment(Pos.TOP_RIGHT); - removeBtn.setOnMouseClicked(evt -> { - tab.removeFromQuickSelection(this); - }); - removeBtn.setId("remove-button"); - getChildren().add(removeBtn); + setPrefWidth(37); + setMaxWidth(37); + setMinWidth(37); + var stackPane = new StackPane(); + stackPane.setAlignment(Pos.TOP_CENTER); // Profile picture - ImageView contactProfilePic = new ImageView(IconUtil.loadIconThemeSensitive("user_icon", 32)); + var picHold = new VBox(); + picHold.setPadding(new Insets(2, 0, 0, 0)); + picHold.setPrefHeight(35); + picHold.setMaxHeight(35); + picHold.setMinHeight(35); + var contactProfilePic = new ImageView(IconUtil.loadIconThemeSensitive("user_icon", 32)); final var clip = new Rectangle(); clip.setWidth(32); clip.setHeight(32); @@ -37,14 +37,35 @@ public class QuickSelectControl extends VBox { clip.setArcWidth(32); contactProfilePic.setClip(clip); setAlignment(Pos.TOP_CENTER); - getChildren().add(contactProfilePic); + picHold.getChildren().add(contactProfilePic); + stackPane.getChildren().add(picHold); - Label nameLabel = new Label(); + var hBox = new HBox(); + hBox.setPrefHeight(12); + hBox.setMaxHeight(12); + hBox.setMinHeight(12); + var region = new Region(); + hBox.getChildren().add(region); + hBox.setHgrow(region, Priority.ALWAYS); + + var removeBtn = new Button(); + removeBtn.setPrefSize(12, 12); + removeBtn.setMaxSize(12, 12); + removeBtn.setMinSize(12, 12); + removeBtn.setOnMouseClicked(evt -> tab.removeFromQuickSelection(this)); + removeBtn.setId("remove-button"); + hBox.getChildren().add(removeBtn); + stackPane.getChildren().add(hBox); + getChildren().add(stackPane); + + + var nameLabel = new Label(); nameLabel.setPrefSize(35, 20); nameLabel.setMaxSize(35, 20); nameLabel.setMinSize(35, 20); nameLabel.setText(user.getName()); nameLabel.setAlignment(Pos.TOP_CENTER); + nameLabel.setPadding(new Insets(0, 5, 0, 0)); getChildren().add(nameLabel); getStyleClass().add("quick-select"); 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 8f055dd..ca6a179 100644 --- a/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java +++ b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java @@ -81,6 +81,9 @@ public class GroupCreationTab implements EventListener { .filter(not(localDB.getUser()::equals)) .map(User.class::cast) .collect(Collectors.toList())); + quickSelectList.setPrefHeight(0); + quickSelectList.setMaxHeight(0); + quickSelectList.setMinHeight(0); } /** @@ -92,6 +95,9 @@ public class GroupCreationTab implements EventListener { private void userListClicked() { createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getText().isBlank()); quickSelectList.getItems().add(new QuickSelectControl(userList.getSelectionModel().getSelectedItem(), this)); + quickSelectList.setPrefHeight(60); + quickSelectList.setMaxHeight(60); + quickSelectList.setMinHeight(60); } /** @@ -157,7 +163,14 @@ public class GroupCreationTab implements EventListener { return localDB.getChats().stream().map(Chat::getRecipient).filter(Group.class::isInstance).map(Contact::getName).anyMatch(newName::equals); } - public void removeFromQuickSelection(QuickSelectControl element) { quickSelectList.getItems().remove(element); } + public void removeFromQuickSelection(QuickSelectControl element) { + quickSelectList.getItems().remove(element); + if (quickSelectList.getItems().size() == 0) { + quickSelectList.setPrefHeight(0); + quickSelectList.setMaxHeight(0); + quickSelectList.setMinHeight(0); + } + } @FXML private void backButtonClicked() { diff --git a/client/src/main/resources/css/base.css b/client/src/main/resources/css/base.css index 79099d7..be559b7 100644 --- a/client/src/main/resources/css/base.css +++ b/client/src/main/resources/css/base.css @@ -41,7 +41,7 @@ -fx-scale-y: 1.05; } -.label { +.label, .quick-select { -fx-background-color: transparent; } @@ -144,3 +144,15 @@ visibility: hidden ; -fx-padding: -20.0 0.0 0.0 0.0; } + +#quick-select-list .scroll-bar:horizontal{ + -fx-pref-height: 0; + -fx-max-height: 0; + -fx-min-height: 0; +} + +#quick-select-list .scroll-bar:vertical{ + -fx-pref-width: 0; + -fx-max-width: 0; + -fx-min-width: 0; +} diff --git a/client/src/main/resources/css/dark.css b/client/src/main/resources/css/dark.css index e2ef2e7..0ed2997 100644 --- a/client/src/main/resources/css/dark.css +++ b/client/src/main/resources/css/dark.css @@ -18,7 +18,7 @@ -fx-background-color: lightgray; } -#message-list, .text-field, .password-field, .tooltip, .pane, .pane .content, .vbox, .titled-pane > .title, .titled-pane > *.content, .context-menu, .menu-item { +#message-list, .text-field, .password-field, .tooltip, .pane, .pane .content, .vbox, .titled-pane > .title, .titled-pane > *.content, .context-menu, .menu-item, #quick-select-list { -fx-background-color: #222222; } @@ -42,7 +42,7 @@ -fx-background-color: #191919; } -#chat-list, #top-bar, #search-panel, #note-background, .quick-select { +#chat-list, #top-bar, #search-panel, #note-background { -fx-background-color: #303030; } @@ -69,7 +69,7 @@ -fx-background-color: transparent; } -.scroll-bar:vertical .increment-arrow, .scroll-bar:vertical .decrement-arrow, #quick-select-list, .list-cell { +.scroll-bar:vertical .increment-arrow, .scroll-bar:vertical .decrement-arrow, .list-cell { -fx-background-color: transparent; } diff --git a/client/src/main/resources/fxml/GroupCreationTab.fxml b/client/src/main/resources/fxml/GroupCreationTab.fxml index 19699dc..688ae0d 100644 --- a/client/src/main/resources/fxml/GroupCreationTab.fxml +++ b/client/src/main/resources/fxml/GroupCreationTab.fxml @@ -64,7 +64,7 @@ - + From ab77c98a361788f69c3adc72ff90b22a90977c07 Mon Sep 17 00:00:00 2001 From: DieGurke Date: Sat, 3 Oct 2020 15:08:02 +0200 Subject: [PATCH 5/9] Added functionality --- .../client/ui/control/QuickSelectControl.java | 5 +++ .../ui/controller/GroupCreationTab.java | 31 ++++++++++++------- 2 files changed, 24 insertions(+), 12 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 9097d1b..2019a5c 100644 --- a/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java +++ b/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java @@ -16,7 +16,10 @@ import envoy.data.User; */ public class QuickSelectControl extends VBox { + User user; + public QuickSelectControl(User user, GroupCreationTab tab) { + this.user = user; setPrefWidth(37); setMaxWidth(37); setMinWidth(37); @@ -70,4 +73,6 @@ public class QuickSelectControl extends VBox { getStyleClass().add("quick-select"); } + + 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 ca6a179..82a24af 100644 --- a/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java +++ b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java @@ -70,7 +70,7 @@ public class GroupCreationTab implements EventListener { @FXML private void initialize() { userList.setCellFactory(new ListCellFactory<>(ContactControl::new)); - userList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); + userList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); createButton.setDisable(true); eventBus.registerListener(this); userList.getItems() @@ -81,9 +81,7 @@ public class GroupCreationTab implements EventListener { .filter(not(localDB.getUser()::equals)) .map(User.class::cast) .collect(Collectors.toList())); - quickSelectList.setPrefHeight(0); - quickSelectList.setMaxHeight(0); - quickSelectList.setMinHeight(0); + resizeQuickSelectSpace(0); } /** @@ -95,9 +93,9 @@ public class GroupCreationTab implements EventListener { private void userListClicked() { createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getText().isBlank()); quickSelectList.getItems().add(new QuickSelectControl(userList.getSelectionModel().getSelectedItem(), this)); - quickSelectList.setPrefHeight(60); - quickSelectList.setMaxHeight(60); - quickSelectList.setMinHeight(60); + resizeQuickSelectSpace(60); + userList.getItems().remove(userList.getSelectionModel().getSelectedItem()); + userList.getSelectionModel().clearSelection(); } /** @@ -107,7 +105,7 @@ public class GroupCreationTab implements EventListener { * @since Envoy Client v0.1-beta */ @FXML - private void textUpdated() { createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getText().isBlank()); } + private void textUpdated() { createButton.setDisable(quickSelectList.getItems().size() == 0 || groupNameField.getText().isBlank()); } /** * Sends a {@link GroupCreation} to the server and closes this scene. @@ -135,6 +133,9 @@ public class GroupCreationTab implements EventListener { // Restoring the original design as tabs will always be reused setErrorMessageLabelSize(0); groupNameField.clear(); + quickSelectList.getItems().forEach(q -> userList.getItems().add(q.getUser())); + quickSelectList.getItems().clear(); + resizeQuickSelectSpace(0); } } @@ -148,7 +149,7 @@ public class GroupCreationTab implements EventListener { private void createGroup(String name) { Context.getInstance() .getClient() - .send(new GroupCreation(name, userList.getSelectionModel().getSelectedItems().stream().map(User::getID).collect(Collectors.toSet()))); + .send(new GroupCreation(name, quickSelectList.getItems().stream().map(q -> q.getUser().getID()).collect(Collectors.toSet()))); } /** @@ -165,13 +166,19 @@ public class GroupCreationTab implements EventListener { public void removeFromQuickSelection(QuickSelectControl element) { quickSelectList.getItems().remove(element); + userList.getItems().add(element.getUser()); if (quickSelectList.getItems().size() == 0) { - quickSelectList.setPrefHeight(0); - quickSelectList.setMaxHeight(0); - quickSelectList.setMinHeight(0); + resizeQuickSelectSpace(0); + createButton.setDisable(true); } } + private void resizeQuickSelectSpace(int value) { + quickSelectList.setPrefHeight(value); + quickSelectList.setMaxHeight(value); + quickSelectList.setMinHeight(value); + } + @FXML private void backButtonClicked() { eventBus.dispatch(new BackEvent()); From 5f0910635a9339196f7b17d96e8335fb0d3c8952 Mon Sep 17 00:00:00 2001 From: DieGurke Date: Sat, 3 Oct 2020 15:11:38 +0200 Subject: [PATCH 6/9] Added insets --- .../main/java/envoy/client/ui/control/QuickSelectControl.java | 1 + 1 file changed, 1 insertion(+) 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 2019a5c..617cd53 100644 --- a/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java +++ b/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java @@ -20,6 +20,7 @@ public class QuickSelectControl extends VBox { public QuickSelectControl(User user, GroupCreationTab tab) { this.user = user; + setPadding(new Insets(1, 0, 0, 0)); setPrefWidth(37); setMaxWidth(37); setMinWidth(37); From 3d987985ff721bc8c17c773f960b547752f9d3da Mon Sep 17 00:00:00 2001 From: DieGurke Date: Sat, 3 Oct 2020 15:19:37 +0200 Subject: [PATCH 7/9] Added javadoc --- .../envoy/client/ui/control/QuickSelectControl.java | 13 +++++++++++++ .../client/ui/controller/GroupCreationTab.java | 6 ++++++ 2 files changed, 19 insertions(+) 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 617cd53..b5d95a7 100644 --- a/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java +++ b/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java @@ -11,6 +11,8 @@ import envoy.client.util.IconUtil; import envoy.data.User; /** + * Displays a user as a quickSelectControl which is used in the quickSelectList. + * * @author Maximilian Käfer * @since Envoy Client v0.3-beta */ @@ -18,6 +20,13 @@ public class QuickSelectControl extends VBox { User user; + /** + * Creates an instance of the {@link QuickSelectControl}. + * + * @param user the user whose data is used to create this instance. + * @param tab the parent tab ({@link GroupCreationTab}). + * @since Envoy Client v0.3-beta + */ public QuickSelectControl(User user, GroupCreationTab tab) { this.user = user; setPadding(new Insets(1, 0, 0, 0)); @@ -75,5 +84,9 @@ public class QuickSelectControl extends VBox { getStyleClass().add("quick-select"); } + /** + * @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 82a24af..2bd09cc 100644 --- a/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java +++ b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java @@ -164,6 +164,12 @@ public class GroupCreationTab implements EventListener { return localDB.getChats().stream().map(Chat::getRecipient).filter(Group.class::isInstance).map(Contact::getName).anyMatch(newName::equals); } + /** + * Removes an element from the quickSelectList. + * + * @param element the element to be removed. + * @since Envoy Client v0.3-beta + */ public void removeFromQuickSelection(QuickSelectControl element) { quickSelectList.getItems().remove(element); userList.getItems().add(element.getUser()); From 51b189e8f5b5d8fd32e306dcfc8cf6df0b6718d4 Mon Sep 17 00:00:00 2001 From: DieGurke Date: Sat, 3 Oct 2020 20:28:43 +0200 Subject: [PATCH 8/9] 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); } From 994cbbcd7273c2864f10d63bd37a88a57ffaebab Mon Sep 17 00:00:00 2001 From: DieGurke Date: Sun, 4 Oct 2020 17:11:45 +0200 Subject: [PATCH 9/9] Implemented change requests by @delvh and @kske --- .../client/ui/control/QuickSelectControl.java | 18 +++++++++--------- .../client/ui/controller/GroupCreationTab.java | 3 +-- 2 files changed, 10 insertions(+), 11 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 92a750f..0e1b2e5 100644 --- a/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java +++ b/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java @@ -1,18 +1,19 @@ package envoy.client.ui.control; +import java.util.function.Consumer; + import javafx.geometry.*; import javafx.scene.control.*; import javafx.scene.image.ImageView; import javafx.scene.layout.*; import javafx.scene.shape.Rectangle; -import envoy.client.ui.controller.GroupCreationTab; import envoy.client.util.IconUtil; -import envoy.data.User; +import envoy.data.*; /** - * Displays an {@link User} as a quickSelectControl which is used in the - * quickSelectList. + * Displays an {@link User} as a quick select control which is used in the + * quick select list. * * @author Maximilian Käfer * @since Envoy Client v0.3-beta @@ -24,11 +25,11 @@ public class QuickSelectControl extends VBox { /** * 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}). + * @param user the contact whose data is used to create this instance. + * @param action the action to perform when a contact is removed with this control as a parameter * @since Envoy Client v0.3-beta */ - public QuickSelectControl(User user, GroupCreationTab tab) { + public QuickSelectControl(User user, Consumer action) { this.user = user; setPadding(new Insets(1, 0, 0, 0)); setPrefWidth(37); @@ -65,13 +66,12 @@ public class QuickSelectControl extends VBox { removeBtn.setPrefSize(12, 12); removeBtn.setMaxSize(12, 12); removeBtn.setMinSize(12, 12); - removeBtn.setOnMouseClicked(evt -> tab.removeFromQuickSelection(this)); + removeBtn.setOnMouseClicked(evt -> action.accept(this)); removeBtn.setId("remove-button"); hBox.getChildren().add(removeBtn); stackPane.getChildren().add(hBox); getChildren().add(stackPane); - var nameLabel = new Label(); nameLabel.setPrefSize(35, 20); nameLabel.setMaxSize(35, 20); 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 6434910..23ec485 100644 --- a/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java +++ b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java @@ -71,7 +71,6 @@ public class GroupCreationTab implements EventListener { @FXML private void initialize() { userList.setCellFactory(new ListCellFactory<>(ContactControl::new)); - userList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); createButton.setDisable(true); eventBus.registerListener(this); userList.getItems() @@ -94,7 +93,7 @@ public class GroupCreationTab implements EventListener { @FXML private void userListClicked() { if (userList.getSelectionModel().getSelectedItem() != null) { - quickSelectList.getItems().add(new QuickSelectControl(userList.getSelectionModel().getSelectedItem(), this)); + quickSelectList.getItems().add(new QuickSelectControl(userList.getSelectionModel().getSelectedItem(), this::removeFromQuickSelection)); createButton.setDisable(quickSelectList.getItems().isEmpty() || groupNameField.getText().isBlank()); resizeQuickSelectSpace(60); userList.getItems().remove(userList.getSelectionModel().getSelectedItem());