Hi All,
Please bare with me for a super newbie questio. I'm trying to transition from macro writing to propper plugins, and I've started using FIJI's script editor. I'm writing in Java as opposed to javascript or some of the other options. Here is my question. When I make a change to my code, save the changes and "compile and run", is it normal that the compiler does not taken the changes in the code into account. For example in the fallowing code, if I change the starting value of "width" from 512 to say 510, then save>compile and run, the change in the value is not reflected in the dialog box. It seems like I have to restart Fiji for the change to be recognized. I'm sure this isn't normal behaviour, so what am I missing? Any help would be greatly appreciated. Damon public class Generic_Dialog_Example implements PlugIn { static String title="Example"; static int width=512,height=512; public void run(String arg) { GenericDialog gd = new GenericDialog("New Image"); gd.addStringField("Title: ", title); gd.addNumericField("Width: ", width, 0); gd.addNumericField("Height: ", height, 0); gd.showDialog(); if (gd.wasCanceled()) return; title = gd.getNextString(); width = (int)gd.getNextNumber(); height = (int)gd.getNextNumber(); IJ.run("New...", "name="+title+" type='8-bit Unsigned' width="+width+" height="+height); } } |
Hi,
On Thu, 24 Mar 2011, Damon Poburko wrote: > Please bare [sic] with me for a super newbie questio. I'm trying to > transition from macro writing to propper plugins, and I've started using > FIJI's script editor. I'm writing in Java as opposed to javascript or > some of the other options. > > Here is my question. When I make a change to my code, save the changes > and "compile and run", is it normal that the compiler does not taken the > changes in the code into account. For example in the fallowing code, if > I change the starting value of "width" from 512 to say 510, then > save>compile and run, the change in the value is not reflected in the > dialog box. It seems like I have to restart Fiji for the change to be > recognized. I'm sure this isn't normal behaviour, so what am I missing? My guess is that your source is somewhere in Fiji.app/plugins/ and that might confuse the plugin class loader. Even if that is not the case, this smells of a class loader issue. You see, once a class loader has loaded a class, it cannot get rid of it. Even if there is a newer version available. ImageJ's trick to work around this is to have a class loader specifically for plugins (which we reuse in Fiji to be able to load also libraries from Fiji.app/jars/, and in the future maybe also plugins from other places), and to throw that class loader away when the user clicks Help>Refresh Menus. The same mechanism is used when compiling and running a Java class from within the Script Editor. And here's the rub: if the class was not actually loaded by that throw-away class loader, but by another class loader (e.g. when the Java class path includes Fiji.app/plugins/ or whatever path your file was saved to), then throwing the class loader away does not help. The easiest way to verify this is most likely to open a new tab in the script editor (File>New), select Language>Beanshell, and execute something like this: print(ij.IJ.getClassLoader().loadClass("MyPlugin").getClassLoader()); Note that even if the plugin class loader is asked to load the class, it might still be the system class loader which actually loaded the class... Please let me know how things go (I prefer answers to my mails to be Cc:ed to the mailing list -- but not only to the list, lest I miss the answer to my very own mail in the craziness that is my inbox!). Ciao, Johannes |
Free forum by Nabble | Edit this page |