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

Add a main() method for convenient debugging

parent 9593a66b
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -22,5 +22,10 @@ directory, run _Help>Refresh Menus_ and the plugin will be available in
_Process>Process Pixels_ (this can be changed by editing
_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
developments, it is in the public domain.
+27 −0
Original line number Diff line number Diff line
import ij.IJ;
import ij.ImageJ;
import ij.ImagePlus;
import ij.gui.GenericDialog;
import ij.plugin.filter.PlugInFilter;
@@ -154,4 +155,30 @@ public class Process_Pixels implements PlugInFilter {
			"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(), "");
	}
}