From 89f99866457333ef272aaf8953d92e11c3a23cb3 Mon Sep 17 00:00:00 2001 From: Mark Joseph Starzynsi Date: Sat, 13 Nov 2021 19:37:43 +0100 Subject: [PATCH 1/3] Fix dropdown menu appearance and add test method to author button - Fixed odd behaviour where dropdown reapppears when repeatedly clicking search bar - Removed detachable attrubute (for now?) - Corrected Checkstyle - Added test method to author button (dont allow attributes without search terms) --- .../org/jabref/gui/search/DropDownMenu.java | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/jabref/gui/search/DropDownMenu.java b/src/main/java/org/jabref/gui/search/DropDownMenu.java index a200033dd0a..4bcfe30562d 100644 --- a/src/main/java/org/jabref/gui/search/DropDownMenu.java +++ b/src/main/java/org/jabref/gui/search/DropDownMenu.java @@ -23,6 +23,7 @@ public class DropDownMenu { public Button leftBracketButton; public Button rightBracketButton; public RecentSearch recentSearch; + private boolean isPrevAttribute; // private final Button articleButton; // private final Button bookButton; // private final Button citationKeyButton; @@ -60,30 +61,34 @@ public DropDownMenu(CustomTextField searchField, GlobalSearchBar globalSearchBar Node buttonBox = mainBox; searchField.addEventFilter(MouseEvent.MOUSE_CLICKED, event -> { - if (searchbarDropDown == null) { + if (searchbarDropDown == null || !searchbarDropDown.isShowing()) { searchbarDropDown = new PopOver(buttonBox); searchbarDropDown.setWidth(searchField.getWidth()); searchbarDropDown.setArrowLocation(PopOver.ArrowLocation.TOP_CENTER); searchbarDropDown.setContentNode(buttonBox); + searchbarDropDown.setDetachable(false); // not detachable searchbarDropDown.show(searchField); - } else if (searchbarDropDown.isShowing()) { - searchbarDropDown.hide(); +// } else if (searchbarDropDown.isShowing()) { +// searchbarDropDown.hide(); // this makes the dropdown disappear if you re-click on searchbar } else { - searchbarDropDown.setContentNode(buttonBox); - searchbarDropDown.show(searchField); +// searchbarDropDown.setContentNode(buttonBox); + // this makes the drop down reappear every time you click on search bar, even if its shown already +// searchbarDropDown.show(searchField); } }); // authorButton action authorButton.setOnAction(event -> { - if (searchField.getCaretPosition() != 0) { - if (!searchField.getText(searchField.getCaretPosition() - 1, searchField.getCaretPosition()).equals(" ")) { - searchField.insertText(searchField.getCaretPosition(), " "); - searchField.positionCaret(searchField.getText().length()); + if (!isPrevAttribute(searchField)) { // checks if the search term prior is an attribute and wont queue another if so + if (searchField.getCaretPosition() != 0) { + if (!searchField.getText(searchField.getCaretPosition() - 1, searchField.getCaretPosition()).equals(" ")) { + searchField.insertText(searchField.getCaretPosition(), " "); + searchField.positionCaret(searchField.getText().length()); + } } + searchField.insertText(searchField.getCaretPosition(), "author:"); + searchField.positionCaret(searchField.getText().length()); } - searchField.insertText(searchField.getCaretPosition(), "author:"); - searchField.positionCaret(searchField.getText().length()); }); // journalButton action @@ -183,4 +188,14 @@ public DropDownMenu(CustomTextField searchField, GlobalSearchBar globalSearchBar }); } + private boolean isPrevAttribute(CustomTextField searchField) { + isPrevAttribute = false; + if (searchField.getCaretPosition() != 0) { + if (searchField.getText(searchField.getCaretPosition() - 1, searchField.getCaretPosition()).equals(":")) { + isPrevAttribute = true; + System.out.println("IS TRUEEEEEEEEEEEEEEEEEEEEEEEEEEEE"); + } + } + return isPrevAttribute; + } } From cd71654c3488b7b97f9f87ff7a3d843f32be4b51 Mon Sep 17 00:00:00 2001 From: Mark Joseph Starzynsi Date: Sat, 13 Nov 2021 20:02:53 +0100 Subject: [PATCH 2/3] Improve buttons and fix dropdown menu appearance - Fixed odd behaviour where dropdown reapppears when repeatedly clicking search bar - Removed detachable attrubute (for now?) - Corrected Checkstyle - Buttons dont allow adding attributes when prior ones are empty --- .../org/jabref/gui/search/DropDownMenu.java | 59 ++++++++----------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/jabref/gui/search/DropDownMenu.java b/src/main/java/org/jabref/gui/search/DropDownMenu.java index 4bcfe30562d..1340008bc24 100644 --- a/src/main/java/org/jabref/gui/search/DropDownMenu.java +++ b/src/main/java/org/jabref/gui/search/DropDownMenu.java @@ -80,12 +80,7 @@ public DropDownMenu(CustomTextField searchField, GlobalSearchBar globalSearchBar // authorButton action authorButton.setOnAction(event -> { if (!isPrevAttribute(searchField)) { // checks if the search term prior is an attribute and wont queue another if so - if (searchField.getCaretPosition() != 0) { - if (!searchField.getText(searchField.getCaretPosition() - 1, searchField.getCaretPosition()).equals(" ")) { - searchField.insertText(searchField.getCaretPosition(), " "); - searchField.positionCaret(searchField.getText().length()); - } - } + checkAndAddSpace(searchField); // checks if there is a space prior and if not adds it searchField.insertText(searchField.getCaretPosition(), "author:"); searchField.positionCaret(searchField.getText().length()); } @@ -93,50 +88,34 @@ public DropDownMenu(CustomTextField searchField, GlobalSearchBar globalSearchBar // journalButton action journalButton.setOnAction(event -> { - if (searchField.getCaretPosition() != 0) { - if (!searchField.getText(searchField.getCaretPosition() - 1, searchField.getCaretPosition()).equals(" ")) { - searchField.insertText(searchField.getCaretPosition(), " "); - searchField.positionCaret(searchField.getText().length()); - } + if (!isPrevAttribute(searchField)) { + checkAndAddSpace(searchField); + searchField.insertText(searchField.getCaretPosition(), "journal:"); + searchField.positionCaret(searchField.getText().length()); } - searchField.insertText(searchField.getCaretPosition(), "journal:"); - searchField.positionCaret(searchField.getText().length()); }); // titleButton action titleButton.setOnAction(event -> { - if (searchField.getCaretPosition() != 0) { - if (!searchField.getText(searchField.getCaretPosition() - 1, searchField.getCaretPosition()).equals(" ")) { - searchField.insertText(searchField.getCaretPosition(), " "); - searchField.positionCaret(searchField.getText().length()); - } + if (!isPrevAttribute(searchField)) { + checkAndAddSpace(searchField); + searchField.insertText(searchField.getCaretPosition(), "title:"); + searchField.positionCaret(searchField.getText().length()); } - searchField.insertText(searchField.getCaretPosition(), "title:"); - searchField.positionCaret(searchField.getText().length()); }); // yearButton action yearButton.setOnAction(event -> { - if (searchField.getCaretPosition() != 0) { - if (!searchField.getText(searchField.getCaretPosition() - 1, searchField.getCaretPosition()).equals(" ")) { - searchField.insertText(searchField.getCaretPosition(), " "); - searchField.positionCaret(searchField.getText().length()); - } + if (!isPrevAttribute(searchField)) { + checkAndAddSpace(searchField); + searchField.insertText(searchField.getCaretPosition(), "year:"); + searchField.positionCaret(searchField.getText().length()); } - searchField.insertText(searchField.getCaretPosition(), "year:"); - searchField.positionCaret(searchField.getText().length()); }); // yearRangeButton action yearRangeButton.setOnAction(event -> { - if (searchField.getCaretPosition() != 0) { - if (!searchField.getText(searchField.getCaretPosition() - 1, searchField.getCaretPosition()).equals(" ")) { - searchField.insertText(searchField.getCaretPosition(), " "); - searchField.positionCaret(searchField.getText().length()); - } - } - searchField.insertText(searchField.getCaretPosition(), "year:"); - searchField.positionCaret(searchField.getText().length()); + }); // andButton action @@ -188,12 +167,20 @@ public DropDownMenu(CustomTextField searchField, GlobalSearchBar globalSearchBar }); } + private void checkAndAddSpace(CustomTextField searchField) { + if (searchField.getCaretPosition() != 0) { + if (!searchField.getText(searchField.getCaretPosition() - 1, searchField.getCaretPosition()).equals(" ")) { + searchField.insertText(searchField.getCaretPosition(), " "); + searchField.positionCaret(searchField.getText().length()); + } + } + } + private boolean isPrevAttribute(CustomTextField searchField) { isPrevAttribute = false; if (searchField.getCaretPosition() != 0) { if (searchField.getText(searchField.getCaretPosition() - 1, searchField.getCaretPosition()).equals(":")) { isPrevAttribute = true; - System.out.println("IS TRUEEEEEEEEEEEEEEEEEEEEEEEEEEEE"); } } return isPrevAttribute; From c6f80668863c1e7d9cde45d94ce5cb5e52b3f780 Mon Sep 17 00:00:00 2001 From: dmadoery Date: Sun, 14 Nov 2021 19:40:59 +0100 Subject: [PATCH 3/3] add buttonEventHandler for DropDownMenu --- .../org/jabref/gui/search/DropDownMenu.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/jabref/gui/search/DropDownMenu.java b/src/main/java/org/jabref/gui/search/DropDownMenu.java index 1340008bc24..23a2c611162 100644 --- a/src/main/java/org/jabref/gui/search/DropDownMenu.java +++ b/src/main/java/org/jabref/gui/search/DropDownMenu.java @@ -78,7 +78,7 @@ public DropDownMenu(CustomTextField searchField, GlobalSearchBar globalSearchBar }); // authorButton action - authorButton.setOnAction(event -> { + authorButton.addEventFilter(MouseEvent.MOUSE_CLICKED, event -> { if (!isPrevAttribute(searchField)) { // checks if the search term prior is an attribute and wont queue another if so checkAndAddSpace(searchField); // checks if there is a space prior and if not adds it searchField.insertText(searchField.getCaretPosition(), "author:"); @@ -87,7 +87,7 @@ public DropDownMenu(CustomTextField searchField, GlobalSearchBar globalSearchBar }); // journalButton action - journalButton.setOnAction(event -> { + journalButton.addEventFilter(MouseEvent.MOUSE_CLICKED, event ->{ if (!isPrevAttribute(searchField)) { checkAndAddSpace(searchField); searchField.insertText(searchField.getCaretPosition(), "journal:"); @@ -96,7 +96,7 @@ public DropDownMenu(CustomTextField searchField, GlobalSearchBar globalSearchBar }); // titleButton action - titleButton.setOnAction(event -> { + titleButton.addEventFilter(MouseEvent.MOUSE_CLICKED, event ->{ if (!isPrevAttribute(searchField)) { checkAndAddSpace(searchField); searchField.insertText(searchField.getCaretPosition(), "title:"); @@ -105,7 +105,7 @@ public DropDownMenu(CustomTextField searchField, GlobalSearchBar globalSearchBar }); // yearButton action - yearButton.setOnAction(event -> { + yearButton.addEventFilter(MouseEvent.MOUSE_CLICKED, event ->{ if (!isPrevAttribute(searchField)) { checkAndAddSpace(searchField); searchField.insertText(searchField.getCaretPosition(), "year:"); @@ -114,12 +114,12 @@ public DropDownMenu(CustomTextField searchField, GlobalSearchBar globalSearchBar }); // yearRangeButton action - yearRangeButton.setOnAction(event -> { + yearRangeButton.addEventFilter(MouseEvent.MOUSE_CLICKED, event ->{ }); // andButton action - andButton.setOnAction(event -> { + andButton.addEventFilter(MouseEvent.MOUSE_CLICKED, event ->{ if (searchField.getCaretPosition() != 0) { if (!searchField.getText(searchField.getCaretPosition() - 1, searchField.getCaretPosition()).equals(" ")) { searchField.insertText(searchField.getCaretPosition(), " "); @@ -131,7 +131,7 @@ public DropDownMenu(CustomTextField searchField, GlobalSearchBar globalSearchBar }); // orButton action - orButton.setOnAction(event -> { + orButton.addEventFilter(MouseEvent.MOUSE_CLICKED, event ->{ if (searchField.getCaretPosition() != 0) { if (!searchField.getText(searchField.getCaretPosition() - 1, searchField.getCaretPosition()).equals(" ")) { searchField.insertText(searchField.getCaretPosition(), " "); @@ -143,7 +143,7 @@ public DropDownMenu(CustomTextField searchField, GlobalSearchBar globalSearchBar }); // leftBracketButton action - leftBracketButton.setOnAction(event -> { + leftBracketButton.addEventFilter(MouseEvent.MOUSE_CLICKED, event ->{ if (searchField.getCaretPosition() != 0) { if (!searchField.getText(searchField.getCaretPosition() - 1, searchField.getCaretPosition()).equals(" ")) { searchField.insertText(searchField.getCaretPosition(), " "); @@ -155,7 +155,7 @@ public DropDownMenu(CustomTextField searchField, GlobalSearchBar globalSearchBar }); // orButton action - rightBracketButton.setOnAction(event -> { + rightBracketButton.addEventFilter(MouseEvent.MOUSE_CLICKED, event ->{ if (searchField.getCaretPosition() != 0) { if (!searchField.getText(searchField.getCaretPosition() - 1, searchField.getCaretPosition()).equals(" ")) { searchField.insertText(searchField.getCaretPosition(), " ");