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