Skip to content

Instantly share code, notes, and snippets.

@dscho
Created May 8, 2015 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dscho/396135ce3270d488da79 to your computer and use it in GitHub Desktop.
Save dscho/396135ce3270d488da79 to your computer and use it in GitHub Desktop.
A simple test for the claim that `Plugin`s with `DialogListener`s are not macro-recordable.
import ij.IJ;
import ij.gui.DialogListener;
import ij.gui.GenericDialog;
import ij.plugin.PlugIn;
import java.awt.AWTEvent;
/**
* A simple test for the claim that {@link Plugin}s with a
* {@link DialogListener} are not macro-recordable.
*/
public class Recorder_Likes_DialogListeners implements PlugIn {
/**
* Performs the plugin's functionality.
*
* @param arg ignored
*/
public void run(final String arg) {
final GenericDialog gd = new GenericDialog("Let's test this");
gd.addStringField("Please enter some text", "<change this>");
/**
* Listens for changes in the dialog values.
* <p>
* Note: any dialog value that is *not* enquired in this
* listener will *not* be recorded, either. This is most likely
* a bug introduced into
* <a href="https://github.com/imagej/ImageJA/commit/a534b8f#diff-3cda9bab45abece23447b8321c867f67R841">version
* 1.38u of June 15th 2007</a>: The intention was probably to
* set <code>recorderOn = false;</code> <it>before</it> running
* the dialog listener, and setting it to <code>true</code>
* afterwards. Being in effect for almost 8 years as of time of
* writing, it is likely that users now rely on that behavior,
* though, so it should not be changed now.
*/
final DialogListener listener = new DialogListener() {
public boolean dialogItemChanged(final GenericDialog gd, final AWTEvent e) {
IJ.log("dialog item changed: " + gd.getNextString() + " (event: " + e + ")");
return true;
}
};
gd.addDialogListener(listener);
gd.showDialog();
if (gd.wasCanceled())
return;
IJ.log("The value is: " + gd.getNextString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment