01: package com.opensymphony.workflow.designer.swing;
02:
03: import java.util.ResourceBundle;
04: import java.util.MissingResourceException;
05: import java.text.MessageFormat;
06: import java.text.FieldPosition;
07: import java.io.InputStream;
08: import java.net.URL;
09: import javax.swing.*;
10:
11: /**
12: * User: Hani Suleiman
13: * Date: Dec 29, 2003
14: * Time: 4:08:58 PM
15: */
16: public class EnhancedResourceBundle {
17: private ResourceBundle bundle;
18: private ClassLoader loader = EnhancedResourceBundle.class
19: .getClassLoader();
20:
21: public EnhancedResourceBundle(String baseName) {
22: this .bundle = ResourceBundle.getBundle(baseName);
23: }
24:
25: public EnhancedResourceBundle(ResourceBundle bundle) {
26: this .bundle = bundle;
27: }
28:
29: public ResourceBundle getBundle() {
30: return bundle;
31: }
32:
33: public String getString(String key) {
34: return getString(key, key);
35: }
36:
37: public String getString(String key, String defaultValue) {
38: try {
39: return bundle.getString(key);
40: } catch (MissingResourceException e) {
41: return defaultValue;
42: }
43: }
44:
45: public String getString(String key, Object args) {
46:
47: try {
48: String value = bundle.getString(key);
49: MessageFormat format = new MessageFormat(value);
50: return format.format(args, new StringBuffer(),
51: new FieldPosition(0)).toString();
52: } catch (MissingResourceException e) {
53: return key;
54: }
55: }
56:
57: public ImageIcon getIcon(String key) {
58: String path = getString("image." + key);
59: if (path == null) {
60: return null;
61: } else if (path.length() == 0) {
62: return null;
63: } else
64: return readImageIcon(path);
65: }
66:
67: public InputStream getInputStream(String path) {
68: return loader.getResourceAsStream(path);
69: }
70:
71: public ImageIcon readImageIcon(String path) {
72: URL url = loader.getResource(path);
73: return null == url ? null : new ImageIcon(url);
74: }
75: }
|