Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

properly log any exception #26

Open
github-actions bot opened this issue Jan 3, 2021 · 0 comments
Open

properly log any exception #26

github-actions bot opened this issue Jan 3, 2021 · 0 comments
Labels
todo Needs to be done todo-log TODO related to logging

Comments

@github-actions
Copy link

github-actions bot commented Jan 3, 2021

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

@github-actions github-actions bot added the todo Needs to be done label Jan 3, 2021
@jhenly jhenly added the todo-log TODO related to logging label Jan 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
todo Needs to be done todo-log TODO related to logging
Projects
None yet
Development

No branches or pull requests

1 participant