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();
}
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());
}
}
}
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;
}
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);
}
Aggregations