| 1 6 7 package com.thoughtriver.open.vectorvisuals; 8 9 import java.awt.*; 10 import java.net.*; 11 import java.util.*; 12 13 import javax.swing.*; 14 15 24 public class ImageManager { 25 26 27 static private ImageManager singleton = null; 28 29 35 static synchronized public ImageManager getSharedInstance() { 36 37 if (singleton == null) { 38 singleton = new ImageManager(); 39 } 40 41 return singleton; 42 } 43 44 45 private Map<String , Image> cache = null; 46 47 51 public ImageManager() { 52 cache = new HashMap<String , Image>(); 53 } 54 55 63 public synchronized Image getImage(final String name) { 64 65 Image img = null; 66 67 if (cache.containsKey(name)) { 69 img = cache.get(name); 70 71 } 72 else { 74 URL imgLoc = Thread.currentThread().getContextClassLoader().getResource(name); 75 img = new ImageIcon(imgLoc).getImage(); 76 77 if (img != null) { 79 cache.put(name, img); 80 } 81 } 82 83 return img; 84 } 85 86 } 87 | Popular Tags |