安徽新华电脑专修学院_安徽电脑培训_安徽电脑培训学校_合肥电脑培训

當(dāng)前位置:首頁(yè) > 網(wǎng)站舊欄目 > 學(xué)習(xí)園地 > 設(shè)計(jì)軟件教程 > 關(guān)于插件中圖標(biāo)對(duì)象的獲取

關(guān)于插件中圖標(biāo)對(duì)象的獲取
2010-01-14 22:54:20  作者:  來(lái)源:
默認(rèn)情況下,插件只能取得gif格式的圖片,有時(shí)候我們需要獲取其他格式的圖片,這里就需要自己來(lái)寫了,最近從另外一個(gè)插件aptana下發(fā)現(xiàn)它在獲取非gif格式圖片的一些做法,值得參考
在需要使用圖標(biāo)的地方,需要這樣寫:
java 代碼
 
  1. private static Image fIconFirefox = JSPlugin.getImage("icons/firefox_icon.png");  

JSPlugin中取得照片的相關(guān)代碼要這樣寫:

java 代碼
 
  1. /**  
  2.  * Returns an image descriptor for the image file at the given  
  3.  * plug-in relative path.  
  4.  *  
  5.  * @param path the path  
  6.  * @return the image descriptor  
  7.  */  
  8. public static ImageDescriptor getImageDescriptor(String path) {   
  9.     return AbstractUIPlugin.imageDescriptorFromPlugin("com.bstek.ide.js.editor", path); //$NON-NLS-1$   
  10. }   
  11.   
  12. private static Hashtable images = new Hashtable();   
  13.   
  14. /**  
  15.  * getImage  
  16.  *   
  17.  * @param path  
  18.  * @return Image  
  19.  */  
  20. public static Image getImage(String path)   
  21. {   
  22.     if (images.get(path) == null)   
  23.     {   
  24.         ImageDescriptor id = getImageDescriptor(path);   
  25.         if (id == null)   
  26.         {   
  27.             return null;   
  28.         }   
  29.   
  30.         Image i = id.createImage();   
  31.         images.put(path, i);   
  32.         return i;   
  33.     }   
  34.     else  
  35.     {   
  36.         return (Image) images.get(path);   
  37.     }   
  38. }  

 

最終讀取圖標(biāo)對(duì)象在AbstractUIPlugin.imageDescriptorFromPlugin()方法中實(shí)現(xiàn)

java 代碼
 
  1.   /**  
  2.    * Creates and returns a new image descriptor for an image file located  
  3.    * within the specified plug-in.  
  4.    * <p>  
  5.    * This is a convenience method that simply locates the image file in  
  6.    * within the plug-in (no image registries are involved). The path is  
  7.    * relative to the root of the plug-in, and takes into account files  
  8.    * coming from plug-in fragments. The path may include $arg$ elements.  
  9.    * However, the path must not have a leading "." or path separator.  
  10.    * Clients should use a path like "icons/mysample.gif" rather than   
  11.    * "./icons/mysample.gif" or "/icons/mysample.gif".  
  12.    * </p>  
  13.    *   
  14.    * @param pluginId the id of the plug-in containing the image file;   
  15.    * <code>null</code> is returned if the plug-in does not exist  
  16.    * @param imageFilePath the relative path of the image file, relative to the  
  17.    * root of the plug-in; the path must be legal  
  18.    * @return an image descriptor, or <code>null</code> if no image  
  19.    * could be found  
  20.    * @since 3.0  
  21.    */  
  22.   public static ImageDescriptor imageDescriptorFromPlugin(String pluginId,   
  23.           String imageFilePath) {   
  24.       if (pluginId == null || imageFilePath == null) {   
  25.           throw new IllegalArgumentException();   
  26.       }   
  27.   
  28.       // if the bundle is not ready then there is no image   
  29.       Bundle bundle = Platform.getBundle(pluginId);   
  30.       if (!BundleUtility.isReady(bundle)) {   
  31.     return null;   
  32. }   
  33.   
  34.       // look for the image (this will check both the plugin and fragment folders   
  35.       URL fullPathString = BundleUtility.find(bundle, imageFilePath);   
  36.       if (fullPathString == null) {   
  37.           try {   
  38.               fullPathString = new URL(imageFilePath);   
  39.           } catch (MalformedURLException e) {   
  40.               return null;   
  41.           }   
  42.       }   
  43.   
  44.       if (fullPathString == null) {   
  45.     return null;   
  46. }   
  47.       return ImageDescriptor.createFromURL(fullPathString);   
  48.   }  

安徽新華電腦學(xué)校專業(yè)職業(yè)規(guī)劃師為你提供更多幫助【在線咨詢
主站蜘蛛池模板: 离子交换树脂_阴离子交换树脂_阳离子交换树脂-中国树脂网 | 清洁公司| 保洁公司| 东莞清洁| 东莞保洁|壹壹清洁 | 医疗器械招标网—打造医械厂家专业服务平台 | 衡水物流网,衡水物流信息网,衡水物流公司,衡水货运专线,衡水专线运输车辆 | 四川迪瑞机电设备有限公司-容积式换热器|半容积式换热器|容积式换热机组|半容积式水加热器|换热器在线除垢防垢器|迪瑞机电 | 乐云SEO | 品牌营销:抖音小红书关键词优化-ai搜索优化GEO推广 | 油压缓冲器-缓冲器-重庆佑旺机械有限公司[官网]西捷克重庆办事处 | 辣椒烘干机-百信机械提供大中小型辣椒烘干机房设备视频图片厂家价格多少钱 | 深圳LED显示屏厂家_室内户外LED显示屏_彩屏电子有限公司 | 辣椒烘干机-百信机械提供大中小型辣椒烘干机房设备视频图片厂家价格多少钱 | 饲料车_散装饲料车_畜禽运输车_散装饲料运输车_饲料车厂家_铝合金运猪车-程力专用汽车股份有限公司 | 石家庄LED显示屏|石家庄显示屏|河北显示屏升级改造|石家庄科航光电科技有限公司_石家庄科航光电科技有限公司 | 仪器仪表维修_示波器维修_进口分析仪维修_热像仪维修_上海仰光电子仪器仪表维修部 | 郑州月嫂|月嫂培训|月嫂服务|郑州布卢家政服务有限公司 | 消防施工,消防工程施工,消防施工改造-北京消防工程公司-亿杰(北京)消防工程有限公司 | 南湖人才网_南湖招聘网_求职找工作平台 | 清研集团 - 北京清研灵智科技有限公司| 领先的一站式_专利申请代理知识产权服务平台_乐知网 | 威学一百-专注国际学校择校备考-DSE-A-level-雅思-托福-OSSD-港澳台联考-AP-IGCSE-IB-AMC-多邻国-PTE-SAT-SSAT-小语种(如日语,韩语,德语,法语,西班牙语,意大利语,俄语,泰语)等考试培训,为出国留学学生提供个性化定制性学习方案,线下实体面授+线上网络课程, 提供一对一,小班课等多种班型 | 铸铁平台-铸铁平板平台厂家-加工优质高精度检验划线装配T型槽平台-尺寸规格全供应-建新铸造 | 张家港起重搬运吊装,工厂设备搬运服务-张家港易源起重搬运有限公司 | 耐磨焊条_高硬度堆焊焊条_碳化钨合金耐磨焊丝_北京耐默 | 网络广播_公共广播系统_校园,学校数字ip,itc智能广播系统方案 | 快速卷帘门-电动卷帘门-快速堆积门-快速门厂家-任丘市康速机电设备有限公司 | 全棉帆布厂家_加工帆布_涤棉帆布价格_染色帆布定制_广州美丽华皮革帆布-广州美丽华皮革帆布 | 冷却特性测试仪_ 刀柄热胀仪_加油小车价格_皮带张力仪_上海川奇机电设备有限公司 | 西安真石漆_无机涂料厂家_无机涂料多少钱一个平方—陕西秦森环保科技有限公司 | 千家网-智能建筑与智能家居产品解决方案平台 | 江苏华海诚科新材料有限公司、连云港华海诚科新材料有限公司、连云港新材料 | 气动隔膜调节阀,气动比例调节隔膜阀|川熙流体设备百科 | 健力普医疗-半导体激光治疗仪,红外偏振光治疗仪,近红外线治疗仪-独家功能,光疗典范 | 深圳钢成培训专业从事,五轴培训,车铣复合培训,数控车床,CNC数控编程,模具编程 ,钣金机械与模具设计,powermill,mastercam,solidworks,ug,hypermill培训 | 深圳心理咨询-专业心理咨询服务平台「专家免费在线」-深圳从心开始心理O2O | 全自动视觉点胶机|在线式点胶机|精密点胶阀设备厂家-杭州迈伺特科技有限公司 | 橡胶粉碎机_轮胎粉碎机_橡胶切条机_橡胶粉碎机价格_河南鑫世昌机械制造有限公司 | 全功能护理训练模拟人-创伤护理人-高级电脑心肺复苏模型-上海康季 | 万通汽车学校,汽车学校,汽修学校,汽修培训学校,汽车美容学校,汽车维修学校,学汽修-武汉万通汽车学校官方网站 | 锦州龙威机械有限公司官网 ,锦州医药包装机,包装机,锦州包装机械,小袋颗粒装盒生产线,颗粒装盒生产线,软双铝装盒线,伺服颗粒 | 随车吊/洒水车/低平板运输车-程力专用汽车股份有限公司 | 直饮水设备-纯水设备-软化水设备 - 亿家清泉水处理设备厂家 | 装盒机|装箱机|封箱机|全自动化包装生产线尽在利悦包装机械 |