From 0b8d11f207528f4a1f5861112894650806d2e26c Mon Sep 17 00:00:00 2001 From: osp1 Date: Tue, 28 Apr 2020 13:33:40 +0100 Subject: [PATCH] Added practistList to Application --- .../cs22120/group20/javafx/Application.java | 104 +++++++++--------- .../group20/javafx/DictionaryController.java | 9 ++ .../javafx/PracticeListController.java | 20 +++- 3 files changed, 80 insertions(+), 53 deletions(-) diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/Application.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/Application.java index 3bf61b9..a5cd015 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/Application.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/Application.java @@ -35,74 +35,80 @@ import java.util.Scanner; * @version 0.1 Initial development */ public class Application extends javafx.application.Application { - private static Scene scene; + private static Scene scene; - private JsonProcessing jsonProcessing = new JsonProcessing(); - private Scanner scanner = new Scanner(System.in); + private JsonProcessing jsonProcessing = new JsonProcessing(); + private Scanner scanner = new Scanner(System.in); - public static LinkedList dictionary = new LinkedList<>(); + public static LinkedList dictionary = new LinkedList<>(); + public static LinkedList practiseList = new LinkedList<>(); - /** - * - * @param stage - * @throws IOException - */ - @Override - public void start(Stage stage) throws IOException { - File jsonFileLocation = null; + /** + * + * @param stage + * @throws IOException + */ + @Override + public void start(Stage stage) throws IOException { + File jsonFileLocation = null; - while(jsonFileLocation ==null) { - FileChooser fileChooser = new FileChooser(); - fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Json Files", "*.json")); - fileChooser.setTitle("Open Json File"); - jsonFileLocation = fileChooser.showOpenDialog(stage); - } + while(jsonFileLocation ==null) { + FileChooser fileChooser = new FileChooser(); + fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Json Files", "*.json")); + fileChooser.setTitle("Open Json File"); + jsonFileLocation = fileChooser.showOpenDialog(stage); + } - final File jsonFileFinalLocation = jsonFileLocation; - dictionary = jsonProcessing.readInJson(jsonFileFinalLocation); + final File jsonFileFinalLocation = jsonFileLocation; + dictionary = jsonProcessing.readInJson(jsonFileFinalLocation); + for (DictionaryEntry entry : dictionary) { + if (entry.isPracticeWord()) { + practiseList.add(entry); + } + } // dictionary.add(new DictionaryEntry("abbey", "abaty", "nm", false)); // dictionary.add(new DictionaryEntry("believe", "credu", "verb", true)); // dictionary.add(new DictionaryEntry("concert", "cyngerdd", "nm", false)); // dictionary.add(new DictionaryEntry("disease", "clefyd", "nm", true)); // dictionary.add(new DictionaryEntry("extremely", "dros ben", "other", false)); // dictionary.add(new DictionaryEntry("flu", "ffliw", "nm", false)); - scene = new Scene(loadFXML("dictionary")); - stage.setScene(scene); + scene = new Scene(loadFXML("dictionary")); + stage.setScene(scene); // stage.setOnCloseRequest(e -> { // jsonProcessing.writeOutJson(jsonFileLocation, dictionary); // Platform.exit(); // System.exit(0); // }); - stage.show(); - } + stage.show(); + } - /** - * - * @param fxml - * @throws IOException - */ - static void setRoot(String fxml) throws IOException { - scene.setRoot(loadFXML(fxml)); - } + /** + * + * @param fxml + * @throws IOException + */ + static void setRoot(String fxml) throws IOException { + scene.setRoot(loadFXML(fxml)); + } - /** - * - * @param fxml - * @return - * @throws IOException - */ - private static Parent loadFXML(String fxml) throws IOException { + /** + * + * @param fxml + * @return + * @throws IOException + */ + private static Parent loadFXML(String fxml) throws IOException { // FXMLLoader fxmlLoader = new FXMLLoader(Application.class.getResource(fxml + ".fxml")); - FXMLLoader fxmlLoader = new FXMLLoader(new URL("file:src/main/resources/uk/ac/aber/cs22120/group20/" + fxml + ".fxml")); - return fxmlLoader.load(); - } + FXMLLoader fxmlLoader = new FXMLLoader(new URL("file:src/main/resources/uk/ac/aber/cs22120/group20/" + fxml + ".fxml")); + return fxmlLoader.load(); + } - /** - * - * @param args - */ - public static void main(String[] args) { - launch(); - } + /** + * + * @param args + */ + public static void main(String[] args) { + launch(); + } } \ No newline at end of file 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 aceadf5..c4b29cb 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 @@ -25,6 +25,7 @@ import uk.ac.aber.cs22120.group20.json.DictionaryEntry; import java.io.IOException; import java.net.URL; +import java.util.ArrayList; import java.util.ResourceBundle; /** @@ -148,9 +149,17 @@ public class DictionaryController implements Initializable { if (mouseEvent.getClickCount() == 1 && (!row.isEmpty())) { if (row.getItem().isPracticeWord()) { Application.dictionary.get(list.indexOf(row.getItem())).setPracticeWord(false); + ArrayList toRemove = new ArrayList(); + for (DictionaryEntry entry : Application.practiseList) { + if (entry.equals(row.getItem())) { + toRemove.add(entry); + } + } + Application.practiseList.removeAll(toRemove); // row.getItem().setPracticeWord(false); } else if (!row.getItem().isPracticeWord()) { Application.dictionary.get(list.indexOf(row.getItem())).setPracticeWord(true); + Application.practiseList.add(row.getItem()); // row.getItem().setPracticeWord(true); } table.getSelectionModel().clearSelection(); 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 22e86a4..581c12e 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 @@ -22,6 +22,7 @@ import uk.ac.aber.cs22120.group20.json.DictionaryEntry; import java.io.IOException; import java.net.URL; +import java.util.ArrayList; import java.util.ResourceBundle; /** @@ -70,10 +71,11 @@ public class PracticeListController implements Initializable { @Override public void initialize(URL url, ResourceBundle resourceBundle) { // list.addAll(Application.dictionary); - for (DictionaryEntry entry : Application.dictionary) { - if (entry.isPracticeWord()) - list.add(entry); - } + list.addAll(Application.practiseList); +// for (DictionaryEntry entry : Application.dictionary) { +// if (entry.isPracticeWord()) +// list.add(entry); +// } FilteredList filteredList = new FilteredList<>(list, p -> true); // Wrap list in a FilteredList @@ -132,7 +134,17 @@ public class PracticeListController implements Initializable { list.remove(row.getItem()); table.refresh(); } + + } + + ArrayList toRemove = new ArrayList(); + for (DictionaryEntry entry : Application.practiseList) { + if (entry.equals(row.getItem())) { + toRemove.add(entry); + list.remove(row.getItem()); + } } + Application.practiseList.removeAll(toRemove); table.getSelectionModel().clearSelection(); } });