1 /**
2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation, version 3.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program. If not, see <http://www.gnu.org/licenses/>.
13 */
14
15 package net.curre.prefcount.event;
16
17 import java.awt.event.ItemEvent;
18 import java.awt.event.ItemListener;
19 import java.awt.event.ActionListener;
20 import java.awt.event.ActionEvent;
21
22 import net.curre.prefcount.PrefCountRegistry;
23
24 /**
25 * Object of this class represents an action listener
26 * to change current language.
27 * <p/>
28 * Created date: Jun 2, 2007
29 *
30 * @author Yevgeny Nyden
31 */
32 public class ChangeLanguageActionListener
33 implements ItemListener, ActionListener {
34
35 /**
36 * The locale identifier (case insensitive language name)
37 * to which to switch.
38 */
39 private String localeId;
40
41 /**
42 * Constructor.
43 *
44 * @param localeId The locale identifier (case insensitive language name).
45 */
46 public ChangeLanguageActionListener(String localeId) {
47 this.localeId = localeId;
48 }
49
50 /**
51 * Changes language only if the item event shows
52 * that the item has been selected (and not deselected).
53 * This ItemListener method is for awt menu only.
54 * <p/>
55 * {@inheritDoc}
56 */
57 public void itemStateChanged(ItemEvent itemEvent) {
58 if (itemEvent.getStateChange() == ItemEvent.DESELECTED) {
59 return;
60 }
61 changeLanguage();
62 }
63
64 /**
65 * Changes language.
66 * This ActionListener method is for swing menu only.
67 * <p/>
68 * {@inheritDoc}
69 */
70 public void actionPerformed(ActionEvent actionEvent) {
71 changeLanguage();
72 }
73
74 /** Helper method that changes the language. */
75 private void changeLanguage() {
76 PrefCountRegistry.getInstance().setCurrentLocale(localeId);
77 }
78
79 }