added license and main menu

Sat, 26 Jan 2013 18:38:12 +0100

author
Mike Becker <universe@uap-core.de>
date
Sat, 26 Jan 2013 18:38:12 +0100
changeset 3
ed931970b4ac
parent 2
5179eff8a9b6
child 4
b8588e318001

added license and main menu

LICENSE file | annotate | diff | comparison | revisions
src/de/uapcore/sudoku/ActionHandler.java file | annotate | diff | comparison | revisions
src/de/uapcore/sudoku/ButtonPanel.java file | annotate | diff | comparison | revisions
src/de/uapcore/sudoku/Field.java file | annotate | diff | comparison | revisions
src/de/uapcore/sudoku/MainMenu.java file | annotate | diff | comparison | revisions
src/de/uapcore/sudoku/Solver.java file | annotate | diff | comparison | revisions
src/de/uapcore/sudoku/Sudoku.java file | annotate | diff | comparison | revisions
src/de/uapcore/sudoku/SudokuTextField.java file | annotate | diff | comparison | revisions
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/LICENSE	Sat Jan 26 18:38:12 2013 +0100
     1.3 @@ -0,0 +1,25 @@
     1.4 +Copyright 2013 Mike Becker. All rights reserved.
     1.5 +
     1.6 +Redistribution and use in source and binary forms, with or without
     1.7 +modification, are permitted provided that the following conditions are met:
     1.8 +
     1.9 +  1. Redistributions of source code must retain the above copyright
    1.10 +     notice, this list of conditions and the following disclaimer.
    1.11 +
    1.12 +  2. Redistributions in binary form must reproduce the above copyright
    1.13 +     notice, this list of conditions and the following disclaimer in the
    1.14 +     documentation and/or other materials provided with the distribution.
    1.15 +
    1.16 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1.17 +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.18 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.19 +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    1.20 +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    1.21 +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    1.22 +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    1.23 +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    1.24 +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    1.25 +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    1.26 +POSSIBILITY OF SUCH DAMAGE.
    1.27 +
    1.28 +
     2.1 --- a/src/de/uapcore/sudoku/ActionHandler.java	Sat Jan 26 17:42:07 2013 +0100
     2.2 +++ b/src/de/uapcore/sudoku/ActionHandler.java	Sat Jan 26 18:38:12 2013 +0100
     2.3 @@ -1,3 +1,29 @@
     2.4 +/*
     2.5 + * Copyright 2013 Mike Becker. All rights reserved.
     2.6 + * 
     2.7 + * Redistribution and use in source and binary forms, with or without
     2.8 + * modification, are permitted provided that the following conditions are met:
     2.9 + * 
    2.10 + * 1. Redistributions of source code must retain the above copyright
    2.11 + *    notice, this list of conditions and the following disclaimer.
    2.12 + * 
    2.13 + * 2. Redistributions in binary form must reproduce the above copyright
    2.14 + *    notice, this list of conditions and the following disclaimer in the
    2.15 + *    documentation and/or other materials provided with the distribution.
    2.16 + * 
    2.17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    2.18 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    2.19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    2.20 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    2.21 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    2.22 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    2.23 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    2.24 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    2.25 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    2.26 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    2.27 + * POSSIBILITY OF SUCH DAMAGE.
    2.28 + */
    2.29 +
    2.30  package de.uapcore.sudoku;
    2.31  
    2.32  import java.awt.event.ActionEvent;
    2.33 @@ -14,6 +40,12 @@
    2.34      public static final String CHECK = "check";
    2.35      public static final String SOLVE = "solve";
    2.36      
    2.37 +    public static final String NEW = "new";
    2.38 +    public static final String OPEN = "open";
    2.39 +    public static final String SAVE_AS = "save as";
    2.40 +    public static final String QUIT = "quit";
    2.41 +    public static final String ABOUT = "about";
    2.42 +    
    2.43      private Field field;
    2.44      private Solver solver;
    2.45      
    2.46 @@ -22,14 +54,16 @@
    2.47          solver = new Solver();
    2.48      }
    2.49      
    2.50 -    private void save() {
    2.51 +    private boolean save() {
    2.52          if (solver.check(field)) {
    2.53              field.setAllCellsModified(false);
    2.54              // TODO: save to file
    2.55 +            return true;
    2.56          } else {
    2.57              JOptionPane.showMessageDialog(field,
    2.58                      "Das Feld kann mit Fehlern nicht gespeichert werden!",
    2.59                      "Sudoku", JOptionPane.ERROR_MESSAGE);
    2.60 +            return false;
    2.61          }
    2.62      }
    2.63      
    2.64 @@ -50,15 +84,37 @@
    2.65      @Override
    2.66      public void actionPerformed(ActionEvent e) {
    2.67          switch (e.getActionCommand()) {
    2.68 -        case "save":
    2.69 +        case SAVE:
    2.70              save();
    2.71              break;
    2.72 -        case "check":
    2.73 +        case CHECK:
    2.74              check();
    2.75              break;
    2.76 -        case "solve":
    2.77 +        case SOLVE:
    2.78              solve();
    2.79              break;
    2.80 +        case QUIT:
    2.81 +            if (field.isAnyCellModified()) {
    2.82 +                int result = JOptionPane.showConfirmDialog(field,
    2.83 +                        "Das Feld ist ungespeichert - jetzt speichern?",
    2.84 +                        "Sudoku", JOptionPane.YES_NO_CANCEL_OPTION);
    2.85 +                if (result == JOptionPane.YES_OPTION) {
    2.86 +                    if (save()) {
    2.87 +                        System.exit(0);
    2.88 +                    }
    2.89 +                } else if (result == JOptionPane.NO_OPTION) {
    2.90 +                    System.exit(0);
    2.91 +                }
    2.92 +            } else {
    2.93 +                System.exit(0);
    2.94 +            }
    2.95 +            break;
    2.96 +        case ABOUT:
    2.97 +            JOptionPane.showMessageDialog(field,
    2.98 +                    "Sudoku - Copyright (c) 2013 Mike Becker\nwww.uap-core.de"+
    2.99 +                    "\nPublished under the BSD License",
   2.100 +                    "Sudoku", JOptionPane.INFORMATION_MESSAGE);
   2.101 +            break;
   2.102          default:
   2.103              throw new UnsupportedOperationException(
   2.104                      "unknown action: "+e.getActionCommand());
     3.1 --- a/src/de/uapcore/sudoku/ButtonPanel.java	Sat Jan 26 17:42:07 2013 +0100
     3.2 +++ b/src/de/uapcore/sudoku/ButtonPanel.java	Sat Jan 26 18:38:12 2013 +0100
     3.3 @@ -1,3 +1,29 @@
     3.4 +/*
     3.5 + * Copyright 2013 Mike Becker. All rights reserved.
     3.6 + * 
     3.7 + * Redistribution and use in source and binary forms, with or without
     3.8 + * modification, are permitted provided that the following conditions are met:
     3.9 + * 
    3.10 + * 1. Redistributions of source code must retain the above copyright
    3.11 + *    notice, this list of conditions and the following disclaimer.
    3.12 + * 
    3.13 + * 2. Redistributions in binary form must reproduce the above copyright
    3.14 + *    notice, this list of conditions and the following disclaimer in the
    3.15 + *    documentation and/or other materials provided with the distribution.
    3.16 + * 
    3.17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    3.18 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    3.19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    3.20 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    3.21 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    3.22 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    3.23 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    3.24 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    3.25 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    3.26 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    3.27 + * POSSIBILITY OF SUCH DAMAGE.
    3.28 + */
    3.29 +
    3.30  package de.uapcore.sudoku;
    3.31  
    3.32  import java.awt.Color;
     4.1 --- a/src/de/uapcore/sudoku/Field.java	Sat Jan 26 17:42:07 2013 +0100
     4.2 +++ b/src/de/uapcore/sudoku/Field.java	Sat Jan 26 18:38:12 2013 +0100
     4.3 @@ -1,3 +1,29 @@
     4.4 +/*
     4.5 + * Copyright 2013 Mike Becker. All rights reserved.
     4.6 + * 
     4.7 + * Redistribution and use in source and binary forms, with or without
     4.8 + * modification, are permitted provided that the following conditions are met:
     4.9 + * 
    4.10 + * 1. Redistributions of source code must retain the above copyright
    4.11 + *    notice, this list of conditions and the following disclaimer.
    4.12 + * 
    4.13 + * 2. Redistributions in binary form must reproduce the above copyright
    4.14 + *    notice, this list of conditions and the following disclaimer in the
    4.15 + *    documentation and/or other materials provided with the distribution.
    4.16 + * 
    4.17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    4.18 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    4.19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    4.20 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    4.21 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    4.22 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    4.23 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    4.24 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    4.25 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    4.26 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    4.27 + * POSSIBILITY OF SUCH DAMAGE.
    4.28 + */
    4.29 +
    4.30  package de.uapcore.sudoku;
    4.31  
    4.32  import java.awt.Color;
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/de/uapcore/sudoku/MainMenu.java	Sat Jan 26 18:38:12 2013 +0100
     5.3 @@ -0,0 +1,101 @@
     5.4 +/*
     5.5 + * Copyright 2013 Mike Becker. All rights reserved.
     5.6 + * 
     5.7 + * Redistribution and use in source and binary forms, with or without
     5.8 + * modification, are permitted provided that the following conditions are met:
     5.9 + * 
    5.10 + * 1. Redistributions of source code must retain the above copyright
    5.11 + *    notice, this list of conditions and the following disclaimer.
    5.12 + * 
    5.13 + * 2. Redistributions in binary form must reproduce the above copyright
    5.14 + *    notice, this list of conditions and the following disclaimer in the
    5.15 + *    documentation and/or other materials provided with the distribution.
    5.16 + * 
    5.17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    5.18 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    5.19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    5.20 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    5.21 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    5.22 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    5.23 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    5.24 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    5.25 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    5.26 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    5.27 + * POSSIBILITY OF SUCH DAMAGE.
    5.28 + */
    5.29 +
    5.30 +package de.uapcore.sudoku;
    5.31 +
    5.32 +import javax.swing.JMenu;
    5.33 +import javax.swing.JMenuBar;
    5.34 +import javax.swing.JMenuItem;
    5.35 +import javax.swing.KeyStroke;
    5.36 +
    5.37 +/**
    5.38 + *
    5.39 + * @author mike
    5.40 + */
    5.41 +public class MainMenu {
    5.42 +    
    5.43 +    private ActionHandler handler;
    5.44 +    private JMenuBar menuBar;
    5.45 +    
    5.46 +    public MainMenu(ActionHandler h) {
    5.47 +        handler = h;
    5.48 +        menuBar = new JMenuBar();
    5.49 +        menuBar.add(createMenu("Datei", 'd',
    5.50 +            createMenuItem("Neu", 'n', "control N", ActionHandler.NEW),
    5.51 +            createMenuItem("Öffnen", 'f', "control O", ActionHandler.OPEN),
    5.52 +            createMenuItem("Speichern", 's', "control S", ActionHandler.SAVE),
    5.53 +            createMenuItem("Speichern als...", 'a', ActionHandler.SAVE_AS),
    5.54 +            createSeparator(),
    5.55 +            createMenuItem("Prüfen", 'p', "control P", ActionHandler.CHECK),
    5.56 +            createMenuItem("Lösen", 'l', "control L", ActionHandler.SOLVE),
    5.57 +            createSeparator(),
    5.58 +            createMenuItem("Beenden", 'e', ActionHandler.QUIT)
    5.59 +        ));
    5.60 +        menuBar.add(createMenu("Help", 'h',
    5.61 +            createMenuItem("Über...", 'b', "F1", ActionHandler.ABOUT)
    5.62 +        ));
    5.63 +    }
    5.64 +    
    5.65 +    private JMenuItem createSeparator() {
    5.66 +        // Return null, the createMenu method knows how to handle it
    5.67 +        return null;
    5.68 +    }
    5.69 +    
    5.70 +    private JMenu createMenu(String caption, char mnemonic, JMenuItem...items) {
    5.71 +        JMenu menu = new JMenu(caption);
    5.72 +        menu.setMnemonic(mnemonic);
    5.73 +        for (JMenuItem item : items) {
    5.74 +            if (item == null) {
    5.75 +                menu.addSeparator();
    5.76 +            } else {
    5.77 +                menu.add(item);
    5.78 +            }
    5.79 +        }
    5.80 +        return menu;
    5.81 +    }
    5.82 +    
    5.83 +    private JMenuItem createMenuItem(String caption, char mnemonic,
    5.84 +            String command) {
    5.85 +        return createMenuItem(caption, mnemonic, null, command);
    5.86 +    }
    5.87 +    
    5.88 +    private JMenuItem createMenuItem(String caption, char mnemonic,
    5.89 +            String stroke, String command) {
    5.90 +        JMenuItem item = new JMenuItem(caption);
    5.91 +        item.setMnemonic(mnemonic);
    5.92 +        if (stroke != null) {
    5.93 +            item.setAccelerator(KeyStroke.getKeyStroke(stroke));
    5.94 +        }
    5.95 +        item.setActionCommand(command);
    5.96 +        item.addActionListener(handler);
    5.97 +        
    5.98 +        return item;
    5.99 +    }
   5.100 +    
   5.101 +    public JMenuBar getMenuBar() {
   5.102 +        return menuBar;
   5.103 +    }
   5.104 +}
     6.1 --- a/src/de/uapcore/sudoku/Solver.java	Sat Jan 26 17:42:07 2013 +0100
     6.2 +++ b/src/de/uapcore/sudoku/Solver.java	Sat Jan 26 18:38:12 2013 +0100
     6.3 @@ -1,3 +1,29 @@
     6.4 +/*
     6.5 + * Copyright 2013 Mike Becker. All rights reserved.
     6.6 + * 
     6.7 + * Redistribution and use in source and binary forms, with or without
     6.8 + * modification, are permitted provided that the following conditions are met:
     6.9 + * 
    6.10 + * 1. Redistributions of source code must retain the above copyright
    6.11 + *    notice, this list of conditions and the following disclaimer.
    6.12 + * 
    6.13 + * 2. Redistributions in binary form must reproduce the above copyright
    6.14 + *    notice, this list of conditions and the following disclaimer in the
    6.15 + *    documentation and/or other materials provided with the distribution.
    6.16 + * 
    6.17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    6.18 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    6.19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    6.20 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    6.21 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    6.22 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    6.23 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    6.24 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    6.25 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    6.26 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    6.27 + * POSSIBILITY OF SUCH DAMAGE.
    6.28 + */
    6.29 +
    6.30  package de.uapcore.sudoku;
    6.31  
    6.32  /**
     7.1 --- a/src/de/uapcore/sudoku/Sudoku.java	Sat Jan 26 17:42:07 2013 +0100
     7.2 +++ b/src/de/uapcore/sudoku/Sudoku.java	Sat Jan 26 18:38:12 2013 +0100
     7.3 @@ -1,11 +1,37 @@
     7.4 +/*
     7.5 + * Copyright 2013 Mike Becker. All rights reserved.
     7.6 + * 
     7.7 + * Redistribution and use in source and binary forms, with or without
     7.8 + * modification, are permitted provided that the following conditions are met:
     7.9 + * 
    7.10 + * 1. Redistributions of source code must retain the above copyright
    7.11 + *    notice, this list of conditions and the following disclaimer.
    7.12 + * 
    7.13 + * 2. Redistributions in binary form must reproduce the above copyright
    7.14 + *    notice, this list of conditions and the following disclaimer in the
    7.15 + *    documentation and/or other materials provided with the distribution.
    7.16 + * 
    7.17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    7.18 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    7.19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    7.20 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    7.21 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    7.22 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    7.23 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    7.24 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    7.25 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    7.26 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    7.27 + * POSSIBILITY OF SUCH DAMAGE.
    7.28 + */
    7.29 +
    7.30  package de.uapcore.sudoku;
    7.31  
    7.32  import java.awt.Color;
    7.33 +import java.awt.Container;
    7.34  import java.awt.GridBagConstraints;
    7.35  import java.awt.GridBagLayout;
    7.36  import java.awt.Insets;
    7.37  import javax.swing.JFrame;
    7.38 -import javax.swing.JRootPane;
    7.39  
    7.40  /**
    7.41   *
    7.42 @@ -18,21 +44,22 @@
    7.43          
    7.44          Field f = new Field();
    7.45          ActionHandler h = new ActionHandler(f);
    7.46 +        setJMenuBar(new MainMenu(h).getMenuBar());
    7.47          
    7.48 -        JRootPane root = getRootPane();
    7.49 +        Container content = getContentPane();
    7.50          
    7.51 -        root.setLayout(new GridBagLayout());
    7.52 +        content.setLayout(new GridBagLayout());
    7.53          GridBagConstraints c = new GridBagConstraints();
    7.54          c.insets = new Insets(20, 20, 20, 20);
    7.55          c.fill = GridBagConstraints.HORIZONTAL;
    7.56          
    7.57          c.gridx = 0; c.gridy = 0;
    7.58 -        root.add(f, c);
    7.59 +        content.add(f, c);
    7.60          c.gridy++;
    7.61 -        root.add(new ButtonPanel(h), c);
    7.62 +        content.add(new ButtonPanel(h), c);
    7.63          
    7.64          pack();
    7.65 -        root.setBackground(Color.WHITE);
    7.66 +        content.setBackground(Color.WHITE);
    7.67          setLocationByPlatform(true);
    7.68          setDefaultCloseOperation(EXIT_ON_CLOSE);
    7.69      }
     8.1 --- a/src/de/uapcore/sudoku/SudokuTextField.java	Sat Jan 26 17:42:07 2013 +0100
     8.2 +++ b/src/de/uapcore/sudoku/SudokuTextField.java	Sat Jan 26 18:38:12 2013 +0100
     8.3 @@ -1,3 +1,29 @@
     8.4 +/*
     8.5 + * Copyright 2013 Mike Becker. All rights reserved.
     8.6 + * 
     8.7 + * Redistribution and use in source and binary forms, with or without
     8.8 + * modification, are permitted provided that the following conditions are met:
     8.9 + * 
    8.10 + * 1. Redistributions of source code must retain the above copyright
    8.11 + *    notice, this list of conditions and the following disclaimer.
    8.12 + * 
    8.13 + * 2. Redistributions in binary form must reproduce the above copyright
    8.14 + *    notice, this list of conditions and the following disclaimer in the
    8.15 + *    documentation and/or other materials provided with the distribution.
    8.16 + * 
    8.17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    8.18 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    8.19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    8.20 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    8.21 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    8.22 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    8.23 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    8.24 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    8.25 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    8.26 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    8.27 + * POSSIBILITY OF SUCH DAMAGE.
    8.28 + */
    8.29 +
    8.30  package de.uapcore.sudoku;
    8.31  
    8.32  import java.awt.Color;
    8.33 @@ -31,19 +57,23 @@
    8.34          
    8.35          addKeyListener(new KeyAdapter() {
    8.36              private void handle(KeyEvent e) {
    8.37 -                if (getText().length() > 0 && getSelectedText() == null) {
    8.38 -                    int c = e.getKeyCode();
    8.39 -                    if (c != KeyEvent.VK_DELETE &&
    8.40 -                            c != KeyEvent.VK_BACK_SPACE &&
    8.41 -                            !e.isActionKey()) {
    8.42 +                char c = e.getKeyChar();
    8.43 +                if (!e.isAltDown() && !e.isControlDown() &&
    8.44 +                        Character.isLetterOrDigit(c)) {
    8.45 +                    // Perform clean input check
    8.46 +                    if (getText().length() > 0 && getSelectedText() == null) {
    8.47                          e.consume();
    8.48 +                    } else {
    8.49 +                        if (c < '1' || c > '9') {
    8.50 +                            e.consume();
    8.51 +                        } else {
    8.52 +                            setModified(true);
    8.53 +                        }
    8.54                      }
    8.55                  } else {
    8.56 -                    char c = e.getKeyChar();
    8.57 -                    if (c < '0' || c > '9') {
    8.58 -                        e.consume();
    8.59 -                    } else {
    8.60 -                        setModified(true);
    8.61 +                    // We can still be tricked by hotkeys, so do it the hard way
    8.62 +                    if (!getText().matches("^[1-9]$")) {
    8.63 +                        setText("");
    8.64                      }
    8.65                  }
    8.66              }

mercurial