Search in sources :

Example 1 with LoadSaveFileChooser

use of net.sf.mzmine.util.dialogs.LoadSaveFileChooser in project mzmine2 by mzmine.

the class ImportLipidModificationsAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    // Parent component.
    final LipidModificationChoiceComponent parent = (LipidModificationChoiceComponent) SwingUtilities.getAncestorOfClass(LipidModificationChoiceComponent.class, (Component) e.getSource());
    if (parent != null) {
        // Create the chooser if necessary.
        if (chooser == null) {
            chooser = new LoadSaveFileChooser("Select lipid modification file");
            chooser.addChoosableFileFilter(new FileNameExtensionFilter("Comma-separated values files", FILENAME_EXTENSION));
        }
        // Select a file.
        final File file = chooser.getLoadFile(parent);
        if (file != null) {
            // Read the CSV file into a string array.
            String[][] csvLines = null;
            try {
                csvLines = CSVParser.parse(new FileReader(file));
            } catch (IOException ex) {
                final Window window = (Window) SwingUtilities.getAncestorOfClass(Window.class, (Component) e.getSource());
                final String msg = "There was a problem reading the lipid modification file.";
                MZmineCore.getDesktop().displayErrorMessage(window, "I/O Error", msg + "\n(" + ex.getMessage() + ')');
                LOG.log(Level.SEVERE, msg, ex);
            }
            // Read the lipid modifications data.
            if (csvLines != null) {
                // Load adducts from CSV data into parent choices.
                parent.setChoices(loadLipidModificationsIntoChoices(csvLines, (LipidModification[]) parent.getChoices()));
            }
        }
    }
}
Also used : Window(java.awt.Window) LoadSaveFileChooser(net.sf.mzmine.util.dialogs.LoadSaveFileChooser) LipidModificationChoiceComponent(net.sf.mzmine.parameters.parametertypes.LipidModificationChoiceComponent) FileReader(java.io.FileReader) IOException(java.io.IOException) LipidModificationChoiceComponent(net.sf.mzmine.parameters.parametertypes.LipidModificationChoiceComponent) Component(java.awt.Component) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File)

Example 2 with LoadSaveFileChooser

use of net.sf.mzmine.util.dialogs.LoadSaveFileChooser in project mzmine2 by mzmine.

the class ExportLipidModificationsAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    // Parent component.
    final LipidModificationChoiceComponent parent = (LipidModificationChoiceComponent) SwingUtilities.getAncestorOfClass(LipidModificationChoiceComponent.class, (Component) e.getSource());
    if (parent != null) {
        // Create the chooser if necessary.
        if (chooser == null) {
            chooser = new LoadSaveFileChooser("Select lipid modifications File");
            chooser.addChoosableFileFilter(new FileNameExtensionFilter("Comma-separated values files", FILENAME_EXTENSION));
        }
        // Choose the file.
        final File file = chooser.getSaveFile(parent, FILENAME_EXTENSION);
        if (file != null) {
            // Export the modifications.
            try {
                exportLipidModificationsToFile(file, (LipidModification[]) parent.getChoices());
            } catch (IOException ex) {
                final Window window = (Window) SwingUtilities.getAncestorOfClass(Window.class, (Component) e.getSource());
                final String msg = "There was a problem writing the lipid modifications file.";
                MZmineCore.getDesktop().displayErrorMessage(window, "I/O Error", msg + "\n(" + ex.getMessage() + ')');
                LOG.log(Level.SEVERE, msg, ex);
            }
        }
    }
}
Also used : Window(java.awt.Window) LoadSaveFileChooser(net.sf.mzmine.util.dialogs.LoadSaveFileChooser) LipidModificationChoiceComponent(net.sf.mzmine.parameters.parametertypes.LipidModificationChoiceComponent) IOException(java.io.IOException) LipidModificationChoiceComponent(net.sf.mzmine.parameters.parametertypes.LipidModificationChoiceComponent) Component(java.awt.Component) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File)

Example 3 with LoadSaveFileChooser

use of net.sf.mzmine.util.dialogs.LoadSaveFileChooser in project mzmine2 by mzmine.

the class ImportAdductsAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    // Parent component.
    final AdductsComponent parent = (AdductsComponent) SwingUtilities.getAncestorOfClass(AdductsComponent.class, (Component) e.getSource());
    if (parent != null) {
        // Create the chooser if necessary.
        if (chooser == null) {
            chooser = new LoadSaveFileChooser("Select Adducts File");
            chooser.addChoosableFileFilter(new FileNameExtensionFilter("Comma-separated values files", FILENAME_EXTENSION));
        }
        // Select a file.
        final File file = chooser.getLoadFile(parent);
        if (file != null) {
            // Read the CSV file into a string array.
            String[][] csvLines = null;
            try {
                csvLines = CSVParser.parse(new FileReader(file));
            } catch (IOException ex) {
                final Window window = (Window) SwingUtilities.getAncestorOfClass(Window.class, (Component) e.getSource());
                final String msg = "There was a problem reading the adducts file.";
                MZmineCore.getDesktop().displayErrorMessage(window, "I/O Error", msg + "\n(" + ex.getMessage() + ')');
                LOG.log(Level.SEVERE, msg, ex);
            }
            // Read the adducts data.
            if (csvLines != null) {
                // Load adducts from CSV data into parent choices.
                parent.setChoices(loadAdductsIntoChoices(csvLines, (AdductType[]) parent.getChoices()));
            }
        }
    }
}
Also used : Window(java.awt.Window) LoadSaveFileChooser(net.sf.mzmine.util.dialogs.LoadSaveFileChooser) AdductsComponent(net.sf.mzmine.parameters.parametertypes.AdductsComponent) FileReader(java.io.FileReader) IOException(java.io.IOException) AdductsComponent(net.sf.mzmine.parameters.parametertypes.AdductsComponent) Component(java.awt.Component) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File)

Example 4 with LoadSaveFileChooser

use of net.sf.mzmine.util.dialogs.LoadSaveFileChooser in project mzmine2 by mzmine.

the class TICVisualizerWindow method exportChromatogram.

/**
 * Export a file's chromatogram.
 *
 * @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));
        }
    }
}
Also used : LoadSaveFileChooser(net.sf.mzmine.util.dialogs.LoadSaveFileChooser) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) File(java.io.File)

Example 5 with LoadSaveFileChooser

use of net.sf.mzmine.util.dialogs.LoadSaveFileChooser in project mzmine2 by mzmine.

the class ExportAdductsAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    // Parent component.
    final AdductsComponent parent = (AdductsComponent) SwingUtilities.getAncestorOfClass(AdductsComponent.class, (Component) e.getSource());
    if (parent != null) {
        // Create the chooser if necessary.
        if (chooser == null) {
            chooser = new LoadSaveFileChooser("Select Adducts File");
            chooser.addChoosableFileFilter(new FileNameExtensionFilter("Comma-separated values files", FILENAME_EXTENSION));
        }
        // Choose the file.
        final File file = chooser.getSaveFile(parent, FILENAME_EXTENSION);
        if (file != null) {
            // Export the adducts.
            try {
                exportAdductsToFile(file, (AdductType[]) parent.getChoices());
            } catch (IOException ex) {
                final Window window = (Window) SwingUtilities.getAncestorOfClass(Window.class, (Component) e.getSource());
                final String msg = "There was a problem writing the adducts file.";
                MZmineCore.getDesktop().displayErrorMessage(window, "I/O Error", msg + "\n(" + ex.getMessage() + ')');
                LOG.log(Level.SEVERE, msg, ex);
            }
        }
    }
}
Also used : Window(java.awt.Window) LoadSaveFileChooser(net.sf.mzmine.util.dialogs.LoadSaveFileChooser) AdductsComponent(net.sf.mzmine.parameters.parametertypes.AdductsComponent) IOException(java.io.IOException) AdductsComponent(net.sf.mzmine.parameters.parametertypes.AdductsComponent) Component(java.awt.Component) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File)

Aggregations

File (java.io.File)5 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)5 LoadSaveFileChooser (net.sf.mzmine.util.dialogs.LoadSaveFileChooser)5 Component (java.awt.Component)4 Window (java.awt.Window)4 IOException (java.io.IOException)4 FileReader (java.io.FileReader)2 AdductsComponent (net.sf.mzmine.parameters.parametertypes.AdductsComponent)2 LipidModificationChoiceComponent (net.sf.mzmine.parameters.parametertypes.LipidModificationChoiceComponent)2 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)1