/*******************************************************************************
* Copyright (c) 2016 Pivotal, 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:
* Phil Webb - initial API and implementation
*******************************************************************************/
package org.springframework.ide.eclipse.boot.restart;
import java.net.URL;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
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;
import org.osgi.framework.Bundle;
public class RestartPluginImages {
private static ImageRegistry imageRegistry;
private static String ICONS_PATH = "$nl$/icons/full/"; //$NON-NLS-1$
private static void declareImages() {
declareRegistryImage(RestartConstants.IMG_RESTART_ICON, ICONS_PATH
+ "refresh_tab.png"); //$NON-NLS-1$
}
private final static void declareRegistryImage(String key, String path) {
ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
Bundle bundle = Platform.getBundle(RestartConstants.PLUGIN_ID);
URL url = null;
if (bundle != null) {
url = FileLocator.find(bundle, new Path(path), null);
if (url != null) {
desc = ImageDescriptor.createFromURL(url);
}
}
imageRegistry.put(key, desc);
}
public static ImageRegistry getImageRegistry() {
if (imageRegistry == null) {
initializeImageRegistry();
}
return imageRegistry;
}
public synchronized static boolean isInitialized() {
return imageRegistry != null;
}
public synchronized static ImageRegistry initializeImageRegistry() {
if (imageRegistry == null) {
imageRegistry = new ImageRegistry(PlatformUI.getWorkbench().getDisplay());
declareImages();
}
return imageRegistry;
}
public static Image getImage(String key) {
return getImageRegistry().get(key);
}
public static ImageDescriptor getImageDescriptor(String key) {
return getImageRegistry().getDescriptor(key);
}
}