Skip to content

Commit

Permalink
Fix a bug with GenericDialog value syncing
Browse files Browse the repository at this point in the history
This fixes Fiji bug #1002:
    http://fiji.sc/bugzilla/show_bug.cgi?id=1002

The problem occurred only with plugins that relied on a DialogListener
to actually keep the values in sync -- one such plugin is GaussianBlur.
  • Loading branch information
ctrueden committed Feb 9, 2015
1 parent bc18f31 commit 4fc6022
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main/java/net/imagej/patcher/HeadlessGenericDialog.java
Expand Up @@ -67,6 +67,8 @@ public class HeadlessGenericDialog {
protected boolean invalidNumber;
protected String errorMessage;

protected DialogListener listener;

public HeadlessGenericDialog() {
if (Macro.getOptions() == null)
throw new RuntimeException("Cannot instantiate headless dialog except in macro mode");
Expand Down Expand Up @@ -187,6 +189,14 @@ public void showDialog() {
checkboxIndex = 0;
choiceIndex = 0;
textAreaIndex = 0;

// NB: ImageJ 1.x has logic to call the first DialogListener at least once,
// in case the plugin _only_ updates its values via the dialogItemChanged
// method. See the bottom of the ij.gui.GenericDialog#showDialog() method.
if (listener != null) {
// NB: Thanks to Javassist, this class _will_ be a GenericDialog object.
listener.dialogItemChanged((ij.gui.GenericDialog) (Object) this, null);
}
}

public boolean wasCanceled() {
Expand All @@ -198,7 +208,11 @@ public boolean wasOKed() {
}

public void dispose() {}
public void addDialogListener(DialogListener dl) {}
public void addDialogListener(DialogListener dl) {
if (listener != null) return;
// NB: Save the first DialogListener, for access during showDialog().
listener = dl;
}
public void addHelp(String url) {}
public void addMessage(String text) {}
public void addMessage(String text, Font font) {}
Expand Down

0 comments on commit 4fc6022

Please sign in to comment.