Search in sources :

Example 46 with Checkbox

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

the class Configuration method showDialog.

/**
 * Show the current properties.
 *
 * @param fitEngineConfiguration the fit engine configuration
 * @param save the save
 * @return true, if successful
 */
public boolean showDialog(FitEngineConfiguration fitEngineConfiguration, boolean save) {
    this.config = fitEngineConfiguration;
    fitConfig = config.getFitConfiguration();
    pluginSettings = Settings.load();
    pluginSettings.save();
    final CalibrationReader calibrationReader = fitConfig.getCalibrationReader();
    ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addHelp(HelpUrls.getUrl("fit-configuration"));
    gd.addMessage("Configuration settings for the single-molecule localisation microscopy plugins");
    final String[] templates = ConfigurationTemplate.getTemplateNames(true);
    gd.addChoice("Template", templates, templates[0]);
    PeakFit.addCameraOptions(gd, fitConfig);
    gd.addNumericField("Calibration (nm/px)", calibrationReader.getNmPerPixel(), 2);
    gd.addNumericField("Exposure_time (ms)", calibrationReader.getExposureTime(), 2);
    gd.addMessage("--- Gaussian parameters ---");
    PeakFit.addPsfOptions(gd, fitConfig);
    gd.addMessage("--- Maxima identification ---");
    final FitEngineConfigurationProvider provider = this::getFitEngineConfiguration;
    PeakFit.addDataFilterOptions(gd, provider);
    PeakFit.addSearchOptions(gd, provider);
    PeakFit.addBorderOptions(gd, provider);
    PeakFit.addFittingOptions(gd, provider);
    gd.addMessage("--- Gaussian fitting ---");
    gd.addChoice("Fit_solver", SettingsManager.getFitSolverNames(), FitProtosHelper.getName(fitConfig.getFitSolver()));
    // Parameters specific to each Fit solver are collected in a second dialog
    gd.addNumericField("Fail_limit", config.getFailuresLimit(), 0);
    gd.addNumericField("Pass_rate", config.getPassRate(), 2);
    gd.addCheckbox("Include_neighbours", config.isIncludeNeighbours());
    gd.addSlider("Neighbour_height", 0.01, 1, config.getNeighbourHeightThreshold());
    gd.addSlider("Residuals_threshold", 0.01, 1, config.getResidualsThreshold());
    PeakFit.addDuplicateDistanceOptions(gd, provider);
    gd.addMessage("--- Peak filtering ---\nDiscard fits that shift; are too low; or expand/contract");
    gd.addCheckbox("Smart_filter", fitConfig.isSmartFilter());
    gd.addCheckbox("Disable_simple_filter", fitConfig.isDisableSimpleFilter());
    gd.addSlider("Shift_factor", 0.01, 2, fitConfig.getCoordinateShiftFactor());
    gd.addNumericField("Signal_strength", fitConfig.getSignalStrength(), 2);
    gd.addNumericField("Min_photons", fitConfig.getMinPhotons(), 0);
    gd.addSlider("Min_width_factor", 0, 0.99, fitConfig.getMinWidthFactor());
    gd.addSlider("Width_factor", 1, 4.5, fitConfig.getMaxWidthFactor());
    PeakFit.addPrecisionOptions(gd, this::getFitConfiguration);
    // Add a mouse listener to the config file field
    if (ImageJUtils.isShowGenericDialog()) {
        final Vector<TextField> numerics = gd.getNumericFields();
        final Vector<Checkbox> checkboxes = gd.getCheckboxes();
        final Vector<Choice> choices = gd.getChoices();
        final Iterator<TextField> nu = numerics.iterator();
        final Iterator<Checkbox> cb = checkboxes.iterator();
        final Iterator<Choice> ch = choices.iterator();
        final Choice textTemplate = ch.next();
        textTemplate.addItemListener(this::itemStateChanged);
        textCameraType = ch.next();
        textNmPerPixel = nu.next();
        textExposure = nu.next();
        textPsf = ch.next();
        textDataFilterType = ch.next();
        textDataFilterMethod = ch.next();
        textSmooth = nu.next();
        textSearch = nu.next();
        textBorder = nu.next();
        textFitting = nu.next();
        textFitSolver = ch.next();
        textFailuresLimit = nu.next();
        textPassRate = nu.next();
        textIncludeNeighbours = cb.next();
        textNeighbourHeightThreshold = nu.next();
        textResidualsThreshold = nu.next();
        textDuplicateDistance = nu.next();
        textSmartFilter = cb.next();
        textDisableSimpleFilter = cb.next();
        textCoordinateShiftFactor = nu.next();
        textSignalStrength = nu.next();
        textMinPhotons = nu.next();
        textMinWidthFactor = nu.next();
        textWidthFactor = nu.next();
        textPrecisionThreshold = nu.next();
        updateFilterInput();
        textSmartFilter.addItemListener(this::itemStateChanged);
        textDisableSimpleFilter.addItemListener(this::itemStateChanged);
    }
    if (save) {
        gd.enableYesNoCancel("Save", "Save template");
    }
    gd.showDialog();
    if (gd.wasCanceled()) {
        return false;
    }
    // In case a template updated the calibration
    final CalibrationWriter calibrationWriter = fitConfig.getCalibrationWriter();
    // Ignore the template
    gd.getNextChoice();
    calibrationWriter.setCameraType(SettingsManager.getCameraTypeValues()[gd.getNextChoiceIndex()]);
    calibrationWriter.setNmPerPixel(gd.getNextNumber());
    calibrationWriter.setExposureTime(gd.getNextNumber());
    fitConfig.setCalibration(calibrationWriter.getCalibration());
    fitConfig.setPsfType(PeakFit.getPsfTypeValues()[gd.getNextChoiceIndex()]);
    config.setDataFilterType(gd.getNextChoiceIndex());
    config.setDataFilter(gd.getNextChoiceIndex(), Math.abs(gd.getNextNumber()), false, 0);
    config.setSearch(gd.getNextNumber());
    config.setBorder(gd.getNextNumber());
    config.setFitting(gd.getNextNumber());
    // Some enum values are not supported
    fitConfig.setFitSolver(SettingsManager.getFitSolverValues()[gd.getNextChoiceIndex()]);
    config.setFailuresLimit((int) gd.getNextNumber());
    config.setPassRate(gd.getNextNumber());
    config.setIncludeNeighbours(gd.getNextBoolean());
    config.setNeighbourHeightThreshold(gd.getNextNumber());
    config.setResidualsThreshold(gd.getNextNumber());
    config.setDuplicateDistance(gd.getNextNumber());
    fitConfig.setSmartFilter(gd.getNextBoolean());
    fitConfig.setDisableSimpleFilter(gd.getNextBoolean());
    fitConfig.setCoordinateShiftFactor(gd.getNextNumber());
    fitConfig.setSignalStrength(gd.getNextNumber());
    fitConfig.setMinPhotons(gd.getNextNumber());
    fitConfig.setMinWidthFactor(gd.getNextNumber());
    fitConfig.setMaxWidthFactor(gd.getNextNumber());
    fitConfig.setPrecisionThreshold(gd.getNextNumber());
    gd.collectOptions();
    // Check arguments
    try {
        ParameterUtils.isAboveZero("nm per pixel", calibrationWriter.getNmPerPixel());
        ParameterUtils.isAboveZero("Exposure time", calibrationWriter.getExposureTime());
        if (fitConfig.getPsfTypeValue() != PSFType.ASTIGMATIC_GAUSSIAN_2D_VALUE) {
            ParameterUtils.isAboveZero("Initial SD0", fitConfig.getInitialXSd());
            if (fitConfig.getPsf().getParametersCount() > 1) {
                ParameterUtils.isAboveZero("Initial SD1", fitConfig.getInitialYSd());
            }
        }
        ParameterUtils.isAboveZero("Search_width", config.getSearch());
        ParameterUtils.isAboveZero("Fitting_width", config.getFitting());
        ParameterUtils.isPositive("Neighbour height threshold", config.getNeighbourHeightThreshold());
        ParameterUtils.isPositive("Residuals threshold", config.getResidualsThreshold());
        ParameterUtils.isPositive("Duplicate distance", config.getDuplicateDistance());
        if (!fitConfig.isSmartFilter()) {
            ParameterUtils.isPositive("Coordinate Shift factor", fitConfig.getCoordinateShiftFactor());
            ParameterUtils.isPositive("Signal strength", fitConfig.getSignalStrength());
            ParameterUtils.isPositive("Min photons", fitConfig.getMinPhotons());
            ParameterUtils.isPositive("Min width factor", fitConfig.getMinWidthFactor());
            ParameterUtils.isPositive("Width factor", fitConfig.getMaxWidthFactor());
            ParameterUtils.isPositive("Precision threshold", fitConfig.getPrecisionThreshold());
        }
    } catch (final IllegalArgumentException ex) {
        IJ.error(TITLE, ex.getMessage());
        return false;
    }
    if (gd.invalidNumber()) {
        return false;
    }
    final int flags = PeakFit.FLAG_NO_SAVE;
    if (!PeakFit.configurePsfModel(config, flags)) {
        return false;
    }
    if (!PeakFit.configureResultsFilter(config, flags)) {
        return false;
    }
    if (!PeakFit.configureDataFilter(config, flags)) {
        return false;
    }
    PeakFit.configureFitSolver(config, null, null, flags);
    if (save) {
        final boolean saveToFile = !gd.wasOKed();
        if (saveToFile) {
            gd = new ExtendedGenericDialog(TITLE);
            gd.addFilenameField("Template_filename", pluginSettings.templateFilename);
            gd.addMessage("Add notes to the template ...");
            gd.addTextAreas(pluginSettings.notes, null, 10, 60);
            gd.showDialog();
            if (gd.wasCanceled()) {
                return false;
            }
            pluginSettings.save();
            final String filename = gd.getNextString();
            pluginSettings.notes = gd.getNextText();
            if (filename != null) {
                pluginSettings.templateFilename = FileUtils.replaceExtension(filename, ".txt");
                final File file = new File(pluginSettings.templateFilename);
                final String name = FileUtils.removeExtension(file.getName());
                final TemplateSettings.Builder settings = TemplateSettings.newBuilder();
                settings.addNotes(pluginSettings.notes);
                settings.setCalibration(fitConfig.getCalibration());
                settings.setFitEngineSettings(config.getFitEngineSettings());
                // Note: No results settings are currently supported
                settings.setPsf(fitConfig.getPsf());
                if (!ConfigurationTemplate.saveTemplate(name, settings.build(), file)) {
                    IJ.error(TITLE, "Failed to save to file: " + pluginSettings.templateFilename);
                }
            }
        } else {
            SettingsManager.writeSettings(config, 0);
        }
    }
    return true;
}
Also used : FitEngineConfigurationProvider(uk.ac.sussex.gdsc.smlm.ij.plugins.PeakFit.FitEngineConfigurationProvider) Choice(java.awt.Choice) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) CalibrationReader(uk.ac.sussex.gdsc.smlm.data.config.CalibrationReader) TemplateSettings(uk.ac.sussex.gdsc.smlm.data.config.TemplateProtos.TemplateSettings) Checkbox(java.awt.Checkbox) TextField(java.awt.TextField) CalibrationWriter(uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter) File(java.io.File)

Example 47 with Checkbox

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

the class CreateFilters method itemStateChanged.

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

Example 48 with Checkbox

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

the class CreateFilters method showDialog.

private boolean showDialog() {
    final GenericDialog gd = new GenericDialog(TITLE);
    gd.addHelp(HelpUrls.getUrl("create-filters"));
    gd.addMessage("Create a set of filters for use in the Filter Analysis plugin.\n" + "Attributes will be enumerated if they are of the form 'min:max:increment'");
    filterSettings = SettingsManager.readGuiFilterSettings(0).toBuilder();
    enumerateEarly = enumerateEarlySetting.get();
    gd.addTextAreas(filterSettings.getFilterTemplate(), null, 20, 80);
    gd.addCheckbox("Enumerate_early attributes first", enumerateEarly);
    gd.addCheckbox("Show_demo_filters", false);
    if (ImageJUtils.isShowGenericDialog()) {
        final Checkbox cb = (Checkbox) gd.getCheckboxes().get(1);
        cb.addItemListener(this);
    }
    gd.showDialog();
    if (gd.wasCanceled()) {
        return false;
    }
    filterSettings.setFilterTemplate(gd.getNextText());
    enumerateEarly = gd.getNextBoolean();
    final boolean demoFilters = gd.getNextBoolean();
    if (demoFilters) {
        logDemoFilters();
        return false;
    }
    enumerateEarlySetting.set(enumerateEarly);
    return SettingsManager.writeSettings(filterSettings.build());
}
Also used : Checkbox(java.awt.Checkbox) GenericDialog(ij.gui.GenericDialog)

Example 49 with Checkbox

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

the class CreateData method showDialog.

/**
 * Show a dialog allowing the parameters for a simulation to be performed.
 *
 * @return True if the parameters were collected
 */
private boolean showDialog() {
    // In track mode we do not need a time, illumination model or blinking model.
    // Fixed length tracks will be drawn, non-overlapping in time. This is the simplest
    // simulation for moving molecules
    helpKey = trackMode ? "create-track-data" : "create-data";
    settings = SettingsManager.readCreateDataSettings(0).toBuilder();
    if (settings.getStepsPerSecond() < 1) {
        settings.setStepsPerSecond(1);
    }
    final String[] backgroundImages = createBackgroundImageList();
    ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addNumericField("Pixel_pitch (nm)", settings.getPixelPitch(), 2);
    gd.addNumericField("Size (px)", settings.getSize(), 0);
    gd.addNumericField("Depth (nm)", settings.getDepth(), 0);
    gd.addCheckbox("Fixed_depth", settings.getFixedDepth());
    if (!trackMode) {
        gd.addNumericField("Seconds", settings.getSeconds(), 1);
    }
    gd.addNumericField("Exposure_time (ms)", settings.getExposureTime(), 1);
    gd.addSlider("Steps_per_second", 1, MathUtils.clip(15, 1000, settings.getStepsPerSecond()), settings.getStepsPerSecond());
    if (!trackMode) {
        gd.addChoice("Illumination", ILLUMINATION, settings.getIllumination());
        gd.addNumericField("Pulse_interval", settings.getPulseInterval(), 0);
        gd.addNumericField("Pulse_ratio", settings.getPulseRatio(), 2);
    }
    if (backgroundImages != null) {
        gd.addChoice("Background_image", backgroundImages, settings.getBackgroundImage());
    }
    if (extraOptions) {
        gd.addCheckbox("No_poisson_noise", !settings.getPoissonNoise());
    }
    gd.addNumericField("Background (photons)", settings.getBackground(), 2);
    addCameraOptions(gd);
    addPsfOptions(gd);
    gd.addMessage("--- Fluorophores ---");
    gd.addChoice("Distribution", DISTRIBUTION, settings.getDistribution());
    gd.addNumericField("Particles", settings.getParticles(), 0);
    gd.addCheckbox("Compound_molecules", settings.getCompoundMolecules());
    gd.addNumericField("Diffusion_rate (um^2/sec)", settings.getDiffusionRate(), 2);
    final String[] diffusionTypes = SettingsManager.getNames((Object[]) DiffusionType.values());
    gd.addChoice("Diffusion_type", diffusionTypes, diffusionTypes[CreateDataSettingsHelper.getDiffusionType(settings.getDiffusionType()).ordinal()]);
    gd.addSlider("Fixed_fraction (%)", 0, 100, settings.getFixedFraction() * 100);
    gd.addChoice("Confinement", CONFINEMENT, settings.getConfinement());
    gd.addNumericField("Photons (sec^-1)", settings.getPhotonsPerSecond(), 0);
    // We cannot use the correlation mode with fixed life time tracks
    final String[] dist = (trackMode) ? Arrays.copyOf(PHOTON_DISTRIBUTION, PHOTON_DISTRIBUTION.length - 1) : PHOTON_DISTRIBUTION;
    gd.addChoice("Photon_distribution", dist, settings.getPhotonDistribution());
    gd.addNumericField("On_time (ms)", settings.getTOn(), 2);
    if (!trackMode) {
        gd.addNumericField("Off_time_short (ms)", settings.getTOffShort(), 2);
        gd.addNumericField("Off_time_long (ms)", settings.getTOffLong(), 2);
        gd.addNumericField("n_Blinks_Short", settings.getNBlinksShort(), 2);
        gd.addNumericField("n_Blinks_Long", settings.getNBlinksLong(), 2);
        gd.addCheckbox("Use_geometric_distribution", settings.getNBlinksGeometricDistribution());
    }
    gd.addMessage("--- Peak filtering ---");
    gd.addSlider("Min_Photons", 0, 50, settings.getMinPhotons());
    gd.addSlider("Min_SNR_t1", 0, 20, settings.getMinSnrT1());
    gd.addSlider("Min_SNR_tN", 0, 10, settings.getMinSnrTN());
    gd.addMessage("--- Save options ---");
    gd.addCheckbox("Raw_image", settings.getRawImage());
    gd.addCheckbox("Save_image", settings.getSaveImage());
    gd.addCheckbox("Save_image_results", settings.getSaveImageResults());
    gd.addCheckbox("Save_fluorophores", settings.getSaveFluorophores());
    gd.addCheckbox("Save_localisations", settings.getSaveLocalisations());
    gd.addMessage("--- Report options ---");
    gd.addCheckbox("Show_histograms", settings.getShowHistograms());
    gd.addCheckbox("Choose_histograms", settings.getChooseHistograms());
    gd.addNumericField("Histogram_bins", settings.getHistogramBins(), 0);
    gd.addCheckbox("Remove_outliers", settings.getRemoveOutliers());
    gd.addSlider("Density_radius (N x HWHM)", 0, 4.5, settings.getDensityRadius());
    gd.addNumericField("Depth-of-field (nm)", settings.getDepthOfField(), 0);
    gd.addHelp(HelpUrls.getUrl(helpKey));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return false;
    }
    settings.setPixelPitch(Math.abs(gd.getNextNumber()));
    settings.setSize(Math.abs((int) gd.getNextNumber()));
    settings.setDepth(Math.abs(gd.getNextNumber()));
    settings.setFixedDepth(gd.getNextBoolean());
    if (!trackMode) {
        settings.setSeconds(Math.abs(gd.getNextNumber()));
    }
    settings.setExposureTime(Math.abs(gd.getNextNumber()));
    settings.setStepsPerSecond(Math.abs(gd.getNextNumber()));
    if (!trackMode) {
        settings.setIllumination(gd.getNextChoice());
        settings.setPulseInterval(Math.abs((int) gd.getNextNumber()));
        settings.setPulseRatio(Math.abs(gd.getNextNumber()));
    }
    if (backgroundImages != null) {
        settings.setBackgroundImage(gd.getNextChoice());
    }
    if (extraOptions) {
        settings.setPoissonNoise(!gd.getNextBoolean());
        poissonNoise = settings.getPoissonNoise();
    }
    settings.setBackground(Math.abs(gd.getNextNumber()));
    settings.setCameraType(SettingsManager.getCameraTypeValues()[gd.getNextChoiceIndex()]);
    settings.setPsfModel(gd.getNextChoice());
    settings.setDistribution(gd.getNextChoice());
    settings.setParticles(Math.abs((int) gd.getNextNumber()));
    settings.setCompoundMolecules(gd.getNextBoolean());
    settings.setDiffusionRate(Math.abs(gd.getNextNumber()));
    settings.setDiffusionType(gd.getNextChoiceIndex());
    settings.setFixedFraction(Math.abs(gd.getNextNumber() / 100.0));
    settings.setConfinement(gd.getNextChoice());
    settings.setPhotonsPerSecond(Math.abs((int) gd.getNextNumber()));
    settings.setPhotonDistribution(gd.getNextChoice());
    settings.setTOn(Math.abs(gd.getNextNumber()));
    if (!trackMode) {
        settings.setTOffShort(Math.abs(gd.getNextNumber()));
        settings.setTOffLong(Math.abs(gd.getNextNumber()));
        settings.setNBlinksShort(Math.abs(gd.getNextNumber()));
        settings.setNBlinksLong(Math.abs(gd.getNextNumber()));
        settings.setNBlinksGeometricDistribution(gd.getNextBoolean());
    }
    settings.setMinPhotons(gd.getNextNumber());
    settings.setMinSnrT1(gd.getNextNumber());
    settings.setMinSnrTN(gd.getNextNumber());
    minPhotons = settings.getMinPhotons();
    minSnrT1 = settings.getMinSnrT1();
    minSnrTn = settings.getMinSnrTN();
    settings.setRawImage(gd.getNextBoolean());
    settings.setSaveImage(gd.getNextBoolean());
    settings.setSaveImageResults(gd.getNextBoolean());
    settings.setSaveFluorophores(gd.getNextBoolean());
    settings.setSaveLocalisations(gd.getNextBoolean());
    settings.setShowHistograms(gd.getNextBoolean());
    settings.setChooseHistograms(gd.getNextBoolean());
    settings.setHistogramBins((int) gd.getNextNumber());
    settings.setRemoveOutliers(gd.getNextBoolean());
    settings.setDensityRadius((float) gd.getNextNumber());
    settings.setDepthOfField((float) Math.abs(gd.getNextNumber()));
    // Ensure tN threshold is more lenient
    if (settings.getMinSnrT1() < settings.getMinSnrTN()) {
        final double tmp = settings.getMinSnrT1();
        settings.setMinSnrT1(settings.getMinSnrTN());
        settings.setMinSnrTN(tmp);
    }
    gd.collectOptions();
    // Save before validation so that the current values are preserved.
    SettingsManager.writeSettings(settings.build());
    // Check arguments
    try {
        ParameterUtils.isAboveZero("Pixel Pitch", settings.getPixelPitch());
        ParameterUtils.isAboveZero("Size", settings.getSize());
        if (!settings.getFixedDepth()) {
            ParameterUtils.isPositive("Depth", settings.getDepth());
        }
        if (!trackMode) {
            ParameterUtils.isAboveZero("Seconds", settings.getSeconds());
        }
        ParameterUtils.isAboveZero("Exposure time", settings.getExposureTime());
        ParameterUtils.isAboveZero("Steps per second", settings.getStepsPerSecond());
        ParameterUtils.isPositive("Background", settings.getBackground());
        ParameterUtils.isAboveZero("Particles", settings.getParticles());
        ParameterUtils.isAboveZero("Photons", settings.getPhotonsPerSecond());
        ParameterUtils.isPositive("Diffusion rate", settings.getDiffusionRate());
        ParameterUtils.isPositive("Fixed fraction", settings.getFixedFraction());
        ParameterUtils.isPositive("Pulse interval", settings.getPulseInterval());
        ParameterUtils.isAboveZero("Pulse ratio", settings.getPulseRatio());
        ParameterUtils.isAboveZero("tOn", settings.getTOn());
        if (!trackMode) {
            ParameterUtils.isAboveZero("tOff Short", settings.getTOffShort());
            ParameterUtils.isAboveZero("tOff Long", settings.getTOffLong());
            ParameterUtils.isPositive("n-Blinks Short", settings.getNBlinksShort());
            ParameterUtils.isPositive("n-Blinks Long", settings.getNBlinksLong());
        }
        ParameterUtils.isPositive("Min photons", settings.getMinPhotons());
        ParameterUtils.isPositive("Min SNR t1", settings.getMinSnrT1());
        ParameterUtils.isPositive("Min SNR tN", settings.getMinSnrTN());
        ParameterUtils.isPositive("Histogram bins", settings.getHistogramBins());
        ParameterUtils.isPositive("Density radius", settings.getDensityRadius());
        validateCameraOptions();
        validatePsfOptions();
    } catch (final IllegalArgumentException ex) {
        IJ.error(TITLE, ex.getMessage());
        return false;
    }
    if (gd.invalidNumber()) {
        return false;
    }
    if (!getHistogramOptions()) {
        return false;
    }
    String[] maskImages = null;
    if (settings.getDistribution().equals(DISTRIBUTION[MASK])) {
        maskImages = createDistributionImageList();
        if (maskImages != null) {
            gd = new ExtendedGenericDialog(TITLE);
            gd.addMessage("Select the mask image for the distribution");
            gd.addChoice("Distribution_mask", maskImages, settings.getDistributionMask());
            if (maskListContainsStacks) {
                gd.addNumericField("Distribution_slice_depth (nm)", settings.getDistributionMaskSliceDepth(), 0);
            }
            gd.addHelp(HelpUrls.getUrl(helpKey));
            gd.showDialog();
            if (gd.wasCanceled()) {
                return false;
            }
            settings.setDistributionMask(gd.getNextChoice());
            if (maskListContainsStacks) {
                settings.setDistributionMaskSliceDepth(Math.abs(gd.getNextNumber()));
            }
        }
    } else if (settings.getDistribution().equals(DISTRIBUTION[GRID])) {
        gd = new ExtendedGenericDialog(TITLE);
        gd.addMessage("Select grid for the distribution");
        gd.addNumericField("Cell_size", settings.getCellSize(), 0);
        gd.addSlider("p-binary", 0, 1, settings.getProbabilityBinary());
        gd.addNumericField("Min_binary_distance (nm)", settings.getMinBinaryDistance(), 0);
        gd.addNumericField("Max_binary_distance (nm)", settings.getMaxBinaryDistance(), 0);
        gd.addHelp(HelpUrls.getUrl(helpKey));
        gd.showDialog();
        if (gd.wasCanceled()) {
            return false;
        }
        settings.setCellSize((int) gd.getNextNumber());
        settings.setProbabilityBinary(gd.getNextNumber());
        settings.setMinBinaryDistance(gd.getNextNumber());
        settings.setMaxBinaryDistance(gd.getNextNumber());
        // Check arguments
        try {
            ParameterUtils.isAboveZero("Cell size", settings.getCellSize());
            ParameterUtils.isPositive("p-binary", settings.getProbabilityBinary());
            ParameterUtils.isEqualOrBelow("p-binary", settings.getProbabilityBinary(), 1);
            ParameterUtils.isPositive("Min binary distance", settings.getMinBinaryDistance());
            ParameterUtils.isPositive("Max binary distance", settings.getMaxBinaryDistance());
            ParameterUtils.isEqualOrBelow("Min binary distance", settings.getMinBinaryDistance(), settings.getMaxBinaryDistance());
        } catch (final IllegalArgumentException ex) {
            IJ.error(TITLE, ex.getMessage());
            return false;
        }
    }
    SettingsManager.writeSettings(settings.build());
    if (settings.getDiffusionRate() > 0 && settings.getFixedFraction() < 1) {
        if (settings.getConfinement().equals(CONFINEMENT[CONFINEMENT_SPHERE])) {
            gd = new ExtendedGenericDialog(TITLE);
            gd.addMessage("Select the sphere radius for the diffusion confinement");
            gd.addSlider("Confinement_radius (nm)", 0, 2000, settings.getConfinementRadius());
            gd.addHelp(HelpUrls.getUrl(helpKey));
            gd.showDialog();
            if (gd.wasCanceled()) {
                return false;
            }
            settings.setConfinementRadius(gd.getNextNumber());
        } else if (settings.getConfinement().equals(CONFINEMENT[CONFINEMENT_MASK])) {
            if (maskImages == null) {
                maskImages = createDistributionImageList();
            }
            if (maskImages != null) {
                gd = new ExtendedGenericDialog(TITLE);
                gd.addMessage("Select the mask image for the diffusion confinement");
                gd.addChoice("Confinement_mask", maskImages, settings.getConfinementMask());
                if (maskListContainsStacks) {
                    gd.addNumericField("Confinement_slice_depth (nm)", settings.getConfinementMaskSliceDepth(), 0);
                }
                gd.addHelp(HelpUrls.getUrl(helpKey));
                gd.showDialog();
                if (gd.wasCanceled()) {
                    return false;
                }
                settings.setConfinementMask(gd.getNextChoice());
                if (maskListContainsStacks) {
                    settings.setConfinementMaskSliceDepth(Math.abs(gd.getNextNumber()));
                }
            }
        }
    }
    SettingsManager.writeSettings(settings.build());
    if (settings.getCompoundMolecules()) {
        // Show a second dialog where the molecule configuration is specified
        gd = new ExtendedGenericDialog(TITLE);
        gd.addMessage("Specify the compound molecules");
        gd.addTextAreas(settings.getCompoundText(), null, 20, 80);
        gd.addCheckbox("Enable_2D_diffusion", settings.getDiffuse2D());
        gd.addCheckbox("Rotate_initial_orientation", settings.getRotateInitialOrientation());
        gd.addCheckbox("Rotate_during_simulation", settings.getRotateDuringSimulation());
        gd.addCheckbox("Enable_2D_rotation", settings.getRotate2D());
        gd.addCheckbox("Show_example_compounds", false);
        if (ImageJUtils.isShowGenericDialog()) {
            @SuppressWarnings("rawtypes") final Vector v = gd.getCheckboxes();
            final Checkbox cb = (Checkbox) v.get(v.size() - 1);
            cb.addItemListener(this::itemStateChanged);
        }
        gd.addHelp(HelpUrls.getUrl(helpKey));
        gd.showDialog();
        if (gd.wasCanceled()) {
            return false;
        }
        settings.setCompoundText(gd.getNextText());
        settings.setDiffuse2D(gd.getNextBoolean());
        settings.setRotateInitialOrientation(gd.getNextBoolean());
        settings.setRotateDuringSimulation(gd.getNextBoolean());
        settings.setRotate2D(gd.getNextBoolean());
        if (gd.getNextBoolean()) {
            logExampleCompounds();
            return false;
        }
    }
    SettingsManager.writeSettings(settings.build());
    gd = new ExtendedGenericDialog(TITLE);
    gd.addMessage("Configure the photon distribution: " + settings.getPhotonDistribution());
    if (PHOTON_DISTRIBUTION[PHOTON_CUSTOM].equals(settings.getPhotonDistribution())) {
        // Nothing more to be done
        return true;
    } else if (PHOTON_DISTRIBUTION[PHOTON_UNIFORM].equals(settings.getPhotonDistribution())) {
        gd.addNumericField("Max_Photons (sec^-1)", settings.getPhotonsPerSecondMaximum(), 0);
    } else if (PHOTON_DISTRIBUTION[PHOTON_GAMMA].equals(settings.getPhotonDistribution())) {
        gd.addNumericField("Photon_shape", settings.getPhotonShape(), 2);
    } else if (PHOTON_DISTRIBUTION[PHOTON_CORRELATED].equals(settings.getPhotonDistribution())) {
        gd.addNumericField("Correlation (to total tOn)", settings.getCorrelation(), 2);
    } else {
        // Nothing more to be done
        return true;
    }
    gd.addHelp(HelpUrls.getUrl(helpKey));
    gd.showDialog();
    if (gd.wasCanceled()) {
        return false;
    }
    try {
        if (PHOTON_DISTRIBUTION[PHOTON_UNIFORM].equals(settings.getPhotonDistribution())) {
            settings.setPhotonsPerSecondMaximum(Math.abs((int) gd.getNextNumber()));
            if (settings.getPhotonsPerSecondMaximum() < settings.getPhotonsPerSecond()) {
                settings.setPhotonsPerSecondMaximum(settings.getPhotonsPerSecond());
            }
        } else if (PHOTON_DISTRIBUTION[PHOTON_GAMMA].equals(settings.getPhotonDistribution())) {
            settings.setPhotonShape(Math.abs(gd.getNextNumber()));
            ParameterUtils.isAbove("Photon shape", settings.getPhotonShape(), 0);
        } else if (PHOTON_DISTRIBUTION[PHOTON_CORRELATED].equals(settings.getPhotonDistribution())) {
            settings.setCorrelation(gd.getNextNumber());
            ParameterUtils.isEqualOrBelow("Correlation", settings.getCorrelation(), 1);
            ParameterUtils.isEqualOrAbove("Correlation", settings.getCorrelation(), -1);
        }
    } catch (final IllegalArgumentException ex) {
        IJ.error(TITLE, ex.getMessage());
        return false;
    }
    SettingsManager.writeSettings(settings.build());
    return true;
}
Also used : Checkbox(java.awt.Checkbox) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) Vector(java.util.Vector)

Example 50 with Checkbox

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

the class CreateData method itemStateChanged.

private void itemStateChanged(ItemEvent event) {
    // When the checkbox is clicked, output example compounds to the ImageJ log
    final Checkbox cb = (Checkbox) event.getSource();
    if (cb.getState()) {
        cb.setState(false);
        logExampleCompounds();
    }
}
Also used : Checkbox(java.awt.Checkbox)

Aggregations

Checkbox (java.awt.Checkbox)54 TextField (java.awt.TextField)21 Choice (java.awt.Choice)18 GenericDialog (ij.gui.GenericDialog)13 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)11 Vector (java.util.Vector)9 Component (java.awt.Component)8 Label (java.awt.Label)8 GlobalSettings (gdsc.smlm.ij.settings.GlobalSettings)7 Panel (java.awt.Panel)7 GridBagLayout (java.awt.GridBagLayout)5 SOCGameOption (soc.game.SOCGameOption)5 BasePoint (gdsc.core.match.BasePoint)4 PeakResultPoint (gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint)4 Color (java.awt.Color)4 GridBagConstraints (java.awt.GridBagConstraints)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 CalibrationWriter (uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter)4 FitConfiguration (uk.ac.sussex.gdsc.smlm.engine.FitConfiguration)4