2 * Sudokuki - essential sudoku game
\r
3 * Copyright (C) 2007-2011 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 FileMenu extends JMenu implements L10nComponent {
\r
39 private final JMenuItem itemNew = new JMenuItem();
\r
40 private final JMenuItem itemOpen = new JMenuItem();
\r
41 private final JMenuItem itemSaveAs = new JMenuItem();
\r
42 private final JMenuItem itemPrint = new JMenuItem();
\r
43 private final JMenuItem itemPrintMulti = new JMenuItem();
\r
44 private final JMenuItem itemQuit = new JMenuItem();
\r
45 private final Action actionNew;
\r
46 private final Action actionOpen;
\r
47 private final Action actionSaveAs;
\r
48 private final Action actionQuit = new QuitAction();
\r
49 private final Action actionPrint;
\r
50 private final Action actionPrintMulti;
\r
52 private final LocaleListener localeListener;
\r
54 public void setL10nMessages(Locale locale, String languageCode) {
\r
57 itemNew.setText(_("New"));
\r
58 actionNew.putValue(Action.SMALL_ICON, StockIcons.ICON_NEW);
\r
59 actionNew.putValue(Action.SHORT_DESCRIPTION, _("New"));
\r
60 actionNew.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_N));
\r
62 itemOpen.setText(_("Open"));
\r
63 actionOpen.putValue(Action.SMALL_ICON, StockIcons.ICON_OPEN);
\r
64 actionOpen.putValue(Action.SHORT_DESCRIPTION, _("Open"));
\r
65 actionOpen.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_O));
\r
67 itemSaveAs.setText(_("Save as"));
\r
68 actionSaveAs.putValue(Action.SMALL_ICON, StockIcons.ICON_SAVE_AS);
\r
69 actionSaveAs.putValue(Action.SHORT_DESCRIPTION, _("Save as"));
\r
70 actionSaveAs.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_S));
\r
72 itemPrint.setText(_("Print"));
\r
73 actionPrint.putValue(Action.SMALL_ICON, StockIcons.ICON_PRINT);
\r
74 actionPrint.putValue(Action.SHORT_DESCRIPTION, _("Print the grid"));
\r
75 actionPrint.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_P));
\r
77 itemPrintMulti.setText(_("Print x 4..."));
\r
78 actionPrintMulti.putValue(Action.SMALL_ICON,
\r
79 StockIcons.ICON_PRINTER_INFO);
\r
80 actionPrintMulti.putValue(Action.SHORT_DESCRIPTION,
\r
81 _("Print four grids"));
\r
83 itemQuit.setText(_("Quit"));
\r
84 actionQuit.putValue(Action.SMALL_ICON, StockIcons.ICON_QUIT);
\r
86 .putValue(Action.SHORT_DESCRIPTION, _("Quit the application"));
\r
87 actionQuit.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_Q));
\r
90 FileMenu(JFrame parent, ActionsRepository actions, SwingGrid grid, SwingView view) {
\r
92 setMnemonic(KeyEvent.VK_F);
\r
93 getAccessibleContext().setAccessibleDescription("File menu");
\r
95 actionNew = new NewGridAction(parent, view, actions);
\r
96 actions.put("NewGrid", actionNew);
\r
97 actionOpen = new OpenGridAction(parent, view, actions);
\r
98 actions.put("OpenGrid", actionOpen);
\r
99 actionSaveAs = new SaveAsAction(parent, view, actions);
\r
100 actions.put("SaveAs", actionSaveAs);
\r
101 actionPrint = new PrintAction(grid);
\r
102 actions.put("Print", actionPrint);
\r
103 actionPrintMulti = new PrintMultiAction(parent, view);
\r
104 actions.put("PrintMulti", actionPrintMulti);;
\r
106 setL10nMessages(null, null);
\r
107 localeListener = new LocaleListenerImpl(this);
\r
108 I18n.addLocaleListener(localeListener);
\r
111 private void addItems() {
\r
113 itemNew.setAction(actionNew);
\r
114 itemNew.setIcon(StockIcons.ICON_NEW);
\r
115 itemNew.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
\r
116 ActionEvent.CTRL_MASK));
\r
119 itemPrint.setAction(actionPrint);
\r
122 itemPrintMulti.setAction(actionPrintMulti);
\r
123 add(itemPrintMulti);
\r
127 itemOpen.setAction(actionOpen);
\r
128 itemOpen.setIcon(StockIcons.ICON_OPEN);
\r
129 itemOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
\r
130 ActionEvent.CTRL_MASK));
\r
133 itemSaveAs.setAction(actionSaveAs);
\r
134 itemSaveAs.setIcon(StockIcons.ICON_SAVE_AS);
\r
135 itemSaveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
\r
136 ActionEvent.CTRL_MASK));
\r
137 itemSaveAs.setMnemonic(KeyEvent.VK_S);
\r
142 itemQuit.setAction(actionQuit);
\r
143 itemQuit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
\r
144 ActionEvent.CTRL_MASK));
\r