blob: bed48b829b4858223b9d8d2e05e99c0dd235c6cb [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ui.internal.commands;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.PlatformUI;
final class ImageFactory {
private static ImageRegistry imageRegistry = new ImageRegistry();
private static Map map = new HashMap();
static {
put("blank", "icons/full/commands/blank.gif"); //$NON-NLS-1$//$NON-NLS-2$
put("change", "icons/full/commands/change.gif"); //$NON-NLS-1$//$NON-NLS-2$
put("exclamation", "icons/full/commands/exclamation.gif"); //$NON-NLS-1$//$NON-NLS-2$
put("minus", "icons/full/commands/minus.gif"); //$NON-NLS-1$//$NON-NLS-2$
put("plus", "icons/full/commands/plus.gif"); //$NON-NLS-1$//$NON-NLS-2$
}
private static ImageDescriptor create(String path) {
try {
URL url = Platform.getPlugin(PlatformUI.PLUGIN_ID).getDescriptor().getInstallURL();
url = new URL(url, path);
return ImageDescriptor.createFromURL(url);
} catch (MalformedURLException eMalformedURL) {
return null;
}
}
private static void put(String key, String value) {
map.put(key, create(value));
}
static Image getImage(String key) {
Image image = (Image) imageRegistry.get(key);
if (image == null) {
ImageDescriptor imageDescriptor = getImageDescriptor(key);
if (imageDescriptor != null) {
image = imageDescriptor.createImage(false);
if (image == null)
System.err.println(ImageFactory.class + ": error creating image for " + key); //$NON-NLS-1$
imageRegistry.put(key, image);
}
}
return image;
}
static ImageDescriptor getImageDescriptor(String key) {
ImageDescriptor imageDescriptor = (ImageDescriptor) map.get(key);
if (imageDescriptor == null)
System.err.println(ImageFactory.class + ": no image descriptor for " + key); //$NON-NLS-1$
return imageDescriptor;
}
}