Login  Register

Antwort: Re: Dynamically updating GenericDialog fields

Posted by Joachim Wesner on Feb 22, 2008; 11:22am
URL: http://imagej.273.s1.nabble.com/Pause-in-a-java-plugin-program-tp3697005p3697013.html

Hi Michael,

thanx a lot, this is exactly the info that I was looking for, I had taken a
look at the description of the genericDialog class,
but did not realize that getNumericFields really returns a *reference*  and
not numeric values that one could use to also update
those!

Joachim



                                                                           
             Michael Schmid                                                
             <[hidden email]                                            
             N.AC.AT>                                                   An
             Gesendet von:              [hidden email]                
             ImageJ Interest                                         Kopie
             Group                                                        
             <[hidden email].                                       Thema
             GOV>                       Re: Dynamically updating          
                                        GenericDialog fields              
                                                                           
             22.02.2008 12:00                                              
                                                                           
                                                                           
              Bitte antworten                                              
                    an                                                    
              ImageJ Interest                                              
                   Group                                                  
             <[hidden email].                                            
                   GOV>                                                    
                                                                           
                                                                           




Hi Joachim

if you want to add a button to a generic dialog, you have to
put it into a panel and use the
   public void addPanel(Panel panel)
method of GenericDialog.

Then you have to add your plugin as an ActionListener to the
dialog and handle th button events in the
   public void actionPerformed(ActionEvent e)
method of your plugin.
To change values after the button has been clicked, use the
   public Vector getNumericFields()
method of GenericDialog to get the references to the fields (the
fields are java.awt.TextField) and then use the
   setText(String text)
of the textfield.

For an example, see ij.plugin.filter.ScaleDialog.java


Note that there is a bug in Mac OSX 10.4:

It does not correctly update of the display if one changes more
than one item (textfield, label, state of a checkbox...) at the
same time. The only workaround I found so far is changing all
items but one at once, then wait for 100 or 200 ms and then
change the last item (or do some dummy change, e.g. add or
remove a trailing space of a label).

It looks like a problem of java.awt.Component.coalesceEvents,
but I was not successful with overriding coalesceEvents by a
method that returns null (to disable coalesceEvents).
So I guess that there is a similar mechanism like coalesceEvents
working on a deeper level (in the Mac OS) and the bug is there.

Michael
________________________________________________________________

On 22 Feb 2008, at 09:37, Joachim Wesner wrote:

> Hi list,
>
> as I understand, GenericDialog is basically a modal dialog that you
> can
> fill in with initial values, ask the user to change them and
> process any
> changes only
> afte she/he has pressed "OK". However, I also learned you can
> circumvent
> this (partially) by using a DialogListener, to implement previews
> etc.,
> i.e. immediately react to changes.
>
> I would now "envision" a plugin that has a button for.ex.
> "centered", when
> you press this the meaning of certain coordinates in other fields
> of the
> dialog changes, as in Specify ROI,
> however I would find it useful, that after any change to that
> button, the
> entries in those fields are changed accordingly, so that they
> reflect the
> **same** selection in the new
> coordinate system, i.e. one would need to update Dialog fields from
> within
> the Dialog Listener.
>
> Is this possible, any example code that already does something
> similar?
>
> Sincerely
>
> Joachim
>



______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________