List of usage examples for java.awt GridBagLayout getConstraints
public GridBagConstraints getConstraints(Component comp)
From source file:gdsc.smlm.ij.plugins.PSFEstimator.java
/** * @param imp/*from w w w . ja v a 2 s .c o m*/ * @return */ private int showDialog(ImagePlus imp) { // Keep class variables for the parameters we are fitting FitConfiguration fitConfig = config.getFitConfiguration(); initialPeakStdDev0 = fitConfig.getInitialPeakStdDev0(); initialPeakStdDev1 = fitConfig.getInitialPeakStdDev1(); initialPeakAngle = fitConfig.getInitialAngle(); if (!extraOptions) { interlacedData = false; integrateFrames = 1; } this.imp = imp; GenericDialog gd = new GenericDialog(TITLE); gd.addHelp(About.HELP_URL); gd.addMessage("Estimate 2D Gaussian to fit maxima"); gd.addNumericField("Initial_StdDev0", initialPeakStdDev0, 3); gd.addNumericField("Initial_StdDev1", initialPeakStdDev1, 3); gd.addNumericField("Initial_Angle", initialPeakAngle, 3); gd.addNumericField("Number_of_peaks", settings.numberOfPeaks, 0); // pValue sets the smallest significance level probability level at which they are said to be different. // i.e. p <= pValue they are different // lower pValue means harder to be found different. // lower pValue means easier to be found the same. gd.addNumericField("p-Value", settings.pValue, 4); gd.addCheckbox("Update_preferences", settings.updatePreferences); gd.addCheckbox("Log_progress", settings.debugPSFEstimator); gd.addCheckbox("Iterate", settings.iterate); gd.addCheckbox("Show_histograms", settings.showHistograms); gd.addNumericField("Histogram_bins", settings.histogramBins, 0); String[] filterTypes = SettingsManager.getNames((Object[]) DataFilterType.values()); gd.addChoice("Spot_filter_type", filterTypes, filterTypes[config.getDataFilterType().ordinal()]); String[] filterNames = SettingsManager.getNames((Object[]) DataFilter.values()); gd.addChoice("Spot_filter", filterNames, filterNames[config.getDataFilter(0).ordinal()]); gd.addSlider("Smoothing", 0, 2.5, config.getSmooth(0)); gd.addSlider("Search_width", 0.5, 2.5, config.getSearch()); gd.addSlider("Border", 0.5, 2.5, config.getBorder()); gd.addSlider("Fitting_width", 2, 4.5, config.getFitting()); if (extraOptions) { gd.addCheckbox("Interlaced_data", optionInterlacedData); gd.addSlider("Integrate_frames", 1, 5, optionIntegrateFrames); } gd.addMessage("--- Gaussian fitting ---"); Component splitLabel = gd.getMessage(); String[] solverNames = SettingsManager.getNames((Object[]) FitSolver.values()); gd.addChoice("Fit_solver", solverNames, solverNames[fitConfig.getFitSolver().ordinal()]); String[] functionNames = SettingsManager.getNames((Object[]) FitFunction.values()); gd.addChoice("Fit_function", functionNames, functionNames[fitConfig.getFitFunction().ordinal()]); // Parameters specific to each Fit solver are collected in a second dialog gd.addNumericField("Fail_limit", config.getFailuresLimit(), 0); gd.addCheckbox("Include_neighbours", config.isIncludeNeighbours()); gd.addSlider("Neighbour_height", 0.01, 1, config.getNeighbourHeightThreshold()); gd.addSlider("Residuals_threshold", 0.01, 1, config.getResidualsThreshold()); gd.addMessage("--- Peak filtering ---\nDiscard fits that shift; are too low; or expand/contract"); 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("Width_factor", 0.01, 5, fitConfig.getWidthFactor()); if (gd.getLayout() != null) { GridBagLayout grid = (GridBagLayout) gd.getLayout(); int xOffset = 0, yOffset = 0; int lastY = -1, rowCount = 0; for (Component comp : gd.getComponents()) { // Check if this should be the second major column if (comp == splitLabel) { xOffset += 2; yOffset -= rowCount; } // Reposition the field GridBagConstraints c = grid.getConstraints(comp); if (lastY != c.gridy) rowCount++; lastY = c.gridy; c.gridx = c.gridx + xOffset; c.gridy = c.gridy + yOffset; c.insets.left = c.insets.left + 10 * xOffset; c.insets.top = 0; c.insets.bottom = 0; grid.setConstraints(comp, c); } if (IJ.isLinux()) gd.setBackground(new Color(238, 238, 238)); } gd.showDialog(); if (gd.wasCanceled() || !readDialog(gd)) return DONE; return flags; }
From source file:gdsc.smlm.ij.plugins.PeakFit.java
@SuppressWarnings("unchecked") private int showDialog(ImagePlus imp) { // Executing as an ImageJ plugin. // Override the defaults with those in the configuration file String filename = SettingsManager.getSettingsFilename(); if (simpleFit) { return showSimpleDialog(filename); }//www . j ava 2 s . c o m GlobalSettings settings = SettingsManager.loadSettings(filename); calibration = settings.getCalibration(); config = settings.getFitEngineConfiguration(); fitConfig = config.getFitConfiguration(); resultsSettings = settings.getResultsSettings(); boolean isCrop = (bounds != null && imp != null && (bounds.width < imp.getWidth() || bounds.height < imp.getHeight())); if (!extraOptions) { integrateFrames = 1; resultsSettings.imageRollingWindow = 0; fitConfig.setBackgroundFitting(true); fitConfig.setMinIterations(0); fitConfig.setNoise(0); config.setNoiseMethod(Method.QUICK_RESIDUALS_LEAST_MEAN_OF_SQUARES); showProcessedFrames = false; } GenericDialog gd = new GenericDialog(TITLE); gd.addHelp(About.HELP_URL); gd.addMessage( (maximaIdentification) ? "Identify candidate maxima" : "Fit 2D Gaussian to identified maxima"); gd.addStringField("Config_file", filename, 40); gd.addNumericField("Calibration (nm/px)", calibration.nmPerPixel, 2); gd.addNumericField("Gain (ADU/photon)", calibration.gain, 2); gd.addCheckbox("EM-CCD", calibration.emCCD); gd.addNumericField("Exposure_time (ms)", calibration.exposureTime, 2); if (isCrop) gd.addCheckbox("Ignore_bounds_for_noise", optionIgnoreBoundsForNoise); // This is already set to false before the dialog is displayed //else // ignoreBoundsForNoise = false; gd.addNumericField("Initial_StdDev0", fitConfig.getInitialPeakStdDev0(), 3); if (!maximaIdentification) { gd.addNumericField("Initial_StdDev1", fitConfig.getInitialPeakStdDev1(), 3); gd.addNumericField("Initial_Angle", fitConfig.getInitialAngle(), 3); } String[] filterTypes = SettingsManager.getNames((Object[]) DataFilterType.values()); gd.addChoice("Spot_filter_type", filterTypes, filterTypes[config.getDataFilterType().ordinal()]); String[] filterNames = SettingsManager.getNames((Object[]) DataFilter.values()); gd.addChoice("Spot_filter", filterNames, filterNames[config.getDataFilter(0).ordinal()]); gd.addSlider("Smoothing", 0, 2.5, config.getSmooth(0)); gd.addSlider("Search_width", 0.5, 2.5, config.getSearch()); gd.addSlider("Border", 0.5, 2.5, config.getBorder()); gd.addSlider("Fitting_width", 2, 4.5, config.getFitting()); if (extraOptions && !fitMaxima) { gd.addCheckbox("Interlaced_data", optionInterlacedData); gd.addSlider("Integrate_frames", 1, 5, optionIntegrateFrames); } Component discardLabel = null; if (!maximaIdentification) { gd.addMessage("--- Gaussian fitting ---"); String[] solverNames = SettingsManager.getNames((Object[]) FitSolver.values()); gd.addChoice("Fit_solver", solverNames, solverNames[fitConfig.getFitSolver().ordinal()]); String[] functionNames = SettingsManager.getNames((Object[]) FitFunction.values()); gd.addChoice("Fit_function", functionNames, functionNames[fitConfig.getFitFunction().ordinal()]); if (extraOptions) gd.addCheckbox("Fit_background", fitConfig.isBackgroundFitting()); // Parameters specific to each Fit solver are collected in a second dialog gd.addNumericField("Fail_limit", config.getFailuresLimit(), 0); gd.addCheckbox("Include_neighbours", config.isIncludeNeighbours()); gd.addSlider("Neighbour_height", 0.01, 1, config.getNeighbourHeightThreshold()); gd.addSlider("Residuals_threshold", 0.01, 1, config.getResidualsThreshold()); gd.addSlider("Duplicate_distance", 0, 1.5, fitConfig.getDuplicateDistance()); gd.addMessage("--- Peak filtering ---\nDiscard fits that shift; are too low; or expand/contract"); discardLabel = gd.getMessage(); gd.addSlider("Shift_factor", 0.01, 2, fitConfig.getCoordinateShiftFactor()); gd.addNumericField("Signal_strength", fitConfig.getSignalStrength(), 2); gd.addNumericField("Min_photons", fitConfig.getMinPhotons(), 0); if (extraOptions) { gd.addNumericField("Noise", fitConfig.getNoise(), 2); String[] noiseMethodNames = SettingsManager.getNames((Object[]) Method.values()); gd.addChoice("Noise_method", noiseMethodNames, noiseMethodNames[config.getNoiseMethod().ordinal()]); } gd.addSlider("Width_factor", 0.01, 5, fitConfig.getWidthFactor()); gd.addNumericField("Precision", fitConfig.getPrecisionThreshold(), 2); } gd.addMessage("--- Results ---"); gd.addCheckbox("Log_progress", resultsSettings.logProgress); if (!maximaIdentification) { gd.addCheckbox("Show_deviations", resultsSettings.showDeviations); } String[] tableNames = SettingsManager.getNames((Object[]) ResultsTable.values()); gd.addChoice("Results_table", tableNames, tableNames[resultsSettings.getResultsTable().ordinal()]); String[] imageNames = SettingsManager.getNames((Object[]) ResultsImage.values()); gd.addMessage("--- Image output ---"); gd.addChoice("Image", imageNames, imageNames[resultsSettings.getResultsImage().ordinal()]); gd.addCheckbox("Weighted", resultsSettings.weightedImage); gd.addCheckbox("Equalised", resultsSettings.equalisedImage); gd.addSlider("Image_Precision (nm)", 5, 30, resultsSettings.precision); gd.addSlider("Image_Scale", 1, 15, resultsSettings.imageScale); if (extraOptions) { gd.addNumericField("Image_window", resultsSettings.imageRollingWindow, 0); gd.addCheckbox("Show_processed_frames", optionShowProcessedFrames); } gd.addMessage("--- File output ---"); gd.addStringField("Results_dir", resultsSettings.resultsDirectory); gd.addCheckbox("Binary_results", resultsSettings.binaryResults); gd.addMessage(" "); gd.addCheckbox("Results_in_memory", resultsSettings.resultsInMemory); // Re-arrange the standard layout which has a GridBagLayout with 2 columns (label,field) // to 4 columns: (label,field) x 2 if (gd.getLayout() != null) { GridBagLayout grid = (GridBagLayout) gd.getLayout(); int xOffset = 0, yOffset = 0; int lastY = -1, rowCount = 0; for (Component comp : gd.getComponents()) { // Check if this should be the second major column if (comp == discardLabel) { xOffset += 2; yOffset -= rowCount; } // Reposition the field GridBagConstraints c = grid.getConstraints(comp); if (lastY != c.gridy) rowCount++; lastY = c.gridy; c.gridx = c.gridx + xOffset; c.gridy = c.gridy + yOffset; c.insets.left = c.insets.left + 10 * xOffset; c.insets.top = 0; c.insets.bottom = 0; grid.setConstraints(comp, c); } if (IJ.isLinux()) gd.setBackground(new Color(238, 238, 238)); } // Add a mouse listener to the config file field if (!(java.awt.GraphicsEnvironment.isHeadless() || IJ.isMacro())) { Vector<TextField> texts = (Vector<TextField>) gd.getStringFields(); Vector<TextField> numerics = (Vector<TextField>) gd.getNumericFields(); Vector<Checkbox> checkboxes = (Vector<Checkbox>) gd.getCheckboxes(); Vector<Choice> choices = (Vector<Choice>) gd.getChoices(); int n = 0; int t = 0; int b = 0; int ch = 0; textConfigFile = texts.get(t++); textConfigFile.addMouseListener(this); textConfigFile.addTextListener(this); // TODO: add a value changed listener to detect when typing a new file textNmPerPixel = numerics.get(n++); textGain = numerics.get(n++); textEMCCD = checkboxes.get(b++); textExposure = numerics.get(n++); textInitialPeakStdDev0 = numerics.get(n++); if (!maximaIdentification) { textInitialPeakStdDev1 = numerics.get(n++); textInitialAngleD = numerics.get(n++); } textDataFilterType = choices.get(ch++); textDataFilter = choices.get(ch++); textSmooth = numerics.get(n++); textSearch = numerics.get(n++); textBorder = numerics.get(n++); textFitting = numerics.get(n++); if (extraOptions && !fitMaxima) { b++; // Skip over the interlaced data option n++; // Skip over the integrate frames option } if (!maximaIdentification) { textFitSolver = choices.get(ch++); textFitFunction = choices.get(ch++); if (extraOptions) textFitBackground = checkboxes.get(b++); textFailuresLimit = numerics.get(n++); textIncludeNeighbours = checkboxes.get(b++); textNeighbourHeightThreshold = numerics.get(n++); textResidualsThreshold = numerics.get(n++); textDuplicateDistance = numerics.get(n++); textCoordinateShiftFactor = numerics.get(n++); textSignalStrength = numerics.get(n++); textMinPhotons = numerics.get(n++); textWidthFactor = numerics.get(n++); textPrecisionThreshold = numerics.get(n++); if (extraOptions) { textNoise = numerics.get(n++); textNoiseMethod = choices.get(ch++); } } textLogProgress = checkboxes.get(b++); if (!maximaIdentification) textShowDeviations = checkboxes.get(b++); textResultsTable = choices.get(ch++); textResultsImage = choices.get(ch++); textWeightedImage = checkboxes.get(b++); textEqualisedImage = checkboxes.get(b++); textPrecision = numerics.get(n++); textImageScale = numerics.get(n++); if (extraOptions) { textImageRollingWindow = numerics.get(n++); b++; // Skip over show processed frames option } textResultsDirectory = texts.get(t++); textResultsDirectory.addMouseListener(this); textBinaryResults = checkboxes.get(b++); textResultsInMemory = checkboxes.get(b++); } gd.showDialog(); if (gd.wasCanceled() || !readDialog(settings, gd, isCrop)) return DONE; if (imp != null) { // Store whether the user selected to process all the images. int flags = IJ.setupDialog(imp, plugin_flags); // Check if cancelled if ((flags & DONE) != 0) return DONE; if ((flags & DOES_STACKS) == 0) { // Save the slice number for the overlay singleFrame = imp.getCurrentSlice(); // Account for interlaced data if (interlacedData) { int start = singleFrame; // Calculate the first frame that is not skipped while (ignoreFrame(start) && start > dataStart) start--; if (start < dataStart) { log("The current frame (%d) is before the start of the interlaced data", singleFrame); return DONE; } if (start != singleFrame) log("Updated the current frame (%d) to a valid interlaced data frame (%d)", singleFrame, start); singleFrame = start; } // Account for integrated frames int endFrame = singleFrame; if (integrateFrames > 1) { int totalFrames = 1; while (totalFrames < integrateFrames) { endFrame++; if (!ignoreFrame(endFrame)) totalFrames++; } log("Updated the image end frame (%d) to %d allow %d integrated frames", singleFrame, endFrame, integrateFrames); } // Create a new image source with the correct frames setSource(new IJImageSource(imp, singleFrame, endFrame - singleFrame)); // Store the image so the results can be added as an overlay this.imp = imp; this.imp.setOverlay(null); } } // Allow interlaced data by wrapping the image source if (interlacedData) { setSource(new InterlacedImageSource(this.source, dataStart, dataBlock, dataSkip)); } // Allow frame aggregation by wrapping the image source if (integrateFrames > 1) { setSource(new AggregatedImageSource(this.source, integrateFrames)); } // Ask if the user wants to log progress on multiple frame images if (resultsSettings.logProgress && source.getFrames() > 1) { gd = new GenericDialog(TITLE); gd.addMessage("Warning: Log progress on multiple-frame image will be slow"); gd.addCheckbox("Log_progress", resultsSettings.logProgress); gd.showDialog(); if (gd.wasCanceled()) return DONE; resultsSettings.logProgress = gd.getNextBoolean(); if (!resultsSettings.logProgress) SettingsManager.saveSettings(settings, filename); } // Get a bias if required if (resultsSettings.getResultsTable() == ResultsTable.CALIBRATED && calibration.bias == 0) { gd = new GenericDialog(TITLE); gd.addMessage("Calibrated results requires a camera bias"); gd.addNumericField("Camera_bias (ADUs)", calibration.bias, 2); gd.showDialog(); if (!gd.wasCanceled()) { calibration.bias = Math.abs(gd.getNextNumber()); if (calibration.bias > 0) SettingsManager.saveSettings(settings, filename); } } // Return the plugin flags (without the DOES_STACKS flag). // The call to run(ImageProcessor) will process the image in 'this.imp' so we only want a // single call to be made. return plugin_flags; }
From source file:gdsc.smlm.ij.plugins.CreateData.java
/** * Show a dialog allowing the parameters for a simple/benchmark simulation to be performed * /* w w w.j a v a 2 s.c o m*/ * @return True if the parameters were collected */ private boolean showSimpleDialog() { GenericDialog gd = new GenericDialog(TITLE); globalSettings = SettingsManager.loadSettings(); settings = globalSettings.getCreateDataSettings(); // Image size gd.addMessage("--- Image Size ---"); gd.addNumericField("Pixel_pitch (nm)", settings.pixelPitch, 2); gd.addNumericField("Size (px)", settings.size, 0); if (!benchmarkMode) { gd.addNumericField("Depth (nm)", settings.depth, 0); gd.addCheckbox("Fixed_depth", settings.fixedDepth); } // Noise model gd.addMessage("--- Noise Model ---"); if (extraOptions) gd.addCheckbox("No_poisson_noise", !settings.poissonNoise); gd.addNumericField("Background (photons)", settings.background, 2); gd.addNumericField("EM_gain", settings.getEmGain(), 2); gd.addNumericField("Camera_gain (ADU/e-)", settings.getCameraGain(), 4); gd.addNumericField("Quantum_efficiency", settings.getQuantumEfficiency(), 2); gd.addNumericField("Read_noise (e-)", settings.readNoise, 2); gd.addNumericField("Bias", settings.bias, 0); // PSF Model List<String> imageNames = addPSFOptions(gd); gd.addMessage("--- Fluorophores ---"); Component splitLabel = gd.getMessage(); // Do not allow grid or mask distribution if (simpleMode) gd.addChoice("Distribution", Arrays.copyOf(DISTRIBUTION, DISTRIBUTION.length - 2), settings.distribution); gd.addNumericField("Particles", settings.particles, 0); if (simpleMode) gd.addNumericField("Density (um^-2)", settings.density, 2); else if (benchmarkMode) { gd.addNumericField("X_position (nm)", settings.xPosition, 2); gd.addNumericField("Y_position (nm)", settings.yPosition, 2); gd.addNumericField("Z_position (nm)", settings.zPosition, 2); } gd.addNumericField("Min_Photons", settings.photonsPerSecond, 0); gd.addNumericField("Max_Photons", settings.photonsPerSecondMaximum, 0); gd.addMessage("--- Save options ---"); gd.addCheckbox("Raw_image", settings.rawImage); gd.addCheckbox("Save_image", settings.saveImage); gd.addCheckbox("Save_image_results", settings.saveImageResults); gd.addCheckbox("Save_localisations", settings.saveLocalisations); gd.addMessage("--- Report options ---"); gd.addCheckbox("Show_histograms", settings.showHistograms); gd.addCheckbox("Choose_histograms", settings.chooseHistograms); gd.addNumericField("Histogram_bins", settings.histogramBins, 0); gd.addCheckbox("Remove_outliers", settings.removeOutliers); if (simpleMode) gd.addSlider("Density_radius (N x HWHM)", 0, 4.5, settings.densityRadius); // Split into two columns // Re-arrange the standard layout which has a GridBagLayout with 2 columns (label,field) // to 4 columns: (label,field) x 2 if (gd.getLayout() != null) { GridBagLayout grid = (GridBagLayout) gd.getLayout(); int xOffset = 0, yOffset = 0; int lastY = -1, rowCount = 0; for (Component comp : gd.getComponents()) { // Check if this should be the second major column if (comp == splitLabel) { xOffset += 2; yOffset -= rowCount; rowCount = 0; } // Reposition the field GridBagConstraints c = grid.getConstraints(comp); if (lastY != c.gridy) rowCount++; lastY = c.gridy; c.gridx = c.gridx + xOffset; c.gridy = c.gridy + yOffset; c.insets.left = c.insets.left + 10 * xOffset; c.insets.top = 0; c.insets.bottom = 0; grid.setConstraints(comp, c); } if (IJ.isLinux()) gd.setBackground(new Color(238, 238, 238)); } gd.showDialog(); if (gd.wasCanceled()) return false; settings.pixelPitch = Math.abs(gd.getNextNumber()); settings.size = Math.abs((int) gd.getNextNumber()); if (!benchmarkMode) { // Allow negative depth settings.depth = gd.getNextNumber(); settings.fixedDepth = gd.getNextBoolean(); } if (extraOptions) poissonNoise = settings.poissonNoise = !gd.getNextBoolean(); settings.background = Math.abs(gd.getNextNumber()); settings.setEmGain(Math.abs(gd.getNextNumber())); settings.setCameraGain(Math.abs(gd.getNextNumber())); settings.setQuantumEfficiency(Math.abs(gd.getNextNumber())); settings.readNoise = Math.abs(gd.getNextNumber()); settings.bias = Math.abs((int) gd.getNextNumber()); if (!collectPSFOptions(gd, imageNames)) return false; if (simpleMode) settings.distribution = gd.getNextChoice(); settings.particles = Math.abs((int) gd.getNextNumber()); if (simpleMode) settings.density = Math.abs(gd.getNextNumber()); else if (benchmarkMode) { settings.xPosition = gd.getNextNumber(); settings.yPosition = gd.getNextNumber(); settings.zPosition = gd.getNextNumber(); } settings.photonsPerSecond = Math.abs((int) gd.getNextNumber()); settings.photonsPerSecondMaximum = Math.abs((int) gd.getNextNumber()); settings.rawImage = gd.getNextBoolean(); settings.saveImage = gd.getNextBoolean(); settings.saveImageResults = gd.getNextBoolean(); settings.saveLocalisations = gd.getNextBoolean(); settings.showHistograms = gd.getNextBoolean(); settings.chooseHistograms = gd.getNextBoolean(); settings.histogramBins = (int) gd.getNextNumber(); settings.removeOutliers = gd.getNextBoolean(); if (simpleMode) settings.densityRadius = (float) gd.getNextNumber(); // Save before validation so that the current values are preserved. SettingsManager.saveSettings(globalSettings); if (gd.invalidNumber()) return false; // Check arguments try { Parameters.isAboveZero("Pixel Pitch", settings.pixelPitch); Parameters.isAboveZero("Size", settings.size); if (!benchmarkMode && !settings.fixedDepth) Parameters.isPositive("Depth", settings.depth); Parameters.isPositive("Background", settings.background); Parameters.isPositive("EM gain", settings.getEmGain()); Parameters.isPositive("Camera gain", settings.getCameraGain()); Parameters.isPositive("Read noise", settings.readNoise); double noiseRange = settings.readNoise * settings.getCameraGain() * 4; Parameters.isEqualOrAbove("Bias must prevent clipping the read noise (@ +/- 4 StdDev) so ", settings.bias, noiseRange); Parameters.isAboveZero("Particles", settings.particles); if (simpleMode) Parameters.isAboveZero("Density", settings.density); Parameters.isAboveZero("Min Photons", settings.photonsPerSecond); if (settings.photonsPerSecondMaximum < settings.photonsPerSecond) settings.photonsPerSecondMaximum = settings.photonsPerSecond; if (!imagePSF) { Parameters.isAboveZero("Wavelength", settings.wavelength); Parameters.isAboveZero("NA", settings.numericalAperture); Parameters.isBelow("NA", settings.numericalAperture, 2); } Parameters.isAbove("Histogram bins", settings.histogramBins, 1); if (simpleMode) Parameters.isPositive("Density radius", settings.densityRadius); } catch (IllegalArgumentException e) { IJ.error(TITLE, e.getMessage()); return false; } return getHistogramOptions(); }
From source file:gdsc.smlm.ij.plugins.CreateData.java
/** * Show a dialog allowing the parameters for a simulation to be performed * /*from ww w . j a va2s . com*/ * @return True if the parameters were collected */ private boolean showDialog() { GenericDialog gd = new GenericDialog(TITLE); globalSettings = SettingsManager.loadSettings(); settings = globalSettings.getCreateDataSettings(); if (settings.stepsPerSecond < 1) settings.stepsPerSecond = 1; String[] backgroundImages = createBackgroundImageList(); gd.addNumericField("Pixel_pitch (nm)", settings.pixelPitch, 2); gd.addNumericField("Size (px)", settings.size, 0); gd.addNumericField("Depth (nm)", settings.depth, 0); gd.addCheckbox("Fixed_depth", settings.fixedDepth); gd.addNumericField("Seconds", settings.seconds, 0); gd.addNumericField("Exposure_time (ms)", settings.exposureTime, 0); gd.addSlider("Steps_per_second", 1, 15, settings.stepsPerSecond); gd.addChoice("Illumination", ILLUMINATION, settings.illumination); gd.addNumericField("Pulse_interval", settings.pulseInterval, 0); gd.addNumericField("Pulse_ratio", settings.pulseRatio, 2); if (backgroundImages != null) gd.addChoice("Background_image", backgroundImages, settings.backgroundImage); if (extraOptions) gd.addCheckbox("No_poisson_noise", !settings.poissonNoise); gd.addNumericField("Background (photons)", settings.background, 2); gd.addNumericField("EM_gain", settings.getEmGain(), 2); gd.addNumericField("Camera_gain (ADU/e-)", settings.getCameraGain(), 4); gd.addNumericField("Quantum_efficiency", settings.getQuantumEfficiency(), 2); gd.addNumericField("Read_noise (e-)", settings.readNoise, 2); gd.addNumericField("Bias", settings.bias, 0); List<String> imageNames = addPSFOptions(gd); gd.addMessage("--- Fluorophores ---"); Component splitLabel = gd.getMessage(); gd.addChoice("Distribution", DISTRIBUTION, settings.distribution); gd.addNumericField("Particles", settings.particles, 0); gd.addCheckbox("Compound_molecules", settings.compoundMolecules); gd.addNumericField("Diffusion_rate (um^2/sec)", settings.diffusionRate, 2); gd.addCheckbox("Use_grid_walk", settings.useGridWalk); gd.addSlider("Fixed_fraction (%)", 0, 100, settings.fixedFraction * 100); gd.addChoice("Confinement", CONFINEMENT, settings.confinement); gd.addNumericField("Photons (sec^-1)", settings.photonsPerSecond, 0); gd.addCheckbox("Custom_photon_distribution", settings.customPhotonDistribution); gd.addNumericField("Photon shape", settings.photonShape, 2); gd.addNumericField("Correlation (to total tOn)", settings.correlation, 2); gd.addNumericField("On_time (ms)", settings.tOn, 2); gd.addNumericField("Off_time_short (ms)", settings.tOffShort, 2); gd.addNumericField("Off_time_long (ms)", settings.tOffLong, 2); gd.addNumericField("n_Blinks_Short", settings.nBlinksShort, 2); gd.addNumericField("n_Blinks_Long", settings.nBlinksLong, 2); gd.addCheckbox("Use_geometric_distribution", settings.nBlinksGeometricDistribution); gd.addMessage("--- Peak filtering ---"); gd.addSlider("Min_Photons", 0, 50, settings.minPhotons); gd.addSlider("Min_SNR_t1", 0, 20, settings.minSNRt1); gd.addSlider("Min_SNR_tN", 0, 10, settings.minSNRtN); gd.addMessage("--- Save options ---"); Component splitLabel2 = gd.getMessage(); gd.addCheckbox("Raw_image", settings.rawImage); gd.addCheckbox("Save_image", settings.saveImage); gd.addCheckbox("Save_image_results", settings.saveImageResults); gd.addCheckbox("Save_fluorophores", settings.saveFluorophores); gd.addCheckbox("Save_localisations", settings.saveLocalisations); gd.addMessage("--- Report options ---"); gd.addCheckbox("Show_histograms", settings.showHistograms); gd.addCheckbox("Choose_histograms", settings.chooseHistograms); gd.addNumericField("Histogram_bins", settings.histogramBins, 0); gd.addCheckbox("Remove_outliers", settings.removeOutliers); gd.addSlider("Density_radius (N x HWHM)", 0, 4.5, settings.densityRadius); // Split into two columns // Re-arrange the standard layout which has a GridBagLayout with 2 columns (label,field) // to 4 columns: (label,field) x 2 if (gd.getLayout() != null) { GridBagLayout grid = (GridBagLayout) gd.getLayout(); int xOffset = 0, yOffset = 0; int lastY = -1, rowCount = 0; for (Component comp : gd.getComponents()) { // Check if this should be the second major column if (comp == splitLabel || comp == splitLabel2) { xOffset += 2; yOffset -= rowCount; rowCount = 0; } // Reposition the field GridBagConstraints c = grid.getConstraints(comp); if (lastY != c.gridy) rowCount++; lastY = c.gridy; c.gridx = c.gridx + xOffset; c.gridy = c.gridy + yOffset; c.insets.left = c.insets.left + 10 * xOffset; c.insets.top = 0; c.insets.bottom = 0; grid.setConstraints(comp, c); } if (IJ.isLinux()) gd.setBackground(new Color(238, 238, 238)); } gd.showDialog(); if (gd.wasCanceled()) return false; settings.pixelPitch = Math.abs(gd.getNextNumber()); settings.size = Math.abs((int) gd.getNextNumber()); settings.depth = Math.abs(gd.getNextNumber()); settings.fixedDepth = gd.getNextBoolean(); settings.seconds = Math.abs((int) gd.getNextNumber()); settings.exposureTime = Math.abs((int) gd.getNextNumber()); settings.stepsPerSecond = Math.abs((int) gd.getNextNumber()); settings.illumination = gd.getNextChoice(); settings.pulseInterval = Math.abs((int) gd.getNextNumber()); settings.pulseRatio = Math.abs(gd.getNextNumber()); if (backgroundImages != null) settings.backgroundImage = gd.getNextChoice(); if (extraOptions) poissonNoise = settings.poissonNoise = !gd.getNextBoolean(); settings.background = Math.abs(gd.getNextNumber()); settings.setEmGain(Math.abs(gd.getNextNumber())); settings.setCameraGain(Math.abs(gd.getNextNumber())); settings.setQuantumEfficiency(Math.abs(gd.getNextNumber())); settings.readNoise = Math.abs(gd.getNextNumber()); settings.bias = Math.abs((int) gd.getNextNumber()); if (!collectPSFOptions(gd, imageNames)) return false; settings.distribution = gd.getNextChoice(); settings.particles = Math.abs((int) gd.getNextNumber()); settings.compoundMolecules = gd.getNextBoolean(); settings.diffusionRate = Math.abs(gd.getNextNumber()); settings.useGridWalk = gd.getNextBoolean(); settings.fixedFraction = Math.abs(gd.getNextNumber() / 100.0); settings.confinement = gd.getNextChoice(); settings.photonsPerSecond = Math.abs((int) gd.getNextNumber()); settings.customPhotonDistribution = gd.getNextBoolean(); settings.photonShape = Math.abs(gd.getNextNumber()); settings.correlation = gd.getNextNumber(); settings.tOn = Math.abs(gd.getNextNumber()); settings.tOffShort = Math.abs(gd.getNextNumber()); settings.tOffLong = Math.abs(gd.getNextNumber()); settings.nBlinksShort = Math.abs(gd.getNextNumber()); settings.nBlinksLong = Math.abs(gd.getNextNumber()); settings.nBlinksGeometricDistribution = gd.getNextBoolean(); minPhotons = settings.minPhotons = gd.getNextNumber(); minSNRt1 = settings.minSNRt1 = gd.getNextNumber(); minSNRtN = settings.minSNRtN = gd.getNextNumber(); settings.rawImage = gd.getNextBoolean(); settings.saveImage = gd.getNextBoolean(); settings.saveImageResults = gd.getNextBoolean(); settings.saveFluorophores = gd.getNextBoolean(); settings.saveLocalisations = gd.getNextBoolean(); settings.showHistograms = gd.getNextBoolean(); settings.chooseHistograms = gd.getNextBoolean(); settings.histogramBins = (int) gd.getNextNumber(); settings.removeOutliers = gd.getNextBoolean(); settings.densityRadius = (float) gd.getNextNumber(); // Ensure tN threshold is more lenient if (settings.minSNRt1 < settings.minSNRtN) { double tmp = settings.minSNRt1; settings.minSNRt1 = settings.minSNRtN; settings.minSNRtN = tmp; } // Save before validation so that the current values are preserved. SettingsManager.saveSettings(globalSettings); // Check arguments try { Parameters.isAboveZero("Pixel Pitch", settings.pixelPitch); Parameters.isAboveZero("Size", settings.size); if (!settings.fixedDepth) Parameters.isPositive("Depth", settings.depth); Parameters.isAboveZero("Seconds", settings.seconds); Parameters.isAboveZero("Exposure time", settings.exposureTime); Parameters.isAboveZero("Steps per second", settings.stepsPerSecond); Parameters.isPositive("Background", settings.background); Parameters.isPositive("EM gain", settings.getEmGain()); Parameters.isPositive("Camera gain", settings.getCameraGain()); Parameters.isPositive("Read noise", settings.readNoise); double noiseRange = settings.readNoise * settings.getCameraGain() * 4; Parameters.isEqualOrAbove("Bias must prevent clipping the read noise (@ +/- 4 StdDev) so ", settings.bias, noiseRange); Parameters.isAboveZero("Particles", settings.particles); Parameters.isAboveZero("Photons", settings.photonsPerSecond); Parameters.isEqualOrBelow("Correlation", settings.correlation, 1); Parameters.isEqualOrAbove("Correlation", settings.correlation, -1); if (!imagePSF) { Parameters.isAboveZero("Wavelength", settings.wavelength); Parameters.isAboveZero("NA", settings.numericalAperture); Parameters.isBelow("NA", settings.numericalAperture, 2); } Parameters.isPositive("Diffusion rate", settings.diffusionRate); Parameters.isPositive("Fixed fraction", settings.fixedFraction); Parameters.isPositive("Pulse interval", settings.pulseInterval); Parameters.isAboveZero("Pulse ratio", settings.pulseRatio); Parameters.isAboveZero("tOn", settings.tOn); Parameters.isAboveZero("tOff Short", settings.tOffShort); Parameters.isAboveZero("tOff Long", settings.tOffLong); Parameters.isPositive("n-Blinks Short", settings.nBlinksShort); Parameters.isPositive("n-Blinks Long", settings.nBlinksLong); Parameters.isPositive("Min photons", settings.minPhotons); Parameters.isPositive("Min SNR t1", settings.minSNRt1); Parameters.isPositive("Min SNR tN", settings.minSNRtN); Parameters.isAbove("Histogram bins", settings.histogramBins, 1); Parameters.isPositive("Density radius", settings.densityRadius); } catch (IllegalArgumentException e) { IJ.error(TITLE, e.getMessage()); return false; } if (gd.invalidNumber()) return false; if (!getHistogramOptions()) return false; String[] maskImages = null; if (settings.distribution.equals(DISTRIBUTION[MASK])) { maskImages = createDistributionImageList(); if (maskImages != null) { gd = new GenericDialog(TITLE); gd.addMessage("Select the mask image for the distribution"); gd.addChoice("Distribution_mask", maskImages, settings.distributionMask); if (maskListContainsStacks) gd.addNumericField("Distribution_slice_depth (nm)", settings.distributionMaskSliceDepth, 0); gd.showDialog(); if (gd.wasCanceled()) return false; settings.distributionMask = gd.getNextChoice(); if (maskListContainsStacks) settings.distributionMaskSliceDepth = Math.abs(gd.getNextNumber()); } } else if (settings.distribution.equals(DISTRIBUTION[GRID])) { gd = new GenericDialog(TITLE); gd.addMessage("Select grid for the distribution"); gd.addNumericField("Cell_size", settings.cellSize, 0); gd.addSlider("p-binary", 0, 1, settings.probabilityBinary); gd.addNumericField("Min_binary_distance (nm)", settings.minBinaryDistance, 0); gd.addNumericField("Max_binary_distance (nm)", settings.maxBinaryDistance, 0); gd.showDialog(); if (gd.wasCanceled()) return false; settings.cellSize = (int) gd.getNextNumber(); settings.probabilityBinary = gd.getNextNumber(); settings.minBinaryDistance = gd.getNextNumber(); settings.maxBinaryDistance = gd.getNextNumber(); // Check arguments try { Parameters.isAboveZero("Cell size", settings.cellSize); Parameters.isPositive("p-binary", settings.probabilityBinary); Parameters.isEqualOrBelow("p-binary", settings.probabilityBinary, 1); Parameters.isPositive("Min binary distance", settings.minBinaryDistance); Parameters.isPositive("Max binary distance", settings.maxBinaryDistance); Parameters.isEqualOrBelow("Min binary distance", settings.minBinaryDistance, settings.maxBinaryDistance); } catch (IllegalArgumentException e) { IJ.error(TITLE, e.getMessage()); return false; } } SettingsManager.saveSettings(globalSettings); if (settings.diffusionRate > 0 && settings.fixedFraction < 1) { if (settings.confinement.equals(CONFINEMENT[CONFINEMENT_SPHERE])) { gd = new GenericDialog(TITLE); gd.addMessage("Select the sphere radius for the diffusion confinement"); gd.addSlider("Confinement_radius (nm)", 0, 2000, settings.confinementRadius); gd.showDialog(); if (gd.wasCanceled()) return false; settings.confinementRadius = gd.getNextNumber(); } else if (settings.confinement.equals(CONFINEMENT[CONFINEMENT_MASK])) { if (maskImages == null) maskImages = createDistributionImageList(); if (maskImages != null) { gd = new GenericDialog(TITLE); gd.addMessage("Select the mask image for the diffusion confinement"); gd.addChoice("Confinement_mask", maskImages, settings.confinementMask); if (maskListContainsStacks) gd.addNumericField("Confinement_slice_depth (nm)", settings.confinementMaskSliceDepth, 0); gd.showDialog(); if (gd.wasCanceled()) return false; settings.confinementMask = gd.getNextChoice(); if (maskListContainsStacks) settings.confinementMaskSliceDepth = Math.abs(gd.getNextNumber()); } } } SettingsManager.saveSettings(globalSettings); if (settings.compoundMolecules) { // Show a second dialog where the molecule configuration is specified gd = new GenericDialog(TITLE); gd.addMessage("Specify the compound molecules"); gd.addTextAreas(settings.compoundText, null, 20, 80); gd.addCheckbox("Rotate_initial_orientation", settings.rotateInitialOrientation); gd.addCheckbox("Rotate_during_simulation", settings.rotateDuringSimulation); gd.addCheckbox("Enable_2D_rotation", settings.rotate2D); gd.addCheckbox("Show_example_compounds", false); if (!(java.awt.GraphicsEnvironment.isHeadless() || IJ.isMacro())) { @SuppressWarnings("rawtypes") Vector v = gd.getCheckboxes(); Checkbox cb = (Checkbox) v.get(v.size() - 1); cb.addItemListener(this); } gd.showDialog(); if (gd.wasCanceled()) return false; settings.compoundText = gd.getNextText(); settings.rotateInitialOrientation = gd.getNextBoolean(); settings.rotateDuringSimulation = gd.getNextBoolean(); settings.rotate2D = gd.getNextBoolean(); if (gd.getNextBoolean()) { logExampleCompounds(); return false; } } SettingsManager.saveSettings(globalSettings); return true; }
From source file:org.eclipse.wb.internal.swing.model.layout.gbl.GridBagLayoutInfo.java
@Override public Object getConstraintsObject(final java.awt.Component component) throws Exception { GridBagConstraints constraints; if (component == null) { // no component instance, we probably add new component, so use just some GridBagConstraints constraints = new GridBagConstraints(); } else {// w w w . j av a 2s . c o m // component is bound to parent, get constraints from layout GridBagLayout layout = (GridBagLayout) getObject(); constraints = layout.getConstraints(component); } return constraints; }
From source file:org.photovault.swingui.PhotoInfoEditor.java
protected void createUI() { setLayout(new BorderLayout()); setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); tabPane = new JTabbedPane(); add(tabPane, BorderLayout.CENTER); // General pane JPanel generalPane = new JPanel(); tabPane.addTab("General", generalPane); // Create the fields & their labels // Photographer field JLabel photographerLabel = new JLabel("Photographer"); photographerField = createMvTextField("photographer", 30); photographerDoc = photographerField.getDocument(); // "Fuzzy time" field JLabel fuzzyDateLabel = new JLabel("Shooting date"); fuzzyDateField = new JTextField(30); fuzzyDateDoc = fuzzyDateField.getDocument(); fuzzyDateDoc.putProperty(FIELD, PhotoInfoFields.FUZZY_SHOOT_TIME); fuzzyDateDoc.addDocumentListener(this); JLabel qualityLabel = new JLabel("Quality"); qualityField = new JComboBox(qualityStrings); qualityField.addActionListener(this); StarRating qualityStars = new StarRating(5); FieldController<Integer> qfCtrl = ctrl.getFieldController("quality"); ValueModel qualityFieldValue = new PropertyAdapter(qfCtrl, "value", true); ValueModel starCount = new PropertyAdapter(qualityStars, "selection", true); PropertyConnector.connect(qualityFieldValue, "value", starCount, "value"); // Shooting place field JLabel shootingPlaceLabel = new JLabel("Shooting place"); shootingPlaceField = createMvTextField("shotLocation.description", 30); shootingPlaceDoc = shootingPlaceField.getDocument(); JLabel shotLocRoadLabel = new JLabel("Road"); JTextField shotLocRoadField = createMvTextField("shotLocation.road", 30); JLabel shotLocSuburbLabel = new JLabel("Suburb"); JTextField shotLocSuburbField = createMvTextField("shotLocation.suburb", 30); JLabel shotLocCityLabel = new JLabel("City"); JTextField shotLocCityField = createMvTextField("shotLocation.city", 30); JLabel shotLocCountryLabel = new JLabel("Country"); JTextField shotLocCountryField = createMvTextField("shotLocation.country", 30); JLabel shotLocGeohashLabel = new JLabel("Geohash code"); JTextField shotLocGeohashField = createMvTextField("shotLocation.geoHashString", 30); shotLocGeohashField.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), "fillAddress"); shotLocGeohashField.getActionMap().put("fillAddress", new FindAddressAction(ctrl)); // Tags/*from w w w. jav a 2 s .c om*/ JLabel tagLabel = new JLabel("Tags"); tagList = new TagList2(ctrl.getTagController()); tagList.setBackground(generalPane.getBackground()); // Description text JLabel descLabel = new JLabel("Description"); descriptionTextArea = new JTextArea(5, 40); descriptionTextArea.setLineWrap(true); descriptionTextArea.setWrapStyleWord(true); JScrollPane descScrollPane = new JScrollPane(descriptionTextArea); descScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); Border descBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED); descBorder = BorderFactory.createTitledBorder(descBorder, "Description"); descScrollPane.setBorder(descBorder); descriptionDoc = descriptionTextArea.getDocument(); descriptionDoc.putProperty(FIELD, PhotoInfoFields.DESCRIPTION); descriptionDoc.addDocumentListener(this); // Lay out the created controls GridBagLayout layout = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); generalPane.setLayout(layout); JLabel[] labels = { photographerLabel, fuzzyDateLabel, shootingPlaceLabel, shotLocGeohashLabel, shotLocRoadLabel, shotLocSuburbLabel, shotLocCityLabel, shotLocCountryLabel, qualityLabel, tagLabel }; JComponent[] fields = { photographerField, fuzzyDateField, shootingPlaceField, shotLocGeohashField, shotLocRoadField, shotLocSuburbField, shotLocCityField, shotLocCountryField, qualityStars, tagList }; addLabelTextRows(labels, fields, layout, generalPane); c = layout.getConstraints(tagList); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0.0; c.weighty = 1.0; layout.setConstraints(tagList, c); generalPane.add(descScrollPane); c.gridwidth = GridBagConstraints.REMAINDER; c.weighty = 0.5; c.fill = GridBagConstraints.BOTH; layout.setConstraints(descScrollPane, c); c = new GridBagConstraints(); c.gridwidth = 1; c.weighty = 0; c.fill = GridBagConstraints.NONE; c.gridy = GridBagConstraints.RELATIVE; c.gridy = GridBagConstraints.RELATIVE; createTechDataUI(); createFolderPaneUI(); createRightsUI(); }