2 * Sudokuki - essential sudoku game
\r
3 * Copyright (C) 2007-2012 Sylvain Vedrenne
\r
5 * This program is free software: you can redistribute it and/or modify
\r
6 * it under the terms of the GNU General Public License as published by
\r
7 * the Free Software Foundation, either version 3 of the License, or
\r
8 * (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
18 package net.jankenpoi.sudokuki.ui.swing;
\r
20 import static net.jankenpoi.i18n.I18n._;
\r
22 import java.awt.event.ActionEvent;
\r
23 import java.util.Locale;
\r
25 import javax.swing.AbstractAction;
\r
26 import javax.swing.Action;
\r
27 import javax.swing.ButtonGroup;
\r
28 import javax.swing.JMenu;
\r
29 import javax.swing.JRadioButtonMenuItem;
\r
31 import net.jankenpoi.i18n.I18n;
\r
32 import net.jankenpoi.i18n.LocaleListener;
\r
33 import net.jankenpoi.sudokuki.preferences.UserPreferences;
\r
34 import net.jankenpoi.sudokuki.ui.L10nComponent;
\r
36 @SuppressWarnings("serial")
\r
37 public class LevelMenu extends JMenu implements L10nComponent {
\r
39 private final Action actionLevel1;
\r
40 private final Action actionLevel2;
\r
41 private final Action actionLevel3;
\r
42 private final Action actionLevel4;
\r
43 private final Action actionLevel5;
\r
44 private final JRadioButtonMenuItem itemLevel1 = new JRadioButtonMenuItem();
\r
45 private final JRadioButtonMenuItem itemLevel2 = new JRadioButtonMenuItem();
\r
46 private final JRadioButtonMenuItem itemLevel3 = new JRadioButtonMenuItem();
\r
47 private final JRadioButtonMenuItem itemLevel4 = new JRadioButtonMenuItem();
\r
48 private final JRadioButtonMenuItem itemLevel5 = new JRadioButtonMenuItem();
\r
49 private final LocaleListener localeListener;
\r
51 public LevelMenu() {
\r
52 actionLevel1 = new AbstractAction(_("Level 1"), null) {
\r
55 public void actionPerformed(ActionEvent arg0) {
\r
56 setLevelRatingBounds(0, 5700);
\r
59 actionLevel2 = new AbstractAction(_("Level 2"), null) {
\r
62 public void actionPerformed(ActionEvent arg0) {
\r
63 setLevelRatingBounds(5700, 6700);
\r
66 actionLevel3 = new AbstractAction(_("Level 3"), null) {
\r
69 public void actionPerformed(ActionEvent arg0) {
\r
70 setLevelRatingBounds(6700, 11000);
\r
73 actionLevel4 = new AbstractAction(_("Level 4"), null) {
\r
76 public void actionPerformed(ActionEvent arg0) {
\r
77 setLevelRatingBounds(11000, 15000);
\r
80 actionLevel5 = new AbstractAction(_("Level 5"), null) {
\r
83 public void actionPerformed(ActionEvent arg0) {
\r
84 setLevelRatingBounds(15000, Integer.MAX_VALUE);
\r
89 setIcon(StockIcons.ICON_PLUS);
\r
91 setL10nMessages(null, null);
\r
92 localeListener = new LocaleListenerImpl(this);
\r
93 I18n.addLocaleListener(localeListener);
\r
99 public void setL10nMessages(Locale locale, String languageCode) {
\r
100 setText(_("Level"));
\r
101 itemLevel1.setText(_("Level 1"));
\r
102 itemLevel2.setText(_("Level 2"));
\r
103 itemLevel3.setText(_("Level 3"));
\r
104 itemLevel4.setText(_("Level 4"));
\r
105 itemLevel5.setText(_("Level 5"));
\r
108 private void addItems() {
\r
110 ButtonGroup levelsGroup = new ButtonGroup();
\r
112 levelsGroup.add(itemLevel1);
\r
113 itemLevel1.setAction(actionLevel1);
\r
114 itemLevel1.setSelected(true);
\r
117 itemLevel2.setAction(actionLevel2);
\r
118 levelsGroup.add(itemLevel2);
\r
121 itemLevel3.setAction(actionLevel3);
\r
122 levelsGroup.add(itemLevel3);
\r
125 itemLevel4.setAction(actionLevel4);
\r
126 levelsGroup.add(itemLevel4);
\r
129 itemLevel5.setAction(actionLevel5);
\r
130 levelsGroup.add(itemLevel5);
\r
135 private void setLevelRatingBounds(final int minRating, final int maxRating) {
\r
136 UserPreferences.getInstance().set("minRating", minRating);
\r
137 UserPreferences.getInstance().set("maxRating", maxRating);
\r