01: /**
02: * Wizard Framework
03: * Copyright 2004 - 2005 Andrew Pietsch
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: *
19: * $Id: I18n.java,v 1.6 2005/05/16 23:06:57 pietschy Exp $
20: */package org.pietschy.wizard;
21:
22: import javax.swing.*;
23: import java.util.ResourceBundle;
24: import java.util.MissingResourceException;
25: import java.util.Locale;
26:
27: /**
28: * Internationalization Helper. By default this class attempts to load the bundle called 'org-pietshcy-wizard'
29: * from the classpath but you can specify you own bundle by calling the static {@link #setBundle} method.
30: *
31: * @author andrewp
32: * @version $Revision: 1.6 $
33: */
34: public class I18n {
35: private static final String _ID_ = "$Id: I18n.java,v 1.6 2005/05/16 23:06:57 pietschy Exp $";
36:
37: private static ResourceBundle bundle = null;
38:
39: private static ResourceBundle getBundle() {
40: if (bundle == null)
41: bundle = ResourceBundle.getBundle("org-pietschy-wizard");
42:
43: return bundle;
44: }
45:
46: public static void setBundle(ResourceBundle bundle) {
47: I18n.bundle = bundle;
48: }
49:
50: public static String getString(String key) {
51: return getBundle().getString(key);
52: }
53:
54: public static Object getObject(String key) {
55: return getBundle().getObject(key);
56: }
57:
58: public static String[] getStringArray(String key) {
59: return getBundle().getStringArray(key);
60: }
61:
62: public static int getMnemonic(String key) {
63: String mnemonicString = getBundle().getString(key);
64:
65: if (mnemonicString == null)
66: throw new MissingResourceException("Missing resource: "
67: + key, I18n.class.getName(), key);
68:
69: if (mnemonicString.length() != 1)
70: throw new IllegalStateException("mnemonic string invalid: "
71: + mnemonicString);
72:
73: KeyStroke ks = KeyStroke.getKeyStroke(mnemonicString
74: .toUpperCase());
75:
76: if (ks == null)
77: throw new IllegalStateException("mnemonic string invalid: "
78: + mnemonicString);
79:
80: return ks.getKeyCode();
81: }
82: }
|