diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/BaseController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/BaseController.java index a8d9e0a..48ceb2e 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/BaseController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/BaseController.java @@ -1,10 +1,10 @@ package ntnu.systemutvikling.team6.controller.components; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; + import javafx.scene.control.Alert; import ntnu.systemutvikling.team6.service.AuthenticationService; + public abstract class BaseController { protected AuthenticationService authToken; @@ -23,6 +23,7 @@ protected boolean isLoggedin(){ return authToken != null && authToken.isLoggedin(); } + /** * Show an JavaFx alert dialog with the specified type, title, and message. * diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/LoaderScene.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/LoaderScene.java index 701094e..771f043 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/LoaderScene.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/LoaderScene.java @@ -24,16 +24,14 @@ */ public class LoaderScene { /** - * When going to a new scene, this method is called to load the new scene. It takes the name of - * the scene to load, the event that triggered the scene change, and the charity that is being - * passed to the new scene (if applicable). It loads the FXML file for the new scene, sets the - * controller, and switches the scene. + * When going to a new scene, this method and another called to load the new scene. + * It loads the FXML file for the new scene, sets the controller, and switches the scene. * * @param sceneName * @param event * @param charity */ - public static void LoadScene(String sceneName, ActionEvent event, Charity charity, String query, AuthenticationService authtoken) { + public static void LoadScene(String sceneName, Stage stage, Charity charity, String query, AuthenticationService authtoken) { try { System.out.println(HmHApplication.class.getResource("/fxml/" + sceneName + ".fxml")); FXMLLoader fxmlLoader = @@ -66,7 +64,6 @@ public static void LoadScene(String sceneName, ActionEvent event, Charity charit baseController.setAuthToken(authtoken); } - Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); Image icon = new Image( Objects.requireNonNull(HmHApplication.class.getResource("/images/Logo.png")) @@ -80,4 +77,15 @@ public static void LoadScene(String sceneName, ActionEvent event, Charity charit throw new RuntimeException(e); } } + /** + * This method is the same as above, but tailored for Action Events, say through clicking a button. + * It takes the name of + * * the scene to load, the event that triggered the scene change, and the charity that is being + * * passed to the new scene (if applicable). + */ + + public static void LoadScene(String sceneName, ActionEvent event, Charity charity, String query, AuthenticationService authtoken) { + Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); + LoadScene(sceneName, stage, charity, query, authtoken); + } }