IconFactorypublic class IconFactory extends Object Factory to generate icons for Android Editors.
Icons are kept here and reused. |
Fields Summary |
---|
public static final int | COLOR_RED | public static final int | COLOR_GREEN | public static final int | COLOR_BLUE | public static final int | COLOR_DEFAULT | public static final int | SHAPE_CIRCLE | public static final int | SHAPE_RECT | public static final int | SHAPE_DEFAULT | private static IconFactory | sInstance | private HashMap | mIconMap | private HashMap | mImageDescMap |
Constructors Summary |
---|
private IconFactory()
|
Methods Summary |
---|
public void | Dispose()
// Dispose icons
for (Image icon : mIconMap.values()) {
// The map can contain null values
if (icon != null) {
icon.dispose();
}
}
mIconMap.clear();
| public org.eclipse.swt.graphics.Image | getIcon(java.lang.String osName)Returns an Image for a given icon name.
Callers should not dispose it.
return getIcon(osName, COLOR_DEFAULT, SHAPE_DEFAULT);
| public org.eclipse.swt.graphics.Image | getIcon(java.lang.String osName, int color, int shape)Returns an Image for a given icon name.
Callers should not dispose it.
String key = Character.toString((char) shape) + Integer.toString(color) + osName;
Image icon = mIconMap.get(key);
if (icon == null && !mIconMap.containsKey(key)) {
ImageDescriptor id = getImageDescriptor(osName, color, shape);
if (id != null) {
icon = id.createImage();
}
// Note that we store null references in the icon map, to avoid looking them
// up every time. If it didn't exist once, it will not exist later.
mIconMap.put(key, icon);
}
return icon;
| public org.eclipse.jface.resource.ImageDescriptor | getImageDescriptor(java.lang.String osName)Returns an ImageDescriptor for a given icon name.
Callers should not dispose it.
return getImageDescriptor(osName, COLOR_DEFAULT, SHAPE_DEFAULT);
| public org.eclipse.jface.resource.ImageDescriptor | getImageDescriptor(java.lang.String osName, int color, int shape)Returns an ImageDescriptor for a given icon name.
Callers should not dispose it.
String key = Character.toString((char) shape) + Integer.toString(color) + osName;
ImageDescriptor id = mImageDescMap.get(key);
if (id == null && !mImageDescMap.containsKey(key)) {
id = AdtPlugin.imageDescriptorFromPlugin(
AdtPlugin.PLUGIN_ID,
String.format("/icons/%1$s.png", osName)); //$NON-NLS-1$
if (id == null) {
id = new LetterImageDescriptor(osName.charAt(0), color, shape);
}
// Note that we store null references in the icon map, to avoid looking them
// up every time. If it didn't exist once, it will not exist later.
mImageDescMap.put(key, id);
}
return id;
| public static synchronized com.android.ide.eclipse.editors.IconFactory | getInstance()
if (sInstance == null) {
sInstance = new IconFactory();
}
return sInstance;
|
|