随笔 - 6  文章 - 129  trackbacks - 0
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(14)

随笔档案(6)

文章分类(467)

文章档案(423)

相册

收藏夹(18)

JAVA

搜索

  •  

积分与排名

  • 积分 - 814466
  • 排名 - 49

最新评论

阅读排行榜

评论排行榜

package hellorcp.tool;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;

public class CacheImage {

 private final Map<String, Image> imageMap = new HashMap<String, Image>();
 private static CacheImage INSTANCE = null;
 
 private CacheImage(){
  
 }
 //單例
 public static CacheImage getInstance() {
  if(INSTANCE == null)
   INSTANCE = new CacheImage();
  return INSTANCE;
 }
 //獲得圖片
 public Image getImage(String applicationId, String imageName) {
  if(imageName == null)
   return null;
  Image image = imageMap.get(imageName);
  if(image == null) {
   image = AbstractUIPlugin.imageDescriptorFromPlugin(applicationId,
imageName).createImage();//應用程序的ID,圖片的路徑
   imageMap.put(imageName, image);
  }
  return image;
 }
 //dispose資源
 public void dispose() {
  Iterator<Image> iterator = imageMap.values().iterator();
  while(iterator.hasNext())
   iterator.next().dispose();
  imageMap.clear();
 }
}



posted on 2008-12-05 23:54 Ke 阅读(878) 评论(0)  编辑  收藏 所属分类: eclipse RCP

只有注册用户登录后才能发表评论。


网站导航: