Changed AddWordController to start words as practice words
Changed false to true so words added to the dictionary will be added as practice words by default
This commit is contained in:
parent
2bc2c415af
commit
cd083bcd1b
1 changed files with 100 additions and 86 deletions
|
@ -17,68 +17,81 @@ import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
|
||||||
|
|
||||||
public class AddWordController {
|
public class AddWordController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField welsh;
|
private TextField welsh;
|
||||||
@FXML
|
@FXML
|
||||||
private TextField english;
|
private TextField english;
|
||||||
@FXML
|
@FXML
|
||||||
private ComboBox<String> wordType;
|
private ComboBox<String> wordType;
|
||||||
|
|
||||||
public TextField getWelsh() {
|
public TextField getWelsh() {
|
||||||
return welsh;
|
return welsh;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TextField getEnglish() {
|
public TextField getEnglish() {
|
||||||
return english;
|
return english;
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
|
|
||||||
wordType.getItems().addAll("Masculine noun", "Feminine noun", "Verb", "Other");
|
wordType.getItems().addAll("Masculine noun", "Feminine noun", "Verb", "Other");
|
||||||
wordType.setValue("Type");
|
wordType.setValue("Type");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void addButtonClick(ActionEvent actionEvent) {
|
protected void addButtonClick(ActionEvent actionEvent) {
|
||||||
boolean entryFound = false;
|
String trueWordType;
|
||||||
// one or more blank fields
|
if (wordType.getValue() == "Masculine noun") {
|
||||||
if (english.getText() == null || welsh.getText() == null || wordType.getValue().equals("Type")) {
|
trueWordType = "nm";
|
||||||
Alert error = new Alert(Alert.AlertType.ERROR);
|
} else if (wordType.getValue() == "Feminine noun") {
|
||||||
error.setTitle("Error");
|
trueWordType = "nf";
|
||||||
error.setHeaderText("Entry Not Saved");
|
} else if (wordType.getValue() == "Verb") {
|
||||||
error.setContentText("One or more fields are blank");
|
trueWordType = "verb";
|
||||||
|
} else {
|
||||||
|
trueWordType = "other";
|
||||||
|
}
|
||||||
|
boolean entryFound = false;
|
||||||
|
// one or more blank fields
|
||||||
|
if (english.getText() == null || welsh.getText() == null || wordType.getValue().equals("Type")) {
|
||||||
|
Alert error = new Alert(Alert.AlertType.ERROR);
|
||||||
|
error.setTitle("Error");
|
||||||
|
error.setHeaderText("Entry Not Saved");
|
||||||
|
error.setContentText("One or more fields are blank");
|
||||||
|
|
||||||
error.showAndWait();
|
error.showAndWait();
|
||||||
} else {
|
} else {
|
||||||
for (DictionaryEntry entry : Application.dictionary) {
|
for (DictionaryEntry entry : Application.dictionary) {
|
||||||
entryFound = false;
|
entryFound = false;
|
||||||
DictionaryEntry newEntry = new DictionaryEntry(english.getText(), welsh.getText(), wordType.getValue());
|
DictionaryEntry newEntry = new DictionaryEntry(english.getText(), welsh.getText(), trueWordType);
|
||||||
if (entry.equals(newEntry)) {
|
if (entry.equals(newEntry)) {
|
||||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||||
alert.setTitle("Error");
|
alert.setTitle("Error");
|
||||||
alert.setHeaderText("Entry Not Saved");
|
alert.setHeaderText("Entry Not Saved");
|
||||||
alert.setContentText("This entry already exists");
|
alert.setContentText("This entry already exists");
|
||||||
|
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
entryFound = true;
|
entryFound = true;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!entryFound) {
|
}
|
||||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
if (!entryFound) {
|
||||||
alert.setTitle("Success");
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||||
alert.setHeaderText("Entry Saved");
|
alert.setTitle("Success");
|
||||||
alert.setContentText("Entry Added - English: " + english.getText() + " Welsh: " + welsh.getText() + " Type: " + wordType.getValue());
|
alert.setHeaderText("Entry Saved");
|
||||||
|
alert.setContentText("Entry Added - English: " + english.getText() + " Welsh: " + welsh.getText() + " Type: " + wordType.getValue());
|
||||||
|
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
DictionaryEntry dictionaryEntry = new DictionaryEntry(english.getText(), welsh.getText(), wordType.getValue());
|
|
||||||
Application.dictionary.contains(dictionaryEntry);
|
|
||||||
Application.dictionary.add(dictionaryEntry);
|
DictionaryEntry dictionaryEntry = new DictionaryEntry(english.getText(), welsh.getText(), trueWordType);
|
||||||
|
dictionaryEntry.setPracticeWord(true);
|
||||||
|
Application.dictionary.contains(dictionaryEntry);
|
||||||
|
Application.dictionary.add(dictionaryEntry);
|
||||||
|
|
||||||
// output of what was saved for testing
|
// output of what was saved for testing
|
||||||
// System.out.print(english.getText());
|
// System.out.print(english.getText());
|
||||||
|
@ -86,16 +99,17 @@ public class AddWordController {
|
||||||
// System.out.println(wordType.getValue());
|
// System.out.println(wordType.getValue());
|
||||||
|
|
||||||
// Resets values to blank for next word to be entered
|
// Resets values to blank for next word to be entered
|
||||||
english.clear();
|
english.clear();
|
||||||
welsh.clear();
|
welsh.clear();
|
||||||
wordType.setValue("Type");
|
wordType.setValue("Type");
|
||||||
|
trueWordType = null;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
// public boolean equals(Object obj) {
|
// public boolean equals(Object obj) {
|
||||||
|
@ -104,42 +118,42 @@ public class AddWordController {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void switchToPrimary() throws IOException {
|
private void switchToPrimary() throws IOException {
|
||||||
Application.setRoot("Primary");
|
Application.setRoot("Primary");
|
||||||
}
|
}
|
||||||
|
|
||||||
// add character methods for characters ch, dd, ff, ng, ll, ph, rh, th
|
// add character methods for characters ch, dd, ff, ng, ll, ph, rh, th
|
||||||
public void addCharch(ActionEvent actionEvent) {
|
public void addCharch(ActionEvent actionEvent) {
|
||||||
welsh.appendText("ch");
|
welsh.appendText("ch");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addChardd(ActionEvent actionEvent) {
|
public void addChardd(ActionEvent actionEvent) {
|
||||||
welsh.appendText("dd");
|
welsh.appendText("dd");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCharff(ActionEvent actionEvent) {
|
public void addCharff(ActionEvent actionEvent) {
|
||||||
welsh.appendText("ff");
|
welsh.appendText("ff");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCharng(ActionEvent actionEvent) {
|
public void addCharng(ActionEvent actionEvent) {
|
||||||
welsh.appendText("ng");
|
welsh.appendText("ng");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCharll(ActionEvent actionEvent) {
|
public void addCharll(ActionEvent actionEvent) {
|
||||||
welsh.appendText("ll");
|
welsh.appendText("ll");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCharph(ActionEvent actionEvent) {
|
public void addCharph(ActionEvent actionEvent) {
|
||||||
welsh.appendText("ph");
|
welsh.appendText("ph");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCharrh(ActionEvent actionEvent) {
|
public void addCharrh(ActionEvent actionEvent) {
|
||||||
welsh.appendText("rh");
|
welsh.appendText("rh");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCharth(ActionEvent actionEvent) {
|
public void addCharth(ActionEvent actionEvent) {
|
||||||
welsh.appendText("th");
|
welsh.appendText("th");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue