use of java.awt.TextField in project GDSC-SMLM by aherbert.
the class SpotAnalysis method createFrame.
@SuppressWarnings({ "rawtypes", "unchecked" })
private void createFrame() {
Panel mainPanel = new Panel();
add(mainPanel);
inputChoice = new Choice();
mainPanel.add(createChoicePanel(inputChoice, ""));
widthTextField = new TextField();
mainPanel.add(createTextPanel(widthTextField, "PSF width", "1.2"));
blurTextField = new TextField();
mainPanel.add(createTextPanel(blurTextField, "Blur (relative to width)", "1"));
gainTextField = new TextField();
mainPanel.add(createTextPanel(gainTextField, "Gain", "37.7"));
exposureTextField = new TextField();
mainPanel.add(createTextPanel(exposureTextField, "ms/Frame", "20"));
smoothingTextField = new TextField();
mainPanel.add(createTextPanel(smoothingTextField, "Smoothing", "0.25"));
profileButton = new Button("Profile");
profileButton.addActionListener(this);
addButton = new Button("Add");
addButton.addActionListener(this);
deleteButton = new Button("Remove");
deleteButton.addActionListener(this);
saveButton = new Button("Save");
saveButton.addActionListener(this);
saveTracesButton = new Button("Save Traces");
saveTracesButton.addActionListener(this);
currentLabel = new Label();
mainPanel.add(createLabelPanel(currentLabel, "", ""));
rawFittedLabel = new Label();
mainPanel.add(createLabelPanel(rawFittedLabel, "", ""));
blurFittedLabel = new Label();
mainPanel.add(createLabelPanel(blurFittedLabel, "", ""));
JPanel buttonPanel = new JPanel();
FlowLayout l = new FlowLayout();
l.setVgap(0);
buttonPanel.setLayout(l);
buttonPanel.add(profileButton, BorderLayout.CENTER);
buttonPanel.add(addButton, BorderLayout.CENTER);
buttonPanel.add(deleteButton, BorderLayout.CENTER);
buttonPanel.add(saveButton, BorderLayout.CENTER);
buttonPanel.add(saveTracesButton, BorderLayout.CENTER);
mainPanel.add(buttonPanel);
listModel = new DefaultListModel();
onFramesList = new JList(listModel);
onFramesList.setVisibleRowCount(15);
onFramesList.addListSelectionListener(this);
//mainPanel.add(onFramesList);
JScrollPane scrollPane = new JScrollPane(onFramesList);
scrollPane.getVerticalScrollBarPolicy();
mainPanel.add(scrollPane);
GridBagLayout mainGrid = new GridBagLayout();
int y = 0;
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.fill = GridBagConstraints.BOTH;
c.anchor = GridBagConstraints.WEST;
c.gridwidth = 1;
c.insets = new Insets(2, 2, 2, 2);
for (Component comp : mainPanel.getComponents()) {
c.gridy = y++;
mainGrid.setConstraints(comp, c);
}
mainPanel.setLayout(mainGrid);
}
use of java.awt.TextField in project GDSC-SMLM by aherbert.
the class CreateData method mouseClicked.
public void mouseClicked(MouseEvent e) {
if (// Double-click
e.getClickCount() > 1) {
if (e.getSource() instanceof TextField) {
TextField textFile = (TextField) e.getSource();
String newFilename = Utils.getFilename("Config_File", textFile.getText());
if (newFilename != null) {
textFile.setText(newFilename);
}
}
}
}
use of java.awt.TextField in project GDSC-SMLM by aherbert.
the class FolderOpenerDialog method getNumber.
public int getNumber(Object field) {
TextField tf = (TextField) field;
String theText = tf.getText();
Double d;
try {
d = new Double(theText);
} catch (NumberFormatException e) {
d = null;
}
if (d != null)
return (int) d.doubleValue();
else
return 0;
}
use of java.awt.TextField in project GDSC-SMLM by aherbert.
the class FolderOpenerDialog method setStackInfo.
void setStackInfo() {
int n = getNumber(numberField.elementAt(0));
int start = getNumber(numberField.elementAt(1));
int inc = getNumber(numberField.elementAt(2));
// Filter by name
TextField tf = (TextField) stringField.elementAt(0);
String filter = tf.getText();
tf = (TextField) stringField.elementAt(1);
String regex = tf.getText();
java.util.regex.Pattern p = null;
if (!regex.equals("")) {
filter = regex;
p = java.util.regex.Pattern.compile(filter);
}
if (!filter.equals("") && !filter.equals("*")) {
int n2 = 0;
for (int i = 0; i < list.length; i++) {
if (p != null && p.matcher(list[i]).matches())
n2++;
else if (list[i].indexOf(filter) >= 0)
n2++;
}
if (n2 < n)
n = n2;
}
// Now count using the input settings
if (start < 1 || start > n)
start = 1;
if (inc < 1)
inc = 1;
int count = 0;
for (int i = start - 1; i < list.length && count < n; i += inc, count++) ;
int frames = imp.getStackSize() * count;
((Label) theLabel).setText(String.format("%d image%s (%d frame%s)", count, (count == 1) ? "" : "s", frames, (frames == 1) ? "" : "s"));
}
use of java.awt.TextField in project GDSC-SMLM by aherbert.
the class BenchmarkSpotFit method showDialog.
@SuppressWarnings("unchecked")
private boolean showDialog() {
GenericDialog gd = new GenericDialog(TITLE);
gd.addHelp(About.HELP_URL);
gd.addMessage(String.format("Fit candidate spots in the benchmark image created by " + CreateData.TITLE + " plugin\nand identified by the " + BenchmarkSpotFilter.TITLE + " plugin.\nPSF width = %s nm (Square pixel adjustment = %s nm)\n \nConfigure the fitting:", Utils.rounded(simulationParameters.s), Utils.rounded(getSa())));
gd.addSlider("Fraction_positives", 50, 100, fractionPositives);
gd.addSlider("Fraction_negatives_after_positives", 0, 100, fractionNegativesAfterAllPositives);
gd.addSlider("Min_negatives_after_positives", 0, 10, negativesAfterAllPositives);
gd.addSlider("Match_distance", 0.5, 3.5, distance);
gd.addSlider("Lower_distance", 0, 3.5, lowerDistance);
gd.addSlider("Match_signal", 0, 3.5, signalFactor);
gd.addSlider("Lower_signal", 0, 3.5, lowerSignalFactor);
// Collect options for fitting
final double sa = getSa();
gd.addNumericField("Initial_StdDev", Maths.round(sa / simulationParameters.a), 3);
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.addMessage("Multi-path filter (used to pick optimum results during fitting)");
// Allow loading the best filter fot these results
boolean benchmarkSettingsCheckbox = fitResultsId == BenchmarkFilterAnalysis.lastId;
// This should always be an opt-in decision. Otherwise the user cannot use the previous settings
useBenchmarkSettings = false;
if (benchmarkSettingsCheckbox)
gd.addCheckbox("Benchmark_settings", useBenchmarkSettings);
gd.addTextAreas(XmlUtils.convertQuotes(multiFilter.toXML()), null, 6, 60);
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.addCheckbox("Compute_doublets", computeDoublets);
gd.addNumericField("Duplicate_distance", fitConfig.getDuplicateDistance(), 2);
gd.addCheckbox("Show_score_histograms", showFilterScoreHistograms);
gd.addCheckbox("Show_correlation", showCorrelation);
gd.addCheckbox("Plot_rank_by_intensity", rankByIntensity);
gd.addCheckbox("Save_filter_range", saveFilterRange);
if (extraOptions) {
}
// Add a mouse listener to the config file field
if (benchmarkSettingsCheckbox && Utils.isShowGenericDialog()) {
Vector<TextField> numerics = (Vector<TextField>) gd.getNumericFields();
Vector<Checkbox> checkboxes = (Vector<Checkbox>) gd.getCheckboxes();
taFilterXml = gd.getTextArea1();
Checkbox b = checkboxes.get(0);
b.addItemListener(this);
textFailLimit = numerics.get(9);
cbIncludeNeighbours = checkboxes.get(1);
textNeighbourHeight = numerics.get(10);
cbComputeDoublets = checkboxes.get(2);
if (useBenchmarkSettings) {
FitConfiguration tmpFitConfig = new FitConfiguration();
FitEngineConfiguration tmp = new FitEngineConfiguration(tmpFitConfig);
// Collect the residuals threshold
tmpFitConfig.setComputeResiduals(true);
if (BenchmarkFilterAnalysis.updateConfiguration(tmp, false)) {
textFailLimit.setText("" + tmp.getFailuresLimit());
cbIncludeNeighbours.setState(tmp.isIncludeNeighbours());
textNeighbourHeight.setText(Utils.rounded(tmp.getNeighbourHeightThreshold()));
cbComputeDoublets.setState(tmp.getResidualsThreshold() < 1);
final DirectFilter primaryFilter = tmpFitConfig.getSmartFilter();
final double residualsThreshold = tmp.getResidualsThreshold();
taFilterXml.setText(new MultiPathFilter(primaryFilter, minimalFilter, residualsThreshold).toXML());
}
}
}
gd.showDialog();
if (gd.wasCanceled())
return false;
fractionPositives = Math.abs(gd.getNextNumber());
fractionNegativesAfterAllPositives = Math.abs(gd.getNextNumber());
negativesAfterAllPositives = (int) Math.abs(gd.getNextNumber());
distance = Math.abs(gd.getNextNumber());
lowerDistance = Math.abs(gd.getNextNumber());
signalFactor = Math.abs(gd.getNextNumber());
lowerSignalFactor = Math.abs(gd.getNextNumber());
fitConfig.setInitialPeakStdDev(gd.getNextNumber());
config.setFitting(gd.getNextNumber());
fitConfig.setFitSolver(gd.getNextChoiceIndex());
fitConfig.setFitFunction(gd.getNextChoiceIndex());
boolean myUseBenchmarkSettings = false;
if (benchmarkSettingsCheckbox)
//useBenchmarkSettings =
myUseBenchmarkSettings = gd.getNextBoolean();
// Read dialog settings
String xml = gd.getNextText();
int failLimit = (int) gd.getNextNumber();
boolean includeNeighbours = gd.getNextBoolean();
double neighbourHeightThreshold = gd.getNextNumber();
boolean myComputeDoublets = gd.getNextBoolean();
double myDuplicateDistance = gd.getNextNumber();
MultiPathFilter myMultiFilter = null;
if (myUseBenchmarkSettings && !Utils.isShowGenericDialog()) {
// Only copy the benchmark settings if not interactive
FitConfiguration tmpFitConfig = new FitConfiguration();
FitEngineConfiguration tmp = new FitEngineConfiguration(tmpFitConfig);
// Collect the residuals threshold
tmpFitConfig.setComputeResiduals(true);
if (BenchmarkFilterAnalysis.updateConfiguration(tmp, false)) {
config.setFailuresLimit(tmp.getFailuresLimit());
config.setIncludeNeighbours(tmp.isIncludeNeighbours());
config.setNeighbourHeightThreshold(tmp.getNeighbourHeightThreshold());
computeDoublets = (tmp.getResidualsThreshold() < 1);
fitConfig.setDuplicateDistance(tmpFitConfig.getDuplicateDistance());
final DirectFilter primaryFilter = tmpFitConfig.getSmartFilter();
final double residualsThreshold = tmp.getResidualsThreshold();
myMultiFilter = new MultiPathFilter(primaryFilter, minimalFilter, residualsThreshold);
}
} else {
myMultiFilter = MultiPathFilter.fromXML(xml);
config.setFailuresLimit(failLimit);
config.setIncludeNeighbours(includeNeighbours);
config.setNeighbourHeightThreshold(neighbourHeightThreshold);
computeDoublets = myComputeDoublets;
fitConfig.setDuplicateDistance(myDuplicateDistance);
}
if (myMultiFilter == null) {
gd = new GenericDialog(TITLE);
gd.addMessage("The multi-path filter was invalid.\n \nContinue with a default filter?");
gd.enableYesNoCancel();
gd.hideCancelButton();
gd.showDialog();
if (!gd.wasOKed())
return false;
} else {
multiFilter = myMultiFilter;
}
if (computeDoublets) {
//config.setComputeResiduals(true);
config.setResidualsThreshold(0);
fitConfig.setComputeResiduals(true);
} else {
config.setResidualsThreshold(1);
fitConfig.setComputeResiduals(false);
}
showFilterScoreHistograms = gd.getNextBoolean();
showCorrelation = gd.getNextBoolean();
rankByIntensity = gd.getNextBoolean();
saveFilterRange = gd.getNextBoolean();
// Avoid stupidness, i.e. things that move outside the fit window and are bad widths
// TODO - Fix this for simple or smart filter...
fitConfig.setDisableSimpleFilter(false);
// Realistically we cannot fit lower than this
fitConfig.setMinPhotons(15);
// Disable shift as candidates may be re-mapped to alternative candidates so the initial position is wrong.
fitConfig.setCoordinateShiftFactor(0);
fitConfig.setMinWidthFactor(1.0 / 5);
fitConfig.setWidthFactor(5);
// Disable the direct filter
fitConfig.setDirectFilter(null);
if (extraOptions) {
}
if (gd.invalidNumber())
return false;
if (lowerDistance > distance)
lowerDistance = distance;
if (lowerSignalFactor > signalFactor)
lowerSignalFactor = signalFactor;
// Distances relative to sa (not s) as this is the same as the BenchmarkSpotFilter plugin
distanceInPixels = distance * sa / simulationParameters.a;
lowerDistanceInPixels = lowerDistance * sa / simulationParameters.a;
GlobalSettings settings = new GlobalSettings();
settings.setFitEngineConfiguration(config);
settings.setCalibration(cal);
// Copy simulation defaults if a new simulation
if (lastId != simulationParameters.id) {
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);
// This is needed to configure the fit solver
fitConfig.setNmPerPixel(Maths.round(cal.getNmPerPixel()));
fitConfig.setGain(Maths.round(cal.getGain()));
fitConfig.setBias(Maths.round(cal.getBias()));
fitConfig.setReadNoise(Maths.round(cal.getReadNoise()));
fitConfig.setAmplification(Maths.round(cal.getAmplification()));
fitConfig.setEmCCD(cal.isEmCCD());
}
if (!PeakFit.configureFitSolver(settings, null, extraOptions))
return false;
return true;
}
Aggregations