Example usage for javafx.stage FileChooser setInitialFileName

List of usage examples for javafx.stage FileChooser setInitialFileName

Introduction

In this page you can find the example usage for javafx.stage FileChooser setInitialFileName.

Prototype

public final void setInitialFileName(final String value) 

Source Link

Usage

From source file:de.bayern.gdi.gui.Controller.java

/**
 * Handle config saving./*from w  w  w.java 2 s.c  om*/
 *
 * @param event The event.
 */
@FXML
protected void handleSaveConfig(ActionEvent event) {
    extractStoredQuery();
    extractBoundingBox();
    extractCql();
    if (validateInput() && validateCqlInput()) {
        FileChooser fileChooser = new FileChooser();
        DirectoryChooser dirChooser = new DirectoryChooser();
        File downloadDir;
        File initDir;

        dirChooser.setTitle(I18n.getMsg("gui.save-dir"));

        if (downloadConfig == null) {
            downloadDir = dirChooser.showDialog(getPrimaryStage());
            String basedir = Config.getInstance().getServices().getBaseDirectory();
            initDir = new File(basedir.isEmpty() ? System.getProperty(USER_DIR) : basedir);
            File uniqueName = Misc.uniqueFile(downloadDir, "config", "xml", null);
            fileChooser.setInitialFileName(uniqueName.getName());
        } else {
            File downloadInitDir = new File(downloadConfig.getDownloadPath());
            if (!downloadInitDir.exists()) {
                downloadInitDir = new File(System.getProperty(USER_DIR));
            }
            dirChooser.setInitialDirectory(downloadInitDir);
            downloadDir = dirChooser.showDialog(getPrimaryStage());

            String path = downloadConfig.getFile().getAbsolutePath();
            path = path.substring(0, path.lastIndexOf(File.separator));
            initDir = new File(path);
            fileChooser.setInitialFileName(downloadConfig.getFile().getName());
        }
        fileChooser.setInitialDirectory(initDir);
        FileChooser.ExtensionFilter xmlFilter = new FileChooser.ExtensionFilter("xml files (*.xml)", "*.xml");
        fileChooser.getExtensionFilters().add(xmlFilter);
        fileChooser.setSelectedExtensionFilter(xmlFilter);
        fileChooser.setTitle(I18n.getMsg("gui.save-conf"));
        File configFile = fileChooser.showSaveDialog(getPrimaryStage());
        if (configFile == null) {
            return;
        }

        if (!configFile.toString().endsWith(".xml")) {
            configFile = new File(configFile.toString() + ".xml");
        }

        this.dataBean.setProcessingSteps(extractProcessingSteps());

        String savePath = downloadDir.getPath();
        DownloadStep ds = dataBean.convertToDownloadStep(savePath);
        try {
            ds.write(configFile);
        } catch (IOException ex) {
            log.warn(ex.getMessage(), ex);
        }
    }
}

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

@FXML
private void onActionButtonExportALSLidarShots(ActionEvent event) {

    File alsFile = new File(textFieldInputFileALS.getText());

    if (!alsFile.exists()) {
        showErrorDialog(new Exception("File does not exist."));
        return;//from w w w.j  av a 2  s .  c  om
    } else if (!alsFile.isFile()) {
        showErrorDialog(new Exception("Input is not a file."));
        return;
    } else if (trajectoryFile == null || !trajectoryFile.exists() || !trajectoryFile.isFile()) {
        showErrorDialog(new Exception("Invalid trajectory file."));
        return;
    }

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

    if (selectedFile == null) {
        return;
    }

    while (!selectedFile.getName().endsWith(".sht")) {

        fc.setInitialFileName(selectedFile.getName() + ".sht");
        fc.setInitialDirectory(new File(selectedFile.getParent()));
        selectedFile = fc.showSaveDialog(stage);

        if (selectedFile == null) {
            return;
        }
    }

    PointsToShot pts = new PointsToShot(trajectoryFile, alsFile,
            MatrixUtility.convertMatrix4dToMat4D(vopMatrix));

    try {
        pts.init();
    } catch (Exception ex) {
        showErrorDialog(ex);
        return;
    }

    try {
        pts.write(selectedFile);
    } catch (Exception ex) {
        showErrorDialog(ex);
    }
}