Example usage for javafx.stage Stage showAndWait

List of usage examples for javafx.stage Stage showAndWait

Introduction

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

Prototype

public void showAndWait() 

Source Link

Document

Shows this stage and waits for it to be hidden (closed) before returning to the caller.

Usage

From source file:com.helegris.szorengeteg.ui.forms.TopicFormView.java

private void bulkAddAudio() {
    if (sortedRows.size() > 0) {
        Stage stage = new Stage();
        BulkAddAudioView view = new BulkAddAudioView(sortedRows);
        stage.setScene(new SceneStyler().createScene(view, SceneStyler.Style.TOPIC_LIST));
        stage.setTitle(Messages.msg("form.bulk_add_something", Messages.msg("form.audio")));
        stage.initModality(Modality.APPLICATION_MODAL);
        stage.initOwner(getScene().getWindow());
        stage.showAndWait();

        if (view.isOk()) {
            view.getFiles().entrySet().stream().forEach((entry) -> {
                ((RowForCard) sortedRows.get(entry.getKey())).setAudioFile(entry.getValue());
            });/*from  ww  w.  ja  va 2  s  .  c om*/
            view.getAudio().entrySet().stream().forEach((entry) -> {
                ((RowForCard) sortedRows.get(entry.getKey())).setAudio(entry.getValue());
            });
        }
    } else {
        Alert alert = new Alert(Alert.AlertType.WARNING);
        alert.setTitle(Messages.msg("alert.error"));
        alert.setHeaderText(Messages.msg("alert.no_words_audio"));
        alert.setContentText(Messages.msg("alert.add_words"));
        alert.showAndWait();
    }
}

From source file:com.helegris.szorengeteg.ui.forms.TopicFormView.java

private void bulkAddImages() {
    if (sortedRows.size() > 0) {
        Stage stage = new Stage();
        BulkAddImagesView view = new BulkAddImagesView(sortedRows);
        stage.setScene(new SceneStyler().createScene(view, SceneStyler.Style.TOPIC_LIST));
        stage.setTitle(Messages.msg("form.bulk_add_something", Messages.msg("form.image")));
        stage.initModality(Modality.APPLICATION_MODAL);
        stage.initOwner(getScene().getWindow());
        stage.showAndWait();

        if (view.isOk()) {
            view.getFiles().entrySet().stream().forEach((entry) -> {
                ((RowForCard) sortedRows.get(entry.getKey())).setImageFile(entry.getValue());
            });/*from  w w  w  . j a  v a2 s. c  o m*/
            view.getImages().entrySet().stream().forEach((entry) -> {
                ((RowForCard) sortedRows.get(entry.getKey())).setImage(entry.getValue());
            });
        }
    } else {
        Alert alert = new Alert(Alert.AlertType.WARNING);
        alert.setTitle(Messages.msg("alert.error"));
        alert.setHeaderText(Messages.msg("alert.no_words_image"));
        alert.setContentText(Messages.msg("alert.add_words"));
        alert.showAndWait();
    }
}

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

@FXML
public void openAboutDialog() {
    logger.info("Open the about dialog");
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(getClass().getResource("/com/properned/gui/aboutFrame.fxml"));
    loader.setResources(MessageReader.getInstance().getBundle());

    try {/*from   www.  j  a v a 2  s .c o  m*/
        loader.load();

        Parent root = loader.getRoot();

        Stage modalDialog = new Stage(StageStyle.UTILITY);
        modalDialog.initOwner(Properned.getInstance().getPrimaryStage());
        modalDialog.setTitle(MessageReader.getInstance().getMessage("menu.help.about"));
        modalDialog.setResizable(false);

        Scene scene = new Scene(root);
        scene.getStylesheets().add("/com/properned/style/application.css");

        modalDialog.setScene(scene);

        modalDialog.showAndWait();
    } catch (IOException e) {
        Properned.getInstance().showError(MessageReader.getInstance().getMessage("error.openFrame"), e);
    }
}

From source file:mesclasses.view.TimetableController.java

private Cours openEditDialog(Cours coursToEdit, Cours originalCours) {
    try {/*from   w w  w .  j a  v  a2  s  .c  o  m*/
        // Load the fxml file and create a new stage for the popup dialog.
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(MainApp.class.getResource(Constants.COURS_EDIT_DIALOG));
        AnchorPane page = (AnchorPane) loader.load();

        // Create the dialog Stage.
        Stage dialogStage = new Stage();
        dialogStage.setTitle("Edition d'un cours");
        dialogStage.initModality(Modality.WINDOW_MODAL);
        dialogStage.initOwner(primaryStage);
        Scene scene = new Scene(page);
        dialogStage.setScene(scene);

        // Set the person into the controller.
        CoursEditDialogController controller = loader.getController();
        controller.setDialogStage(dialogStage);
        controller.setCours(coursToEdit, false);

        // Show the dialog and wait until the user closes it
        dialogStage.showAndWait();
        int status = controller.getStatus();
        if (status >= 0) {
            //update/cancel
            return controller.getCours();
        } else {
            //delete
            getPane(coursToEdit).getChildren().remove(coursToEdit.getEvent());
            int seances = model.delete(originalCours).size();
            ModalUtil.info("Sances modifies", seances + " sances ont t modifies");
            return null;
        }

    } catch (IOException e) {
        notif(e);
        return null;
    }
}

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

/**
 * Creates a new DXML project and has the user set it up, then places it in
 * the tab.//from   w w w  .  j  a v  a  2s  .  c  o m
 */
public void newDXMLProject() {
    // Create the wizard and wait for the result.
    DXMLProjectCreatorController controller = SpringContainer.getContext()
            .getBean(DXMLProjectCreatorController.class);

    Scene scene = new Scene(controller.getRootPane());
    scene.getStylesheets().add(cssPath);

    Stage stage = new Stage();
    stage.setTitle("DXML Project Setup Wizard");
    stage.setResizable(false);
    stage.initModality(Modality.WINDOW_MODAL);
    stage.initOwner(coreController.getStage());
    stage.setScene(scene);
    controller.setStage(stage); // Required for it to be able to close properly.
    controller.setParentStage(coreController.getStage()); // Required as well to block input if browsing for files.
    stage.showAndWait();

    // If the user finished the work, get the DXML file.
    if (!controller.wasClosedByUser()) {
        DXML dxmlData = controller.getDxmlData();
        // The file must also be valid. This should not ever be false unless there is a coding error.
        if (dxmlData.isValidDXMLFile()) {
            // Create it on the disk.
            DXMLCreationStatus status = dxmlData.createOnDisk();

            // If the status shows success, add it to the view.
            switch (status) {
            case SUCCESS:
                // Since it succeeded, open up the project now.
                String path = dxmlData.getProjectInfo().getProjectLocationPath() + File.separator;
                path += dxmlData.getCompilation().getFilename() + File.separator;
                path += dxmlData.getCompilation().getFilename() + ".dxml"; // TODO - support any case extension.
                openDXMLProject(Paths.get(path));
                break;
            case ALREADY_EXISTS:
                log.warn("DXML project already exists at the specified location. Aborting.");
                break;
            case FOLDER_CREATION_FAILURE:
                log.warn("Unable to create directory for the project. Are your permissions correct? Aborting.");
                break;
            case DXML_FILE_EXISTS:
                log.warn("DXML file already exists at location, aborting to prevent potential overwrite.");
                break;
            case DXML_FILE_CREATION_FAILURE:
                log.warn("Unable to create DXML file at location, are your permissions correct? Aborting.");
                break;
            case XML_MARSHALL_ERROR:
                log.warn("Unable to create the .dxml file. Are your file permissions correct? Aborting.");
                break;
            case FAILED:
                log.warn("Unable to create the necessary DXML file/folder resources at the provided location.");
                break;
            case INVALID_DXML_DATA:
            case BAD_PROJECT_PATH:
                log.warn("DXML project has corrupt data. Contact a developer, Aborting [Reason: {}].",
                        status.name());
                break;
            default:
                throw new DXMLException(
                        "DXML status for disk creation returned an unexpected enumeration. Contact a developer.");
            }
        } else {
            throw new DXMLException(
                    "DXML Wizard has not properly generated a proper file. Please contact a developer.");
        }
    } else {
        log.info("DXML project cancelled by user.");
    }
}

From source file:com.helegris.szorengeteg.ui.forms.TopicFormView.java

/**
 * Handles click events on the table. When clicking on the "image" or
 * "audio" column of a word, it opens a new stage for editing them.
 *
 * @param event//from   w ww . ja v a 2s. co m
 */
private void tableClick(MouseEvent event) {
    if (!rows.isEmpty() && !tableView.getSelectionModel().getSelectedCells().isEmpty()) {
        TablePosition position = tableView.getSelectionModel().getSelectedCells().get(0);
        if (colImage.equals(position.getTableColumn())) {
            int index = position.getRow();
            RowForCard row = (RowForCard) sortedRows.get(index);
            Image currentImage = row.getImageView().getImage();
            ImagePopup imagePopup = new ImagePopup(currentImage);
            Stage stage = new Stage();
            stage.setScene(new SceneStyler().createScene(imagePopup, SceneStyler.Style.TOPIC_LIST));
            stage.setTitle(Messages.msg("form.set_image_of_word", row.getTxtWord().getText()));
            stage.initModality(Modality.APPLICATION_MODAL);
            stage.initOwner(tableView.getScene().getWindow());
            stage.setResizable(false);
            tableView.getSelectionModel().clearSelection();

            stage.showAndWait();
            if (imagePopup.isOk()) {
                Image rowImage = imagePopup.getFinalImage();
                File cardImageFile = imagePopup.getFile();
                if (rowImage != null && cardImageFile != null) {
                    row.setImageFile(cardImageFile);
                    row.setImage(rowImage);
                } else if (rowImage == null) {
                    row.setImage(DefaultImage.getInstance());
                }
            }
        } else if (colAudio.equals(position.getTableColumn())) {
            int index = position.getRow();
            RowForCard row = (RowForCard) sortedRows.get(index);
            AudioPopup audioPopup = new AudioPopup(row.getAudioIcon().getAudio());
            Stage stage = new Stage();
            stage.setScene(new SceneStyler().createScene(audioPopup, SceneStyler.Style.TOPIC_LIST));
            stage.setTitle(Messages.msg("form.set_audio_of_word", row.getTxtWord().getText()));
            stage.initModality(Modality.APPLICATION_MODAL);
            stage.initOwner(tableView.getScene().getWindow());
            stage.setResizable(false);
            tableView.getSelectionModel().clearSelection();

            stage.showAndWait();
            if (audioPopup.isOk()) {
                File audioFile = audioPopup.getFile();
                row.setAudioFile(audioFile);
                row.setAudio(audioPopup.getFinalAudio());
            }
        }
    }
}

From source file:main.Content.java

public boolean showInputDialog(Activity aktivitet) {
    try {//from   w  w  w.  j av  a 2s . c o m
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(Main.class.getResource("view/InputDialog.fxml"));
        AnchorPane page = (AnchorPane) loader.load();

        Stage dialogStage = new Stage();
        dialogStage.setTitle("Data Input");
        dialogStage.initModality(Modality.WINDOW_MODAL);
        dialogStage.initOwner(mainApp.getPrimaryStage());
        Scene scene = new Scene(page);
        dialogStage.setScene(scene);

        InputDialogController controller = loader.getController();
        controller.setListData(data);
        controller.setDialogStage(dialogStage);
        controller.setData(aktivitet);

        dialogStage.showAndWait();

        return controller.isSaveClicked();
    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        return false;
    }
}

From source file:de.serverfrog.pw.ui.MainViewController.java

@FXML
public void onLoadButton(ActionEvent ae) {
    try {//from   ww  w  . jav a2 s  .  c o  m
        if (this.masterPasswordField.getText().isEmpty()) {
            return;
        }
        Stage dialog = new Stage(StageStyle.UTILITY);
        dialog.initModality(Modality.APPLICATION_MODAL);
        FXMLLoader fXMLLoader = new FXMLLoader(
                getClass().getResource("/de/serverfrog/pw/ui/ConfigLoadDialog.fxml"));
        Parent root = fXMLLoader.<Parent>load();
        ConfigLoadDialogController controller = fXMLLoader.<ConfigLoadDialogController>getController();
        try {
            controller.prepareList(masterPasswordField.getText());
        } catch (IOException exception) {
            this.messageField.setText(exception.getMessage());
            return;
        }
        this.messageField.setText("");
        Scene scene = new Scene(root);
        dialog.setScene(scene);
        controller.setStage(dialog);
        dialog.showAndWait();
        setConfiguration(controller.getConfig());
    } catch (IOException ex) {
        Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

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

@FXML
public void openLocaleDialog() {
    logger.info("Open the locale dialog");

    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(getClass().getResource("/com/properned/gui/localeFrame.fxml"));
    loader.setResources(MessageReader.getInstance().getBundle());

    try {// w  w w. j  av  a 2s  .c  o m
        loader.load();

        Parent root = loader.getRoot();

        Stage modalDialog = new Stage(StageStyle.UNIFIED);
        modalDialog.initModality(Modality.APPLICATION_MODAL);
        modalDialog.initOwner(Properned.getInstance().getPrimaryStage());
        modalDialog.setTitle(MessageReader.getInstance().getMessage("manageLocale.title"));
        modalDialog.setResizable(true);
        modalDialog.getIcons().add(new Image("/com/properned/style/icon/icon_16.png"));

        Scene scene = new Scene(root);
        scene.getStylesheets().add("/com/properned/style/application.css");

        modalDialog.setScene(scene);

        modalDialog.showAndWait();
    } catch (IOException e) {
        Properned.getInstance().showError(MessageReader.getInstance().getMessage("error.openFrame"), e);
    }
}

From source file:tachyon.view.ProjectProperties.java

public ProjectProperties(JavaProject project, Window w) {
    this.project = project;
    stage = new Stage();
    stage.initOwner(w);/*from   www .  j  a v  a  2s  .  c  om*/
    stage.initModality(Modality.APPLICATION_MODAL);
    stage.setWidth(600);
    stage.setTitle("Project Properties - " + project.getProjectName());
    stage.getIcons().add(tachyon.Tachyon.icon);
    stage.setResizable(false);
    HBox mai, libs, one, two, thr, fou;
    ListView<String> compileList, runtimeList;
    Button compileAdd, compileRemove, preview, selectIm, runtimeAdd, runtimeRemove;
    TextField iconField;
    stage.setScene(new Scene(new VBox(5, pane = new TabPane(
            new Tab("Library Settings",
                    box1 = new VBox(15,
                            libs = new HBox(10, new Label("External Libraries"), libsView = new ListView<>(),
                                    new VBox(5, addJar = new Button("Add Jar"),
                                            removeJar = new Button("Remove Jar"))))),
            new Tab("Program Settings",
                    new ScrollPane(box2 = new VBox(15, one = new HBox(10, new Label("Main-Class"),
                            mainClass = new TextField(project.getMainClassName()),
                            select = new Button("Select")),
                            two = new HBox(10, new Label("Compile-Time Arguments"),
                                    compileList = new ListView<>(),
                                    new VBox(5, compileAdd = new Button("Add Argument"),
                                            compileRemove = new Button("Remove Argument")))))),
            new Tab("Deployment Settings",
                    box3 = new VBox(15, thr = new HBox(10, new Label("Icon File"),
                            iconField = new TextField(project.getFileIconPath()),
                            preview = new Button("Preview Image"), selectIm = new Button("Select Icon")),
                            fou = new HBox(10, new Label("Runtime Arguments"), runtimeList = new ListView<>(),
                                    new VBox(5, runtimeAdd = new Button("Add Argument"),
                                            runtimeRemove = new Button("Remove Argument")))))),
            new VBox(15, mai = new HBox(10, cancel = new Button("Cancel"), confirm = new Button("Confirm"))))));
    if (applyCss.get()) {
        stage.getScene().getStylesheets().add(css);
    }
    for (Tab b : pane.getTabs()) {
        b.setClosable(false);
    }
    mainClass.setPromptText("Main-Class");
    box1.setPadding(new Insets(5, 10, 5, 10));
    mai.setAlignment(Pos.CENTER_RIGHT);
    mai.setPadding(box1.getPadding());
    libs.setAlignment(Pos.CENTER);
    one.setAlignment(Pos.CENTER);
    two.setAlignment(Pos.CENTER);
    thr.setAlignment(Pos.CENTER);
    fou.setAlignment(Pos.CENTER);
    box1.setAlignment(Pos.CENTER);
    box2.setPadding(box1.getPadding());
    box2.setAlignment(Pos.CENTER);
    box3.setPadding(box1.getPadding());
    box3.setAlignment(Pos.CENTER);
    mainClass.setEditable(false);
    mainClass.setPrefWidth(200);
    for (JavaLibrary lib : project.getAllLibs()) {
        libsView.getItems().add(lib.getBinaryAbsolutePath());
    }
    for (String sa : project.getCompileTimeArguments().keySet()) {
        compileList.getItems().add(sa + ":" + project.getCompileTimeArguments().get(sa));
    }
    for (String sa : project.getRuntimeArguments()) {
        runtimeList.getItems().add(sa);
    }
    compileAdd.setOnAction((e) -> {
        Dialog<Pair<String, String>> dialog = new Dialog<>();
        dialog.setTitle("Compiler Argument");
        dialog.initOwner(stage);
        dialog.setHeaderText("Entry the argument");

        ButtonType loginButtonType = new ButtonType("Done", ButtonData.OK_DONE);
        dialog.getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL);

        GridPane grid = new GridPane();
        grid.setHgap(10);
        grid.setVgap(10);
        grid.setPadding(new Insets(20, 150, 10, 10));

        TextField username = new TextField();
        username.setPromptText("Key");
        TextField password = new TextField();
        password.setPromptText("Value");

        grid.add(new Label("Key:"), 0, 0);
        grid.add(username, 1, 0);
        grid.add(new Label("Value:"), 0, 1);
        grid.add(password, 1, 1);

        Node loginButton = dialog.getDialogPane().lookupButton(loginButtonType);
        loginButton.setDisable(true);

        username.textProperty().addListener((observable, oldValue, newValue) -> {
            loginButton.setDisable(newValue.trim().isEmpty());
        });

        dialog.getDialogPane().setContent(grid);

        Platform.runLater(() -> username.requestFocus());

        dialog.setResultConverter(dialogButton -> {
            if (dialogButton == loginButtonType) {
                return new Pair<>(username.getText(), password.getText());
            }
            return null;
        });

        Optional<Pair<String, String>> result = dialog.showAndWait();
        if (result.isPresent()) {
            compileList.getItems().add(result.get().getKey() + ":" + result.get().getValue());
        }
    });
    compileRemove.setOnAction((e) -> {
        if (compileList.getSelectionModel().getSelectedItem() != null) {
            compileList.getItems().remove(compileList.getSelectionModel().getSelectedItem());
        }
    });
    runtimeAdd.setOnAction((e) -> {
        TextInputDialog dia = new TextInputDialog();
        dia.setTitle("Add Runtime Argument");
        dia.setHeaderText("Enter an argument");
        dia.initOwner(stage);
        Optional<String> res = dia.showAndWait();
        if (res.isPresent()) {
            runtimeList.getItems().add(res.get());
        }
    });
    runtimeRemove.setOnAction((e) -> {
        if (runtimeList.getSelectionModel().getSelectedItem() != null) {
            runtimeList.getItems().remove(runtimeList.getSelectionModel().getSelectedItem());
        }
    });
    preview.setOnAction((e) -> {
        if (!iconField.getText().isEmpty()) {
            if (iconField.getText().endsWith(".ico")) {
                List<BufferedImage> read = new ArrayList<>();
                try {
                    read.addAll(ICODecoder.read(new File(iconField.getText())));
                } catch (IOException ex) {
                }
                if (read.size() >= 1) {
                    Image im = SwingFXUtils.toFXImage(read.get(0), null);
                    Stage st = new Stage();
                    st.initOwner(stage);
                    st.initModality(Modality.APPLICATION_MODAL);
                    st.setTitle("Icon Preview");
                    st.getIcons().add(Tachyon.icon);
                    st.setScene(new Scene(new BorderPane(new ImageView(im))));
                    if (applyCss.get()) {
                        st.getScene().getStylesheets().add(css);
                    }
                    st.showAndWait();
                }
            } else if (iconField.getText().endsWith(".icns")) {
                try {
                    BufferedImage ima = Imaging.getBufferedImage(new File(iconField.getText()));
                    if (ima != null) {
                        Image im = SwingFXUtils.toFXImage(ima, null);
                        Stage st = new Stage();
                        st.initOwner(stage);
                        st.initModality(Modality.APPLICATION_MODAL);
                        st.setTitle("Icon Preview");
                        st.getIcons().add(Tachyon.icon);
                        st.setScene(new Scene(new BorderPane(new ImageView(im))));
                        if (applyCss.get()) {
                            st.getScene().getStylesheets().add(css);
                        }
                        st.showAndWait();
                    }
                } catch (ImageReadException | IOException ex) {
                }
            } else {
                Image im = new Image(new File(iconField.getText()).toURI().toString());
                Stage st = new Stage();
                st.initOwner(stage);
                st.initModality(Modality.APPLICATION_MODAL);
                st.setTitle("Icon Preview");
                st.getIcons().add(Tachyon.icon);
                st.setScene(new Scene(new BorderPane(new ImageView(im))));
                if (applyCss.get()) {
                    st.getScene().getStylesheets().add(css);
                }
                st.showAndWait();
            }
        }
    });
    selectIm.setOnAction((e) -> {
        FileChooser fc = new FileChooser();
        fc.setTitle("Icon File");
        String OS = System.getProperty("os.name").toLowerCase();
        fc.getExtensionFilters().add(new ExtensionFilter("Icon File",
                OS.contains("win") ? getWindowsImageExtensions() : getMacImageExtensions()));
        fc.setSelectedExtensionFilter(fc.getExtensionFilters().get(0));
        File lf = fc.showOpenDialog(stage);
        if (lf != null) {
            iconField.setText(lf.getAbsolutePath());
        }
    });

    addJar.setOnAction((e) -> {
        FileChooser f = new FileChooser();
        f.setTitle("External Libraries");
        f.setSelectedExtensionFilter(new ExtensionFilter("Jar Files", "*.jar"));
        List<File> showOpenMultipleDialog = f.showOpenMultipleDialog(stage);
        if (showOpenMultipleDialog != null) {
            for (File fi : showOpenMultipleDialog) {
                if (!libsView.getItems().contains(fi.getAbsolutePath())) {
                    libsView.getItems().add(fi.getAbsolutePath());
                }
            }
        }
    });

    removeJar.setOnAction((e) -> {
        String selected = libsView.getSelectionModel().getSelectedItem();
        if (selected != null) {
            libsView.getItems().remove(selected);
        }
    });

    select.setOnAction((e) -> {
        List<String> all = getAll();
        ChoiceDialog<String> di = new ChoiceDialog<>(project.getMainClassName(), all);
        di.setTitle("Select Main Class");
        di.initOwner(stage);
        di.setHeaderText("Select A Main Class");
        Optional<String> show = di.showAndWait();
        if (show.isPresent()) {
            mainClass.setText(show.get());
        }
    });
    cancel.setOnAction((e) -> {
        stage.close();
    });
    confirm.setOnAction((e) -> {
        project.setMainClassName(mainClass.getText());
        project.setFileIconPath(iconField.getText());
        project.setRuntimeArguments(runtimeList.getItems());
        HashMap<String, String> al = new HashMap<>();
        for (String s : compileList.getItems()) {
            String[] spl = s.split(":");
            al.put(spl[0], spl[1]);
        }
        project.setCompileTimeArguments(al);
        project.setAllLibs(libsView.getItems());
        stage.close();
    });
}