2 * Sudokuki - essential sudoku game
\r
3 * Copyright (C) 2007-2013 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.awt.event.KeyEvent;
\r
24 import java.util.Locale;
\r
26 import javax.swing.Action;
\r
27 import javax.swing.JFrame;
\r
28 import javax.swing.JMenu;
\r
29 import javax.swing.JMenuItem;
\r
30 import javax.swing.KeyStroke;
\r
32 import net.jankenpoi.i18n.I18n;
\r
33 import net.jankenpoi.i18n.LocaleListener;
\r
34 import net.jankenpoi.sudokuki.ui.L10nComponent;
\r
36 @SuppressWarnings("serial")
\r
37 public class EditMenu extends JMenu implements L10nComponent {
\r
39 private final JMenuItem itemClearAllMoves = new JMenuItem();
\r
40 private final JMenuItem itemEraseAllMemos = new JMenuItem();
\r
41 private final JMenuItem itemCustomGrid = new JMenuItem();
\r
42 private final JMenuItem itemPlayCustomGrid = new JMenuItem();
\r
43 private final Action actionClearAllMoves;
\r
44 private final Action actionEraseAllMemos;
\r
45 private final Action actionCustomGrid;
\r
46 private final Action actionPlayCustomGrid;
\r
48 private final LocaleListener localeListener;
\r
49 private LevelMenu levelMenu;
\r
50 private CheatMenu cheatMenu;
\r
53 public void setL10nMessages(Locale locale, String languageCode) {
\r
55 itemClearAllMoves.setText(_("Clear moves"));
\r
56 actionClearAllMoves.putValue(Action.SHORT_DESCRIPTION, _("Clear all moves"));
\r
57 itemEraseAllMemos.setText(_("Hide memos..."));
\r
58 actionEraseAllMemos.putValue(Action.SHORT_DESCRIPTION, _("Hide all memos..."));
\r
59 itemCustomGrid.setText(_("Custom grid"));
\r
60 actionCustomGrid.putValue(Action.SHORT_DESCRIPTION, _("Compose a custom grid..."));
\r
61 itemPlayCustomGrid.setText(_("Play grid"));
\r
62 actionPlayCustomGrid.putValue(Action.SHORT_DESCRIPTION, _("Play with current grid..."));
\r
65 EditMenu(ActionsRepository actions, JFrame parent, SwingView view) {
\r
66 setMnemonic(KeyEvent.VK_E);
\r
67 getAccessibleContext().setAccessibleDescription(
\r
70 actionClearAllMoves = new ClearAllMovesAction("Clear all moves",
\r
71 StockIcons.ICON_CLEAR, "Clear all my moves", new Integer(
\r
72 KeyEvent.VK_X), view);
\r
73 actions.put("ClearAllMoves", actionClearAllMoves);
\r
75 actionEraseAllMemos = new EraseAllMemosAction("Erase all memos",
\r
76 StockIcons.ICON_CLEAR_ALL_MEMOS, "Erase all memos...", new Integer(
\r
77 KeyEvent.VK_X), view);
\r
78 actions.put("EraseAllMemos", actionEraseAllMemos);
\r
80 actionCustomGrid = new CustomGridAction("Custom grid",
\r
81 StockIcons.ICON_EDIT, "Compose a custom grid...", new Integer(
\r
82 KeyEvent.VK_G), view);
\r
83 actions.put("CustomGrid", actionCustomGrid);
\r
85 actionPlayCustomGrid = new PlayCustomGridAction("Play custom grid",
\r
86 StockIcons.ICON_PLAY, "Play with current grid...", new Integer(
\r
87 KeyEvent.VK_H), view);
\r
88 actions.put("PlayCustomGrid", actionPlayCustomGrid);
\r
90 addItems(actions, parent, view);
\r
92 setL10nMessages(null, _("DETECTED_LANGUAGE"));
\r
93 localeListener = new LocaleListenerImpl(this);
\r
94 I18n.addLocaleListener(localeListener);
\r
97 private void addItems(ActionsRepository actions, JFrame parent, SwingView view) {
\r
99 itemClearAllMoves.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
\r
100 ActionEvent.CTRL_MASK));
\r
101 itemClearAllMoves.setAction(actionClearAllMoves);
\r
102 actionClearAllMoves.setEnabled(false);
\r
103 add(itemClearAllMoves);
\r
105 itemEraseAllMemos.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M,
\r
106 ActionEvent.CTRL_MASK));
\r
107 itemEraseAllMemos.setAction(actionEraseAllMemos);
\r
108 actionEraseAllMemos.setEnabled(false);
\r
109 add(itemEraseAllMemos);
\r
113 levelMenu = new LevelMenu();
\r
116 add(new NumbersMenu(view));
\r
118 add(new LanguageMenu());
\r
122 cheatMenu = new CheatMenu(actions, parent, view);
\r
127 itemCustomGrid.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G,
\r
128 ActionEvent.CTRL_MASK));
\r
129 itemCustomGrid.setAction(actionCustomGrid);
\r
130 itemCustomGrid.setEnabled(true);
\r
131 add(itemCustomGrid);
\r
133 itemPlayCustomGrid.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H,
\r
134 ActionEvent.CTRL_MASK));
\r
135 itemPlayCustomGrid.setAction(actionPlayCustomGrid);
\r
136 itemPlayCustomGrid.setEnabled(false);
\r
137 add(itemPlayCustomGrid);
\r
140 public CheatMenu getCheatMenu() {
\r
144 public LevelMenu getLevelMenu() {
\r