GenericDialog Choice with units method

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

GenericDialog Choice with units method

CARL Philippe (LBP)
Dear all,
Within a GenericDialog there are 3 methods for adding a NumericField, one of them nicely giving the possibility to define the unit of the field content:
                void addNumericField(java.lang.String label, double defaultValue, int digits, int columns, java.lang.String units)
Very unfortunately there is only one method for adding a Choice which actually doesn't give the option for an unit entry:
                addChoice(java.lang.String label, java.lang.String[] items, java.lang.String defaultItem)
Thus following the addChoice method, I thought using a:
        addToSameRow()
followed by a
        addMessage
will be doing the job.
Very unfortunately, in this case the added message correctly shows up on the same line than the choice but really really far away from the given Choice Component.
As an alternative, I tryed then to use the following code:
        Component[] dlgItems = gd.getComponents();
        Component comp = dlgItems[6];
        GridBagLayout grid = (GridBagLayout) gd.getLayout();
        GridBagConstraints cst = grid.getConstraints(comp);
        cst.gridx = cst.gridx - 20;
        cst.gridy = cst.gridy - 1;
        grid.setConstraints(comp, cst);
But as I'm able to modify the cst.gridy value as wished, this isn't the case for the cst.gridx one which seems to be kind of blocked.
Thus is there a way to define an unit value just following a Choice Component?
I thank you very much in advance for your lights on this and wish you a nice week-end.
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 42 89

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: GenericDialog Choice with units method

Kenneth R Sloan-2
You could make the unit part of the choice string.

On Fri, Jul 17, 2020 at 10:48 CARL Philippe (LBP) <[hidden email]>
wrote:

> Dear all,
> Within a GenericDialog there are 3 methods for adding a NumericField, one
> of them nicely giving the possibility to define the unit of the field
> content:
>                 void addNumericField(java.lang.String label, double
> defaultValue, int digits, int columns, java.lang.String units)
> Very unfortunately there is only one method for adding a Choice which
> actually doesn't give the option for an unit entry:
>                 addChoice(java.lang.String label, java.lang.String[]
> items, java.lang.String defaultItem)
> Thus following the addChoice method, I thought using a:
>         addToSameRow()
> followed by a
>         addMessage
> will be doing the job.
> Very unfortunately, in this case the added message correctly shows up on
> the same line than the choice but really really far away from the given
> Choice Component.
> As an alternative, I tryed then to use the following code:
>         Component[]                     dlgItems        =
> gd.getComponents();
>         Component                       comp            = dlgItems[6];
>         GridBagLayout                   grid            = (GridBagLayout)
> gd.getLayout();
>         GridBagConstraints              cst             =
> grid.getConstraints(comp);
>         cst.gridx                                       = cst.gridx - 20;
>         cst.gridy                                       = cst.gridy - 1;
>         grid.setConstraints(comp, cst);
> But as I'm able to modify the cst.gridy value as wished, this isn't the
> case for the cst.gridx one which seems to be kind of blocked.
> Thus is there a way to define an unit value just following a Choice
> Component?
> I thank you very much in advance for your lights on this and wish you a
> nice week-end.
> My best regards,
> Philippe
>
>
> Philippe CARL
> Laboratoire de Bioimagerie et Pathologies
> UMR 7021 CNRS - Université de Strasbourg
> Faculté de Pharmacie
> 74 route du Rhin
> <https://www.google.com/maps/search/74+route+du+Rhin?entry=gmail&source=g>
> 67401 ILLKIRCH
> Tel : +33(0)3 68 85 42 89
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
--
-Kenneth Sloan

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: GenericDialog Choice with units method

CARL Philippe (LBP)
Indeed, and that is exactly what I have (= had) up to now (both for the NumericField as well as for the Choice)...

----- Le 17 Juil 20, à 18:01, Kenneth R Sloan [hidden email] a écrit :

You could make the unit part of the choice string.

On Fri, Jul 17, 2020 at 10:48 CARL Philippe (LBP) <[hidden email]>
wrote:

> Dear all,
> Within a GenericDialog there are 3 methods for adding a NumericField, one
> of them nicely giving the possibility to define the unit of the field
> content:
>                 void addNumericField(java.lang.String label, double
> defaultValue, int digits, int columns, java.lang.String units)
> Very unfortunately there is only one method for adding a Choice which
> actually doesn't give the option for an unit entry:
>                 addChoice(java.lang.String label, java.lang.String[]
> items, java.lang.String defaultItem)
> Thus following the addChoice method, I thought using a:
>         addToSameRow()
> followed by a
>         addMessage
> will be doing the job.
> Very unfortunately, in this case the added message correctly shows up on
> the same line than the choice but really really far away from the given
> Choice Component.
> As an alternative, I tryed then to use the following code:
>         Component[]                     dlgItems        =
> gd.getComponents();
>         Component                       comp            = dlgItems[6];
>         GridBagLayout                   grid            = (GridBagLayout)
> gd.getLayout();
>         GridBagConstraints              cst             =
> grid.getConstraints(comp);
>         cst.gridx                                       = cst.gridx - 20;
>         cst.gridy                                       = cst.gridy - 1;
>         grid.setConstraints(comp, cst);
> But as I'm able to modify the cst.gridy value as wished, this isn't the
> case for the cst.gridx one which seems to be kind of blocked.
> Thus is there a way to define an unit value just following a Choice
> Component?
> I thank you very much in advance for your lights on this and wish you a
> nice week-end.
> My best regards,
> Philippe
>
>
> Philippe CARL
> Laboratoire de Bioimagerie et Pathologies
> UMR 7021 CNRS - Université de Strasbourg
> Faculté de Pharmacie
> 74 route du Rhin
> <https://www.google.com/maps/search/74+route+du+Rhin?entry=gmail&source=g>
> 67401 ILLKIRCH
> Tel : +33(0)3 68 85 42 89
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
--
-Kenneth Sloan

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

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: GenericDialog Choice with units method

Kenneth R Sloan-2
I meant the choice VALUE - not the prompt.  You can’t do this with numeric
(or string) fields, do it’s more important to have a special location for
units for those fields, but choice values are strings determined by the
program and not altered by the user, so putting the units there makes sense.

I can also imagine cases where the various choice options have DIFFERENT
units.  Indeed, where it is precisely the units that are being selected.

That said, I agree that it would be nice to have a “units” parameter for
choices - if only for the sake of orthogonal design.

On Fri, Jul 17, 2020 at 11:15 CARL Philippe (LBP) <[hidden email]>
wrote:

> Indeed, and that is exactly what I have (= had) up to now (both for the
> NumericField as well as for the Choice)...
>
> ----- Le 17 Juil 20, à 18:01, Kenneth R Sloan [hidden email] a
> écrit :
>
> You could make the unit part of the choice string.
>
> On Fri, Jul 17, 2020 at 10:48 CARL Philippe (LBP) <
> [hidden email]>
> wrote:
>
> > Dear all,
> > Within a GenericDialog there are 3 methods for adding a NumericField, one
> > of them nicely giving the possibility to define the unit of the field
> > content:
> >                 void addNumericField(java.lang.String label, double
> > defaultValue, int digits, int columns, java.lang.String units)
> > Very unfortunately there is only one method for adding a Choice which
> > actually doesn't give the option for an unit entry:
> >                 addChoice(java.lang.String label, java.lang.String[]
> > items, java.lang.String defaultItem)
> > Thus following the addChoice method, I thought using a:
> >         addToSameRow()
> > followed by a
> >         addMessage
> > will be doing the job.
> > Very unfortunately, in this case the added message correctly shows up on
> > the same line than the choice but really really far away from the given
> > Choice Component.
> > As an alternative, I tryed then to use the following code:
> >         Component[]                     dlgItems        =
> > gd.getComponents();
> >         Component                       comp            = dlgItems[6];
> >         GridBagLayout                   grid            = (GridBagLayout)
> > gd.getLayout();
> >         GridBagConstraints              cst             =
> > grid.getConstraints(comp);
> >         cst.gridx                                       = cst.gridx - 20;
> >         cst.gridy                                       = cst.gridy - 1;
> >         grid.setConstraints(comp, cst);
> > But as I'm able to modify the cst.gridy value as wished, this isn't the
> > case for the cst.gridx one which seems to be kind of blocked.
> > Thus is there a way to define an unit value just following a Choice
> > Component?
> > I thank you very much in advance for your lights on this and wish you a
> > nice week-end.
> > My best regards,
> > Philippe
> >
> >
> > Philippe CARL
> > Laboratoire de Bioimagerie et Pathologies
> > UMR 7021 CNRS - Université de Strasbourg
> > Faculté de Pharmacie
> > 74 route du Rhin
> > <
> https://www.google.com/maps/search/74+route+du+Rhin?entry=gmail&source=g>
> > 67401 ILLKIRCH
> > Tel : +33(0)3 68 85 42 89
> >
> > --
> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> >
> --
> -Kenneth Sloan
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
--
-Kenneth Sloan

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: GenericDialog Choice with units method

Wayne Rasband-2
In reply to this post by CARL Philippe (LBP)
> On Jul 17, 2020, at 11:44 AM, CARL Philippe (LBP) <[hidden email]> wrote:

> Thus is there a way to define an unit value just following a Choice Component?

You can add the unit to the label, for example:

  gd.addChoice("Width ("+unit+")", items, null);

I am reluctant to make changes to GenericDialog since it appears to slow down Fiji updates:

   https://github.com/imagej/ij1-patcher/pull/47

Fiji  currently includes ImageJ 1.52p, released more than a year ago and seven versions out of date.

-wayne


> Dear all,
> Within a GenericDialog there are 3 methods for adding a NumericField, one of them nicely giving the possibility to define the unit of the field content:
> void addNumericField(java.lang.String label, double defaultValue, int digits, int columns, java.lang.String units)
> Very unfortunately there is only one method for adding a Choice which actually doesn't give the option for an unit entry:
> addChoice(java.lang.String label, java.lang.String[] items, java.lang.String defaultItem)
> Thus following the addChoice method, I thought using a:
> addToSameRow()
> followed by a
> addMessage
> will be doing the job.
> Very unfortunately, in this case the added message correctly shows up on the same line than the choice but really really far away from the given Choice Component.
> As an alternative, I tryed then to use the following code:
> Component[] dlgItems = gd.getComponents();
> Component comp = dlgItems[6];
> GridBagLayout grid = (GridBagLayout) gd.getLayout();
> GridBagConstraints cst = grid.getConstraints(comp);
> cst.gridx = cst.gridx - 20;
> cst.gridy = cst.gridy - 1;
> grid.setConstraints(comp, cst);
> But as I'm able to modify the cst.gridy value as wished, this isn't the case for the cst.gridx one which seems to be kind of blocked.
> Thus is there a way to define an unit value just following a Choice Component?
> I thank you very much in advance for your lights on this and wish you a nice week-end.
> My best regards,
> Philippe

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: GenericDialog Choice with units method

CARL Philippe (LBP)
Dear Wayne,
What you are recommending me with adding the unit to the label is how the GenericDialog was originally formatted both for the numericFields and Choices of the plugin I'm working on (I'm actually not the original author of it).
So I changed the used addNumericField method to the one defining a unit and implemented now the solution described by Kenneth for the Choices.
But in the case you want all units to be nicely aligned (as I do) it is really not easy to use such a solution, especially given that the tabulations are ignored within the java.lang.String[]_items of the
addChoice(java.lang.String label, java.lang.String[] items, java.lang.String defaultItem).
Also I don't understand why the GridBagLayout and GridBagConstraints solution I described below is only working for the .gridy settings and not the .gridx one.
At last concerning Fiji, I was a more than convinced user of what I thought to be a kind of ImageJ++ tool ages ago.
Very unfortunately, using Fiji I got some very serious either infinite loops and/or memory leaks issues with some analysis which were not only taking ages but especially generating wrong results.
Having spent several weeks without being able to either locate or solve the issue, I finally jumped into the bet of a colleague who recommended me to give a try with the "vanilla version" of ImageJ.
And by trying so, the calculations that were previously taking a couple / several hours with Fiji (and generating wrong results) were done within only a couple minutes and especially generating right results!
I agree that I more than probably should have reported such an issue.
But having lost so much time on such an unexpected issue, I rather didn't want to hear about Fiji anymore!
Take care,
Philippe

----- Mail original -----
De: "Wayne Rasband" <[hidden email]>
À: "imagej" <[hidden email]>
Envoyé: Vendredi 17 Juillet 2020 20:58:19
Objet: Re: GenericDialog Choice with units method

> On Jul 17, 2020, at 11:44 AM, CARL Philippe (LBP) <[hidden email]> wrote:

> Thus is there a way to define an unit value just following a Choice Component?

You can add the unit to the label, for example:

  gd.addChoice("Width ("+unit+")", items, null);

I am reluctant to make changes to GenericDialog since it appears to slow down Fiji updates:

   https://github.com/imagej/ij1-patcher/pull/47

Fiji  currently includes ImageJ 1.52p, released more than a year ago and seven versions out of date.

-wayne


> Dear all,
> Within a GenericDialog there are 3 methods for adding a NumericField, one of them nicely giving the possibility to define the unit of the field content:
> void addNumericField(java.lang.String label, double defaultValue, int digits, int columns, java.lang.String units)
> Very unfortunately there is only one method for adding a Choice which actually doesn't give the option for an unit entry:
> addChoice(java.lang.String label, java.lang.String[] items, java.lang.String defaultItem)
> Thus following the addChoice method, I thought using a:
> addToSameRow()
> followed by a
> addMessage
> will be doing the job.
> Very unfortunately, in this case the added message correctly shows up on the same line than the choice but really really far away from the given Choice Component.
> As an alternative, I tryed then to use the following code:
> Component[] dlgItems = gd.getComponents();
> Component comp = dlgItems[6];
> GridBagLayout grid = (GridBagLayout) gd.getLayout();
> GridBagConstraints cst = grid.getConstraints(comp);
> cst.gridx = cst.gridx - 20;
> cst.gridy = cst.gridy - 1;
> grid.setConstraints(comp, cst);
> But as I'm able to modify the cst.gridy value as wished, this isn't the case for the cst.gridx one which seems to be kind of blocked.
> Thus is there a way to define an unit value just following a Choice Component?
> I thank you very much in advance for your lights on this and wish you a nice week-end.
> My best regards,
> Philippe

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

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