Search in sources :

Example 16 with OpenDialog

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();
                }
            }
        }
    }
}
Also used : FluorophoreSequenceModel(gdsc.smlm.model.FluorophoreSequenceModel) FileWriter(java.io.FileWriter) IOException(java.io.IOException) IOException(java.io.IOException) NullArgumentException(org.apache.commons.math3.exception.NullArgumentException) OpenDialog(ij.io.OpenDialog) BufferedWriter(java.io.BufferedWriter)

Example 17 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 18 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 19 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)

Example 20 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)

Aggregations

OpenDialog (ij.io.OpenDialog)34 IOException (java.io.IOException)13 ImagePlus (ij.ImagePlus)6 FormatException (loci.formats.FormatException)6 BufferedWriter (java.io.BufferedWriter)5 File (java.io.File)5 NullArgumentException (org.apache.commons.math3.exception.NullArgumentException)4 GlobalSettings (gdsc.smlm.ij.settings.GlobalSettings)3 FilePeakResults (gdsc.smlm.results.FilePeakResults)3 AmiraMeshDecoder (amira.AmiraMeshDecoder)2 FilterSettings (gdsc.smlm.ij.settings.FilterSettings)2 FileSaver (ij.io.FileSaver)2 Layer (ini.trakem2.display.Layer)2 Patch (ini.trakem2.display.Patch)2 YesNoDialog (ini.trakem2.display.YesNoDialog)2 BufferedReader (java.io.BufferedReader)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 FileWriter (java.io.FileWriter)2 ArrayList (java.util.ArrayList)2