From 937b6beee877d20195ef486edcc154c8e786d617 Mon Sep 17 00:00:00 2001 From: osp1 Date: Thu, 30 Apr 2020 12:33:18 +0100 Subject: [PATCH] Made wordType enum and added words are now in PL --- .../group20/javafx/AddWordController.java | 11 ++++---- .../group20/javafx/DictionaryController.java | 8 +++--- .../javafx/PracticeListController.java | 9 +++--- .../cs22120/group20/json/DictionaryEntry.java | 28 ++++++++++++++----- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/AddWordController.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/AddWordController.java index a944611..3fe3985 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/AddWordController.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/AddWordController.java @@ -51,15 +51,15 @@ public class AddWordController extends SharedCodeController { @FXML protected void addButtonClick(ActionEvent actionEvent) { - String trueWordType; + DictionaryEntry.wordTypeEnum trueWordType; if (wordType.getValue() == "Masculine noun") { - trueWordType = "nm"; + trueWordType = DictionaryEntry.wordTypeEnum.nm; } else if (wordType.getValue() == "Feminine noun") { - trueWordType = "nf"; + trueWordType = DictionaryEntry.wordTypeEnum.nf; } else if (wordType.getValue() == "Verb") { - trueWordType = "verb"; + trueWordType = DictionaryEntry.wordTypeEnum.verb; } else { - trueWordType = "other"; + trueWordType = DictionaryEntry.wordTypeEnum.other; } boolean entryFound = false; // one or more blank fields @@ -100,6 +100,7 @@ public class AddWordController extends SharedCodeController { dictionaryEntry.setPracticeWord(true); Application.dictionary.contains(dictionaryEntry); Application.dictionary.add(dictionaryEntry); + Application.practiceList.add(dictionaryEntry); // output of what was saved for testing // System.out.print(english.getText()); 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 34914b6..8dd3513 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 @@ -174,9 +174,9 @@ public class DictionaryController extends SharedCodeController { } ); welsh.setCellValueFactory(dictionaryEntryStringCellDataFeatures -> { - if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals("nm")) { + if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals(DictionaryEntry.wordTypeEnum.nm)) { return new SimpleStringProperty(dictionaryEntryStringCellDataFeatures.getValue().getWelsh() + " {nm}"); - } else if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals("nf")) { + } else if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals(DictionaryEntry.wordTypeEnum.nf)) { return new SimpleStringProperty(dictionaryEntryStringCellDataFeatures.getValue().getWelsh() + " {nf}"); } else { return new SimpleStringProperty(dictionaryEntryStringCellDataFeatures.getValue().getWelsh()); @@ -184,7 +184,7 @@ public class DictionaryController extends SharedCodeController { }); english.setCellValueFactory(dictionaryEntryStringCellDataFeatures -> { - if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals("verb")) { + if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals(DictionaryEntry.wordTypeEnum.verb)) { return new SimpleStringProperty("to " + dictionaryEntryStringCellDataFeatures.getValue().getEnglish()); } else { return new SimpleStringProperty(dictionaryEntryStringCellDataFeatures.getValue().getEnglish()); @@ -210,7 +210,7 @@ public class DictionaryController extends SharedCodeController { result = true; // Filter matches English // } else if (dictionaryEntry.getWordType().toLowerCase().contains(lowerCaseSearchFilter)) { // result = true; // Filter matches Word Type - } else if (dictionaryEntry.getWordType().equals("verb") && ("to " + dictionaryEntry.getEnglish()).toLowerCase().contains(lowerCaseSearchFilter)) { + } else if (dictionaryEntry.getWordType().equals(DictionaryEntry.wordTypeEnum.verb) && ("to " + dictionaryEntry.getEnglish()).toLowerCase().contains(lowerCaseSearchFilter)) { result = true; // Filter matches ['to' + a word] or [a word] if word is a verb } } diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/PracticeListController.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/PracticeListController.java index c6e7399..3211868 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/PracticeListController.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/PracticeListController.java @@ -11,6 +11,7 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; import javafx.collections.transformation.SortedList; +import javafx.css.converter.DurationConverter; import javafx.fxml.FXML; import javafx.scene.control.*; import javafx.scene.image.Image; @@ -104,7 +105,7 @@ public class PracticeListController extends SharedCodeController{ result = true; // Filter matches English // } else if (dictionaryEntry.getWordType().toLowerCase().contains(lowerCaseSearchFilter)) { // result = true; // Filter matches Word Type - } else if (dictionaryEntry.getWordType().equals("verb") && ("to " + dictionaryEntry.getEnglish()).toLowerCase().contains(lowerCaseSearchFilter)) { + } else if (dictionaryEntry.getWordType().equals(DictionaryEntry.wordTypeEnum.verb) && ("to " + dictionaryEntry.getEnglish()).toLowerCase().contains(lowerCaseSearchFilter)) { result = true; // Filter matches ['to' + a word] or [a word] if word is a verb } } @@ -161,9 +162,9 @@ public class PracticeListController extends SharedCodeController{ welsh.setCellValueFactory(dictionaryEntryStringCellDataFeatures -> { - if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals("nm")) { + if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals(DictionaryEntry.wordTypeEnum.nm)) { return new SimpleStringProperty(dictionaryEntryStringCellDataFeatures.getValue().getWelsh() + " {nm}"); - } else if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals("nf")) { + } else if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals(DictionaryEntry.wordTypeEnum.nf)) { return new SimpleStringProperty(dictionaryEntryStringCellDataFeatures.getValue().getWelsh() + " {nf}"); } else { return new SimpleStringProperty(dictionaryEntryStringCellDataFeatures.getValue().getWelsh()); @@ -171,7 +172,7 @@ public class PracticeListController extends SharedCodeController{ }); english.setCellValueFactory(dictionaryEntryStringCellDataFeatures -> { - if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals("verb")) { + if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals(DictionaryEntry.wordTypeEnum.verb)) { return new SimpleStringProperty("to " + dictionaryEntryStringCellDataFeatures.getValue().getEnglish()); } else { return new SimpleStringProperty(dictionaryEntryStringCellDataFeatures.getValue().getEnglish()); diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/json/DictionaryEntry.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/json/DictionaryEntry.java index 6174b6a..e096c0e 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/json/DictionaryEntry.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/json/DictionaryEntry.java @@ -26,7 +26,11 @@ import uk.ac.aber.cs22120.group20.javafx.DictionaryController; public class DictionaryEntry { private String english; private String welsh; - private String wordType; + public enum wordTypeEnum { + nm, nf, verb, other + } + private wordTypeEnum wordType; +// private String wordType; private Boolean practiceWord; @@ -46,9 +50,10 @@ public class DictionaryEntry { * @see Application * @see DictionaryController */ - public DictionaryEntry(String english, String welsh, String wordType) { + public DictionaryEntry(String english, String welsh, wordTypeEnum wordType) { this.english = english; this.welsh = welsh; +// this.wordType = wordType; this.wordType = wordType; } @@ -68,15 +73,22 @@ public class DictionaryEntry { this.welsh = welsh.trim(); } - public String getWordType() { + public wordTypeEnum getWordType() { return wordType; } +// public word getWordType() { +// return wordType; +// } - public void setWordType(String wordType) { - this.wordType = wordType.trim(); + public void setWordType(wordTypeEnum wordType) { + this.wordType = wordType; } - public Boolean isPracticeWord() { +// public void setWordType(String wordType) { +// this.wordType = wordType; +// } + + public Boolean isPracticeWord() { return practiceWord; } @@ -87,6 +99,8 @@ public class DictionaryEntry { @Override public boolean equals(Object entry) { DictionaryEntry otherEntry = (DictionaryEntry) entry; - return otherEntry.getEnglish().equals(this.getEnglish()) && otherEntry.getWelsh().equals(this.getWelsh()) && otherEntry.getWordType().equals(this.getWordType()); + return otherEntry.getEnglish().equals(this.getEnglish()) && + otherEntry.getWelsh().equals(this.getWelsh()) && + otherEntry.getWordType().equals(this.getWordType()); } }