01: /*
02: * Created on 10/02/2005
03: *
04: * ============================================================================
05: * GNU Lesser General Public License
06: * ============================================================================
07: *
08: * Swing Components - visit http://sf.net/projects/gfd
09: *
10: * Copyright (C) 2004 Igor Regis da Silva Simões
11: *
12: * This library is free software; you can redistribute it and/or
13: * modify it under the terms of the GNU Lesser General Public
14: * License as published by the Free Software Foundation; either
15: * version 2.1 of the License, or (at your option) any later version.
16: *
17: * This library is distributed in the hope that it will be useful,
18: * but WITHOUT ANY WARRANTY; without even the implied warranty of
19: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20: * Lesser General Public License for more details.
21: *
22: * You should have received a copy of the GNU Lesser General Public
23: * License along with this library; if not, write to the Free Software
24: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
25: */
26: package br.com.igor.beans;
27:
28: import java.util.ArrayList;
29: import java.util.Arrays;
30: import java.util.HashMap;
31: import java.util.Locale;
32: import java.util.Map;
33: import java.util.Set;
34:
35: import javax.swing.ComboBoxModel;
36: import javax.swing.DefaultComboBoxModel;
37: import javax.swing.JComboBox;
38:
39: /**
40: *
41: * @author Igor Regis da Silva Simoes - f4353008
42: * @since 10/02/2005 16:59:20
43: */
44: public class LanguageEditor extends JComboBox {
45: /**
46: *
47: */
48: public LanguageEditor() {
49: this (null);
50: }
51:
52: public LanguageEditor(ArrayList<Locale> languages) {
53: Locale[] locais = null;
54: Map<String, String> idiomas = new HashMap<String, String>();
55: if (languages != null)
56: locais = languages.toArray(new Locale[languages.size()]);
57: else
58: locais = Locale.getAvailableLocales();
59:
60: for (int i = 0; i < locais.length; i++)
61: idiomas.put(locais[i].getLanguage().toString(), null);
62:
63: String[] resultado = new String[idiomas.size()];
64: Set<String> temp = idiomas.keySet();
65: int i = 0;
66: for (String tempLang : temp)
67: resultado[i++] = tempLang;
68:
69: Arrays.sort(resultado);
70: ComboBoxModel model = new DefaultComboBoxModel(resultado);
71: setModel(model);
72: setRenderer(new LocaleComboBoxRenderer());
73: }
74: }
|