Search in sources :

Example 6 with OpenDialog

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;
}
Also used : GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) UnicodeReader(gdsc.core.utils.UnicodeReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) OpenDialog(ij.io.OpenDialog) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) FilterSettings(gdsc.smlm.ij.settings.FilterSettings)

Example 7 with OpenDialog

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());
}
Also used : CreateDataSettings(gdsc.smlm.ij.settings.CreateDataSettings) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) PeakResult(gdsc.smlm.results.PeakResult) AttributePeakResult(gdsc.smlm.results.AttributePeakResult) OpenDialog(ij.io.OpenDialog)

Example 8 with OpenDialog

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();
        }
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) ParameterSettings(gdsc.smlm.ij.settings.ParameterSettings) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) TransformerException(javax.xml.transform.TransformerException) XStreamException(com.thoughtworks.xstream.XStreamException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) OpenDialog(ij.io.OpenDialog) XPathFactory(javax.xml.xpath.XPathFactory) BatchSettings(gdsc.smlm.ij.settings.BatchSettings) Checkbox(java.awt.Checkbox) FileOutputStream(java.io.FileOutputStream)

Example 9 with OpenDialog

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);
            }
        }
    }
}
Also used : OpenDialog(ij.io.OpenDialog)

Example 10 with OpenDialog

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
                }
            }
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) FilterSettings(gdsc.smlm.ij.settings.FilterSettings) IOException(java.io.IOException) OpenDialog(ij.io.OpenDialog)

Aggregations

OpenDialog (ij.io.OpenDialog)13 IOException (java.io.IOException)5 GlobalSettings (gdsc.smlm.ij.settings.GlobalSettings)3 FilePeakResults (gdsc.smlm.results.FilePeakResults)3 FilterSettings (gdsc.smlm.ij.settings.FilterSettings)2 BufferedWriter (java.io.BufferedWriter)2 FileOutputStream (java.io.FileOutputStream)2 FileWriter (java.io.FileWriter)2 NullArgumentException (org.apache.commons.math3.exception.NullArgumentException)2 XStreamException (com.thoughtworks.xstream.XStreamException)1 UnicodeReader (gdsc.core.utils.UnicodeReader)1 BatchSettings (gdsc.smlm.ij.settings.BatchSettings)1 CreateDataSettings (gdsc.smlm.ij.settings.CreateDataSettings)1 ParameterSettings (gdsc.smlm.ij.settings.ParameterSettings)1 FluorophoreSequenceModel (gdsc.smlm.model.FluorophoreSequenceModel)1 LocalisationModel (gdsc.smlm.model.LocalisationModel)1 AttributePeakResult (gdsc.smlm.results.AttributePeakResult)1 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)1 PeakResult (gdsc.smlm.results.PeakResult)1 Trace (gdsc.smlm.results.Trace)1