Example usage for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter

List of usage examples for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter

Introduction

In this page you can find the example usage for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter.

Prototype

public FileNameExtensionFilter(String description, String... extensions) 

Source Link

Document

Creates a FileNameExtensionFilter with the specified description and file name extensions.

Usage

From source file:edu.umich.robot.GuiApplication.java

/**
 * <p>/*  w w  w . j  a va2 s .  c  o  m*/
 * Firing up this application requires a configuration file. If no
 * configuration file is presented on the command line, this is called to
 * prompt the user to select a configuration file.
 * 
 * <p>
 * Future work should probably include some default instead of doing this.
 * 
 * @return The selected, loaded configuration file.
 */
public static Config promptForConfig(Component parent) {

    System.out.println("CLASSPATH: " + System.getenv("CLASSPATH"));
    System.out.println("DYLD_LIBRARY_PATH: " + System.getenv("DYLD_LIBRARY_PATH"));
    System.out.println("LD_LIBRARY_PATH: " + System.getenv("LD_LIBRARY_PATH"));
    System.out.println("SOAR_HOME: " + System.getenv("SOAR_HOME"));
    System.out.println("java.library.path: " + System.getProperty("java.library.path"));

    JFileChooser fc = new JFileChooser(System.getProperty("user.dir"));
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    FileFilter filter = new FileNameExtensionFilter("Text Config File", "txt");
    fc.setFileFilter(filter);
    fc.setMultiSelectionEnabled(false);
    int ret = fc.showOpenDialog(parent);
    if (ret == JFileChooser.APPROVE_OPTION) {
        try {
            return new ConfigFile(fc.getSelectedFile().getAbsolutePath());
        } catch (IOException e) {
            logger.error(e.getMessage());
        }
    }
    return null;
}

From source file:com.sf.energy.transfer.form.DataConfiguration.java

/**
 * ??/*from w  w  w .  j a va 2 s.com*/
 * @param evt ?
 */
private void scanActionPerformed(java.awt.event.ActionEvent evt) {
    JFileChooser fc = new JFileChooser();
    File directory = new File(dir);
    // ??
    fc.setCurrentDirectory(directory);
    fc.setDialogTitle("");
    // 
    FileNameExtensionFilter filter1 = new FileNameExtensionFilter(".xls", "xls");
    fc.addChoosableFileFilter(filter1);
    FileNameExtensionFilter filter2 = new FileNameExtensionFilter(".dmp", "dmp");
    fc.addChoosableFileFilter(filter1);
    // 
    fc.setFileFilter(fc.getAcceptAllFileFilter());
    int intRetVal = fc.showOpenDialog(new JFrame());
    // ?
    if (intRetVal == JFileChooser.APPROVE_OPTION) {
        // ?
        dir = fc.getSelectedFile().getPath();
        // 
        filePath.setText(dir);
    }

}

From source file:org.pgptool.gui.ui.encryptone.EncryptOnePm.java

public SaveFileChooserDialog getTargetFileChooser() {
    if (targetFileChooser == null) {
        targetFileChooser = new SaveFileChooserDialog(findRegisteredWindowIfAny(), "action.chooseTargetFile",
                "action.choose", appProps, "EncryptionTargetChooser") {
            @Override/* w  w w. ja  v  a2 s  . c  o  m*/
            protected String onDialogClosed(String filePathName, JFileChooser ofd) {
                String ret = super.onDialogClosed(filePathName, ofd);
                if (ret != null) {
                    targetFile.setValueByOwner(ret);
                }
                return ret;
            }

            @Override
            protected void onFileChooserPostConstrct(JFileChooser ofd) {
                ofd.setAcceptAllFileFilterUsed(false);
                ofd.addChoosableFileFilter(new FileNameExtensionFilter("GPG Files (.pgp)", "pgp"));
                // NOTE: Should we support other extensions?....
                ofd.addChoosableFileFilter(ofd.getAcceptAllFileFilter());
                ofd.setFileFilter(ofd.getChoosableFileFilters()[0]);
            }

            @Override
            protected void suggestTarget(JFileChooser ofd) {
                String sourceFileStr = sourceFile.getValue();
                if (StringUtils.hasText(targetFile.getValue())) {
                    use(ofd, targetFile.getValue());
                } else if (encryptionDialogParameters != null
                        && encryptionDialogParameters.getTargetFile() != null) {
                    if (encryptionDialogParameters.getSourceFile().equals(sourceFile.getValue())) {
                        use(ofd, encryptionDialogParameters.getTargetFile());
                    } else {
                        use(ofd, madeUpTargetFileName(sourceFile.getValue(), FilenameUtils
                                .getFullPathNoEndSeparator(encryptionDialogParameters.getTargetFile())));
                    }
                } else if (StringUtils.hasText(sourceFileStr) && new File(sourceFileStr).exists()) {
                    String basePath = FilenameUtils.getFullPathNoEndSeparator(sourceFileStr);
                    ofd.setCurrentDirectory(new File(basePath));
                    ofd.setSelectedFile(new File(madeUpTargetFileName(sourceFileStr, basePath)));
                }
            }

            private void use(JFileChooser ofd, String filePathName) {
                ofd.setCurrentDirectory(new File(FilenameUtils.getFullPathNoEndSeparator(filePathName)));
                ofd.setSelectedFile(new File(filePathName));
            }
        };
    }
    return targetFileChooser;
}

From source file:eu.apenet.dpt.standalone.gui.dateconversion.DateConversionRulesDialog.java

private void createDataConversionRulesList() {
    Vector<String> columnNames = new Vector<String>();
    columnNames.add(labels.getString("dateConversion.valueRead"));
    columnNames.add(labels.getString("dateConversion.valueConverted"));
    dm = new DefaultTableModel(xmlFilehandler.loadDataFromFile(FILENAME), columnNames);
    dm.addRow(new Vector<String>());
    dm.addTableModelListener(new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            if (ruleTable.getEditingRow() != ruleTable.getRowCount() - 1
                    && (StringUtils.isEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 0))
                            && StringUtils.isEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1)))) {
                dm.removeRow(ruleTable.getEditingRow());
            }//from  w w  w.j  av  a  2 s.  c  o  m
            if (ruleTable.getEditingRow() == ruleTable.getRowCount() - 1) {
                if (StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 0))
                        && StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1))) {
                    dm.addRow(new Vector<String>());
                }
            }
            if (ruleTable.getEditingColumn() == 1) {
                if (StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1))
                        && !isCorrectDateFormat((String) dm.getValueAt(ruleTable.getEditingRow(), 1))) {
                    createOptionPaneForIsoDate(ruleTable.getEditingRow(), 1);
                }
            }
        }
    });

    ruleTable = new JTable(dm);
    oldModel = new DefaultTableModel(xmlFilehandler.loadDataFromFile(FILENAME), columnNames);

    JButton saveButton = new JButton(labels.getString("saveBtn"));
    saveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (ruleTable.isEditing()) {
                ruleTable.getCellEditor().stopCellEditing();
            }
            Vector<Vector<String>> data = ((DefaultTableModel) ruleTable.getModel()).getDataVector();
            for (int i = 0; i < data.size() - 1; i++) {
                Vector<String> vector = data.elementAt(i);
                if (vector.elementAt(1) != null && !isCorrectDateFormat((String) vector.elementAt(1))) {
                    createOptionPaneForIsoDate(i, 1);
                }
            }
            xmlFilehandler.saveDataToFile(data, FILENAME);
            saveMessage.setText(MessageFormat.format(labels.getString("dateConversion.saveMsg"),
                    new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())));
        }
    });

    JButton closeButton = new JButton(labels.getString("quit"));
    closeButton.addActionListener(new ActionListener() {
        // boolean cancel = true;

        public void actionPerformed(ActionEvent e) {
            /*System.out.println(Boolean.toString(oldModel.getRowCount() == (ruleTable.getModel().getRowCount() - 1)) + "<<" + oldModel.getRowCount() + ", " + (ruleTable.getModel().getRowCount() - 1));
            if (oldModel.getRowCount() != ruleTable.getModel().getRowCount() - 1) {
            cancel = showUnsavedChangesDialog();
            } else {
            for (int i = 0; i < (ruleTable.getModel().getRowCount() - 1); i++) {
                for (int j = 0; j <= 1; j++) {
                    System.out.println(oldModel.getValueAt(i, j) == ruleTable.getModel().getValueAt(i, j) + " >> " + oldModel.getValueAt(i, j) + ", " + ruleTable.getModel().getValueAt(i, j));
                    if (oldModel.getValueAt(i, j) != ruleTable.getModel().getValueAt(i, j)) {
                        cancel = showUnsavedChangesDialog();
                    }
                }
            }
            }
            if (cancel) {*/
            dispose();
            //  }
        }
    });

    JButton downloadButton = new JButton(labels.getString("downloadBtn"));
    downloadButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (ruleTable.isEditing()) {
                ruleTable.getCellEditor().stopCellEditing();
            }
            Vector<Vector<String>> data = ((DefaultTableModel) ruleTable.getModel()).getDataVector();
            File currentLocation = new File(retrieveFromDb.retrieveOpenLocation());
            JFileChooser fileChooser = new JFileChooser(currentLocation);
            fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
            fileChooser.setFileFilter(new FileNameExtensionFilter("XML file", "xml"));
            int returnedVal = fileChooser.showSaveDialog(getParent());

            if (returnedVal == JFileChooser.APPROVE_OPTION) {
                String fileName = fileChooser.getSelectedFile().toString();
                if (!fileName.endsWith(".xml")) {
                    fileName = fileName + ".xml";
                }
                xmlFilehandler.saveDataToFile(data, fileName);
                //additionally save data to standard file
                xmlFilehandler.saveDataToFile(data, FILENAME);
                saveMessage.setText(MessageFormat.format(labels.getString("dateConversion.saveMsg"),
                        new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())));
            }
        }
    });

    JPanel contentPanel = new JPanel(new BorderLayout());
    contentPanel.add(new JScrollPane(ruleTable));
    saveMessage = new JLabel();
    contentPanel.add(saveMessage, BorderLayout.SOUTH);

    JPanel buttonPanel = new JPanel(new GridLayout(1, 3));
    buttonPanel.add(saveButton);
    buttonPanel.add(closeButton);
    buttonPanel.add(downloadButton);

    JPanel pane = new JPanel(new BorderLayout());
    pane.add(contentPanel, BorderLayout.PAGE_START);
    pane.add(buttonPanel, BorderLayout.PAGE_END);
    add(pane);
}

From source file:e3fraud.gui.MainWindow.java

public MainWindow() {
    super(new BorderLayout(5, 5));

    extended = false;//from   www  . j  ava 2s. c  o  m

    //Create the log first, because the action listeners
    //need to refer to it.
    log = new JTextArea(10, 50);
    log.setMargin(new Insets(5, 5, 5, 5));
    log.setEditable(false);
    logScrollPane = new JScrollPane(log);
    DefaultCaret caret = (DefaultCaret) log.getCaret();
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

    //        create the progress bar
    progressBar = new JProgressBar(0, 100);
    progressBar.setValue(progressBar.getMinimum());
    progressBar.setVisible(false);
    progressBar.setStringPainted(true);
    //Create the settings pane
    generationSettingLabel = new JLabel("Generate:");
    SpinnerModel collusionsSpinnerModel = new SpinnerNumberModel(1, 0, 3, 1);
    collusionSettingsPanel = new JPanel(new FlowLayout()) {
        @Override
        public Dimension getMaximumSize() {
            return getPreferredSize();
        }
    };
    // collusionSettingsPanel.setLayout(new BoxLayout(collusionSettingsPanel, BoxLayout.X_AXIS));
    collusionsButton = new JSpinner(collusionsSpinnerModel);
    collusionsLabel = new JLabel("collusion(s)");
    collusionSettingsPanel.add(collusionsButton);
    collusionSettingsPanel.add(collusionsLabel);

    rankingSettingLabel = new JLabel("Rank by:");
    lossButton = new JRadioButton("loss");
    lossButton.setToolTipText("Sort sub-ideal models based on loss for Target of Assessment (high -> low)");
    gainButton = new JRadioButton("gain");
    gainButton.setToolTipText(
            "Sort sub-ideal models based on gain of any actor except Target of Assessment (high -> low)");
    lossGainButton = new JRadioButton("loss + gain");
    lossGainButton.setToolTipText(
            "Sort sub-ideal models based on loss for Target of Assessment and, if equal, on gain of any actor except Target of Assessment");
    //gainLossButton = new JRadioButton("gain + loss");
    lossGainButton.setSelected(true);
    rankingGroup = new ButtonGroup();
    rankingGroup.add(lossButton);
    rankingGroup.add(gainButton);
    rankingGroup.add(lossGainButton);
    //rankingGroup.add(gainLossButton);
    groupingSettingLabel = new JLabel("Group by:");
    groupingButton = new JCheckBox("collusion");
    groupingButton.setToolTipText(
            "Groups sub-ideal models based on the pair of actors colluding before ranking them");
    groupingButton.setSelected(false);
    refreshButton = new JButton("Refresh");
    refreshButton.addActionListener(this);

    settingsPanel = new JPanel();
    settingsPanel.setLayout(new BoxLayout(settingsPanel, BoxLayout.PAGE_AXIS));
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    settingsPanel.add(generationSettingLabel);
    collusionSettingsPanel.setAlignmentX(LEFT_ALIGNMENT);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    settingsPanel.add(collusionSettingsPanel);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    rankingSettingLabel.setAlignmentY(TOP_ALIGNMENT);
    settingsPanel.add(rankingSettingLabel);
    settingsPanel.add(lossButton);
    settingsPanel.add(gainButton);
    settingsPanel.add(lossGainButton);
    //settingsPanel.add(gainLossButton);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    settingsPanel.add(groupingSettingLabel);
    settingsPanel.add(groupingButton);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    settingsPanel.add(refreshButton);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 20)));
    progressBar.setPreferredSize(
            new Dimension(settingsPanel.getSize().width, progressBar.getPreferredSize().height));
    settingsPanel.add(progressBar);

    //Create the result tree
    root = new DefaultMutableTreeNode("No models to display");
    treeModel = new DefaultTreeModel(root);
    tree = new JTree(treeModel);
    //tree.setUI(new CustomTreeUI());
    tree.setCellRenderer(new CustomTreeCellRenderer(tree));
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setLargeModel(true);
    resultScrollPane = new JScrollPane(tree);
    tree.addTreeSelectionListener(treeSelectionListener);

    //tree.setShowsRootHandles(true);
    //Create a file chooser for saving
    sfc = new JFileChooser();
    FileFilter jpegFilter = new FileNameExtensionFilter("JPEG image", new String[] { "jpg", "jpeg" });
    sfc.addChoosableFileFilter(jpegFilter);
    sfc.setFileFilter(jpegFilter);

    //Create a file chooser for loading
    fc = new JFileChooser();
    FileFilter rdfFilter = new FileNameExtensionFilter("RDF file", "RDF");
    fc.addChoosableFileFilter(rdfFilter);
    fc.setFileFilter(rdfFilter);

    //Create the open button.  
    openButton = new JButton("Load model", createImageIcon("images/Open24.png"));
    openButton.addActionListener(this);
    openButton.setToolTipText("Load a e3value model");

    //Create the ideal graph button. 
    idealGraphButton = new JButton("Show ideal graph", createImageIcon("images/Plot.png"));
    idealGraphButton.setToolTipText("Display ideal profitability graph");
    idealGraphButton.addActionListener(this);

    Dimension thinButtonDimension = new Dimension(15, 420);

    //Create the expand subideal graph button. 
    expandButton = new JButton(">");
    expandButton.setPreferredSize(thinButtonDimension);
    expandButton.setMargin(new Insets(0, 0, 0, 0));
    expandButton.setToolTipText("Expand to show non-ideal profitability graph for selected model");
    expandButton.addActionListener(this);

    //Create the collapse sub-ideal graph button. 
    collapseButton = new JButton("<");
    collapseButton.setPreferredSize(thinButtonDimension);
    collapseButton.setMargin(new Insets(0, 0, 0, 0));
    collapseButton.setToolTipText("Collapse non-ideal profitability graph for selected model");
    collapseButton.addActionListener(this);

    //Create the generation button. 
    generateButton = new JButton("Generate sub-ideal models", createImageIcon("images/generate.png"));
    generateButton.addActionListener(this);
    generateButton.setToolTipText("Generate sub-ideal models for the e3value model currently loaded");

    //Create the chart panel
    chartPane = new JPanel();
    chartPane.setLayout(new FlowLayout(FlowLayout.LEFT));
    chartPane.add(expandButton);

    //For layout purposes, put the buttons in a separate panel
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    buttonPanel.add(openButton);
    buttonPanel.add(Box.createRigidArea(new Dimension(20, 0)));
    buttonPanel.add(generateButton);
    buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
    buttonPanel.add(idealGraphButton);

    //Add the buttons, the ranking options, the result list and the log to this panel.
    add(buttonPanel, BorderLayout.PAGE_START);
    add(settingsPanel, BorderLayout.LINE_START);
    add(resultScrollPane, BorderLayout.CENTER);

    add(logScrollPane, BorderLayout.PAGE_END);
    add(chartPane, BorderLayout.LINE_END);
    //and make a nice border around it
    setBorder(BorderFactory.createEmptyBorder(5, 10, 10, 10));
}

From source file:au.org.ala.delta.intkey.ui.UIUtils.java

/**
 * Prompts for a file using the file chooser dialog
 * //  www. j a  v a 2  s.  c o m
 * @param fileExtensions
 *            Accepted file extensions - must be null if filePrefixes is
 *            non-null
 * @param filePrefixes
 *            Accepted file prefixes - must be null if fileExtensions is
 *            non-null
 * @param description
 *            Description of the acceptable files
 * @param createFileIfNonExistant
 *            if true, the file will be created if it does not exist. Also,
 *            the system's "save" will be used instead of the "open" dialog.
 * @param startBrowseDirectory
 *            The directory that the file chooser should start in
 * @param parent
 *            parent component for the file chooser
 * @return the selected file, or null if no file was selected.
 * @throws IOException
 */
public static File promptForFile(List<String> fileExtensions, List<String> filePrefixes,
        final String description, boolean createFileIfNonExistant, File startBrowseDirectory, Component parent)
        throws IOException {
    if (fileExtensions != null && filePrefixes != null) {
        throw new IllegalArgumentException(
                "Only one of the file extensions or file prefixes should be non-null");
    }

    JFileChooser chooser = new JFileChooser(startBrowseDirectory);
    FileFilter filter;

    if (fileExtensions != null) {
        String[] extensionsArray = new String[fileExtensions.size()];
        fileExtensions.toArray(extensionsArray);
        filter = new FileNameExtensionFilter(description, extensionsArray);
    } else {
        final String[] prefixesArray = new String[filePrefixes.size()];
        filePrefixes.toArray(prefixesArray);
        filter = new FileFilter() {

            @Override
            public String getDescription() {
                return description;
            }

            @Override
            public boolean accept(File f) {
                if (f.isDirectory()) {
                    return true;
                } else {
                    return StringUtils.startsWithAny(f.getName(), prefixesArray);
                }
            }
        };
    }
    chooser.setFileFilter(filter);

    int returnVal;

    if (createFileIfNonExistant) {
        returnVal = chooser.showSaveDialog(parent);
    } else {
        returnVal = chooser.showOpenDialog(parent);
    }

    if (returnVal == JFileChooser.APPROVE_OPTION) {

        if (createFileIfNonExistant) {
            File file = chooser.getSelectedFile();

            if (!file.exists()) {
                // if only one file extension was supplied and the filename
                // does
                // not end with this extension, add it before
                // creating the file
                if (fileExtensions.size() == 1) {
                    String extension = fileExtensions.get(0);
                    String filePath = chooser.getSelectedFile().getAbsolutePath();
                    if (!filePath.endsWith(extension)) {
                        file = new File(filePath + "." + extension);
                    }
                }

                file.createNewFile();
            }
            return file;
        } else {
            return chooser.getSelectedFile();
        }
    } else {
        return null;
    }
}

From source file:com.holycityaudio.SpinCAD.SpinCADFile.java

public SpinCADPatch fileOpenHex() {

    loadRecentHexFileList();//from  w w w .j av  a  2  s. c  o m
    final String newline = "\n";
    SpinCADPatch p = new SpinCADPatch();

    // In response to a button click:
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Spin Hex Files", "hex");
    fc.setFileFilter(filter);
    fc.setAccessory(recentHexFileList);
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);

    int returnVal = fc.showOpenDialog(new JFrame());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        String filePath = null;
        File file = fc.getSelectedFile();

        System.out.println("Opening: " + file.getName() + "." + newline);
        filePath = file.getPath();
        try {
            p = fileReadHex(filePath);
        } catch (Exception e) {
            e.printStackTrace();
            SpinCADDialogs.MessageBox("Hex File open failed!", "That's not supposed to happen!");
        } finally {
            saveMRUHexFolder(filePath);
            recentHexFileList.add(file);
            String fileName = file.getName();
            p.patchFileName = fileName;
            p.cb.setFileName(fileName);
            p.isHexFile = true;
            p.setChanged(false);
        }
    } else {
        System.out.println("Open command cancelled by user." + newline);
    }
    saveRecentHexFileList();
    return p;
}

From source file:Compare.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    String userDir = System.getProperty("user.home");
    JFileChooser folder = new JFileChooser(userDir + "/Desktop");
    folder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    folder.setFileSelectionMode(JFileChooser.FILES_ONLY);
    FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Excel Files  (*.xls)", "xls");
    folder.setFileFilter(xmlfilter);/*from   w w w .  ja  v a  2  s. co  m*/
    int returnvalue = folder.showSaveDialog(this);

    File myfolder = null;
    if (returnvalue == JFileChooser.APPROVE_OPTION) {
        myfolder = folder.getSelectedFile();
        //            System.out.println(myfolder);         
    }

    if (myfolder != null) {
        JOptionPane.showMessageDialog(null, "The current choosen file directory is : " + myfolder);
    }

    listofFiles(myfolder);
    sortByName();

    DefaultTableModel model = (DefaultTableModel) FileDetails.getModel();

    int count = 1;
    for (Files filename : filenames1) {
        String size = Long.toString(filename.Filesize) + "Bytes";
        model.addRow(new Object[] { count++, filename.Filename, size, filename.FileLocation });
    }

}

From source file:net.sf.mzmine.modules.visualization.tic.TICVisualizerWindow.java

/**
 * Export a file's chromatogram.//from  www  .  j  ava 2  s.com
 *
 * @param file the file.
 */
public void exportChromatogram(RawDataFile file) {

    // Get the data set.
    final TICDataSet dataSet = ticDataSets.get(file);
    if (dataSet != null) {

        // Create the chooser if necessary.
        if (exportChooser == null) {

            exportChooser = new LoadSaveFileChooser("Select Chromatogram File");
            exportChooser.addChoosableFileFilter(
                    new FileNameExtensionFilter("Comma-separated values files", CSV_EXTENSION));
        }

        // Choose an export file.
        final File exportFile = exportChooser.getSaveFile(this, file.getName(), CSV_EXTENSION);
        if (exportFile != null) {

            MZmineCore.getTaskController().addTask(new ExportChromatogramTask(dataSet, exportFile));
        }
    }
}

From source file:com.seanmadden.net.fast.FastInterpretype.java

public boolean saveLogToFile() {
    JFileChooser jfc = new JFileChooser();
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Text Files", "txt");
    jfc.setFileFilter(filter);/*  w  w w . java 2  s  .  co m*/
    int retVal = jfc.showSaveDialog(null);
    if (retVal == JFileChooser.APPROVE_OPTION) {
        String filename = jfc.getSelectedFile().getPath();
        mw.saveWindowToFile(filename);
        return true;
    }
    return false;
}