Example usage for javafx.application Platform setImplicitExit

List of usage examples for javafx.application Platform setImplicitExit

Introduction

In this page you can find the example usage for javafx.application Platform setImplicitExit.

Prototype

public static void setImplicitExit(boolean implicitExit) 

Source Link

Document

Sets the implicitExit attribute to the specified value.

Usage

From source file:io.uploader.drive.DriveUploader.java

public static void main(String[] args) {

    if (isMacOsX()) {
        System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.setProperty("com.apple.mrj.application.apple.menu.about.name",
                Configuration.INSTANCE.getAppName());
        try {//from  w w  w .j  av a  2  s. c  o  m
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                | UnsupportedLookAndFeelException e) {
            logger.error("Error occurred while initializing the UI", e);
        }
    }

    Platform.setImplicitExit(false);

    // load the settings
    String settingsFile = "driveuploader-settings.xml";
    if (!new java.io.File(settingsFile).exists())
        settingsFile = null;
    try {
        Configuration.INSTANCE.load(settingsFile);
    } catch (ConfigurationException e) {
        logger.error("Error occurred while initializing the configuration", e);
    }

    try {
        // initialize the transport
        httpTransport = GoogleNetHttpTransport.newTrustedTransport();

        // initialize the data store factory
        dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);

    } catch (IOException e) {
        logger.error("Error occurred while initializing the drive", e);
        Platform.exit();
    } catch (Throwable t) {
        logger.error("Error occurred while initializing the drive", t);
        Platform.exit();
    }

    launch(args);
}

From source file:org.pidpys.standalone.configuration.JavaFxApplicationConfiguration.java

@PostConstruct
public void init() {
    new JFXPanel();
    Platform.setImplicitExit(false);
}

From source file:ninja.javafx.smartcsv.fx.SmartCSV.java

@Override
public void start(Stage primaryStage) throws Exception {
    appContext = new AnnotationConfigApplicationContext(SmartCSV.class);
    String name = appContext.getEnvironment().getProperty("application.name");
    String version = appContext.getEnvironment().getProperty("application.version");

    Platform.setImplicitExit(false);

    AboutController aboutController = appContext.getBean(AboutController.class);
    aboutController.setHostServices(getHostServices());

    try {/*from   ww  w .j  a v  a 2 s  .  co m*/
        showUI(primaryStage, name, version);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:io.github.moosbusch.permagon.application.spi.AbstractPermagonApplicationContext.java

private void init(PermagonApplication<? extends PermagonApplicationContext> application) {
    Platform.setImplicitExit(true);
    registerShutdownHook();/* w ww  .ja  va  2s.  c  o m*/

    try {
        getBeanFactory().registerSingleton(APPLICATION_BEAN_NAME, application);
        loadAnnotationConfig(application);
    } finally {
        refresh();
    }
    try {
        initFrameWork();
    } catch (BundleException ex) {
        Logger.getLogger(AbstractPermagonApplicationContext.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.esri.geoevent.test.performance.ui.ProducerUI.java

@Override
public void start(Stage primaryStage) {
    String modeStr = "Producer";
    if (StringUtils.isEmpty(modeStr)) {
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_NULL")
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();/*from  ww w . ja va  2 s  .  c  o m*/
        System.exit(0);
        return;
    }

    Mode mode = Mode.fromValue(modeStr);
    String fxmlFile = "";
    Object controller = null;
    switch (mode) {
    case Producer:
        fxmlFile = "PerformanceCollector.fxml";
        controller = new ProducerController();
        break;
    default:
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_UNKNOWN", mode)
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();
        System.exit(0);
        return;
    }

    Platform.setImplicitExit(true);
    try {
        FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFile));
        if (controller != null) {
            loader.setController(controller);
        }
        Parent parent = (Parent) loader.load();
        Scene scene = new Scene(parent);

        primaryStage.setOnCloseRequest(new AppCloser());
        primaryStage.setTitle(UIMessages.getMessage("UI_TITLE", mode));
        primaryStage.setScene(scene);
        primaryStage.show();
        ProducerUI.primaryStage = primaryStage;
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.esri.geoevent.test.performance.ui.ConsumerUI.java

@Override
public void start(Stage primaryStage) {

    String modeStr = "Consumer";
    if (StringUtils.isEmpty(modeStr)) {
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_NULL")
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();//from w w  w .j av a 2  s  . co m
        System.exit(0);
        return;
    }

    Mode mode = Mode.fromValue(modeStr);
    String fxmlFile = "";
    Object controller = null;
    switch (mode) {

    case Consumer:
        fxmlFile = "PerformanceCollector.fxml";
        controller = new ConsumerController();
        break;

    default:
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_UNKNOWN", mode)
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();
        System.exit(0);
        return;
    }

    Platform.setImplicitExit(true);
    try {
        FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFile));
        if (controller != null) {
            loader.setController(controller);
        }
        Parent parent = (Parent) loader.load();
        Scene scene = new Scene(parent);

        primaryStage.setOnCloseRequest(new AppCloser());
        primaryStage.setTitle(UIMessages.getMessage("UI_TITLE", mode));
        primaryStage.setScene(scene);
        primaryStage.show();
        ConsumerUI.primaryStage = primaryStage;
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.esri.geoevent.test.performance.ui.OrchestratorUI.java

@Override
public void start(Stage primaryStage) {

    Parameters parameters = getParameters();
    Map<String, String> args = parameters.getNamed();
    String modeStr = args.get("mode");
    if (modeStr == null) {
        modeStr = "Orchestrator";
    }/* www . j  av  a 2  s  .com*/
    if (StringUtils.isEmpty(modeStr)) {
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_NULL")
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();
        System.exit(0);
        return;
    }

    Mode mode = Mode.fromValue(modeStr);
    String fxmlFile = "";
    Object controller = null;
    switch (mode) {

    case Orchestrator:
        fxmlFile = "Orchestrator.fxml";
        //controller = new OrchestratorController();
        break;
    default:
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_UNKNOWN", mode)
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();
        System.exit(0);
        return;
    }

    Platform.setImplicitExit(true);
    try {
        FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFile));
        if (controller != null) {
            loader.setController(controller);
        }
        Parent parent = (Parent) loader.load();
        Scene scene = new Scene(parent);

        // set the stage on the orchestrator
        if (loader.getController() instanceof OrchestratorController) {
            OrchestratorController orchestratorController = loader.getController();
            orchestratorController.setStage(primaryStage);
        }

        primaryStage.setOnCloseRequest(new AppCloser());
        primaryStage.setTitle(UIMessages.getMessage("UI_TITLE", mode));
        primaryStage.setScene(scene);
        primaryStage.show();
        OrchestratorUI.primaryStage = primaryStage;
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:de.chaosfisch.uploader.gui.GUIUploader.java

@Override
public void start(final Stage primaryStage) {
    StyleManager.getInstance().addUserAgentStylesheet(
            getClass().getResource("/de/chaosfisch/uploader/resources/style.css").toExternalForm());

    final boolean useMasterPassword = configuration.getBoolean(IPersistenceService.MASTER_PASSWORD, false);
    if (useMasterPassword) {
        dialogHelper.showInputDialog("Masterpasswort", "Masterpasswort:", new Callback() {
            @Override// w w  w.ja  v  a  2s  . c  o  m
            public void onInput(final InputDialogController controller, final String input) {
                if (Strings.isNullOrEmpty(input)) {
                    controller.input.getStyleClass().add("input-invalid");
                } else {
                    persistenceService.generateBackup();
                    persistenceService.setMasterPassword(input);
                    controller.closeDialog(null);
                }
            }
        }, true);
    }
    if (!persistenceService.loadFromStorage()) {
        if (useMasterPassword) {
            dialogHelper.showErrorDialog("Closing..", "Invalid password.");
        } else {
            dialogHelper.showErrorDialog("Closing..", "Unknown error occured.");
        }
        Platform.exit();
    } else {
        persistenceService.cleanStorage();
        Platform.setImplicitExit(false);
        initApplication(primaryStage);

        uploadService.resetUnfinishedUploads();
        uploadService.startStarttimeCheck();

        LOGGER.info("Verifying accounts");
        final List<Account> accounts = accountService.getAll();
        for (final Account account : accounts) {
            if (!accountService.verifyAccount(account)) {
                LOGGER.warn("Account is invalid: {}", account.getName());
                dialogHelper.showAccountPermissionsDialog(account);
            }
        }
    }
}

From source file:de.mirkosertic.desktopsearch.DesktopSearch.java

@Override
public void start(Stage aStage) throws Exception {

    // This is our base directory
    File theBaseDirectory = new File(SystemUtils.getUserHome(), "FreeSearchIndexDir");
    theBaseDirectory.mkdirs();/*from  ww w  .  j a  va 2 s  .  c  o m*/

    configurationManager = new ConfigurationManager(theBaseDirectory);

    Notifier theNotifier = new Notifier();

    stage = aStage;

    // Create the known preview processors
    PreviewProcessor thePreviewProcessor = new PreviewProcessor();

    try {
        // Boot the search backend and set it up for listening to configuration changes
        backend = new Backend(theNotifier, configurationManager.getConfiguration(), thePreviewProcessor);
        configurationManager.addChangeListener(backend);

        // Boot embedded JSP container
        embeddedWebServer = new FrontendEmbeddedWebServer(aStage, backend, thePreviewProcessor,
                configurationManager);

        embeddedWebServer.start();
    } catch (BindException | LockReleaseFailedException | LockObtainFailedException e) {
        // In this case, there is already an instance of DesktopSearch running
        // Inform the instance to bring it to front end terminate the current process.
        URL theURL = new URL(FrontendEmbeddedWebServer.getBringToFrontUrl());
        // Retrieve the content, but it can be safely ignored
        // There must only be the get request
        Object theContent = theURL.getContent();

        // Terminate the JVM. The window of the running instance is visible now.
        System.exit(0);
    }

    aStage.setTitle("Free Desktop Search");
    aStage.setWidth(800);
    aStage.setHeight(600);
    aStage.initStyle(StageStyle.TRANSPARENT);

    FXMLLoader theLoader = new FXMLLoader(getClass().getResource("/scenes/mainscreen.fxml"));
    AnchorPane theMainScene = theLoader.load();

    final DesktopSearchController theController = theLoader.getController();
    theController.configure(this, backend, FrontendEmbeddedWebServer.getSearchUrl(), stage.getOwner());

    Undecorator theUndecorator = new Undecorator(stage, theMainScene);
    theUndecorator.getStylesheets().add("/skin/undecorator.css");

    Scene theScene = new Scene(theUndecorator);

    // Hacky, but works...
    theUndecorator.setStyle("-fx-background-color: rgba(0, 0, 0, 0);");

    theScene.setFill(Color.TRANSPARENT);
    aStage.setScene(theScene);

    aStage.getIcons().add(new Image(getClass().getResourceAsStream("/fds.png")));

    if (SystemTray.isSupported()) {
        Platform.setImplicitExit(false);
        SystemTray theTray = SystemTray.getSystemTray();

        // We need to reformat the icon according to the current tray icon dimensions
        // this depends on the underlying OS
        java.awt.Image theTrayIconImage = Toolkit.getDefaultToolkit()
                .getImage(getClass().getResource("/fds_small.png"));
        int trayIconWidth = new TrayIcon(theTrayIconImage).getSize().width;
        TrayIcon theTrayIcon = new TrayIcon(
                theTrayIconImage.getScaledInstance(trayIconWidth, -1, java.awt.Image.SCALE_SMOOTH),
                "Free Desktop Search");
        theTrayIcon.setImageAutoSize(true);
        theTrayIcon.setToolTip("FXDesktopSearch");
        theTrayIcon.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 1) {
                    Platform.runLater(() -> {
                        if (stage.isIconified()) {
                            stage.setIconified(false);
                        }
                        stage.show();
                        stage.toFront();
                    });
                }
            }
        });
        theTray.add(theTrayIcon);

        aStage.setOnCloseRequest(aEvent -> stage.hide());
    } else {

        aStage.setOnCloseRequest(aEvent -> shutdown());
    }

    aStage.setMaximized(true);
    aStage.show();
}

From source file:application.Main.java

@Override
public void start(Stage primaryStage) throws InterruptedException {

    System.out.println(applicationTitle + " initialized!");

    // define working variables
    String text = "";
    Boolean terminateExecution = Boolean.FALSE;

    // does the specified FXML XML file path exist?
    String fxmlXmlFileFullPath = fxmlPath.equals("") ? fxmlXmlFileName : fxmlPath + "/" + fxmlXmlFileName;
    URL urlXml = Main.class.getResource(fxmlXmlFileFullPath);
    if (urlXml == null) {
        terminateExecution = Boolean.TRUE;
        text = Main.class.getName() + ": FXML XML File '" + fxmlXmlFileFullPath
                + "' not found in resource path!";
        GenericUtilities.outputToSystemErr(text, systemErrorsDesired);
    }/*from   ww  w .  j a  v  a2  s.com*/

    // does the specified FXML CSS file path exist?
    String fxmlCssFileFullPath = fxmlPath.equals("") ? fxmlCssFileName : fxmlPath + "/" + fxmlCssFileName;
    URL urlCss = Main.class.getResource(fxmlCssFileFullPath);
    if (urlCss == null) {
        terminateExecution = Boolean.TRUE;
        text = Main.class.getName() + ": FXML CSS File '" + fxmlCssFileFullPath
                + "' not found in resource path!";
        GenericUtilities.outputToSystemErr(text, systemErrorsDesired);
    }

    if (terminateExecution) {
        text = Main.class.getName() + ": Execution terminated due to errors!";
        GenericUtilities.outputToSystemErr(text, systemErrorsDesired);
        GenericUtilities.outputToSystemOut(text, systemOutputDesired);
        return;
    }

    // initialize and display the primary stage
    try {
        // load the FXML file and instantiate the "root" object
        FXMLLoader fxmlLoader = new FXMLLoader(urlXml);
        Parent root = (Parent) fxmlLoader.load();

        controller = (FracKhemGUIController) fxmlLoader.getController();
        controller.setStage(primaryStage);
        controller.setInitStageTitle(applicationTitle);

        // initialize and display the stage
        createTrayIcon(primaryStage);
        firstTime = Boolean.TRUE;
        Platform.setImplicitExit(Boolean.FALSE);

        Scene scene = new Scene(root);
        scene.getStylesheets().add(urlCss.toExternalForm());
        primaryStage.setScene(scene);
        primaryStage.setTitle(applicationTitle + " - " + controller.getPropFileCurrFileVal());
        primaryStage.show();
    } catch (Exception e) {
        text = ExceptionUtils.getStackTrace(e);
        GenericUtilities.outputToSystemErr(text, systemErrorsDesired);
        text = Main.class.getName() + ": Execution terminated due to errors!";
        GenericUtilities.outputToSystemErr(text, systemErrorsDesired);
        GenericUtilities.outputToSystemOut(text, systemOutputDesired);
    }

}