diff -r 5179eff8a9b6 -r ed931970b4ac src/de/uapcore/sudoku/ActionHandler.java --- a/src/de/uapcore/sudoku/ActionHandler.java Sat Jan 26 17:42:07 2013 +0100 +++ b/src/de/uapcore/sudoku/ActionHandler.java Sat Jan 26 18:38:12 2013 +0100 @@ -1,3 +1,29 @@ +/* + * Copyright 2013 Mike Becker. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + package de.uapcore.sudoku; import java.awt.event.ActionEvent; @@ -14,6 +40,12 @@ public static final String CHECK = "check"; public static final String SOLVE = "solve"; + public static final String NEW = "new"; + public static final String OPEN = "open"; + public static final String SAVE_AS = "save as"; + public static final String QUIT = "quit"; + public static final String ABOUT = "about"; + private Field field; private Solver solver; @@ -22,14 +54,16 @@ solver = new Solver(); } - private void save() { + private boolean save() { if (solver.check(field)) { field.setAllCellsModified(false); // TODO: save to file + return true; } else { JOptionPane.showMessageDialog(field, "Das Feld kann mit Fehlern nicht gespeichert werden!", "Sudoku", JOptionPane.ERROR_MESSAGE); + return false; } } @@ -50,15 +84,37 @@ @Override public void actionPerformed(ActionEvent e) { switch (e.getActionCommand()) { - case "save": + case SAVE: save(); break; - case "check": + case CHECK: check(); break; - case "solve": + case SOLVE: solve(); break; + case QUIT: + if (field.isAnyCellModified()) { + int result = JOptionPane.showConfirmDialog(field, + "Das Feld ist ungespeichert - jetzt speichern?", + "Sudoku", JOptionPane.YES_NO_CANCEL_OPTION); + if (result == JOptionPane.YES_OPTION) { + if (save()) { + System.exit(0); + } + } else if (result == JOptionPane.NO_OPTION) { + System.exit(0); + } + } else { + System.exit(0); + } + break; + case ABOUT: + JOptionPane.showMessageDialog(field, + "Sudoku - Copyright (c) 2013 Mike Becker\nwww.uap-core.de"+ + "\nPublished under the BSD License", + "Sudoku", JOptionPane.INFORMATION_MESSAGE); + break; default: throw new UnsupportedOperationException( "unknown action: "+e.getActionCommand());