FileDocCategorySizeDatePackage
IconFactory.javaAPI DocAndroid 1.5 API9644Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors

IconFactory

public 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 voidDispose()

        // 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.ImagegetIcon(java.lang.String osName)
Returns an Image for a given icon name.

Callers should not dispose it.

param
osName The leaf name, without the extension, of an existing icon in the editor's "icons" directory. If it doesn't exists, a default icon will be generated automatically based on the name.

        return getIcon(osName, COLOR_DEFAULT, SHAPE_DEFAULT);
    
public org.eclipse.swt.graphics.ImagegetIcon(java.lang.String osName, int color, int shape)
Returns an Image for a given icon name.

Callers should not dispose it.

param
osName The leaf name, without the extension, of an existing icon in the editor's "icons" directory. If it doesn't exists, a default icon will be generated automatically based on the name.
param
color The color of the text in the automatically generated icons, one of COLOR_DEFAULT, COLOR_RED, COLOR_BLUE or COLOR_RED.
param
shape The shape of the icon in the automatically generated icons, one of SHAPE_DEFAULT, SHAPE_CIRCLE or SHAPE_RECT.

        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.ImageDescriptorgetImageDescriptor(java.lang.String osName)
Returns an ImageDescriptor for a given icon name.

Callers should not dispose it.

param
osName The leaf name, without the extension, of an existing icon in the editor's "icons" directory. If it doesn't exists, a default icon will be generated automatically based on the name.

        return getImageDescriptor(osName, COLOR_DEFAULT, SHAPE_DEFAULT);
    
public org.eclipse.jface.resource.ImageDescriptorgetImageDescriptor(java.lang.String osName, int color, int shape)
Returns an ImageDescriptor for a given icon name.

Callers should not dispose it.

param
osName The leaf name, without the extension, of an existing icon in the editor's "icons" directory. If it doesn't exists, a default icon will be generated automatically based on the name.
param
color The color of the text in the automatically generated icons. one of COLOR_DEFAULT, COLOR_RED, COLOR_BLUE or COLOR_RED.
param
shape The shape of the icon in the automatically generated icons, one of SHAPE_DEFAULT, SHAPE_CIRCLE or SHAPE_RECT.

        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.IconFactorygetInstance()

        if (sInstance == null) {
            sInstance = new IconFactory();
        }
        return sInstance;