blob: b27a105d19149a86d36f5bf379f06dda2a32ee9d [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004, 2008 Tasktop Technologies and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Tasktop Technologies - initial API and implementation
*******************************************************************************/
package org.eclipse.mylyn.internal.web.tasks;
import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
/**
* @author Mik Kersten
*/
public class WebImages {
private static ImageRegistry imageRegistry;
private static final String T_OBJ = "obj16"; //$NON-NLS-1$
private static final URL baseURL = TasksWebPlugin.getDefault().getBundle().getEntry("/icons/"); //$NON-NLS-1$
public static final ImageDescriptor OVERLAY_TASK_WEB = create(T_OBJ, "overlay-web.gif"); //$NON-NLS-1$
public static ImageDescriptor create(String prefix, String name) {
try {
return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name));
} catch (MalformedURLException e) {
return ImageDescriptor.getMissingImageDescriptor();
}
}
private static URL makeIconFileURL(String prefix, String name) throws MalformedURLException {
if (baseURL == null) {
throw new MalformedURLException();
}
StringBuilder buffer = new StringBuilder(prefix);
buffer.append('/');
buffer.append(name);
return new URL(baseURL, buffer.toString());
}
private static ImageRegistry getImageRegistry() {
if (imageRegistry == null) {
imageRegistry = new ImageRegistry();
}
return imageRegistry;
}
/**
* Lazily initializes image map.
*/
public static Image getImage(ImageDescriptor imageDescriptor) {
ImageRegistry imageRegistry = getImageRegistry();
Image image = imageRegistry.get("" + imageDescriptor.hashCode()); //$NON-NLS-1$
if (image == null) {
image = imageDescriptor.createImage();
imageRegistry.put("" + imageDescriptor.hashCode(), image); //$NON-NLS-1$
}
return image;
}
}