Custom image icons in a workspace access plugin

Post here questions and problems related to oXygen frameworks/document types.
jakubsimek
Posts: 11
Joined: Fri Oct 04, 2019 11:26 pm

Custom image icons in a workspace access plugin

Post 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
Radu
Posts: 8992
Joined: Fri Jul 09, 2004 5:18 pm

Re: Custom image icons in a workspace access plugin

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
jakubsimek
Posts: 11
Joined: Fri Oct 04, 2019 11:26 pm

Re: Custom image icons in a workspace access plugin

Post 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
alex_jitianu
Posts: 1007
Joined: Wed Nov 16, 2005 11:11 am

Re: Custom image icons in a workspace access plugin

Post 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
Post Reply