grid.setConstraints issue with Choice

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

grid.setConstraints issue with Choice

CARL Philippe (LBP)
Dear all,
I'm using the following code:
                gd.addChoice ("Young's_modulus_(in Pascal)" , EText     , EText[EIndex]);
                gd.addChoice ("Regularization_factor" , lambdaText, lambdaText[lambdaIndex]);
                ........
                comp = (Component) gd.getChoices().get(1);
                cst = grid.getConstraints(comp);
                cst.gridx = cst.gridx + 1;
                cst.gridy = cst.gridy - 1;
                grid.setConstraints(comp, cst);
in order to shift position of a Choice within a GenericDialog.
But as can be seen within the following PrintScreen of the launched plugin, the Choice dropdown menu gets well shifted but not the text associated to it (which stays in its attributed position when declared):
http://punias.free.fr/ImageJ/create_job.jpg
Am I doing something wrong here (knowing that a similar code applied on CheckBoxes is working well) or is there a stecific issue when applied on Choices?
I thank you very much in advance for your suggestions and help.
My best egards,
Philippe

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

Re: grid.setConstraints issue with Choice

Michael Schmid
Hi Philippe,

if you look at the GenericDialog addChoice code, you will see that the
Label and the Choice are two separate components.
Unfortunately, one can't access the Label directly (the reference to it
is not kept, so there is nothing like the gd.getChoices() for the Label).

Possible solutions:
- stick to the layout of the GenericDialog, with vertical alignment, or
- have your own dialog (if you don't need interaction with macros), or
- persuade Wayne to add something like a
GenericDialog.addToLine(boolean) method, and for all 'add's have
   if (addToLine)
     y++; c.gridy = y;
   else
     c.gridx = 0; c.gridy = y;

(roughly 10 occurrences)

Michael
________________________________________________________________


On 09/02/2018 12:50, CARL Philippe (PHA) wrote:

> Dear all,
> I'm using the following code:
> gd.addChoice ("Young's_modulus_(in Pascal)" , EText     , EText[EIndex]);
> gd.addChoice ("Regularization_factor" , lambdaText, lambdaText[lambdaIndex]);
>                  ........
> comp = (Component) gd.getChoices().get(1);
> cst = grid.getConstraints(comp);
> cst.gridx = cst.gridx + 1;
> cst.gridy = cst.gridy - 1;
> grid.setConstraints(comp, cst);
> in order to shift position of a Choice within a GenericDialog.
> But as can be seen within the following PrintScreen of the launched plugin, the Choice dropdown menu gets well shifted but not the text associated to it (which stays in its attributed position when declared):
> http://punias.free.fr/ImageJ/create_job.jpg
> Am I doing something wrong here (knowing that a similar code applied on CheckBoxes is working well) or is there a stecific issue when applied on Choices?
> I thank you very much in advance for your suggestions and help.
> My best egards,
> Philippe
>
> --
> 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: grid.setConstraints issue with Choice

CARL Philippe (LBP)
Dear Michael,
I thank you very much for your (as always) very precise and sharp answer!
And given that you always prefer to postpone discussions in public rather than in private I contact you here.
Thus given that I "don't need interaction with macros" for this plugin I want to rather go into the direction of "having my own dialog" implementing this feature.
But I have some starter (or if you prefer beginner) issues.
So what I did is to download the "GenericDialog.java" file, renaming the class into "GenericDialogExt" and modifying the "package ij.gui;" line into "import ij.gui.*;"
But when I compile this I get the following errors:
        java.lang.InstantiationException: GenericDialogExt
        at java.lang.Class.newInstance(Class.java:427)
        at ij.plugin.PlugInExecuter.runCompiledPlugin(Compiler.java:323)
        at ij.plugin.PlugInExecuter.run(Compiler.java:314)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoSuchMethodException: GenericDialogExt.<init>()
        at java.lang.Class.getConstructor0(Class.java:3082)
        at java.lang.Class.newInstance(Class.java:412)
        ... 3 more
As when I leave the line "package ij.gui;" the compilation is done right but I will then need to put this new class into the ij.gui folder on order to use it afterwards isn't it?
So how should I start the code and why?
My best regards,
Philippe

-----Message d'origine-----
De : ImageJ Interest Group [mailto:[hidden email]] De la part de Michael Schmid
Envoyé : vendredi 9 février 2018 14:59
À : [hidden email]
Objet : Re: grid.setConstraints issue with Choice

Hi Philippe,

if you look at the GenericDialog addChoice code, you will see that the Label and the Choice are two separate components.
Unfortunately, one can't access the Label directly (the reference to it is not kept, so there is nothing like the gd.getChoices() for the Label).

Possible solutions:
- stick to the layout of the GenericDialog, with vertical alignment, or
- have your own dialog (if you don't need interaction with macros), or
- persuade Wayne to add something like a
GenericDialog.addToLine(boolean) method, and for all 'add's have
   if (addToLine)
     y++; c.gridy = y;
   else
     c.gridx = 0; c.gridy = y;

(roughly 10 occurrences)

Michael
________________________________________________________________


On 09/02/2018 12:50, CARL Philippe (PHA) wrote:

> Dear all,
> I'm using the following code:
> gd.addChoice ("Young's_modulus_(in Pascal)" , EText     , EText[EIndex]);
> gd.addChoice ("Regularization_factor" , lambdaText, lambdaText[lambdaIndex]);
>                  ........
> comp = (Component) gd.getChoices().get(1);
> cst = grid.getConstraints(comp);
> cst.gridx = cst.gridx + 1;
> cst.gridy = cst.gridy - 1;
> grid.setConstraints(comp, cst);
> in order to shift position of a Choice within a GenericDialog.
> But as can be seen within the following PrintScreen of the launched plugin, the Choice dropdown menu gets well shifted but not the text associated to it (which stays in its attributed position when declared):
> http://punias.free.fr/ImageJ/create_job.jpg
> Am I doing something wrong here (knowing that a similar code applied on CheckBoxes is working well) or is there a stecific issue when applied on Choices?
> I thank you very much in advance for your suggestions and help.
> My best egards,
> Philippe
>
> --
> 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
Reply | Threaded
Open this post in threaded view
|

Re: grid.setConstraints issue with Choice

Michael Schmid
Hi Philippe,

my guess is that the ImageJ class loader needs a constructor with no
argument for Compile&Run, e.g.
   public GenericDialogExt() {
     this("");
   }

Java seems to create a no-argument constructor by itself only if there
is no other constructor (The GenericDialog has a constructor with a
String argument).
 
https://stackoverflow.com/questions/3078389/why-do-we-need-a-default-no-argument-constructor-in-java#4490416

Michael
________________________________________________________________
On 13/02/2018 15:28, Philippe CARL wrote:

> Dear Michael,
> I thank you very much for your (as always) very precise and sharp answer!
> And given that you always prefer to postpone discussions in public rather than in private I contact you here.
> Thus given that I "don't need interaction with macros" for this plugin I want to rather go into the direction of "having my own dialog" implementing this feature.
> But I have some starter (or if you prefer beginner) issues.
> So what I did is to download the "GenericDialog.java" file, renaming the class into "GenericDialogExt" and modifying the "package ij.gui;" line into "import ij.gui.*;"
> But when I compile this I get the following errors:
> java.lang.InstantiationException: GenericDialogExt
> at java.lang.Class.newInstance(Class.java:427)
> at ij.plugin.PlugInExecuter.runCompiledPlugin(Compiler.java:323)
> at ij.plugin.PlugInExecuter.run(Compiler.java:314)
> at java.lang.Thread.run(Thread.java:745)
> Caused by: java.lang.NoSuchMethodException: GenericDialogExt.<init>()
> at java.lang.Class.getConstructor0(Class.java:3082)
> at java.lang.Class.newInstance(Class.java:412)
> ... 3 more
> As when I leave the line "package ij.gui;" the compilation is done right but I will then need to put this new class into the ij.gui folder on order to use it afterwards isn't it?
> So how should I start the code and why?
> My best regards,
> Philippe
>
> -----Message d'origine-----
> De : ImageJ Interest Group [mailto:[hidden email]] De la part de Michael Schmid
> Envoyé : vendredi 9 février 2018 14:59
> À : [hidden email]
> Objet : Re: grid.setConstraints issue with Choice
>
> Hi Philippe,
>
> if you look at the GenericDialog addChoice code, you will see that the Label and the Choice are two separate components.
> Unfortunately, one can't access the Label directly (the reference to it is not kept, so there is nothing like the gd.getChoices() for the Label).
>
> Possible solutions:
> - stick to the layout of the GenericDialog, with vertical alignment, or
> - have your own dialog (if you don't need interaction with macros), or
> - persuade Wayne to add something like a
> GenericDialog.addToLine(boolean) method, and for all 'add's have
>     if (addToLine)
>       y++; c.gridy = y;
>     else
>       c.gridx = 0; c.gridy = y;
>
> (roughly 10 occurrences)
>
> Michael
> ________________________________________________________________
>
>
> On 09/02/2018 12:50, CARL Philippe (PHA) wrote:
>> Dear all,
>> I'm using the following code:
>> gd.addChoice ("Young's_modulus_(in Pascal)" , EText     , EText[EIndex]);
>> gd.addChoice ("Regularization_factor" , lambdaText, lambdaText[lambdaIndex]);
>>                   ........
>> comp = (Component) gd.getChoices().get(1);
>> cst = grid.getConstraints(comp);
>> cst.gridx = cst.gridx + 1;
>> cst.gridy = cst.gridy - 1;
>> grid.setConstraints(comp, cst);
>> in order to shift position of a Choice within a GenericDialog.
>> But as can be seen within the following PrintScreen of the launched plugin, the Choice dropdown menu gets well shifted but not the text associated to it (which stays in its attributed position when declared):
>> http://punias.free.fr/ImageJ/create_job.jpg
>> Am I doing something wrong here (knowing that a similar code applied on CheckBoxes is working well) or is there a stecific issue when applied on Choices?
>> I thank you very much in advance for your suggestions and help.
>> My best egards,
>> Philippe
>>
>> --
>> 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
>

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

Re: grid.setConstraints issue with Choice

CARL Philippe (LBP)
Hi Michael,
Your suggestion was indeed correct and I was then able to compile the GenericDialogExt code after disabling 2-3 things from the code (like code referring to "((DialogListener)dialogListeners.elementAt(i)).dialogItemChanged(this, e)").
But then when I try to compile the code that using this newly compiled class it doesn't accept that I use:
        public boolean dialogItemChanged(GenericDialogExt gd, AWTEvent e)
but I have to overwrite the method using:
        public boolean dialogItemChanged(GenericDialog gd, AWTEvent e)
But if I do so then there isn't any more a dialogItemChanged detection on the defined GenericDialogExt window.
How can I solve this new issue?
I thank you very much in advance for your help on this one.
Philippe

-----Message d'origine-----
De : ImageJ Interest Group [mailto:[hidden email]] De la part de Michael Schmid
Envoyé : mardi 13 février 2018 16:02
À : [hidden email]
Objet : Re: grid.setConstraints issue with Choice

Hi Philippe,

my guess is that the ImageJ class loader needs a constructor with no argument for Compile&Run, e.g.
   public GenericDialogExt() {
     this("");
   }

Java seems to create a no-argument constructor by itself only if there is no other constructor (The GenericDialog has a constructor with a String argument).
 
https://stackoverflow.com/questions/3078389/why-do-we-need-a-default-no-argument-constructor-in-java#4490416

Michael

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

Re: grid.setConstraints issue with Choice

Michael Schmid
Hi Philippe,

do you need the DialogListener interface for preview?
If not, you can remove all the DialogListener stuff (e.g. use sparate
listeners) or create your own DialogListenerExt interface.

If you want preview, I see no nice solution.
Preview is done by the combination of the PlugInFilter implementing the
DialogListener, the GenericDialog, and the PlugInFilterRunner, you can
have it only with a GenericDialog.

In that case, we have to ask Wayne whether he would agree to have a
modification of the GenericDialog to have more that one item per line.

Maybe this is something that others might also like?

I had already a few cases where I would have liked to have a number and
a checkbox in one line, e.g. for keeping some parameters fixed in
optimization/curve fitting, or several pairs of numbers (ranges).

[For some applications like this, there would another small problem:
In many cases, the second item in the line would not have a unique
label, e.g. for fixing some parameters, there would be several
checkboxes with 'fix', or for several ranges, there would be just a 'to'
between the numbers. Then it would not be macro-recordable.]


Best,

Michael
________________________________________________________________
On 14/02/2018 13:41, Philippe CARL wrote:

> Hi Michael,
> Your suggestion was indeed correct and I was then able to compile the GenericDialogExt code after disabling 2-3 things from the code (like code referring to "((DialogListener)dialogListeners.elementAt(i)).dialogItemChanged(this, e)").
> But then when I try to compile the code that using this newly compiled class it doesn't accept that I use:
> public boolean dialogItemChanged(GenericDialogExt gd, AWTEvent e)
> but I have to overwrite the method using:
> public boolean dialogItemChanged(GenericDialog gd, AWTEvent e)
> But if I do so then there isn't any more a dialogItemChanged detection on the defined GenericDialogExt window.
> How can I solve this new issue?
> I thank you very much in advance for your help on this one.
> Philippe
>
> -----Message d'origine-----
> De : ImageJ Interest Group [mailto:[hidden email]] De la part de Michael Schmid
> Envoyé : mardi 13 février 2018 16:02
> À : [hidden email]
> Objet : Re: grid.setConstraints issue with Choice
>
> Hi Philippe,
>
> my guess is that the ImageJ class loader needs a constructor with no argument for Compile&Run, e.g.
>     public GenericDialogExt() {
>       this("");
>     }
>
> Java seems to create a no-argument constructor by itself only if there is no other constructor (The GenericDialog has a constructor with a String argument).
>  
> https://stackoverflow.com/questions/3078389/why-do-we-need-a-default-no-argument-constructor-in-java#4490416
>
> Michael
>
> --
> 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: grid.setConstraints issue with Choice

CARL Philippe (LBP)
Hi again Michael,

> In that case, we have to ask Wayne whether he would agree to have a modification of the GenericDialog to have more that one item per line.

I had exactly the same idea meanwhile and actually just did this, tested it and it works!!!
So the code can be found under the following link:
http://punias.free.fr/ImageJ/GenericDialog.java

It would be nice if Wayne would like to integrate it, otherwise I will replace the original GenericDialog class with this one in my IJ.jar file each time I would need to compile this plugin.

Kindest regards,

Philippe

-----Message d'origine-----
De : ImageJ Interest Group [mailto:[hidden email]] De la part de Michael Schmid
Envoyé : mercredi 14 février 2018 14:34
À : [hidden email]
Objet : Re: grid.setConstraints issue with Choice

Hi Philippe,

do you need the DialogListener interface for preview?
If not, you can remove all the DialogListener stuff (e.g. use sparate
listeners) or create your own DialogListenerExt interface.

If you want preview, I see no nice solution.
Preview is done by the combination of the PlugInFilter implementing the DialogListener, the GenericDialog, and the PlugInFilterRunner, you can have it only with a GenericDialog.

In that case, we have to ask Wayne whether he would agree to have a modification of the GenericDialog to have more that one item per line.

Maybe this is something that others might also like?

I had already a few cases where I would have liked to have a number and a checkbox in one line, e.g. for keeping some parameters fixed in optimization/curve fitting, or several pairs of numbers (ranges).

[For some applications like this, there would another small problem:
In many cases, the second item in the line would not have a unique label, e.g. for fixing some parameters, there would be several checkboxes with 'fix', or for several ranges, there would be just a 'to'
between the numbers. Then it would not be macro-recordable.]


Best,

Michael
________________________________________________________________
On 14/02/2018 13:41, Philippe CARL wrote:

> Hi Michael,
> Your suggestion was indeed correct and I was then able to compile the GenericDialogExt code after disabling 2-3 things from the code (like code referring to "((DialogListener)dialogListeners.elementAt(i)).dialogItemChanged(this, e)").
> But then when I try to compile the code that using this newly compiled class it doesn't accept that I use:
> public boolean dialogItemChanged(GenericDialogExt gd, AWTEvent e) but
> I have to overwrite the method using:
> public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) But if
> I do so then there isn't any more a dialogItemChanged detection on the defined GenericDialogExt window.
> How can I solve this new issue?
> I thank you very much in advance for your help on this one.
> Philippe
>
> -----Message d'origine-----
> De : ImageJ Interest Group [mailto:[hidden email]] De la part de
> Michael Schmid Envoyé : mardi 13 février 2018 16:02 À :
> [hidden email] Objet : Re: grid.setConstraints issue with Choice
>
> Hi Philippe,
>
> my guess is that the ImageJ class loader needs a constructor with no argument for Compile&Run, e.g.
>     public GenericDialogExt() {
>       this("");
>     }
>
> Java seems to create a no-argument constructor by itself only if there is no other constructor (The GenericDialog has a constructor with a String argument).
>  
> https://stackoverflow.com/questions/3078389/why-do-we-need-a-default-n
> o-argument-constructor-in-java#4490416
>
> Michael
>
> --
> 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