Updated ScreenSwitch Class

ScreenSwitch Class now uses 3 space tabbing consistently
This commit is contained in:
law39 2020-04-30 19:07:14 +01:00
parent 4198844932
commit 6b5cf0e457

View file

@ -17,134 +17,134 @@ import java.net.URL;
* @see SceneEnum * @see SceneEnum
*/ */
public class ScreenSwitch extends SharedCodeController { public class ScreenSwitch extends SharedCodeController {
private static Scene scene; private static Scene scene;
private static Stage stage; private static Stage stage;
/** /**
* This constructor is used by Application to pass control of the stage. * This constructor is used by Application to pass control of the stage.
* It will also display the launch scene on the stage to the user. * It will also display the launch scene on the stage to the user.
* Change the Scene loaded here to change the launch screen. * Change the Scene loaded here to change the launch screen.
* @see Application * @see Application
* @param stage This a JavaFX stage setup by application, this will be ready to have a scene assigned. * @param stage This a JavaFX stage setup by application, this will be ready to have a scene assigned.
*/ */
public ScreenSwitch(Stage stage){ public ScreenSwitch(Stage stage){
scene = new Scene(fxmlLoader(SceneEnum.dictionaryScene)); scene = new Scene(fxmlLoader(SceneEnum.dictionaryScene));
stage.setMinHeight(680); stage.setMinHeight(680);
stage.setHeight(680); stage.setHeight(680);
stage.setMinWidth(1100); stage.setMinWidth(1100);
stage.setWidth(1100); stage.setWidth(1100);
stage.setScene(scene); stage.setScene(scene);
stage.show(); stage.show();
ScreenSwitch.stage = stage; ScreenSwitch.stage = stage;
} }
/** /**
* This method should only be used by Application. * This method should only be used by Application.
* This provides legacy support for the old way of screen switching by continuing to allow Application to access scene. * This provides legacy support for the old way of screen switching by continuing to allow Application to access scene.
* It should be removed before release. * It should be removed before release.
* *
* @Deprecated This is depreciated pending removal of all legacy screen switches * @Deprecated This is depreciated pending removal of all legacy screen switches
* @see Application * @see Application
* @return This returns the currently displayed scene for purposes of screen switching * @return This returns the currently displayed scene for purposes of screen switching
*/ */
public static void setLegacyScene(String fxmlFile){ public static void setLegacyScene(String fxmlFile){
System.err.println("Switching Scene with legacy method, you should change to ScreenSwitch"); System.err.println("Switching Scene with legacy method, you should change to ScreenSwitch");
String fileInclExtension = fxmlFile + ".fxml"; String fileInclExtension = fxmlFile + ".fxml";
Parent root = null; Parent root = null;
try{ try{
root = FXMLLoader.load(new URL("file:src/main/resources/uk/ac/aber/cs22120/group20/" + fileInclExtension)); root = FXMLLoader.load(new URL("file:src/main/resources/uk/ac/aber/cs22120/group20/" + fileInclExtension));
}catch (IOException e){ // If an error occurs, print out error message on STDIO and crash gracefully }catch (IOException e){ // If an error occurs, print out error message on STDIO and crash gracefully
System.err.print("Loading the FXML file "); System.err.print("Loading the FXML file ");
System.err.print(fileInclExtension); System.err.print(fileInclExtension);
System.err.println(" failed!"); System.err.println(" failed!");
System.err.println("Using depreciated method, shame!"); System.err.println("Using depreciated method, shame!");
e.printStackTrace(System.err); e.printStackTrace(System.err);
System.exit(-1); System.exit(-1);
} }
scene.setRoot(root); scene.setRoot(root);
} }
/** /**
* Method that is responsible for the switching between * Method that is responsible for the switching between
* JavaFX, with it taking the new scenes name as an enum as a parameter. * JavaFX, with it taking the new scenes name as an enum as a parameter.
* @see SceneEnum * @see SceneEnum
* @param newScene This is a SceneEnum of the scene which is requested to switch to * @param newScene This is a SceneEnum of the scene which is requested to switch to
*/ */
public static void swap(SceneEnum newScene){ public static void swap(SceneEnum newScene){
Parent root = fxmlLoader(newScene); Parent root = fxmlLoader(newScene);
scene.setRoot(root); scene.setRoot(root);
} }
/** /**
* This private method responsible for loading in FXML * This private method responsible for loading in FXML
* Returns a JavaFX Parent containing the loaded in FXML * Returns a JavaFX Parent containing the loaded in FXML
* *
* @param newScene This is a SceneEnum of the scene which is to be loaded in. * @param newScene This is a SceneEnum of the scene which is to be loaded in.
* @return Parent containing the interpreted FXML. * @return Parent containing the interpreted FXML.
*/ */
private static Parent fxmlLoader(SceneEnum newScene){ private static Parent fxmlLoader(SceneEnum newScene){
Parent root = null; Parent root = null;
try{ try{
String fxmlName = newScene.getFXML(); String fxmlName = newScene.getFXML();
root = FXMLLoader.load(new URL("file:src/main/resources/uk/ac/aber/cs22120/group20/" + fxmlName)); root = FXMLLoader.load(new URL("file:src/main/resources/uk/ac/aber/cs22120/group20/" + fxmlName));
}catch (IOException e){ // If an error occurs, print out error message on STDIO and crash gracefully }catch (IOException e){ // If an error occurs, print out error message on STDIO and crash gracefully
System.err.print("Loading the FXML file "); System.err.print("Loading the FXML file ");
System.err.print(newScene.getFXML()); System.err.print(newScene.getFXML());
System.err.println(" Failed!"); System.err.println(" Failed!");
System.err.println(e.toString()); System.err.println(e.toString());
e.printStackTrace(System.err); e.printStackTrace(System.err);
System.exit(-1); System.exit(-1);
} }
return root; return root;
} }
public enum SceneEnum{ public enum SceneEnum{
/** /**
* Enum containing each of the scenes required for use in the program along with the FXML file names. * Enum containing each of the scenes required for use in the program along with the FXML file names.
* This is a sub-enum of ScreenSwitch * This is a sub-enum of ScreenSwitch
* *
* To add a new scene just add an enum containing the name to be used following which in parenthesis the FXML file with extension. * To add a new scene just add an enum containing the name to be used following which in parenthesis the FXML file with extension.
* Following the spirit of those already setup. * Following the spirit of those already setup.
* This file must be located in the resources folder in the package uk.ac.aber.cs22120.group20. * This file must be located in the resources folder in the package uk.ac.aber.cs22120.group20.
* *
* @author Luke Wybar (LAW39) * @author Luke Wybar (LAW39)
* @version 0.1 * @version 0.1
* @see ScreenSwitch * @see ScreenSwitch
*/ */
addWordScene("addword.fxml"), addWordScene("addword.fxml"),
dictionaryScene("dictionary.fxml"), dictionaryScene("dictionary.fxml"),
flashcardScene("flashcard.fxml"), flashcardScene("flashcard.fxml"),
practiceListScene("practicelist.fxml"), practiceListScene("practicelist.fxml"),
matchMeaningScene("matchthemeaning.fxml"), matchMeaningScene("matchthemeaning.fxml"),
sixMeaningScene("sixmeanings.fxml"), sixMeaningScene("sixmeanings.fxml"),
translationScene("translation.fxml"), translationScene("translation.fxml"),
; ;
private String fxmlName; private String fxmlName;
/** /**
* Constructor for giving the FXML file name to the enum. * Constructor for giving the FXML file name to the enum.
* *
* @param fxmlName This is the FXML file name including extension. * @param fxmlName This is the FXML file name including extension.
*/ */
SceneEnum(String fxmlName) { SceneEnum(String fxmlName) {
this.fxmlName = fxmlName; this.fxmlName = fxmlName;
} }
/** /**
* This method returns the filename of the selected enum. * This method returns the filename of the selected enum.
* *
* @return Filename of the selected enumeration including extension. * @return Filename of the selected enumeration including extension.
*/ */
String getFXML(){ String getFXML(){
return this.fxmlName; return this.fxmlName;
} }
} }
} }