Login  Register

Re: Plugin with own context menu!?

Posted by Wayne Rasband on Sep 04, 2009; 9:41pm
URL: http://imagej.273.s1.nabble.com/Plugin-with-own-context-menu-tp3691307p3691308.html

 >Hi group,
 >
 >I would like to write a plugin that overrides or extends
 >the mouse context menu of it´s image(s) with own
 >operations to add some simple "dynamic functionality"
 >to the plugin.
 >(A regular Plugin or PluginFilter is more static, usually
 >after it´s run you need to rerun it on the original source
 >image if you want to get to the dialog to change any
 >parameters etc.)
 >
 >I have a basic idea how to achieve this via mouse
 >listeners etc. but I wonder if there is a simpler solution
 >that uses ImageJ built-in functionality.
 >
 >Has anybody already done something like that in his plugin?

You can write a simple macro to customize the contextual menu that
appears when you right click on an image. There is an example at

     http://rsb.info.nih.gov/ij/macros/CustomPopupMenu.txt

Look at the the installPopupMenu() method in ImageJ's MacroInstaller
class at

     http://rsb.info.nih.gov/ij/source/ij/plugin/MacroInstaller.java

to see how to do this in a plugin.

It would be better and easier, however, to simply add a "Preview"
button to your plugin's dialog box. There is a plugin at

     http://rsb.info.nih.gov/ij/plugins/erode-demo.html

that demonstrates how to do this. It also demonstrates how to add a
"Help" button to a dialog box.

-wayne