Swing Java components in ImageJ plugin frames?

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

Swing Java components in ImageJ plugin frames?

Bill Mohler
Dear All:

I'm confused by what's "allowed" or doable in writing code for ImageJ plugins.

I am interested in adding some JSpinner components to my plugin
frame, to save space instead of using sliders and to allow text input
from the user as a shortcut.

I know that JSpinner is a Swing component, and I recall
hearing/reading that ImageJ was not designed to use Swing.  Does this
mean that the Swing libraries are not included in the bundled version
of Java that comes with ImageJ?  Or is this just a limitation on what
classes are used in the base code of ImageJ?...

Wait a minute...

Searching through the ImageJ website, I just realized that
javax.swing. libraries are used in a number if classes in the ImageJ
source!  So, is there actually no limit on using swing components?
Was there ever?  That would certainly make things much easier.

Hoping for a quick and certain answer.

Bill
Reply | Threaded
Open this post in threaded view
|

Re: Swing Java components in ImageJ plugin frames?

ctrueden
Hi Bill,

ImageJ uses predominantly AWT components (the old toolkit), though as you
say there are a small number of places where Swing (the new toolkit) is
used. The two toolkits can be mixed, but there are some gotchas:

  http://java.sun.com/products/jfc/tsc/articles/mixing/

You should be fine to use a JSpinner in your frame.

The only other reason not to mix the two toolkits is aesthetics, since they
can look quite different on different platforms. Swing supports a pluggable
look and feel, but any AWT components you use won't respect that setting, of
course.

-Curtis

On Mon, May 11, 2009 at 3:50 PM, Bill Mohler <[hidden email]>wrote:

> Dear All:
>
> I'm confused by what's "allowed" or doable in writing code for ImageJ
> plugins.
>
> I am interested in adding some JSpinner components to my plugin frame, to
> save space instead of using sliders and to allow text input from the user as
> a shortcut.
>
> I know that JSpinner is a Swing component, and I recall hearing/reading
> that ImageJ was not designed to use Swing.  Does this mean that the Swing
> libraries are not included in the bundled version of Java that comes with
> ImageJ?  Or is this just a limitation on what classes are used in the base
> code of ImageJ?...
>
> Wait a minute...
>
> Searching through the ImageJ website, I just realized that javax.swing.
> libraries are used in a number if classes in the ImageJ source!  So, is
> there actually no limit on using swing components? Was there ever?  That
> would certainly make things much easier.
>
> Hoping for a quick and certain answer.
>
> Bill
>
Reply | Threaded
Open this post in threaded view
|

Re: Swing Java components in ImageJ plugin frames?

Bill Mohler
Thanks, Curtis.  I'm a bit less confused now, and confident that I
can try what I want to try.

Bill

>Hi Bill,
>
>ImageJ uses predominantly AWT components (the old toolkit), though as you
>say there are a small number of places where Swing (the new toolkit) is
>used. The two toolkits can be mixed, but there are some gotchas:
>
>   http://java.sun.com/products/jfc/tsc/articles/mixing/
>
>You should be fine to use a JSpinner in your frame.
>
>The only other reason not to mix the two toolkits is aesthetics, since they
>can look quite different on different platforms. Swing supports a pluggable
>look and feel, but any AWT components you use won't respect that setting, of
>course.
>
>-Curtis
>
>On Mon, May 11, 2009 at 3:50 PM, Bill Mohler <[hidden email]>wrote:
>
>>  Dear All:
>>
>>  I'm confused by what's "allowed" or doable in writing code for ImageJ
>>  plugins.
>>
>>  I am interested in adding some JSpinner components to my plugin frame, to
>>  save space instead of using sliders and to allow text input from the user as
>>  a shortcut.
>>
>>  I know that JSpinner is a Swing component, and I recall hearing/reading
>>  that ImageJ was not designed to use Swing.  Does this mean that the Swing
>>  libraries are not included in the bundled version of Java that comes with
>>  ImageJ?  Or is this just a limitation on what classes are used in the base
>>  code of ImageJ?...
>>
>>  Wait a minute...
>>
>>  Searching through the ImageJ website, I just realized that javax.swing.
>>  libraries are used in a number if classes in the ImageJ source!  So, is
>>  there actually no limit on using swing components? Was there ever?  That
>>  would certainly make things much easier.
>>
>>  Hoping for a quick and certain answer.
>>
>>  Bill
>>
Reply | Threaded
Open this post in threaded view
|

Re: Swing Java components in ImageJ plugin frames?

dscho
In reply to this post by Bill Mohler
Hi,

On Mon, 11 May 2009, Bill Mohler wrote:

> I'm confused by what's "allowed" or doable in writing code for ImageJ
> plugins.

Anything.

> I am interested in adding some JSpinner components to my plugin frame,
> to save space instead of using sliders and to allow text input from the
> user as a shortcut.

Quite possible.

> I know that JSpinner is a Swing component, and I recall hearing/reading
> that ImageJ was not designed to use Swing.  Does this mean that the
> Swing libraries are not included in the bundled version of Java that
> comes with ImageJ?  Or is this just a limitation on what classes are
> used in the base code of ImageJ?...

The problem is that you cannot add an ImageCanvas to any Swing layout.  
That's where the pain starts...

Ciao,
Dscho
Reply | Threaded
Open this post in threaded view
|

Re: Swing Java components in ImageJ plugin frames?

Marcel
In reply to this post by Bill Mohler
It should be noted that with Java version 1.6.12 a limited mixing of heavyweight and lightweight components is supported.

Release Notes

For example you can put (with Java 1.6.12) a JPanel on top of a
Canvas component without problems.

Reply | Threaded
Open this post in threaded view
|

Re: Swing Java components in ImageJ plugin frames?

simon andrews (BI)
In reply to this post by dscho
On 12 May 2009, at 00:32, Johannes Schindelin wrote:

> The problem is that you cannot add an ImageCanvas to any Swing layout.

Sure you can.  There are gotchas with mixing heavyweight (AWT) and  
lightweight (Swing) components, but it's certainly not forbidden.  You  
can add anything which derives from Component to a Swing layout, which  
covers ImageCanvas.

Someone else posted a pointer to a list of workrounds for common  
problems, but one other option which I've used is to create a swing  
based version of ImageCanvas.  There are very few changes required to  
turn ImageCanvas into JImagePanel and then everything plays really  
nicely with the rest of Swing.  Probably overkill in your case, but in  
the right situation it can be the best solution.

Simon.
--
Simon Andrews PhD
Babraham Bioinformatics
www.bioinformatics.bbsrc.ac.uk
[hidden email]
+44 (0) 1223 496463
Reply | Threaded
Open this post in threaded view
|

Re: Swing Java components in ImageJ plugin frames?

dscho
Hi,

On Tue, 12 May 2009, Simon Andrews wrote:

> On 12 May 2009, at 00:32, Johannes Schindelin wrote:
>
> >The problem is that you cannot add an ImageCanvas to any Swing layout.
>
> Sure you can.  There are gotchas with mixing heavyweight (AWT) and
> lightweight (Swing) components, but it's certainly not forbidden.  You
> can add anything which derives from Component to a Swing layout, which
> covers ImageCanvas.

Just that it does not display properly, defeating the purpose of the
exercise.

> Someone else posted a pointer to a list of workrounds for common
> problems, but one other option which I've used is to create a swing
> based version of ImageCanvas.  There are very few changes required to
> turn ImageCanvas into JImagePanel and then everything plays really
> nicely with the rest of Swing. Probably overkill in your case, but in
> the right situation it can be the best solution.

Care to post your solution for the benefit of others (including me)?

Ciao,
Dscho
Reply | Threaded
Open this post in threaded view
|

Re: Swing Java components in ImageJ plugin frames?

simon andrews (BI)
On 12 May 2009, at 09:16, Johannes Schindelin wrote:

> Hi,
>
> On Tue, 12 May 2009, Simon Andrews wrote:
>
>> On 12 May 2009, at 00:32, Johannes Schindelin wrote:
>>
>>> The problem is that you cannot add an ImageCanvas to any Swing  
>>> layout.
>>
>> Sure you can.  There are gotchas with mixing heavyweight (AWT) and
>> lightweight (Swing) components, but it's certainly not forbidden.  
>> You
>> can add anything which derives from Component to a Swing layout,  
>> which
>> covers ImageCanvas.
>
> Just that it does not display properly, defeating the purpose of the
> exercise.

That's not been my experience.  It can throw off some of the dimension  
calculations in swing , but these are easily worked around.  The only  
thing which really proved a problem was embedding AWT objects in a  
JScrollPane which caused all kinds of odd display quirks.

>> Someone else posted a pointer to a list of workrounds for common
>> problems, but one other option which I've used is to create a swing
>> based version of ImageCanvas.  There are very few changes required to
>> turn ImageCanvas into JImagePanel and then everything plays really
>> nicely with the rest of Swing. Probably overkill in your case, but in
>> the right situation it can be the best solution.
>
> Care to post your solution for the benefit of others (including me)?

The code is released as part of our FocalPoint viewer:

http://www.bioinformatics.bbsrc.ac.uk/projects/focalpoint/

All of the image panels in the application are swing based ImageCanvas  
objects.  I've actually stripped out a lot of code in our released  
version to keep only what we use, just to make it easier to maintain,  
but when I did the original conversion I did a full swing adaption  
which was surprisingly quick.

Simon.
--
Simon Andrews PhD
Babraham Bioinformatics
www.bioinformatics.bbsrc.ac.uk
[hidden email]
+44 (0) 1223 496463
Reply | Threaded
Open this post in threaded view
|

Re: Swing Java components in ImageJ plugin frames?

dscho
Hi,

On Tue, 12 May 2009, Simon Andrews wrote:

> On 12 May 2009, at 09:16, Johannes Schindelin wrote:
>
> >On Tue, 12 May 2009, Simon Andrews wrote:
> >
> > >Someone else posted a pointer to a list of workrounds for common
> > >problems, but one other option which I've used is to create a swing
> > >based version of ImageCanvas.  There are very few changes required to
> > >turn ImageCanvas into JImagePanel and then everything plays really
> > >nicely with the rest of Swing. Probably overkill in your case, but in
> > >the right situation it can be the best solution.
> >
> >Care to post your solution for the benefit of others (including me)?
>
> The code is released as part of our FocalPoint viewer:
>
> http://www.bioinformatics.bbsrc.ac.uk/projects/focalpoint/
>
> All of the image panels in the application are swing based ImageCanvas
> objects.  I've actually stripped out a lot of code in our released
> version to keep only what we use, just to make it easier to maintain,
> but when I did the original conversion I did a full swing adaption which
> was surprisingly quick.

Whoa, that's 16 megabytes compressed.

BTW would you be willing to relicense just the JImageCanvas part to GPLv2
so that we can ship it inside Fiji?

Ciao,
Dscho
Reply | Threaded
Open this post in threaded view
|

Re: Swing Java components in ImageJ plugin frames?

simon andrews (BI)
On 12 May 2009, at 09:45, Johannes Schindelin wrote:

> Hi,
>
> On Tue, 12 May 2009, Simon Andrews wrote:
>
>> On 12 May 2009, at 09:16, Johannes Schindelin wrote:
>>>
>>> Care to post your solution for the benefit of others (including me)?
>>
>> The code is released as part of our FocalPoint viewer:
>>
>> http://www.bioinformatics.bbsrc.ac.uk/projects/focalpoint/
>>
>> All of the image panels in the application are swing based  
>> ImageCanvas
>> objects.  I've actually stripped out a lot of code in our released
>> version to keep only what we use, just to make it easier to maintain,
>> but when I did the original conversion I did a full swing adaption  
>> which
>> was surprisingly quick.
>
> Whoa, that's 16 megabytes compressed.

To be fair, nearly all of that comes from the copies of ImageJ and  
Bioformats we bundle in with our code :-)

> BTW would you be willing to relicense just the JImageCanvas part to  
> GPLv2
> so that we can ship it inside Fiji?

The JImagePanel class is released under the same public domain license  
as ImageJ since it's basically their code anyway.  If you want to use  
any of the rest of the code then contact me off list, but you can use  
the JImagePanel code as it is.

Simon.


--
Simon Andrews PhD
Babraham Bioinformatics
www.bioinformatics.bbsrc.ac.uk
[hidden email]
+44 (0) 1223 496463
Reply | Threaded
Open this post in threaded view
|

help with stack of masks

Leon Espinosa-2
In reply to this post by Marcel
Dear all,

I'm trying to obtain the ImagePlus of the stack of masks created by  
the analyze particle command. But I get only de active slide. I guess  
there is something wrong with the flag "PlugInFilter.DOES_STACKS"... ??
this is the code:

public class My_Plugin implements PlugIn {
ImagePlus imp, impOut;
ParticleAnalyzer pa;
ResultsTable rt;

        public void run(String arg) {
                imp=IJ.getImage();
                rt = new ResultsTable();
                pa = new ParticleAnalyzer(ParticleAnalyzer.SHOW_MASKS|
PlugInFilter.DOES_STACKS, Measurements.AREA, rt, 100, 10000);
                pa.analyze(imp);
                impOut = pa.getOutputImage();
                impOut.show();
                IJ.showMessage("My_Plugin","Hello world!");

        }

}


Thank you...

all the best,

  Leon Espinosa



Leon Espinosa
Laboratoire des Rickettsies du Pr. RAOULT
URMITE CNRS IRD
UMR 6236
Fac. de Medecine de la Timone
27 Bd Jean Moulin
13005 Marseille

mail: [hidden email]

tel:
Bureau: 04 91 32 46 32
Secrétariat: 04 91 32 43 75

Fax:
04 91 83 03 90
04 91 32 46 34

portable: 06 79 25 97 40
Reply | Threaded
Open this post in threaded view
|

Re: help with stack of masks

Michael Schmid
Hi Leon,

the Particle Analyzer does not accept PlugInFilter options in the  
'options' argument. PlugInFilter options are processed by the  
PlugInFilterRunner, which would call the particle analyzer's run(ip)  
method for all stack slices if the DOES_STACKS flag is set.

So you have to use a loop over stack slices.

Michael
________________________________________________________________


On 12 May 2009, at 11:29, Leon Espinosa wrote:

> Dear all,
>
> I'm trying to obtain the ImagePlus of the stack of masks created by  
> the analyze particle command. But I get only de active slide. I  
> guess there is something wrong with the flag  
> "PlugInFilter.DOES_STACKS"... ??
> this is the code:
>
> public class My_Plugin implements PlugIn {
> ImagePlus imp, impOut;
> ParticleAnalyzer pa;
> ResultsTable rt;
>
> public void run(String arg) {
> imp=IJ.getImage();
> rt = new ResultsTable();
> pa = new ParticleAnalyzer(ParticleAnalyzer.SHOW_MASKS|
> PlugInFilter.DOES_STACKS, Measurements.AREA, rt, 100, 10000);
> pa.analyze(imp);
> impOut = pa.getOutputImage();
> impOut.show();
> IJ.showMessage("My_Plugin","Hello world!");
>
> }
>
> }
>
>
> Thank you...
>
> all the best,
>
>  Leon Espinosa