Merge remote-tracking branch 'origin/master'

This commit is contained in:
law39 2020-04-30 11:26:49 +01:00
commit 3beb45941c
3 changed files with 80 additions and 31 deletions

View file

@ -41,7 +41,7 @@ public class MatchTheMeaningController extends SharedCodeController {
public static ArrayList<DictionaryEntry> answer =new ArrayList<>(); public static ArrayList<DictionaryEntry> answer =new ArrayList<>();
private ArrayList<Integer> orderList = new ArrayList<>(Arrays.asList(0,1,2,3)); private ArrayList<Integer> orderList = new ArrayList<>(Arrays.asList(0,1,2,3));
private boolean isEnglish; private boolean isEnglish = AssessmentGenerator.isEnglish;
@FXML @FXML
@ -96,9 +96,8 @@ public class MatchTheMeaningController extends SharedCodeController {
*/ */
private void setWords(ArrayList<DictionaryEntry> questions, ArrayList<Integer> orderList){ public void setWords(ArrayList<DictionaryEntry> questions, ArrayList<Integer> orderList){
isEnglish = AssessmentGenerator.isEnglish;
if(isEnglish){ if(isEnglish){
LeftWord1.setText(questions.get(0).getEnglish()); LeftWord1.setText(questions.get(0).getEnglish());

View file

@ -7,19 +7,26 @@ import javafx.scene.image.ImageView;
import javafx.scene.shape.Rectangle; import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import uk.ac.aber.cs22120.group20.selfassessment.AssessmentGenerator; import uk.ac.aber.cs22120.group20.selfassessment.AssessmentGenerator;
import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
/** /**
* Abstract class that contains all the shared FXML elements between the * Abstract class that contains all the shared FXML elements between the
* different controller classes including the sliding menu and the test score counter, to reduce code * different controller classes including the sliding menu and the test score counter, to reduce code
* duplication. This will be extended by all the controller classes. * duplication. This will be extended by all the controller classes.
* @Author * @Author top19
* @Version * @Version 0.1 Initial development.
* @See * @see Application
* @see DictionaryEntry
* @see ScreenSwitch
* @see AssessmentGenerator
*/ */
abstract public class SharedCodeController { abstract public class SharedCodeController {
static int sideBarWidth = 50; static int sideBarWidth = 50;
// /////////////////// //
// Instance Variables. //
// /////////////////// //
@FXML @FXML
Rectangle sideBar; Rectangle sideBar;
@ -47,12 +54,17 @@ abstract public class SharedCodeController {
@FXML @FXML
ImageView studyIcon; ImageView studyIcon;
@FXML @FXML
ImageView searchIcon;
@FXML
ImageView addDefinitionIcon; ImageView addDefinitionIcon;
@FXML @FXML
ImageView currentPageIcon; ImageView currentPageIcon;
// //////// //
// Methods. //
// //////// //
/***
* Method that sets up the program's menu in each of the controllers, intialising the icons and text.
*/
public void setup() { public void setup() {
initializeIcons(); initializeIcons();
sideBar.setWidth(sideBarWidth); sideBar.setWidth(sideBarWidth);
@ -61,6 +73,9 @@ abstract public class SharedCodeController {
initializeMenuText(); initializeMenuText();
} }
/**
* Method that sets up all of the menus icons by setting them to the images stored within the resources file.
*/
private void initializeIcons() { private void initializeIcons() {
expandMenuIcon.setImage(new Image("file:src/main/resources/assets/icons/white_icons/50px/menu-50.png")); expandMenuIcon.setImage(new Image("file:src/main/resources/assets/icons/white_icons/50px/menu-50.png"));
dictionaryIcon.setImage(new Image("file:src/main/resources/assets/icons/white_icons/50px/read-50.png")); dictionaryIcon.setImage(new Image("file:src/main/resources/assets/icons/white_icons/50px/read-50.png"));
@ -70,6 +85,9 @@ abstract public class SharedCodeController {
addDefinitionIcon.setImage(new Image("file:src/main/resources/assets/icons/white_icons/50px/add-50.png")); addDefinitionIcon.setImage(new Image("file:src/main/resources/assets/icons/white_icons/50px/add-50.png"));
} }
/**
* Method that sets up all of the menus text by setting them to their desired text when the menu is expanded.
*/
private void initializeMenuText() { private void initializeMenuText() {
dictionaryText.setText("Dictionary"); dictionaryText.setText("Dictionary");
practiceListTest.setText("Practice List"); practiceListTest.setText("Practice List");
@ -78,6 +96,9 @@ abstract public class SharedCodeController {
addDefinitionText.setText("Add"); addDefinitionText.setText("Add");
} }
/**
* Method that disables the menus text when the menu is collapsed.
*/
private void disableMenuText() { private void disableMenuText() {
dictionaryText.setText(""); dictionaryText.setText("");
practiceListTest.setText(""); practiceListTest.setText("");
@ -86,47 +107,76 @@ abstract public class SharedCodeController {
addDefinitionText.setText(""); addDefinitionText.setText("");
} }
/**
* Event that expands the menu whenever the menu's 'expandMenuIcon' icon is clicked.
*/
@FXML @FXML
private void expandMenuClick() { private void expandMenuClick() {
if(sideBar.getWidth() == 50) { if(sideBar.getWidth() == 50) { // If sideBar is currently collapsed, expand it and display menu text.
sideBar.setWidth(sideBarWidth = 230); sideBar.setWidth(sideBarWidth = 230);
initializeMenuText(); initializeMenuText(); // Display menu
} else { } else {
sideBar.setWidth(sideBarWidth = 50); sideBar.setWidth(sideBarWidth = 50); // Else collapse the menu and disable its text.
disableMenuText(); disableMenuText();
} }
} }
/**
* Event to switch scenes to 'dictionary.fxml' when the menu's 'dictionaryIcon' icon is clicked.
* @see ScreenSwitch
*/
@FXML @FXML
private void dictionaryIconClick() { private void dictionaryIconClick() {
ScreenSwitch.swap(ScreenSwitch.SceneEnum.dictionaryScene); ScreenSwitch.swap(ScreenSwitch.SceneEnum.dictionaryScene);
} }
/**
* Event to switch scenes to 'practicelist.fxml' when the menu's 'practiceListIcon' icon is clicked.
* @see ScreenSwitch
*/
@FXML @FXML
private void practiceListIconClick() { private void practiceListIconClick() {
ScreenSwitch.swap(ScreenSwitch.SceneEnum.practiceListScene); ScreenSwitch.swap(ScreenSwitch.SceneEnum.practiceListScene);
} }
/**
* Event to switch scenes to 'flashcard.fxml' when the menu's 'practiceListIcon' icon is clicked. This method checks to see if practiceList is empty before switching in order
* to avoid NullPointerException's in the flashcard scene.
* @see ScreenSwitch
* @see Application
* @see DictionaryEntry
* @see NullPointerException
*/
@FXML @FXML
private void flashcardIconClick() { private void flashcardIconClick() {
if(Application.practiseList.size() == 0) { if(Application.practiseList.size() == 0) { // Check to see if there are any practice words before switching scene, throwing an alert notifying them that they can't switch scenes.
Alert alert = new Alert(Alert.AlertType.ERROR); Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error"); alert.setTitle("Error");
alert.setHeaderText("Unable to use Flashcard"); alert.setHeaderText("Unable to use Flashcard");
alert.setContentText("The practice list is currently empty, please add some practice words to use the Flashcard feature."); alert.setContentText("The practice list is currently empty, please add some practice words to use the Flashcard feature.");
alert.showAndWait(); alert.showAndWait();
} else{ } else{
ScreenSwitch.swap(ScreenSwitch.SceneEnum.flashcardScene); ScreenSwitch.swap(ScreenSwitch.SceneEnum.flashcardScene); // Switch to flashcard scene if the program has practice words.
} }
} }
/**
* Event to generate an assessment using AssessmentGenerator when the menu's 'studyIcon' icon is clicked.
* @see AssessmentGenerator
* @see Application
* @see DictionaryEntry
*/
@FXML @FXML
private void studyIconClick() { private void studyIconClick() {
AssessmentGenerator.generateAssessment(Application.practiseList); AssessmentGenerator.generateAssessment(Application.practiseList);
} }
/**
* Event to switch scenes to 'addword.fxml' when the menu's 'addwordIcon' icon is clicked.
* @see ScreenSwitch
*/
@FXML @FXML
private void addWordIconClick(){ private void addWordIconClick(){

View file

@ -105,11 +105,11 @@ public class SixMeaningsController extends SharedCodeController {
private void setWords(boolean isEnglish){ public void setWords(ArrayList<DictionaryEntry> questions, ArrayList<Integer> orderList){
if(isEnglish){ if(isEnglish){
wordSet.add(allQuestions.get(0)); wordSet.add(questions.get(0));
//WelshWord1 Is the question word and as a result is always right. //WelshWord1 Is the question word and as a result is always right.
wordToTranslate.setText(wordSet.get(0).getEnglish()); wordToTranslate.setText(wordSet.get(0).getEnglish());
@ -117,27 +117,27 @@ public class SixMeaningsController extends SharedCodeController {
Collections.shuffle(orderList); Collections.shuffle(orderList);
possibleAnswer1.setText(allQuestions.get(orderList.get(0)).getWelsh()); possibleAnswer1.setText(questions.get(orderList.get(0)).getWelsh());
possibleAnswer2.setText(allQuestions.get(orderList.get(1)).getWelsh()); possibleAnswer2.setText(questions.get(orderList.get(1)).getWelsh());
possibleAnswer3.setText(allQuestions.get(orderList.get(2)).getWelsh()); possibleAnswer3.setText(questions.get(orderList.get(2)).getWelsh());
possibleAnswer4.setText(allQuestions.get(orderList.get(3)).getWelsh()); possibleAnswer4.setText(questions.get(orderList.get(3)).getWelsh());
possibleAnswer5.setText(allQuestions.get(orderList.get(4)).getWelsh()); possibleAnswer5.setText(questions.get(orderList.get(4)).getWelsh());
possibleAnswer6.setText(allQuestions.get(orderList.get(5)).getWelsh()); possibleAnswer6.setText(questions.get(orderList.get(5)).getWelsh());
}else { }else {
wordSet.add(allQuestions.get(0)); wordSet.add(questions.get(0));
//WelshWord1 Is the question word and as a result is always right. //WelshWord1 Is the question word and as a result is always right.
wordToTranslate.setText(wordSet.get(0).getWelsh()); wordToTranslate.setText(wordSet.get(0).getWelsh());
//This stores the correct answer for the english word. //This stores the correct answer for the english word.
Collections.shuffle(orderList); Collections.shuffle(orderList);
possibleAnswer1.setText(allQuestions.get(orderList.get(0)).getEnglish()); possibleAnswer1.setText(questions.get(orderList.get(0)).getEnglish());
possibleAnswer2.setText(allQuestions.get(orderList.get(1)).getEnglish()); possibleAnswer2.setText(questions.get(orderList.get(1)).getEnglish());
possibleAnswer3.setText(allQuestions.get(orderList.get(2)).getEnglish()); possibleAnswer3.setText(questions.get(orderList.get(2)).getEnglish());
possibleAnswer4.setText(allQuestions.get(orderList.get(3)).getEnglish()); possibleAnswer4.setText(questions.get(orderList.get(3)).getEnglish());
possibleAnswer5.setText(allQuestions.get(orderList.get(4)).getEnglish()); possibleAnswer5.setText(questions.get(orderList.get(4)).getEnglish());
possibleAnswer6.setText(allQuestions.get(orderList.get(5)).getEnglish()); possibleAnswer6.setText(questions.get(orderList.get(5)).getEnglish());
} }
@ -145,7 +145,7 @@ public class SixMeaningsController extends SharedCodeController {
private void checkAnswers() { public void checkAnswers() {
ArrayList<String> answer = new ArrayList<>(); ArrayList<String> answer = new ArrayList<>();
@ -171,7 +171,7 @@ public class SixMeaningsController extends SharedCodeController {
studyIcon.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/pass-fail-50.png")); studyIcon.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/pass-fail-50.png"));
studyText.setFill(Color.BLACK); studyText.setFill(Color.BLACK);
setWords(isEnglish); setWords(allQuestions,orderList);
correctAnswer.setText(Integer.toString(Question.correctAnswers)); correctAnswer.setText(Integer.toString(Question.correctAnswers));