Search in sources :

Example 6 with TxtFileFilter

use of uk.ac.babraham.SeqMonk.Utilities.FileFilters.TxtFileFilter in project SeqMonk by s-andrews.

the class ReportTableDialog method actionPerformed.

/* (non-Javadoc)
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equals("close")) {
        setVisible(false);
        dispose();
    } else if (ae.getActionCommand().equals("save")) {
        JFileChooser chooser = new JFileChooser(SeqMonkPreferences.getInstance().getSaveLocation());
        chooser.setMultiSelectionEnabled(false);
        if (report.canExportGFF()) {
            chooser.addChoosableFileFilter(new GFFFileFilter());
        }
        TxtFileFilter txtff = new TxtFileFilter();
        chooser.addChoosableFileFilter(txtff);
        chooser.setFileFilter(txtff);
        int result = chooser.showSaveDialog(this);
        if (result == JFileChooser.CANCEL_OPTION)
            return;
        File file = chooser.getSelectedFile();
        SeqMonkPreferences.getInstance().setLastUsedSaveLocation(file);
        if (file.isDirectory())
            return;
        FileFilter filter = chooser.getFileFilter();
        if (filter instanceof TxtFileFilter) {
            if (!file.getPath().toLowerCase().endsWith(".txt")) {
                file = new File(file.getPath() + ".txt");
            }
        } else if (filter instanceof GFFFileFilter) {
            if (!file.getPath().toLowerCase().endsWith(".gff")) {
                file = new File(file.getPath() + ".gff");
            }
        } else {
            System.err.println("Unknown file filter type " + filter + " when saving image");
            return;
        }
        // Check if we're stepping on anyone's toes...
        if (file.exists()) {
            int answer = JOptionPane.showOptionDialog(this, file.getName() + " exists.  Do you want to overwrite the existing file?", "Overwrite file?", 0, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Overwrite and Save", "Cancel" }, "Overwrite and Save");
            if (answer > 0) {
                return;
            }
        }
        try {
            if (filter instanceof TxtFileFilter) {
                saveTextReport(file);
            } else if (filter instanceof GFFFileFilter) {
                saveGFFReport(file);
            } else {
                System.err.println("Unknown file filter type " + filter + " when saving image");
                return;
            }
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }
}
Also used : GFFFileFilter(uk.ac.babraham.SeqMonk.Utilities.FileFilters.GFFFileFilter) JFileChooser(javax.swing.JFileChooser) TxtFileFilter(uk.ac.babraham.SeqMonk.Utilities.FileFilters.TxtFileFilter) IOException(java.io.IOException) TxtFileFilter(uk.ac.babraham.SeqMonk.Utilities.FileFilters.TxtFileFilter) FileFilter(javax.swing.filechooser.FileFilter) GFFFileFilter(uk.ac.babraham.SeqMonk.Utilities.FileFilters.GFFFileFilter) File(java.io.File)

Example 7 with TxtFileFilter

use of uk.ac.babraham.SeqMonk.Utilities.FileFilters.TxtFileFilter in project SeqMonk by s-andrews.

the class ProbeValueHistogramPlot method actionPerformed.

/* (non-Javadoc)
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equals("close")) {
        setVisible(false);
        dispose();
    } else if (ae.getActionCommand().equals("save")) {
        ImageSaver.saveImage(plotPanel.mainHistogramPanel());
    } else if (ae.getActionCommand().equals("export")) {
        JFileChooser chooser = new JFileChooser(SeqMonkPreferences.getInstance().getSaveLocation());
        chooser.setMultiSelectionEnabled(false);
        chooser.setFileFilter(new TxtFileFilter());
        int result = chooser.showSaveDialog(this);
        if (result == JFileChooser.CANCEL_OPTION)
            return;
        File file = chooser.getSelectedFile();
        SeqMonkPreferences.getInstance().setLastUsedSaveLocation(file);
        if (file.isDirectory())
            return;
        if (!file.getPath().toLowerCase().endsWith(".txt")) {
            file = new File(file.getPath() + ".txt");
        }
        // Check if we're stepping on anyone's toes...
        if (file.exists()) {
            int answer = JOptionPane.showOptionDialog(this, file.getName() + " exists.  Do you want to overwrite the existing file?", "Overwrite file?", 0, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Overwrite and Save", "Cancel" }, "Overwrite and Save");
            if (answer > 0) {
                return;
            }
        }
        try {
            plotPanel.exportData(file);
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) TxtFileFilter(uk.ac.babraham.SeqMonk.Utilities.FileFilters.TxtFileFilter) IOException(java.io.IOException) File(java.io.File)

Aggregations

File (java.io.File)7 IOException (java.io.IOException)7 JFileChooser (javax.swing.JFileChooser)7 TxtFileFilter (uk.ac.babraham.SeqMonk.Utilities.FileFilters.TxtFileFilter)7 ActionEvent (java.awt.event.ActionEvent)2 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 ActionListener (java.awt.event.ActionListener)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 Vector (java.util.Vector)1 JButton (javax.swing.JButton)1 JComboBox (javax.swing.JComboBox)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JTextField (javax.swing.JTextField)1 FileFilter (javax.swing.filechooser.FileFilter)1 DataGroup (uk.ac.babraham.SeqMonk.DataTypes.DataGroup)1