ImageJ Applet and Macros

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

ImageJ Applet and Macros

StrongSteve
Hi Everybody!

I am currently trying to integrate existing macros into an ImageJ Applet. Unfortunally with little (none) success! ;)

Basically I am trying to integrate this macro Window Level Macro into the applet version of ImageJ - ImageJA.

I put the sources into the ImageJ Sources, generated a new jar file, signed it. Wrote a simple HTML-File, put an StartupMacros.txt file into the same directory and started my webbrowser. Altough I can see the button for the macro in the toolbar and I can click it without an error, nothing happens. No functionality is executed.

I have already tried monitoring the macro code with some simple logging statements (good old system.out.println(...)) but nothing is being writen to the Java Console in the browser so I guess the click on the new macro button does not execute any functionality, but it does not throw an exception either.

Any ideas why this is so? I am really stuck here! ;(
 
Thanks in Advance for your time!

Greetings
Stefan
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ Applet and Macros

Sami Badawi-2
Hi Stefan,

When you are debugging a Java applet you might want allow it to read from
local disk. Here is a description of how to do that:

http://geosim.cs.vt.edu/Java/MigModel/help/Policies.html

When you have the applet working you can disable that again.

-Sami Badawi
http://www.shapelogic.org
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ Applet and Macros

StrongSteve
Thanks for your answer. I am not debugging the Applet. I just inserted some print-statements to see workflow at execution time. The problem seems to be, that the macro is not loaded or executed at all.

Any ideas?

Greetings
Stefan

Sami Badawi-2 wrote
Hi Stefan,

When you are debugging a Java applet you might want allow it to read from
local disk. Here is a description of how to do that:

http://geosim.cs.vt.edu/Java/MigModel/help/Policies.html

When you have the applet working you can disable that again.

-Sami Badawi
http://www.shapelogic.org
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ Applet and Macros

Sami Badawi-2
In reply to this post by StrongSteve
A few years back I did a lot of Java applet work. I found that if I ran into
a problem while developing it was better to turn off all the applet
permission restrictions. Since a lot of things can go wrong due to them.
When I had it working I would turn permission restrictions on again.
In that way you can separate normal bugs from permission problems.

-Sami Badawi
http://www.shapelogic.org
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ Applet and Macros

Sami Badawi-2
In reply to this post by StrongSteve
Hi Stefan,

Sorry I did not follow the link to Window Level Macro page.
It turns out that you also need to have a jar file loaded: windowLevelMacro.jar
You need to set the path for that in the html applet tag

Another thing that I found very useful when doing applet development was to
actually debug the applet, I got that to work from both JBuilder and
Eclipse. It is very easy to set up here is a link:

http://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/debugger.html

-Sami Badawi
http://www.shapelogic.org
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ Applet and Macros

StrongSteve
Thanks again, but now I have found the root the problem. Unfortunately i do not know an answer yet. any ideas?

Till now I have developed a simple Java Applet (mostly with ImageJ files) that is being packed in a signed jar-file and has the following structure:

{code}
-edu
³   -ucla
³       -alger
³           -wlmacro
-ij
³   -gui
³   -io
³   -macro
³   -measure
³   -plugin
³   ³   -filter
³   ³   -frame
³   -process
³   -text
³   -util
-macros
-META-INF
-plugins
{code}

Now I have a very tricky problem, I can not solve. Inside the Funtions.class located in the package ij.macro is this statement:

{code}
ClassLoader.getSystemClassLoader().loadClass("edu.ucla.alger.wlmacro.WindowLevelMacro");
{code}

Whenever I execute this statement the follwing stacktrace appears in the Java Console (from IE).

{code}
java.lang.ClassNotFoundException: edu.ucla.alger.wlmacro.WindowLevelMacro
                at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at ij.macro.Functions.call(Functions.java:3090)
        at ij.macro.Functions.getStringFunction(Functions.java:233)
        at ij.macro.Interpreter.getStringTerm(Interpreter.java:1134)
        at ij.macro.Interpreter.getString(Interpreter.java:1109)
        at ij.macro.Interpreter.doStatement(Interpreter.java:263)
        at ij.macro.Interpreter.doBlock(Interpreter.java:540)
        at ij.macro.Interpreter.runMacro(Interpreter.java:123)
        at ij.macro.MacroRunner.run(MacroRunner.java:112)
        at java.lang.Thread.run(Unknown Source)
{code}

Nevertheless the statement below executes without any problems. (I just wanted to try if class loading is possible from applets in general.)

{code}
ClassLoader.getSystemClassLoader().loadClass("java.net.URL");
{code}

So I think the problem is, that the class loader searches in a wrong classpath. It does find classes from the Java distribution but not from - or within - my applet jar-file.

How can I solve this problem?

Thanks a lot in advance!

Greetings
Stefan

Sami Badawi-2 wrote
Hi Stefan,

Sorry I did not follow the link to Window Level Macro page.
It turns out that you also need to have a jar file loaded: windowLevelMacro.jar
You need to set the path for that in the html applet tag

Another thing that I found very useful when doing applet development was to
actually debug the applet, I got that to work from both JBuilder and
Eclipse. It is very easy to set up here is a link:

http://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/debugger.html

-Sami Badawi
http://www.shapelogic.org
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ Applet and Macros

Sami Badawi-2
In reply to this post by StrongSteve
In order for the applet to see all your jar files you have to all them all
to the applet html tag:

    <applet code=Animator.class
      archive="classes.jar ,  images.jar ,  sounds.jar"
      width=460 height=160>
      <param name=foo value="bar">
    </applet>

See:
http://java.sun.com/j2se/1.5.0/docs/guide/jar/jarGuide.html

In order for ImageJ to see plugin jar you normally have to have them in the
plugin directory. I am not sure how you get around this.
Maybe you can unpack the windowLevelMacro.jar and put the code in with you
own code. Otherwise you would also have to sign both of them.

-Sami Badawi
http://www.shapelogic.org
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ Applet and Macros

StrongSteve
I have unpacked and put them in one signed jar file as you can see from the package structure. But the problem is, that the class loader always throws an exception when I try to class-load a class from inside this jar-file and i do not know why.

Greetings
Stefan

Sami Badawi-2 wrote
In order for the applet to see all your jar files you have to all them all
to the applet html tag:

    <applet code=Animator.class
      archive="classes.jar ,  images.jar ,  sounds.jar"
      width=460 height=160>
     
    </applet>

See:
http://java.sun.com/j2se/1.5.0/docs/guide/jar/jarGuide.html

In order for ImageJ to see plugin jar you normally have to have them in the
plugin directory. I am not sure how you get around this.
Maybe you can unpack the windowLevelMacro.jar and put the code in with you
own code. Otherwise you would also have to sign both of them.

-Sami Badawi
http://www.shapelogic.org