use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.
the class FilterAnalysis method readFilterSets.
@SuppressWarnings("unchecked")
private List<FilterSet> readFilterSets() {
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) {
IJ.showStatus("Reading filters ...");
filterSettings.filterSetFilename = chooser.getDirectory() + chooser.getFileName();
BufferedReader input = null;
try {
FileInputStream fis = new FileInputStream(filterSettings.filterSetFilename);
input = new BufferedReader(new UnicodeReader(fis, null));
Object o = XStreamWrapper.getInstance().fromXML(input);
if (o != null && o instanceof List<?>) {
SettingsManager.saveSettings(gs);
return (List<FilterSet>) o;
}
IJ.log("No filter sets defined in the specified file: " + filterSettings.filterSetFilename);
} catch (Exception e) {
IJ.log("Unable to load the filter sets from file: " + e.getMessage());
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
// Ignore
}
}
IJ.showStatus("");
}
}
return null;
}
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());
}
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
}
}
}
}
}
Aggregations