Commit 517bdefe authored by Johannes Schindelin's avatar Johannes Schindelin

Add a main() method for convenient debugging

Signed-off-by: 's avatarJohannes Schindelin <johannes.schindelin@gmx.de>
parent 9593a66b
...@@ -22,5 +22,10 @@ directory, run _Help&gt;Refresh Menus_ and the plugin will be available in ...@@ -22,5 +22,10 @@ directory, run _Help&gt;Refresh Menus_ and the plugin will be available in
_Process&gt;Process Pixels_ (this can be changed by editing _Process&gt;Process Pixels_ (this can be changed by editing
_src/main/resources/plugins.config_). _src/main/resources/plugins.config_).
Developing plugins in an IDE is convenient, especially for debugging. To
that end, the plugin contains a _main()_ method which sets the _plugins.dir_
system property (so that the plugin is added to the Plugins menu), starts
ImageJ, loads an image and runs the plugin.
Since this project is intended as a starting point for your own Since this project is intended as a starting point for your own
developments, it is in the public domain. developments, it is in the public domain.
import ij.IJ; import ij.IJ;
import ij.ImageJ;
import ij.ImagePlus; import ij.ImagePlus;
import ij.gui.GenericDialog; import ij.gui.GenericDialog;
import ij.plugin.filter.PlugInFilter; import ij.plugin.filter.PlugInFilter;
...@@ -154,4 +155,30 @@ public class Process_Pixels implements PlugInFilter { ...@@ -154,4 +155,30 @@ public class Process_Pixels implements PlugInFilter {
"a template for processing each pixel of an image" "a template for processing each pixel of an image"
); );
} }
/**
* Main method for debugging.
*
* For debugging, it is convenient to have a method that starts ImageJ, loads an
* image and calls the plugin, e.g. after setting breakpoints.
*
* @param args unused
*/
public static void main(String[] args) {
// set the plugins.dir property to make the plugin appear in the Plugins menu
Class<?> clazz = Process_Pixels.class;
String url = clazz.getResource("/" + clazz.getName().replace('.', '/') + ".class").toString();
String pluginsDir = url.substring(5, url.length() - clazz.getName().length() - 6);
System.setProperty("plugins.dir", pluginsDir);
// start ImageJ
new ImageJ();
// open the Clown sample
ImagePlus image = IJ.openImage("http://imagej.net/images/clown.jpg");
image.show();
// run the plugin
IJ.runPlugIn(clazz.getName(), "");
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment