Example usage for javafx.stage Stage initModality

List of usage examples for javafx.stage Stage initModality

Introduction

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

Prototype

public final void initModality(Modality modality) 

Source Link

Document

Specifies the modality for this stage.

Usage

From source file:jlotoprint.MainViewController.java

public static Stage loadTemplateChooser() {
    final Stage stage = new Stage();
    try {//from w  w  w. j  av  a 2  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:spdxedit.PackageEditor.java

/**
 * Opens the modal package editor for the provided package.
 *
 * @param pkg               The package to edit.
 * @param relatablePackages Packages to which the edited package may optionally have defined relationships
 * @param parentWindow      The parent window.
 *//*from ww w  .j a  v a  2s . com*/
public static void editPackage(final SpdxPackage pkg, final List<SpdxPackage> relatablePackages,
        SpdxDocumentContainer documentContainer, Window parentWindow) {

    final PackageEditor packageEditor = new PackageEditor(pkg, relatablePackages, documentContainer);
    final Stage dialogStage = new Stage();
    dialogStage.setTitle("Edit SPDX Package: " + pkg.getName());
    dialogStage.initStyle(StageStyle.DECORATED);
    dialogStage.initModality(Modality.APPLICATION_MODAL);
    dialogStage.setY(parentWindow.getX() + parentWindow.getWidth() / 2);
    dialogStage.setY(parentWindow.getY() + parentWindow.getHeight() / 2);
    dialogStage.setResizable(false);
    try {
        FXMLLoader loader = new FXMLLoader(NewPackageDialog.class.getResource("/PackageEditor.fxml"));
        loader.setController(packageEditor);
        Pane pane = loader.load();
        Scene scene = new Scene(pane);
        dialogStage.setScene(scene);
        dialogStage.getIcons().clear();
        dialogStage.getIcons().add(UiUtils.ICON_IMAGE_VIEW.getImage());
        //Populate the file list on appearance
        dialogStage.setOnShown(event -> {
            try {
                final SpdxFile dummyfile = new SpdxFile(pkg.getName(), null, null, null, null, null, null, null,
                        null, null, null, null, null);
                TreeItem<SpdxFile> root = new TreeItem<>(dummyfile);
                packageEditor.filesTable.setRoot(root);
                //Assume a package without is external
                //TODO: replace with external packages or whatever alternate mechanism in 2.1
                packageEditor.btnAddFile.setDisable(pkg.getFiles().length == 0);
                root.getChildren()
                        .setAll(Stream.of(pkg.getFiles())
                                .sorted(Comparator.comparing(file -> StringUtils.lowerCase(file.getName()))) //Sort by file name
                                .map(TreeItem<SpdxFile>::new).collect(Collectors.toList()));
            } catch (InvalidSPDXAnalysisException e) {
                logger.error("Unable to get files for package " + pkg.getName(), e);
            }

            packageEditor.tabFiles.setExpanded(true);

        });

        //Won't assign this event through FXML - don't want to propagate the stage beyond this point.
        packageEditor.btnOk.setOnMouseClicked(event -> dialogStage.close());
        dialogStage.showAndWait();

    } catch (IOException ioe) {
        throw new RuntimeException("Unable to load dialog", ioe);
    }
}

From source file:Main.java

@Override
public void start(Stage stage) {

    Button openURLButton = new Button("Go!");
    openURLButton.setOnAction(e -> {//w w w  .ja va  2s  .c o m
        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:com.esri.geoevent.clusterSimulator.ui.CertificateCheckerDialog.java

@Override
public boolean allowConnection(final X509Certificate[] chain) {
    if (trustedCerts.contains(chain[0])) {
        return true;
    }// w w  w  . ja v a  2 s .  c om
    final ArrayBlockingQueue<Boolean> responseQueue = new ArrayBlockingQueue<Boolean>(1);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            try {
                final Stage dialog = new Stage();
                dialog.initModality(Modality.APPLICATION_MODAL);
                dialog.initOwner(MainApplication.primaryStage);
                dialog.setTitle("Certificate Check");
                FXMLLoader loader = new FXMLLoader(getClass().getResource("CertificateCheckerDialog.fxml"));
                Parent parent = (Parent) loader.load();
                CertCheckController controller = (CertCheckController) loader.getController();
                controller.certText.setText(chain[0].toString());
                Scene scene = new Scene(parent);
                dialog.setScene(scene);
                dialog.showAndWait();
                responseQueue.put(Boolean.valueOf(controller.allowConnection));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    };
    if (Platform.isFxApplicationThread()) {
        runnable.run();
    } else {
        Platform.runLater(runnable);
    }

    try {
        boolean retVal = responseQueue.take();
        if (retVal) {
            trustedCerts.add(chain[0]);
        }
        return retVal;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

From source file:gui.accessories.GraphPopup.java

private void initFX(JFXPanel fxPanel) {
    // This method is invoked on the JavaFX thread
    Stage window = new Stage();
    window.initModality(Modality.APPLICATION_MODAL);
    window.setTitle(labels.getString("PONTOS.VITORIA"));
    window.setMinWidth(500);/*from ww w  .  j ava  2  s . c om*/

    Chart chart = createStackedBarChart();
    chart.setAnimated(true);
    Scene scene = new Scene(chart);

    //show and tell
    window.setScene(scene);
    window.showAndWait();

    fxPanel.setScene(scene);
}

From source file:ijfx.ui.test.DummyCategories.java

@Override
public void run() {

    ExplorableList output = new ExplorableList();
    ExplorableList output2 = new ExplorableList();
    ExplorableList output3 = new ExplorableList();

    for (int i = 0; i != 10; i++) {

        MetaData name = MetaData.create(MetaData.NAME, RandomStringUtils.random(3, true, false));
        MetaData m1 = MetaData.create("Random strings 1", RandomStringUtils.random(5, true, false));
        MetaData m2 = MetaData.create("Random strings 2", RandomStringUtils.random(3, true, false));
        MetaData m3 = MetaData.create("Random double 1", new Random().nextDouble());
        MetaData m4 = MetaData.create("Random double 2", new Random().nextDouble());

        Explorable explorable = new MetaDataSetExplorerWrapper(name, m1, m2, m3, m4);
        explorable.addTag(Tag.create(RandomStringUtils.random(3, true, false)));
        explorable.addTag(Tag.create(RandomStringUtils.random(3, true, false)));
        output.add(explorable);/* ww  w.  j  a va  2 s .  c  o m*/

    }

    for (int i = 0; i != 5; i++) {

        MetaData name = MetaData.create(MetaData.NAME, RandomStringUtils.random(3, true, false));
        MetaData m1 = MetaData.create("Random strings 1", RandomStringUtils.random(5, true, false));
        MetaData m2 = MetaData.create("Random strings 2", RandomStringUtils.random(3, true, false));
        MetaData m3 = MetaData.create("Random double 1", new Random().nextDouble());
        MetaData m4 = MetaData.create("Random double 2", new Random().nextDouble());

        Explorable explorable = new MetaDataSetExplorerWrapper(name, m1, m2, m3, m4);
        explorable.addTag(Tag.create(RandomStringUtils.random(3, true, false)));
        explorable.addTag(Tag.create(RandomStringUtils.random(3, true, false)));
        output2.add(explorable);

    }

    for (int i = 0; i != 3; i++) {

        MetaData name = MetaData.create(MetaData.NAME, RandomStringUtils.random(3, true, false));
        MetaData m1 = MetaData.create("Random strings 1", RandomStringUtils.random(5, true, false));
        MetaData m2 = MetaData.create("Random strings 2", RandomStringUtils.random(3, true, false));
        MetaData m3 = MetaData.create("Random double 1", new Random().nextDouble());
        MetaData m4 = MetaData.create("Random double 2", new Random().nextDouble());

        Explorable explorable = new MetaDataSetExplorerWrapper(name, m1, m2, m3, m4);
        explorable.addTag(Tag.create(RandomStringUtils.random(3, true, false)));
        explorable.addTag(Tag.create(RandomStringUtils.random(3, true, false)));
        output3.add(explorable);

    }

    Pane pane = ctrl.addCategory("Cat 1").setElements("Cat 1", output) //set the element that the first line will contain
            .addCategory("Cat 2").setElements("Cat 2", output2).setMaxItemPerCategory(8).generate(); // returns the Pane that contains the view

    ctrl.setElements("Cat 2", output3);
    ctrl.update(); // updates the pane returned previously

    Platform.runLater(() -> {

        Stage stage = new Stage();
        stage.initModality(Modality.APPLICATION_MODAL);
        Scene scene = new Scene(pane, 550, 600);

        ////////CSS part///////

        URL cssURL = getClass().getResource("/ijfx/ui/flatterfx.css");
        if (cssURL != null) {
            scene.getStylesheets().add(cssURL.toExternalForm());
        }

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

    });

}

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

@FXML
public void onLoadButton(ActionEvent ae) {
    try {//from   w w w .  ja  va 2 s  . co  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.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  ww . j  av a 2s  . c  om*/
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:org.ado.biblio.desktop.update.UpdatePresenter.java

public void download() throws IOException {
    LOGGER.info("download");
    final Artifact artifact = release.getArtifactUrl().get(ComponentEnum.DESKTOP_CLIENT);

    final Stage stage = new Stage();
    final DownloadView updateView = new DownloadView();
    final DownloadPresenter presenter = (DownloadPresenter) updateView.getPresenter();
    presenter.process(stage, artifact);//from w w w.  j ava2s.c o  m
    stage.initModality(Modality.APPLICATION_MODAL);
    stage.setScene(new Scene(updateView.getView()));
    stage.setTitle("Update");
    stage.show();

    this.stage.close();
}

From source file:mesclasses.view.TimetableController.java

private Cours openEditDialog(Cours coursToEdit, Cours originalCours) {
    try {/*from  w  ww  .  ja  va  2 s  .com*/
        // 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;
    }
}