Example usage for javafx.scene.control ChoiceDialog setSelectedItem

List of usage examples for javafx.scene.control ChoiceDialog setSelectedItem

Introduction

In this page you can find the example usage for javafx.scene.control ChoiceDialog setSelectedItem.

Prototype

public final void setSelectedItem(T item) 

Source Link

Document

Sets the currently selected item in the dialog.

Usage

From source file:fr.amap.lidar.amapvox.gui.MainFrameController.java

@FXML
private void onActionButtonSaveCanopyAnalyzerDirections(ActionEvent event) {

    ChoiceDialog<String> choiceDialog = new ChoiceDialog<>();
    choiceDialog.getItems().addAll("OBJ", "CSV (spherical coordinates)", "CSV (cartesian coordinates)");
    choiceDialog.setSelectedItem("OBJ");

    choiceDialog.setTitle("Output format");
    choiceDialog.setContentText("Choose the output format");

    Optional<String> result = choiceDialog.showAndWait();

    if (result.isPresent()) {

        String format = result.get();

        boolean csv = (format.equals("CSV (spherical coordinates)")
                || format.equals("CSV (cartesian coordinates)"));

        boolean cartesian = format.equals("CSV (cartesian coordinates)") && csv;

        FileChooser fc = new FileChooser();
        File selectedFile = fc.showSaveDialog(stage);

        if (selectedFile != null) {

            LAI2xxx lAi2xxx = new LAI2200(
                    comboboxChooseCanopyAnalyzerSampling.getSelectionModel().getSelectedItem(),
                    LAI2xxx.ViewCap.CAP_360, new boolean[] { false, false, false, false, false });

            lAi2xxx.computeDirections();
            Vector3f[] directions = lAi2xxx.getDirections();
            try (BufferedWriter writer = new BufferedWriter(new FileWriter(selectedFile))) {

                if (csv) {
                    if (cartesian) {
                        writer.write("X_cartesian Y_cartesian Z_cartesian\n");
                    } else {
                        writer.write("azimut elevation\n");
                    }//w  ww  . j a v a 2  s  .c o m
                }

                SphericalCoordinates sc = new SphericalCoordinates();

                for (Vector3f direction : directions) {

                    if (csv) {
                        if (cartesian) {
                            writer.write(direction.x + " " + direction.y + " " + direction.z + "\n");
                        } else {
                            sc.toSpherical(new Vector3d(direction));
                            writer.write(sc.getAzimut() + " " + sc.getZenith() + "\n");
                        }
                    } else {
                        writer.write("v " + direction.x + " " + direction.y + " " + direction.z + "\n");
                    }
                }

            } catch (IOException ex) {
                showErrorDialog(ex);
            }
        }
    }

}