01: /*
02: * 02/02/2002 - 20:54:54
03: *
04: * LocaleEditor.java - a locale editor for JavaBeans
05: * Copyright (C) 2002 Kai Toedter
06: * kai@toedter.com
07: * www.toedter.com
08: *
09: * This program is free software; you can redistribute it and/or
10: * modify it under the terms of the GNU Lesser General Public License
11: * as published by the Free Software Foundation; either version 2
12: * of the License, or (at your option) any later version.
13: *
14: * This program is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: * GNU Lesser General Public License for more details.
18: *
19: * You should have received a copy of the GNU Lesser General Public License
20: * along with this program; if not, write to the Free Software
21: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22: */
23:
24: package com.toedter.components;
25:
26: import java.util.Calendar;
27: import java.util.Locale;
28:
29: /**
30: * Property editor for locales.
31: *
32: * @version 1.1 02/04/02
33: * @author Kai Toedter
34: */
35: public class LocaleEditor extends java.beans.PropertyEditorSupport {
36: /**
37: * Default LocaleEditor constructor.
38: */
39: public LocaleEditor() {
40: locale = Locale.getDefault();
41: locales = Calendar.getAvailableLocales();
42: length = locales.length;
43: localeStrings = new String[length];
44: }
45:
46: /**
47: * Returns the locale Strings.
48: */
49: public String[] getTags() {
50: for (int i = 0; i < length; i++)
51: localeStrings[i] = locales[i].getDisplayName();
52: return localeStrings;
53: }
54:
55: /**
56: * Sets the locale Strings as text and invokes setValue( locale ).
57: */
58: public void setAsText(String text) throws IllegalArgumentException {
59: for (int i = 0; i < length; i++)
60: if (text.equals(locales[i].getDisplayName())) {
61: locale = locales[i];
62: setValue(locale);
63: break;
64: }
65: }
66:
67: /**
68: * Returnss the locale String as text.
69: */
70: public String getAsText() {
71: return locale.getDisplayName();
72: }
73:
74: private Locale[] locales;
75: private String[] localeStrings;
76: private Locale locale;
77: private int length;
78: }
|