Search in sources :

Example 31 with OpenDialog

use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.

the class FilterAnalysis method readFilterSets.

@SuppressWarnings("unchecked")
private static List<FilterSet> readFilterSets() {
    final GUIFilterSettings.Builder filterSettings = SettingsManager.readGuiFilterSettings(0).toBuilder();
    final String[] path = ImageJUtils.decodePath(filterSettings.getFilterSetFilename());
    final OpenDialog chooser = new OpenDialog("Filter_File", path[0], path[1]);
    if (chooser.getFileName() != null) {
        IJ.showStatus("Reading filters ...");
        filterSettings.setFilterSetFilename(chooser.getDirectory() + chooser.getFileName());
        try (BufferedReader input = Files.newBufferedReader(Paths.get(filterSettings.getFilterSetFilename()))) {
            // Use the instance so we can catch the exception
            final Object o = FilterXStreamUtils.getXStreamInstance().fromXML(input);
            if (o instanceof List<?>) {
                SettingsManager.writeSettings(filterSettings.build());
                return (List<FilterSet>) o;
            }
            IJ.log("No filter sets defined in the specified file: " + filterSettings.getFilterSetFilename());
        } catch (final Exception ex) {
            IJ.log("Unable to load the filter sets from file: " + ex.getMessage());
        } finally {
            IJ.showStatus("");
        }
    }
    return Collections.emptyList();
}
Also used : GUIFilterSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.GUIFilterSettings) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) OpenDialog(ij.io.OpenDialog)

Example 32 with OpenDialog

use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.

the class FilterAnalysis method saveFilterSets.

private static void saveFilterSets(List<FilterSet> filterSets) {
    final GUIFilterSettings.Builder filterSettings = SettingsManager.readGuiFilterSettings(0).toBuilder();
    final String[] path = ImageJUtils.decodePath(filterSettings.getFilterSetFilename());
    final OpenDialog chooser = new OpenDialog("Filter_File", path[0], path[1]);
    if (chooser.getFileName() != null) {
        filterSettings.setFilterSetFilename(chooser.getDirectory() + chooser.getFileName());
        try (BufferedWriter out = Files.newBufferedWriter(Paths.get(filterSettings.getFilterSetFilename()))) {
            // Use the instance so we can catch the exception
            FilterXStreamUtils.getXStreamInstance().toXML(filterSets, out);
            SettingsManager.writeSettings(filterSettings.build());
        } catch (final Exception ex) {
            IJ.log("Unable to save the filter sets to file: " + ex.getMessage());
        }
    }
}
Also used : GUIFilterSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.GUIFilterSettings) OpenDialog(ij.io.OpenDialog) BufferedWriter(java.io.BufferedWriter)

Example 33 with OpenDialog

use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.

the class DriftCalculator method getDriftFilename.

private boolean getDriftFilename() {
    final String[] path = ImageJUtils.decodePath(settings.driftFilename);
    final OpenDialog chooser = new OpenDialog("Drift_file", path[0], path[1]);
    if (chooser.getFileName() == null) {
        return false;
    }
    settings.driftFilename = chooser.getDirectory() + chooser.getFileName();
    FileUtils.replaceExtension(settings.driftFilename, "tsv");
    return true;
}
Also used : OpenDialog(ij.io.OpenDialog)

Example 34 with OpenDialog

use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.

the class LoadLocalisations method run.

@Override
public void run(String arg) {
    SmlmUsageTracker.recordPlugin(this.getClass(), arg);
    final LoadLocalisationsSettings.Builder settings = SettingsManager.readLoadLocalisationsSettings(0).toBuilder();
    final String[] path = ImageJUtils.decodePath(settings.getLocalisationsFilename());
    final OpenDialog chooser = new OpenDialog("Localisations_File", path[0], path[1]);
    if (chooser.getFileName() == null) {
        return;
    }
    settings.setLocalisationsFilename(chooser.getDirectory() + chooser.getFileName());
    final LocalisationList localisations = loadLocalisations(settings);
    SettingsManager.writeSettings(settings.build());
    if (localisations == null) {
        // Cancelled
        return;
    }
    if (localisations.isEmpty()) {
        IJ.error(TITLE, "No localisations could be loaded");
        return;
    }
    final MemoryPeakResults results = localisations.toPeakResults(settings.getName());
    // Create the in-memory results
    if (results.size() > 0) {
        MemoryPeakResults.addResults(results);
    }
    final String msg = "Loaded " + TextUtils.pleural(results.size(), "localisation");
    IJ.showStatus(msg);
    ImageJUtils.log(msg);
}
Also used : LoadLocalisationsSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.LoadLocalisationsSettings) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) OpenDialog(ij.io.OpenDialog)

Aggregations

OpenDialog (ij.io.OpenDialog)34 IOException (java.io.IOException)13 ImagePlus (ij.ImagePlus)6 FormatException (loci.formats.FormatException)6 BufferedWriter (java.io.BufferedWriter)5 File (java.io.File)5 NullArgumentException (org.apache.commons.math3.exception.NullArgumentException)4 GlobalSettings (gdsc.smlm.ij.settings.GlobalSettings)3 FilePeakResults (gdsc.smlm.results.FilePeakResults)3 AmiraMeshDecoder (amira.AmiraMeshDecoder)2 FilterSettings (gdsc.smlm.ij.settings.FilterSettings)2 FileSaver (ij.io.FileSaver)2 Layer (ini.trakem2.display.Layer)2 Patch (ini.trakem2.display.Patch)2 YesNoDialog (ini.trakem2.display.YesNoDialog)2 BufferedReader (java.io.BufferedReader)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 FileWriter (java.io.FileWriter)2 ArrayList (java.util.ArrayList)2