Example usage for javafx.stage FileChooser getExtensionFilters

List of usage examples for javafx.stage FileChooser getExtensionFilters

Introduction

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

Prototype

public ObservableList<ExtensionFilter> getExtensionFilters() 

Source Link

Document

Gets the extension filters used in the displayed file dialog.

Usage

From source file:editeurpanovisu.EquiCubeDialogController.java

/**
 *
 * @return liste des fichiers/* ww w .  j a v a2s .c o  m*/
 */
private File[] choixFichiers() {
    File[] fileLstFich = null;
    FileChooser fcRepertChoix = new FileChooser();
    fcRepertChoix.getExtensionFilters().addAll(
            new FileChooser.ExtensionFilter("fichier Image (*.jpg|*.bmp|*.tif)", "*.jpg", "*.bmp", "*.tif"));
    File fileRepert = new File(strRepertFichier + File.separator);
    fcRepertChoix.setInitialDirectory(fileRepert);
    List<File> fileListe = fcRepertChoix.showOpenMultipleDialog(stTransformations);
    int i = 0;
    boolean bAttention = false;
    if (fileListe != null) {
        File[] fileLstFich1 = new File[fileListe.size()];
        for (File fileLst : fileListe) {
            if (i == 0) {
                strRepertFichier = fileLst.getParent();
            }
            String strNomFich = fileLst.getAbsolutePath();
            String strExtension;
            strExtension = strNomFich.substring(strNomFich.lastIndexOf(".") + 1, strNomFich.length())
                    .toLowerCase();
            Image img = null;
            if (!strExtension.equals("tif")) {
                img = new Image("file:" + strNomFich);
            } else {
                try {
                    img = ReadWriteImage.readTiff(strNomFich);
                } catch (ImageReadException | IOException ex) {
                    Logger.getLogger(EquiCubeDialogController.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (strTypeTransformation.equals(EquiCubeDialogController.EQUI2CUBE)) {
                if (img.getWidth() == 2 * img.getHeight()) {
                    fileLstFich1[i] = fileLst;
                    i++;
                } else {
                    bAttention = true;
                }
            } else {
                if (img.getWidth() == img.getHeight()) {
                    String strNom = fileLst.getAbsolutePath().substring(0,
                            fileLst.getAbsolutePath().length() - 6);
                    boolean bTrouve = false;
                    for (int j = 0; j < i; j++) {
                        String strNom1 = fileLstFich1[j].getAbsolutePath().substring(0,
                                fileLst.getAbsolutePath().length() - 6);
                        if (strNom.equals(strNom1)) {
                            bTrouve = true;
                        }
                    }
                    if (!bTrouve) {
                        fileLstFich1[i] = fileLst;
                        i++;
                    }
                } else {
                    bAttention = true;
                }

            }
        }
        if (bAttention) {
            Alert alert = new Alert(AlertType.ERROR);
            alert.setTitle(rbLocalisation.getString("transformation.traiteImages"));
            alert.setHeaderText(null);
            alert.setContentText(rbLocalisation.getString("transformation.traiteImagesType"));
            alert.showAndWait();
        }
        fileLstFich = new File[i];
        System.arraycopy(fileLstFich1, 0, fileLstFich, 0, i);
        lblDragDropE2C.setVisible(false);
    }

    return fileLstFich;
}

From source file:ch.unibas.charmmtools.gui.step1.mdAssistant.CHARMM_GUI_InputAssistant.java

/**
 * Handles the event when one of the 3 button_open_XXX is pressed button_generate is enabled only when the 3 files
 * have been loaded// w w w. ja v a2 s.com
 *
 * @param event
 */
@FXML
protected void OpenButtonPressed(ActionEvent event) {

    Window myParent = button_generate.getScene().getWindow();
    FileChooser chooser = new FileChooser();
    chooser.setInitialDirectory(new File("."));
    File selectedFile = null;

    chooser.setTitle("Open File");

    if (event.getSource().equals(button_open_PAR)) {
        chooser.getExtensionFilters().add(
                new FileChooser.ExtensionFilter("CHARMM FF parameters file (*.par,*.prm)", "*.par", "*.prm"));
        selectedFile = chooser.showOpenDialog(myParent);
        if (selectedFile != null) {
            textfield_PAR.setText(selectedFile.getAbsolutePath());
            PAR_selected = true;
        }
    } else if (event.getSource().equals(button_open_RTF)) {
        chooser.getExtensionFilters().add(
                new FileChooser.ExtensionFilter("CHARMM FF topology file (*.top,*.rtf)", "*.top", "*.rtf"));
        selectedFile = chooser.showOpenDialog(myParent);
        if (selectedFile != null) {
            textfield_RTF.setText(selectedFile.getAbsolutePath());
            RTF_selected = true;
        }
    } else if (event.getSource().equals(button_open_COR_gas)) {
        chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Coordinates file (*.pdb)", "*.pdb"));
        selectedFile = chooser.showOpenDialog(myParent);
        if (selectedFile != null) {
            textfield_COR_gas.setText(selectedFile.getAbsolutePath());
            COR_selected_gas = true;
        }
    } else if (event.getSource().equals(button_open_COR_liquid)) {
        chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Coordinates file (*.pdb)", "*.pdb"));
        selectedFile = chooser.showOpenDialog(myParent);
        if (selectedFile != null) {
            textfield_COR_liquid.setText(selectedFile.getAbsolutePath());
            COR_selected_liquid = true;
        }
    } else if (event.getSource().equals(button_open_COR_solv)) {
        chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Coordinates file (*.pdb)", "*.pdb"));
        selectedFile = chooser.showOpenDialog(myParent);
        if (selectedFile != null) {
            textfield_COR_solv.setText(selectedFile.getAbsolutePath());
            COR_selected_solv = true;
        }
    } else if (event.getSource().equals(button_open_LPUN)) {
        chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("LPUN file", "*.lpun"));
        selectedFile = chooser.showOpenDialog(myParent);
        if (selectedFile != null) {
            textfield_LPUN.setText(selectedFile.getAbsolutePath());
            LPUN_selected = true;
        }
    } else {
        throw new UnknownError("Unknown Event in OpenButtonPressed(ActionEvent event)");
    }

    this.validateButtonGenerate();

}

From source file:io.github.mzmine.modules.plots.msspectrum.MsSpectrumPlotWindowController.java

public void handleExportMSP(Event event) {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export to MSP");
    fileChooser.getExtensionFilters().add(new ExtensionFilter("NIST MSP format", "*.msp"));

    // 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;/*from   www  .  ja va 2  s.c o m*/

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

    final List<MsSpectrum> spectra = new ArrayList<>();
    for (MsSpectrumDataSet dataset : datasets) {
        spectra.add(dataset.getSpectrum());
    }

    // Do the export in a new thread
    final File finalFile = file;
    new Thread(() -> {
        try {
            MspExportAlgorithm.exportSpectra(finalFile, spectra);
        } catch (Exception e) {
            MZmineGUI.displayMessage("Unable to export: " + e.getMessage());
            e.printStackTrace();
        }
    }).start();
}

From source file:io.github.mzmine.modules.plots.msspectrum.MsSpectrumPlotWindowController.java

public void handleExportTXT(Event event) {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export to TXT");
    fileChooser.getExtensionFilters().add(new ExtensionFilter("TXT", "*.txt"));

    // 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;//from   www .  j  a  va 2  s  . c  om

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

    final List<MsSpectrum> spectra = new ArrayList<>();
    for (MsSpectrumDataSet dataset : datasets) {
        spectra.add(dataset.getSpectrum());
    }

    // Do the export in a new thread
    final File finalFile = file;
    new Thread(() -> {
        try {
            TxtExportAlgorithm.exportSpectra(finalFile, spectra);
        } catch (Exception e) {
            MZmineGUI.displayMessage("Unable to export: " + e.getMessage());
            e.printStackTrace();
        }
    }).start();
}

From source file:io.github.mzmine.modules.plots.msspectrum.MsSpectrumPlotWindowController.java

public void handleExportMGF(Event event) {

    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export to MGF");
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Mascot Generic Format", "*.mgf"));

    // 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;//  www  . j av a  2s  .c om

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

    final List<MsSpectrum> spectra = new ArrayList<>();
    for (MsSpectrumDataSet dataset : datasets) {
        spectra.add(dataset.getSpectrum());
    }

    // Do the export in a new thread
    final File finalFile = file;
    new Thread(() -> {
        try {
            MgfFileExportMethod mgfEx = new MgfFileExportMethod(spectra, finalFile);
            mgfEx.execute();
        } catch (Exception e) {
            MZmineGUI.displayMessage("Unable to export: " + e.getMessage());
            e.printStackTrace();
        }
    }).start();
}

From source file:io.github.mzmine.modules.plots.msspectrum.MsSpectrumPlotWindowController.java

public void handleExportMzML(Event event) {

    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export to mzML");
    fileChooser.getExtensionFilters().add(new ExtensionFilter("mzML", "*.mzML"));

    // 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;/*w  w  w. j  av  a2s. c  o  m*/

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

    final List<MsSpectrum> spectra = new ArrayList<>();
    for (MsSpectrumDataSet dataset : datasets) {
        spectra.add(dataset.getSpectrum());
    }

    // Do the export in a new thread
    final File finalFile = file;

    new Thread(() -> {
        try {
            // Create a temporary raw data file
            DataPointStore tmpStore = DataPointStoreFactory.getMemoryDataStore();
            RawDataFile tmpRawFile = MSDKObjectBuilder.getRawDataFile("Exported spectra", null,
                    FileType.UNKNOWN, tmpStore);
            int scanNum = 1;
            for (MsSpectrumDataSet dataset : datasets) {
                MsSpectrum spectrum = dataset.getSpectrum();
                MsScan newScan;
                if (spectrum instanceof MsScan) {
                    newScan = MsScanUtil.clone(tmpStore, (MsScan) spectrum, true);
                } else {
                    MsFunction msf = MSDKObjectBuilder.getMsFunction(MsFunction.DEFAULT_MS_FUNCTION_NAME);
                    newScan = MSDKObjectBuilder.getMsScan(tmpStore, scanNum, msf);
                }
                tmpRawFile.addScan(newScan);
            }
            MzMLFileExportMethod exporter = new MzMLFileExportMethod(tmpRawFile, finalFile);
            exporter.execute();
            tmpRawFile.dispose();
        } catch (Exception e) {
            MZmineGUI.displayMessage("Unable to export: " + e.getMessage());
            e.printStackTrace();
        }
    }).start();

}

From source file:open.dolphin.client.MainWindowController.java

@FXML
protected void fileChoose() {
    FileChooser fc = new FileChooser();
    fc.setTitle("select file");
    fc.setInitialDirectory(new File(System.getProperty("user.home")));
    fc.getExtensionFilters().add(new ExtensionFilter("????", "*.*"));

    File f = fc.showOpenDialog(null);
    if (f != null) {
        try {/*from  w  ww .  j  a  v a2  s .co m*/
            Path path = f.toPath();
            choiceFile.setText(path.getFileName().toString());
            for (String s : Files.readAllLines(path, Charset.forName("SJIS"))) {
                System.out.println(s);
            }
        } catch (IOException ex) {
            Logger.getLogger(MainWindowController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:dsfixgui.FileIO.DSFixFileController.java

public void exportDSFIniFile() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle(DIALOG_TITLE_EXPORT_INI);
    FileChooser.ExtensionFilter iniFilter = new FileChooser.ExtensionFilter(INI_EXT_FILTER[0],
            INI_EXT_FILTER[1]);//from ww  w .j  a v  a 2  s . c  o  m
    fileChooser.getExtensionFilters().add(iniFilter);
    File exportedFile = fileChooser.showSaveDialog(ui.getStage());

    if (exportedFile != null) {
        ui.getConfig().writeSettingsToIniFile(exportedFile.getPath());
    }
}

From source file:dsfixgui.FileIO.DSFixFileController.java

public void exportDSFKeybindsIniFile() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle(DIALOG_TITLE_EXPORT_INI);
    FileChooser.ExtensionFilter iniFilter = new FileChooser.ExtensionFilter(INI_EXT_FILTER[0],
            INI_EXT_FILTER[1]);/*from w w w .  j a v a  2 s .  c o m*/
    fileChooser.getExtensionFilters().add(iniFilter);
    File exportedFile = fileChooser.showSaveDialog(ui.getStage());

    if (exportedFile != null) {
        ui.getDSFKeybinds().writeSettingsToIniFile(exportedFile.getPath());
    }
}

From source file:dsfixgui.FileIO.DSFixFileController.java

public void loadDSFConfig() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle(DIALOG_TITLE_IMPORT_INI);
    FileChooser.ExtensionFilter iniFilter = new FileChooser.ExtensionFilter(INI_EXT_FILTER[0],
            INI_EXT_FILTER[1]);/*  w  ww  .j a v a  2s  . c  o  m*/
    fileChooser.getExtensionFilters().add(iniFilter);

    File importedFile = fileChooser.showOpenDialog(ui.getStage());
    if (importedFile != null) {
        ui.getConfig().loadSettingsFromIniFile(importedFile.getPath());
    }
}