Tango! Mambo! Swing! (Swing Icons II)
Building Swing icon sets (and a Swing Icon Viewer!) with... properties files? Why not? After all icon designers don't need to know Java. They're doing an excellent job building icons, so I don't see a reason why they should know Java. A small Java Web Start demo is included.
Tango! Properties files
These are easy to use. Everybody knows how to build a properties file. It's easy.
So the idea is to use standard icon names (and a suffix with a size, say "small", "medium" and "large") to indicate where real icons really are. Something like this:
Excerpt from tango-mini.properties file: 1 # 2 # Tango! mini icon set definition file. 3 # 4 icon-theme.name=Tango! mini : A small subset of Tango! 5 icon-theme.author=See http://tango.freedesktop.org/The_People to meet the Tango! team 6 icon-theme.license=Creative Commons Attribution Share-Alike license 7 actions/address-book-new.small=net/antonioshome/swing/icons/tangomini/small/actions/address-book-new.png 8 actions/address-book-new.medium=net/antonioshome/swing/icons/tangomini/medium/actions/address-book-new.png 9 actions/address-book-new.large=net/antonioshome/swing/icons/tangomini/large/actions/address-book-new.png 10 actions/application-exit.small=net/antonioshome/swing/icons/tangomini/small/actions/application-exit.png 11 actions/application-exit.medium=net/antonioshome/swing/icons/tangomini/medium/actions/application-exit.png
The advantage of using these properties files is that one can easily augment them to, say, include mnemonics, action names, and the such (as Nicola suggested).
And, well, of course, you can easily build your own custom theme with your preferred icons: Just include the path to the resource for a given (standard icon name). So, for instance, if you have a nice icon for address books in the path "com/mycompany/icons/addressbook16x16.gif" inside the jar file you can say:
10 actions/address-book-new.small=com/mycompany/icons/addressbook16x16.gif
I've downloaded the Java Look and Feel Graphics Repository and I've done just that: map some standard icon names to JLFGR resources (you can see the jlfgr.properties file ). Since this is a demo I just wanted to add a few icons, so the list is not really exhaustive. The Icon Chooser allows you to switch between different icon themes (Tango! and JLFGR at the moment) built with these properties files.
One Master Properties File... to rule them all
So the idea is to build a jar file with all icons and a properties file (say "tango-mini.properties", or "jlfgr.properties") in the format above.
Now, how do you find that properties file inside the jar file?
What I've done is to use another Master Properties File (located always in the "/icon-themes.properties" that contains the path to the previous properties file). For instance, if I want to build a "jar" file with two icon sets I'd do something like this:
(/icon-themes.properties) 1 # 2 # Contains a list of all icon theme property files in this jar 3 # 4 tango=tango/tango.properties
That way you can bundle different icon themes within a single jar file.
Transforming properties files into icon sets
Of course I could have used the Jar Service Provider Specification and build an IconTheme interface and place actual implementations of those in a META-INF/services directory.
But Ethan Nicolas' Blog "Creating a Service Provider Interface" contains a much better approach, that needs no interfaces at all. Let me explain.
As Echan Nicolas says, the ClassLoader.getResources() is a good way to find things in the current classloader. I can find all "Master Properties Files" by doing:
90 Enumeration iconThemeProperties = aClassLoader.getResources("icon-themes.properties");
I can then read all those master properties files and, in turn, determine what the paths to each icon property definition file are. And then read them.
I think this is a good approach because icon packs can be built declaratively: no Java coding is necessary (this is good for icon designers, of course. After all there're some use cases for icon designers in this software, right?). You just need a master properties file (located in /icon-themes.properties) and then another icon pack definition file for each one of the icon sets you want.
And, well, properties files are an easy way to extend icon packs too (you can add mnemonics and whatever very easily).
Now, show me the money, please!
I've been working a little bit on this and I have a preliminar Icon Editor for you to see (I need feedback on the user interface, please). This is an alpha version that does not anything really useful (just shows the icons and lets you browse different icon themes and icon contexts), but, hey, I need feedback.
Future steps include buidling a small library and working out the Property Editor. That's probably going to be a little bit of pain:
- The PropertyEditor will have to handle both standard icon names and non-standard icon paths (to be able to choose any other custom icons from the classpath).
- I'd like to build different NetBeans modules, a first one with this Icon Property Editor and different others with the icon packs themselves.
- I'll have to investigate if NetBeans classpath loading mechanism is able to find all master properties files.
- Build a .jar file (with properties like above) for the Nuvola Icon Theme (LGPL'ed) and for the Crystal Clear Theme (LGPL'ed too, I think)
So, as you can see, lots of things to investigate. I'd appreciate feedback on the icon viewer, though. (The code is under revision so I won't post it at the moment)
Please try out the (alpha version) Icon Chooser
Mambo!
If you haven't already, please visit Roumen's blog to enjoy some of the finest Mambo you can ever listen to in the Java world.
Thanks in advance, and happy Mambo-ing, Tango-ing and Swing-ing, Antonio
P.S.: I'll be traveling around North-West Spain for a while (for fun, this time, and with my camera) so I may be late with replies. My apologies by that.
blog comments powered by Disqus