Example usage for javafx.stage WindowEvent WINDOW_CLOSE_REQUEST

List of usage examples for javafx.stage WindowEvent WINDOW_CLOSE_REQUEST

Introduction

In this page you can find the example usage for javafx.stage WindowEvent WINDOW_CLOSE_REQUEST.

Prototype

EventType WINDOW_CLOSE_REQUEST

To view the source code for javafx.stage WindowEvent WINDOW_CLOSE_REQUEST.

Click Source Link

Document

This event is delivered to a window when there is an external request to close that window.

Usage

From source file:dpfmanager.shell.modules.messages.MessagesModule.java

private void closeNow() {
    Platform.runLater(new Runnable() {
        @Override/*from  w w w .  j a v a 2 s  . com*/
        public void run() {
            GuiWorkbench.getMyStage()
                    .fireEvent(new DpfCloseEvent(GuiWorkbench.getMyStage(), WindowEvent.WINDOW_CLOSE_REQUEST));
        }
    });
}

From source file:de.micromata.mgc.javafx.ControllerService.java

public <M, C extends AbstractModelController<M>> C loadAsDialog(AbstractMainWindow<?> mainWindow,
        Class<C> controllerClass, String dialogTitle) {
    Pair<Pane, C> pair = loadControllerControl(controllerClass, Pane.class, mainWindow);
    Stage stage = new Stage();
    stage.addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, e -> {
        stage.hide();/*from w  ww.ja  v a2s.  c  o m*/
        e.consume();
    });
    Pane root = pair.getFirst();
    C controller = pair.getSecond();
    Scene s = new Scene(root);//, AbstractConfigDialog.PREF_WIDTH, AbstractConfigDialog.PREF_HEIGHT
    controller.setParent(root);
    controller.setScene(s);
    controller.setStage(stage);
    stage.setScene(s);
    stage.initModality(Modality.APPLICATION_MODAL);
    //stage.setResizable(false);
    stage.setTitle(dialogTitle);
    return controller;
}

From source file:com.ggvaidya.scinames.ui.DatasetImporterController.java

@FXML
private void cancelImport(ActionEvent e) {
    // Close this without resetting the controller.
    // From http://stackoverflow.com/a/29711376/27310

    Stage stage = datasetImporterView.getStage();

    stage.fireEvent(new WindowEvent(stage, WindowEvent.WINDOW_CLOSE_REQUEST));
}

From source file:de.micromata.mgc.javafx.ControllerService.java

public <M, C extends AbstractModelController<M>> C loadAsWindow(AbstractMainWindow<?> mainWindow,
        Class<C> controllerClass, M model, String dialogTitle) {
    Pair<Pane, C> pair = loadControlWithModel(controllerClass, Pane.class, model, mainWindow);
    Stage stage = new Stage();
    stage.addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, e -> {
        stage.hide();/*w  w w .ja  v  a  2s  .c om*/
        e.consume();
    });
    Pane root = pair.getFirst();
    C controller = pair.getSecond();
    Scene s = new Scene(root);//, AbstractConfigDialog.PREF_WIDTH, AbstractConfigDialog.PREF_HEIGHT
    controller.setParent(root);
    controller.setScene(s);
    controller.setStage(stage);
    stage.setScene(s);
    //stage.setResizable(false);
    stage.setTitle(dialogTitle);
    return controller;
}

From source file:ca.wumbo.doommanager.client.controller.CoreController.java

/**
 * The starting point of the application. The Core should pass the first
 * stage (what should be the primary stage) to this method, which will in
 * turn cascade and create all the /*  w ww  .j  a v a  2  s .  c om*/
 * 
 * @param primaryStage
 *       The stage created by the main JavaFX thread at the beginning.
 * 
 * @throws IOException
 *       If there is an error loading the FXML file.
 * 
 * @throws NullPointerException
 *       If the argument is null.
 */
public void start(Stage primaryStage) throws IOException {
    if (primaryStage == null)
        throw new NullPointerException("Passed a null stage to start.");

    // Load the required data into ourselves.
    FXMLLoader loader = new FXMLLoader(Client.class.getResource(fxmlPath));
    loader.setControllerFactory((cls) -> {
        return this;
    });
    loader.load();

    // Add the loaded tab panes into their respective tabs.
    mainTab.setContent(startController.getRootPane());
    fileEditorTab.setContent(fileEditorController.getRootPane());
    mapEditorTab.setContent(mapEditorController.getRootPane());
    textureDatabaseTab.setContent(textureDatabaseController.getRootPane());
    serverBrowserTab.setContent(serverBrowserController.getRootPane());
    ircTab.setContent(ircController.getRootPane());
    optionsTab.setContent(optionsController.getRootPane());
    consoleTab.setContent(consoleController.getRootPane());

    // Set up the scene and stage and display it.
    ClientConfig clientConfig = config.getClientConfig();
    Scene primaryScene = new Scene(rootBorderPane, clientConfig.getStartingWidth(),
            clientConfig.getStartingHeight());
    scene = primaryScene;
    scene.getStylesheets().add(cssPath);
    stage = primaryStage;
    stage.setTitle(applicationTitle + " v" + applicationVersion);
    stage.setMaximized(clientConfig.isStartMaximized());
    stage.setScene(scene);
    stage.show();

    // Start the ticker now that everything is ready to go.
    ticker = new JavaFXTicker((int) (TICRATE_NANO / MS_PER_NANO), event -> tick());
    ticker.start();

    // Set up the network connections by starting the selector.
    if (clientSelector.errorOccured()) {
        Alert alert = new Alert(Alert.AlertType.WARNING, "Unable to request network channels from OS."); // TODO - make less cryptic.
        alert.show();
    } else if (!clientSelector.selectorIsOpen()) {
        Alert alert = new Alert(Alert.AlertType.WARNING, "Unable to open network channels."); // TODO - make less cryptic.
        alert.show();
    }

    // Set up the stage exit handling.
    stage.addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, event -> ticker.stop());

    log.info("Welcome to " + applicationTitle + " v" + applicationVersion + "!");
}

From source file:ca.wumbo.doommanager.client.controller.file.DXMLProjectCreatorController.java

/**
 * Tells the wizard to exit.//ww w  .  j  a va  2  s  .co  m
 */
public void exitWizard() {
    if (stage == null) {
        log.error("Attempting to close a stage without it being set.");
        return;
    }
    stage.fireEvent(new WindowEvent(parentStage, WindowEvent.WINDOW_CLOSE_REQUEST));
}

From source file:ca.wumbo.doommanager.client.controller.CoreController.java

/**
 * Attempts to terminate the application. This will request the main window
 * to close, and the closer listener will take care of any logic needed
 * before shutting down (like asking the user if that's what they want, and
 * to save anything... etc).//from  ww  w.j  a v a  2s  .  co m
 */
public void exit() {
    stage.fireEvent(new WindowEvent(stage, WindowEvent.WINDOW_CLOSE_REQUEST));
}

From source file:de.micromata.mgc.javafx.launcher.gui.AbstractMainWindow.java

@FXML
private void openConfigDialog(ActionEvent event) {
    Pair<Pane, ? extends AbstractConfigDialog<M>> load = loadConfigDialog();
    Pane root = load.getKey();/*from  w  ww. java 2 s .  c om*/
    AbstractConfigDialog<M> controller = load.getValue();
    controller.mainWindow = this;

    controller.getStage().addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, e -> {
        controller.closeDialog();
        e.consume();
    });

    controller.getStage().initModality(Modality.APPLICATION_MODAL);
    controller.getStage().setWidth(800);
    controller.getStage().setHeight(600);

    controller.getStage().setTitle("Configuration");
    controller.getStage().show();

}

From source file:de.bayern.gdi.gui.Controller.java

/**
 * Handler to close the application./*from   w  w w  . j  a v a 2s .  c  om*/
 *
 * @param event The event.
 */
@FXML
protected void handleCloseApp(ActionEvent event) {
    Alert closeDialog = new Alert(Alert.AlertType.CONFIRMATION);
    closeDialog.setTitle(I18n.getMsg("gui.confirm-exit"));
    closeDialog.setContentText(I18n.getMsg("gui.want-to-quit"));
    ButtonType confirm = new ButtonType(I18n.getMsg("gui.exit"));
    ButtonType cancel = new ButtonType(I18n.getMsg("gui.cancel"), ButtonData.CANCEL_CLOSE);
    closeDialog.getButtonTypes().setAll(confirm, cancel);
    Optional<ButtonType> res = closeDialog.showAndWait();
    if (res.isPresent() && res.get() == confirm) {
        logToAppLog(I18n.format("dlc.stop"));
        Stage stage = (Stage) buttonClose.getScene().getWindow();
        stage.fireEvent(new WindowEvent(stage, WindowEvent.WINDOW_CLOSE_REQUEST));
    }
}

From source file:com.properned.application.SystemController.java

@FXML
public void close() {
    logger.info("closed by menu");
    Properned.getInstance().getPrimaryStage().getOnCloseRequest().handle(
            new WindowEvent(Properned.getInstance().getPrimaryStage(), WindowEvent.WINDOW_CLOSE_REQUEST));
    Properned.getInstance().getPrimaryStage().close();
}