Advanced Dialog boxes

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

Advanced Dialog boxes

John Alexander-7
Hello group,

I am wondering about some more advanced dialog box features in a macro.

For example, let's say I want to have a field on the box continuously
updated.  For example, I want one option to depend on the other.  If the
person types "2" in the X box, then the Y box automatically prints "4"
(as in 2*X).  If the person types "6" in the Y box, then the X
automatically is set to 3.  Basically I want the dialog box to be
interactive - and only commit the values to the assigned variables once
the person clicks "ok".

Another thing is to have an "input directory" and an "output directory"
field with a "browse" button next to them.

What about having an option grayed out if it is unecessary.

For example: I would have a checkbox that says "process single file?" If
the person checks it - then the "recursively process directory" field
would be greyed out since it is irrelevant.

Are such advanced dialog featuers available in ImageJ macros?  Or is
such interactivity for plug-ins?

So far I am exclusively writing macros - since I have really not found
the need to learn how to write a plug-in.  I know that if I put a tad
bit of effort into learning how to write a plug-in it will be easy - ust
being lazy.  :P



John




--
John K. Alexander, Ph.D.
Post-Doctoral Fellow
William Green Laboratory
University of Chicago
Dept. Neurobiology, Pharmacology, and Physiology
947 East 58th Street
Abott Hall 402
Chicago, IL 60637
(off) 773-702-9386
(fax) 773-702-3774
[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Advanced Dialog boxes

Gabriel Landini
On Sunday 18 May 2008, John Alexander wrote:

> For example, let's say I want to have a field on the box continuously
> updated.  For example, I want one option to depend on the other.  If the
> person types "2" in the X box, then the Y box automatically prints "4"
> (as in 2*X).  If the person types "6" in the Y box, then the X
> automatically is set to 3.  Basically I want the dialog box to be
> interactive - and only commit the values to the assigned variables once
> the person clicks "ok"

> Another thing is to have an "input directory" and an "output directory"
> field with a "browse" button next to them.

> What about having an option grayed out if it is unecessary.

I think you can't because the macro dialogs act as "modal windows".
http://en.wikipedia.org/wiki/Modal_dialog
They show the options based on a previous state, collect all the user
selections and only then carry on with the rest of the macro.

For doing what you want, you need to write a plugin that works interactively
on a separate thread (see for example the Colour_threshold, or the Align_4
plugins).

The problem then becomes that if you launch those plugins from a macro, they
are not really "recordable", as they do not wait for the user (i.e. launch
the plugin in a different thread).

One alternative is to create a button in the interactive plugin that (if the
Macro Recorder is active) will write a macro in the Recorder window that does
what the plugin is set to do. The Colour_Threshold plugin does that.

The other is to launch a "waitForUser( )" in a macro, but although this allows
you to stop the macro and do something else interactively, the interactive
plugin is still not recordable unless programmed specially to output macro
commands.

Maybe somebody has a better idea...

G.
Reply | Threaded
Open this post in threaded view
|

Re: Advanced Dialog boxes

Michael Schmid
In reply to this post by John Alexander-7
Hi John,

some of the features you want are possible when writing a
plugin and using the GenericDialog class of ImageJ (so you
can record the options by the Macro Recorder and run the
plugin from a macro):

Register your plugin as a DialogListener, then its
dialogItemChanged method gets called on every user action
(typing, clicking).
For examples, see, e.g., the Convolver.java or SpecifyROI.java
codes.

You can also use the getCheckboxes() etc. methods of the
GenericDialog class to get references to the fields. Then
you can enable or disable ("gray out") the fields by the usual
java.awt commands like myCheckbox.setEnabled(true) and you
can write into text fields.

A problem with these methods is a very nasty bug on Mac OSX 10.4
(possibly also other versions?):
If more than one modification of a dialog, such as enabling or
disabling a field, writing into a field, etc. is done at the same
time, only the first of them is actually made, the others are
delayed until the next input (clicking, typing) operation.
E.g., it may happen that checkboxes remain disabled and the user
cannot check or uncheck them.

Browse file or Browse directory - this would require the
addPanel method of a GenericDialog, but then you have to do
all the coding for it, including macro options, by yourself.
I would suggest to use a separate file or directory dialog
istead.

I see no way how to implement any of these functionalities in
a macro (instead of a plugin). So you have to learn Java (this
is not extremely difficult, at least much easier than C++).

Michael
________________________________________________________________

On 18 May 2008, at 04:42, John Alexander wrote:


> Hello group,
>
> I am wondering about some more advanced dialog box features in a  
> macro.
>
> For example, let's say I want to have a field on the box continuously
> updated.  For example, I want one option to depend on the other.  
> If the
> person types "2" in the X box, then the Y box automatically prints "4"
> (as in 2*X).  If the person types "6" in the Y box, then the X
> automatically is set to 3.  Basically I want the dialog box to be
> interactive - and only commit the values to the assigned variables  
> once
> the person clicks "ok".
>
> Another thing is to have an "input directory" and an "output  
> directory"
> field with a "browse" button next to them.
>
> What about having an option grayed out if it is unecessary.
>
> For example: I would have a checkbox that says "process single  
> file?" If
> the person checks it - then the "recursively process directory" field
> would be greyed out since it is irrelevant.
>
> Are such advanced dialog featuers available in ImageJ macros?  Or is
> such interactivity for plug-ins?
>
> So far I am exclusively writing macros - since I have really not found
> the need to learn how to write a plug-in.  I know that if I put a tad
> bit of effort into learning how to write a plug-in it will be easy  
> - ust
> being lazy.  :P
>
>
>
> John
>
>
>
>
> --
> John K. Alexander, Ph.D.
> Post-Doctoral Fellow
> William Green Laboratory
> University of Chicago
> Dept. Neurobiology, Pharmacology, and Physiology
> 947 East 58th Street
> Abott Hall 402
> Chicago, IL 60637
> (off) 773-702-9386
> (fax) 773-702-3774
> [hidden email]
>
Reply | Threaded
Open this post in threaded view
|

Re: Advanced Dialog boxes

John Alexander-7
Thank you (and everyone).

I guess I have begun to reach the limits of macro coding.  I once knew
c++ so I am rather familiar with the java syntax - but just haven't
written any real code in a decade.

Looks like now is a decent time to begin going through the plug-in
tutorials I've found.

John



Michael Schmid wrote:

> Hi John,
>
> some of the features you want are possible when writing a
> plugin and using the GenericDialog class of ImageJ (so you
> can record the options by the Macro Recorder and run the
> plugin from a macro):
>
> Register your plugin as a DialogListener, then its
> dialogItemChanged method gets called on every user action
> (typing, clicking).
> For examples, see, e.g., the Convolver.java or SpecifyROI.java
> codes.
>
> You can also use the getCheckboxes() etc. methods of the
> GenericDialog class to get references to the fields. Then
> you can enable or disable ("gray out") the fields by the usual
> java.awt commands like myCheckbox.setEnabled(true) and you
> can write into text fields.
>
> A problem with these methods is a very nasty bug on Mac OSX 10.4
> (possibly also other versions?):
> If more than one modification of a dialog, such as enabling or
> disabling a field, writing into a field, etc. is done at the same
> time, only the first of them is actually made, the others are
> delayed until the next input (clicking, typing) operation.
> E.g., it may happen that checkboxes remain disabled and the user
> cannot check or uncheck them.
>
> Browse file or Browse directory - this would require the
> addPanel method of a GenericDialog, but then you have to do
> all the coding for it, including macro options, by yourself.
> I would suggest to use a separate file or directory dialog
> istead.
>
> I see no way how to implement any of these functionalities in
> a macro (instead of a plugin). So you have to learn Java (this
> is not extremely difficult, at least much easier than C++).
>
> Michael
> ________________________________________________________________
>
> On 18 May 2008, at 04:42, John Alexander wrote:
>
>
>> Hello group,
>>
>> I am wondering about some more advanced dialog box features in a macro.
>>
>> For example, let's say I want to have a field on the box continuously
>> updated.  For example, I want one option to depend on the other.  If the
>> person types "2" in the X box, then the Y box automatically prints "4"
>> (as in 2*X).  If the person types "6" in the Y box, then the X
>> automatically is set to 3.  Basically I want the dialog box to be
>> interactive - and only commit the values to the assigned variables once
>> the person clicks "ok".
>>
>> Another thing is to have an "input directory" and an "output directory"
>> field with a "browse" button next to them.
>>
>> What about having an option grayed out if it is unecessary.
>>
>> For example: I would have a checkbox that says "process single file?" If
>> the person checks it - then the "recursively process directory" field
>> would be greyed out since it is irrelevant.
>>
>> Are such advanced dialog featuers available in ImageJ macros?  Or is
>> such interactivity for plug-ins?
>>
>> So far I am exclusively writing macros - since I have really not found
>> the need to learn how to write a plug-in.  I know that if I put a tad
>> bit of effort into learning how to write a plug-in it will be easy - ust
>> being lazy.  :P
>>
>>
>>
>> John
>>
>>
>>
>>
>> --
>> John K. Alexander, Ph.D.
>> Post-Doctoral Fellow
>> William Green Laboratory
>> University of Chicago
>> Dept. Neurobiology, Pharmacology, and Physiology
>> 947 East 58th Street
>> Abott Hall 402
>> Chicago, IL 60637
>> (off) 773-702-9386
>> (fax) 773-702-3774
>> [hidden email]
>>
>

--
John K. Alexander, Ph.D.
Post-Doctoral Fellow
William Green Laboratory
University of Chicago
Dept. Neurobiology, Pharmacology, and Physiology
947 East 58th Street
Abott Hall 402
Chicago, IL 60637
(off) 773-702-9386
(fax) 773-702-3774
[hidden email]