Search in sources :

Example 16 with Checkbox

use of java.awt.Checkbox 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;
}
Also used : Checkbox(java.awt.Checkbox) GenericDialog(ij.gui.GenericDialog)

Example 17 with Checkbox

use of java.awt.Checkbox 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 Checkbox

use of java.awt.Checkbox 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;
}
Also used : ItemEvent(java.awt.event.ItemEvent) TextArea(java.awt.TextArea) IOException(java.io.IOException) Checkbox(java.awt.Checkbox) GenericDialog(ij.gui.GenericDialog) NonBlockingGenericDialog(ij.gui.NonBlockingGenericDialog) TextField(java.awt.TextField) ItemListener(java.awt.event.ItemListener)

Example 19 with Checkbox

use of java.awt.Checkbox in project GDSC-SMLM by aherbert.

the class FreeFilterResults method showDialog.

private boolean showDialog() {
    ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addHelp(About.HELP_URL);
    gd.addMessage("Select a dataset to filter");
    ResultsManager.addInput(gd, inputOption, InputSource.MEMORY);
    GlobalSettings gs = SettingsManager.loadSettings();
    filterSettings = gs.getFilterSettings();
    String text;
    try {
        text = XmlUtils.prettyPrintXml(filterSettings.freeFilter);
    } catch (Exception e) {
        text = filterSettings.freeFilter;
    }
    gd.addTextAreas(text, null, 20, 80);
    gd.addCheckbox("Show_demo_filters", false);
    if (Utils.isShowGenericDialog()) {
        Checkbox cb = (Checkbox) gd.getCheckboxes().get(0);
        cb.addItemListener(this);
    }
    gd.showDialog();
    if (gd.wasCanceled())
        return false;
    inputOption = ResultsManager.getInputSource(gd);
    filterSettings.freeFilter = gd.getNextText();
    boolean demoFilters = gd.getNextBoolean();
    if (demoFilters) {
        logDemoFilters(TITLE);
        return false;
    }
    return SettingsManager.saveSettings(gs);
}
Also used : Checkbox(java.awt.Checkbox) GlobalSettings(gdsc.smlm.ij.settings.GlobalSettings) ExtendedGenericDialog(ij.gui.ExtendedGenericDialog)

Example 20 with Checkbox

use of java.awt.Checkbox in project GDSC-SMLM by aherbert.

the class FreeFilterResults method itemStateChanged.

public void itemStateChanged(ItemEvent e) {
    // When the checkbox is clicked, output the list of available filters to the ImageJ log
    Checkbox cb = (Checkbox) e.getSource();
    if (cb.getState()) {
        cb.setState(false);
        logDemoFilters(TITLE);
    }
}
Also used : Checkbox(java.awt.Checkbox)

Aggregations

Checkbox (java.awt.Checkbox)24 GenericDialog (ij.gui.GenericDialog)9 TextField (java.awt.TextField)9 Choice (java.awt.Choice)8 GlobalSettings (gdsc.smlm.ij.settings.GlobalSettings)7 Vector (java.util.Vector)7 Component (java.awt.Component)5 GridBagLayout (java.awt.GridBagLayout)5 BasePoint (gdsc.core.match.BasePoint)4 FitEngineConfiguration (gdsc.smlm.engine.FitEngineConfiguration)4 FitConfiguration (gdsc.smlm.fitting.FitConfiguration)4 PeakResultPoint (gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint)4 GridBagConstraints (java.awt.GridBagConstraints)4 ExtendedGenericDialog (ij.gui.ExtendedGenericDialog)3 Color (java.awt.Color)3 Panel (java.awt.Panel)3 DirectFilter (gdsc.smlm.results.filter.DirectFilter)2 MultiPathFilter (gdsc.smlm.results.filter.MultiPathFilter)2 BorderLayout (java.awt.BorderLayout)2 Button (java.awt.Button)2