/** * Gets the next available size of the requested size. If the size is available in the icon set, it will be * returned. Otherwise, the next size that is bigger than the requested size will be returned. For example, if there * are 16, 24, 32, 48, 64 size available. If the requested size is 12, 16 will be returned. If 24 is requested, 24 * will be returned. If 60 is requested, 64 will be returned. If 128 is requested and it is not available, so 64 * will be returned. * * @param size the requested size * @return the next available size. */ public int getNextAvailableSize(int size) { int[] sizes = getAvailableSizes(); int nextSize = sizes[sizes.length - 1]; for (int i : sizes) { if (i == size) { return i; } if (i > size && i < nextSize) { nextSize = i; } } return nextSize; }
/** * Gets the ImageIcon. * * @param iconName the icon name as defined in IconSet. * @param size the icon size. If the size is not available, it will find the closest size that is larger than * the requested size. * * @return the ImageIcon. */ public ImageIcon getImageIcon(String iconName, int size) { String packageName = _activeIconSet.getPackageName(); int actualSize = _activeIconSet.getNextAvailableSize(size); String fullIconName = packageName + "/png/" + actualSize + "x" + actualSize + "/" + iconName; ImageIcon icon = IconsFactory.getImageIcon(IconSetManager.class, fullIconName); if (actualSize == size) { return icon; } else { return IconsFactory.getScaledImage(null, icon, size, size); } }
public void add(String name, int[] sizes, String packageName) { if (_availableStyles == null) { _availableStyles = new HashMap<String, IconSet>(); } _availableStyles.put(name, new IconSet(name, sizes, packageName)); if (_availableStyles.size() == 1) { setActiveIconSetName(name); } }