Login  Register

Re: addSlider question

Posted by Xavier Colomé on Dec 03, 2014; 7:06am
URL: http://imagej.273.s1.nabble.com/addSlider-question-tp5010711p5010731.html

Hi Jan. Thank you so much.

I can see my error now!

Best regards

2014-12-02 18:54 GMT+01:00 Jan Eglinger <[hidden email]>:

> Hi again,
>
> I modified your script to make it compile and display the values:
>
> https://gist.github.com/imagejan/f238e6a5a7d49b597329
>
> On 02.12.14 17:53, Xavier Colomé wrote:
>
>> I had tried so but I get a compile error when I use...
>>    IJ.log("Slider 1 value: "+gd.getSliders().get(0).getValue());
>>
>> But works file when I compile as:
>>
>>    IJ.log("Slider 1 value: "+gd.getSliders().get(0));
>>
>> the same issue when I use by example:
>>
>> Scrollbar firstSlider = gd.getSliders().get(0);
>>
>>
> In my first post, I forgot to cast the object to Scrollbar:
>
>   Scrollbar slider1 = (Scrollbar)gd.getSliders().get(0);
>
> In addition, I'm using the IJ.d2s() method for logging the value returned
> by getValue().
>
> >> (See the javadoc [1] for more details)
>
> I see I forgot to include the link in my previous post:
> [1]: http://javadoc.imagej.net/Java6/index.html?java/awt/Scrollbar.html
>
>  We can see the next error:
>>
>> "java.lang.ClassNotFoundExcepcion: Dialog_Test"
>>
>> Maybe I need to add another "Import*.*"?
>>
>
> You should try to avoid wildcard imports, since they can generate trouble
> when reusing the script in a different environment [2].
>
> Cheers,
> Jan
>
> [2]: http://imagej.1557.x6.nabble.com/TextField-in-Fiji-
> tp5005091p5005098.html
>
>
>
>
>> 2014-12-02 16:07 GMT+01:00 Jan Eglinger <[hidden email]>:
>>
>>  Hi Xavier,
>>>
>>>       IJ.log("Slider 1 value: "+gd.getSliders().get(0));
>>>>
>>>
>>> You probably want
>>>
>>>      IJ.log("Slider 1 value: "+gd.getSliders().get(0).getValue());
>>>
>>> here.
>>>
>>>    gd.getSliders()         => Vector containing the Scrollbar objects
>>>    gd.getSliders().get(0)  => the first Scrollbar object
>>>    gd.getSliders().get(0).getValue()=> the *value* of the first
>>> scrollbar
>>>
>>>
>>>  How can I set the slider 1 value to slider 2?
>>>>
>>>
>>> If you assign the Scrollbars to variables:
>>>
>>>    Scrollbar firstSlider = gd.getSliders().get(0);
>>>    Scrollbar secondSlider = gd.getSliders().get(1);
>>>
>>> you can set the values as such:
>>>
>>>    secondSlider.setValue(firstSlider.getValue);
>>>
>>> (See the javadoc [1] for more details)
>>>
>>>
>>> Since the GenericDialog sliders are a combination of `Scrollbar` and
>>> `TextField`, you might want to update the values of both in your plugin
>>> dialog.
>>>
>>> Cheers,
>>> Jan
>>>
>>>
>>>
>>>
>>> On 02.12.14 15:16, Xavier Colomé wrote:
>>>
>>>  Thank you. I'm testing with two dimensions X and Y but can not get the
>>>> slider1 value and set to slider2...
>>>>
>>>> import ij.*;
>>>> import ij.gui.GenericDialog;
>>>> import ij.gui.DialogListener;
>>>> import ij.ImagePlus;
>>>> import ij.process.*;
>>>> import ij.plugin.PlugIn;
>>>> import ij.gui.*;
>>>> import java.awt.*;
>>>>
>>>> public class Dialog_Test implements PlugIn, DialogListener {
>>>>       private static GenericDialog gd;
>>>>       String text;
>>>>
>>>>       public void run(String arg) {
>>>>           showDialog();
>>>>           IJ.log("Text: "+text);
>>>>       }
>>>>
>>>>       void showDialog() {
>>>>           gd = new GenericDialog("Test Dialog");
>>>>           gd.addSlider("X", 0, 100, 0);
>>>>           gd.addSlider("Y", 0, 200, 0);
>>>>           gd.addDialogListener(this);
>>>>           gd.showDialog();
>>>>       }
>>>>
>>>>
>>>>       public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
>>>>
>>>>           final double Valor_X = gd.getNextNumber();
>>>>           final double Valor_Y = gd.getNextNumber();
>>>>           IJ.log("Slider 1 value: "+gd.getSliders().get(0));
>>>>
>>>>           // I want to set  Slider 1 value to Slicder2...
>>>>
>>>>
>>>>           return true;
>>>>       }
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>> How can I set the slider 1 value to slider 2?
>>>>
>>>> Thank you and best regards!
>>>>
>>>> 2014-12-02 11:35 GMT+01:00 Jan Eglinger <[hidden email]>:
>>>>
>>>>   Hi Xavier,
>>>>
>>>>>
>>>>>
>>>>> On 01.12.14 17:54, Xavier Colomé wrote:
>>>>>
>>>>>   Hello, I'm testing with dialogs and I want to create three sliders
>>>>> that
>>>>>
>>>>>> interact with each other. The sum of the three slider must total 100%.
>>>>>> By
>>>>>> example:
>>>>>>
>>>>>> X [----*-----] [5]
>>>>>> Y [--*-------] [3]
>>>>>> Z [-*--------] [2]
>>>>>>
>>>>>> By example, if I move one of te three slider to 100% then we can not
>>>>>> move
>>>>>> the other two slider above 0%
>>>>>>
>>>>>> By example, this is a not permited configuration:
>>>>>>
>>>>>> X [---*------] [4]
>>>>>> Y [------*---] [7]
>>>>>> Z [-*--------] [2]
>>>>>>
>>>>>> Is it possible?
>>>>>>
>>>>>>
>>>>>>   You can use the ij.gui.DialogListener class [1] for this. Your
>>>>>> plugin
>>>>>>
>>>>> should implement `DialogListener` and include a `dialogItemChanged`
>>>>> method
>>>>> that set the slider values according to your constraints.
>>>>>
>>>>> Below I paste the code of a python script that has three sliders
>>>>> (X,Y,Z)
>>>>> whose values always sum up to 100. Just paste it into Fiji's script
>>>>> editor
>>>>> and press "Run". It has limited functionality (the Z slider cannot be
>>>>> adjusted on its own), but you might get the idea.
>>>>>
>>>>> Hope that helps,
>>>>> Jan
>>>>>
>>>>> [1]: http://javadoc.imagej.net/ImageJ1/index.html?ij/gui/
>>>>> DialogListener.html
>>>>>
>>>>>
>>>>> ********* Python script to demonstrate slider listeners ***********
>>>>>
>>>>> from ij import IJ
>>>>> from ij.gui import DialogListener
>>>>> from ij.gui import GenericDialog
>>>>>
>>>>> class MyDL (DialogListener):
>>>>>           def dialogItemChanged(self, dialog, event):
>>>>>                   x = dialog.getNextNumber()
>>>>>                   y = dialog.getNextNumber()
>>>>>                   z = dialog.getNextNumber()
>>>>>                   sliders = dialog.getSliders()
>>>>>                   numFields = dialog.getNumericFields()
>>>>>                   zSlider = sliders.get(2)
>>>>>                   zField = numFields.get(2)
>>>>>                   zSlider.setValue((int)(100-(x+y)))
>>>>>                   zField.setText(IJ.d2s(100-(x+y), 0))
>>>>>                   return 1
>>>>>
>>>>> gd = GenericDialog("Slider Listener")
>>>>> gd.addSlider("X", 0, 100, 50)
>>>>> gd.addSlider("Y", 0, 100, 20)
>>>>> gd.addSlider("Z", 0, 100, 30)
>>>>> gd.addDialogListener(MyDL())
>>>>> gd.showDialog()
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>  --
>>>> 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