Search in sources :

Example 56 with TextField

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

the class PsfCreator method showAlignmentDialog.

private boolean showAlignmentDialog() {
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addHelp(HelpUrls.getUrl("psf-creator"));
    gd.addMessage("Use XYZ stack alignment to create a combined PSF");
    final CalibrationWriter cw = CalibrationWriter.create(settings.getCalibration());
    // These are ignored for reset
    gd.addChoice("Alignment_mode", ALIGNMENT_MODE, settings.getAlignmentMode());
    gd.addSlider("Z_radius (px)", 0, imp.getStackSize(), settings.getAlignmentZRadius());
    gd.addChoice("PSF_type", PSF_TYPE, settings.getPsfType());
    gd.addNumericField("nm_per_pixel", cw.getNmPerPixel(), 2, 6, "nm");
    gd.addNumericField("nm_per_slice", settings.getNmPerSlice(), 0, 6, "nm");
    PeakFit.addCameraOptions(gd, PeakFit.FLAG_NO_GAIN | PeakFit.FLAG_NO_READ_NOISE, cw);
    // For reset
    final LocalList<TextField> tf = new LocalList<>();
    final LocalList<Checkbox> cb = new LocalList<>();
    tf.add(gd.addAndGetSlider("Analysis_window", 0, 8, settings.getAnalysisWindow()));
    tf.add(gd.addAndGetSlider("Smoothing", 0.1, 0.5, settings.getSmoothing()));
    tf.add(gd.addAndGetSlider("CoM_z_window", 0, 8, settings.getComWindow()));
    tf.add(gd.addAndGetSlider("CoM_border", 0, 0.5, settings.getComBorder()));
    tf.add(gd.addAndGetSlider("Alignment_magnification", 1, 8, settings.getAlignmentMagnification()));
    cb.add(gd.addAndGetCheckbox("Smooth_stack_signal", settings.getSmoothStackSignal()));
    tf.add(gd.addAndGetSlider("Max_iterations", 1, 20, settings.getMaxIterations()));
    if (settings.getInteractiveMode()) {
        cb.add(gd.addAndGetCheckbox("Check_alignments", settings.getCheckAlignments()));
    }
    tf.add(gd.addAndGetNumericField("Sub-pixel_precision", settings.getSubPixelPrecision(), -2));
    if (!settings.getInteractiveMode()) {
        tf.add(gd.addAndGetNumericField("RMSD_XY_threshold", settings.getRmsdXyThreshold(), -2));
        tf.add(gd.addAndGetNumericField("RMSD_Z_threshold", settings.getRmsdZThreshold(), -2));
        tf.add(gd.addAndGetNumericField("CoM_shift_threshold", settings.getComShiftThreshold(), -2));
    }
    if (ImageJUtils.isShowGenericDialog()) {
        gd.addAndGetButton("Reset", event -> {
            final boolean interactive = PsfCreator.this.settings.getInteractiveMode();
            final PSFCreatorSettings defaults = GuiProtosHelper.defaultPSFCreatorSettings;
            int ti = 0;
            int cbi = 0;
            tf.get(ti++).setText(Double.toString(defaults.getAnalysisWindow()));
            tf.get(ti++).setText(Double.toString(defaults.getSmoothing()));
            tf.get(ti++).setText(Integer.toString(defaults.getComWindow()));
            tf.get(ti++).setText(Double.toString(defaults.getComBorder()));
            tf.get(ti++).setText(Integer.toString(defaults.getAlignmentMagnification()));
            cb.get(cbi++).setState(defaults.getSmoothStackSignal());
            tf.get(ti++).setText(Integer.toString(defaults.getMaxIterations()));
            if (interactive) {
                cb.get(cbi++).setState(defaults.getCheckAlignments());
            }
            tf.get(ti++).setText(Double.toString(defaults.getSubPixelPrecision()));
            if (!interactive) {
                tf.get(ti++).setText(Double.toString(defaults.getRmsdXyThreshold()));
                tf.get(ti++).setText(Double.toString(defaults.getRmsdZThreshold()));
                tf.get(ti++).setText(Double.toString(defaults.getComShiftThreshold()));
            }
            // Reset later options too
            PsfCreator.this.settings.setPsfMagnification(defaults.getPsfMagnification());
            PsfCreator.this.settings.setWindow(defaults.getWindow());
            PsfCreator.this.settings.setSmoothStackSignal(defaults.getSmoothStackSignal());
            PsfCreator.this.settings.setComBorder(defaults.getComBorder());
            PsfCreator.this.settings.setCropBorder(0);
            PsfCreator.this.settings.setCropStart(0);
            PsfCreator.this.settings.setCropEnd(0);
        });
    }
    gd.showDialog();
    if (gd.wasCanceled()) {
        return false;
    }
    settings.setAlignmentMode(gd.getNextChoiceIndex());
    settings.setAlignmentZRadius((int) gd.getNextNumber());
    settings.setPsfType(gd.getNextChoiceIndex());
    cw.setNmPerPixel(gd.getNextNumber());
    settings.setNmPerSlice(gd.getNextNumber());
    cw.setCameraType(SettingsManager.getCameraTypeValues()[gd.getNextChoiceIndex()]);
    settings.setAnalysisWindow((int) gd.getNextNumber());
    settings.setSmoothing(gd.getNextNumber());
    settings.setComWindow((int) gd.getNextNumber());
    settings.setComBorder(gd.getNextNumber());
    settings.setAlignmentMagnification((int) gd.getNextNumber());
    settings.setSmoothStackSignal(gd.getNextBoolean());
    settings.setMaxIterations((int) gd.getNextNumber());
    if (settings.getInteractiveMode()) {
        checkAlignments = gd.getNextBoolean();
        settings.setCheckAlignments(checkAlignments);
    }
    settings.setSubPixelPrecision(gd.getNextNumber());
    if (!settings.getInteractiveMode()) {
        settings.setRmsdXyThreshold(gd.getNextNumber());
        settings.setRmsdZThreshold(gd.getNextNumber());
        settings.setComShiftThreshold(gd.getNextNumber());
    }
    gd.collectOptions();
    nmPerPixel = cw.getNmPerPixel();
    settings.setCalibration(cw.getBuilder());
    SettingsManager.writeSettings(settings);
    // Check arguments
    try {
        ParameterUtils.isPositive("nm/pixel", nmPerPixel);
        ParameterUtils.isPositive("nm/slice", settings.getNmPerSlice());
        // Since we do a local background estimation for each extracted PSF then we
        // do not need the bias for non sCMOS cameras.
        // if (!cw.isSCMOS())
        // Parameters.isAboveZero("Bias", cw.getBias());
        ParameterUtils.isEqualOrAbove("Projection magnification", settings.getAlignmentMagnification(), 1);
        ParameterUtils.isEqualOrAbove("Max iterations", settings.getMaxIterations(), 1);
        ParameterUtils.isEqualOrAbove("PSF magnification", settings.getPsfMagnification(), 1);
        ParameterUtils.isAbove("Smoothing", settings.getSmoothing(), 0);
        ParameterUtils.isBelow("Smoothing", settings.getSmoothing(), 1);
    } catch (final IllegalArgumentException ex) {
        IJ.error(TITLE, ex.getMessage());
        return false;
    }
    return true;
}
Also used : LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) PSFCreatorSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.PSFCreatorSettings) Checkbox(java.awt.Checkbox) CalibrationWriter(uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter) TextField(java.awt.TextField) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) Point(java.awt.Point) BasePoint(uk.ac.sussex.gdsc.core.match.BasePoint)

Aggregations

TextField (java.awt.TextField)56 Checkbox (java.awt.Checkbox)21 Choice (java.awt.Choice)21 Label (java.awt.Label)18 Panel (java.awt.Panel)17 Button (java.awt.Button)13 GenericDialog (ij.gui.GenericDialog)11 GridBagConstraints (java.awt.GridBagConstraints)11 GridBagLayout (java.awt.GridBagLayout)11 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)10 Color (java.awt.Color)9 Component (java.awt.Component)8 Vector (java.util.Vector)8 BorderLayout (java.awt.BorderLayout)6 FlowLayout (java.awt.FlowLayout)6 Dimension (java.awt.Dimension)5 Frame (java.awt.Frame)5 Insets (java.awt.Insets)5 Point (java.awt.Point)5 JPanel (javax.swing.JPanel)5