Changing icons at runtime

I`m writing a cruise control monitor plugin.I`m required to switch between red and green icons. Is there anyway i can do this

0
8 comments
Avatar
Permanently deleted user

Where the icons should be changed?

Tom

0
Avatar
Permanently deleted user

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

0
Avatar
Permanently deleted user

akshay wrote:

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().

HTH,
Sascha

0
Avatar
Permanently deleted user


>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

0
Avatar
Permanently deleted user

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.

What is wrong here?

Alain


--
Martin Fuhrer
Fuhrer Engineering AG
http://www.fuhrer.com

0
Avatar
Permanently deleted user

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


0
Avatar
Permanently deleted user

Alexey

public final class ZoomInAction extends AbstractEditorAction {
public void update(ImageEditor imageEditor, AnActionEvent e) {




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

0
Avatar
Permanently deleted user

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


0

Please sign in to leave a comment.