Wed, 26 Aug 2020 19:09:07 +0200
fixes wrong call of assertEquals()
1 /*
2 * Copyright 2013 Mike Becker. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
25 */
27 package de.uapcore.sudoku;
29 import javax.swing.*;
31 /**
32 * Main menu bar.
33 */
34 public class MainMenu extends JMenuBar {
36 private final ActionHandler handler;
38 public MainMenu(ActionHandler h) {
39 handler = h;
40 add(createMenu("Datei", 'd',
41 createMenuItem("Neu", 'n', "control N", ActionHandler.NEW),
42 createMenuItem("Öffnen", 'f', "control O", ActionHandler.OPEN),
43 createMenuItem("Speichern", 's', "control S", ActionHandler.SAVE),
44 createMenuItem("Speichern als...", 'a', ActionHandler.SAVE_AS),
45 createSeparator(),
46 createMenuItem("Prüfen", 'p', "control P", ActionHandler.CHECK),
47 createMenuItem("Lösen", 'l', "control L", ActionHandler.SOLVE),
48 createSeparator(),
49 createMenuItem("Beenden", 'e', ActionHandler.QUIT)
50 ));
51 add(createMenu("Info", 'i',
52 createMenuItem("Über...", 'b', "F1", ActionHandler.ABOUT)
53 ));
54 }
56 private JMenuItem createSeparator() {
57 // Return null, the createMenu method knows how to handle it
58 return null;
59 }
61 private JMenu createMenu(String caption, char mnemonic, JMenuItem...items) {
62 JMenu menu = new JMenu(caption);
63 menu.setMnemonic(mnemonic);
64 for (JMenuItem item : items) {
65 if (item == null) {
66 menu.addSeparator();
67 } else {
68 menu.add(item);
69 }
70 }
71 return menu;
72 }
74 private JMenuItem createMenuItem(String caption, char mnemonic,
75 String command) {
76 return createMenuItem(caption, mnemonic, null, command);
77 }
79 private JMenuItem createMenuItem(String caption, char mnemonic,
80 String stroke, String command) {
81 JMenuItem item = new JMenuItem(caption);
82 item.setMnemonic(mnemonic);
83 if (stroke != null) {
84 item.setAccelerator(KeyStroke.getKeyStroke(stroke));
85 }
86 item.setActionCommand(command);
87 item.addActionListener(handler);
89 return item;
90 }
92 }