Example usage for javafx.stage Modality WINDOW_MODAL

List of usage examples for javafx.stage Modality WINDOW_MODAL

Introduction

In this page you can find the example usage for javafx.stage Modality WINDOW_MODAL.

Prototype

Modality WINDOW_MODAL

To view the source code for javafx.stage Modality WINDOW_MODAL.

Click Source Link

Document

Defines a modal window that block events from being delivered to its entire owner window hierarchy.

Usage

From source file:Main.java

@Override
public void start(Stage stage) {

    Button openURLButton = new Button("Go!");
    openURLButton.setOnAction(e -> {//  w  ww .j  a va2 s.c  om
        HostServices host = getHostServices();
        JSObject js = host.getWebContext();
        if (js == null) {
            Stage s = new Stage(StageStyle.UTILITY);
            s.initModality(Modality.WINDOW_MODAL);
            Label msgLabel = new Label("This is an FX alert!");
            Group root = new Group(msgLabel);
            Scene scene = new Scene(root);
            s.setScene(scene);
            s.setTitle("FX Alert");
            s.show();
        } else {
            js.eval("window.alert('This is a JavaScript alert!')");
        }
    });

    Scene scene = new Scene(openURLButton);
    stage.setScene(scene);
    stage.setTitle("Knowing the Host");
    stage.show();
}

From source file:org.pdfsam.ui.dialog.OverwriteConfirmationDialog.java

@Inject
public OverwriteConfirmationDialog(StylesConfig styles) {
    initModality(Modality.WINDOW_MODAL);
    initStyle(StageStyle.UTILITY);//  w w w.  java2 s.  c o  m
    setResizable(false);
    BorderPane containerPane = new BorderPane();
    containerPane.getStyleClass().addAll(Style.CONTAINER.css());
    containerPane.getStyleClass().addAll("-pdfsam-dialog", "-pdfsam-warning-dialog");
    containerPane.setCenter(dialogContent);
    HBox buttons = new HBox(buildButton(DefaultI18nContext.getInstance().i18n("Overwrite"), true),
            buildButton(DefaultI18nContext.getInstance().i18n("Cancel"), false));
    buttons.getStyleClass().add("-pdfsam-dialog-buttons");
    containerPane.setBottom(buttons);
    Scene scene = new Scene(containerPane);
    scene.getStylesheets().addAll(styles.styles());
    scene.setOnKeyReleased(new HideOnEscapeHandler(this));
    setScene(scene);
}

From source file:mesclasses.objects.LoadWindow.java

public LoadWindow(Stage stage, List<AppTask> tasks) {
    tasks.forEach(t -> {/*  w  w  w  . j a va 2 s . com*/
        services.add(new LoadingService(t));
    });
    dialogStage = new Stage();
    dialogStage.setTitle("Chargement");
    dialogStage.initModality(Modality.WINDOW_MODAL);
    dialogStage.initOwner(stage);
    dialogStage.setScene(createloadingScene());
    LOG.info("LOAD WINDOW REQUESTED. tasks = " + StringUtils.join(getTaskNames(), ","));

}

From source file:jlotoprint.MainViewController.java

public static Stage loadTemplateChooser() {
    final Stage stage = new Stage();
    try {/*from  ww w  .j  a v a2  s .  c o m*/
        FXMLLoader dialog = new FXMLLoader(MainViewController.class.getResource("TemplateDialog.fxml"));
        Parent root = (Parent) dialog.load();
        root.addEventHandler(TemplateDialogEvent.CANCELED, (actionEvent) -> {
            stage.close();
        });
        stage.setScene(new Scene(root));
        stage.setTitle("Choose a template");
        stage.getIcons().add(new Image("file:resources/icon.png"));
        stage.initModality(Modality.WINDOW_MODAL);
        stage.initOwner(JLotoPrint.stage.getScene().getWindow());
        stage.show();
    } catch (IOException ex) {
        Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
    return stage;
}

From source file:com.coolchick.translatortemplater.Main.java

/**
 * Opens a dialog to edit details for the specified person. If the user clicks OK, the changes
 * are saved into the provided person object and true is returned.
 *
 * @param person the person object to be edited
 * @return true if the user clicked OK, false otherwise.
 *///from w  w w .j  a v a 2  s  . co  m
public boolean showTranslatorEditDialog(Translator person) {
    try {
        // Load the fxml file and create a new stage for the popup dialog.
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(Main.class.getResource("PersonEditDialog.fxml"));
        AnchorPane page = (AnchorPane) loader.load();
        // Create the dialog Stage.
        Stage dialogStage = new Stage();
        dialogStage.setTitle("Edit Person");
        dialogStage.initModality(Modality.WINDOW_MODAL);
        dialogStage.initOwner(primaryStage);
        Scene scene = new Scene(page);
        dialogStage.setScene(scene);
        // Set the person into the controller.
        PersonEditDialogController controller = loader.getController();
        controller.setDialogStage(dialogStage);
        controller.setMain(this);
        controller.setTranslator(person);
        // Show the dialog and wait until the user closes it
        dialogStage.showAndWait();
        return controller.isOkClicked();
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:ui.ChoseFonctionnalite.java

private void startClientMode(ActionEvent eventT) {
    //File config = new File("resource/config.json");
    String host = "";
    String port = "8000";
    Stage stageModal = new Stage();
    Pane root = new Pane();
    root.setBackground(new Background(new BackgroundImage(new Image("resource/background.jpg"),
            BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER,
            new BackgroundSize(530, 400, true, true, true, true))));
    stageModal.setScene(new Scene(root, 200, 200));
    stageModal.initStyle(StageStyle.UTILITY);
    Label adresse = new Label("Adresse serveur:");
    adresse.setLayoutX(10);/*from w ww  .j  a  va 2s  . c o  m*/
    adresse.setLayoutY(10);
    adresse.setFont(Font.font("Arial", 16));
    JFXTextField adresseInput = new JFXTextField("127.0.0.1");
    adresseInput.setPrefWidth(180);
    adresseInput.setLayoutX(10);
    adresseInput.setLayoutY(40);
    JFXButton valider = new JFXButton("Se connecter");
    valider.setCursor(Cursor.HAND);
    valider.setMinSize(100, 30);
    valider.setLayoutX(20);
    valider.setLayoutY(130);
    valider.setFont(new Font(20));
    valider.setStyle("-fx-background-color: #9E21FF;");
    valider.setOnAction(event -> {
        if (adresseInput.getText() != "") {
            stageModal.close();
            InitClient initializeClient = new InitClient(stage, adresseInput.getText(), port);
        }
    });
    root.getChildren().add(valider);
    root.getChildren().add(adresse);
    root.getChildren().add(adresseInput);
    stageModal.setTitle("Adresse serveur");
    stageModal.initModality(Modality.WINDOW_MODAL);
    stageModal.initOwner(((Node) eventT.getSource()).getScene().getWindow());
    stageModal.show();
}

From source file:main.Content.java

public boolean showInputDialog(Activity aktivitet) {
    try {//from   w w  w .j  ava  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.perdoctus.ebikeconnect.gui.MainWindowController.java

public void showAbout() throws IOException {
    Alert alert = new Alert(Alert.AlertType.INFORMATION);
    alert.initOwner(tabPane.getScene().getWindow());
    alert.initModality(Modality.WINDOW_MODAL);
    alert.setWidth(640);//  ww  w  .  j a va2 s  . co  m
    alert.setTitle(rb.getString("application-name"));
    alert.setHeaderText(rb.getString("application-name") + " Version " + rb.getString("app-version"));

    final String aboutInfo = IOUtils.toString(getClass().getResourceAsStream("/about-info.txt"), "UTF-8");
    alert.setContentText(aboutInfo);

    final String licenseInfo = IOUtils.toString(getClass().getResourceAsStream("/license-info.txt"), "UTF-8");

    final Label label = new Label(rb.getString("licenses"));
    final TextArea licenses = new TextArea(licenseInfo);
    licenses.setMaxWidth(Double.MAX_VALUE);
    licenses.setEditable(false);

    GridPane expContent = new GridPane();
    expContent.setMaxWidth(Double.MAX_VALUE);
    expContent.add(label, 0, 0);
    expContent.add(licenses, 0, 1);

    alert.getDialogPane().setExpandableContent(expContent);
    alert.show();

}

From source file:com.panemu.tiwulfx.control.LookupFieldController.java

/**
 * Show lookup dialog.//from  w w  w .j av a2  s  .  c om
 *
 * @param stage parent
 * @param initialValue this value will be returned if user clik the close
 * button instead of double clicking a row or click Select button
 * @param propertyName propertyName corresponds to searchCriteria
 * @param searchCriteria searchCriteria (nullable)
 * @return selected object or the initialValue
 */
public T show(final Window stage, T initialValue, String propertyName, String searchCriteria) {
    if (dialogStage == null) {
        PropertyDescriptor[] props = PropertyUtils.getPropertyDescriptors(recordClass);
        lookupWindow = new LookupWindow();
        for (String clm : getColumns()) {
            for (PropertyDescriptor prop : props) {
                if (prop.getName().equals(clm)) {
                    Class type = prop.getPropertyType();
                    if (type.equals(Boolean.class)) {
                        lookupWindow.table.addColumn(new CheckBoxColumn<T>(clm));
                    } else if (type.equals(String.class)) {
                        lookupWindow.table.addColumn(new TextColumn<T>(clm));
                    } else if (type.equals(Date.class)) {
                        lookupWindow.table.addColumn(new LocalDateColumn<T>(clm));
                    } else if (Number.class.isAssignableFrom(type)) {

                        if (Long.class.isAssignableFrom(type)) {
                            lookupWindow.table.addColumn(new NumberColumn<T, Long>(clm, type));
                        } else {
                            lookupWindow.table.addColumn(new NumberColumn<T, Double>(clm, type));
                        }
                    } else {
                        TableColumn column = new TableColumn();
                        column.setCellValueFactory(new PropertyValueFactory(clm));
                        lookupWindow.table.addColumn(column);
                    }
                    break;
                }
            }

        }
        dialogStage = new Stage();
        if (stage instanceof Stage) {
            dialogStage.initOwner(stage);
            dialogStage.initModality(Modality.WINDOW_MODAL);
        } else {
            dialogStage.initOwner(null);
            dialogStage.initModality(Modality.APPLICATION_MODAL);
        }
        dialogStage.initStyle(StageStyle.UTILITY);
        dialogStage.setResizable(true);
        dialogStage.setScene(new Scene(lookupWindow));
        dialogStage.getIcons().add(new Image(
                LookupFieldController.class.getResourceAsStream("/com/panemu/tiwulfx/res/image/lookup.png")));
        dialogStage.setTitle(getWindowTitle());
        dialogStage.getScene().getStylesheets()
                .add(getClass().getResource("/com/panemu/tiwulfx/res/tiwulfx.css").toExternalForm());
        initCallback(lookupWindow, lookupWindow.table);
    }

    for (TableColumn column : lookupWindow.table.getTableView().getColumns()) {
        if (column instanceof BaseColumn && ((BaseColumn) column).getPropertyName().equals(propertyName)) {
            if (searchCriteria != null && !searchCriteria.isEmpty()) {
                TableCriteria tc = new TableCriteria(propertyName, TableCriteria.Operator.ilike_anywhere,
                        searchCriteria);
                ((BaseColumn) column).setTableCriteria(tc);
            } else {
                ((BaseColumn) column).setTableCriteria(null);
            }

            break;
        }
    }
    selectedValue = initialValue;
    beforeShowCallback(lookupWindow.table);
    lookupWindow.table.reloadFirstPage();

    if (stage != null) {
        /**
         * Since we support multiple monitors, ensure that the stage is
         * located in the center of parent stage. But we don't know the
         * dimension of the stage for the calculation, so we defer the
         * relocation after the stage is actually displayed.
         */
        Runnable runnable = new Runnable() {
            public void run() {
                dialogStage.setX(stage.getX() + stage.getWidth() / 2 - dialogStage.getWidth() / 2);
                dialogStage.setY(stage.getY() + stage.getHeight() / 2 - dialogStage.getHeight() / 2);

                //set the opacity back to fully opaque
                dialogStage.setOpacity(1);
            }
        };

        Platform.runLater(runnable);

        //set the opacity to 0 to minimize flicker effect
        dialogStage.setOpacity(0);
    }

    dialogStage.showAndWait();
    return selectedValue;
}

From source file:org.virtualAsylum.spriggan.data.Addon.java

public State doInstall() {
    log("Installing %s (%s)", getDisplayName(), getID());
    State result = State.IDLE;
    State error = State.ERROR;
    setState(State.INSTALLING);//  ww  w.j  a va2s  .  com
    setStateProgress(-1);
    boolean didError = false;
    try {
        //<editor-fold desc="Dependencies">
        Collection<String> dependencyIDs = getDependencies();
        ArrayList<Addon> dependencies = new ArrayList();
        if (dependencyIDs.size() > 0) {
            setState(State.INSTALLING_DEPENDENCIES);
            for (String dependencyIDString : dependencyIDs) {
                Addon dependency = Database.find_ID(dependencyIDString);
                if (dependency == null) {
                    throw new Exception(String.format("Dependency %s was missing for %s(%s)",
                            dependencyIDString, getDisplayName(), getID()));
                }
                if (!dependency.getInstalled()) {
                    dependencies.add(dependency);
                }
            }
            if (dependencies.size() > 0) {
                SimpleObjectProperty<Boolean> popupResult = new SimpleObjectProperty(null);
                runLater(() -> {
                    DependencyPopup popup = new DependencyPopup(this, dependencies, popupResult);
                    Stage stage = popup.popup(StageStyle.UTILITY, Modality.WINDOW_MODAL,
                            MainInterface.current.getWindow(), getDisplayName());
                    stage.setOnCloseRequest(e -> popupResult.set(false));
                    stage.show();
                });

                while (popupResult.get() == null) {
                    sleep(500);
                }
                if (!popupResult.get()) {
                    error = State.IDLE;
                    throw new Exception(String.format("Did not install dependencies for %s (%s)",
                            getDisplayName(), getID()));
                }
                double perDep = 1.0 / dependencies.size();
                setStateProgress(0.0);
                for (Addon dependency : dependencies) {
                    boolean downloaded = Database.getCurrent().getRepository().contains(dependency);
                    State depResult = State.IDLE;
                    if (!downloaded) {
                        depResult = dependency.doDownloadAndInstall();
                    } else if (!dependency.getInstalled()) {
                        depResult = dependency.doInstall();
                    }
                    if (depResult != State.IDLE) {
                        throw new Exception(
                                String.format("Dependency %s (%s) failed to download and/or install",
                                        dependency.getDisplayName(), dependency.getID()));
                    }
                    incrementStateProgress(perDep);
                }
                setState(State.INSTALLING);
            }

        }
        //</editor-fold>

        error = State.ERROR;

        final File repositoryDirectory = getRepositoryDirectory(this);
        final File installDirectory = getInstallDirectory(this);

        ArrayList<File> files = getRepositoryFiles();

        double perFile = 1.0 / files.size();
        setStateProgress(0.0);
        for (File inputFile : files) {
            File outputFile = new File(installDirectory,
                    repositoryDirectory.toPath().relativize(inputFile.toPath()).toString());
            outputFile.getParentFile().mkdirs();
            Files.copy(inputFile.toPath(), outputFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
            incrementStateProgress(perFile);
        }

    } catch (Exception ex) {
        if (error == State.ERROR) {
            handleException(ex);
        }
        result = error;
        didError = true;
    }

    if (!didError) {
        setInstalled(true);
    }
    log("Installing %s (%s): %s", getDisplayName(), getID(), result);
    setStateProgress(0);
    setState(result);
    return result;
}