Page 1 of 1

Custom image icons in a workspace access plugin

Posted: Wed May 12, 2021 1:12 pm
by jakubsimek
Dear list,

May I ask for help with the way how to include custom image icons for a toolbar in a standalone workspace access plugin extension?

Unfortunately I cannot find any documentation to the "ro.sync.ui.Icons.getIcon(String iconKey)" mentioned in another post here ([topic12826.html]).

I am (naively?) trying something like to following line to put an image into a button:

Code: Select all

Button btn = new Button("text",new ImageIcon("/main/resources/my_image.png")); 
The image file resides in "src/main/resources" of my Maven project.

It doesn't work however. Do I need to tell Maven somehow about copying the image into the final "jar" file?

And how would I proceed with an alternative high resolution image for Retina monitors (or with dark mode images)?

Sorry for perhaps asking the obvious; I am still a newbie. Any hints are very welcome.

Best,
Jakub

---
Jakub Šimek
Heidelberg University Library

Re: Custom image icons in a workspace access plugin

Posted: Wed May 12, 2021 1:25 pm
by Radu
Hi Jakub,

Maybe you can take inspiration from some of the plugins we've built like our Git client plugin, it has the images here:

https://github.com/oxygenxml/oxygen-git ... ces/images

as you see the retina images have the "@2x.png" suffix.
And it has this Icons class which defines all icon constants and has a special method which uses our API to load the icons:

https://github.com/oxygenxml/oxygen-git ... Icons.java

The method "PluginWorkspaceProvider.getPluginWorkspace().getImageUtilities().loadIcon" will automatically load the @2 icon if running on retina displays.
Also you need to load the icon directly with the path "/resources/images/icon.png" because that's how the image is placed in the JAR library.

Regards,
Radu

Re: Custom image icons in a workspace access plugin

Posted: Wed May 12, 2021 6:08 pm
by jakubsimek
Hi Radu,

A part of my beginner problems seems to be that the "resources" directory ("src/main/resources") does not land in the "JAR" at all. I thought that this is handled by Maven correctly by default. Or do I have to tell this Maven explicitly somehow in the pom.xml file?

Neither are the "resources" being copied into the "target" directory.

Do you perhaps have an idea what I am doing wrong?

Best wishes,
Jakub

Re: Custom image icons in a workspace access plugin

Posted: Thu May 13, 2021 1:27 pm
by alex_jitianu
Hi Jakub,

The src/main/resources directory is handled by default and its content end up in the jar artifact. Its content is copied inside target/classes during the build process.

If I have a resource, src/main/resources/myfile.xml, after an mvn install :
- myfile.xml will appear in the jar file on the top level.
- target/classes/myfile.xml will exist

Is this true for your project as well?

Best regards,
Alex

Re: Custom image icons in a workspace access plugin

Posted: Tue Sep 30, 2025 10:59 am
by nh89ur168
Radu wrote: Wed May 12, 2021 1:25 pm Maybe you can take inspiration from some of the plugins we've built like our Git client plugin, it has the images here:
https://github.com/oxygenxml/oxygen-git ... ces/images
Hi Radu,

I'm also having trouble in loading custom image icon in a custom JavaScript based workspace access plugin, however the link above is no longer available on GitHub. Could you kindly provide available git repo for our reference, thanks in advance.

Best Regards,
Jeff

Re: Custom image icons in a workspace access plugin

Posted: Tue Sep 30, 2025 11:31 am
by Radu
Hi Jeff,

We made the Git plugin a private GitHub repo and thus the broken link.

Most of our plugins are Java based though, and in this case we place the icons directly in a folder path like:
https://github.com/oxygenxml/oxygen-bat ... ces/images
And the images become part of the JAR library of the plugin and are accessed in this manner.
In general once a plugin's code becomes more advanced/complex, working directly in Java on it makes sense.

For Javascript plugins, maybe this sample plugin's way of loading a custom icon will help:
https://github.com/oxygenxml/wsaccess-j ... esAndIcons

Regards,
Radu

Re: Custom image icons in a workspace access plugin

Posted: Tue Sep 30, 2025 9:14 pm
by nh89ur168
Hi Radu,
Thanks for the links. It reminds me the magic "jsDirUrl", a globally defined field that points to the folder where the JavaScript file is located.
Thank you again :D