package de.thdeg.grademanager.gui; import javafx.event.ActionEvent; import javafx.event.Event; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Node; import javafx.scene.Scene; import javafx.stage.Stage; import java.io.IOException; /** * This is used to reduce redundant code for switching gui-windows. * * author: Kevin Thaller */ public class SwitchWindowHelper { /** * This method is used to "switchTo" a certain window. * * author: Kevin Thaller * * @param windowTitle the String of the new switched to window. * @param event the Event which triggers the window change. * @throws IOException */ @FXML public static void switchTo(String windowTitle, Event event) throws IOException { FXMLLoader root = new FXMLLoader(Main.class.getResource(getResourceName(windowTitle))); Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); Scene scene = new Scene(root.load(), 960, 540); if (stage != null){ stage.setTitle(windowTitle); stage.setScene(scene); stage.show(); } } /** * This method is used to get the JavaFX-Gui-File for a given window-title. * * author: Kevin Thaller * * @param windowTitle the String of the new-window. * @return the String of the JavaFX-Gui-File for a given window-title. * If the window-title isn't found an empty String will be returned. */ private static String getResourceName(String windowTitle) { switch (windowTitle) { case "Main": return "main.fxml"; case "Student Details": return "student-details.fxml"; case "Student Modification": return "student-modification.fxml"; case "CoursesOfStudy Modification": return "courses-of-study-modification.fxml"; case "CoursesOfStudy Details": return "courses-of-study-details.fxml"; case "Course Modification": return "course-modification.fxml"; case "Student Stats": return "student-stats.fxml"; case "Student Courses": return "student-courses.fxml"; case "Student Grades": return "student-grades.fxml"; } return ""; } }