Example usage for javafx.scene.control ChoiceDialog getItems

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

Introduction

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

Prototype

public final ObservableList<T> getItems() 

Source Link

Document

Returns the list of all items that will be displayed to users.

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");
                    }/*from  w ww.  j  a v a2 s . c  om*/
                }

                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);
            }
        }
    }

}