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.CheckboxMenuItem;
18 import java.awt.event.ActionEvent;
19 import java.awt.event.ActionListener;
20 import java.awt.event.ItemEvent;
21 import java.awt.event.ItemListener;
22
23 import net.curre.prefcount.gui.theme.skin.PrefSkin;
24 import net.curre.prefcount.service.LafThemeService;
25 import net.curre.prefcount.service.SettingsService;
26
27 /**
28 * Object of this class represents a listener
29 * for a L&F menu item (a <code>CheckboxMenuItem</code> object).
30 * <p/>
31 * Created date: Jan 22, 2008
32 *
33 * @author Yevgeny Nyden
34 */
35 public class LafMenuItemListener implements ActionListener, ItemListener {
36
37 /** The Pref skin this listener is for. */
38 private PrefSkin skin;
39
40 /**
41 * Constructor that sets the skin this listener is for.
42 *
43 * @param skin Pref skin to set.
44 */
45 public LafMenuItemListener(PrefSkin skin) {
46 this.skin = skin;
47 }
48
49 /**
50 * Changes the current L&F skin to the listener's skin
51 * (this.skin). This ItemListener method is for awt menu only.
52 * <p/>
53 * {@inheritDoc}
54 */
55 public void itemStateChanged(ItemEvent itemEvent) {
56 if (itemEvent.getStateChange() == ItemEvent.DESELECTED) {
57 ((CheckboxMenuItem) itemEvent.getSource()).setState(true);
58 }
59 changeSkin();
60 }
61
62 /**
63 * Changes the current L&F skin to the listener's skin
64 * (this.skin). This ActionListener method is for swing
65 * menu only.
66 * <p/>
67 * {@inheritDoc}
68 */
69 public void actionPerformed(ActionEvent actionEvent) {
70 changeSkin();
71 }
72
73 /** Helper method that performs LAF skin change. */
74 private void changeSkin() {
75 LafThemeService.getInstance().setLookAndFeel(skin.getNameResourceKey(), false);
76 SettingsService.updateSkin(skin);
77 }
78
79 }