use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.
the class CreateData method saveFluorophores.
/**
* Save the fluorophores to a text file
*
* @param fluorophores
*/
private void saveFluorophores(List<? extends FluorophoreSequenceModel> fluorophores) {
if (!settings.saveFluorophores || fluorophores == null)
return;
String[] path = Utils.decodePath(settings.fluorophoresFilename);
OpenDialog chooser = new OpenDialog("Fluorophores_File", path[0], path[1]);
if (chooser.getFileName() != null) {
settings.fluorophoresFilename = chooser.getDirectory() + chooser.getFileName();
settings.fluorophoresFilename = Utils.replaceExtension(settings.fluorophoresFilename, "xls");
BufferedWriter output = null;
try {
output = new BufferedWriter(new FileWriter(settings.fluorophoresFilename));
output.write(createResultsFileHeader());
output.write("#Id\tn-Blinks\tStart\tStop\t...");
output.newLine();
for (int id = 1; id <= fluorophores.size(); id++) {
FluorophoreSequenceModel f = fluorophores.get(id - 1);
StringBuffer sb = new StringBuffer();
sb.append(f.getId()).append("\t");
sb.append(f.getNumberOfBlinks()).append("\t");
for (double[] burst : f.getBurstSequence()) {
sb.append(Utils.rounded(burst[0], 3)).append("\t").append(Utils.rounded(burst[1], 3)).append("\t");
}
output.write(sb.toString());
output.newLine();
}
} catch (Exception e) {
// Q. Add better handling of errors?
e.printStackTrace();
IJ.log("Failed to save fluorophores to file: " + settings.fluorophoresFilename);
} finally {
if (output != null) {
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.
the class BatchPeakFit method itemStateChanged.
/*
* (non-Javadoc)
*
* @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
*/
public void itemStateChanged(ItemEvent e) {
// When the checkbox is clicked, create a default configuration file and update the
// GenericDialog with the file location.
Checkbox cb = (Checkbox) e.getSource();
if (cb.getState()) {
cb.setState(false);
Document doc = getDefaultSettingsXmlDocument();
if (doc == null)
return;
try {
// Look for nodes that are part of the fit configuration
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
XPathExpression expr = xpath.compile("//gdsc.smlm.engine.FitEngineConfiguration//*");
// For each node, add the name and value to the BatchParameters
BatchSettings batchSettings = new BatchSettings();
batchSettings.resultsDirectory = System.getProperty("java.io.tmpdir");
batchSettings.images.add("/path/to/image.tif");
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (// Only nodes with a single text entry
node.getChildNodes().getLength() == 1) {
batchSettings.parameters.add(new ParameterSettings(node.getNodeName(), node.getTextContent()));
}
}
// Save the settings file
String[] path = Utils.decodePath(configFilenameText.getText());
OpenDialog chooser = new OpenDialog("Settings_file", path[0], path[1]);
if (chooser.getFileName() != null) {
String newFilename = chooser.getDirectory() + chooser.getFileName();
if (!newFilename.endsWith(".xml"))
newFilename += ".xml";
FileOutputStream fs = null;
try {
fs = new FileOutputStream(newFilename);
xs.toXML(batchSettings, fs);
} finally {
if (fs != null) {
fs.close();
}
}
// Update dialog filename
configFilenameText.setText(newFilename);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.
the class BatchPeakFit method mouseClicked.
/*
* (non-Javadoc)
*
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
*/
public void mouseClicked(MouseEvent e) {
if (// Double-click
e.getClickCount() > 1) {
if (e.getSource() == configFilenameText) {
String[] path = Utils.decodePath(configFilenameText.getText());
OpenDialog chooser = new OpenDialog("Settings_file", path[0], path[1]);
if (chooser.getFileName() != null) {
String newFilename = chooser.getDirectory() + chooser.getFileName();
configFilenameText.setText(newFilename);
}
}
}
}
use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.
the class FilterAnalysis method saveFilterSets.
private void saveFilterSets(List<FilterSet> filterSets) {
GlobalSettings gs = SettingsManager.loadSettings();
FilterSettings filterSettings = gs.getFilterSettings();
String[] path = Utils.decodePath(filterSettings.filterSetFilename);
OpenDialog chooser = new OpenDialog("Filter_File", path[0], path[1]);
if (chooser.getFileName() != null) {
filterSettings.filterSetFilename = chooser.getDirectory() + chooser.getFileName();
OutputStreamWriter out = null;
try {
FileOutputStream fos = new FileOutputStream(filterSettings.filterSetFilename);
out = new OutputStreamWriter(fos, "UTF-8");
XStreamWrapper.getInstance().toXML(filterSets, out);
SettingsManager.saveSettings(gs);
} catch (Exception e) {
IJ.log("Unable to save the filter sets to file: " + e.getMessage());
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
// Ignore
}
}
}
}
}
use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.
the class LoadLocalisations method run.
/*
* (non-Javadoc)
*
* @see ij.plugin.PlugIn#run(java.lang.String)
*/
public void run(String arg) {
SMLMUsageTracker.recordPlugin(this.getClass(), arg);
GlobalSettings globalSettings = SettingsManager.loadSettings();
CreateDataSettings settings = globalSettings.getCreateDataSettings();
String[] path = Utils.decodePath(settings.localisationsFilename);
OpenDialog chooser = new OpenDialog("Localisations_File", path[0], path[1]);
if (chooser.getFileName() == null)
return;
settings.localisationsFilename = chooser.getDirectory() + chooser.getFileName();
SettingsManager.saveSettings(globalSettings);
LocalisationList localisations = loadLocalisations(settings.localisationsFilename);
if (localisations == null)
// Cancelled
return;
if (localisations.isEmpty()) {
IJ.error(TITLE, "No localisations could be loaded");
return;
}
MemoryPeakResults results = localisations.toPeakResults();
// Ask the user what depth to use to create the in-memory results
if (!getZDepth(results))
return;
if (myLimitZ) {
MemoryPeakResults results2 = new MemoryPeakResults(results.size());
results.setName(name);
results.copySettings(results);
for (PeakResult peak : results.getResults()) {
if (peak.error < minz || peak.error > maxz)
continue;
results2.add(peak);
}
results = results2;
}
// Create the in-memory results
if (results.size() > 0) {
MemoryPeakResults.addResults(results);
}
IJ.showStatus(String.format("Loaded %d localisations", results.size()));
if (myLimitZ)
Utils.log("Loaded %d localisations, z between %.2f - %.2f", results.size(), minz, maxz);
else
Utils.log("Loaded %d localisations", results.size());
}
Aggregations