Newer
Older

Karsch Lukas
committed
package mi.hdm.controllers;

Karsch Lukas
committed
import javafx.scene.Parent;
import javafx.scene.Scene;

Karsch Lukas
committed
import javafx.scene.layout.AnchorPane;

Karsch Lukas
committed
import javafx.stage.Stage;
import mi.hdm.GuiController;

Karsch Lukas
committed
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Karsch Lukas
committed

Karsch Lukas
committed
import java.io.IOException;

Karsch Lukas
committed
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();

Karsch Lukas
committed
protected void changeScene(final View newScene, Object... args) {
if (newScene == currentView) {
return;
}
final Stage stage = GuiController.getApplicationStage();

Karsch Lukas
committed
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);

Karsch Lukas
committed
currentScene = new Scene(newParent, sizeX, sizeY);

Karsch Lukas
committed
stage.setTitle(newWindowTitle);
stage.setScene(currentScene);
stage.setMaximized(wasMaximized);
log.info("new view: {}", currentView);

Karsch Lukas
committed
} catch (IOException io) {
log.error("IO Exception: something went wrong when changing the scene.");
io.printStackTrace();
}
}

Karsch Lukas
committed

Karsch Lukas
committed
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();
}

Karsch Lukas
committed
}