01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: LocalizedString.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.tools;
09:
10: /**
11: * This class makes it possible to always keep a localized string up-to-date.
12: * By providing it with a lookup key instead of the final text, it is able to
13: * always provide a text representation according to the active default
14: * localization settings.
15: *
16: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
17: * @version $Revision: 3634 $
18: * @since 1.0
19: */
20: public class LocalizedString implements CharSequence {
21: private String mKey = null;
22:
23: /**
24: * Instantiates a new <code>LocalizedString</code> instance.
25: *
26: * @param key the key that will be used to look up the localized string
27: * @since 1.0
28: */
29: public LocalizedString(String key) {
30: if (null == key)
31: throw new IllegalArgumentException("key can't be null.");
32:
33: mKey = key;
34: }
35:
36: public char charAt(int index) {
37: return toString().charAt(index);
38: }
39:
40: public CharSequence subSequence(int start, int end) {
41: return toString().subSequence(start, end);
42: }
43:
44: public int length() {
45: return toString().length();
46: }
47:
48: public String toString() {
49: return Localization.getString(mKey);
50: }
51: }
|