Action Tool Icon Toggle

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

Action Tool Icon Toggle

Alan Brooks
Is there a way to dynamically update the icon for an action tool from a Java PlugIn or Macro PlugIn? I am making a tool that toggles between two states and I’d like to update the icon to represent the state.

Alan

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

Re: Action Tool Icon Toggle

Wayne Rasband-2
> On Jan 15, 2021, at 8:51 AM, Alan Brooks <[hidden email]> wrote:
>
> Is there a way to dynamically update the icon for an action tool from a Java PlugIn or Macro PlugIn? I am making a tool that toggles between two states and I’d like to update the icon to represent the state.

The latest daily build (1.53h46) adds a Toolbar.setIcon(name,icon) method that allows macros and plugins to update tool icons. The action tool below uses this method to toggle between blue square and red circle icons. I am trying to figure out why the icon sometimes flashes when it is updated.

-wayne
 

  var state = 1

  macro "Toggle Icon Action Tool - C00cF00ff" {
       if (state==1) {
          call("ij.gui.Toolbar.setIcon", "Toggle Icon Action Tool", "Cc00V00ff");
          state = 2;
       } else {
          call("ij.gui.Toolbar.setIcon", "Toggle Icon Action Tool", "C00cF00ff");
          state = 1;
       }
  }

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

Re: Action Tool Icon Toggle

Alan Brooks
Thanks, Wayne. This API is exactly what I was after.

I also see the visual flickering and sometimes also see the blue square / red circle update again when I interact with a different tool such as switching from the Rectangle to Oval selection tool. It is as if the some clicks are missed and they catch up the next time I interact with the Toolbar?

Alan


> On Jan 15, 2021, at 9:07 PM, Wayne Rasband <[hidden email]> wrote:
>
>> On Jan 15, 2021, at 8:51 AM, Alan Brooks <[hidden email]> wrote:
>>
>> Is there a way to dynamically update the icon for an action tool from a Java PlugIn or Macro PlugIn? I am making a tool that toggles between two states and I’d like to update the icon to represent the state.
>
> The latest daily build (1.53h46) adds a Toolbar.setIcon(name,icon) method that allows macros and plugins to update tool icons. The action tool below uses this method to toggle between blue square and red circle icons. I am trying to figure out why the icon sometimes flashes when it is updated.
>
> -wayne
>
>
>  var state = 1
>
>  macro "Toggle Icon Action Tool - C00cF00ff" {
>       if (state==1) {
>          call("ij.gui.Toolbar.setIcon", "Toggle Icon Action Tool", "Cc00V00ff");
>          state = 2;
>       } else {
>          call("ij.gui.Toolbar.setIcon", "Toggle Icon Action Tool", "C00cF00ff");
>          state = 1;
>       }
>  }
>
> --
> 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: Action Tool Icon Toggle

Wayne Rasband-2
> On Jan 16, 2021, at 12:21 AM, Alan Brooks <[hidden email]> wrote:
>
> Thanks, Wayne. This API is exactly what I was after.
>
> I also see the visual flickering and sometimes also see the blue square / red circle update again when I interact with a different tool such as switching from the Rectangle to Oval selection tool. It is as if the some clicks are missed and they catch up the next time I interact with the Toolbar?

The flickering problem is fixed in the 1.53h48 daily build. The daily build also adds Jerome Mutterer’s very cool Help>Examples>Tools>Animated Icon Tool demo.

-wayne

>> On Jan 15, 2021, at 9:07 PM, Wayne Rasband <[hidden email]> wrote:
>>
>>> On Jan 15, 2021, at 8:51 AM, Alan Brooks <[hidden email]> wrote:
>>>
>>> Is there a way to dynamically update the icon for an action tool from a Java PlugIn or Macro PlugIn? I am making a tool that toggles between two states and I’d like to update the icon to represent the state.
>>
>> The latest daily build (1.53h46) adds a Toolbar.setIcon(name,icon) method that allows macros and plugins to update tool icons. The action tool below uses this method to toggle between blue square and red circle icons. I am trying to figure out why the icon sometimes flashes when it is updated.
>>
>> -wayne
>>
>>
>> var state = 1
>>
>> macro "Toggle Icon Action Tool - C00cF00ff" {
>>      if (state==1) {
>>         call("ij.gui.Toolbar.setIcon", "Toggle Icon Action Tool", "Cc00V00ff");
>>         state = 2;
>>      } else {
>>         call("ij.gui.Toolbar.setIcon", "Toggle Icon Action Tool", "C00cF00ff");
>>         state = 1;
>>      }
>> }

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