Hi all
I'm having a go at writing a dialog that responds to input by changing the the numbers and text it's displaying, which are then assigned to variables after OK is hit and gd.getNextNumber() etc. are called. Specifically I want the user to identify whether a particular state is true (their images are or are not Hounsfield unit calibrated) and (un)tick a checkbox, then enter thresholds based on HU calibrated or raw values. So, the values that have to change are the ones in the threshold boxes: gd.addNumericField("Bone Min:", this.min, 0, 6, pixUnits); this.min would change from the raw value to the calibrated value and pixUnits would change from "grey" to "HU". I had a go writing this with a DialogListener, using ij.plugin.SpecifyROI.java as an example, but have not been able to get my dialog box to update when the HU box is ticked. Any ideas or pointers to examples are welcome, Michael |
Hi Michael,
as fat as I understand it you want to change the text in a numeric field after the dialog has been displayed? You have to get the vector of nummeric input fields, Vector nFields = gd.getNumericFields(); then extract the element at the correct position, cast it to java.awt.TextField and do a setText(String), with a String representing the number of your choice. If it should be in response to a checkbox, do it in the DialogItemStateChanged method of your plugin (it has to register as a DialogListener for that) or as an ItemListener of the checkbox - you get the reference to it from the vector obtained by gd.getCheckboxes(). Michael ________________________________________________________________ On 1 Apr 2010, at 15:20, Michael Doube wrote: > Hi all > > I'm having a go at writing a dialog that responds to input by changing > the the numbers and text it's displaying, which are then assigned to > variables after OK is hit and gd.getNextNumber() etc. are called. > > Specifically I want the user to identify whether a particular state is > true (their images are or are not Hounsfield unit calibrated) and > (un)tick a checkbox, then enter thresholds based on HU calibrated > or raw > values. > > So, the values that have to change are the ones in the threshold > boxes: > > gd.addNumericField("Bone Min:", this.min, 0, 6, pixUnits); > > this.min would change from the raw value to the calibrated value and > pixUnits would change from "grey" to "HU". > > I had a go writing this with a DialogListener, using > ij.plugin.SpecifyROI.java as an example, but have not been able to get > my dialog box to update when the HU box is ticked. > > Any ideas or pointers to examples are welcome, > > Michael |
Thanks for your response Michael. Looks complicated; I'll have a go
this evening. > as fat as I understand it you want to change the text in a numeric > field after the dialog has been displayed? Yes, and also the units to the right of the numeric field. But I can deal with each of these issues one at a time... Michael |
Hi Michael,
changing the contents of the numeric field is not so difficult as it may seem, see the Fast_Filters for an example. There the x radius and y radius fields are synchronized if a checkbox is on. http://imagejdocu.tudor.lu/doku.php? id=plugin:filter:fast_filters:start For the units - hm, I fear that this will be more complicated. In GenericDialog you can get no reference to the Label where the units are displayed. You would have to iterate through the components of the GenericDialog (gd.getComponents(), a method of the Container class) and find the correct one (maybe it is the one after the TextField that you want to modify, but I am not sure). Michael ________________________________________________________________ On 1 Apr 2010, at 19:57, Michael Doube wrote: > Thanks for your response Michael. Looks complicated; I'll have a go > this evening. > >> as far as I understand it you want to change the text in a numeric >> field after the dialog has been displayed? > > Yes, and also the units to the right of the numeric field. But I can > deal with each of these issues one at a time... > > > Michael |
> changing the contents of the numeric field is not so difficult as it
> may seem, Correct; already done. > For the units - hm, I fear that this will be more complicated. In > GenericDialog you can get no reference to the Label where the units > are displayed. You would have to iterate through the components of > the GenericDialog (gd.getComponents(), a method of the Container > class) and find the correct one (maybe it is the one after the > TextField that you want to modify, but I am not sure). Well, that is at least a place to start, thank you. Michael |
Michael,
>> For the units - hm, I fear that this will be more complicated. In >> GenericDialog you can get no reference to the Label where the units >> are displayed. You would have to iterate through the components of >> the GenericDialog (gd.getComponents(), a method of the Container >> class) and find the correct one (maybe it is the one after the >> TextField that you want to modify, but I am not sure). You have to iterate through all the Components, then get a reference to each Panel Component, then get the Label from the Panel's 1st Component. Then you get access to the Label's getText() and setText() methods. I have written a method, replaceUnitString(), that does this. http://github.com/mdoube/BoneJ/commit/6885d1b0489fed0811027401a04e737fbe26337c Thanks again for your suggestions, Michael |
Free forum by Nabble | Edit this page |