From 19fcf162ee946b07db0ef40c163c34d6d2460bca Mon Sep 17 00:00:00 2001 From: top19 Date: Fri, 1 May 2020 14:20:47 +0100 Subject: [PATCH 1/6] Updated documentation for SharedCodeController.java. Addressed issue #49. --- .../group20/javafx/SharedCodeController.java | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/SharedCodeController.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/SharedCodeController.java index 89e8149..5a0a2f0 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/SharedCodeController.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/SharedCodeController.java @@ -1,3 +1,9 @@ +/** + * @(#) FlashcardController.java 0,1 2020/05/07 + *

+ * Copyright (c) 2020 Aberystwyth University. + * All rights reserved. + */ package uk.ac.aber.cs221.group20.javafx; import javafx.fxml.FXML; @@ -12,8 +18,9 @@ import uk.ac.aber.cs221.group20.json.DictionaryEntry; * Abstract class that contains all the shared FXML elements between the * different controller classes including the sliding menu and the test score counter, to reduce code * duplication. This will be extended by all the controller classes. + * * @author Tom Perry [top19] - * @Version 0.1 Initial development. + * @Version 0.2 Documentation. * @see Application * @see DictionaryEntry * @see ScreenSwitch @@ -25,7 +32,9 @@ abstract public class SharedCodeController { // Class variables. // // //////////////// // + // Static variable that tracks whether the words are currently sorted by english or welsh. static boolean isSortedByEnglish = true; + // Static variable that tracks the current size of the menu's sideBar to keep its size consistent when switching scenes. static int sideBarWidth = 50; // /////////////////// // @@ -71,9 +80,11 @@ abstract public class SharedCodeController { * Method that sets up the program's menu in each of the controllers, intialising the icons and text. */ public void setup() { + // Call method to setup the icons and set the menus side bars width to the current value of 'sideBar'. initializeIcons(); sideBar.setWidth(sideBarWidth); + // If the menus width isnt the default value, the menu is determined to be expanded and the text is initialised. if (sideBarWidth != 50) initializeMenuText(); } @@ -102,7 +113,7 @@ abstract public class SharedCodeController { } /** - * Method that disables the menus text when the menu is collapsed. + * Method that disables the menus text when the menu is collapsed by setting their text to nothing. */ private void disableMenuText() { dictionaryText.setText(""); @@ -113,41 +124,49 @@ abstract public class SharedCodeController { } /** - * Event that expands the menu whenever the menu's 'expandMenuIcon' icon is clicked. + * Event that collapses or expands the menu whenever the 'expandMenuIcon' is clicked by the user. The method determines the menus current state by looking at the value of + * 'sideBarWidth' and uses to decide whether the menu needs to expand to 230 and initialise the menu text or collapse to 50, disabling menu text. */ @FXML private void expandMenuClick() { - if(sideBar.getWidth() == 50) { // If sideBar is currently collapsed, expand it and display menu text. - + // If sideBar is currently collapsed, expand it and display menu text. + if(sideBar.getWidth() == 50) { sideBar.setWidth(sideBarWidth = 230); - initializeMenuText(); // Display menu + // Display menu + initializeMenuText(); } else { - sideBar.setWidth(sideBarWidth = 50); // Else collapse the menu and disable its text. + // Else collapse the menu and disable its text. + sideBar.setWidth(sideBarWidth = 50); disableMenuText(); } } /** * Event to switch scenes to 'dictionary.fxml' when the menu's 'dictionaryIcon' icon is clicked. + * * @see ScreenSwitch */ @FXML private void dictionaryIconClick() { + // Use 'ScreenSwitch' to switch to the 'dictionaryScene'. ScreenSwitch.swap(ScreenSwitch.SceneType.dictionaryScene); } /** * Event to switch scenes to 'practicelist.fxml' when the menu's 'practiceListIcon' icon is clicked. + * * @see ScreenSwitch */ @FXML private void practiceListIconClick() { - ScreenSwitch.swap(ScreenSwitch.SceneType.practiceListScene); + // Use 'ScreenSwitch' to switch to the 'practiceListScene'. + ScreenSwitch.swap(ScreenSwitch.SceneType.practiceListScene); } /** * Event to switch scenes to 'flashcard.fxml' when the menu's 'practiceListIcon' icon is clicked. This method checks to see if practiceList is empty before switching in order * to avoid NullPointerException's in the flashcard scene. + * * @see ScreenSwitch * @see Application * @see DictionaryEntry @@ -155,36 +174,40 @@ abstract public class SharedCodeController { */ @FXML private void flashcardIconClick() { - - if(Application.practiceList.size() == 0) { // Check to see if there are any practice words before switching scene, throwing an alert notifying them that they can't switch scenes. + // Check to see if there are any practice words before switching scene, throwing an alert notifying them that they can't switch scenes. + if(Application.practiceList.size() == 0) { Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle("Error"); alert.setHeaderText("Unable to use Flashcard"); alert.setContentText("The practice list is currently empty, please add some practice words to use the Flashcard feature."); alert.showAndWait(); } else{ - ScreenSwitch.swap(ScreenSwitch.SceneType.flashcardScene); // Switch to flashcard scene if the program has practice words. + // Switch to flashcard scene if the program has practice words. + ScreenSwitch.swap(ScreenSwitch.SceneType.flashcardScene); } } /** * Event to generate an assessment using AssessmentGenerator when the menu's 'studyIcon' icon is clicked. + * * @see AssessmentGenerator * @see Application * @see DictionaryEntry */ @FXML private void studyIconClick() { + // Generate a new assessment using the programs practice list. AssessmentGenerator.generateAssessment(Application.practiceList); } /** * Event to switch scenes to 'addword.fxml' when the menu's 'addwordIcon' icon is clicked. + * * @see ScreenSwitch */ @FXML private void addWordIconClick(){ - + // Use 'ScreenSwitch' to switch to the 'addWordScene'. ScreenSwitch.swap(ScreenSwitch.SceneType.addWordScene); } From 96d9722cf88e0dda1f0091ca69ad34fa0483ac7b Mon Sep 17 00:00:00 2001 From: top19 Date: Fri, 1 May 2020 14:25:53 +0100 Subject: [PATCH 2/6] Updated documentation for FlashcardController.java. Addressed issue #41. --- .../group20/javafx/FlashcardController.java | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/FlashcardController.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/FlashcardController.java index c0e1e64..530ecae 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/FlashcardController.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/FlashcardController.java @@ -42,7 +42,8 @@ public class FlashcardController extends SharedCodeController { // /////////////////// // int index = 0; - Node card; // Node that will be flipped using RotateTransition. + // Node that will be flipped using RotateTransition. + Node card; @FXML private Text counter; @@ -70,22 +71,25 @@ public class FlashcardController extends SharedCodeController { */ @FXML private void initialize() { - - setup(); // Call method from SharedCodeController to setup the menu screens images. + // Call method from SharedCodeController to setup the menu screens images. + setup(); currentPageIcon.setImage(new Image("file:src/main/resources/assets/icons/white_icons/50px/flashcard-50.png")); currentPageText.setText("Flashcard"); flashcardIcon.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/flashcard-50.png")); flashcardsText.setFill(Color.BLACK); - if(isSortedByEnglish){ // If the current language ordering is by english, display the english word first. + // If the current language ordering is by english, display the english word first. + if(isSortedByEnglish){ testWord.setText(Application.practiceList.getFirst().getEnglish()); wordType.setText("English"); - } else{ // Else display the word definition first. + } else{ + // Else display the word definition first. testWord.setText(Application.practiceList.getFirst().getWelsh()); wordType.setText("Welsh"); } - updateCounter(); // Update the on screen counter and setup the flashcards images. + // Update the on screen counter and setup the flashcards images. + updateCounter(); flashcard.setImage(new Image("file:src/main/resources/assets/flashcard/FlashCard.png")); leftArrow.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/left-50.png")); rightArrow.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/right-50.png")); @@ -99,8 +103,10 @@ public class FlashcardController extends SharedCodeController { @FXML private void handleFlashcardClick() { card = flashcard; - RotateTransition rotator = RotateCard(card); // Call method to create the RotateTransition. - rotator.play(); // Play the rotate transition. + // Call method to create the RotateTransition. + RotateTransition rotator = RotateCard(card); + // Play the rotate transition. + rotator.play(); } /** @@ -116,10 +122,12 @@ public class FlashcardController extends SharedCodeController { index--; updateCounter(); - if (isSortedByEnglish) { // If the current language ordering is by english, display the english word first. + // If the current language ordering is by english, display the english word first. + if (isSortedByEnglish) { testWord.setText(Application.practiceList.get(index).getEnglish()); wordType.setText("English"); - } else { // Else display the word definition first. + } else { + // Else display the word definition first. testWord.setText(Application.practiceList.get(index).getWelsh()); wordType.setText("Welsh"); } @@ -139,10 +147,12 @@ public class FlashcardController extends SharedCodeController { index++; updateCounter(); - if (isSortedByEnglish) { // If the current language ordering is by english, display the english word first. + // If the current language ordering is by english, display the english word first. + if (isSortedByEnglish) { testWord.setText(Application.practiceList.get(index).getEnglish()); wordType.setText("English"); - } else { // Else display the word definition first. + } else { + // Else display the word definition first. testWord.setText(Application.practiceList.get(index).getWelsh()); wordType.setText("Welsh"); } @@ -182,12 +192,15 @@ public class FlashcardController extends SharedCodeController { rotate.setToAngle(180); rotate.setInterpolator(Interpolator.LINEAR); rotate.setCycleCount(1); - rotate.setOnFinished(event -> { // Once the transition is completed, update the text on the flashcard. + // Once the transition is completed, update the text on the flashcard. + rotate.setOnFinished(event -> { - if (wordType.getText().equals("Welsh")) { // If the word currently on the flashcard is welsh, display the english translation. + // If the word currently on the flashcard is welsh, display the english translation. + if (wordType.getText().equals("Welsh")) { testWord.setText(Application.practiceList.get(index).getEnglish()); wordType.setText("English"); - } else { // Else display the welsh translation. + } else { + // Else display the welsh translation. testWord.setText(Application.practiceList.get(index).getWelsh()); wordType.setText("Welsh"); } From 99049dc5b99fd175f9e2ecb2c0d2ba8e842e3e8e Mon Sep 17 00:00:00 2001 From: maj83 Date: Fri, 1 May 2020 14:28:08 +0100 Subject: [PATCH 3/6] Update with comboboxes --- .../group20/javafx/AddWordController.java | 113 +++++------------- 1 file changed, 27 insertions(+), 86 deletions(-) diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/AddWordController.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/AddWordController.java index abafd2a..997831c 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/AddWordController.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/AddWordController.java @@ -26,7 +26,7 @@ import uk.ac.aber.cs221.group20.json.DictionaryEntry; * @author Henry Dugmore [hjd3] * @author Kain Bryan-Jones [kab74] * @author Luke Wybar [law39] - * @author Marcin Jakob [maj83] + * @author Marcin Jakobik [maj83] * @author Oscar Pocock [osp1] * @author Tom Perry [top19] * @author Waylen Watts [ncw] @@ -40,6 +40,8 @@ public class AddWordController extends SharedCodeController { // Instance variables. // // /////////////////// // + + @FXML private TextField welsh; @FXML @@ -47,10 +49,23 @@ public class AddWordController extends SharedCodeController { @FXML private ComboBox wordType; - // //////// // + @FXML + private ComboBox specialChar1; + + @FXML + private ComboBox specialChar2; + + @FXML + private ComboBox specialChar3; + + @FXML + private ComboBox specialChar4; + + +// //////// // // Methods. // // //////// // - + /** * Gets the value from the welsh text field * @@ -162,6 +177,7 @@ public class AddWordController extends SharedCodeController { } + /** * Method that adds ch to the welsh text field and runs when the user clicks the ch button on the add word screen * @@ -236,93 +252,18 @@ public class AddWordController extends SharedCodeController { welsh.appendText("th"); } - public void addCharâ(ActionEvent actionEvent) { - welsh.appendText("â"); - } - public void addCharê(ActionEvent actionEvent) { - welsh.appendText("ê"); - } - public void addCharî(ActionEvent actionEvent) { - welsh.appendText("î"); - } - public void addCharô(ActionEvent actionEvent) { - welsh.appendText("ô"); - } - public void addCharû(ActionEvent actionEvent) { - welsh.appendText("û"); - } - public void addCharŵ(ActionEvent actionEvent) { - welsh.appendText("ŵ"); - } - public void addCharŷ(ActionEvent actionEvent) { - welsh.appendText("ŷ"); + public void specialChar1(ActionEvent actionEvent){ + welsh.appendText(specialChar1.getValue()); } - // äëïöüẅÿ - public void addCharä(ActionEvent actionEvent) { - welsh.appendText("ä"); + public void specialChar2(ActionEvent actionEvent) { + welsh.appendText(specialChar2.getValue()); } - public void addCharë(ActionEvent actionEvent) { - welsh.appendText("ë"); + public void specialChar3(ActionEvent actionEvent) { + welsh.appendText(specialChar3.getValue()); } - public void addCharï(ActionEvent actionEvent) { - welsh.appendText("ï"); - } - public void addCharö(ActionEvent actionEvent) { - welsh.appendText("ö"); - } - public void addCharü(ActionEvent actionEvent) { - welsh.appendText("ü"); - } - public void addCharẅ(ActionEvent actionEvent) { - welsh.appendText("ẅ"); - } - public void addCharÿ(ActionEvent actionEvent) { - welsh.appendText("ÿ"); - } - - // áéíóúẃý - public void addChará(ActionEvent actionEvent) { - welsh.appendText("á"); - } - public void addCharé(ActionEvent actionEvent) { - welsh.appendText("é"); - } - public void addCharí(ActionEvent actionEvent) { - welsh.appendText("í"); - } - public void addCharó(ActionEvent actionEvent) { - welsh.appendText("ó"); - } - public void addCharú(ActionEvent actionEvent) { - welsh.appendText("ú"); - } - public void addCharẃ(ActionEvent actionEvent) { - welsh.appendText("ẃ"); - } - public void addCharý(ActionEvent actionEvent) { - welsh.appendText("ý"); - } - - // àèìòùẁỳ - public void addCharà(ActionEvent actionEvent) { - welsh.appendText("à"); - } - public void addCharè(ActionEvent actionEvent) { - welsh.appendText("è"); - } - public void addCharì(ActionEvent actionEvent) { welsh.appendText("ì"); } - public void addCharò(ActionEvent actionEvent) { - welsh.appendText("ò"); - } - public void addCharù(ActionEvent actionEvent) { - welsh.appendText("ù"); - } - public void addCharẁ(ActionEvent actionEvent) { - welsh.appendText("ẁ"); - } - public void addCharỳ(ActionEvent actionEvent) { - welsh.appendText("ỳ"); + public void specialChar4(ActionEvent actionEvent) { + welsh.appendText(specialChar4.getValue()); } } \ No newline at end of file From 5d4ed5441bb6481baa7e48b08d3937751188d3bc Mon Sep 17 00:00:00 2001 From: maj83 Date: Fri, 1 May 2020 14:28:57 +0100 Subject: [PATCH 4/6] Update with comboboxes --- .../uk/ac/aber/cs221/group20/addword.fxml | 339 +++++++++--------- 1 file changed, 178 insertions(+), 161 deletions(-) diff --git a/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs221/group20/addword.fxml b/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs221/group20/addword.fxml index 256b705..6f66d3a 100644 --- a/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs221/group20/addword.fxml +++ b/src/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs221/group20/addword.fxml @@ -1,5 +1,3 @@ - - @@ -15,186 +13,205 @@ + + - - + - + - - + + - + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - + + + - - - + + + + - - + + + -

- + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + +
+
From 2a11c4a1fedec65a4a93192e70d016e598e8fec2 Mon Sep 17 00:00:00 2001 From: osp1 Date: Fri, 1 May 2020 14:39:31 +0100 Subject: [PATCH 5/6] Commenting for Dictionary and Practice List Issue #47 Issue #37 --- .../group20/javafx/DictionaryController.java | 56 +++++++++++++---- .../javafx/PracticeListController.java | 60 ++++++++++++++----- 2 files changed, 89 insertions(+), 27 deletions(-) diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/DictionaryController.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/DictionaryController.java index 66cfb33..41e1313 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/DictionaryController.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/DictionaryController.java @@ -46,6 +46,10 @@ import java.util.Comparator; */ public class DictionaryController extends SharedCodeController { + // /////////////////// // + // Instance variables. // + // /////////////////// // + @FXML private ImageView alphaSort; @FXML @@ -61,6 +65,10 @@ public class DictionaryController extends SharedCodeController { public ObservableList list = FXCollections.observableArrayList(); + // //////// // + // Methods. // + // //////// // + /** * Method to switch the language used to sort the dictionary list. *

@@ -138,6 +146,8 @@ public class DictionaryController extends SharedCodeController { */ public void initialize() { setup(); + + // Hide TableViewHeader table.widthProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observableValue, Number number, Number t1) { @@ -151,6 +161,8 @@ public class DictionaryController extends SharedCodeController { } } }); + + // Compare words while ignoring the "to" english.setComparator(new Comparator() { @Override public int compare(String s, String t1) { @@ -166,7 +178,7 @@ public class DictionaryController extends SharedCodeController { } }); - currentPageIcon.setImage(new Image(getClass().getResourceAsStream("/assets/icons/white_icons/50px/read-50.png"))); + currentPageIcon.setImage(new Image(getClass().getResourceAsStream("/assets/icons/white_icons/50px/read-50.png"))); currentPageText.setText("Dictionary"); alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-50.png")); @@ -190,6 +202,8 @@ public class DictionaryController extends SharedCodeController { } } }; + + // Unsets practice word when they are clicked on row.setOnMouseClicked(mouseEvent -> { if (mouseEvent.getClickCount() == 1 && (!row.isEmpty())) { if (row.getItem().isPracticeWord()) { @@ -201,11 +215,9 @@ public class DictionaryController extends SharedCodeController { } } Application.practiceList.removeAll(toRemove); -// row.getItem().setPracticeWord(false); } else if (!row.getItem().isPracticeWord()) { Application.dictionary.get(list.indexOf(row.getItem())).setPracticeWord(true); Application.practiceList.add(row.getItem()); -// row.getItem().setPracticeWord(true); } table.getSelectionModel().clearSelection(); } @@ -214,6 +226,7 @@ public class DictionaryController extends SharedCodeController { } ); + // Render Welsh nouns as "[masculine noun] {nm}" and "[feminine noun] {nm}" respectively. welsh.setCellValueFactory(dictionaryEntryStringCellDataFeatures -> { if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals(DictionaryEntry.wordTypeEnum.nm)) { return new SimpleStringProperty(dictionaryEntryStringCellDataFeatures.getValue().getWelsh() + " {nm}"); @@ -224,6 +237,7 @@ public class DictionaryController extends SharedCodeController { } }); + // Render English verbs as "to [verb]" english.setCellValueFactory(dictionaryEntryStringCellDataFeatures -> { if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals(DictionaryEntry.wordTypeEnum.verb)) { return new SimpleStringProperty("to " + dictionaryEntryStringCellDataFeatures.getValue().getEnglish()); @@ -232,31 +246,41 @@ public class DictionaryController extends SharedCodeController { } }); - FilteredList filteredList = new FilteredList<>(list, p -> true); // Wrap list in a FilteredList + // Wrap list in a FilteredList + FilteredList filteredList = new FilteredList<>(list, p -> true); 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 + // returns true on a filter match, false if no match + filteredList.setPredicate(dictionaryEntry -> { + boolean result = false; + + // This fixes the table highlighting issue + table.refresh(); + + // If filter text is empty, display all dictionary entries + if (newSearchTerm == null || newSearchTerm.isEmpty()) { result = true; } else { // need all same case for compare. final String lowerCaseSearchFilter = newSearchTerm.toLowerCase(); if (isSortedByEnglish) { if (dictionaryEntry.getEnglish().toLowerCase().startsWith(lowerCaseSearchFilter)) { - result = true; // Filter matches English + + // Filter matches English + result = true; } 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 + // Filter matches ['to' + a word] or [a word] if word is a verb + result = true; } } } else { if (dictionaryEntry.getWelsh().toLowerCase().startsWith(lowerCaseSearchFilter)) { - result = true; // Filter matches Welsh + // Filter matches Welsh + result = true; } } } @@ -264,15 +288,21 @@ public class DictionaryController extends SharedCodeController { }); }); - SortedList sortedList = new SortedList<>(filteredList); //Wrap the filtered list in a SortedList - sortedList.comparatorProperty().bind(table.comparatorProperty()); //Bind the sorted list comparator to the table comparator + //Wrap the filtered list in a SortedList + SortedList sortedList = new SortedList<>(filteredList); + + //Bind the sorted list comparator to the table comparator + sortedList.comparatorProperty().bind(table.comparatorProperty()); table.setItems(sortedList); + // Change Table sorting based on boolean value if(isSortedByEnglish){ table.getSortOrder().add(english); + langSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-lang-eng-50.png")); } else{ table.getSortOrder().add(welsh); + langSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-lang-welsh-50.png")); } } diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/PracticeListController.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/PracticeListController.java index 42d4149..907ea40 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/PracticeListController.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/PracticeListController.java @@ -42,6 +42,10 @@ import java.util.Comparator; */ public class PracticeListController extends SharedCodeController { + // /////////////////// // + // Instance variables. // + // /////////////////// // + @FXML private ImageView alphaSort; @FXML @@ -57,6 +61,10 @@ public class PracticeListController extends SharedCodeController { public ObservableList list = FXCollections.observableArrayList(); + // //////// // + // Methods. // + // //////// // + /** * Method to switch the language used to sort the dictionary list. *

@@ -132,6 +140,8 @@ public class PracticeListController extends SharedCodeController { */ public void initialize() { setup(); + + // Hide TableViewHeader table.widthProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observableValue, Number number, Number t1) { @@ -146,6 +156,7 @@ public class PracticeListController extends SharedCodeController { } }); + // Compare words while ignoring the "to" english.setComparator(new Comparator() { @Override public int compare(String s, String t1) { @@ -172,20 +183,19 @@ public class PracticeListController extends SharedCodeController { list.addAll(Application.practiceList); table.setPlaceholder(new Label("No practice words found. Please try adding a practice word from the 'Dictionary' page.")); + table.setRowFactory(tv -> { TableRow row = new TableRow() { @Override protected void updateItem(DictionaryEntry dictionaryEntry, boolean b) { super.updateItem(dictionaryEntry, b); if (!isEmpty()) { -// if (dictionaryEntry.isPracticeWord()) { -// setStyle("-fx-background-color: gray;"); -// } else { setStyle(" "); -// } } } }; + + // Remove practice word when they are clicked on row.setOnMouseClicked(mouseEvent -> { if (mouseEvent.getClickCount() == 1 && (!row.isEmpty())) { for (DictionaryEntry entry : Application.dictionary) { @@ -212,6 +222,8 @@ public class PracticeListController extends SharedCodeController { return row; } ); + + // Render Welsh nouns as "[masculine noun] {nm}" and "[feminine noun] {nm}" respectively. welsh.setCellValueFactory(dictionaryEntryStringCellDataFeatures -> { if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals(DictionaryEntry.wordTypeEnum.nm)) { return new SimpleStringProperty(dictionaryEntryStringCellDataFeatures.getValue().getWelsh() + " {nm}"); @@ -222,6 +234,7 @@ public class PracticeListController extends SharedCodeController { } }); + // Render English verbs as "to [verb]" english.setCellValueFactory(dictionaryEntryStringCellDataFeatures -> { if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals(DictionaryEntry.wordTypeEnum.verb)) { return new SimpleStringProperty("to " + dictionaryEntryStringCellDataFeatures.getValue().getEnglish()); @@ -230,29 +243,42 @@ public class PracticeListController extends SharedCodeController { } }); - FilteredList filteredList = new FilteredList<>(list, p -> true); // Wrap list in a FilteredList + // Wrap list in a FilteredList + FilteredList filteredList = new FilteredList<>(list, p -> true); 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 + // Returns true on a filter match, false if no match + filteredList.setPredicate(dictionaryEntry -> { + boolean result = false; + + // This fixes the table highlighting issue + table.refresh(); + + // If filter text is empty, display all dictionary entries + if (newSearchTerm == null || newSearchTerm.isEmpty()) { result = true; } else { + // need all same case for compare. final String lowerCaseSearchFilter = newSearchTerm.toLowerCase(); if (isSortedByEnglish) { if (dictionaryEntry.getEnglish().toLowerCase().startsWith(lowerCaseSearchFilter)) { - result = true; // Filter matches English + + // Filter matches English + result = true; } 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 + + // Filter matches ['to' + a word] or [a word] if word is a verb + result = true; } } } else { if (dictionaryEntry.getWelsh().toLowerCase().startsWith(lowerCaseSearchFilter)) { - result = true; // Filter matches Welsh + + // Filter matches Welsh + result = true; } } } @@ -260,15 +286,21 @@ public class PracticeListController extends SharedCodeController { }); }); - SortedList sortedList = new SortedList<>(filteredList); //Wrap the filtered list in a SortedList - sortedList.comparatorProperty().bind(table.comparatorProperty()); //Bind the sorted list comparator to the table comparator + // Wrap the filtered list in a SortedList + SortedList sortedList = new SortedList<>(filteredList); + + // Bind the sorted list comparator to the table comparator + sortedList.comparatorProperty().bind(table.comparatorProperty()); table.setItems(sortedList); + // Change Table sorting based on boolean value if (isSortedByEnglish) { table.getSortOrder().add(english); + langSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-lang-eng-50.png")); } else { table.getSortOrder().add(welsh); + langSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-lang-welsh-50.png")); } } From 155dee3a556a22f25224c7e99002c487eb1f5897 Mon Sep 17 00:00:00 2001 From: top19 Date: Fri, 1 May 2020 14:40:15 +0100 Subject: [PATCH 6/6] Updated documentation for JSONText.java. Addressed issue #44 --- .../ac/aber/cs221/group20/test/JSONTest.java | 123 ++++++++++-------- 1 file changed, 71 insertions(+), 52 deletions(-) diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/test/JSONTest.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/test/JSONTest.java index 58db68b..f4bcb56 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/test/JSONTest.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/test/JSONTest.java @@ -18,6 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; /** * Class that contains methods which will be used to test that the JSON package classes are * correctly loading and saving to and from the JSON file. + * * @author Tom Perry [top19] * @version 0.1 Initial development. * @see JsonProcessing @@ -25,67 +26,85 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; */ public class JSONTest { - static LinkedList testList; - LinkedList loadedList; - static File testFile; - static JsonProcessing processor = new JsonProcessing(); + // //////////////// // + // Class variables. // + // //////////////// // - /** - * Setup method that is run before all of the tests, setting up a test list of DictionaryEntry's that it saved to a JSON test file. - * @see JsonProcessing - * @see DictionaryEntry - */ - @BeforeAll - public static void setupTest() { + static LinkedList testList; + LinkedList loadedList; + static File testFile; + static JsonProcessing processor = new JsonProcessing(); - // Populate a test list with DictionaryEntrys that is to be used for the loading/saving tests. - testList = new LinkedList<>(Arrays.asList(new DictionaryEntry("abbey","abaty", DictionaryEntry.wordTypeEnum.other), new DictionaryEntry("about to", "ar fin", DictionaryEntry.wordTypeEnum.other), - new DictionaryEntry("above","uwchben", DictionaryEntry.wordTypeEnum.other), new DictionaryEntry("abroad","dramor", DictionaryEntry.wordTypeEnum.other), - new DictionaryEntry("abstract","haniaethol", DictionaryEntry.wordTypeEnum.other))); + // ////////////// // + // Class methods. // + // ////////////// // - // Create a JSON test file in the test package. - testFile = new File("src/main/java/uk/ac/aber/cs22120/group20/test/jsontest.json"); + /** + * Setup method that is run before all of the tests, setting up a test list of DictionaryEntry's that it saved to a JSON test file. + * + * @see JsonProcessing + * @see DictionaryEntry + */ + @BeforeAll + public static void setupTest() { - // Save the testList to the testFile. - processor.writeOutJson("src/main/java/uk/ac/aber/cs22120/group20/test/jsontest.json", testList); - } + // Populate a test list with DictionaryEntrys that is to be used for the loading/saving tests. + testList = new LinkedList<>(Arrays.asList(new DictionaryEntry("abbey","abaty", DictionaryEntry.wordTypeEnum.other), new DictionaryEntry("about to", "ar fin", DictionaryEntry.wordTypeEnum.other), + new DictionaryEntry("above","uwchben", DictionaryEntry.wordTypeEnum.other), new DictionaryEntry("abroad","dramor", DictionaryEntry.wordTypeEnum.other), + new DictionaryEntry("abstract","haniaethol", DictionaryEntry.wordTypeEnum.other))); - /** - * JUnit test to check that the JSON file has been correctly loaded. - * @see JsonProcessing - * @see DictionaryEntry - */ - @Test - public void testLoad(){ + // Create a JSON test file in the test package. + testFile = new File("src/main/java/uk/ac/aber/cs22120/group20/test/jsontest.json"); - // Load the DictionaryEntry's from testFile and check if the loaded list matches the test list. - loadedList = processor.readInJson(testFile); - assertArrayEquals(testList.toArray(),loadedList.toArray()); - } + // Save the testList to the testFile. + processor.writeOutJson("src/main/java/uk/ac/aber/cs22120/group20/test/jsontest.json", testList); + } - /** - * JUnit test to check that any changes to the list of definitions are - * updated and saved to the JSON file accordingly. - * @see JsonProcessing - * @see DictionaryEntry - */ - @Test public void testSave(){ - // Add an additional word to the testList and save it to jsontest. - testList.add(new DictionaryEntry("beer", "cwrw", DictionaryEntry.wordTypeEnum.nm)); - processor.writeOutJson("src/main/java/uk/ac/aber/cs22120/group20/test/jsontest.json", testList); + /** + * Method that is ran after the JUnit tests have finished to remove the JSON test file from program. + */ + @AfterAll + public static void deleteFile() { + testFile.delete(); + } - // Load the DictionaryEntry's back from the file and check that they match the testList. - loadedList = processor.readInJson(testFile); - assertArrayEquals(testList.toArray(), loadedList.toArray()); - } + // //////// // + // Methods. // + // //////// // + + /** + * JUnit test to check that the JSON file has been correctly loaded. This works by loading the test file and check + * its contents match the list that was saved to it. + * + * @see JsonProcessing + * @see DictionaryEntry + */ + @Test + public void testLoad(){ + + // Load the DictionaryEntry's from testFile and check if the loaded list matches the test list. + loadedList = processor.readInJson(testFile); + assertArrayEquals(testList.toArray(),loadedList.toArray()); + } + + /** + * JUnit test to check that changes to the list of definitions are + * updated and saved to the JSON file accordingly. This is done by adding a new item to the JSON test list and + * saving it to the file before reloading it to check the loaded list matches the updated test list. + * + * @see JsonProcessing + * @see DictionaryEntry + */ + @Test public void testSave(){ + // Add an additional word to the testList and save it to jsontest. + testList.add(new DictionaryEntry("beer", "cwrw", DictionaryEntry.wordTypeEnum.nm)); + processor.writeOutJson("src/main/java/uk/ac/aber/cs22120/group20/test/jsontest.json", testList); + + // Load the DictionaryEntry's back from the file and check that they match the testList. + loadedList = processor.readInJson(testFile); + assertArrayEquals(testList.toArray(), loadedList.toArray()); + } - /** - * Method that is ran after the JUnit tests have finished to remove the JSON test file from program. - */ - @AfterAll - public static void deleteFile() { - testFile.delete(); - } }