The icons are on the toolbar. They are required to change automatically depending on the Cruise control status. So i need a way to switch between green and red icons
The icons are on the toolbar. They are required to change automatically depending on the Cruise control status. So i need a way to switch between green and red icons
I think this can be done by overriding the update(ActionEvent) method of your AnAction implementation and calling event.getPresentation().setIcon().
>I think this can be done by overriding the update(ActionEvent) method of your AnAction >implementation and calling event.getPresentation().setIcon(). >
>
Rawly applied, it works only once. Later setIcon() calls have no effect.
Initial setting of the icon: DefaultActionGroup mainToolBar = (DefaultActionGroup) ActionManager.getInstance().getAction("MainToolBar"); __noopAction = new AnAction(){ public void actionPerformed (AnActionEvent e) { } }; mainToolBar.add(__noopAction); __noopAction.getTemplatePresentation().setIcon(image_1);
When later I do another: __noopAction.getTemplatePresentation().setIcon(image_2); it has no effect.
I'm not quite sure about those things, but IMHO the template presentation is only used to initialize the real presentation. Once the real presentation is created calls to change the template presentaion won't have any effect.
Try Sascha's suggestion: event.getPresentation().setIcon(). Here you are changing the real presentation, not the template.
Alain Ravet wrote:
>> I think this can be done by overriding the update(ActionEvent) method >> of your AnAction >> implementation and calling event.getPresentation().setIcon(). >> >> >>
Rawly applied, it works only once. Later setIcon() calls have no effect.
Initial setting of the icon: DefaultActionGroup mainToolBar = (DefaultActionGroup) ActionManager.getInstance().getAction("MainToolBar"); __noopAction = new AnAction(){ public void actionPerformed (AnActionEvent e) { } }; mainToolBar.add(__noopAction); __noopAction.getTemplatePresentation().setIcon(image_1);
When later I do another: __noopAction.getTemplatePresentation().setIcon(image_2); it has no effect.
AR> If the code that wants to update the toolbar icon is not part of an AR> action, - ex: a background task running in a plugin - AR> there is no action event ?!
The 'update' method is invoked by internal timer in IDEA. Infinity triggered by timer task.
Where the icons should be changed?
Tom
The icons are on the toolbar. They are required to change automatically depending on the Cruise control status. So i need a way to switch between green and red icons
akshay wrote:
I think this can be done by overriding the update(ActionEvent) method of your AnAction
implementation and calling event.getPresentation().setIcon().
HTH,
Sascha
>I think this can be done by overriding the update(ActionEvent) method of your AnAction
>implementation and calling event.getPresentation().setIcon().
>
>
Rawly applied, it works only once. Later setIcon() calls have no effect.
Initial setting of the icon:
DefaultActionGroup mainToolBar = (DefaultActionGroup)
ActionManager.getInstance().getAction("MainToolBar");
__noopAction = new AnAction(){ public void actionPerformed
(AnActionEvent e) { } };
mainToolBar.add(__noopAction);
__noopAction.getTemplatePresentation().setIcon(image_1);
When later I do another:
__noopAction.getTemplatePresentation().setIcon(image_2);
it has no effect.
What is wrong here?
Alain
I'm not quite sure about those things, but IMHO the template
presentation is only used to initialize the real presentation. Once the
real presentation is created calls to change the template presentaion
won't have any effect.
Try Sascha's suggestion: event.getPresentation().setIcon(). Here you are
changing the real presentation, not the template.
Alain Ravet wrote:
>> I think this can be done by overriding the update(ActionEvent) method
>> of your AnAction
>> implementation and calling event.getPresentation().setIcon().
>>
>>
>>
--
Martin Fuhrer
Fuhrer Engineering AG
http://www.fuhrer.com
Hello Alain,
AR> Rawly applied, it works only once. Later setIcon() calls have no
AR> effect.
Just checkit out on one of my actions:
--
public final class ZoomInAction extends AbstractEditorAction {
private boolean f = false;
public void actionPerformed(ImageEditor imageEditor, AnActionEvent e) {
ImageZoomModel zoomModel = imageEditor.getZoomModel();
zoomModel.zoomIn();
}
public void update(ImageEditor imageEditor, AnActionEvent e) {
super.update(imageEditor, e);
ImageZoomModel zoomModel = imageEditor.getZoomModel();
Presentation presentation = e.getPresentation();
presentation.setEnabled(zoomModel.canZoomIn());
if (f) {
presentation.setIcon(IconLoader.getIcon("/org/intellij/images/icons/ZoomOut.png"));
} else {
presentation.setIcon(IconLoader.getIcon("/org/intellij/images/icons/ZoomIn.png"));
}
f = !f;
}
}
--
It works fine and change icon twice per second.
Thanks
--
Alexey Efimov, Java Developer
Tops BI
Alexey
If the code that wants to update the toolbar icon is not part of an
action, - ex: a background task running in a plugin -
there is no action event ?!
Alain
Hello Alain,
AR> If the code that wants to update the toolbar icon is not part of an
AR> action, - ex: a background task running in a plugin -
AR> there is no action event ?!
The 'update' method is invoked by internal timer in IDEA. Infinity triggered
by timer task.
--
Alexey Efimov, Java Developer
Tops BI