1.1 --- a/src/de/uapcore/sudoku/ActionHandler.java Sat Jan 26 17:42:07 2013 +0100 1.2 +++ b/src/de/uapcore/sudoku/ActionHandler.java Sat Jan 26 18:38:12 2013 +0100 1.3 @@ -1,3 +1,29 @@ 1.4 +/* 1.5 + * Copyright 2013 Mike Becker. All rights reserved. 1.6 + * 1.7 + * Redistribution and use in source and binary forms, with or without 1.8 + * modification, are permitted provided that the following conditions are met: 1.9 + * 1.10 + * 1. Redistributions of source code must retain the above copyright 1.11 + * notice, this list of conditions and the following disclaimer. 1.12 + * 1.13 + * 2. Redistributions in binary form must reproduce the above copyright 1.14 + * notice, this list of conditions and the following disclaimer in the 1.15 + * documentation and/or other materials provided with the distribution. 1.16 + * 1.17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 1.18 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1.20 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 1.21 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1.22 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1.23 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1.24 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1.25 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.26 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1.27 + * POSSIBILITY OF SUCH DAMAGE. 1.28 + */ 1.29 + 1.30 package de.uapcore.sudoku; 1.31 1.32 import java.awt.event.ActionEvent; 1.33 @@ -14,6 +40,12 @@ 1.34 public static final String CHECK = "check"; 1.35 public static final String SOLVE = "solve"; 1.36 1.37 + public static final String NEW = "new"; 1.38 + public static final String OPEN = "open"; 1.39 + public static final String SAVE_AS = "save as"; 1.40 + public static final String QUIT = "quit"; 1.41 + public static final String ABOUT = "about"; 1.42 + 1.43 private Field field; 1.44 private Solver solver; 1.45 1.46 @@ -22,14 +54,16 @@ 1.47 solver = new Solver(); 1.48 } 1.49 1.50 - private void save() { 1.51 + private boolean save() { 1.52 if (solver.check(field)) { 1.53 field.setAllCellsModified(false); 1.54 // TODO: save to file 1.55 + return true; 1.56 } else { 1.57 JOptionPane.showMessageDialog(field, 1.58 "Das Feld kann mit Fehlern nicht gespeichert werden!", 1.59 "Sudoku", JOptionPane.ERROR_MESSAGE); 1.60 + return false; 1.61 } 1.62 } 1.63 1.64 @@ -50,15 +84,37 @@ 1.65 @Override 1.66 public void actionPerformed(ActionEvent e) { 1.67 switch (e.getActionCommand()) { 1.68 - case "save": 1.69 + case SAVE: 1.70 save(); 1.71 break; 1.72 - case "check": 1.73 + case CHECK: 1.74 check(); 1.75 break; 1.76 - case "solve": 1.77 + case SOLVE: 1.78 solve(); 1.79 break; 1.80 + case QUIT: 1.81 + if (field.isAnyCellModified()) { 1.82 + int result = JOptionPane.showConfirmDialog(field, 1.83 + "Das Feld ist ungespeichert - jetzt speichern?", 1.84 + "Sudoku", JOptionPane.YES_NO_CANCEL_OPTION); 1.85 + if (result == JOptionPane.YES_OPTION) { 1.86 + if (save()) { 1.87 + System.exit(0); 1.88 + } 1.89 + } else if (result == JOptionPane.NO_OPTION) { 1.90 + System.exit(0); 1.91 + } 1.92 + } else { 1.93 + System.exit(0); 1.94 + } 1.95 + break; 1.96 + case ABOUT: 1.97 + JOptionPane.showMessageDialog(field, 1.98 + "Sudoku - Copyright (c) 2013 Mike Becker\nwww.uap-core.de"+ 1.99 + "\nPublished under the BSD License", 1.100 + "Sudoku", JOptionPane.INFORMATION_MESSAGE); 1.101 + break; 1.102 default: 1.103 throw new UnsupportedOperationException( 1.104 "unknown action: "+e.getActionCommand());