blob: e83e219464653991e9842c5a74a1b487b9d1cf00 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2016 KPIT Technologies.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Jan Mauersberger- initial API and implementation
* Sascha Baumgart- initial API and implementation
*******************************************************************************/
package org.eclipse.opencert.userguidance.util;
import java.net.URL;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
public class ImageUtil {
/**
* Creates an image for the specified file name. This method looks for the
* image inside the bundle of the specified requester object.
*/
public static Image createImage(Object requester, String fileName) {
Bundle bundle = FrameworkUtil.getBundle(requester.getClass());
URL url = FileLocator.find(bundle, new Path(fileName), null);
ImageDescriptor image = ImageDescriptor.createFromURL(url);
return image.createImage();
}
}