Wed, 26 Aug 2020 19:09:07 +0200
fixes wrong call of assertEquals()
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@18 | 34 | public class MainMenu extends JMenuBar { |
universe@3 | 35 | |
universe@12 | 36 | private final ActionHandler handler; |
universe@18 | 37 | |
universe@3 | 38 | public MainMenu(ActionHandler h) { |
universe@3 | 39 | handler = h; |
universe@18 | 40 | add(createMenu("Datei", 'd', |
universe@3 | 41 | createMenuItem("Neu", 'n', "control N", ActionHandler.NEW), |
universe@3 | 42 | createMenuItem("Öffnen", 'f', "control O", ActionHandler.OPEN), |
universe@3 | 43 | createMenuItem("Speichern", 's', "control S", ActionHandler.SAVE), |
universe@3 | 44 | createMenuItem("Speichern als...", 'a', ActionHandler.SAVE_AS), |
universe@3 | 45 | createSeparator(), |
universe@3 | 46 | createMenuItem("Prüfen", 'p', "control P", ActionHandler.CHECK), |
universe@3 | 47 | createMenuItem("Lösen", 'l', "control L", ActionHandler.SOLVE), |
universe@3 | 48 | createSeparator(), |
universe@3 | 49 | createMenuItem("Beenden", 'e', ActionHandler.QUIT) |
universe@3 | 50 | )); |
universe@18 | 51 | add(createMenu("Info", 'i', |
universe@3 | 52 | createMenuItem("Über...", 'b', "F1", ActionHandler.ABOUT) |
universe@3 | 53 | )); |
universe@3 | 54 | } |
universe@3 | 55 | |
universe@3 | 56 | private JMenuItem createSeparator() { |
universe@3 | 57 | // Return null, the createMenu method knows how to handle it |
universe@3 | 58 | return null; |
universe@3 | 59 | } |
universe@3 | 60 | |
universe@3 | 61 | private JMenu createMenu(String caption, char mnemonic, JMenuItem...items) { |
universe@3 | 62 | JMenu menu = new JMenu(caption); |
universe@3 | 63 | menu.setMnemonic(mnemonic); |
universe@3 | 64 | for (JMenuItem item : items) { |
universe@3 | 65 | if (item == null) { |
universe@3 | 66 | menu.addSeparator(); |
universe@3 | 67 | } else { |
universe@3 | 68 | menu.add(item); |
universe@3 | 69 | } |
universe@3 | 70 | } |
universe@3 | 71 | return menu; |
universe@3 | 72 | } |
universe@3 | 73 | |
universe@3 | 74 | private JMenuItem createMenuItem(String caption, char mnemonic, |
universe@3 | 75 | String command) { |
universe@3 | 76 | return createMenuItem(caption, mnemonic, null, command); |
universe@3 | 77 | } |
universe@3 | 78 | |
universe@3 | 79 | private JMenuItem createMenuItem(String caption, char mnemonic, |
universe@3 | 80 | String stroke, String command) { |
universe@3 | 81 | JMenuItem item = new JMenuItem(caption); |
universe@3 | 82 | item.setMnemonic(mnemonic); |
universe@3 | 83 | if (stroke != null) { |
universe@3 | 84 | item.setAccelerator(KeyStroke.getKeyStroke(stroke)); |
universe@3 | 85 | } |
universe@3 | 86 | item.setActionCommand(command); |
universe@3 | 87 | item.addActionListener(handler); |
universe@3 | 88 | |
universe@3 | 89 | return item; |
universe@3 | 90 | } |
universe@18 | 91 | |
universe@3 | 92 | } |