| /******************************************************************************* |
| * Copyright (c) 2004, 2007 Mylyn project committers 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 |
| *******************************************************************************/ |
| /* |
| * Created on Apr 20, 2004 |
| */ |
| 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"; |
| |
| private static final URL baseURL = TasksWebPlugin.getDefault().getBundle().getEntry("/icons/"); |
| |
| public static final ImageDescriptor OVERLAY_TASK_WEB = create(T_OBJ, "overlay-web.gif"); |
| |
| 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()); |
| if (image == null) { |
| image = imageDescriptor.createImage(); |
| imageRegistry.put("" + imageDescriptor.hashCode(), image); |
| } |
| return image; |
| } |
| |
| } |