1 | /* |
---|
2 | * Jeti, a Java Jabber client, Copyright (C) 2004 E.S. de Boer |
---|
3 | * |
---|
4 | * This program is free software; you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU General Public License as published by |
---|
6 | * the Free Software Foundation; either version 2 of the License, or |
---|
7 | * (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program; if not, write to the Free Software |
---|
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | * |
---|
18 | * For questions, comments etc, |
---|
19 | * use the website at http://jeti.jabberstudio.org |
---|
20 | * or mail me at eric@jeti.tk or Jabber at jeti@jabber.org |
---|
21 | * |
---|
22 | * Created on 10-jul-2004 |
---|
23 | */ |
---|
24 | |
---|
25 | package nu.fw.jeti.ui.models; |
---|
26 | |
---|
27 | import java.awt.event.ActionEvent; |
---|
28 | import java.awt.event.ActionListener; |
---|
29 | import java.awt.event.ItemListener; |
---|
30 | import java.util.List; |
---|
31 | import java.util.Locale; |
---|
32 | import java.util.Map; |
---|
33 | |
---|
34 | import javax.swing.AbstractListModel; |
---|
35 | import javax.swing.ComboBoxModel; |
---|
36 | import javax.swing.JComboBox; |
---|
37 | |
---|
38 | import nu.fw.jeti.util.I18N; |
---|
39 | |
---|
40 | /** |
---|
41 | * @author E.S. de Boer |
---|
42 | * |
---|
43 | */ |
---|
44 | public class LocaleModel extends AbstractListModel implements ComboBoxModel, ActionListener |
---|
45 | { |
---|
46 | private Map countries; |
---|
47 | private List currentCountries; |
---|
48 | private Object selectedItem; |
---|
49 | |
---|
50 | public LocaleModel(I18N i18n) |
---|
51 | { |
---|
52 | countries = i18n.getCountries(); |
---|
53 | //currentCountries = (List)countries.get("en"); |
---|
54 | } |
---|
55 | |
---|
56 | /* (non-Javadoc) |
---|
57 | * @see javax.swing.ComboBoxModel#getSelectedItem() |
---|
58 | */ |
---|
59 | public Object getSelectedItem() |
---|
60 | { |
---|
61 | return selectedItem; |
---|
62 | } |
---|
63 | |
---|
64 | /* (non-Javadoc) |
---|
65 | * @see javax.swing.ComboBoxModel#setSelectedItem(java.lang.Object) |
---|
66 | */ |
---|
67 | public void setSelectedItem(Object arg0) |
---|
68 | { |
---|
69 | selectedItem = arg0; |
---|
70 | } |
---|
71 | |
---|
72 | /* (non-Javadoc) |
---|
73 | * @see javax.swing.ListModel#getSize() |
---|
74 | */ |
---|
75 | public int getSize() |
---|
76 | { |
---|
77 | return currentCountries.size(); |
---|
78 | } |
---|
79 | |
---|
80 | /* (non-Javadoc) |
---|
81 | * @see javax.swing.ListModel#getElementAt(int) |
---|
82 | */ |
---|
83 | public Object getElementAt(int pos) |
---|
84 | { |
---|
85 | return currentCountries.get(pos); |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * react to language combobox events |
---|
90 | */ |
---|
91 | public void actionPerformed(ActionEvent e) |
---|
92 | { |
---|
93 | JComboBox cb = (JComboBox)e.getSource(); |
---|
94 | String languageCode =((I18N.Language)cb.getSelectedItem()).getLanguageCode(); |
---|
95 | // if(currentCountries!=null) fireIntervalRemoved(this,0,currentCountries.size()); |
---|
96 | currentCountries = (List) countries.get(languageCode); |
---|
97 | //fireIntervalAdded(this,0,currentCountries.size()); |
---|
98 | |
---|
99 | fireContentsChanged(this,0,currentCountries.size()); |
---|
100 | } |
---|
101 | |
---|
102 | } |
---|
103 | |
---|
104 | /* |
---|
105 | * Overrides for emacs |
---|
106 | * Local variables: |
---|
107 | * tab-width: 4 |
---|
108 | * End: |
---|
109 | */ |
---|