package mi.hdm.controllers; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.layout.AnchorPane; import javafx.stage.Stage; import mi.hdm.GuiController; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.io.IOException; public abstract class BaseController { private final static Logger log = LogManager.getLogger(BaseController.class); protected Scene currentScene; //TODO this should be static? private static View currentView = GuiController.getStartupView(); protected void changeScene(final View newScene, Object... args) { if (newScene == currentView) { return; } final Stage stage = GuiController.getApplicationStage(); try { boolean wasMaximized = stage.isMaximized(); double sizeX = stage.getWidth(); double sizeY = stage.getHeight(); String newWindowTitle = newScene.getWindowTitle(); log.debug("Attempting to change the scene to {}", newScene); Parent newParent = newScene.getScene(args); currentScene = new Scene(newParent, sizeX, sizeY); currentView = newScene; stage.setTitle(newWindowTitle); stage.setScene(currentScene); stage.setMaximized(wasMaximized); log.info("new view: {}", currentView); } catch (IOException io) { log.error("IO Exception: something went wrong when changing the scene."); io.printStackTrace(); } } protected void loadHeader(AnchorPane parent) { try { //load the header and constrain it to the borders of the parent element AnchorPane header = (AnchorPane) ViewComponent.HEADER.getParentElement(); AnchorPane.setLeftAnchor(header, 0.0); AnchorPane.setTopAnchor(header, 0.0); AnchorPane.setRightAnchor(header, 0.0); parent.getChildren().add(header); } catch (IOException e) { log.error("Something went wrong loading the header"); e.printStackTrace(); } } }