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