use of java.awt.TextField in project GDSC-SMLM by aherbert.
the class DoubletAnalysis method showDialog.
/**
* Show dialog.
*
* @return true, if successful
*/
@SuppressWarnings("unchecked")
private boolean showDialog() {
GenericDialog gd = new GenericDialog(TITLE);
gd.addHelp(About.HELP_URL);
final double sa = getSa();
gd.addMessage(String.format("Fits the benchmark image created by CreateData plugin.\nPSF width = %s, adjusted = %s", Utils.rounded(simulationParameters.s / simulationParameters.a), Utils.rounded(sa)));
// For each new benchmark width, reset the PSF width to the square pixel adjustment
if (lastId != simulationParameters.id) {
double w = sa;
matchDistance = w * Gaussian2DFunction.SD_TO_HWHM_FACTOR;
lowerDistance = 0.5 * matchDistance;
fitConfig.setInitialPeakStdDev(w);
cal.setNmPerPixel(simulationParameters.a);
cal.setGain(simulationParameters.gain);
cal.setAmplification(simulationParameters.amplification);
cal.setExposureTime(100);
cal.setReadNoise(simulationParameters.readNoise);
cal.setBias(simulationParameters.bias);
cal.setEmCCD(simulationParameters.emCCD);
fitConfig.setGain(cal.getGain());
fitConfig.setBias(cal.getBias());
fitConfig.setReadNoise(cal.getReadNoise());
fitConfig.setAmplification(cal.getAmplification());
}
// Support for using templates
String[] templates = ConfigurationTemplate.getTemplateNames(true);
gd.addChoice("Template", templates, templates[0]);
// Allow the settings from the benchmark analysis to be used
gd.addCheckbox("Benchmark_settings", useBenchmarkSettings);
// Collect options for fitting
gd.addNumericField("Initial_StdDev", fitConfig.getInitialPeakStdDev0(), 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());
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()]);
gd.addSlider("Iteration_increase", 1, 4.5, iterationIncrease);
gd.addCheckbox("Ignore_with_neighbours", ignoreWithNeighbours);
gd.addCheckbox("Show_overlay", showOverlay);
gd.addCheckbox("Show_histograms", showHistograms);
gd.addCheckbox("Show_results", showResults);
gd.addCheckbox("Show_Jaccard_Plot", showJaccardPlot);
gd.addCheckbox("Use_max_residuals", useMaxResiduals);
gd.addNumericField("Match_distance", matchDistance, 2);
gd.addNumericField("Lower_distance", lowerDistance, 2);
gd.addNumericField("Signal_factor", signalFactor, 2);
gd.addNumericField("Lower_factor", lowerSignalFactor, 2);
gd.addChoice("Matching", MATCHING, MATCHING[matching]);
// Add a mouse listener to the config file field
if (Utils.isShowGenericDialog()) {
Vector<TextField> numerics = (Vector<TextField>) gd.getNumericFields();
Vector<Choice> choices = (Vector<Choice>) gd.getChoices();
int n = 0;
int ch = 0;
choices.get(ch++).addItemListener(this);
Checkbox b = (Checkbox) gd.getCheckboxes().get(0);
b.addItemListener(this);
textInitialPeakStdDev0 = 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++);
textFitSolver = choices.get(ch++);
textFitFunction = choices.get(ch++);
// Iteration increase
n++;
textMatchDistance = numerics.get(n++);
textLowerDistance = numerics.get(n++);
textSignalFactor = numerics.get(n++);
textLowerFactor = numerics.get(n++);
}
gd.showDialog();
if (gd.wasCanceled())
return false;
// Ignore the template
gd.getNextChoice();
useBenchmarkSettings = gd.getNextBoolean();
fitConfig.setInitialPeakStdDev(gd.getNextNumber());
config.setDataFilterType(gd.getNextChoiceIndex());
config.setDataFilter(gd.getNextChoiceIndex(), Math.abs(gd.getNextNumber()), 0);
config.setSearch(gd.getNextNumber());
config.setBorder(gd.getNextNumber());
config.setFitting(gd.getNextNumber());
fitConfig.setFitSolver(gd.getNextChoiceIndex());
fitConfig.setFitFunction(gd.getNextChoiceIndex());
// Avoid stupidness. Note: We are mostly ignoring the validation result and
// checking the results for the doublets manually.
// Realistically we cannot fit lower than this
fitConfig.setMinPhotons(15);
// Set the width factors to help establish bounds for bounded fitters
fitConfig.setMinWidthFactor(1.0 / 10);
fitConfig.setWidthFactor(10);
iterationIncrease = gd.getNextNumber();
ignoreWithNeighbours = gd.getNextBoolean();
showOverlay = gd.getNextBoolean();
showHistograms = gd.getNextBoolean();
showResults = gd.getNextBoolean();
showJaccardPlot = gd.getNextBoolean();
useMaxResiduals = gd.getNextBoolean();
matchDistance = Math.abs(gd.getNextNumber());
lowerDistance = Math.abs(gd.getNextNumber());
signalFactor = Math.abs(gd.getNextNumber());
lowerSignalFactor = Math.abs(gd.getNextNumber());
matching = gd.getNextChoiceIndex();
if (gd.invalidNumber())
return false;
if (lowerDistance > matchDistance)
lowerDistance = matchDistance;
if (lowerSignalFactor > signalFactor)
lowerSignalFactor = signalFactor;
if (useBenchmarkSettings) {
if (!updateFitConfiguration(config))
return false;
}
GlobalSettings settings = new GlobalSettings();
settings.setFitEngineConfiguration(config);
settings.setCalibration(cal);
boolean configure = true;
if (useBenchmarkSettings) {
// Only configure the fit solver if not in a macro
configure = Macro.getOptions() == null;
}
if (configure && !PeakFit.configureFitSolver(settings, null, false))
return false;
lastId = simulationParameters.id;
if (showHistograms) {
gd = new GenericDialog(TITLE);
gd.addMessage("Select the histograms to display");
for (int i = 0; i < NAMES.length; i++) gd.addCheckbox(NAMES[i].replace(' ', '_'), displayHistograms[i]);
for (int i = 0; i < NAMES2.length; i++) gd.addCheckbox(NAMES2[i].replace(' ', '_'), displayHistograms[i + NAMES.length]);
gd.showDialog();
if (gd.wasCanceled())
return false;
for (int i = 0; i < displayHistograms.length; i++) displayHistograms[i] = gd.getNextBoolean();
}
return true;
}
use of java.awt.TextField in project GDSC-SMLM by aherbert.
the class CreateData method showLoadDialog.
/**
* Show a dialog allowing the parameters for a benchmark simulation to be loaded
*
* @return True if the parameters were collected
*/
private boolean showLoadDialog() {
GenericDialog gd = new GenericDialog(TITLE);
String[] images = Utils.getImageList(Utils.GREY_SCALE);
gd.addChoice("Image", images, benchmarkImage);
gd.addStringField("Results_file", benchmarkFile);
gd.addCheckbox("Preprocessed_results", benchmarkAuto);
if (Utils.isShowGenericDialog()) {
// Add a listener to allow selection of the file
@SuppressWarnings("unchecked") Vector<TextField> texts = (Vector<TextField>) gd.getStringFields();
TextField textFile = texts.get(0);
textFile.addMouseListener(this);
}
gd.showDialog();
if (gd.wasCanceled())
return false;
benchmarkImage = gd.getNextChoice();
benchmarkFile = gd.getNextString();
benchmarkAuto = gd.getNextBoolean();
return true;
}
use of java.awt.TextField in project GDSC-SMLM by aherbert.
the class Configuration method showDialog.
/**
* Show the current properties
*/
@SuppressWarnings("unchecked")
public void showDialog() {
configurationChanged = false;
String filename = SettingsManager.getSettingsFilename();
GlobalSettings settings = SettingsManager.loadSettings(filename);
FitEngineConfiguration config = settings.getFitEngineConfiguration();
FitConfiguration fitConfig = config.getFitConfiguration();
Calibration calibration = settings.getCalibration();
GenericDialog gd = new GenericDialog(TITLE);
gd.addHelp(About.HELP_URL);
gd.addMessage("Configuration settings for the single-molecule localisation microscopy plugins");
gd.addStringField("Config_file", filename, 40);
gd.addNumericField("Calibration (nm/px)", calibration.getNmPerPixel(), 2);
gd.addNumericField("Gain", calibration.getGain(), 2);
gd.addCheckbox("EM-CCD", calibration.isEmCCD());
gd.addNumericField("Exposure_time (ms)", calibration.getExposureTime(), 2);
gd.addMessage("--- Gaussian parameters ---");
gd.addNumericField("Initial_StdDev0", fitConfig.getInitialPeakStdDev0(), 3);
gd.addNumericField("Initial_StdDev1", fitConfig.getInitialPeakStdDev1(), 3);
gd.addNumericField("Initial_Angle", fitConfig.getInitialAngle(), 3);
gd.addMessage("--- Maxima identification ---");
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());
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.addSlider("Duplicate_distance", 0, 1.5, fitConfig.getDuplicateDistance());
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.01, 5, fitConfig.getWidthFactor());
gd.addNumericField("Precision_threshold", fitConfig.getPrecisionThreshold(), 2);
// Add a mouse listener to the config file field
if (Utils.isShowGenericDialog()) {
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++);
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++);
textFitSolver = choices.get(ch++);
textFitFunction = choices.get(ch++);
textFailuresLimit = numerics.get(n++);
textIncludeNeighbours = checkboxes.get(b++);
textNeighbourHeightThreshold = numerics.get(n++);
textResidualsThreshold = numerics.get(n++);
textDuplicateDistance = numerics.get(n++);
textSmartFilter = checkboxes.get(b++);
textDisableSimpleFilter = checkboxes.get(b++);
textCoordinateShiftFactor = numerics.get(n++);
textSignalStrength = numerics.get(n++);
textMinPhotons = numerics.get(n++);
textMinWidthFactor = numerics.get(n++);
textWidthFactor = numerics.get(n++);
textPrecisionThreshold = numerics.get(n++);
updateFilterInput();
textSmartFilter.addItemListener(this);
textDisableSimpleFilter.addItemListener(this);
}
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())
return;
filename = gd.getNextString();
calibration.setNmPerPixel(gd.getNextNumber());
calibration.setGain(gd.getNextNumber());
calibration.setEmCCD(gd.getNextBoolean());
calibration.setExposureTime(gd.getNextNumber());
fitConfig.setInitialPeakStdDev0(gd.getNextNumber());
fitConfig.setInitialPeakStdDev1(gd.getNextNumber());
fitConfig.setInitialAngleD(gd.getNextNumber());
config.setDataFilterType(gd.getNextChoiceIndex());
config.setDataFilter(gd.getNextChoiceIndex(), Math.abs(gd.getNextNumber()), 0);
config.setSearch(gd.getNextNumber());
config.setBorder(gd.getNextNumber());
config.setFitting(gd.getNextNumber());
fitConfig.setFitSolver(gd.getNextChoiceIndex());
fitConfig.setFitFunction(gd.getNextChoiceIndex());
config.setFailuresLimit((int) gd.getNextNumber());
config.setIncludeNeighbours(gd.getNextBoolean());
config.setNeighbourHeightThreshold(gd.getNextNumber());
config.setResidualsThreshold(gd.getNextNumber());
fitConfig.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.setWidthFactor(gd.getNextNumber());
fitConfig.setPrecisionThreshold(gd.getNextNumber());
// Check arguments
try {
Parameters.isAboveZero("nm per pixel", calibration.getNmPerPixel());
Parameters.isAboveZero("Gain", calibration.getGain());
Parameters.isAboveZero("Exposure time", calibration.getExposureTime());
Parameters.isAboveZero("Initial SD0", fitConfig.getInitialPeakStdDev0());
Parameters.isAboveZero("Initial SD1", fitConfig.getInitialPeakStdDev1());
Parameters.isPositive("Initial angle", fitConfig.getInitialAngleD());
Parameters.isAboveZero("Search_width", config.getSearch());
Parameters.isAboveZero("Fitting_width", config.getFitting());
Parameters.isPositive("Failures limit", config.getFailuresLimit());
Parameters.isPositive("Neighbour height threshold", config.getNeighbourHeightThreshold());
Parameters.isPositive("Residuals threshold", config.getResidualsThreshold());
Parameters.isPositive("Duplicate distance", fitConfig.getDuplicateDistance());
Parameters.isPositive("Coordinate Shift factor", fitConfig.getCoordinateShiftFactor());
Parameters.isPositive("Signal strength", fitConfig.getSignalStrength());
Parameters.isPositive("Min photons", fitConfig.getMinPhotons());
Parameters.isPositive("Min width factor", fitConfig.getMinWidthFactor());
Parameters.isPositive("Width factor", fitConfig.getWidthFactor());
Parameters.isPositive("Precision threshold", fitConfig.getPrecisionThreshold());
} catch (IllegalArgumentException e) {
IJ.error(TITLE, e.getMessage());
return;
}
if (gd.invalidNumber())
return;
configurationChanged = SettingsManager.saveSettings(settings, filename);
if (configurationChanged)
SettingsManager.saveSettingsFilename(filename);
if (!PeakFit.configureSmartFilter(settings, filename))
return;
if (!PeakFit.configureDataFilter(settings, filename, false))
return;
PeakFit.configureFitSolver(settings, filename, false);
}
use of java.awt.TextField in project jgnash by ccavanaugh.
the class PayeePieChart method createPanel.
private JPanel createPanel() {
JButton refreshButton = new JButton(rb.getString("Button.Refresh"));
JButton addFilterButton = new JButton(rb.getString("Button.AddFilter"));
final JButton saveButton = new JButton(rb.getString("Button.SaveFilters"));
JButton deleteFilterButton = new JButton(rb.getString("Button.DeleteFilter"));
JButton clearPrefButton = new JButton(rb.getString("Button.MasterDelete"));
filterCombo = new JComboBox<>();
startField = new DatePanel();
endField = new DatePanel();
txtAddFilter = new TextField();
filterList = new ArrayList<>();
filtersChanged = false;
useFilters = new JCheckBox(rb.getString("Label.UseFilters"));
useFilters.setSelected(true);
showPercentCheck = new JCheckBox(rb.getString("Button.ShowPercentValues"));
combo = AccountListComboBox.getFullInstance();
final LocalDate dStart = DateUtils.getFirstDayOfTheMonth(LocalDate.now().minusYears(DEBIT));
long start = pref.getLong(START_DATE, DateUtils.asEpochMilli(dStart));
startField.setDate(DateUtils.asLocalDate(start));
currentAccount = combo.getSelectedAccount();
PieDataset[] data = createPieDataSet(currentAccount);
JFreeChart chartCredit = createPieChart(currentAccount, data, CREDIT);
chartPanelCredit = new ChartPanel(chartCredit, true, true, true, false, true);
// (chart, properties, save, print, zoom, tooltips)
JFreeChart chartDebit = createPieChart(currentAccount, data, DEBIT);
chartPanelDebit = new ChartPanel(chartDebit, true, true, true, false, true);
FormLayout layout = new FormLayout("p, $lcgap, 70dlu, 8dlu, p, $lcgap, 70dlu, $ugap, p, $lcgap:g, left:p", "d, $rgap, d, $ugap, f:p:g, $rgap, d");
DefaultFormBuilder builder = new DefaultFormBuilder(layout);
layout.setRowGroups(new int[][] { { DEBIT, 3 } });
// row 1
builder.append(combo, 9);
builder.append(useFilters);
builder.nextLine();
builder.nextLine();
// row 3
builder.append(rb.getString("Label.StartDate"), startField);
builder.append(rb.getString("Label.EndDate"), endField);
builder.append(refreshButton);
builder.append(showPercentCheck);
builder.nextLine();
builder.nextLine();
// row 5
FormLayout subLayout = new FormLayout("180dlu:g, 1dlu, 180dlu:g", "f:180dlu:g");
DefaultFormBuilder subBuilder = new DefaultFormBuilder(subLayout);
subBuilder.append(chartPanelCredit);
subBuilder.append(chartPanelDebit);
builder.append(subBuilder.getPanel(), 11);
builder.nextLine();
builder.nextLine();
// row 7
builder.append(txtAddFilter, 3);
builder.append(addFilterButton, 3);
builder.append(saveButton);
builder.nextLine();
// row
builder.append(filterCombo, 3);
builder.append(deleteFilterButton, 3);
builder.append(clearPrefButton);
builder.nextLine();
JPanel panel = builder.getPanel();
combo.addActionListener(e -> {
Account newAccount = combo.getSelectedAccount();
if (filtersChanged) {
int result = JOptionPane.showConfirmDialog(null, rb.getString("Message.SaveFilters"), "Warning", JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.YES_OPTION) {
saveButton.doClick();
}
}
filtersChanged = false;
String[] list = POUND_DELIMITER_PATTERN.split(pref.get(FILTER_TAG + newAccount.hashCode(), ""));
filterList.clear();
for (String filter : list) {
if (!filter.isEmpty()) {
filterList.add(filter);
}
}
refreshFilters();
setCurrentAccount(newAccount);
pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
});
refreshButton.addActionListener(e -> {
setCurrentAccount(currentAccount);
pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
});
clearPrefButton.addActionListener(e -> {
int result = JOptionPane.showConfirmDialog(null, rb.getString("Message.MasterDelete"), "Warning", JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.YES_OPTION) {
try {
pref.clear();
} catch (Exception ex) {
System.out.println("Exception clearing preferences" + ex);
}
}
});
saveButton.addActionListener(e -> {
final StringBuilder sb = new StringBuilder();
for (String filter : filterList) {
sb.append(filter);
sb.append('#');
}
pref.put(FILTER_TAG + currentAccount.hashCode(), sb.toString());
filtersChanged = false;
});
addFilterButton.addActionListener(e -> {
String newFilter = txtAddFilter.getText();
filterList.remove(newFilter);
if (!newFilter.isEmpty()) {
filterList.add(newFilter);
filtersChanged = true;
txtAddFilter.setText("");
}
refreshFilters();
});
deleteFilterButton.addActionListener(e -> {
if (!filterList.isEmpty()) {
String filter = (String) filterCombo.getSelectedItem();
filterList.remove(filter);
filtersChanged = true;
}
refreshFilters();
});
useFilters.addActionListener(e -> setCurrentAccount(currentAccount));
showPercentCheck.addActionListener(e -> {
((PiePlot) chartPanelCredit.getChart().getPlot()).setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);
((PiePlot) chartPanelDebit.getChart().getPlot()).setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);
});
return panel;
}
Aggregations