Example usage for javafx.stage Stage setOnCloseRequest

List of usage examples for javafx.stage Stage setOnCloseRequest

Introduction

In this page you can find the example usage for javafx.stage Stage setOnCloseRequest.

Prototype

public final void setOnCloseRequest(EventHandler<WindowEvent> value) 

Source Link

Usage

From source file:qupath.lib.gui.panels.survival.KaplanMeierDisplay.java

private Stage createStage(final Window parent, final String title) {
    Stage frame = new Stage();
    if (parent != null)
        frame.initOwner(parent);//from   ww w .  j av  a2  s  . co m
    frame.setTitle("Kaplan Meier: " + title);

    frame.setOnCloseRequest(e -> {
        if (hierarchy != null)
            hierarchy.removePathObjectListener(KaplanMeierDisplay.this);
        panelParams.removeParameterChangeListener(KaplanMeierDisplay.this);
        frame.hide();
    });

    Scene scene = new Scene(getView(), 600, 400);
    frame.setScene(scene);
    frame.setMinWidth(600);
    frame.setMinHeight(400);
    return frame;
}

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();// ww  w .j av a 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();/*www .  j  a v  a2 s  . c o 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.deicos.lince.Initializer.java

@Override
public void start(Stage stage) throws Exception {
    /*AppPreloader preloader = new AppPreloader();
    preloader.start(stage);*//*from   w  w w  . jav  a  2s  . c  om*/
    notifyPreloader(new Preloader.StateChangeNotification(Preloader.StateChangeNotification.Type.BEFORE_START));
    stage.setTitle(windowTitle);
    //stage.setScene(new Scene(mainLayout));

    Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
    Browser browser = new Browser(BrowserType.HEAVYWEIGHT);
    BrowserView view = new BrowserView(browser);
    //String url = getClass().getClassLoader().getResource("app-lince.html").toString();
    String url = getServerURL();
    browser.loadURL(url);
    String remoteDebuggingURL = browser.getRemoteDebuggingURL();
    logger.info("==============================================================================");
    logger.info("   Remote debug   :" + remoteDebuggingURL);
    logger.info("   Remote uri     :" + url);
    logger.info("==============================================================================");
    Scene scene = new Scene(new BorderPane(view), screenBounds.getWidth() - 20, screenBounds.getHeight() - 40);
    stage.setScene(scene);
    stage.setResizable(true);
    stage.centerOnScreen();
    stage.show();
    stage.setOnCloseRequest(this);
}

From source file:io.bitsquare.app.gui.BitsquareApp.java

@Override
public void start(Stage primaryStage) throws IOException {
    bitsquareAppModule = new BitsquareAppModule(env, primaryStage);
    injector = Guice.createInjector(bitsquareAppModule);
    injector.getInstance(GuiceControllerFactory.class).setInjector(injector);

    // route uncaught exceptions to a user-facing dialog

    Thread.currentThread().setUncaughtExceptionHandler(
            (thread, throwable) -> Popups.handleUncaughtExceptions(Throwables.getRootCause(throwable)));

    // initialize the application data directory (if necessary)

    initAppDir(env.getRequiredProperty(APP_DATA_DIR_KEY));

    // load and apply any stored settings

    User user = injector.getInstance(User.class);
    AccountSettings accountSettings = injector.getInstance(AccountSettings.class);
    Persistence persistence = injector.getInstance(Persistence.class);
    persistence.init();/*from   ww  w . j  a va2s.c o  m*/

    User persistedUser = (User) persistence.read(user);
    user.applyPersistedUser(persistedUser);

    accountSettings.applyPersistedAccountSettings(
            (AccountSettings) persistence.read(accountSettings.getClass().getName()));

    // load the main view and create the main scene

    ViewLoader viewLoader = injector.getInstance(ViewLoader.class);
    ViewLoader.Item loaded = viewLoader.load(Navigation.Item.MAIN.getFxmlUrl(), false);

    Scene scene = new Scene((Parent) loaded.view, 1000, 600);
    scene.getStylesheets().setAll("/io/bitsquare/gui/bitsquare.css", "/io/bitsquare/gui/images.css");

    // configure the system tray

    SystemTray systemTray = new SystemTray(primaryStage, this::stop);
    primaryStage.setOnCloseRequest(e -> stop());
    scene.setOnKeyReleased(keyEvent -> {
        // For now we exit when closing/quit the app.
        // Later we will only hide the window (systemTray.hideStage()) and use the exit item in the system tray for
        // shut down.
        if (new KeyCodeCombination(KeyCode.W, KeyCombination.SHORTCUT_DOWN).match(keyEvent)
                || new KeyCodeCombination(KeyCode.Q, KeyCombination.SHORTCUT_DOWN).match(keyEvent))
            stop();
    });

    // configure the primary stage

    primaryStage.setTitle(env.getRequiredProperty(APP_NAME_KEY));
    primaryStage.setScene(scene);
    primaryStage.setMinWidth(75);
    primaryStage.setMinHeight(50);

    // on windows the title icon is also used as task bar icon in a larger size
    // on Linux no title icon is supported but also a large task bar icon is derived form that title icon
    String iconPath;
    if (Utilities.isOSX())
        iconPath = ImageUtil.isRetina() ? "/images/window_icon@2x.png" : "/images/window_icon.png";
    else if (Utilities.isWindows())
        iconPath = "/images/task_bar_icon_windows.png";
    else
        iconPath = "/images/task_bar_icon_linux.png";

    if (iconPath != null)
        primaryStage.getIcons().add(new Image(getClass().getResourceAsStream(iconPath)));

    // make the UI visible

    primaryStage.show();
}

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";
    }/*from   w  w  w .  java 2  s  . c o  m*/
    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:net.rptools.tokentool.client.TokenTool.java

@Override
public void start(Stage primaryStage) throws IOException {
    stage = primaryStage;/*from   w  w  w  .  j  ava 2  s .c  o  m*/
    setUserAgentStylesheet(STYLESHEET_MODENA); // Setting the style back to the new Modena
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(AppConstants.TOKEN_TOOL_FXML),
            ResourceBundle.getBundle(AppConstants.TOKEN_TOOL_BUNDLE));
    root = fxmlLoader.load();
    tokentool_Controller = (TokenTool_Controller) fxmlLoader.getController();

    Scene scene = new Scene(root);
    primaryStage.setTitle(I18N.getString("TokenTool.stage.title"));
    primaryStage.getIcons().add(new Image(getClass().getResourceAsStream(AppConstants.TOKEN_TOOL_ICON)));
    primaryStage.setScene(scene);

    primaryStage.widthProperty().addListener((obs, oldVal, newVal) -> {
        if (Double.isNaN(oldVal.doubleValue()))
            return;

        deltaX += newVal.doubleValue() - oldVal.doubleValue();

        // Only adjust on even width adjustments
        if (deltaX > 1 || deltaX < -1) {
            if (deltaX % 2 == 0) {
                tokentool_Controller.updatePortraitLocation(deltaX, 0);
                deltaX = 0;
            } else {
                tokentool_Controller.updatePortraitLocation(deltaX - 1, 0);
                deltaX = 1;
            }
        }
    });

    primaryStage.heightProperty().addListener((obs, oldVal, newVal) -> {
        if (Double.isNaN(oldVal.doubleValue()))
            return;

        deltaY += newVal.doubleValue() - oldVal.doubleValue();

        // Only adjust on even width adjustments
        if (deltaY > 1 || deltaY < -1) {
            if (deltaY % 2 == 0) {
                tokentool_Controller.updatePortraitLocation(0, deltaY);
                deltaY = 0;
            } else {
                tokentool_Controller.updatePortraitLocation(0, deltaY - 1);
                deltaY = 1;
            }
        }
    });

    primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
        @Override
        public void handle(WindowEvent event) {
            tokentool_Controller.exitApplication();
        }
    });

    // Load all the overlays into the treeview
    tokentool_Controller.updateOverlayTreeview(overlayTreeItems);

    // Restore saved settings
    AppPreferences.restorePreferences(tokentool_Controller);

    // Add recent list to treeview
    tokentool_Controller.updateOverlayTreeViewRecentFolder(true);

    // Set the Overlay Options accordion to be default open view
    tokentool_Controller.expandOverlayOptionsPane(true);

    primaryStage.show();

    // Finally, update token preview image after everything is done loading
    Platform.runLater(() -> tokentool_Controller.updateTokenPreviewImageView());
}

From source file:ui.main.MainViewController.java

private void createNewConversation() {
    //this method displays the new convesation create view
    try {//  w  w w .  j  a v  a  2  s  .c  om
        //default configuration and initialization of the form
        Parent root = FXMLLoader
                .load(getClass().getClassLoader().getResource("ui/conversation/ConversationView.fxml"));

        Scene scene = new Scene(root);

        Stage stage = new Stage();

        stage.setScene(scene);
        stage.show();

        stage.setResizable(false);
        stage.setTitle("IMP : Conversation Creation");

        final Stage mainStage = (Stage) presence.getScene().getWindow();
        stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
            @Override
            public void handle(WindowEvent event) {
                showConversations();
            }
        });

    } catch (IOException ex) {
        Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:jp.co.heppokoact.autocapture.FXMLDocumentController.java

@FXML
private void areaButtonClicked(ActionEvent event) throws IOException {
    System.out.println("areaButtonClicked");

    // ??//from w  ww.java  2  s .  c  om
    Stage transparentStage = createTransparentStage();

    // ?????
    Scene scene = transparentStage.getScene();
    scene.setOnMousePressed(e -> {
        // 
        dragStartX = (int) e.getScreenX();
        dragStartY = (int) e.getScreenY();
        // ??
        areaRect = new Rectangle(e.getX(), e.getY(), 0, 0);
        areaRect.setStroke(Color.RED);
        areaRect.setStrokeWidth(1.0);
        areaRect.setFill(Color.TRANSPARENT);
        ((Pane) scene.getRoot()).getChildren().add(areaRect);
    });

    // ?????
    scene.setOnMouseDragged(e -> {
        // ??????
        areaRect.setWidth(e.getScreenX() - dragStartX);
        areaRect.setHeight(e.getScreenY() - dragStartY);

    });

    // ?????
    scene.setOnMouseReleased(e -> {
        // ?
        areaStartX.set(dragStartX);
        areaStartY.set(dragStartY);
        areaEndX.set((int) e.getScreenX());
        areaEndY.set((int) e.getScreenY());
        // ??
        transparentStage.close();
    });

    // ??????
    transparentStage.setOnCloseRequest(e -> {
        // ?????
        dragStartX = 0;
        dragStartY = 0;
        areaRect = null;
    });

    transparentStage.show();
}

From source file:eu.over9000.skadi.ui.MainWindow.java

@Override
public void start(final Stage stage) throws Exception {
    this.stage = stage;

    this.detailPane = new ChannelDetailPane(this);

    this.bp = new BorderPane();
    this.sp = new SplitPane();
    this.sb = new StatusBar();

    this.setupTable();
    this.setupToolbar(stage);

    this.sp.getItems().add(this.table);

    this.bp.setTop(this.tb);
    this.bp.setCenter(this.sp);
    this.bp.setBottom(this.sb);

    final Scene scene = new Scene(this.bp, 1280, 720);
    scene.getStylesheets().add(this.getClass().getResource("/styles/copyable-label.css").toExternalForm());
    scene.setOnDragOver(event -> {//from www.j  av  a 2s  .c o m
        final Dragboard d = event.getDragboard();
        if (d.hasUrl() || d.hasString()) {
            event.acceptTransferModes(TransferMode.COPY);
        } else {
            event.consume();
        }
    });
    scene.setOnDragDropped(event -> {
        final Dragboard d = event.getDragboard();
        boolean success = false;
        if (d.hasUrl()) {
            final String user = StringUtil.extractUsernameFromURL(d.getUrl());
            if (user != null) {
                success = this.channelHandler.addChannel(user, this.sb);
            } else {
                this.sb.setText("dragged url is no twitch stream");
            }
        } else if (d.hasString()) {
            success = this.channelHandler.addChannel(d.getString(), this.sb);
        }
        event.setDropCompleted(success);
        event.consume();

    });

    stage.setTitle("Skadi");
    stage.getIcons().add(new Image(this.getClass().getResourceAsStream("/icons/skadi.png")));
    stage.setScene(scene);
    stage.show();

    stage.iconifiedProperty().addListener((obs, oldV, newV) -> {
        if (this.currentState.isMinimizeToTray()) {
            if (newV) {
                stage.hide();
            }
        }
    });
    stage.setOnCloseRequest(event -> Platform.exit());

    this.bindColumnWidths();

}