Skip to content

Commit

Permalink
Feat: Extended to LoaderScene with a another method (that points to t…
Browse files Browse the repository at this point in the history
…he original), to make use of the stage instead of only actionEvent
  • Loading branch information
AdrianBalunan committed Apr 18, 2026
1 parent 40d2815 commit 5162b5d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -23,6 +23,7 @@ protected boolean isLoggedin(){
return authToken != null && authToken.isLoggedin();
}


/**
* Show an JavaFx alert dialog with the specified type, title, and message.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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"))
Expand All @@ -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);
}
}

0 comments on commit 5162b5d

Please sign in to comment.