How do I change the icon of the vision module? I can set icons for the components within my module, but I can't seem to change the module icon from the green puzzle that shows up by default.
Where is this applicable? (The Vision module is supplied by IA, so I wouldn't expect anything you do in your module could change anything about it.)
Sorry, that was badly worded. I added a component to the vision module, just like the Reporting component.
Ah, I see. You need to implement the getIcon(int kind)
method in your component's BeanInfo
.
That method for my NoteChart component looks like this:
@Override
public Image getIcon(int kind) {
switch (kind) {
case BeanInfo.ICON_COLOR_16x16:
case BeanInfo.ICON_MONO_16x16:
return new ImageIcon(getClass().getResource("/images/note-chart_16.png")).getImage();
case SimpleBeanInfo.ICON_COLOR_32x32:
case SimpleBeanInfo.ICON_MONO_32x32:
return new ImageIcon(getClass().getResource("/images/note-chart_32.png")).getImage();
}
return null;
}
Edit: Ooooo! You've made your own category. You'll need to investigate how the PaletteItemGroup
works. I've not done that, and wouldn't recommend it.
Pssst!
Don't use any punctuation in your component's name or description--they become the default component name, where that is forbidden.
I took the punctuation out.
What do you mean you wouldn't recommend making a category? Isn't that the only way to add your own components?
I did check out the "PaletteItemGroup", but it doesn't seem to have a way to set an Icon. However, there is a "DefaultPaletteItemGroup" that does have a "setIcon()" method. Can I use that somehow?
No, add your components to an existing category.
Hm, that's how it was setup in the example that I downloaded to get started on this.
https://docs.inductiveautomation.com/display/SE/Designer+Hook
Couple things clear from the JavaDocs:
-
CustomPaletteItemGroup
is a subclass ofDefaultPaletteItemGroup
, so you should be able to set an icon. -
The PaletteImpl has a getGroupAt(int) method that could be used to discover all of the existing palette item group names for you to re-use.
I would like to stick to my own category, since there will be about 10 components that I will add. To have them all grouped together is the way to go I think.
Indeed, there's a public icon bean property. Should be able to set any arbitrary icon on your custom group that way.
Sure, I can set an icon for each component within the group. I've been able to do that.
However, the group itself has the green puzzle icon, which I'm struggling to change.
I tried the following, but that doesn't change the icon. Note the DefaultPaletteItemGroup
DefaultPaletteItemGroup group = (DefaultPaletteItemGroup) palette.addGroup("LV Control");
group.addPaletteItem(new JavaBeanPaletteItem(HelloWorldComponent.class));
group.addPaletteItem(new JavaBeanPaletteItem(BinComponent.class));
group.setIcon((Icon) new ImageIcon(getClass().getResource("/images/lv_32.png")).getImage());
What if you construct your group completely and then pass it in to the other overload of addGroup?
PaletteItemGroup group = new CustomPaletteItemGroup("LV Control");
group.setIcon(new ImageIcon(getClass().getResource("/images/lv_32.png")).getImage());
group.addPaletteItem(new JavaBeanPaletteItem(HelloWorldComponent.class));
group.addPaletteItem(new JavaBeanPaletteItem(BinComponent.class));
palette.addGroup(group);
PaletteImpl also has an addGroup(PaletteItemGroup group)
method. Perhaps you should create a CustomPaletteItemGroup
then add it.
the addGroup("String")
is expecting a string, it won't let me put the group in there.
I tried the PaletteImpl, but still no success. The below code actually causes my group to disappear altogether.
VisionDesignerInterface sdk = (VisionDesignerInterface) context
.getModule(VisionDesignerInterface.VISION_MODULE_ID);
if (sdk != null) {
PaletteImpl palette = new PaletteImpl(sdk);
CustomPaletteItemGroup group = new CustomPaletteItemGroup("LV Control");
group.addPaletteItem(new JavaBeanPaletteItem(HelloWorldComponent.class));
group.addPaletteItem(new JavaBeanPaletteItem(BinComponent.class));
group.setIcon((Icon) new ImageIcon(getClass().getResource("/images/lv_32.png")).getImage());
palette.addGroup(group);
Don't create a new Palette or PaletteImpl. Cast the Vision palette to PaletteImpl so you can use the overload of addGroup().
This is what I have right now, and my group won't show up at all in the vision component palette
PaletteImpl palette = (PaletteImpl) sdk.getPalette();
CustomPaletteItemGroup group = new CustomPaletteItemGroup("LV Control");
group.addPaletteItem(new JavaBeanPaletteItem(HelloWorldComponent.class));
group.addPaletteItem(new JavaBeanPaletteItem(BinComponent.class));
group.setIcon((Icon) new ImageIcon(getClass().getResource("/images/lv_32.png")).getImage());
palette.addGroup(group);