Let's Tango! (Swing icons)

Icons are very important for creating user interfaces. What about icon sets for Swing? I'm tired of having to google, download, pack and use icons for my Swing applications. Things should be easier. I'd like to visually select icons in NetBeans. What about building some icon themes for Swing that we can swap at runtime? And... what about a NetBeans module?

Icon collections out there

The icons at Java Look and Feel Graphics Repository have been around for quite a long time now. Some other icon collections out there are, indeed, impressive. Here's a short list (I'd appreciate any other pointers):

One spec to rule them all?

So the problem with all these icon sets is that each icon has different names. And if you use one icon set (by the way, remember to give proper credit and to verify licensing terms) you cannot swap it and use another. And you spend lots of time downloading, selecting, selecting (again), selecting (yes, again) and attaching icons to your widgets. And, well, many icons are duplicated in different places.

So I'm glad to see there's an Icon Naming Specification at FreeDesktop.org. That's good for both icon users and icon developers, I think. The idea is to have "standard" names for icons, so that everybody agrees on them and things are easier to manage.

This is very important for Linux distros and Linux applications, that should follow another Icon Theme Specification to pack their icons.

So, what about Swing?

And, well, to solve the problem I've decided to build a simple-to-use library to pack some of these icon sets. I think this is a good idea both for Swing developers and for icon authors (that may advertise their work, too).

I'm still thinking of the high-level architecture of this stuff, and I wanted to share it with you so as to get some early feedback on it.

Icon Dependency Diagram

My idea is to split the library in the following different pieces (separate projects with dependencies):

  • An IconNaming part, responsible for assigning Java constants to icon names. The idea is to make this follow the Icon Naming Specification as much as possible, and that part of the Icon Theme Spec, too. This should contain the constants and an Icon Theme interface.

  • An IconManager part, responsible for :

    • retrieving icons given their names (names as defined in the IconNaming part)
    • caching icons in memory (to reduce memory footprint).
    • locating and instantiating a given "Icon Theme".
    • registering visual PropertyEditors to visually select icons
  • Different icon themes, that contain the real icons. These could contain, for instance, some of the icons on the Nuvola theme, or some of the icons on the Crystal Clear or Tango themes. Each icon theme should be packed

I think the dependencies should be like the ones depicted in the diagram. This is:

  • the naming part should depend on nothing else.
  • each real icon theme should depend on the icon naming only.
  • the icon manager should depend on the icon naming (compile-time dependency) and on a given icon set (run-time dependency).

The idea is to solve the run-time dependencies (deciding which icon theme is actually used) using something similar to JNDI or NetBeans lookup mechanisms.

Some stuff I'm still considering:

  • Using icon-theme inheritance, so if a given icon is not present in a given icon theme then get the icon from another (parent) theme.
  • Using a default theme with dummy icons, just in case no icon theme is present.

Visual icon choosers, please!!

NetBeans Form Editor is a great piece of software. It's possibly the best one for Swing development I've seen (I've been told IDEA and JBuilder have great stuff, too). I would like to have visual icon choosers for as many IDEs as possible, so that selecting a given icon is not a pain in the neck (well, at least until I learn the standard icon names and I can do it by typing an icon name in a text field).

I think I'll start with NetBeans first. Then possibly build some stuff for IDEA or JBuilder.

Feedback appreciated!!

I'd appreciate thoughts, ideas and complaints about this icon manager effort. Please either leave a comment on this entry or send me an email.

Thanks and happy Swinging (at least until I can wish you a happy Tango-ing ;-)),


blog comments powered by Disqus