use of uk.ac.sussex.gdsc.core.ij.gui.MultiDialog in project GDSC-SMLM by aherbert.
the class ConfigurationTemplate method loadSelectedStandardTemplates.
/**
* Load selected standard templates.
*
* @param settings the settings
*/
private static void loadSelectedStandardTemplates(ConfigurationTemplateSettings.Builder settings) {
final String[] inlineNames = listInlineTemplates();
final TemplateResource[] templateResources = listTemplateResources();
if (templateResources.length + inlineNames.length == 0) {
return;
}
final List<String> items = new LocalList<>();
Arrays.stream(inlineNames).forEach(items::add);
Arrays.stream(templateResources).forEach(t -> items.add(t.name));
final MultiDialog md = new MultiDialog("Select templates", items);
md.setSelected(settings.getSelectedStandardTemplatesList());
md.setHelpUrl(HelpUrls.getUrl("template-manager-load-standard"));
md.showDialog();
if (md.wasCancelled()) {
return;
}
final List<String> selected = md.getSelectedResults();
if (selected.isEmpty()) {
return;
}
// Save
settings.clearSelectedStandardTemplates();
settings.addAllSelectedStandardTemplates(selected);
int count = templates.size();
// Keep a hash of those not loaded from inline resources
final HashSet<String> remaining = new HashSet<>(selected.size());
for (int i = 0; i < selected.size(); i++) {
final String name = selected.get(i);
// Try and get the template from inline resources
final Template t = inlineTemplates.get(name);
if (t != null) {
templates.put(name, t);
} else {
remaining.add(name);
}
}
if (!remaining.isEmpty()) {
// Build a list of resources to load
final LocalList<TemplateResource> list = new LocalList<>(remaining.size());
for (final TemplateResource t : templateResources) {
if (remaining.contains(t.name)) {
list.add(t);
}
}
loadTemplateResources(list.toArray(new TemplateResource[0]));
}
count = templates.size() - count;
if (count > 0) {
saveLoadedTemplates(templates);
IJ.showMessage(TITLE, "Loaded " + TextUtils.pleural(count, "new standard template"));
}
}
use of uk.ac.sussex.gdsc.core.ij.gui.MultiDialog in project GDSC-SMLM by aherbert.
the class ConfigurationTemplate method removeLoadedTemplates.
private void removeLoadedTemplates() {
if (templates.isEmpty()) {
IJ.error(title, "No templates are currently loaded");
return;
}
final MultiDialog md = new MultiDialog("Select templates to remove", getTemplateNamesAsList());
md.setHelpUrl(HelpUrls.getUrl("template-manager-remove"));
md.showDialog();
if (md.wasCancelled()) {
return;
}
final List<String> selected = md.getSelectedResults();
if (selected.isEmpty()) {
// Nothing to do
return;
}
if (selected.size() == templates.size()) {
clearTemplates();
} else {
for (final String name : selected) {
templates.remove(name);
}
}
saveLoadedTemplates(templates);
}
use of uk.ac.sussex.gdsc.core.ij.gui.MultiDialog in project GDSC-SMLM by aherbert.
the class TraceDiffusion method showMultiDialog.
private boolean showMultiDialog(ArrayList<MemoryPeakResults> allResults) {
multiMode = true;
// Show a list box containing all the results. This should remember the last set of chosen
// items.
final MultiDialog md = ResultsManager.createMultiDialog(TITLE);
md.setSelected(selectedRef.get());
md.setHelpUrl(HelpUrls.getUrl("trace-diffusion-multi"));
md.showDialog();
if (md.wasCancelled()) {
return false;
}
final List<String> selected = md.getSelectedResults();
if (selected.isEmpty()) {
IJ.error(TITLE, "No results were selected");
return false;
}
selectedRef.set(selected);
for (final String name : selected) {
final MemoryPeakResults r = MemoryPeakResults.getResults(name);
if (r != null) {
allResults.add(r);
}
}
if (allResults.isEmpty()) {
return false;
}
// Check calibration exists for the first set of results
if (!checkCalibration(allResults.get(0))) {
return false;
}
// Check the calibration is the same for the rest
final CalibrationReader cal = allResults.get(0).getCalibrationReader();
final double nmPerPixel = cal.getNmPerPixel();
final double exposureTime = cal.getExposureTime();
final DistanceUnit distanceUnit = cal.getDistanceUnit();
for (int i = 1; i < allResults.size(); i++) {
final MemoryPeakResults results = allResults.get(i);
if (!results.hasCalibration() || results.getCalibrationReader().getExposureTime() != exposureTime || results.getNmPerPixel() != nmPerPixel || results.getDistanceUnit() != distanceUnit) {
IJ.error(TITLE, "The exposure time, pixel pitch and distance unit must match across all the results");
return false;
}
}
return true;
}
use of uk.ac.sussex.gdsc.core.ij.gui.MultiDialog in project GDSC-SMLM by aherbert.
the class TraceExporter method showMultiDialog.
private static boolean showMultiDialog(ArrayList<MemoryPeakResults> allResults, MemoryResultsList items) {
// Show a list box containing all the results. This should remember the last set of chosen
// items.
final MultiDialog md = new MultiDialog(TITLE, items);
md.setDisplayConverter(items.getDisplayConverter());
md.setSelected(selectedRef.get());
md.showDialog();
if (md.wasCancelled()) {
return false;
}
final List<String> selected = md.getSelectedResults();
if (selected.isEmpty()) {
IJ.error(TITLE, "No results were selected");
return false;
}
selectedRef.set(selected);
for (final String name : selected) {
final MemoryPeakResults r = MemoryPeakResults.getResults(name);
if (r != null) {
allResults.add(r);
}
}
return !allResults.isEmpty();
}
use of uk.ac.sussex.gdsc.core.ij.gui.MultiDialog in project GDSC-SMLM by aherbert.
the class ResultsManager method batchSave.
/**
* Batch save a set of results files.
*/
private void batchSave() {
if (MemoryPeakResults.isMemoryEmpty()) {
IJ.error(TITLE, "No localisations in memory");
return;
}
final MultiDialog md = createMultiDialog(TITLE);
md.setSelected(lastSelected.get());
md.setHelpUrl(HelpUrls.getUrl("batch-save-results"));
md.showDialog();
if (md.wasCancelled()) {
return;
}
final List<String> selected = md.getSelectedResults();
if (selected.isEmpty()) {
return;
}
lastSelected.set(selected);
resultsSettings = SettingsManager.readResultsSettings(0).toBuilder();
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
addFileResultsOptions(gd, resultsSettings, FLAG_RESULTS_DIRECTORY | FLAG_NO_SECTION_HEADER);
gd.addHelp(HelpUrls.getUrl("batch-save-results"));
gd.showDialog();
if (gd.wasCanceled()) {
return;
}
gd.collectOptions();
final ResultsFileSettings.Builder b = resultsSettings.getResultsFileSettingsBuilder();
final String dir = gd.getNextString();
b.setFileFormatValue(gd.getNextChoiceIndex());
b.setResultsDirectory(dir);
SettingsManager.writeSettings(resultsSettings);
if (!new File(dir).exists()) {
IJ.error(TITLE, "Output directory does not exist");
return;
}
final ResultsFileSettings resultsFileSettings = resultsSettings.getResultsFileSettings();
if (resultsFileSettings.getFileFormatValue() <= 0) {
IJ.error(TITLE, "No output file format");
return;
}
int count = 0;
for (final String name : selected) {
final MemoryPeakResults r = MemoryPeakResults.getResults(name);
if (r != null && save(resultsFileSettings, r)) {
count++;
}
}
IJ.showStatus("Saved " + TextUtils.pleural(count, "dataset"));
}
Aggregations