From 7e6cb6178a3bba7bdcf02d06cdb84e855780ccf6 Mon Sep 17 00:00:00 2001 From: kab74 Date: Tue, 14 Apr 2020 11:36:54 +0100 Subject: [PATCH] Made JSON package comply with QA 9 Java Standards --- .../.~lock.UISpecPresentationGroup20.odg# | 1 - .../Welsh Vocabulary Tutor/.idea/compiler.xml | 13 + .../.idea/encodings.xml | 8 + .../Welsh Vocabulary Tutor/.idea/misc.xml | 14 + .../.idea/uiDesigner.xml | 124 +++++++ .../Welsh Vocabulary Tutor/.idea/vcs.xml | 7 + .../.idea/workspace.xml | 133 ++++++++ .../kab74/Welsh Vocabulary Tutor/pom.xml | 44 +++ .../src/main/java/JSON/DictionaryEntry.java | 108 +++++++ .../src/main/java/JSON/JSONProcessor.java | 81 +++++ .../src/main/java/module-info.java | 7 + .../java/uk/ac/aber/cs22120/group20/App.java | 48 +++ .../cs22120/group20/PrimaryController.java | 14 + .../cs22120/group20/SecondaryController.java | 14 + .../uk/ac/aber/cs22120/group20/primary.fxml | 16 + .../uk/ac/aber/cs22120/group20/secondary.fxml | 16 + .../target/classes/module-info.class | Bin 0 -> 270 bytes .../uk/ac/aber/cs22120/group20/App.class | Bin 0 -> 1923 bytes .../cs22120/group20/PrimaryController.class | Bin 0 -> 620 bytes .../cs22120/group20/SecondaryController.class | Bin 0 -> 622 bytes .../uk/ac/aber/cs22120/group20/primary.fxml | 16 + .../uk/ac/aber/cs22120/group20/secondary.fxml | 16 + dev/20200407/top19/JSONExample/.idea/misc.xml | 2 +- dev/20200407/top19/JSONExample/.idea/vcs.xml | 6 + .../top19/JSONExample/.idea/workspace.xml | 302 ++---------------- .../top19/JSONExample/JSONExample.iml | 2 - 26 files changed, 713 insertions(+), 279 deletions(-) delete mode 100644 dev/20200218/kab74/.~lock.UISpecPresentationGroup20.odg# create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/compiler.xml create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/encodings.xml create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/misc.xml create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/uiDesigner.xml create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/vcs.xml create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/workspace.xml create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/pom.xml create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/JSON/DictionaryEntry.java create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/JSON/JSONProcessor.java create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/module-info.java create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/App.java create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/PrimaryController.java create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/SecondaryController.java create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs22120/group20/primary.fxml create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs22120/group20/secondary.fxml create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/target/classes/module-info.class create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/target/classes/uk/ac/aber/cs22120/group20/App.class create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/target/classes/uk/ac/aber/cs22120/group20/PrimaryController.class create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/target/classes/uk/ac/aber/cs22120/group20/SecondaryController.class create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/target/classes/uk/ac/aber/cs22120/group20/primary.fxml create mode 100644 dev/20200407/kab74/Welsh Vocabulary Tutor/target/classes/uk/ac/aber/cs22120/group20/secondary.fxml create mode 100644 dev/20200407/top19/JSONExample/.idea/vcs.xml delete mode 100644 dev/20200407/top19/JSONExample/JSONExample.iml diff --git a/dev/20200218/kab74/.~lock.UISpecPresentationGroup20.odg# b/dev/20200218/kab74/.~lock.UISpecPresentationGroup20.odg# deleted file mode 100644 index d9a500d..0000000 --- a/dev/20200218/kab74/.~lock.UISpecPresentationGroup20.odg# +++ /dev/null @@ -1 +0,0 @@ -,kainpretzel,Kain-ThinkPad,25.02.2020 11:13,file:///home/kainpretzel/.config/libreoffice/4; \ No newline at end of file diff --git a/dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/compiler.xml b/dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/compiler.xml new file mode 100644 index 0000000..0c465ee --- /dev/null +++ b/dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/encodings.xml b/dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/encodings.xml new file mode 100644 index 0000000..34d7d10 --- /dev/null +++ b/dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/encodings.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/misc.xml b/dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/misc.xml new file mode 100644 index 0000000..a2037a3 --- /dev/null +++ b/dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/uiDesigner.xml b/dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/vcs.xml b/dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/vcs.xml new file mode 100644 index 0000000..423963a --- /dev/null +++ b/dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/workspace.xml b/dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/workspace.xml new file mode 100644 index 0000000..506093f --- /dev/null +++ b/dev/20200407/kab74/Welsh Vocabulary Tutor/.idea/workspace.xml @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1585703857421 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dev/20200407/kab74/Welsh Vocabulary Tutor/pom.xml b/dev/20200407/kab74/Welsh Vocabulary Tutor/pom.xml new file mode 100644 index 0000000..d2e762f --- /dev/null +++ b/dev/20200407/kab74/Welsh Vocabulary Tutor/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + uk.ac.aber.cs22120.group20 + Welsh Vocabulary Tutor + 1.0-SNAPSHOT + + UTF-8 + 11 + 11 + + + + org.openjfx + javafx-controls + 11 + + + org.openjfx + javafx-fxml + 11 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + 11 + + + + org.openjfx + javafx-maven-plugin + 0.0.1 + + uk.ac.aber.cs22120.group20.App + + + + + \ No newline at end of file diff --git a/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/JSON/DictionaryEntry.java b/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/JSON/DictionaryEntry.java new file mode 100644 index 0000000..668ae5b --- /dev/null +++ b/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/JSON/DictionaryEntry.java @@ -0,0 +1,108 @@ +package JSON; + +/* + * This class stores information on dictionary entries. A dictionary entries consists of + * a pair of words, that is the English and Welsh version of the same word. It also + * stores the type of word it is, that is 'verb' or 'noun' etc. It also marks whether or not this entry + * is a 'practice word'. + * @Author kab74 + * @Author top19 + * @Version 0.1 + */ +public class DictionaryEntry { + + private String englishWord; + private String welshWord; + private String wordType; + private boolean isPracticeWord; + + /* + * Default constructor for DictionaryEntry. By default the entry is NOT a practice word. + */ + public DictionaryEntry(){ + isPracticeWord = false; + } + + /* + * This method is the constructor which allows the user to enter all the field values of the class + * except for isPracticeWord. + * @Param englishWord The English translation of the word + * @Param welshWord The Welsh translation of the word + * @Param wordType The type of word + */ + public DictionaryEntry(String englishWord, String welshWord, String wordType ){ + this.englishWord = englishWord; + this.welshWord = welshWord; + this.wordType = wordType; + } + + /* + * @return englishWord the English translation of the word as a String. + */ + public String getEnglishWord() { + return englishWord; + } + + /* + * @return englishWord the English translation of the word as a String. + */ + public void setEnglishWord(String englishWord) { + this.englishWord = englishWord; + } + + /* + * @return englishWord the English translation of the word as a String. + */ + public String getWelshWord() { + return welshWord; + } + + /* + * @Param welshWord The word to set this Dictionary Entry's welsh word to. + */ + public void setWelshWord(String welshWord) { + this.welshWord = welshWord; + } + + + /* + * @Return The word type of the dictionary entry. + */ + public String getWordType() { + return wordType; + } + + /* + *Sets the word type. + * @Param word type to be set to. + */ + public void setWordType(String wordType) { + this.wordType = wordType; + } + + + /* + *@return whether the word is a practice word or not. + */ + public boolean isPracticeWord() { + return isPracticeWord; + } + + + /* + * @Param the boolean value of whether or not this entry is a practice word. + */ + public void setPracticeWord(boolean practiceWord) { + this.isPracticeWord = practiceWord; + } + + + @Override + public String toString() { + return "english='" + englishWord + "'\t" + + "welsh='" + welshWord + "'\t" + + "wordType='" + wordType + "'" + + "practiceWord = " + isPracticeWord; + } + +} diff --git a/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/JSON/JSONProcessor.java b/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/JSON/JSONProcessor.java new file mode 100644 index 0000000..a818a2d --- /dev/null +++ b/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/JSON/JSONProcessor.java @@ -0,0 +1,81 @@ +package JSON; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.LinkedList; + +/* + * A Class that provides functionality for saving/loading information to/from JSON files. It uses the jackson library + * to perform this functionality. + * @Author kab74 + * @Author top19 + * @Version 0.1 + */ +public class JSONProcessor { + + /* + * A file is then read and loaded into a + * It loads a list from the JSON file and returns them in the form of a linked list. + * @Author kab74 + * @Author top19 + * @Version + * @Param fileDirectoryName the directory of the file to read from. + * @return all dictionary entries in the form of a LinkedList + * @See DictionaryEntry + */ + public LinkedList readFile (String fileDirectoryName){ + + LinkedList result = new LinkedList<>(); //This is the linked list object the method will return. + ObjectMapper welshDictionaryObjectMapper = new ObjectMapper(); + File dictionaryFile = new File(fileDirectoryName); + + try { + + //This method first uses the ObjectMapper to [MISSING INFORMATION] then converts it to a List, which is all then + //added to the 'result' LinkedList. + result.addAll(Arrays.asList(welshDictionaryObjectMapper.readValue(dictionaryFile, DictionaryEntry[].class))); + + } catch (IOException e){ + + e.printStackTrace(); + + } + + return result; + } + + /* + * This method encodes the current session data to the dictionary file. + * @Author kab474 + * @Author top19 + * @Version + * @Param originalDictionaryDirectory The file directory to save the data to. + * @Param dictionary A linked list which stores the DictionaryEntry objects. + * @See DictionaryEntry + * @See ObjectMapper + */ + public void saveFile(String originalDictionaryDirectory, LinkedList dictionary){ + ObjectMapper welshDictionaryObjectMapper = new ObjectMapper(); + String linkedListDictionaryAsString =""; + + try { + //Convert the dictionary into a string format through use of ObjectMapper. + linkedListDictionaryAstring = welshDictionaryObjectMapper.writeValueAsString(dictionary); + }catch (IOException e){ + e.printStackTrace(); + } + + try { + //Write to the file. + Files.writeString(Paths.get(originalDictionaryDirectory), linkedListDictionaryAsString); + }catch (IOException e){ + e.printStackTrace(); + } + + } +} diff --git a/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/module-info.java b/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/module-info.java new file mode 100644 index 0000000..5d44bb3 --- /dev/null +++ b/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/module-info.java @@ -0,0 +1,7 @@ +module uk.ac.aber.cs22120.group20 { + requires javafx.controls; + requires javafx.fxml; + + opens uk.ac.aber.cs22120.group20 to javafx.fxml; + exports uk.ac.aber.cs22120.group20; +} \ No newline at end of file diff --git a/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/App.java b/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/App.java new file mode 100644 index 0000000..8b5c64d --- /dev/null +++ b/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/App.java @@ -0,0 +1,48 @@ +package uk.ac.aber.cs22120.group20; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +import java.io.IOException; + +/** + * Launch class of the Welsh Vocabulary tutor Application + * + * @author Brad Corbett [brc9] + * @author Henry Dugmore [hjd3] + * @author Kain Bryan-Jones [kab74] + * @author Luke Wybar [law39] + * @author Marcin Jakob [maj83] + * @author Oscar Pocock [osp1] + * @author Tom Perry [top1] + * @author Waylen Watts [ncw] + * + * @version 0.1 + */ +public class App extends Application { + private static Scene scene; + + @Override + public void start(Stage stage) throws IOException { + scene = new Scene(loadFXML("primary")); + stage.setScene(scene); + stage.show(); + } + + static void setRoot(String fxml) throws IOException { + scene.setRoot(loadFXML(fxml)); + } + + private static Parent loadFXML(String fxml) throws IOException { + FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml")); + return fxmlLoader.load(); + } + + public static void main(String[] args) { + launch(); + } + +} \ No newline at end of file diff --git a/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/PrimaryController.java b/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/PrimaryController.java new file mode 100644 index 0000000..b1929a6 --- /dev/null +++ b/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/PrimaryController.java @@ -0,0 +1,14 @@ +package uk.ac.aber.cs22120.group20; + +import java.io.IOException; +import javafx.fxml.FXML; +/** + * Placeholder Controller + */ +public class PrimaryController { + + @FXML + private void switchToSecondary() throws IOException { + App.setRoot("secondary"); + } +} diff --git a/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/SecondaryController.java b/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/SecondaryController.java new file mode 100644 index 0000000..94eb1ac --- /dev/null +++ b/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/SecondaryController.java @@ -0,0 +1,14 @@ +package uk.ac.aber.cs22120.group20; + +import java.io.IOException; +import javafx.fxml.FXML; +/** + * Placeholder Controller + */ +public class SecondaryController { + + @FXML + private void switchToPrimary() throws IOException { + App.setRoot("primary"); + } +} \ No newline at end of file diff --git a/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs22120/group20/primary.fxml b/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs22120/group20/primary.fxml new file mode 100644 index 0000000..e2ba159 --- /dev/null +++ b/dev/20200407/kab74/Welsh Vocabulary Tutor/src/main/resources/uk/ac/aber/cs22120/group20/primary.fxml @@ -0,0 +1,16 @@ + + + + + + + + + +