Example usage for javafx.stage FileChooser FileChooser

List of usage examples for javafx.stage FileChooser FileChooser

Introduction

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

Prototype

FileChooser

Source Link

Usage

From source file:com.github.douglasjunior.simpleCSVEditor.FXMLController.java

private File openFileChooser() {
    if (fileChooser == null) {
        fileChooser = new FileChooser();
        fileChooser.setTitle("Abrir Arquivo");
        fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
        fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("CSV", "*.csv"));
    }//from w ww  . jav a 2s  .  c om
    return fileChooser.showOpenDialog(root.getScene().getWindow());
}

From source file:ExcelFx.FXMLDocumentController.java

@FXML
private void Print(ActionEvent event) throws IOException {

    System.out.println("Pressed print button");

    FileChooser chooser = new FileChooser();

    chooser.setTitle("Open File");
    File file = chooser.showSaveDialog(this.SplitPane.getScene().getWindow());
    System.out.println(file.getAbsolutePath());

    printXls(file.getAbsolutePath(), sortProf);

    System.out.println("Print finished");
    System.out.println("-----------------------------------------------------------");

}

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

@FXML
private void chooseFile(ActionEvent e) {
    FileChooser chooser = new FileChooser();
    chooser.getExtensionFilters().addAll(
            new FileChooser.ExtensionFilter("Comma-separated values (CSV) file", "*.csv"),
            new FileChooser.ExtensionFilter("Tab-delimited values file", "*.txt", "*.tab", "*.tsv"),
            new FileChooser.ExtensionFilter("List of names", "*.txt"),
            new FileChooser.ExtensionFilter("TaxDiff file", "*.taxdiff"),
            new FileChooser.ExtensionFilter("Excel file", "*.xls", "*.xlsx"));

    currentFile = chooser.showOpenDialog(datasetImporterView.getStage());
    if (currentFile == null)
        return;// w w w.  j av  a  2 s.co m

    filePathTextField.setText(currentFile.getAbsolutePath());
    String filterDesc = chooser.getSelectedExtensionFilter().getDescription();

    if (filterDesc.startsWith("Comma")) {
        fileFormatComboBox.getSelectionModel().select("Default CSV");
    } else if (filterDesc.startsWith("Tab")) {
        fileFormatComboBox.getSelectionModel().select("Tab-delimited file");
    } else if (filterDesc.startsWith("List of names")) {
        fileFormatComboBox.getSelectionModel().select("List of names");
    } else if (filterDesc.startsWith("TaxDiff")) {
        fileFormatComboBox.getSelectionModel().select("TaxDiff file");
    } else if (filterDesc.startsWith("Excel")) {
        fileFormatComboBox.getSelectionModel().select("Excel file");
    }

    displayPreview();
}

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

@FXML
private void onLoadFile(ActionEvent e) {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Open JFXScad File");
    fileChooser.getExtensionFilters().add(
            new FileChooser.ExtensionFilter("JFXScad files (*.jfxscad, *.groovy)", "*.jfxscad", "*.groovy"));

    File f = fileChooser.showOpenDialog(null);

    if (f == null) {
        return;/*from w  w w . ja va  2 s.com*/
    }

    String fName = f.getAbsolutePath();

    if (!fName.toLowerCase().endsWith(".groovy") && !fName.toLowerCase().endsWith(".jfxscad")) {
        fName += ".jfxscad";
    }

    try {
        setCode(new String(Files.readAllBytes(Paths.get(fName)), "UTF-8"));
    } catch (IOException ex) {
        Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:view.EditorView.java

@FXML
void menuItemSaveAsOnAction(@SuppressWarnings("unused") ActionEvent event) {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Save game file");
    File file = fileChooser.showSaveDialog(stage);

    if (file != null) {
        // if file == null the action was aborted
        try {/*w w w . j a v a 2 s.c o  m*/
            getCurrentGame().save(file);
        } catch (IOException e) {
            FOKLogger.log(MainWindow.class.getName(), Level.SEVERE,
                    "Could not save the game from the \"Save As\" menu", e);
            new Alert(Alert.AlertType.ERROR,
                    "Could not save the game file: \n\n" + ExceptionUtils.getRootCauseMessage(e)).show();
        }
    }
}

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

/**
 * A handler for the export to PDF option in the context menu.
 *//*w w w  .ja v a 2s .com*/
private void handleExportToPDF() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setSelectedExtensionFilter(
            new FileChooser.ExtensionFilter("Portable Document Format (PDF)", "pdf"));
    fileChooser.setTitle("Export to PDF");
    File file = fileChooser.showSaveDialog(this.getScene().getWindow());
    if (file != null) {
        ExportUtils.writeAsPDF(this.chart, (int) getWidth(), (int) getHeight(), file);
    }
}

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

@FXML
private void onSaveFile(ActionEvent e) {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Save JFXScad File");
    fileChooser.getExtensionFilters().add(
            new FileChooser.ExtensionFilter("JFXScad files (*.jfxscad, *.groovy)", "*.jfxscad", "*.groovy"));

    File f = fileChooser.showSaveDialog(null);

    if (f == null) {
        return;/*from  w ww. j  av a2  s . co  m*/
    }

    String fName = f.getAbsolutePath();

    if (!fName.toLowerCase().endsWith(".groovy") && !fName.toLowerCase().endsWith(".jfxscad")) {
        fName += ".jfxscad";
    }

    try {
        Files.write(Paths.get(fName), getCode().getBytes("UTF-8"));
    } catch (IOException ex) {
        Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.ggvaidya.scinames.complexquery.ComplexQueryViewController.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(scene.getWindow());
    if (file != null) {
        CSVFormat format = CSVFormat.RFC4180;

        String outputFormat = chooser.getSelectedExtensionFilter().getDescription();
        if (outputFormat.equalsIgnoreCase("Tab-delimited file"))
            format = CSVFormat.TDF;/*from ww  w  .j  a v a2  s .c  o  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:de.hs.mannheim.modUro.controller.diagram.fx.ChartViewer.java

/**
 * A handler for the export to SVG option in the context menu.
 *//* w w  w  .ja  va2  s.  com*/
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.loop81.fxcomparer.FXComparerController.java

private ComparableArchive selectFile(Window window) {
    try {//from  w w  w .ja  v a2  s . com
        FileChooser fileChooser = new FileChooser();
        ExtensionFilter filter = new ExtensionFilter(MessageBundle.getString("file.selector.text"), "*.zip",
                "*.jar", "*.war");
        fileChooser.getExtensionFilters().add(filter);
        return new ComparableArchive(fileChooser.showOpenDialog(window));
    } catch (ArchiveException e) {
        new AlertDialog(MessageBundle.getString("exceptions.archive.open")).show();
        return null;
    }
}