Re: "No" button within GenericDialog class feature update

Posted by Curtis Rueden-2 on
URL: http://imagej.273.s1.nabble.com/No-button-within-GenericDialog-class-feature-update-tp5022458p5022460.html

Hi,

> I would also like to have more functionality for additional buttons

ImageJ2-style Command plugins support any number of extra buttons with
syntax:

  import org.scijava.widget.Button;
  ...
  @Plugin(type = Command.class)
  public class MyCommandWithHelp {
  ...
  @Parameter(label = "Help", callback = "help")
  private Button helpButton;
  ...
  private void help() {
    System.out.println("Help button pressed.");
  }
  ...
  public void run() {
    System.out.println("Command executing");
    ...
  }
  ...

See here for a demo of SciJava parameters in action (though not a lot of
extra buttons):
https://github.com/imagej/tutorials/blob/27d059117b3bfd1c73d8300f3193db11f6aebb9d/maven-projects/widget-demo/src/main/java/WidgetDemo.java#L244-L245

Regards,
Curtis

--
Curtis Rueden
Software architect, LOCI/Eliceiri lab - https://loci.wisc.edu/software
ImageJ2 lead, Fiji maintainer - https://imagej.net/User:Rueden
Have you tried the Image.sc Forum? https://forum.image.sc/



On Tue, Sep 24, 2019 at 6:05 PM Michael Schmid <[hidden email]>
wrote:

> Hi Philippe,
>
> yes, I would also like to have more functionality for additional
> buttons, and I am sometimes "misusing" the "No" button for such purposes.
>
> In your sample code, after gd.showDialog() I think that the code will
> never again be able to react to the dialog, even if the dialog remains
> on the screen?
>
> So I think we need some callback, using the DialogListener and/or
> ActionListener interface.
>
> So my dream would be a GenericDialog method
>    Button[] addBottomButtons(String[] buttonLabels)
> which adds one or more buttons at the position where usually the 'no'
> button would appear.
> Or, alternatively,
>    Button addBottomButton(String buttonLabel)
> which could be called multiple times (the buttons would go into a Vector
> or ArrayList)
>
> Then the user plugin could either use the references to the buttons and
> register as an ActionListener for them, or it could register as
> DialogListener and it would get its dialogItemChanged method called when
> the user presses a button while the dialog window is still open.
>
> Of course, the same could be done already now by adding a panel with the
> buttons, and registering for each of them as ActionListener, but that is
> more cumbersome, and in many cases one wants the button(s) at the bottom.
>
> (unfortunately, I can't quickly do the coding now; too much unfinished
> work on my desk)
>
>
> Michael
> ________________________________________________________________
> On 24.09.19 17:09, CARL Philippe (LBP) wrote:
> > Dear all,
> > Within the GenericDialog class it is now possible to add an additional
> button and even customize its name (see enableYesNoCancel(java.lang.String
> yesLabel, java.lang.String noLabel) method).
> > Nevertheless, it would additionally be interesting to have this custom
> "No" button being able to launch a method without launching itself the
> GenericDialog dispose() method, for example for having an "Apply" button
> which would not close the dialog like I illustrated it within the small
> plugin that can be found here:
> >       http://punias.free.fr/ImageJ/test/My_Plugin.java
> > that can be linked with the GenericDialog update try that can be found
> within:
> >       http://punias.free.fr/ImageJ/test/GenericDialog.java
> > Nevertheless I don't know how I could define the method I would like to
> launch from "outside" the GenericDialog class.
> > I thank you very much in advance for your lighting on this.
> > My best regards
> > Philippe
> >
> > Philippe CARL
> > Laboratoire de Bioimagerie et Pathologies
> > UMR 7021 CNRS - Université de Strasbourg
> > Faculté de Pharmacie
> > 74 route du Rhin
> > 67401 ILLKIRCH
> > Tel : +33(0)3 68 85 41 84
> >
> > --
> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> >
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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