Example usage for javafx.fxml FXMLLoader getController

List of usage examples for javafx.fxml FXMLLoader getController

Introduction

In this page you can find the example usage for javafx.fxml FXMLLoader getController.

Prototype

@SuppressWarnings("unchecked")
public <T> T getController() 

Source Link

Document

Returns the controller associated with the root object.

Usage

From source file:snpviewer.SnpViewer.java

public void showAbout(ActionEvent ev) {
    try {/*from   w ww . j  a v  a 2  s .co  m*/
        FXMLLoader loader = new FXMLLoader(getClass().getResource("about.fxml"));
        Pane page = (Pane) loader.load();
        Scene scene = new Scene(page);
        Stage stage = new Stage();
        stage.setScene(scene);
        scene.getStylesheets().add(SnpViewer.class.getResource("SnpViewerStyleSheet.css").toExternalForm());
        AboutController controller = loader.getController();
        controller.setVersion(VERSION);
        stage.initModality(Modality.APPLICATION_MODAL);
        stage.getIcons().add(new Image(this.getClass().getResourceAsStream("icon.png")));
        stage.setTitle("About SnpViewer");

        stage.show();
    } catch (Exception ex) {
        Dialogs.showErrorDialog(null, "Error showing about information - see" + " details for stack trace",
                "ERROR!", "SnpViewer", ex);
    }
}

From source file:snpviewer.SnpViewer.java

private void zoomRegion(Rectangle rectangle) {
    try {//from w  w  w .ja  v  a 2s . c o m
        FXMLLoader loader = new FXMLLoader(getClass().getResource("ZoomRegionView.fxml"));
        ChromosomeLength chromLength = new ChromosomeLength(genomeVersion);
        String currentChrom = (String) chromosomeBoxList[chromosomeSelector.getSelectionModel()
                .getSelectedIndex()];
        double startCoordinate = chromLength.getLength(currentChrom) / selectionOverlayPane.getWidth()
                * rectangle.getX();
        double selectionWidth = chromLength.getLength(currentChrom) / selectionOverlayPane.getWidth()
                * rectangle.getWidth();
        if (rectangle.getX() == 0) {
            startCoordinate = 1;
        }

        Pane page = (Pane) loader.load();
        Scene scene = new Scene(page);
        Stage stage = new Stage();
        stage.setScene(scene);
        stage.setTitle("chr" + currentChrom + ":" + nf.format(startCoordinate) + "-"
                + nf.format(startCoordinate + selectionWidth));
        scene.getStylesheets().add(SnpViewer.class.getResource("SnpViewerStyleSheet.css").toExternalForm());
        String subPath = "zoom";
        stage.initModality(Modality.NONE);
        stage.getIcons().add(new Image(this.getClass().getResourceAsStream("icon.png")));
        stage.show();
        ZoomRegionViewController zoomController = (ZoomRegionViewController) loader.getController();
        ArrayList<SnpFile> bothFiles = new ArrayList<>();
        bothFiles.addAll(affFiles);
        bothFiles.addAll(unFiles);
        ArrayList<Pane> zoomPanes = zoomController.setPanes(bothFiles);
        zoomController.setParentController(this);
        zoomController.setLoadingRectangle(rectangle);
        zoomController.setRegionLength(selectionWidth);
        zoomController.setRegionStart(startCoordinate);
        zoomController.setChromosome(currentChrom);
        SplitPane zoomSplit = zoomController.getSplitPane();
        Iterator<SnpFile> sIter = bothFiles.iterator();
        Iterator<Pane> pIter = zoomPanes.iterator();
        if (!sIter.hasNext() || !pIter.hasNext()) {
            return;
        }
        SnpFile firstFile = sIter.next();
        Pane firstPane = pIter.next();
        drawCoordinatesWithIterator(firstFile, firstPane, subPath, sIter, pIter, 1, bothFiles.size(),
                currentChrom, startCoordinate, startCoordinate + selectionWidth, true, zoomSplit);
        zoomController.tidyPanes();

    } catch (ChromosomeLength.ChromosomeLengthException | IOException ex) {
        Dialogs.showErrorDialog(null, "Please see details for stack trace.", "Error displaying zoomed region",
                "SnpViewer", ex);
    }
}

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

private void exportDartMaket(final File voxelFile) {

    Stage exportDartFrame = new Stage();
    DartExporterFrameController controller;

    Parent root;/* www  .ja  v  a  2 s .c om*/

    if (Util.checkIfVoxelFile(voxelFile)) {

        try {
            FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/export/DartExporterDialog.fxml"));
            root = loader.load();
            controller = loader.getController();
            controller.setStage(exportDartFrame);
            controller.setParent(this);
            controller.setVoxelFile(voxelFile);
            exportDartFrame.setScene(new Scene(root));
        } catch (IOException ex) {
            logger.error("Cannot load fxml file", ex);
        }

        exportDartFrame.show();
    } else {

        logger.error("File is not a voxel file: " + voxelFile.getAbsolutePath());
        Alert alert = new Alert(AlertType.CONFIRMATION);
        alert.setHeaderText("Incorrect file");
        alert.setContentText("File is corrupted or cannot be read!\n" + "Do you want to keep it?");

        Optional<ButtonType> result = alert.showAndWait();

        if (result.get() == ButtonType.CANCEL) {
            listViewProductsFiles.getItems().remove(voxelFile);
        }
    }
}

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

private void editVoxelSpace(final File voxelFile) {

    if (editingFrameOpened) {
        return;// ww  w.  j ava  2s .  c o  m
    }

    editingFrameOpened = true;
    voxelsToRemove.clear();

    final String attributeToView = "PadBVTotal";

    //window size
    ObservableList<Screen> screens = Screen.getScreens();

    if (screens != null && screens.size() > 0) {
        SCREEN_WIDTH = screens.get(0).getBounds().getWidth();
        SCREEN_HEIGHT = screens.get(0).getBounds().getHeight();
    }

    try {

        Service s = new Service() {

            @Override
            protected Task createTask() {
                return new Task() {

                    @Override
                    protected Object call() throws Exception {

                        SimpleViewer viewer3D = new SimpleViewer((int) (SCREEN_WIDTH / 4.0d),
                                (int) (SCREEN_HEIGHT / 4.0d), (int) (SCREEN_WIDTH / 1.5d),
                                (int) (SCREEN_HEIGHT / 2.0d), voxelFile.toString());

                        fr.amap.viewer3d.object.scene.Scene scene = viewer3D.getScene();

                        /**
                         * *VOXEL SPACE**
                         */
                        updateMessage("Loading voxel space: " + voxelFile.getAbsolutePath());

                        final VoxelSpaceSceneObject voxelSpace = new VoxelSpaceSceneObject(voxelFile);
                        voxelSpace.setMousePickable(true);

                        voxelSpace.addVoxelSpaceListener(new VoxelSpaceAdapter() {

                            @Override
                            public void voxelSpaceCreationProgress(int progress) {
                                updateProgress(progress, 100);
                            }
                        });

                        voxelSpace.loadVoxels();
                        float voxelResolution = voxelSpace.data.getVoxelSpaceInfos().getResolution();

                        VoxelFileReader reader = new VoxelFileReader(voxelFile);
                        VoxelSpaceInfos infos = reader.getVoxelSpaceInfos();

                        final SceneObject boundingBox = new SimpleSceneObject();
                        boundingBox.setMesh(GLMeshFactory.createBoundingBox((float) infos.getMinCorner().x,
                                (float) infos.getMinCorner().y, (float) infos.getMinCorner().z,
                                (float) infos.getMaxCorner().x, (float) infos.getMaxCorner().y,
                                (float) infos.getMaxCorner().z));

                        SimpleShader s = new SimpleShader();
                        s.setColor(new Vec3F(1, 0, 0));
                        boundingBox.setShader(s);
                        boundingBox.setDrawType(GLMesh.DrawType.LINES);
                        scene.addSceneObject(boundingBox);

                        /*
                         * Voxel information
                         */
                        StringToImage stringToImage = new StringToImage(1024, 1024);
                        stringToImage.setAdaptableFontSize(true);
                        stringToImage.setBackgroundColor(new Color(255, 255, 255, 127));
                        stringToImage.setTextColor(new Color(0, 0, 0, 255));

                        BufferedImage image = new BufferedImage(1024, 1024, BufferedImage.TYPE_INT_ARGB);

                        Texture texture = new Texture(image);

                        int pickingInfoObjectWidth = viewer3D.getWidth() / 5;
                        int pickingInfoObjectHeight = viewer3D.getHeight() / 5;

                        SceneObject pickingInfoObject = SceneObjectFactory.createTexturedPlane(
                                new Vec3F(viewer3D.getWidth() - pickingInfoObjectWidth,
                                        viewer3D.getHeight() - pickingInfoObjectHeight, 0),
                                pickingInfoObjectWidth, pickingInfoObjectHeight, texture);

                        pickingInfoObject.setShader(new TextureShader());
                        pickingInfoObject.setDrawType(GLMesh.DrawType.TRIANGLES);

                        SceneObject sceneObjectSelectedVox = new SimpleSceneObject(
                                GLMeshFactory.createBoundingBox(-voxelResolution / 2.0f,
                                        -voxelResolution / 2.0f, -voxelResolution / 2.0f,
                                        voxelResolution / 2.0f, voxelResolution / 2.0f, voxelResolution / 2.0f),
                                false);

                        SimpleShader simpleShader = new SimpleShader();
                        simpleShader.setColor(new Vec3F(1, 0, 0));
                        sceneObjectSelectedVox.setVisible(false);
                        sceneObjectSelectedVox.setShader(simpleShader);
                        sceneObjectSelectedVox.setDrawType(GLMesh.DrawType.LINES);

                        viewer3D.getScene().addSceneObject(sceneObjectSelectedVox);

                        final SimpleObjectProperty<VoxelObject> selectedVoxel = new SimpleObjectProperty<>();

                        SceneObjectListener listener = new SceneObjectListener() {
                            @Override
                            public void clicked(SceneObject sceneObject, MousePicker mousePicker,
                                    Point3D intersection) {

                                Vec3F camLocation = viewer3D.getScene().getCamera().getLocation();

                                selectedVoxel.set(voxelSpace.doPicking(mousePicker));

                                if (selectedVoxel.get() != null) {

                                    String[][] lines = new String[voxelSpace.getColumnsNames().length][2];

                                    for (int i = 0; i < voxelSpace.getColumnsNames().length; i++) {

                                        lines[i][0] = voxelSpace.getColumnsNames()[i];

                                        float attribut = selectedVoxel.get().getAttributs()[i];
                                        if (Float.isNaN(attribut)) {
                                            lines[i][1] = "NaN";
                                        } else {
                                            lines[i][1] = String
                                                    .valueOf(Math.round(attribut * 1000.0f) / 1000.0f);
                                        }

                                    }

                                    arrangeText(lines);

                                    String text = "";
                                    for (int i = 0; i < voxelSpace.getColumnsNames().length; i++) {

                                        String attribut = lines[i][0] + " " + lines[i][1];
                                        text += attribut + "\n";
                                    }

                                    stringToImage.setText(text, 0, 0);

                                    texture.setBufferedImage(stringToImage.buildImage());
                                    Point3f voxelPosition = voxelSpace.getVoxelPosition(selectedVoxel.get().$i,
                                            selectedVoxel.get().$j, selectedVoxel.get().$k);

                                    sceneObjectSelectedVox.setPosition(
                                            new Point3F(voxelPosition.x, voxelPosition.y, voxelPosition.z));
                                    sceneObjectSelectedVox.setVisible(true);
                                    pickingInfoObject.setVisible(true);
                                } else {
                                    sceneObjectSelectedVox.setVisible(false);
                                    pickingInfoObject.setVisible(false);
                                }
                            }
                        };

                        final SimpleIntegerProperty currentZCropIndex = new SimpleIntegerProperty(0);

                        viewer3D.addEventListener(new EventManager(null, new InputKeyListener()) {
                            @Override
                            public void updateEvents() {

                                if (this.keyboard.isKeyClicked(KeyEvent.VK_DELETE)) {
                                    if (selectedVoxel.get() != null) {
                                        selectedVoxel.get().setAlpha(0);
                                        selectedVoxel.get().isHidden = true;
                                        voxelSpace.updateVao();
                                        sceneObjectSelectedVox.setVisible(false);
                                        pickingInfoObject.setVisible(false);
                                        voxelsToRemove.add(new Point3i(selectedVoxel.get().$i,
                                                selectedVoxel.get().$j, selectedVoxel.get().$k));
                                    }
                                }
                            }
                        });

                        voxelSpace.addSceneObjectListener(listener);

                        voxelSpace.changeCurrentAttribut(attributeToView);
                        voxelSpace.setShader(new InstanceLightedShader());
                        voxelSpace.setDrawType(GLMesh.DrawType.TRIANGLES);
                        scene.addSceneObject(voxelSpace);

                        scene.addSceneObjectAsHud(pickingInfoObject);

                        /**
                         * *scale**
                         */
                        updateMessage("Generating scale");
                        final Texture scaleTexture = new Texture(ScaleGradient.createColorScaleBufferedImage(
                                voxelSpace.getGradient(), voxelSpace.getAttributValueMin(),
                                voxelSpace.getAttributValueMax(), viewer3D.getWidth() - 80,
                                (int) (viewer3D.getHeight() / 20), ScaleGradient.Orientation.HORIZONTAL, 5, 8));

                        SceneObject scalePlane = SceneObjectFactory.createTexturedPlane(new Vec3F(40, 20, 0),
                                (int) (viewer3D.getWidth() - 80), (int) (viewer3D.getHeight() / 20),
                                scaleTexture);

                        scalePlane.setShader(new TextureShader());
                        scalePlane.setDrawType(GLMesh.DrawType.TRIANGLES);
                        scene.addSceneObjectAsHud(scalePlane);

                        voxelSpace.addPropertyChangeListener("gradientUpdated", new PropertyChangeListener() {

                            @Override
                            public void propertyChange(PropertyChangeEvent evt) {

                                BufferedImage image = ScaleGradient.createColorScaleBufferedImage(
                                        voxelSpace.getGradient(), voxelSpace.getAttributValueMin(),
                                        voxelSpace.getAttributValueMax(), viewer3D.getWidth() - 80,
                                        (int) (viewer3D.getHeight() / 20), ScaleGradient.Orientation.HORIZONTAL,
                                        5, 8);

                                scaleTexture.setBufferedImage(image);
                            }
                        });

                        /**
                         * *light**
                         */
                        scene.setLightPosition(
                                new Point3F(voxelSpace.getGravityCenter().x, voxelSpace.getGravityCenter().y,
                                        voxelSpace.getGravityCenter().z + voxelSpace.widthZ + 100));

                        /**
                         * *camera**
                         */
                        TrackballCamera trackballCamera = new TrackballCamera();
                        trackballCamera.setPivot(voxelSpace);
                        trackballCamera
                                .setLocation(new Vec3F(voxelSpace.getGravityCenter().x + voxelSpace.widthX,
                                        voxelSpace.getGravityCenter().y + voxelSpace.widthY,
                                        voxelSpace.getGravityCenter().z + voxelSpace.widthZ));
                        viewer3D.getScene().setCamera(trackballCamera);

                        Platform.runLater(new Runnable() {

                            @Override
                            public void run() {

                                final Stage toolBarFrameStage = new Stage();
                                final FXMLLoader loader = new FXMLLoader(
                                        getClass().getResource("/fxml/ToolBoxFrame.fxml"));

                                try {
                                    stage.setAlwaysOnTop(false);

                                    Parent root = loader.load();
                                    toolBarFrameStage.setScene(new Scene(root));
                                    toolBarFrameStage.initStyle(StageStyle.UNDECORATED);

                                    toolBarFrameStage.setAlwaysOnTop(true);

                                    ToolBoxFrameController toolBarFrameController = loader.getController();
                                    toolBarFrameController.setStage(toolBarFrameStage);
                                    toolBarFrameStage.setX(viewer3D.getPosition().getX());
                                    toolBarFrameStage.setY(viewer3D.getPosition().getY());
                                    toolBarFrameController.setJoglListener(viewer3D.getJoglContext());
                                    toolBarFrameController.setAttributes(attributeToView,
                                            voxelSpace.data.getVoxelSpaceInfos().getColumnNames());

                                    toolBarFrameStage.focusedProperty()
                                            .addListener(new ChangeListener<Boolean>() {

                                                @Override
                                                public void changed(
                                                        ObservableValue<? extends Boolean> observable,
                                                        Boolean oldValue, Boolean newValue) {
                                                    if (newValue) {
                                                        toolBarFrameStage.setAlwaysOnTop(true);
                                                        toolBarFrameStage.setX(viewer3D.getPosition().getX());
                                                        toolBarFrameStage.setY(viewer3D.getPosition().getY());
                                                    } else if (!viewer3D.isFocused()) {
                                                        toolBarFrameStage.setAlwaysOnTop(false);
                                                    }
                                                }
                                            });

                                    toolBarFrameController.initContent(voxelSpace);
                                    toolBarFrameStage.setAlwaysOnTop(true);

                                    toolBarFrameStage.show();

                                    double maxToolBoxHeight = toolBarFrameStage.getHeight();
                                    viewer3D.getJoglContext().setStartX((int) toolBarFrameStage.getWidth());

                                    viewer3D.getRenderFrame().addWindowListener(new WindowAdapter() {

                                        @Override
                                        public void windowResized(com.jogamp.newt.event.WindowEvent we) {

                                            Window window = (Window) we.getSource();
                                            final double height = window.getHeight();

                                            Platform.runLater(new Runnable() {

                                                @Override
                                                public void run() {

                                                    if (height < maxToolBoxHeight) {
                                                        toolBarFrameStage.setHeight(height);
                                                    } else {
                                                        toolBarFrameStage.setHeight(maxToolBoxHeight);
                                                    }

                                                    toolBarFrameStage.setX(viewer3D.getPosition().getX());
                                                    toolBarFrameStage.setY(viewer3D.getPosition().getY());
                                                }
                                            });
                                        }

                                        @Override
                                        public void windowMoved(com.jogamp.newt.event.WindowEvent we) {

                                            Platform.runLater(new Runnable() {

                                                @Override
                                                public void run() {
                                                    toolBarFrameStage.setX(viewer3D.getPosition().getX());
                                                    toolBarFrameStage.setY(viewer3D.getPosition().getY());
                                                }
                                            });
                                        }

                                        @Override
                                        public void windowDestroyed(com.jogamp.newt.event.WindowEvent we) {

                                            Platform.runLater(new Runnable() {

                                                @Override
                                                public void run() {
                                                    toolBarFrameStage.close();

                                                    if (fcSaveVoxelFileForAreaExtracting == null) {
                                                        fcSaveVoxelFileForAreaExtracting = new FileChooserContext();

                                                        if (fcOpenVoxelFileForAreaExtracting != null) {
                                                            fcSaveVoxelFileForAreaExtracting.fc
                                                                    .setInitialDirectory(
                                                                            fcOpenVoxelFileForAreaExtracting.lastSelectedFile
                                                                                    .getParentFile());
                                                        }
                                                    }

                                                    File selectedFile = fcSaveVoxelFileForAreaExtracting
                                                            .showSaveDialog(stage);

                                                    if (selectedFile != null) {
                                                        VoxelFileReader reader;
                                                        BufferedWriter writer = null;

                                                        try {
                                                            reader = new VoxelFileReader(voxelFile, true);
                                                            VoxelSpaceInfos infos = reader.getVoxelSpaceInfos();

                                                            writer = new BufferedWriter(
                                                                    new FileWriter(selectedFile));

                                                            writer.write(infos.toString() + "\n");

                                                            Iterator<Voxel> iterator = reader.iterator();

                                                            while (iterator.hasNext()) {

                                                                Voxel voxel = iterator.next();

                                                                if (voxelsToRemove.contains(new Point3i(
                                                                        voxel.$i, voxel.$j, voxel.$k))) {
                                                                    voxel.PadBVTotal = 0;
                                                                    voxel.nbEchos = 0;
                                                                    voxel.transmittance = 1;
                                                                    voxel.bvIntercepted = 0;
                                                                }

                                                                writer.write(voxel + "\n");
                                                            }

                                                            writer.close();

                                                            addFileToProductsList(selectedFile);

                                                        } catch (Exception ex) {
                                                            showErrorDialog(ex);
                                                        } finally {
                                                            try {
                                                                if (writer != null) {
                                                                    writer.close();
                                                                }

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

                                                    editingFrameOpened = false;
                                                }
                                            });
                                        }

                                        @Override
                                        public void windowGainedFocus(com.jogamp.newt.event.WindowEvent we) {

                                            viewer3D.setIsFocused(true);

                                            Platform.runLater(new Runnable() {

                                                @Override
                                                public void run() {

                                                    if (!toolBarFrameStage.isShowing()) {
                                                        toolBarFrameStage.toFront();
                                                    }

                                                    toolBarFrameStage.setIconified(false);
                                                    toolBarFrameStage.setAlwaysOnTop(true);

                                                    toolBarFrameStage.setX(viewer3D.getPosition().getX());
                                                    toolBarFrameStage.setY(viewer3D.getPosition().getY());
                                                }
                                            });
                                        }

                                        @Override
                                        public void windowLostFocus(com.jogamp.newt.event.WindowEvent e) {

                                            viewer3D.setIsFocused(false);
                                            Platform.runLater(new Runnable() {

                                                @Override
                                                public void run() {
                                                    if (!toolBarFrameStage.focusedProperty().get()) {
                                                        toolBarFrameStage.setIconified(true);
                                                        toolBarFrameStage.setAlwaysOnTop(false);
                                                    }
                                                }
                                            });
                                        }
                                    });

                                    viewer3D.show();

                                    toolBarFrameStage.setAlwaysOnTop(true);

                                } catch (IOException e) {
                                    showErrorDialog(new Exception("Loading ToolBarFrame.fxml failed", e));
                                } catch (Exception e) {
                                    showErrorDialog(new Exception("Error occured during toolbar init", e));
                                }
                            }
                        });

                        return null;
                    }
                };
            }
        };

        ProgressDialog d = new ProgressDialog(s);
        d.show();

        s.start();

    } catch (Exception ex) {
        showErrorDialog(new Exception("Cannot launch 3d view", ex));
    }
}

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

/**
 * Initializes the controller class.//from www. ja  v  a 2s .co  m
 */
@Override
public void initialize(URL url, ResourceBundle rb) {

    this.resourceBundle = rb;

    viewer3DPanelController.setResourceBundle(rb);

    initStrings(rb);

    colorPickerSeries.valueProperty().addListener(new ChangeListener<javafx.scene.paint.Color>() {
        @Override
        public void changed(ObservableValue<? extends javafx.scene.paint.Color> observable,
                javafx.scene.paint.Color oldValue, javafx.scene.paint.Color newValue) {
            if (listViewVoxelsFilesChart.getSelectionModel().getSelectedItems().size() == 1) {
                listViewVoxelsFilesChart.getSelectionModel().getSelectedItem().getSeriesParameters()
                        .setColor(new Color((float) newValue.getRed(), (float) newValue.getGreen(),
                                (float) newValue.getBlue(), 1.0f));
            }
        }
    });

    comboboxScript.getItems().setAll("Daniel script");

    vboxWeighting.disableProperty().bind(checkboxEnableWeighting.selectedProperty().not());

    checkboxEnableWeighting.selectedProperty().addListener(new ChangeListener<Boolean>() {
        @Override
        public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
            if (newValue && textAreaWeighting.getText().isEmpty()) {

                int selectedVoxTab = tabPaneVoxelisation.getSelectionModel().getSelectedIndex();

                if (selectedVoxTab == 0) { //ALS
                    fillWeightingData(EchoesWeightParams.DEFAULT_ALS_WEIGHTING);
                } else if (selectedVoxTab == 1) { //TLS
                    fillWeightingData(EchoesWeightParams.DEFAULT_TLS_WEIGHTING);
                }
            }
        }
    });

    /*comboboxTransMode.getItems().setAll(1, 2, 3);
    comboboxTransMode.getSelectionModel().selectFirst();
            
    comboboxPathLengthMode.getItems().setAll("A", "B");
    comboboxPathLengthMode.getSelectionModel().selectFirst();*/

    helpButtonNaNsCorrection.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            helpButtonNaNsCorrectionController.showHelpDialog(resourceBundle.getString("help_NaNs_correction"));
        }
    });

    helpButtonAutoBBox.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            helpButtonAutoBBoxController.showHelpDialog(resourceBundle.getString("help_bbox"));
        }
    });

    helpButtonHemiPhoto.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            helpButtonHemiPhotoController.showHelpDialog(resourceBundle.getString("help_hemiphoto"));
        }
    });

    buttonHelpEmptyShotsFilter.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            buttonHelpEmptyShotsFilterController
                    .showHelpDialog(resourceBundle.getString("help_empty_shots_filter"));
        }
    });

    /*work around, the divider positions values are defined in the fxml,
    but when the window is initialized the values are lost*/
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            splitPaneMain.setDividerPositions(0.75f);
            splitPaneVoxelization.setDividerPositions(0.45f);
        }
    });

    initValidationSupport();
    initPostProcessTab();

    listViewTransmittanceMapSensorPositions.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    listViewTaskList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

    MenuItem menuItemPadValue1m = new MenuItem("1m voxel size");
    addMenuItemPadValue(menuItemPadValue1m, 3.536958f);

    MenuItem menuItemPadValue2m = new MenuItem("2m voxel size");
    addMenuItemPadValue(menuItemPadValue2m, 2.262798f);

    MenuItem menuItemPadValue3m = new MenuItem("3m voxel size");
    addMenuItemPadValue(menuItemPadValue3m, 1.749859f);

    MenuItem menuItemPadValue4m = new MenuItem("4m voxel size");
    addMenuItemPadValue(menuItemPadValue4m, 1.3882959f);

    MenuItem menuItemPadValue5m = new MenuItem("5m voxel size");
    addMenuItemPadValue(menuItemPadValue5m, 1.0848f);

    menuButtonAdvisablePADMaxValues.getItems().addAll(menuItemPadValue1m, menuItemPadValue2m,
            menuItemPadValue3m, menuItemPadValue4m, menuItemPadValue5m);

    fileChooserSaveCanopyAnalyserOutputFile = new FileChooserContext();
    fileChooserSaveCanopyAnalyserCfgFile = new FileChooserContext();
    fileChooserSaveTransmittanceSimCfgFile = new FileChooserContext();
    fileChooserOpenCanopyAnalyserInputFile = new FileChooserContext();
    listViewCanopyAnalyzerSensorPositions.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

    ContextMenu contextMenuProductsList = new ContextMenu();
    MenuItem openImageItem = new MenuItem(RS_STR_OPEN_IMAGE);
    openImageItem.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            File selectedFile = listViewProductsFiles.getSelectionModel().getSelectedItem();

            showImage(selectedFile);
        }
    });

    Menu menuEdit = new Menu(RS_STR_EDIT);

    MenuItem menuItemEditVoxels = new MenuItem("Remove voxels (delete key)");
    MenuItem menuItemFitToContent = new MenuItem("Fit to content");
    MenuItem menuItemCrop = new MenuItem("Crop");

    menuEdit.getItems().setAll(menuItemEditVoxels, menuItemFitToContent, menuItemCrop);

    menuItemFitToContent.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            File selectedItem = listViewProductsFiles.getSelectionModel().getSelectedItem();

            if (selectedItem != null) {
                fitVoxelSpaceToContent(selectedItem);
            }
        }
    });

    menuItemEditVoxels.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {

            File selectedItem = listViewProductsFiles.getSelectionModel().getSelectedItem();

            if (selectedItem != null) {
                editVoxelSpace(selectedItem);
            }
        }
    });

    menuItemCrop.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {

            File selectedItem = listViewProductsFiles.getSelectionModel().getSelectedItem();

            if (selectedItem != null) {
                try {
                    voxelSpaceCroppingFrameController.setVoxelFile(selectedItem);
                    voxelSpaceCroppingFrame.show();
                } catch (Exception ex) {
                    showErrorDialog(ex);
                }
            }
        }
    });

    Menu menuExport = new Menu(RS_STR_EXPORT);
    MenuItem menuItemExportDartMaket = new MenuItem("Dart (maket.txt)");
    MenuItem menuItemExportDartPlots = new MenuItem("Dart (plots.xml)");
    MenuItem menuItemExportMeshObj = new MenuItem("Mesh (*.obj)");

    menuItemExportDartMaket.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {

            File selectedItem = listViewProductsFiles.getSelectionModel().getSelectedItem();

            if (selectedItem != null) {
                exportDartMaket(selectedItem);
            }
        }
    });

    menuItemExportDartPlots.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {

            File selectedItem = listViewProductsFiles.getSelectionModel().getSelectedItem();

            if (selectedItem != null) {
                exportDartPlots(selectedItem);
            }
        }
    });

    menuItemExportMeshObj.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {

            File selectedItem = listViewProductsFiles.getSelectionModel().getSelectedItem();

            if (selectedItem != null) {
                exportMeshObj(selectedItem);
            }
        }
    });

    menuExport.getItems().setAll(menuItemExportDartMaket, menuItemExportDartPlots, menuItemExportMeshObj);

    MenuItem menuItemInfo = new MenuItem(RS_STR_INFO);

    menuItemInfo.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {

            Alert alert = new Alert(AlertType.INFORMATION);

            File selectedItem = listViewProductsFiles.getSelectionModel().getSelectedItem();

            if (selectedItem != null) {
                VoxelFileReader reader;
                try {
                    reader = new VoxelFileReader(selectedItem);
                    VoxelSpaceInfos voxelSpaceInfos = reader.getVoxelSpaceInfos();
                    alert.setTitle("Information");
                    alert.setHeaderText("Voxel space informations");
                    alert.setContentText(voxelSpaceInfos.toString());
                    alert.show();
                } catch (Exception ex) {
                    showErrorDialog(ex);
                }

            }
        }
    });

    final MenuItem menuItemOpenContainingFolder = new MenuItem(RS_STR_OPEN_CONTAINING_FOLDER);

    menuItemOpenContainingFolder.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {

            final File selectedItem = listViewProductsFiles.getSelectionModel().getSelectedItem();

            if (selectedItem != null) {
                if (Desktop.isDesktopSupported()) {
                    new Thread(() -> {
                        try {
                            Desktop.getDesktop().open(selectedItem.getParentFile());
                        } catch (IOException ex) {
                            logger.error("Cannot open directory " + selectedItem);
                        }
                    }).start();
                }

            }

        }
    });

    listViewProductsFiles.setOnContextMenuRequested(new EventHandler<ContextMenuEvent>() {
        @Override
        public void handle(ContextMenuEvent event) {

            if (listViewProductsFiles.getSelectionModel().getSelectedIndices().size() == 1) {

                File selectedFile = listViewProductsFiles.getSelectionModel().getSelectedItem();
                String extension = FileManager.getExtension(selectedFile);

                switch (extension) {
                case ".png":
                case ".bmp":
                case ".jpg":
                    contextMenuProductsList.getItems().setAll(openImageItem, menuItemOpenContainingFolder);
                    contextMenuProductsList.show(listViewProductsFiles, event.getScreenX(), event.getScreenY());
                    break;
                case ".vox":

                default:
                    if (VoxelFileReader.isFileAVoxelFile(selectedFile)) {
                        contextMenuProductsList.getItems().setAll(menuItemInfo, menuItemOpenContainingFolder,
                                menuEdit, menuExport);
                        contextMenuProductsList.show(listViewProductsFiles, event.getScreenX(),
                                event.getScreenY());
                    }
                }

            }

        }
    });

    ContextMenu contextMenuLidarScanEdit = new ContextMenu();
    MenuItem editItem = new MenuItem("Edit");

    editItem.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {

            filterFrameController.setFilters("Reflectance", "Deviation", "Amplitude");
            filterFrame.show();

            filterFrame.setOnHidden(new EventHandler<WindowEvent>() {

                @Override
                public void handle(WindowEvent event) {

                    if (filterFrameController.getFilter() != null) {
                        ObservableList<LidarScan> items = listViewHemiPhotoScans.getSelectionModel()
                                .getSelectedItems();
                        for (LidarScan scan : items) {
                            scan.filters.add(filterFrameController.getFilter());
                        }
                    }
                }
            });
        }
    });

    contextMenuLidarScanEdit.getItems().add(editItem);

    listViewHemiPhotoScans.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    listViewHemiPhotoScans.setOnContextMenuRequested(new EventHandler<ContextMenuEvent>() {

        @Override
        public void handle(ContextMenuEvent event) {
            contextMenuLidarScanEdit.show(listViewHemiPhotoScans, event.getScreenX(), event.getScreenY());
        }
    });

    /**LAD tab initialization**/
    comboboxLADChoice.getItems().addAll(LeafAngleDistribution.Type.UNIFORM, LeafAngleDistribution.Type.SPHERIC,
            LeafAngleDistribution.Type.ERECTOPHILE, LeafAngleDistribution.Type.PLANOPHILE,
            LeafAngleDistribution.Type.EXTREMOPHILE, LeafAngleDistribution.Type.PLAGIOPHILE,
            LeafAngleDistribution.Type.HORIZONTAL, LeafAngleDistribution.Type.VERTICAL,
            LeafAngleDistribution.Type.ELLIPSOIDAL, LeafAngleDistribution.Type.ELLIPTICAL,
            LeafAngleDistribution.Type.TWO_PARAMETER_BETA);

    comboboxLADChoice.getSelectionModel().select(LeafAngleDistribution.Type.SPHERIC);
    comboboxLADChoice.getSelectionModel().selectedItemProperty()
            .addListener(new ChangeListener<LeafAngleDistribution.Type>() {

                @Override
                public void changed(ObservableValue<? extends LeafAngleDistribution.Type> observable,
                        LeafAngleDistribution.Type oldValue, LeafAngleDistribution.Type newValue) {

                    if (newValue == LeafAngleDistribution.Type.TWO_PARAMETER_BETA
                            || newValue == LeafAngleDistribution.Type.ELLIPSOIDAL) {

                        hboxTwoBetaParameters.setVisible(true);

                        if (newValue == LeafAngleDistribution.Type.ELLIPSOIDAL) {
                            labelLADBeta.setVisible(false);
                        } else {
                            labelLADBeta.setVisible(true);
                        }
                    } else {
                        hboxTwoBetaParameters.setVisible(false);
                    }
                }
            });

    ToggleGroup ladTypeGroup = new ToggleGroup();
    radiobuttonLADHomogeneous.setToggleGroup(ladTypeGroup);
    radiobuttonLADLocalEstimation.setToggleGroup(ladTypeGroup);

    /**CHART panel initialization**/

    ToggleGroup profileChartType = new ToggleGroup();
    radiobuttonPreDefinedProfile.setToggleGroup(profileChartType);
    radiobuttonFromVariableProfile.setToggleGroup(profileChartType);

    ToggleGroup profileChartRelativeHeightType = new ToggleGroup();
    radiobuttonHeightFromAboveGround.setToggleGroup(profileChartRelativeHeightType);
    radiobuttonHeightFromBelowCanopy.setToggleGroup(profileChartRelativeHeightType);

    comboboxFromVariableProfile.disableProperty().bind(radiobuttonPreDefinedProfile.selectedProperty());
    comboboxPreDefinedProfile.disableProperty().bind(radiobuttonFromVariableProfile.selectedProperty());

    hboxMaxPADVegetationProfile.visibleProperty().bind(radiobuttonPreDefinedProfile.selectedProperty());

    listViewVoxelsFilesChart.getSelectionModel().selectedIndexProperty()
            .addListener(new ChangeListener<Number>() {

                @Override
                public void changed(ObservableValue<? extends Number> observable, Number oldValue,
                        Number newValue) {

                    if (listViewVoxelsFilesChart.getSelectionModel().getSelectedItems().size() > 1) {
                        colorPickerSeries.setDisable(true);
                    } else if (listViewVoxelsFilesChart.getSelectionModel().getSelectedItems().size() == 1) {

                        VoxelFileChart selectedItem = listViewVoxelsFilesChart.getSelectionModel()
                                .getSelectedItem();
                        Color selectedItemColor = selectedItem.getSeriesParameters().getColor();

                        colorPickerSeries.setDisable(false);
                        colorPickerSeries.setValue(new javafx.scene.paint.Color(
                                selectedItemColor.getRed() / 255.0, selectedItemColor.getGreen() / 255.0,
                                selectedItemColor.getBlue() / 255.0, 1.0));

                        if (newValue.intValue() >= 0) {
                            textfieldLabelVoxelFileChart.setText(
                                    listViewVoxelsFilesChart.getItems().get(newValue.intValue()).label);
                        }
                    }
                }
            });

    textfieldLabelVoxelFileChart.textProperty().addListener(new ChangeListener<String>() {

        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {

            if (listViewVoxelsFilesChart.getSelectionModel().getSelectedIndex() >= 0) {
                listViewVoxelsFilesChart.getSelectionModel().getSelectedItem().label = newValue;
            }
        }
    });

    listViewVoxelsFilesChart.getItems().addListener(new ListChangeListener<VoxelFileChart>() {

        @Override
        public void onChanged(ListChangeListener.Change<? extends VoxelFileChart> c) {

            while (c.next()) {
            }

            if (c.wasAdded() && c.getAddedSize() == c.getList().size()) {

                try {
                    VoxelFileReader reader = new VoxelFileReader(c.getList().get(0).file);
                    String[] columnNames = reader.getVoxelSpaceInfos().getColumnNames();
                    comboboxFromVariableProfile.getItems().clear();
                    comboboxFromVariableProfile.getItems().addAll(columnNames);
                    comboboxFromVariableProfile.getSelectionModel().selectFirst();
                } catch (Exception ex) {
                    logger.error("Cannot read voxel file", ex);
                }
            }

        }
    });

    anchorpaneQuadrats.disableProperty().bind(checkboxMakeQuadrats.selectedProperty().not());

    comboboxSelectAxisForQuadrats.getItems().addAll("X", "Y", "Z");
    comboboxSelectAxisForQuadrats.getSelectionModel().select(1);

    comboboxPreDefinedProfile.getItems().addAll("Vegetation (PAD)");
    comboboxPreDefinedProfile.getSelectionModel().selectFirst();

    radiobuttonSplitCountForQuadrats.selectedProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
            textFieldSplitCountForQuadrats.setDisable(!newValue);
            textFieldLengthForQuadrats.setDisable(newValue);
        }
    });

    ToggleGroup chartMakeQuadratsSplitType = new ToggleGroup();
    radiobuttonLengthForQuadrats.setToggleGroup(chartMakeQuadratsSplitType);
    radiobuttonSplitCountForQuadrats.setToggleGroup(chartMakeQuadratsSplitType);

    /**Virtual measures panel initialization**/

    comboboxHemiPhotoBitmapOutputMode.getItems().addAll("Pixel", "Color");
    comboboxHemiPhotoBitmapOutputMode.getSelectionModel().selectFirst();

    ToggleGroup virtualMeasuresChoiceGroup = new ToggleGroup();

    toggleButtonLAI2000Choice.setToggleGroup(virtualMeasuresChoiceGroup);
    toggleButtonLAI2200Choice.setToggleGroup(virtualMeasuresChoiceGroup);

    comboboxChooseCanopyAnalyzerSampling.getItems().setAll(500, 4000, 10000);
    comboboxChooseCanopyAnalyzerSampling.getSelectionModel().selectFirst();

    initEchoFiltering();

    data = FXCollections.observableArrayList();

    tableViewSimulationPeriods.setItems(data);
    tableViewSimulationPeriods.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

    comboboxChooseDirectionsNumber.getItems().addAll(1, 6, 16, 46, 136, 406);
    comboboxChooseDirectionsNumber.getSelectionModel().select(4);

    ToggleGroup scannerPositionsMode = new ToggleGroup();

    /*radiobuttonScannerPosSquaredArea.setToggleGroup(scannerPositionsMode);
    radiobuttonScannerPosFile.setToggleGroup(scannerPositionsMode);*/

    tableColumnPeriod.setCellValueFactory(
            new Callback<TableColumn.CellDataFeatures<SimulationPeriod, String>, ObservableValue<String>>() {

                @Override
                public ObservableValue<String> call(
                        TableColumn.CellDataFeatures<SimulationPeriod, String> param) {
                    return new SimpleStringProperty(param.getValue().getPeriod().toString());
                }
            });

    tableColumnClearness.setCellValueFactory(
            new Callback<TableColumn.CellDataFeatures<SimulationPeriod, String>, ObservableValue<String>>() {

                @Override
                public ObservableValue<String> call(
                        TableColumn.CellDataFeatures<SimulationPeriod, String> param) {
                    return new SimpleStringProperty(String.valueOf(param.getValue().getClearnessCoefficient()));
                }
            });

    checkboxMultiFiles.selectedProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
            anchorpaneBoundingBoxParameters.setDisable(newValue);
        }
    });

    hboxGenerateBitmapFiles.disableProperty().bind(checkboxGenerateBitmapFile.selectedProperty().not());
    hboxGenerateTextFile.disableProperty().bind(checkboxGenerateTextFile.selectedProperty().not());

    fileChooserOpenConfiguration = new FileChooser();
    fileChooserOpenConfiguration.setTitle("Choose configuration file");

    fileChooserSaveConfiguration = new FileChooserContext("cfg.xml");
    fileChooserSaveConfiguration.fc.setTitle("Choose output file");

    fileChooserOpenInputFileALS = new FileChooser();
    fileChooserOpenInputFileALS.setTitle("Open input file");
    fileChooserOpenInputFileALS.getExtensionFilters().addAll(new ExtensionFilter("All Files", "*"),
            new ExtensionFilter("Shot files", "*.sht"), new ExtensionFilter("Text Files", "*.txt"),
            new ExtensionFilter("Las Files", "*.las", "*.laz"));

    fileChooserOpenTrajectoryFileALS = new FileChooser();
    fileChooserOpenTrajectoryFileALS.setTitle("Open trajectory file");
    fileChooserOpenTrajectoryFileALS.getExtensionFilters().addAll(new ExtensionFilter("All Files", "*"),
            new ExtensionFilter("Text Files", "*.txt"));

    fileChooserOpenOutputFileALS = new FileChooser();
    fileChooserOpenOutputFileALS.setTitle("Choose output file");

    fileChooserOpenInputFileTLS = new FileChooserContext();
    fileChooserOpenInputFileTLS.fc.setTitle("Open input file");
    fileChooserOpenInputFileTLS.fc.getExtensionFilters().addAll(new ExtensionFilter("All Files", "*"),
            new ExtensionFilter("Text Files", "*.txt"), new ExtensionFilter("Rxp Files", "*.rxp"),
            new ExtensionFilter("Project Rsp Files", "*.rsp"));

    directoryChooserOpenOutputPathTLS = new DirectoryChooser();
    directoryChooserOpenOutputPathTLS.setTitle("Choose output path");

    directoryChooserOpenOutputPathALS = new DirectoryChooser();
    directoryChooserOpenOutputPathALS.setTitle("Choose output path");

    fileChooserSaveOutputFileTLS = new FileChooser();
    fileChooserSaveOutputFileTLS.setTitle("Save voxel file");

    fileChooserSaveTransmittanceTextFile = new FileChooser();
    fileChooserSaveTransmittanceTextFile.setTitle("Save text file");

    directoryChooserSaveTransmittanceBitmapFile = new DirectoryChooser();
    directoryChooserSaveTransmittanceBitmapFile.setTitle("Choose output directory");

    fileChooserSaveHemiPhotoOutputBitmapFile = new FileChooserContext("*.png");
    fileChooserSaveHemiPhotoOutputBitmapFile.fc.setTitle("Save bitmap file");

    directoryChooserSaveHemiPhotoOutputBitmapFile = new DirectoryChooser();
    directoryChooserSaveHemiPhotoOutputBitmapFile.setTitle("Choose bitmap files output directory");

    directoryChooserSaveHemiPhotoOutputTextFile = new DirectoryChooser();
    directoryChooserSaveHemiPhotoOutputTextFile.setTitle("Choose text files output directory");

    fileChooserSaveHemiPhotoOutputTextFile = new FileChooser();
    fileChooserSaveHemiPhotoOutputTextFile.setTitle("Save text file");

    fileChooserOpenVoxelFile = new FileChooser();
    fileChooserOpenVoxelFile.setTitle("Open voxel file");
    fileChooserOpenVoxelFile.getExtensionFilters().addAll(new ExtensionFilter("All Files", "*"),
            new ExtensionFilter("Voxel Files", "*.vox"));

    fileChooserOpenPopMatrixFile = new FileChooser();
    fileChooserOpenPopMatrixFile.setTitle("Choose matrix file");
    fileChooserOpenPopMatrixFile.getExtensionFilters().addAll(new ExtensionFilter("All Files", "*"),
            new ExtensionFilter("Text Files", "*.txt"));

    fileChooserOpenSopMatrixFile = new FileChooser();
    fileChooserOpenSopMatrixFile.setTitle("Choose matrix file");
    fileChooserOpenSopMatrixFile.getExtensionFilters().addAll(new ExtensionFilter("All Files", "*"),
            new ExtensionFilter("Text Files", "*.txt"));

    fileChooserOpenVopMatrixFile = new FileChooser();
    fileChooserOpenVopMatrixFile.setTitle("Choose matrix file");
    fileChooserOpenVopMatrixFile.getExtensionFilters().addAll(new ExtensionFilter("All Files", "*"),
            new ExtensionFilter("Text Files", "*.txt"));

    fileChooserOpenPonderationFile = new FileChooser();
    fileChooserOpenPonderationFile.setTitle("Choose ponderation file");
    fileChooserOpenPonderationFile.getExtensionFilters().addAll(new ExtensionFilter("All Files", "*"),
            new ExtensionFilter("Text Files", "*.txt"));

    fileChooserOpenDTMFile = new FileChooser();
    fileChooserOpenDTMFile.setTitle("Choose DTM file");
    fileChooserOpenDTMFile.getExtensionFilters().addAll(new ExtensionFilter("All Files", "*"),
            new ExtensionFilter("DTM Files", "*.asc"));

    fileChooserOpenPointCloudFile = new FileChooser();
    fileChooserOpenPointCloudFile.setTitle("Choose point cloud file");
    fileChooserOpenPointCloudFile.getExtensionFilters().addAll(new ExtensionFilter("All Files", "*"),
            new ExtensionFilter("TXT Files", "*.txt"));

    fileChooserOpenMultiResVoxelFile = new FileChooser();
    fileChooserOpenMultiResVoxelFile.setTitle("Choose voxel file");
    fileChooserOpenMultiResVoxelFile.getExtensionFilters().addAll(new ExtensionFilter("All Files", "*"),
            new ExtensionFilter("Voxel Files", "*.vox"));

    fileChooserOpenOutputFileMultiRes = new FileChooser();
    fileChooserOpenOutputFileMultiRes.setTitle("Save voxel file");

    fileChooserAddTask = new FileChooser();
    fileChooserAddTask.setTitle("Choose parameter file");
    fileChooserAddTask.getExtensionFilters().addAll(new ExtensionFilter("All Files", "*"),
            new ExtensionFilter("XML Files", "*.xml"));

    fileChooserSaveDartFile = new FileChooser();
    fileChooserSaveDartFile.setTitle("Save dart file (.maket)");
    fileChooserSaveDartFile.getExtensionFilters().addAll(new ExtensionFilter("All Files", "*"),
            new ExtensionFilter("Maket File", "*.maket"));

    fileChooserOpenOutputFileMerging = new FileChooser();
    fileChooserOpenOutputFileMerging.setTitle("Choose voxel file");
    fileChooserOpenOutputFileMerging.getExtensionFilters().addAll(new ExtensionFilter("All Files", "*"),
            new ExtensionFilter("Voxel Files", "*.vox"));

    fileChooserOpenScriptFile = new FileChooser();
    fileChooserOpenScriptFile.setTitle("Choose script file");

    fileChooserSaveGroundEnergyOutputFile = new FileChooser();
    fileChooserSaveGroundEnergyOutputFile.setTitle("Save ground energy file");

    fileChooserOpenPointsPositionFile = new FileChooser();
    fileChooserOpenPointsPositionFile.setTitle("Choose points file");
    fileChooserOpenPointsPositionFile.getExtensionFilters().addAll(new ExtensionFilter("All Files", "*"),
            new ExtensionFilter("TXT Files", "*.txt"));

    try {
        viewCapsSetupFrame = new Stage();
        FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/ViewCapsSetupFrame.fxml"));
        Parent root = loader.load();
        viewCapsSetupFrameController = loader.getController();
        viewCapsSetupFrame.setScene(new Scene(root));
    } catch (IOException ex) {
        logger.error("Cannot load fxml file", ex);
    }

    try {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/FilteringPaneComponent.fxml"));
        anchorPaneEchoFilteringRxp = loader.load();
        filteringPaneController = loader.getController();
        filteringPaneController.setFiltersNames("Reflectance", "Amplitude", "Deviation");
    } catch (IOException ex) {
        logger.error("Cannot load fxml file", ex);
    }

    try {
        positionImporterFrame = new Stage();
        FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/PositionImporterFrame.fxml"));
        Parent root = loader.load();
        positionImporterFrameController = loader.getController();
        positionImporterFrame.setScene(new Scene(root));
        positionImporterFrameController.setStage(positionImporterFrame);
    } catch (IOException ex) {
        logger.error("Cannot load fxml file", ex);
    }

    try {
        voxelSpaceCroppingFrame = new Stage();
        FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/VoxelSpaceCroppingFrame.fxml"));
        Parent root = loader.load();
        voxelSpaceCroppingFrameController = loader.getController();
        voxelSpaceCroppingFrame.setScene(new Scene(root));
    } catch (IOException ex) {
        logger.error("Cannot load fxml file", ex);
    }

    try {
        attributsImporterFrame = new Stage();
        FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/AttributsImporterFrame.fxml"));
        Parent root = loader.load();
        attributsImporterFrameController = loader.getController();
        attributsImporterFrame.setScene(new Scene(root));
        attributsImporterFrameController.setStage(attributsImporterFrame);
    } catch (IOException ex) {
        logger.error("Cannot load fxml file", ex);
    }

    try {
        textFileParserFrameController = TextFileParserFrameController.getInstance();
    } catch (Exception ex) {
        logger.error("Cannot load fxml file", ex);
    }

    try {
        transformationFrameController = TransformationFrameController.getInstance();
        transformationFrame = transformationFrameController.getStage();
    } catch (Exception ex) {
        logger.error("Cannot load fxml file", ex);
    }

    updaterFrame = new Stage();

    try {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/update/UpdaterFrame.fxml"));
        Parent root = loader.load();
        updaterFrameController = loader.getController();
        updaterFrame.setScene(new Scene(root));

    } catch (IOException ex) {
        logger.error("Cannot load fxml file", ex);
    }

    riscanProjectExtractor = new RiscanProjectExtractor();
    ptxProjectExtractor = new PTXProjectExtractor();
    ptgProjectExtractor = new PTGProjectExtractor();

    dateChooserFrame = new Stage();

    try {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/DateChooserFrame.fxml"));
        Parent root = loader.load();
        dateChooserFrameController = loader.getController();
        dateChooserFrame.setScene(new Scene(root));
        dateChooserFrameController.setStage(dateChooserFrame);
    } catch (IOException ex) {
        logger.error("Cannot load fxml file", ex);
    }

    comboboxModeALS.getItems().addAll(RS_STR_INPUT_TYPE_LAS, RS_STR_INPUT_TYPE_LAZ,
            /*RS_STR_INPUT_TYPE_XYZ, */RS_STR_INPUT_TYPE_SHOTS);

    comboboxModeALS.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {

            if (newValue.equals(RS_STR_INPUT_TYPE_SHOTS)) {
                alsVoxValidationSupport.registerValidator(textFieldTrajectoryFileALS, false,
                        Validators.unregisterValidator);
            } else {
                alsVoxValidationSupport.registerValidator(textFieldTrajectoryFileALS, false,
                        Validators.fileExistValidator);
            }
        }
    });

    comboboxModeTLS.getItems().setAll("Rxp scan", "Rsp project", "PTX",
            "PTG"/*, RS_STR_INPUT_TYPE_XYZ, RS_STR_INPUT_TYPE_SHOTS*/);
    comboboxGroundEnergyOutputFormat.getItems().setAll("txt", "png");

    comboboxLaserSpecification.getItems().addAll(LaserSpecification.getPresets());

    comboboxLaserSpecification.getSelectionModel().selectedItemProperty()
            .addListener(new ChangeListener<LaserSpecification>() {
                @Override
                public void changed(ObservableValue<? extends LaserSpecification> observable,
                        LaserSpecification oldValue, LaserSpecification newValue) {
                    DecimalFormatSymbols symb = new DecimalFormatSymbols();
                    symb.setDecimalSeparator('.');
                    DecimalFormat formatter = new DecimalFormat("#####.######", symb);

                    textFieldBeamDiameterAtExit.setText(formatter.format(newValue.getBeamDiameterAtExit()));
                    textFieldBeamDivergence.setText(formatter.format(newValue.getBeamDivergence()));
                }
            });

    comboboxLaserSpecification.getSelectionModel().select(LaserSpecification.LMS_Q560);

    comboboxLaserSpecification.disableProperty().bind(checkboxCustomLaserSpecification.selectedProperty());
    textFieldBeamDiameterAtExit.disableProperty()
            .bind(checkboxCustomLaserSpecification.selectedProperty().not());
    textFieldBeamDivergence.disableProperty().bind(checkboxCustomLaserSpecification.selectedProperty().not());

    listViewProductsFiles.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

    listViewProductsFiles.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
            int size = listViewProductsFiles.getSelectionModel().getSelectedIndices().size();

            if (size == 1) {
                viewer3DPanelController
                        .updateCurrentVoxelFile(listViewProductsFiles.getSelectionModel().getSelectedItem());
            }
        }
    });

    listViewTaskList.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
            int size = listViewTaskList.getSelectionModel().getSelectedIndices().size();

            if (size == 1) {
                buttonLoadSelectedTask.setDisable(false);
            } else {
                buttonLoadSelectedTask.setDisable(true);
            }

            buttonExecute.setDisable(size == 0);
        }
    });

    resetMatrices();

    calculateMatrixFrame = new Stage();

    try {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/CalculateMatrixFrame.fxml"));
        Parent root = loader.load();
        calculateMatrixFrameController = loader.getController();
        calculateMatrixFrameController.setStage(calculateMatrixFrame);
        Scene scene = new Scene(root);
        calculateMatrixFrame.setScene(scene);
    } catch (IOException ex) {
        logger.error("Cannot load fxml file", ex);
    }

    filterFrame = new Stage();

    try {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/FilterFrame.fxml"));
        Parent root = loader.load();
        filterFrameController = loader.getController();
        filterFrameController.setStage(filterFrame);
        filterFrameController.setFilters("Angle");
        filterFrame.setScene(new Scene(root));
    } catch (IOException ex) {
        logger.error("Cannot load fxml file", ex);
    }

    try {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/export/ObjExporterDialog.fxml"));
        Parent root = loader.load();
        objExporterController = loader.getController();
        Stage s = new Stage();
        objExporterController.setStage(s);
        s.setScene(new Scene(root));
    } catch (IOException ex) {
        logger.error("Cannot load fxml file", ex);
    }

    textFieldResolution.textProperty().addListener(new ChangeListener<String>() {
        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            voxelSpacePanelVoxelizationController.setResolution(Float.valueOf(newValue));
        }
    });

    textFieldResolution.textProperty().addListener(voxelSpacePanelVoxelizationController.getChangeListener());

    checkboxUseDTMFilter.selectedProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {

            if (checkboxUseDTMFilter.isSelected()) {
                buttonOpenDTMFile.setDisable(false);
                textfieldDTMPath.setDisable(false);
                textfieldDTMValue.setDisable(false);
                checkboxApplyVOPMatrix.setDisable(false);
                labelDTMValue.setDisable(false);
                labelDTMPath.setDisable(false);
            } else {
                buttonOpenDTMFile.setDisable(true);
                textfieldDTMPath.setDisable(true);
                textfieldDTMValue.setDisable(true);
                checkboxApplyVOPMatrix.setDisable(true);
                labelDTMValue.setDisable(true);
                labelDTMPath.setDisable(true);
            }
        }
    });

    checkboxUseVopMatrix.selectedProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
            buttonSetVOPMatrix.setDisable(!newValue);
        }
    });

    checkboxUsePopMatrix.selectedProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
            if (newValue) {
                checkBoxUseDefaultPopMatrix.setDisable(false);
                buttonOpenPopMatrixFile.setDisable(false);
            } else {
                checkBoxUseDefaultPopMatrix.setDisable(true);
                buttonOpenPopMatrixFile.setDisable(true);
            }
        }
    });

    checkboxUseSopMatrix.selectedProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
            if (newValue) {
                checkBoxUseDefaultSopMatrix.setDisable(false);
                buttonOpenSopMatrixFile.setDisable(false);
            } else {
                checkBoxUseDefaultSopMatrix.setDisable(true);
                buttonOpenSopMatrixFile.setDisable(true);
            }
        }
    });

    checkboxCalculateGroundEnergy.selectedProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
            if (newValue) {
                anchorPaneGroundEnergyParameters.setDisable(false);
            } else {
                anchorPaneGroundEnergyParameters.setDisable(true);
            }
        }
    });

    listviewRxpScans.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<LidarScan>() {

        @Override
        public void changed(ObservableValue<? extends LidarScan> observable, LidarScan oldValue,
                LidarScan newValue) {
            if (newValue != null) {
                sopMatrix = newValue.matrix;
                updateResultMatrix();
            }
        }
    });

    comboboxModeTLS.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {

            switch (newValue.intValue()) {

            case 1:
            case 2:
            case 3:
                listviewRxpScans.setDisable(false);
                checkboxMergeAfter.setDisable(false);
                textFieldMergedFileName.setDisable(false);
                disableSopMatrixChoice(false);
                labelTLSOutputPath.setText("Output path");
                break;

            default:
                listviewRxpScans.setDisable(true);
                checkboxMergeAfter.setDisable(true);
                textFieldMergedFileName.setDisable(true);
                //disableSopMatrixChoice(true);
                labelTLSOutputPath.setText("Output file");
            }

            if (newValue.intValue() == 0 || newValue.intValue() == 1) {
                checkboxEmptyShotsFilter.setDisable(false);
            } else {
                checkboxEmptyShotsFilter.setDisable(true);
            }
        }
    });

    tabPaneVoxelisation.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {

            switch (newValue.intValue()) {

            case 1:
                disableSopMatrixChoice(false);
                disablePopMatrixChoice(false);
                checkboxEmptyShotsFilter.setDisable(false);
                break;

            default:
                disableSopMatrixChoice(true);
                disablePopMatrixChoice(true);
                checkboxEmptyShotsFilter.setDisable(true);
            }

            switch (newValue.intValue()) {
            case 0:
                checkboxCalculateGroundEnergy.setDisable(false);

                if (checkboxCalculateGroundEnergy.isSelected()) {
                    anchorPaneGroundEnergyParameters.setDisable(true);
                    checkboxCalculateGroundEnergy.setDisable(false);

                }

                anchorPaneEchoFiltering.getChildren().set(0, anchorPaneEchoFilteringClassifications);

                //anchorPaneEchoFilteringClassifications.setVisible(true);
                anchorpaneBoundingBoxParameters.setDisable(checkboxMultiFiles.isSelected());
                hboxAutomaticBBox.setDisable(false);
                break;
            default:
                anchorPaneGroundEnergyParameters.setDisable(true);
                checkboxCalculateGroundEnergy.setDisable(true);
                anchorPaneEchoFiltering.getChildren().set(0, anchorPaneEchoFilteringRxp);
                //anchorPaneEchoFilteringClassifications.setVisible(false);
                anchorpaneBoundingBoxParameters.setDisable(false);
                hboxAutomaticBBox.setDisable(true);
            }
        }
    });

    int availableCores = Runtime.getRuntime().availableProcessors();

    sliderRSPCoresToUse.setMin(1);
    sliderRSPCoresToUse.setMax(availableCores);
    sliderRSPCoresToUse.setValue(availableCores);

    textFieldInputFileALS.setOnDragOver(DragAndDropHelper.dragOverEvent);
    textFieldTrajectoryFileALS.setOnDragOver(DragAndDropHelper.dragOverEvent);
    textFieldOutputFileALS.setOnDragOver(DragAndDropHelper.dragOverEvent);
    textFieldInputFileTLS.setOnDragOver(DragAndDropHelper.dragOverEvent);
    textFieldOutputFileMerging.setOnDragOver(DragAndDropHelper.dragOverEvent);
    textfieldDTMPath.setOnDragOver(DragAndDropHelper.dragOverEvent);
    textFieldOutputFileGroundEnergy.setOnDragOver(DragAndDropHelper.dragOverEvent);
    listViewTaskList.setOnDragOver(DragAndDropHelper.dragOverEvent);
    listViewProductsFiles.setOnDragOver(DragAndDropHelper.dragOverEvent);
    textfieldVoxelFilePathTransmittance.setOnDragOver(DragAndDropHelper.dragOverEvent);
    textfieldOutputTextFilePath.setOnDragOver(DragAndDropHelper.dragOverEvent);
    textfieldOutputBitmapFilePath.setOnDragOver(DragAndDropHelper.dragOverEvent);

    textFieldInputFileALS.setOnDragDropped(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent event) {
            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasFiles() && db.getFiles().size() == 1) {
                success = true;
                for (File file : db.getFiles()) {
                    if (file != null) {
                        textFieldInputFileALS.setText(file.getAbsolutePath());
                        selectALSInputMode(file);
                    }
                }
            }
            event.setDropCompleted(success);
            event.consume();
        }
    });
    textFieldTrajectoryFileALS.setOnDragDropped(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent event) {
            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasFiles() && db.getFiles().size() == 1) {
                success = true;
                for (File file : db.getFiles()) {
                    if (file != null) {
                        onTrajectoryFileChoosed(file);
                    }
                }
            }
            event.setDropCompleted(success);
            event.consume();
        }
    });

    textFieldInputFileTLS.setOnDragDropped(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent event) {
            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasFiles() && db.getFiles().size() == 1) {
                success = true;
                for (File file : db.getFiles()) {
                    if (file != null) {
                        onInputFileTLSChoosed(file);
                    }
                }
            }
            event.setDropCompleted(success);
            event.consume();
        }
    });

    setDragDroppedSingleFileEvent(textFieldOutputFileALS);
    setDragDroppedSingleFileEvent(textFieldOutputFileMerging);
    setDragDroppedSingleFileEvent(textfieldDTMPath);
    setDragDroppedSingleFileEvent(textFieldOutputFileGroundEnergy);
    setDragDroppedSingleFileEvent(textfieldVoxelFilePathTransmittance);
    setDragDroppedSingleFileEvent(textfieldOutputTextFilePath);
    setDragDroppedSingleFileEvent(textfieldOutputBitmapFilePath);

    listViewTaskList.setOnDragDropped(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent event) {
            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasFiles()) {
                success = true;
                for (File file : db.getFiles()) {
                    addFileToTaskList(file);
                }
            }
            event.setDropCompleted(success);
            event.consume();
        }
    });

    listViewProductsFiles.setOnDragDropped(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent event) {
            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasFiles()) {
                success = true;
                for (File file : db.getFiles()) {
                    addFileToProductsList(file);
                }
            }
            event.setDropCompleted(success);
            event.consume();
        }
    });

    listViewProductsFiles.setOnDragDetected(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent event) {

            Dragboard db = listViewProductsFiles.startDragAndDrop(TransferMode.COPY);

            ClipboardContent content = new ClipboardContent();
            content.putFiles(listViewProductsFiles.getSelectionModel().getSelectedItems());
            db.setContent(content);

            event.consume();
        }
    });

    addPointcloudFilterComponent();

    checkboxUsePointcloudFilter.selectedProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {

            hBoxPointCloudFiltering.setDisable(!newValue);

            ObservableList<Node> list = vBoxPointCloudFiltering.getChildren();
            for (Node n : list) {
                if (n instanceof PointCloudFilterPaneComponent) {

                    PointCloudFilterPaneComponent panel = (PointCloudFilterPaneComponent) n;
                    panel.disableContent(!newValue);
                }
            }

            buttonAddPointcloudFilter.setDisable(!newValue);

        }
    });

    //displayGThetaAllDistributions();
}