01: /*
02: * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
03: *
04: * The program is provided "as is" without any warranty express or
05: * implied, including the warranty of non-infringement and the implied
06: * warranties of merchantibility and fitness for a particular purpose.
07: * IBM will not be liable for any damages suffered by you as a result
08: * of using the Program. In no event will IBM be liable for any
09: * special, indirect or consequential damages or lost profits even if
10: * IBM has been advised of the possibility of their occurrence. IBM
11: * will not be liable for any third party claims against you.
12: */
13: package com.ibm.richtext.demo;
14:
15: import java.awt.MenuItem;
16: import java.awt.MenuShortcut;
17:
18: import java.util.MissingResourceException;
19: import java.util.ResourceBundle;
20:
21: /**
22: * Utility class for dealing with resource data.
23: */
24: public final class ResourceUtils {
25:
26: static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
27: private static ResourceBundle BUNDLE;
28: static {
29: String bundleName = "com.ibm.richtext.demo.EditorResources";
30: try {
31: BUNDLE = ResourceBundle.getBundle(bundleName);
32: } catch (MissingResourceException e) {
33: System.out.println("Couldn't load " + bundleName
34: + "; Exception: " + e);
35: BUNDLE = new EditorResources();
36: }
37: }
38:
39: public static String getString(String key) {
40:
41: try {
42: return BUNDLE.getString(key);
43: } catch (MissingResourceException e) {
44: return key;
45: }
46: }
47:
48: public static MenuData getMenuData(String key) {
49:
50: try {
51: return (MenuData) BUNDLE.getObject(key);
52: } catch (MissingResourceException e) {
53: return new MenuData(key);
54: }
55: }
56:
57: public static MenuItem createMenuItem(String key) {
58:
59: MenuData menuData = getMenuData(key);
60:
61: if (menuData.hasShortcut()) {
62: MenuShortcut shortcut = new MenuShortcut(menuData
63: .getShortcut());
64: return new MenuItem(menuData.getName(), shortcut);
65: } else {
66: return new MenuItem(menuData.getName());
67: }
68: }
69: }
|