Tue, 28 Jul 2020 14:27:14 +0200
bugfix: modified state is reset even when saving fails + more tests
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@2 | 27 | package de.uapcore.sudoku; |
universe@2 | 28 | |
universe@9 | 29 | import javax.swing.*; |
universe@9 | 30 | import java.awt.*; |
universe@2 | 31 | |
universe@2 | 32 | /** |
universe@10 | 33 | * The panel displaying some actions for the Sudoku solver. |
universe@2 | 34 | */ |
universe@2 | 35 | public final class ButtonPanel extends JPanel { |
universe@2 | 36 | |
universe@12 | 37 | private final JButton save, check, solve; |
universe@2 | 38 | |
universe@2 | 39 | public ButtonPanel(ActionHandler l) { |
universe@2 | 40 | setLayout(new GridBagLayout()); |
universe@2 | 41 | |
universe@2 | 42 | GridBagConstraints c = new GridBagConstraints(); |
universe@2 | 43 | c.insets = new Insets(10, 10, 10, 10); |
universe@2 | 44 | c.fill = GridBagConstraints.HORIZONTAL; |
universe@2 | 45 | c.weightx = 1; |
universe@2 | 46 | |
universe@2 | 47 | c.gridx = 0; |
universe@2 | 48 | c.gridy = 0; |
universe@2 | 49 | save = new JButton("Speichern"); |
universe@2 | 50 | add(save, c); |
universe@2 | 51 | c.gridx++; |
universe@2 | 52 | check = new JButton("Prüfen"); |
universe@2 | 53 | add(check, c); |
universe@2 | 54 | solve = new JButton("Lösen"); |
universe@2 | 55 | c.gridx++; |
universe@2 | 56 | add(solve, c); |
universe@2 | 57 | |
universe@2 | 58 | save.setActionCommand(ActionHandler.SAVE); |
universe@2 | 59 | save.addActionListener(l); |
universe@2 | 60 | check.setActionCommand(ActionHandler.CHECK); |
universe@2 | 61 | check.addActionListener(l); |
universe@2 | 62 | solve.setActionCommand(ActionHandler.SOLVE); |
universe@2 | 63 | solve.addActionListener(l); |
universe@2 | 64 | |
universe@2 | 65 | setBackground(Color.WHITE); |
universe@2 | 66 | } |
universe@2 | 67 | } |