src/main/java/de/uapcore/sudoku/MainMenu.java

Sat, 25 Jul 2020 15:56:48 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 25 Jul 2020 15:56:48 +0200
changeset 11
f7433671fec5
parent 10
369903afbb29
child 12
1c62c6009161
permissions
-rw-r--r--

missing class documentation

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

mercurial