use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class About method installResource.
/**
* @param resource
* @param ijDirectory
* @param destinationName
* @param resourceTitle
* @param notes
* @param options
* @return -1 on error, 0 if installed, 1 if removed
*/
private static int installResource(String resource, String ijDirectory, String destinationName, String resourceTitle, String notes, ConfigureOption... options) {
Class<About> resourceClass = About.class;
InputStream toolsetStream = resourceClass.getResourceAsStream(resource);
if (toolsetStream == null)
return -1;
String dir = IJ.getDirectory(ijDirectory);
if (dir == null) {
IJ.error("Unable to locate " + ijDirectory + " directory");
return -1;
}
EnumSet<ConfigureOption> opt = EnumSet.of(options[0], options);
GenericDialog gd = new GenericDialog(TITLE);
String filename = dir + destinationName;
boolean fileExists = new File(filename).exists();
StringBuilder sb = new StringBuilder();
sb.append("Configure resource '").append(resourceTitle).append("' at:\n \n").append(filename);
if (notes != null)
sb.append("\n \n").append(XmlUtils.lineWrap(notes, 80, 0, null));
gd.addMessage(sb.toString());
// Configure the options
String[] choices = new String[3];
ConfigureOption[] optChoices = new ConfigureOption[choices.length];
int count = 0;
if (opt.contains(ConfigureOption.INSTALL)) {
choices[count] = ConfigureOption.INSTALL.toString();
if (fileExists)
choices[count] += " (overwrite)";
optChoices[count] = ConfigureOption.INSTALL;
count++;
}
if (opt.contains(ConfigureOption.EDIT)) {
choices[count] = ConfigureOption.EDIT.toString();
if (fileExists)
choices[count] += " (overwrite)";
optChoices[count] = ConfigureOption.EDIT;
count++;
}
if (opt.contains(ConfigureOption.REMOVE) && fileExists) {
choices[count] = ConfigureOption.REMOVE.toString();
optChoices[count] = ConfigureOption.REMOVE;
count++;
}
if (count == 0)
return -1;
choices = Arrays.copyOf(choices, count);
gd.addChoice("Option", choices, choices[0]);
gd.showDialog();
if (gd.wasCanceled())
return -1;
ConfigureOption choice = optChoices[gd.getNextChoiceIndex()];
if (choice == ConfigureOption.REMOVE) {
try {
new File(filename).delete();
return 1;
} catch (SecurityException e) {
IJ.error("Unable to remove existing file");
}
return -1;
}
// Read the file
LinkedList<String> contents = new LinkedList<String>();
BufferedReader input = null;
try {
// Read
input = new BufferedReader(new UnicodeReader(toolsetStream, null));
String line;
while ((line = input.readLine()) != null) {
contents.add(line);
}
} catch (IOException e) {
IJ.error("Unable to install " + resourceTitle + ".\n \n" + e.getMessage());
return -1;
} finally {
close(input);
}
if (choice == ConfigureOption.EDIT) {
// Allow the user to edit the file contents
gd = new GenericDialog(TITLE);
gd.addMessage("Edit the file contents before install:");
sb.setLength(0);
for (String line : contents) sb.append(line).append("\n");
gd.addTextAreas(sb.toString(), null, 20, 80);
gd.showDialog();
if (gd.wasOKed()) {
contents.clear();
String text = gd.getNextText();
for (String line : text.split("\n")) contents.add(line);
}
}
// Install the file
BufferedWriter output = null;
try {
// Write
FileOutputStream fos = new FileOutputStream(filename);
output = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8"));
for (String content : contents) {
output.write(content);
output.newLine();
}
} catch (IOException e) {
IJ.error("Unable to install " + resourceTitle + ".\n \n" + e.getMessage());
} finally {
close(output);
}
return 0;
}
use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class BatchPeakFit method showDialog.
/**
* Ask for parameters
*
* @return True if not cancelled
*/
private boolean showDialog() {
GenericDialog gd = new GenericDialog(TITLE);
gd.addHelp(About.HELP_URL);
gd.addStringField("Config_filename", configFilename);
gd.addCheckbox("Create_config_file", false);
if (Utils.isShowGenericDialog()) {
configFilenameText = (TextField) gd.getStringFields().get(0);
configFilenameText.setColumns(30);
configFilenameText.addMouseListener(this);
Checkbox cb = (Checkbox) gd.getCheckboxes().get(0);
cb.addItemListener(this);
}
gd.showDialog();
if (gd.wasCanceled())
return false;
configFilename = gd.getNextString().trim();
return true;
}
use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class About method showAbout.
public static void showAbout() {
// Locate the README.txt file and load that into the dialog. Include revision
Class<About> resourceClass = About.class;
InputStream readmeStream = resourceClass.getResourceAsStream("/gdsc/smlm/README.txt");
StringBuilder msg = new StringBuilder();
String helpURL = HELP_URL;
String version = Version.getVersion();
String buildDate = Version.getBuildDate();
BufferedReader input = null;
try {
// Read the contents of the README file
input = new BufferedReader(new UnicodeReader(readmeStream, null));
String line;
while ((line = input.readLine()) != null) {
if (line.contains("http:")) {
helpURL = line;
} else {
if (line.equals(""))
// Required to insert a line in the GenericDialog
line = " ";
msg.append(line).append("\n");
}
}
} catch (IOException e) {
// Default message
msg.append("GDSC SMLM Plugins for ImageJ\n");
msg.append(" \n");
msg.append("Copyright (C) ").append(YEAR).append(" Alex Herbert\n");
msg.append("MRC Genome Damage and Stability Centre\n");
msg.append("University of Sussex, UK\n");
} finally {
try {
input.close();
} catch (IOException e) {
}
}
// Build final message
msg = new StringBuilder(msg.toString().trim());
if (version != Version.UNKNOWN || buildDate != Version.UNKNOWN)
msg.append("\n \n");
if (version != Version.UNKNOWN)
msg.append("Version : ").append(version).append("\n");
if (buildDate != Version.UNKNOWN)
msg.append("Build Date : ").append(buildDate).append("\n");
if (helpURL != null)
msg.append("\n \n(Click help for more information)");
GenericDialog gd = new GenericDialog(TITLE);
gd.addMessage(msg.toString());
gd.addHelp(helpURL);
gd.hideCancelButton();
gd.showDialog();
}
use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class BenchmarkFilterAnalysis method showIterationDialog.
private boolean showIterationDialog() {
GenericDialog gd = new GenericDialog(TITLE);
StringBuilder sb = new StringBuilder();
sb.append("Iterate ").append(BenchmarkSpotFit.TITLE).append(" & ").append(TITLE).append(".\n");
sb.append(BenchmarkSpotFit.TITLE).append(" will be run once interactively if results cannot be loaded.\n");
sb.append(TITLE).append(" will be run once interactively to obtain settings.\n \n");
sb.append("Configure the convergence criteria for iteration:");
gd.addMessage(sb.toString());
gd.addNumericField("Score_Tolerance", iterationScoreTolerance, -1);
gd.addNumericField("Filter_Tolerance", iterationFilterTolerance, -1);
gd.addCheckbox("Compare_Results", iterationCompareResults);
gd.addNumericField("Compare_Distance", iterationCompareDistance, 2);
gd.addNumericField("Iter_Max_Iterations", iterationMaxIterations, 0);
gd.addMessage("Configure how the parameter range is updated per iteration:");
gd.addSlider("Min_range_reduction", 0, 1, iterationMinRangeReduction);
gd.addSlider("Min_range_reduction_iteration", 1, 10, iterationMinRangeReductionIteration);
gd.addCheckbox("Converge_before_refit", iterationConvergeBeforeRefit);
gd.showDialog();
if (gd.wasCanceled())
return false;
iterationScoreTolerance = gd.getNextNumber();
iterationFilterTolerance = gd.getNextNumber();
iterationCompareResults = gd.getNextBoolean();
iterationCompareDistance = Math.abs(gd.getNextNumber());
iterationMaxIterations = (int) gd.getNextNumber();
iterationMinRangeReduction = Math.abs(gd.getNextNumber());
iterationMinRangeReductionIteration = (int) Math.abs(gd.getNextNumber());
iterationConvergeBeforeRefit = gd.getNextBoolean();
return true;
}
use of ij.gui.GenericDialog in project GDSC-SMLM by aherbert.
the class BenchmarkFilterAnalysis method showScoreDialog.
private boolean showScoreDialog() {
GenericDialog gd = new GenericDialog(TITLE);
gd.addHelp(About.HELP_URL);
addSimulationData(gd);
// Get the last scored filter or default to the best filter
getScoreFilter();
gd.addSlider("Fail_count", 0, 20, scoreFailCount);
if (BenchmarkSpotFit.computeDoublets)
gd.addSlider("Residuals_threshold", 0.01, 1, scoreResidualsThreshold);
gd.addNumericField("Duplicate_distance", scoreDuplicateDistance, 2);
gd.addTextAreas(XmlUtils.convertQuotes(scoreFilter.toXML()), null, 6, 60);
gd.addCheckbox("Reset_filter", false);
//gd.addCheckbox("Show_table", showResultsTable);
gd.addCheckbox("Show_summary", showSummaryTable);
gd.addCheckbox("Clear_tables", clearTables);
//gd.addSlider("Summary_top_n", 0, 20, summaryTopN);
gd.addCheckbox("Save_best_filter", saveBestFilter);
gd.addCheckbox("Save_template", saveTemplate);
gd.addCheckbox("Calculate_sensitivity", calculateSensitivity);
gd.addSlider("Delta", 0.01, 1, delta);
if (!simulationParameters.fixedDepth)
gd.addCheckbox("Depth_recall_analysis", depthRecallAnalysis);
gd.addCheckbox("Score_analysis", scoreAnalysis);
gd.addChoice("Component_analysis", COMPONENT_ANALYSIS, COMPONENT_ANALYSIS[componentAnalysis]);
gd.addStringField("Title", resultsTitle, 20);
String[] labels = { "Show_TP", "Show_FP", "Show_FN" };
gd.addCheckboxGroup(1, 3, labels, new boolean[] { showTP, showFP, showFN });
// Dialog to have a reset checkbox. This reverts back to the default.
if (Utils.isShowGenericDialog()) {
final Checkbox cb = (Checkbox) (gd.getCheckboxes().get(0));
@SuppressWarnings("unchecked") final Vector<TextField> v = gd.getNumericFields();
final TextArea ta = gd.getTextArea1();
cb.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (cb.getState()) {
scoreFilter = null;
getScoreFilter();
int i = 0;
v.get(i++).setText(Integer.toString(scoreFailCount));
if (BenchmarkSpotFit.computeDoublets)
v.get(i++).setText(Double.toString(scoreResidualsThreshold));
v.get(i++).setText(Double.toString(scoreDuplicateDistance));
ta.setText(XmlUtils.convertQuotes(scoreFilter.toXML()));
}
}
});
}
gd.showDialog();
if (gd.wasCanceled())
return false;
scoreFailCount = (int) Math.abs(gd.getNextNumber());
if (BenchmarkSpotFit.computeDoublets)
scoreResidualsThreshold = Math.abs(gd.getNextNumber());
scoreDuplicateDistance = Math.abs(gd.getNextNumber());
String xml = gd.getNextText();
try {
scoreFilter = (DirectFilter) DirectFilter.fromXML(xml);
} catch (Exception e) {
scoreFilter = null;
getScoreFilter();
}
boolean reset = gd.getNextBoolean();
if (reset) {
scoreFilter = null;
getScoreFilter();
}
//showResultsTable = gd.getNextBoolean();
showSummaryTable = gd.getNextBoolean();
clearTables = gd.getNextBoolean();
//summaryTopN = (int) Math.abs(gd.getNextNumber());
saveBestFilter = gd.getNextBoolean();
saveTemplate = gd.getNextBoolean();
calculateSensitivity = gd.getNextBoolean();
delta = gd.getNextNumber();
if (!simulationParameters.fixedDepth)
depthRecallAnalysis = gd.getNextBoolean();
scoreAnalysis = gd.getNextBoolean();
componentAnalysis = gd.getNextChoiceIndex();
resultsTitle = gd.getNextString();
showTP = gd.getNextBoolean();
showFP = gd.getNextBoolean();
showFN = gd.getNextBoolean();
if (gd.invalidNumber())
return false;
resultsPrefix = BenchmarkSpotFit.resultPrefix + "\t" + resultsTitle + "\t";
createResultsPrefix2(scoreFailCount, scoreResidualsThreshold, scoreDuplicateDistance);
// Check there is one output
if (!showSummaryTable && !calculateSensitivity && !saveBestFilter && !saveTemplate) {
IJ.error(TITLE, "No output selected");
return false;
}
// Check arguments
try {
Parameters.isAboveZero("Delta", delta);
Parameters.isBelow("Delta", delta, 1);
} catch (IllegalArgumentException e) {
IJ.error(TITLE, e.getMessage());
return false;
}
if (!selectTableColumns())
return false;
return true;
}
Aggregations