All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.epics.gpclient.javafx.tools.JavaFXLaunchUtil Maven / Gradle / Ivy

There is a newer version: 1.0.8
Show newest version
/**
 * Copyright information and license terms for this software can be
 * found in the file LICENSE.TXT included with the distribution.
 */
package org.epics.gpclient.javafx.tools;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.EventHandler;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

/**
 *
 * @author carcassi
 */
public class JavaFXLaunchUtil {
    
    private JavaFXLaunchUtil() {
        // No instances allowed
    }
    
    public static void launch(String title, Class rootClass, String... args) {
        appTitle = title;
        appRootClass = rootClass;
        SimpleApplication.launch(SimpleApplication.class, args);
    }

    public static void open(String title, Class rootClass) {
        try {
            Stage stage = new Stage();
            stage.setTitle(title);
            stage.setScene(new Scene(rootClass.newInstance()));
            stage.show();
        } catch (InstantiationException | IllegalAccessException instantiationException) {
            // TODO put an Alert, but requires jdk 8u40
        }
    }
    
    private static volatile String appTitle;
    private static volatile Class appRootClass;
    
    public static class SimpleApplication extends Application {
        @Override
        public void start(Stage primaryStage) throws Exception {
            primaryStage.setTitle(appTitle);
            Scene scene = new Scene(appRootClass.newInstance());
            primaryStage.setScene(scene);
            primaryStage.setOnCloseRequest(new EventHandler() {
                @Override
                public void handle(WindowEvent t) {
                    Platform.exit();
                    System.exit(0);
                }
            });
            primaryStage.show();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy