use of java.awt.Label in project GDSC-SMLM by aherbert.
the class ResultsManager method showDialog.
private boolean showDialog() {
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.addHelp(HelpUrls.getUrl("results-manager"));
settings = Settings.load();
resultsSettings = SettingsManager.readResultsSettings(0).toBuilder();
gd.addMessage("Read the Peak Results and output to a new format");
gd.addMessage("Select the Peak Results");
addInput(gd, INPUT_NAME, settings.inputOption, new FilenameLoadOption[] { new FilenameLoadOption(settings.inputFilename) }, InputSource.MEMORY, InputSource.FILE);
final Choice inputChoice = gd.getLastChoice();
addTableResultsOptions(gd, resultsSettings, FLAG_TABLE_FORMAT);
addImageResultsOptions(gd, resultsSettings);
addFileResultsOptions(gd, resultsSettings, 0);
addInMemoryResultsOptions(gd, resultsSettings);
final Label messageLabel = (Label) gd.getMessage();
final Checkbox saveCheckbox = gd.getLastCheckbox();
// Hide the in-memory settings if the input is not a file
if (ImageJUtils.isShowGenericDialog()) {
final Label saveLabel = gd.getLastLabel();
final ItemListener listener = event -> {
final boolean enable = INPUT_FILE.equals(inputChoice.getSelectedItem());
if (enable != messageLabel.isVisible()) {
messageLabel.setVisible(enable);
saveCheckbox.setVisible(enable);
saveLabel.setVisible(enable);
gd.pack();
}
};
// Run once to set up
listener.itemStateChanged(null);
inputChoice.addItemListener(listener);
}
gd.showDialog();
if (gd.wasCanceled()) {
return false;
}
settings.inputOption = ResultsManager.getInputSource(gd);
settings.inputFilename = gd.getNextString();
resultsSettings.getResultsTableSettingsBuilder().setResultsTableFormatValue(gd.getNextChoiceIndex());
resultsSettings.getResultsImageSettingsBuilder().setImageTypeValue(gd.getNextChoiceIndex());
resultsSettings.getResultsFileSettingsBuilder().setFileFormatValue(gd.getNextChoiceIndex());
resultsSettings.getResultsFileSettingsBuilder().setResultsFilename(gd.getNextString());
resultsSettings.getResultsInMemorySettingsBuilder().setInMemory(gd.getNextBoolean());
gd.collectOptions();
// Check arguments
try {
final ResultsImageSettings.Builder imageSettings = resultsSettings.getResultsImageSettingsBuilder();
if (imageSettings.getImageType() == ResultsImageType.DRAW_INTENSITY_AVERAGE_PRECISION || imageSettings.getImageType() == ResultsImageType.DRAW_LOCALISATIONS_AVERAGE_PRECISION) {
ParameterUtils.isAboveZero("Image precision", imageSettings.getAveragePrecision());
}
ParameterUtils.isAboveZero("Image scale", imageSettings.getScale());
if (extraOptions) {
ParameterUtils.isPositive("Image rolling window", imageSettings.getRollingWindowSize());
}
} catch (final IllegalArgumentException ex) {
IJ.error(TITLE, ex.getMessage());
return false;
}
settings.save();
SettingsManager.writeSettings(resultsSettings.build());
return true;
}
use of java.awt.Label in project GDSC-SMLM by aherbert.
the class PsfDrift method showHwhm.
private void showHwhm() {
// Build a list of suitable images
final List<String> titles = createImageList(false);
if (titles.isEmpty()) {
IJ.error(TITLE, "No suitable PSF images");
return;
}
final GenericDialog gd = new GenericDialog(TITLE);
gd.addMessage("Approximate the volume of the PSF as a Gaussian and\n" + "compute the equivalent Gaussian width.");
settings = Settings.load();
gd.addChoice("PSF", titles.toArray(new String[0]), settings.title);
gd.addCheckbox("Use_offset", settings.useOffset);
gd.addSlider("Smoothing", 0, 0.5, settings.smoothing);
gd.addHelp(HelpUrls.getUrl("psf-hwhm"));
gd.showDialog();
if (gd.wasCanceled()) {
return;
}
settings.title = gd.getNextChoice();
settings.useOffset = gd.getNextBoolean();
settings.smoothing = gd.getNextNumber();
settings.save();
imp = WindowManager.getImage(settings.title);
if (imp == null) {
IJ.error(TITLE, "No PSF image for image: " + settings.title);
return;
}
psfSettings = getPsfSettings(imp);
if (psfSettings == null) {
IJ.error(TITLE, "No PSF settings for image: " + settings.title);
return;
}
final int size = imp.getStackSize();
final ImagePsfModel psf = createImagePsf(1, size, 1);
final double[] w0 = psf.getAllHwhm0();
final double[] w1 = psf.getAllHwhm1();
// Get current centre
final int centre = psfSettings.getCentreImage();
// Extract valid values (some can be NaN)
double[] sw0 = new double[w0.length];
double[] sw1 = new double[w1.length];
final TDoubleArrayList s0 = new TDoubleArrayList(w0.length);
final TDoubleArrayList s1 = new TDoubleArrayList(w0.length);
int c0 = 0;
int c1 = 0;
for (int i = 0; i < w0.length; i++) {
if (Double.isFinite(w0[i])) {
s0.add(i + 1);
sw0[c0++] = w0[i];
}
if (Double.isFinite(w1[i])) {
s1.add(i + 1);
sw1[c1++] = w1[i];
}
}
if (c0 == 0 && c1 == 0) {
IJ.error(TITLE, "No computed HWHM for image: " + settings.title);
return;
}
double[] slice0 = s0.toArray();
sw0 = Arrays.copyOf(sw0, c0);
double[] slice1 = s1.toArray();
sw1 = Arrays.copyOf(sw1, c1);
// Smooth
if (settings.smoothing > 0) {
final LoessInterpolator loess = new LoessInterpolator(settings.smoothing, 1);
sw0 = loess.smooth(slice0, sw0);
sw1 = loess.smooth(slice1, sw1);
}
final TDoubleArrayList minWx = new TDoubleArrayList();
final TDoubleArrayList minWy = new TDoubleArrayList();
for (int i = 0; i < w0.length; i++) {
double weight = 0;
if (Double.isFinite(w0[i])) {
if (Double.isFinite(w1[i])) {
weight = w0[i] * w1[i];
} else {
weight = w0[i] * w0[i];
}
} else if (Double.isFinite(w1[i])) {
weight = w1[i] * w1[i];
}
if (weight != 0) {
minWx.add(i + 1);
minWy.add(Math.sqrt(weight));
}
}
// Smooth the combined line
final double[] cx = minWx.toArray();
double[] cy = minWy.toArray();
if (settings.smoothing > 0) {
final LoessInterpolator loess = new LoessInterpolator(settings.smoothing, 1);
cy = loess.smooth(cx, cy);
}
final int newCentre = SimpleArrayUtils.findMinIndex(cy);
// Convert to FWHM
final double fwhm = psfSettings.getFwhm();
// Widths are in pixels
final String title = TITLE + " HWHM";
final Plot plot = new Plot(title, "Slice", "HWHM (px)");
double[] limits = MathUtils.limits(sw0);
limits = MathUtils.limits(limits, sw1);
final double maxY = limits[1] * 1.05;
plot.setLimits(1, size, 0, maxY);
plot.setColor(Color.red);
plot.addPoints(slice0, sw0, Plot.LINE);
plot.setColor(Color.blue);
plot.addPoints(slice1, sw1, Plot.LINE);
plot.setColor(Color.magenta);
plot.addPoints(cx, cy, Plot.LINE);
plot.setColor(Color.black);
plot.addLabel(0, 0, "X=red; Y=blue, Combined=Magenta");
final PlotWindow pw = ImageJUtils.display(title, plot);
// Show a non-blocking dialog to allow the centre to be updated ...
// Add a label and dynamically update when the centre is moved.
final NonBlockingExtendedGenericDialog gd2 = new NonBlockingExtendedGenericDialog(TITLE);
final double scale = psfSettings.getPixelSize();
// @formatter:off
ImageJUtils.addMessage(gd2, "Update the PSF information?\n \n" + "Current z-centre = %d, FHWM = %s px (%s nm)\n", centre, MathUtils.rounded(fwhm), MathUtils.rounded(fwhm * scale));
// @formatter:on
gd2.addSlider("z-centre", cx[0], cx[cx.length - 1], newCentre);
final TextField tf = gd2.getLastTextField();
gd2.addMessage("");
gd2.addAndGetButton("Reset", event -> tf.setText(Integer.toString(newCentre)));
final Label label = gd2.getLastLabel();
gd2.addCheckbox("Update_centre", settings.updateCentre);
gd2.addCheckbox("Update_HWHM", settings.updateHwhm);
gd2.enableYesNoCancel();
gd2.hideCancelButton();
final UpdateDialogListener dl = new UpdateDialogListener(cx, cy, maxY, newCentre, scale, pw, label);
gd2.addDialogListener(dl);
gd.addHelp(HelpUrls.getUrl("psf-hwhm"));
gd2.showDialog();
if (gd2.wasOKed() && (settings.updateCentre || settings.updateHwhm)) {
final ImagePSF.Builder b = psfSettings.toBuilder();
if (settings.updateCentre) {
b.setCentreImage(dl.centre);
}
if (settings.updateHwhm) {
b.setFwhm(dl.getFwhm());
}
imp.setProperty("Info", ImagePsfHelper.toString(b));
}
}
use of java.awt.Label in project GDSC-SMLM by aherbert.
the class PeakFit method addRelativeParameterOptions.
/**
* Adds the relative parameter options.
*
* @param gd the dialog
* @param rp the relative parameter
*/
static void addRelativeParameterOptions(final ExtendedGenericDialog gd, final RelativeParameterProvider rp) {
final String label = rp.getDialogName();
gd.addSlider(label, rp.getMin(), rp.getMax(), rp.getValue(), new OptionListener<Double>() {
@Override
public boolean collectOptions(Double value) {
// Nothing depends on the input double value so just collect the options
return collectOptions(false);
}
@Override
public boolean collectOptions() {
return collectOptions(true);
}
private boolean collectOptions(boolean silent) {
final ExtendedGenericDialog egd = new ExtendedGenericDialog(rp.name + " Options", null);
final boolean oldValue = rp.isAbsolute();
egd.addCheckbox(rp.getDialogName() + "_absolute", oldValue);
egd.setSilent(silent);
egd.showDialog(true, gd);
if (egd.wasCanceled()) {
return false;
}
final boolean newValue = egd.getNextBoolean();
rp.setAbsolute(newValue);
return oldValue != newValue;
}
});
// Add a label after the button.
// The button is added in a panel with a GridBagLayout.
final Panel p = gd.getLastPanel();
final GridBagConstraints pc = new GridBagConstraints();
pc.gridy = 0;
pc.gridx = 3;
pc.insets = new Insets(5, 5, 0, 0);
pc.anchor = GridBagConstraints.EAST;
final Label flagLabel = new Label();
updateFlag(flagLabel, rp.isAbsolute());
p.add(flagLabel, pc);
gd.addOptionCollectedListener(event -> {
if (label.equals(event.getLabel())) {
updateFlag(flagLabel, rp.isAbsolute());
}
});
}
use of java.awt.Label in project mzmine2 by mzmine.
the class FeatureOverviewWindow method addFeatureDataSummary.
private JPanel addFeatureDataSummary(PeakListRow row) {
JPanel featureDataSummary = new JPanel(new GridLayout(0, 1));
featureDataSummary.setBackground(Color.WHITE);
featureDataSummary.add(new Label("Feature: " + row.getID()));
if (row.getPreferredPeakIdentity() != null)
featureDataSummary.add(new Label("Identity: " + row.getPreferredPeakIdentity().getName()));
if (row.getComment() != null)
featureDataSummary.add(new Label("Comment: " + row.getComment()));
featureDataSummary.add(new Label("Raw File: " + rawFiles[0].getName()));
featureDataSummary.add(new Label("Intensity: " + MZmineCore.getConfiguration().getIntensityFormat().format(feature.getHeight())));
featureDataSummary.add(new Label("Area: " + MZmineCore.getConfiguration().getIntensityFormat().format(feature.getArea())));
featureDataSummary.add(new Label("Charge: " + feature.getCharge()));
featureDataSummary.add(new Label("m/z: " + MZmineCore.getConfiguration().getMZFormat().format(feature.getMZ())));
featureDataSummary.add(new Label("Retention time: " + MZmineCore.getConfiguration().getRTFormat().format(feature.getRT())));
featureDataSummary.add(new Label("Asymmetry factor " + MZmineCore.getConfiguration().getRTFormat().format(feature.getAsymmetryFactor())));
featureDataSummary.add(new Label("Tailing Factor factor " + MZmineCore.getConfiguration().getRTFormat().format(feature.getTailingFactor())));
featureDataSummary.add(new Label("Status: " + feature.getFeatureStatus()));
return featureDataSummary;
}
Aggregations