Javascript in Fiji does not work anymore

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Javascript in Fiji does not work anymore

lechristophe
Hi,

With the current up-to-date Fiji, my javascripts do not run anymore. When I
try to launch them directly from the plugins menu, nothing happens. When I
open them in the Fiji editor and run them, I get reference errors for
basically every command :

IJ.log("hello");
fails

var gd = new GenericDialog("test");
fails too.

Here is the error I get with IJ.log:

Started ProFeatFit_3.js at Thu Jun 19 14:29:33 CEST 2014
javax.script.ScriptException:
sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "IJ" n'est
pas défini
(/Users/christo/Travail/Labo/Processing/Fiji_current/Fiji.app/plugins/added
WIP/ProFeatFit_3.js#5) in
/Users/christo/Travail/Labo/Processing/Fiji_current/Fiji.app/plugins/added
WIP/ProFeatFit_3.js at line number 5
 at
com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:156)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:232)
 at org.scijava.script.ScriptModule.run(ScriptModule.java:172)
at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
 at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
 at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
 at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
 at java.lang.Thread.run(Thread.java:695)

Thanks for your help,



Christophe

--
Christophe Leterrier
Chercheur
Equipe Architecture des Domaines Axonaux
CRN2M CNRS UMR 7286 - Aix Marseille Université

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Javascript in Fiji does not work anymore

Jan Eglinger
Hi Christophe,

On 19.06.2014, 2:33 PM, Christophe Leterrier wrote:

> With the current up-to-date Fiji, my javascripts do not run anymore. When I
> try to launch them directly from the plugins menu, nothing happens. When I
> open them in the Fiji editor and run them, I get reference errors for
> basically every command :
>
> IJ.log("hello");
> fails
>
> var gd = new GenericDialog("test");
> fails too.
>
> Here is the error I get with IJ.log:
>
> Started ProFeatFit_3.js at Thu Jun 19 14:29:33 CEST 2014
> javax.script.ScriptException:
> sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "IJ" n'est
> pas défini

You get these errors because the classes of the ij.* package are not
imported by default any more by the script editor.

I just discovered that there is an option to switch the auto-imports
back on: in Fiji's script editor, go to:

*Edit > Auto-import (deprecated)*


In any case, it might be a good idea to not trust the auto-imports but
import the classes you need explicitly:

     importClass(Packages.ij.IJ);
     importClass(Packages.ij.gui.GenericDialog);

Hope that helps,
Jan

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Javascript in Fiji does not work anymore

dscho
In reply to this post by lechristophe
Hi Christophe,

On Thu, 19 Jun 2014, Christophe Leterrier wrote:

> With the current up-to-date Fiji, my javascripts do not run anymore.
> When I try to launch them directly from the plugins menu, nothing
> happens. When I open them in the Fiji editor and run them, I get
> reference errors for basically every command :
>
> IJ.log("hello");
> fails
>
> var gd = new GenericDialog("test");
> fails too.

You need to call

importClass(Packages.ij.IJ);
importClass(Packages.ij.gui.GenericDialog);

before using the classes. I was unfortunately not aware of this behavior
in Fiji's Refresh_Javascripts plugin (which used to install the scripts
into the menu structure): apparently it auto-imported ImageJ 1.x' classes.

I was only aware that the script editor used to do that, therefore the
ImageJ2 script editor (which is now used in Fiji) supports auto-imports as
a deprecated feature.

Let's be very clear about this: auto-imports, as well as wildcard imports
are wrong. They are sloppy, and they *will* come back to bite you. What if
*some* plugin implemented an "IJ" class in the default package, i.e.
without a "package ..." statement? All of a sudden, you would be in a
royal mess of pain. I know, you would report it to the mailing list, and I
would fix it for you, but at some stage, I really have to question the use
of sloppy coding practices.

There is really no substitute for telling the computer *exactly* what to
do. Otherwise it will -- eventually, because computers are machines
designed to make your life as hard as possible -- break in the best of
funniest ways.

So: change your scripts to specify exactly which classes they want to use.
And then you're safer for all the future.

Ciao,
Johannes

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Javascript in Fiji does not work anymore

Jan Eglinger
In reply to this post by Jan Eglinger
Hi all,

On 19.06.2014, 4:22 PM, Jan Eglinger wrote:
> I just discovered that there is an option to switch the auto-imports
> back on: in Fiji's script editor, go to:
>
> *Edit > Auto-import (deprecated)*
>

For the record:
The auto-import was adopted from the Fiji script editor to the ImageJ
script editor in these two commits (including very informative commit
messages by Johannes Schindelin :):

https://github.com/imagej/imagej-ui-swing/commit/094a3ac5
https://github.com/imagej/imagej-ui-swing/commit/d48a482f

>
> In any case, it might be a good idea to not trust the auto-imports but
> import the classes you need explicitly:
>
>      importClass(Packages.ij.IJ);
>      importClass(Packages.ij.gui.GenericDialog);
>

Cheers,
Jan

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Javascript in Fiji does not work anymore

lechristophe
Dear Jan and Johannes,

Thanks for your explanations.
It must be noted that Edit>Auto-import does not work with Javascript in the
Fiji script editor.

I sequentially run and manually added the classes at each error stop, now I
have calls for all the ImageJ classes used in my script (a dozen). I should
say that as a non-developper, my Javascript knowledge is mostly based on
web tutorials such as http://fiji.sc/wiki/index.php/Javascript_Scripting
(which is out dated now, I'm not sure I understand the new system enough to
edit it), and in these tutorials most exemple scripts don't import default
ij classes.

Thanks again for the help,

Christophe



2014-06-19 16:49 GMT+02:00 Jan Eglinger <[hidden email]>:

> Hi all,
>
>
> On 19.06.2014, 4:22 PM, Jan Eglinger wrote:
>
>> I just discovered that there is an option to switch the auto-imports
>> back on: in Fiji's script editor, go to:
>>
>> *Edit > Auto-import (deprecated)*
>>
>>
> For the record:
> The auto-import was adopted from the Fiji script editor to the ImageJ
> script editor in these two commits (including very informative commit
> messages by Johannes Schindelin :):
>
> https://github.com/imagej/imagej-ui-swing/commit/094a3ac5
> https://github.com/imagej/imagej-ui-swing/commit/d48a482f
>
>
>
>> In any case, it might be a good idea to not trust the auto-imports but
>> import the classes you need explicitly:
>>
>>      importClass(Packages.ij.IJ);
>>      importClass(Packages.ij.gui.GenericDialog);
>>
>>
> Cheers,
> Jan
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Javascript in Fiji does not work anymore

lechristophe
Hi again,

There is a class I don't manage to find. What should I import to be able to
use load("path/to/my/ javascript.js"), the command that allows to load
other scripts from a script (as used in
http://fiji.sc/wiki/index.php/Javascript_Scripting)?

Thanks for you help,

Christophe


2014-06-19 21:23 GMT+02:00 Christophe Leterrier <
[hidden email]>:

> Dear Jan and Johannes,
>
> Thanks for your explanations.
> It must be noted that Edit>Auto-import does not work with Javascript in
> the Fiji script editor.
>
> I sequentially run and manually added the classes at each error stop, now
> I have calls for all the ImageJ classes used in my script (a dozen). I
> should say that as a non-developper, my Javascript knowledge is mostly
> based on web tutorials such as
> http://fiji.sc/wiki/index.php/Javascript_Scripting (which is out dated
> now, I'm not sure I understand the new system enough to edit it), and in
> these tutorials most exemple scripts don't import default ij classes.
>
> Thanks again for the help,
>
> Christophe
>
>
>
> 2014-06-19 16:49 GMT+02:00 Jan Eglinger <[hidden email]>:
>
> Hi all,
>>
>>
>> On 19.06.2014, 4:22 PM, Jan Eglinger wrote:
>>
>>> I just discovered that there is an option to switch the auto-imports
>>> back on: in Fiji's script editor, go to:
>>>
>>> *Edit > Auto-import (deprecated)*
>>>
>>>
>> For the record:
>> The auto-import was adopted from the Fiji script editor to the ImageJ
>> script editor in these two commits (including very informative commit
>> messages by Johannes Schindelin :):
>>
>> https://github.com/imagej/imagej-ui-swing/commit/094a3ac5
>> https://github.com/imagej/imagej-ui-swing/commit/d48a482f
>>
>>
>>
>>> In any case, it might be a good idea to not trust the auto-imports but
>>> import the classes you need explicitly:
>>>
>>>      importClass(Packages.ij.IJ);
>>>      importClass(Packages.ij.gui.GenericDialog);
>>>
>>>
>> Cheers,
>> Jan
>>
>
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Javascript in Fiji does not work anymore

dscho
Hi Christophe,

On Thu, 19 Jun 2014, Christophe Leterrier wrote:

> There is a class I don't manage to find. What should I import to be able to
> use load("path/to/my/ javascript.js"), the command that allows to load
> other scripts from a script (as used in
> http://fiji.sc/wiki/index.php/Javascript_Scripting)?

Please note that "load(path)" is not an officially supported Javascript
function.

Having said that, I just spent an hour to port it from Fiji's Javascript
interpreter, add a regression test, release, deploy and upload it. So
there you go, after Fiji update, you got it.

Enjoy,
Johannes

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Javascript in Fiji does not work anymore

lechristophe
Hi Johannes,

Thanks a lot for that, everything seem to works fine now.

Cheers,

Christophe


2014-06-20 3:22 GMT+02:00 Johannes Schindelin <[hidden email]>:

> Hi Christophe,
>
> On Thu, 19 Jun 2014, Christophe Leterrier wrote:
>
> > There is a class I don't manage to find. What should I import to be able
> to
> > use load("path/to/my/ javascript.js"), the command that allows to load
> > other scripts from a script (as used in
> > http://fiji.sc/wiki/index.php/Javascript_Scripting)?
>
> Please note that "load(path)" is not an officially supported Javascript
> function.
>
> Having said that, I just spent an hour to port it from Fiji's Javascript
> interpreter, add a regression test, release, deploy and upload it. So
> there you go, after Fiji update, you got it.
>
> Enjoy,
> Johannes
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html