Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

All gui swing classes uses the IconBundle class to get there icons. This class is managing ImageIcons to avoid having two times the same image loaded in memory, if the image has allready been loaded it will return you the same reference.

Isn't it a little heavy to load images and images in memory like this?
Don't worry, this class use weakreferences for ImageIcons, so they are remove by the Garbage Collector when no one uses them.

I consider icons as not important and should never block the program, that's why the IconBundle class will never return errors, in the worst case (can not fine the image) it will return a 1x1 transparant ImageIcon.

Changing/adding icons

make a property file :

Code Block
16_zoom_pan=/my/project/icon/bat.png
16_mapcontext_enable=/my/project/icon/openegg.png
16_mapcontext_disable=/my/project/icon/egg.png
16_style=/my/project/icon/balloons.png
...
  • You can find the keys in the default file :
    org.geotools.gui.swing.icon.defaultset.properties
  • You don't have to replace all keys, if a key if missing in your list the
    IconBundle class will go find it in the default icon set.
  • To add icons just add your own keys in the file, the IconBundle class
    will handle them for you.

Once the file is ready, load it once at startup in the IconBundle :

Code Block
ResourceBundle bundle =  ResourceBundle.getBundle( path_to_new_bundle );
IconBundle.getResource().setBundle( bundle );

Getting an icon

nothing simpler :

Code Block
ImageIcon img = IconBundle.getResource().getIcon("maplayer_visible");