01: /**
02: * Created on Dec 2, 2004
03: *
04: * @author karthikeyanr
05: *
06: */package wizard.helper;
07:
08: import java.awt.Image;
09: import java.net.URL;
10: import java.util.*;
11:
12: import javax.swing.ImageIcon;
13:
14: public class ResourceBundleManager {
15: private static ResourceBundle resourceBundle;
16:
17: private static ResourceBundleManager resourceManager;
18:
19: static {
20: try {
21: resourceBundle = ResourceBundle.getBundle("Wizard", Locale
22: .getDefault(), ResourceBundleManager.class
23: .getClassLoader());
24: } catch (Exception e) {
25: e.printStackTrace();
26: }
27: }
28:
29: private Map imageCache = new HashMap();
30:
31: public static ResourceBundleManager getInstance() {
32: if (resourceManager == null)
33: resourceManager = new ResourceBundleManager();
34:
35: return resourceManager;
36: }
37:
38: private ResourceBundleManager() {
39: }
40:
41: public String getString(String key) {
42: String localString = null;
43: try {
44: localString = resourceBundle.getString(key).trim();
45: } catch (MissingResourceException mre) {
46: mre.printStackTrace();
47: }
48:
49: return localString;
50: }
51:
52: public Image getImage(String imageKey) {
53: Image image = (Image) imageCache.get(imageKey);
54: if (image != null)
55: return image;
56:
57: String imageName = getString(imageKey);
58: if (imageName == null)
59: return null;
60:
61: URL url = ClassLoader.getSystemResource(imageName);
62: image = new ImageIcon(url).getImage();
63:
64: if (image != null)
65: imageCache.put(imageKey, image);
66:
67: return image;
68: }
69:
70: }
|