Example usage for javafx.stage FileChooser showSaveDialog

List of usage examples for javafx.stage FileChooser showSaveDialog

Introduction

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

Prototype

public File showSaveDialog(final Window ownerWindow) 

Source Link

Document

Shows a new file save dialog.

Usage

From source file:de.hs.mannheim.modUro.controller.diagram.fx.ChartViewer.java

/**
 * A handler for the export to SVG option in the context menu.
 *//*from   w  w  w .j  a v  a  2s.  c  om*/
private void handleExportToSVG() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export to SVG");
    fileChooser.setSelectedExtensionFilter(
            new FileChooser.ExtensionFilter("Scalable Vector Graphics (SVG)", "svg"));
    File file = fileChooser.showSaveDialog(this.getScene().getWindow());
    if (file != null) {
        ExportUtils.writeAsSVG(this.chart, (int) getWidth(), (int) getHeight(), file);
    }
}

From source file:com.ggvaidya.scinames.ui.BulkChangeEditorController.java

@FXML
private void backupCurrentDataset(ActionEvent evt) {
    // We just need to save this somewhere that isn't the project's actual file location.
    File currentFile = project.getFile();

    FileChooser chooser = new FileChooser();
    chooser.setTitle("Save project to ...");
    chooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("Project XML.gz file", "*.xml.gz"));
    File f = chooser.showSaveDialog(bulkChangeEditor.getStage());
    if (f != null) {
        project.setFile(f);// w w w  .j av a 2s .  co  m

        try {
            SciNames.reportMemoryStatus("Saving project " + project + " to disk");
            project.saveToFile();
            SciNames.reportMemoryStatus("Project saved to disk");

            new Alert(Alert.AlertType.INFORMATION,
                    "Project saved as " + f + "; subsequent saves will return to " + currentFile).showAndWait();
        } catch (IOException ex) {
            new Alert(Alert.AlertType.ERROR, "Could not save project to file '" + f + "': " + ex).showAndWait();
        }
    }

    project.setFile(currentFile);
}

From source file:de.hs.mannheim.modUro.controller.diagram.fx.ChartViewer.java

/**
 * A handler for the export to PNG option in the context menu.
 *//* w ww  .  j av a 2  s.  c o m*/
private void handleExportToPNG() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export to PNG");
    fileChooser.setSelectedExtensionFilter(
            new FileChooser.ExtensionFilter("Portable Network Graphics (PNG)", "png"));
    File file = fileChooser.showSaveDialog(this.getScene().getWindow());
    if (file != null) {
        try {
            ExportUtils.writeAsPNG(this.chart, (int) getWidth(), (int) getHeight(), file);
        } catch (IOException ex) {
            // FIXME: show a dialog with the error
        }
    }
}

From source file:com.ggvaidya.scinames.ui.BulkChangeEditorController.java

@FXML
private void exportToCSV(ActionEvent evt) {
    FileChooser chooser = new FileChooser();
    chooser.getExtensionFilters().setAll(new FileChooser.ExtensionFilter("CSV file", "*.csv"),
            new FileChooser.ExtensionFilter("Tab-delimited file", "*.txt"));
    File file = chooser.showSaveDialog(bulkChangeEditor.getStage());
    if (file != null) {
        CSVFormat format = CSVFormat.RFC4180;

        String outputFormat = chooser.getSelectedExtensionFilter().getDescription();
        if (outputFormat.equalsIgnoreCase("Tab-delimited file"))
            format = CSVFormat.TDF;/*from www  .j  a  v  a2s .co m*/

        try {
            List<List<String>> dataAsTable = getDataAsTable();
            fillCSVFormat(format, new FileWriter(file), dataAsTable);

            Alert window = new Alert(Alert.AlertType.CONFIRMATION,
                    "CSV file '" + file + "' saved with " + (dataAsTable.get(0).size() - 1) + " rows.");
            window.showAndWait();

        } catch (IOException e) {
            Alert window = new Alert(Alert.AlertType.ERROR, "Could not save CSV to '" + file + "': " + e);
            window.showAndWait();
        }
    }
}

From source file:org.nmrfx.processor.gui.MainApp.java

private void saveProjectAs() {
    FileChooser chooser = new FileChooser();
    chooser.setTitle("Project Creator");
    File directoryFile = chooser.showSaveDialog(null);
    if (directoryFile != null) {
        GUIProject activeProject = getActive();
        if (activeProject != null) {
            GUIProject newProject = GUIProject.replace(appName, activeProject);

            try {
                newProject.createProject(directoryFile.toPath());
                newProject.saveProject();
            } catch (IOException ex) {
                ExceptionDialog dialog = new ExceptionDialog(ex);
                dialog.showAndWait();//from w w w.j a  v  a  2 s  . co  m
            }
        }
    }

}

From source file:be.makercafe.apps.makerbench.editors.JFXMillEditor.java

private void handleExportAsGCodeFile(ActionEvent e) {

    if (millObject == null) {
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Oeps an error occured");
        alert.setHeaderText("Cannot export gcode. There is no geometry !");
        alert.setContentText("Please verify that your code generates a valid millcrum object.");
        alert.showAndWait();//from   w  ww  .j a v  a 2  s .c o  m
        return;
    }

    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export GCODE File");
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("GCODE files (*.gcode)", "*.tap"));

    File f = fileChooser.showSaveDialog(null);

    if (f == null) {
        return;
    }

    String fName = f.getAbsolutePath();

    if (!fName.toLowerCase().endsWith(".gcode")) {
        fName += ".gcode";
    }

    try {
        millObject.get();
        FileUtils.write(new File(fName), millObject.getToSaveGcode());
    } catch (IOException ex) {

        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Oeps an error occured");
        alert.setHeaderText("Cannot export gcode. There went something wrong writing the file.");
        alert.setContentText(
                "Please verify that your file is not read only, is not locked by other user or program, you have enough diskspace.");
        alert.showAndWait();
    }
}

From source file:org.noroomattheinn.visibletesla.TripController.java

@FXML
void exportItHandler(ActionEvent event) {
    String initialDir = prefs.storage().get(App.LastExportDirKey, System.getProperty("user.home"));
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export Trip as KMZ");
    fileChooser.setInitialDirectory(new File(initialDir));

    File file = fileChooser.showSaveDialog(app.stage);
    if (file != null) {
        String enclosingDirectory = file.getParent();
        if (enclosingDirectory != null)
            prefs.storage().put(App.LastExportDirKey, enclosingDirectory);
        if (vtData.exportTripsAsKML(getSelectedTrips(), file)) {
            Dialogs.showInformationDialog(app.stage, "Your data has been exported", "Data Export Process",
                    "Export Complete");
        } else {// www.  j a v a2  s . c o  m
            Dialogs.showWarningDialog(app.stage, "There was a problem exporting your trip data to KMZ",
                    "Data Export Process", "Export Failed");
        }
    }
}

From source file:be.makercafe.apps.makerbench.editors.JFXMillEditor.java

private void handleExportAsPngFile(ActionEvent e) {

    if (millObject == null) {
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Oeps an error occured");
        alert.setHeaderText("Cannot export PNG. There is no geometry !");
        alert.setContentText("Please verify that your code generates a valid CSG object.");
        alert.showAndWait();//from w w  w.  j av a 2s  .  c o m
        return;
    }

    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export PNG File");
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Image files (*.png)", "*.png"));

    File f = fileChooser.showSaveDialog(null);

    if (f == null) {
        return;
    }

    String fName = f.getAbsolutePath();

    if (!fName.toLowerCase().endsWith(".png")) {
        fName += ".png";
    }

    int snWidth = 1024;
    int snHeight = 1024;

    double realWidth = viewGroup.getBoundsInLocal().getWidth();
    double realHeight = viewGroup.getBoundsInLocal().getHeight();

    double scaleX = snWidth / realWidth;
    double scaleY = snHeight / realHeight;

    double scale = Math.min(scaleX, scaleY);

    PerspectiveCamera snCam = new PerspectiveCamera(false);
    snCam.setTranslateZ(-200);

    SnapshotParameters snapshotParameters = new SnapshotParameters();
    snapshotParameters.setTransform(new Scale(scale, scale));
    snapshotParameters.setCamera(snCam);
    snapshotParameters.setDepthBuffer(true);
    snapshotParameters.setFill(Color.TRANSPARENT);

    WritableImage snapshot = new WritableImage(snWidth, (int) (realHeight * scale));

    viewGroup.snapshot(snapshotParameters, snapshot);

    try {
        ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), "png", new File(fName));
    } catch (IOException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Oeps an error occured");
        alert.setHeaderText("Cannot export PNG. There went something wrong writing the file.");
        alert.setContentText(
                "Please verify that your file is not read only, is not locked by other user or program, you have enough diskspace.");
        alert.showAndWait();
    }
}

From source file:eu.mihosoft.vrl.fxscad.MainController.java

@FXML
private void onExportAsSTLFile(ActionEvent e) {

    if (csgObject == null) {
        Action response = Dialogs.create().title("Error").message("Cannot export STL. There is no geometry :(")
                .lightweight().showError();

        return;/* w  ww .  jav  a 2  s  . c o m*/
    }

    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export STL File");
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("STL files (*.stl)", "*.stl"));

    File f = fileChooser.showSaveDialog(null);

    if (f == null) {
        return;
    }

    String fName = f.getAbsolutePath();

    if (!fName.toLowerCase().endsWith(".stl")) {
        fName += ".stl";
    }

    try {
        eu.mihosoft.vrl.v3d.FileUtil.write(Paths.get(fName), csgObject.toStlString());
    } catch (IOException ex) {
        Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:io.github.mzmine.util.jfreechart.JFreeChartUtils.java

public static void showSaveDialog(ChartViewer chartNode, ImgFileType fileType) {
    FileChooser fileChooser = new FileChooser();
    switch (fileType) {

    case JPG:/*w  w w .  j  a  v a 2  s  .  c o  m*/
        fileChooser.setTitle("Export to JPG");
        fileChooser.getExtensionFilters().add(new ExtensionFilter("JPEG", "*.jpg"));
        break;

    case PNG:
        fileChooser.setTitle("Export to PNG");
        fileChooser.getExtensionFilters().add(new ExtensionFilter("Portable Network Graphics (PNG)", "*.png"));
        break;

    case SVG:
        fileChooser.setTitle("Export to SVG");
        fileChooser.getExtensionFilters().add(new ExtensionFilter("Scalable Vector Graphics (SVG)", "*.svg"));
        break;

    case PDF:
        fileChooser.setTitle("Export to PDF");
        fileChooser.getExtensionFilters().add(new ExtensionFilter("Portable Document Format (PDF)", "*.pdf"));
        break;

    case EMF:
        fileChooser.setTitle("Export to EMF");
        fileChooser.getExtensionFilters().add(new ExtensionFilter("EMF image", "*.emf"));
        break;

    case EPS:
        fileChooser.setTitle("Export to EPS");
        fileChooser.getExtensionFilters().add(new ExtensionFilter("EPS Image", "*.eps"));
        break;
    }

    // Remember last directory
    if (lastSaveDirectory != null && lastSaveDirectory.isDirectory())
        fileChooser.setInitialDirectory(lastSaveDirectory);

    // Show the file chooser
    File file = fileChooser.showSaveDialog(chartNode.getScene().getWindow());

    // If nothing was chosen, quit
    if (file == null)
        return;

    // Save the last open directory
    lastSaveDirectory = file.getParentFile();

    // Do the export in a new thread
    final File finalFile = file;
    new Thread(() -> {
        exportToImageFile(chartNode, finalFile, fileType);
    }).start();
}