public Icon getIcon ( String iconSet , int index ) { try { // see if the tileset is already loaded TileSet set = _icons . get ( iconSet ) ; // load it up if not if ( set == null ) { String path = _config . getProperty ( iconSet + PATH_SUFFIX ) ; if ( StringUtil . isBlank ( path ) ) { throw new Exception ( "No path specified for icon set" ) ; } String metstr = _config . getProperty ( iconSet + METRICS_SUFFIX ) ; if ( StringUtil . isBlank ( metstr ) ) { throw new Exception ( "No metrics specified for icon set" ) ; } int [ ] metrics = StringUtil . parseIntArray ( metstr ) ; if ( metrics == null || metrics . length != 2 ) { throw new Exception ( "Invalid icon set metrics " + "[metrics=" + metstr + "]" ) ; } // load up the tileset if ( _rsrcSet == null ) { set = _tilemgr . loadTileSet ( path , metrics [ 0 ] , metrics [ 1 ] ) ; } else { set = _tilemgr . loadTileSet ( _rsrcSet , path , metrics [ 0 ] , metrics [ 1 ] ) ; } // cache it _icons . put ( iconSet , set ) ; } // fetch the appropriate image and create an image icon return new TileIcon ( set . getTile ( index ) ) ; } catch ( Exception e ) { log . warning ( "Unable to load icon [iconSet=" + iconSet + ", index=" + index + ", error=" + e + "]." ) ; } // return an error icon return new ImageIcon ( ImageUtil . createErrorImage ( 32 , 32 ) ) ; }
Fetches the icon with the specified index from the named icon set .