Sat, 25 Jul 2020 15:56:48 +0200
missing class documentation
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 {
36 private ActionHandler handler;
37 private JMenuBar menuBar;
39 public MainMenu(ActionHandler h) {
40 handler = h;
41 menuBar = new JMenuBar();
42 menuBar.add(createMenu("Datei", 'd',
43 createMenuItem("Neu", 'n', "control N", ActionHandler.NEW),
44 createMenuItem("Öffnen", 'f', "control O", ActionHandler.OPEN),
45 createMenuItem("Speichern", 's', "control S", ActionHandler.SAVE),
46 createMenuItem("Speichern als...", 'a', ActionHandler.SAVE_AS),
47 createSeparator(),
48 createMenuItem("Prüfen", 'p', "control P", ActionHandler.CHECK),
49 createMenuItem("Lösen", 'l', "control L", ActionHandler.SOLVE),
50 createSeparator(),
51 createMenuItem("Beenden", 'e', ActionHandler.QUIT)
52 ));
53 menuBar.add(createMenu("Help", 'h',
54 createMenuItem("Über...", 'b', "F1", ActionHandler.ABOUT)
55 ));
56 }
58 private JMenuItem createSeparator() {
59 // Return null, the createMenu method knows how to handle it
60 return null;
61 }
63 private JMenu createMenu(String caption, char mnemonic, JMenuItem...items) {
64 JMenu menu = new JMenu(caption);
65 menu.setMnemonic(mnemonic);
66 for (JMenuItem item : items) {
67 if (item == null) {
68 menu.addSeparator();
69 } else {
70 menu.add(item);
71 }
72 }
73 return menu;
74 }
76 private JMenuItem createMenuItem(String caption, char mnemonic,
77 String command) {
78 return createMenuItem(caption, mnemonic, null, command);
79 }
81 private JMenuItem createMenuItem(String caption, char mnemonic,
82 String stroke, String command) {
83 JMenuItem item = new JMenuItem(caption);
84 item.setMnemonic(mnemonic);
85 if (stroke != null) {
86 item.setAccelerator(KeyStroke.getKeyStroke(stroke));
87 }
88 item.setActionCommand(command);
89 item.addActionListener(handler);
91 return item;
92 }
94 public JMenuBar getMenuBar() {
95 return menuBar;
96 }
97 }