/******************************************************************************* * Copyright (c) 2012 VMWare, Inc. * 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: * VMWare, Inc. - initial API and implementation *******************************************************************************/ package org.grails.ide.eclipse.ui; 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 Christian Dupuis * @since 2.2.0 */ public class GrailsUiImages { private static ImageRegistry imageRegistry; // private static final String T_VIEW = "view16"; // private static final String WIZBAN = "wizban"; private static final String OBJ = "obj16"; private static final URL baseURL = GrailsUiActivator.getDefault().getBundle().getEntry("/icons/full/"); public static final ImageDescriptor IMG_OBJ_GRAILS = create(OBJ, "grails_obj.png"); private static ImageDescriptor create(String prefix, String name) { try { return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name)); } catch (MalformedURLException e) { return ImageDescriptor.getMissingImageDescriptor(); } } /** * 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(true); imageRegistry.put("" + imageDescriptor.hashCode(), image); } return image; } private static ImageRegistry getImageRegistry() { if (imageRegistry == null) { imageRegistry = new ImageRegistry(); } return imageRegistry; } private static URL makeIconFileURL(String prefix, String name) throws MalformedURLException { if (baseURL == null) { throw new MalformedURLException(); } StringBuffer buffer = new StringBuffer(prefix); buffer.append('/'); buffer.append(name); return new URL(baseURL, buffer.toString()); } }