-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
properly log any exception
| // TODO properly log any exception |
private Stage primaryStage;
private ControllerMediator controllerMediator;
// used by stage's scene, set by loadFxmlAndCreateControllerMediator()
private Parent rootView;
/**
* JavaFX needed no-arg constructor .
*/
public ApplicationHandler() {}
@Override
public final void start(Stage primaryStage) throws Exception {
this.primaryStage = primaryStage;
try {
// load all of the fxml files and create controller mediator
controllerMediator = loadFxmlAndCreateControllerMediator();
} catch (Exception e) {
// TODO properly notify user of unrecoverable exception
System.err.println(e.getMessage());
e.printStackTrace();
/* exception is unrecoverable, exit javafx */
Platform.exit();
}
// allow system tray supporting implementing classes to do their thing
setUpSystemTrayIfSupported();
// configure and set up listeners in controller mediator
configureControllerMediator();
// load fonts from resources
FontUtils.loadFontsFromResources(FONT_RES_PATH);
// create window with no title bar or default min, max, close buttons
primaryStage.initStyle(StageStyle.UNDECORATED);
primaryStage.setScene(new Scene(rootView));
// add listener to stage for window edge resizing
ResizeHelper.addResizeListener(primaryStage);
primaryStage.show();
// TODO hide stage if app should start minimized in system tray
controllerMediator.requestShowDashboardView();
setPrimaryStageMinBounds();
}
/**
* Loads all of the fxmls into FXMLReferences and creates a
* ControllerMediator from them.
* <p>
* This must be called after the primary stage has been set.
*/
private ControllerMediator loadFxmlAndCreateControllerMediator() throws IOException {
// load fxml references from fxml file
FXMLReference rootReference = loadReference(ROOT_FXML);
FXMLReference dashReference = loadReference(DASHBOARD_FXML);
FXMLReference settingsReference = loadReference(SETTINGS_FXML);
FXMLReference logReference = loadReference(LOG_FXML);
// need this to init stage's scene
rootView = rootReference.getView();
return new ControllerMediator(primaryStage, rootReference, dashReference, settingsReference, logReference);
}
/** Convenience helper that loads fxml references. */
private static FXMLReference loadReference(String ref) throws IOException {
return FXMLReference.loadFxml(ApplicationHandler.class.getResource(ref));
}
/**
* Helper method that configures and sets up handlers in controller
* mediator.
*/
private void configureControllerMediator() {
/* set application control button handlers */
controllerMediator.setOnWindowCloseButtonActionHandler(getApplicationCloseButtonHandler());
controllerMediator.setOnWindowMinimizeButtonActionHandler(getApplicationMinimizeButtonHandler());
controllerMediator.setOnWindowMinimizeButtonActionHandler(getApplicationMaximizeButtonHandler());
}
/** Allow system tray supporting implementing classes to do their thing. */
private void setUpSystemTrayIfSupported() {
// do nothing if system tray is not supported
if (!systemTrayIsSupported()) { return; }
try {
// call 'this' abstract method
setUpSystemTray();
} catch (Exception e) {
// TODO properly log any exception
System.err.println(e.getMessage());
}
}
/* enforces window to not become smaller than root's min bounds */5d6d4736cd0d3e25df00a1962e9ac3e1ae0aa18f