From dde7702eab503861a905687a6055083fc9aa363d Mon Sep 17 00:00:00 2001 From: law39 Date: Thu, 30 Apr 2020 17:32:03 +0100 Subject: [PATCH] Search in Dictionary Controller updated Search in Dictionary Controller now displays verbs by the search term to when you enter "to " only. --- .../cs22120/group20/javafx/DictionaryController.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/DictionaryController.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/DictionaryController.java index 5bf3355..6ececf2 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/DictionaryController.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/DictionaryController.java @@ -87,7 +87,7 @@ public class DictionaryController extends SharedCodeController { } table.sort(); searchBox.textProperty().setValue(searchBox.textProperty().getValue() + " "); - searchBox.textProperty().setValue(searchBox.textProperty().getValue().trim()); + searchBox.textProperty().setValue(searchBox.textProperty().getValue().substring(0, searchBox.textProperty().getValue().length()-1)); searchBox.positionCaret(searchBox.textProperty().getValue().length()); } @@ -215,7 +215,6 @@ public class DictionaryController extends SharedCodeController { searchBox.textProperty().addListener((observable, oldSearchTerm, newSearchTerm) -> { filteredList.setPredicate(dictionaryEntry -> { // returns true on a filter match, false if no match boolean result = false; - table.refresh(); // This fixes the table highlighting issue if (newSearchTerm == null || newSearchTerm.isEmpty()) { // If filter text is empty, display all dictionary entries @@ -227,8 +226,10 @@ public class DictionaryController extends SharedCodeController { if (dictionaryEntry.getEnglish().toLowerCase().startsWith(lowerCaseSearchFilter)) { result = true; // Filter matches English } - else if (dictionaryEntry.getWordType().equals(DictionaryEntry.wordTypeEnum.verb) && ("to " + dictionaryEntry.getEnglish()).toLowerCase().startsWith(lowerCaseSearchFilter)) { - result = true; // Filter matches ['to' + a word] or [a word] if word is a verb + else if(lowerCaseSearchFilter.startsWith("to ")){ + if (dictionaryEntry.getWordType().equals(DictionaryEntry.wordTypeEnum.verb) && ("to " + dictionaryEntry.getEnglish()).toLowerCase().startsWith(lowerCaseSearchFilter)) { + result = true; // Filter matches ['to' + a word] or [a word] if word is a verb + } } } else {