Merge remote-tracking branch 'origin/master'

This commit is contained in:
law39 2020-04-29 16:07:11 +01:00
commit bc9cce00e2
4 changed files with 174 additions and 103 deletions

View file

@ -17,68 +17,81 @@ import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
public class AddWordController {
@FXML
private TextField welsh;
@FXML
private TextField english;
@FXML
private ComboBox<String> wordType;
@FXML
private TextField welsh;
@FXML
private TextField english;
@FXML
private ComboBox<String> wordType;
public TextField getWelsh() {
return welsh;
}
public TextField getWelsh() {
return welsh;
}
public TextField getEnglish() {
return english;
}
public TextField getEnglish() {
return english;
}
@FXML
private void initialize() {
@FXML
private void initialize() {
wordType.getItems().addAll("Masculine noun", "Feminine noun", "Verb", "Other");
wordType.setValue("Type");
wordType.getItems().addAll("Masculine noun", "Feminine noun", "Verb", "Other");
wordType.setValue("Type");
}
}
@FXML
protected void addButtonClick(ActionEvent actionEvent) {
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");
@FXML
protected void addButtonClick(ActionEvent actionEvent) {
String trueWordType;
if (wordType.getValue() == "Masculine noun") {
trueWordType = "nm";
} else if (wordType.getValue() == "Feminine noun") {
trueWordType = "nf";
} else if (wordType.getValue() == "Verb") {
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();
} else {
for (DictionaryEntry entry : Application.dictionary) {
entryFound = false;
DictionaryEntry newEntry = new DictionaryEntry(english.getText(), welsh.getText(), wordType.getValue());
if (entry.equals(newEntry)) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("Entry Not Saved");
alert.setContentText("This entry already exists");
error.showAndWait();
} else {
for (DictionaryEntry entry : Application.dictionary) {
entryFound = false;
DictionaryEntry newEntry = new DictionaryEntry(english.getText(), welsh.getText(), trueWordType);
if (entry.equals(newEntry)) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("Entry Not Saved");
alert.setContentText("This entry already exists");
alert.showAndWait();
entryFound = true;
break;
} else {
continue;
}
alert.showAndWait();
entryFound = true;
break;
} else {
continue;
}
if (!entryFound) {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Success");
alert.setHeaderText("Entry Saved");
alert.setContentText("Entry Added - English: " + english.getText() + " Welsh: " + welsh.getText() + " Type: " + wordType.getValue());
}
if (!entryFound) {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Success");
alert.setHeaderText("Entry Saved");
alert.setContentText("Entry Added - English: " + english.getText() + " Welsh: " + welsh.getText() + " Type: " + wordType.getValue());
alert.showAndWait();
DictionaryEntry dictionaryEntry = new DictionaryEntry(english.getText(), welsh.getText(), wordType.getValue());
Application.dictionary.contains(dictionaryEntry);
Application.dictionary.add(dictionaryEntry);
alert.showAndWait();
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
// System.out.print(english.getText());
@ -86,16 +99,17 @@ public class AddWordController {
// System.out.println(wordType.getValue());
// Resets values to blank for next word to be entered
english.clear();
welsh.clear();
wordType.setValue("Type");
english.clear();
welsh.clear();
wordType.setValue("Type");
trueWordType = null;
}
}
}
}
}
}
// @Override
// public boolean equals(Object obj) {
@ -104,42 +118,42 @@ public class AddWordController {
// }
@FXML
private void switchToPrimary() throws IOException {
Application.setRoot("Primary");
}
@FXML
private void switchToPrimary() throws IOException {
Application.setRoot("Primary");
}
// add character methods for characters ch, dd, ff, ng, ll, ph, rh, th
public void addCharch(ActionEvent actionEvent) {
welsh.appendText("ch");
}
// add character methods for characters ch, dd, ff, ng, ll, ph, rh, th
public void addCharch(ActionEvent actionEvent) {
welsh.appendText("ch");
}
public void addChardd(ActionEvent actionEvent) {
welsh.appendText("dd");
}
public void addChardd(ActionEvent actionEvent) {
welsh.appendText("dd");
}
public void addCharff(ActionEvent actionEvent) {
welsh.appendText("ff");
}
public void addCharff(ActionEvent actionEvent) {
welsh.appendText("ff");
}
public void addCharng(ActionEvent actionEvent) {
welsh.appendText("ng");
}
public void addCharng(ActionEvent actionEvent) {
welsh.appendText("ng");
}
public void addCharll(ActionEvent actionEvent) {
welsh.appendText("ll");
}
public void addCharll(ActionEvent actionEvent) {
welsh.appendText("ll");
}
public void addCharph(ActionEvent actionEvent) {
welsh.appendText("ph");
}
public void addCharph(ActionEvent actionEvent) {
welsh.appendText("ph");
}
public void addCharrh(ActionEvent actionEvent) {
welsh.appendText("rh");
}
public void addCharrh(ActionEvent actionEvent) {
welsh.appendText("rh");
}
public void addCharth(ActionEvent actionEvent) {
welsh.appendText("th");
}
public void addCharth(ActionEvent actionEvent) {
welsh.appendText("th");
}
}

View file

@ -9,12 +9,33 @@ import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.scene.transform.Rotate;
import javafx.util.Duration;
import uk.ac.aber.cs22120.group20.javafx.Application;
import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
import uk.ac.aber.cs22120.group20.selfassessment.AssessmentGenerator;
import java.io.IOException;
/**
* A class that servers as the controller for the programs Flashcard JavaFX scene, handling all of its events and attributes. This scene is defined as "flashcard.fxml".
*
* @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 [top19]
* @author Waylen Watts [ncw]
* @version 0.1 Initial development.
* @see Application
* @see DictionaryEntry
* @see SharedCodeController
*/
public class FlashcardController {
// /////////////////// //
// Instance Variables. //
// /////////////////// //
int index = 0;
Node card;
@ -32,6 +53,14 @@ public class FlashcardController {
@FXML
private ImageView right_arrow;
// //////// //
// Methods. //
// //////// //
/**
* Method that initializes 'flashcard.fxml' by setting up the icons and text. This method is called automatically whenever the flashcard scene starts.
*
*/
@FXML
private void initialize() {
testWord.setText(Application.practiseList.getFirst().getWelsh());
@ -40,22 +69,28 @@ public class FlashcardController {
updateCounter();
card = flashcard;
Image left = new Image("file:src/main/resources/assets/icons/black_icons/50px/left-50.png");
Image right = new Image("file:src/main/resources/assets/icons/black_icons/50px/right-50.png");
left_arrow.setImage(left);
right_arrow.setImage(right);
left_arrow.setImage(new Image(getClass().getResourceAsStream("/assets/icons/black_icons/50px/left-50.png")));
right_arrow.setImage(new Image(getClass().getResourceAsStream("/assets/icons/black_icons/50px/right-50.png")));
}
/**
* Event that rotates the scenes flashcard using RotateTransition whenever the user clicks the flashcard.
* @see RotateTransition
*/
@FXML
private void handleFlashcardClick() {
RotateTransition rotator = RotateCard(card);
rotator.play();
rotator.play(); // Play the rotate transition.
}
/**
* Event that switches to the previous flashcard whenever the user clicks the 'leftArrow' icon.
* @see Application
* @see DictionaryEntry
*/
@FXML
private void handlePreviousCard() {
// If statement to check the start of the practiceList hasn't been reached before moving to the previous card.
if (index > 0) {
index--;
}
@ -64,8 +99,14 @@ public class FlashcardController {
wordType.setText("Welsh");
}
/**
* Event that switches to the next flashcard whenever the user clicks the 'right-arrow' icon.
* @see Application
* @see DictionaryEntry
*/
@FXML
private void handleNextCard() {
// If statement to check the end of the practiceList hasn't been reached before moving to the next card.
if (index < Application.practiseList.size()-1) {
index++;
}
@ -75,28 +116,42 @@ public class FlashcardController {
wordType.setText("Welsh");
}
/**
* Method that updates the onscreen counter of the current flashcard.
* @see Application
* @see DictionaryEntry
*/
private void updateCounter() {
counter.setText((index + 1) + "/" + Application.practiseList.size());
}
/**
* Method that creates a RotateTransition animation for flipping the flashcard 180 degrees.
* @param card FXML rectangle element that will be flipped.
* @return RotateTransition that will flip the rectangle 180 degrees.
* @see Application
* @see DictionaryEntry
* @see RotateTransition
*/
private RotateTransition RotateCard(Node card) {
RotateTransition rotate = new RotateTransition(Duration.millis(1000), card);
// Make the text on the card go invisible whilst the cardFlip is happening.
testWord.setVisible(false);
wordType.setVisible(false);
// Set the axis and angle of the rotation.
rotate.setAxis(Rotate.Y_AXIS);
rotate.setFromAngle(0);
rotate.setToAngle(180);
rotate.setInterpolator(Interpolator.LINEAR);
rotate.setCycleCount(1);
rotate.setOnFinished(event -> {
rotate.setOnFinished(event -> { // Once the transition is completed, update the text on the flashcard.
testWord.setText("Welsh word: \t" + Application.practiseList.get(index).getWelsh());
if (wordType.getText().equals("Welsh")) {
if (wordType.getText().equals("Welsh")) { // If the word currently on the flashcard is welsh, display the english translation.
testWord.setText(Application.practiseList.get(index).getEnglish());
wordType.setText("English");
} else {
} else { // Else display the welsh translation.
testWord.setText(Application.practiseList.get(index).getWelsh());
wordType.setText("Welsh");
}

View file

@ -143,8 +143,6 @@ public class MatchTheMeaningController implements Initializable{
Question.checkAnswer(answer,listOfAnswers,isEnglish);
CorrectAnswer.setText(Integer.toString(Question.correctAnswers));
WrongAnswer.setText(Integer.toString(Question.wrongAnswers));
answer.clear();
AssessmentGenerator.goToNextQuestion();
@ -156,6 +154,8 @@ public class MatchTheMeaningController implements Initializable{
public void initialize(URL url, ResourceBundle resourceBundle) {
setWords(answer,orderList);
CorrectAnswer.setText(Integer.toString(Question.correctAnswers));
WrongAnswer.setText(Integer.toString(Question.wrongAnswers));
}
}

View file

@ -149,9 +149,7 @@ public class SixMeaningsController implements Initializable {
Question.checkAnswer(wordSet,answer,isEnglish);
correctAnswer.setText(Integer.toString(Question.correctAnswers));
wrongAnswer.setText(Integer.toString(Question.wrongAnswers));
wordSet.clear();
@ -163,6 +161,10 @@ public class SixMeaningsController implements Initializable {
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
setWords(isEnglish);
correctAnswer.setText(Integer.toString(Question.correctAnswers));
wrongAnswer.setText(Integer.toString(Question.wrongAnswers));
}