eclipse插件获取ImageDescriptor的方法

来源:互联网 发布:淘宝店铺2心要多少单 编辑:程序博客网 时间:2024/06/01 10:26

org.eclipse.ui.plugin.AbstractUIPlugin

public static ImageDescriptor imageDescriptorFromPlugin(String pluginId,            String imageFilePath) {        if (pluginId == null || imageFilePath == null) {            throw new IllegalArgumentException();        }IWorkbench workbench = PlatformUI.isWorkbenchRunning() ? PlatformUI.getWorkbench() : null;ImageDescriptor imageDescriptor = workbench == null ? null : workbench.getSharedImages().getImageDescriptor(imageFilePath);if (imageDescriptor != null)return imageDescriptor; // found in the shared images        // if the bundle is not ready then there is no image        Bundle bundle = Platform.getBundle(pluginId);        if (!BundleUtility.isReady(bundle)) {return null;}        // look for the image (this will check both the plugin and fragment folders        URL fullPathString = BundleUtility.find(bundle, imageFilePath);        if (fullPathString == null) {            try {                fullPathString = new URL(imageFilePath);            } catch (MalformedURLException e) {                return null;            }        }        return ImageDescriptor.createFromURL(fullPathString);    }

 


org.eclipse.jface.resource.ImageDescriptor

public static ImageDescriptor createFromURL(URL url) {        if (url == null) {            return getMissingImageDescriptor();        }        return new URLImageDescriptor(url);    }
public static ImageDescriptor createFromFile(Class location, String filename) {        return new FileImageDescriptor(location, filename);    }
public static ImageDescriptor createFromImageData(ImageData data) {        return new ImageDataImageDescriptor(data);    }

                                             
0 0
原创粉丝点击