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