Created
May 8, 2015 08:01
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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