Updated documentation for SharedCodeController.java.

Addressed issue .
This commit is contained in:
top19 2020-05-01 14:20:47 +01:00
parent 430cbcebad
commit 19fcf162ee

View file

@ -1,3 +1,9 @@
/**
* @(#) FlashcardController.java 0,1 2020/05/07
* <p>
* Copyright (c) 2020 Aberystwyth University.
* All rights reserved.
*/
package uk.ac.aber.cs221.group20.javafx; package uk.ac.aber.cs221.group20.javafx;
import javafx.fxml.FXML; import javafx.fxml.FXML;
@ -12,8 +18,9 @@ import uk.ac.aber.cs221.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 Tom Perry [top19] * @author Tom Perry [top19]
* @Version 0.1 Initial development. * @Version 0.2 Documentation.
* @see Application * @see Application
* @see DictionaryEntry * @see DictionaryEntry
* @see ScreenSwitch * @see ScreenSwitch
@ -25,7 +32,9 @@ abstract public class SharedCodeController {
// Class variables. // // Class variables. //
// //////////////// // // //////////////// //
// Static variable that tracks whether the words are currently sorted by english or welsh.
static boolean isSortedByEnglish = true; static boolean isSortedByEnglish = true;
// Static variable that tracks the current size of the menu's sideBar to keep its size consistent when switching scenes.
static int sideBarWidth = 50; static int sideBarWidth = 50;
// /////////////////// // // /////////////////// //
@ -71,9 +80,11 @@ abstract public class SharedCodeController {
* Method that sets up the program's menu in each of the controllers, intialising the icons and text. * Method that sets up the program's menu in each of the controllers, intialising the icons and text.
*/ */
public void setup() { public void setup() {
// Call method to setup the icons and set the menus side bars width to the current value of 'sideBar'.
initializeIcons(); initializeIcons();
sideBar.setWidth(sideBarWidth); sideBar.setWidth(sideBarWidth);
// If the menus width isnt the default value, the menu is determined to be expanded and the text is initialised.
if (sideBarWidth != 50) if (sideBarWidth != 50)
initializeMenuText(); initializeMenuText();
} }
@ -102,7 +113,7 @@ abstract public class SharedCodeController {
} }
/** /**
* Method that disables the menus text when the menu is collapsed. * Method that disables the menus text when the menu is collapsed by setting their text to nothing.
*/ */
private void disableMenuText() { private void disableMenuText() {
dictionaryText.setText(""); dictionaryText.setText("");
@ -113,41 +124,49 @@ abstract public class SharedCodeController {
} }
/** /**
* Event that expands the menu whenever the menu's 'expandMenuIcon' icon is clicked. * Event that collapses or expands the menu whenever the 'expandMenuIcon' is clicked by the user. The method determines the menus current state by looking at the value of
* 'sideBarWidth' and uses to decide whether the menu needs to expand to 230 and initialise the menu text or collapse to 50, disabling menu text.
*/ */
@FXML @FXML
private void expandMenuClick() { private void expandMenuClick() {
if(sideBar.getWidth() == 50) { // If sideBar is currently collapsed, expand it and display menu text. // If sideBar is currently collapsed, expand it and display menu text.
if(sideBar.getWidth() == 50) {
sideBar.setWidth(sideBarWidth = 230); sideBar.setWidth(sideBarWidth = 230);
initializeMenuText(); // Display menu // Display menu
initializeMenuText();
} else { } else {
sideBar.setWidth(sideBarWidth = 50); // Else collapse the menu and disable its text. // Else collapse the menu and disable its text.
sideBar.setWidth(sideBarWidth = 50);
disableMenuText(); disableMenuText();
} }
} }
/** /**
* Event to switch scenes to 'dictionary.fxml' when the menu's 'dictionaryIcon' icon is clicked. * Event to switch scenes to 'dictionary.fxml' when the menu's 'dictionaryIcon' icon is clicked.
*
* @see ScreenSwitch * @see ScreenSwitch
*/ */
@FXML @FXML
private void dictionaryIconClick() { private void dictionaryIconClick() {
// Use 'ScreenSwitch' to switch to the 'dictionaryScene'.
ScreenSwitch.swap(ScreenSwitch.SceneType.dictionaryScene); ScreenSwitch.swap(ScreenSwitch.SceneType.dictionaryScene);
} }
/** /**
* Event to switch scenes to 'practicelist.fxml' when the menu's 'practiceListIcon' icon is clicked. * Event to switch scenes to 'practicelist.fxml' when the menu's 'practiceListIcon' icon is clicked.
*
* @see ScreenSwitch * @see ScreenSwitch
*/ */
@FXML @FXML
private void practiceListIconClick() { private void practiceListIconClick() {
ScreenSwitch.swap(ScreenSwitch.SceneType.practiceListScene); // Use 'ScreenSwitch' to switch to the 'practiceListScene'.
ScreenSwitch.swap(ScreenSwitch.SceneType.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 * 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. * to avoid NullPointerException's in the flashcard scene.
*
* @see ScreenSwitch * @see ScreenSwitch
* @see Application * @see Application
* @see DictionaryEntry * @see DictionaryEntry
@ -155,36 +174,40 @@ abstract public class SharedCodeController {
*/ */
@FXML @FXML
private void flashcardIconClick() { private void flashcardIconClick() {
// Check to see if there are any practice words before switching scene, throwing an alert notifying them that they can't switch scenes.
if(Application.practiceList.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. if(Application.practiceList.size() == 0) {
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.SceneType.flashcardScene); // Switch to flashcard scene if the program has practice words. // Switch to flashcard scene if the program has practice words.
ScreenSwitch.swap(ScreenSwitch.SceneType.flashcardScene);
} }
} }
/** /**
* Event to generate an assessment using AssessmentGenerator when the menu's 'studyIcon' icon is clicked. * Event to generate an assessment using AssessmentGenerator when the menu's 'studyIcon' icon is clicked.
*
* @see AssessmentGenerator * @see AssessmentGenerator
* @see Application * @see Application
* @see DictionaryEntry * @see DictionaryEntry
*/ */
@FXML @FXML
private void studyIconClick() { private void studyIconClick() {
// Generate a new assessment using the programs practice list.
AssessmentGenerator.generateAssessment(Application.practiceList); AssessmentGenerator.generateAssessment(Application.practiceList);
} }
/** /**
* Event to switch scenes to 'addword.fxml' when the menu's 'addwordIcon' icon is clicked. * Event to switch scenes to 'addword.fxml' when the menu's 'addwordIcon' icon is clicked.
*
* @see ScreenSwitch * @see ScreenSwitch
*/ */
@FXML @FXML
private void addWordIconClick(){ private void addWordIconClick(){
// Use 'ScreenSwitch' to switch to the 'addWordScene'.
ScreenSwitch.swap(ScreenSwitch.SceneType.addWordScene); ScreenSwitch.swap(ScreenSwitch.SceneType.addWordScene);
} }