OSDN Git Service

- Fixed item #3520726 "Cannot enter filename when saving a grid on MacOS X"
authorSylvain Vedrenne <sylvain@jankenpoi.net>
Mon, 30 Apr 2012 22:04:34 +0000 (00:04 +0200)
committerSylvain Vedrenne <sylvain@jankenpoi.net>
Mon, 30 Apr 2012 22:04:34 +0000 (00:04 +0200)
- Fixed item #3522650 "Corrupted or wrong grid files are not correctly handled"

README
src/classes/net/jankenpoi/sudokuki/controller/GridController.java
src/classes/net/jankenpoi/sudokuki/model/GridModel.java
src/classes/net/jankenpoi/sudokuki/ui/swing/OpenGridAction.java
src/classes/net/jankenpoi/sudokuki/ui/swing/SaveAsAction.java

diff --git a/README b/README
index 74a2070..69bcce9 100644 (file)
--- a/README
+++ b/README
@@ -2,6 +2,13 @@ Sudokuki - essential sudoku game
 
 -- Changelog --
 
+* 2012-xx-xx - released Sudokuki 1.1.4 (Stable)
+- Fixed item #3520726 "Cannot enter filename when saving a grid on MacOS X"
+- Fixed item #3522650 "Corrupted or wrong grid files are not correctly handled"
+- Fixed item #3520759 "AboutDialog: ensure all text is visible (like for GPLv3 txt)"
+- Fixed item #3522280 "With Sun/Oracle JDK: fatal error: jni_md.h: No such file ..."
+- Updated Portuguese and Russian po files with Dutch translator's name
+
 * 2012-04-28 - released Sudokuki 1.1.3 (Stable)
 - Dutch translations from Jeroen P. Broks. Added country flag for new translation, 
   updated some po files accordingly.
index ce09e96..a02b54c 100644 (file)
@@ -100,12 +100,17 @@ public class GridController {
                model.fireGridChanged(new GridChangedEvent(model, 0, 0, (short)0));
        }
 
-       public void notifyResetGridFromShorts(short[] externalCellInfos) {
-               if (model.getCustomGridMode()) {
+       public boolean notifyResetGridFromShorts(short[] externalCellInfos) {
+               final boolean wasCustomGridModeOn = model.getCustomGridMode();
+               if (wasCustomGridModeOn) {
                        model.exitCustomGridMode();
                }
-               model.resetGridModelFromShorts(externalCellInfos);
+               boolean result = model.resetGridModelFromShorts(externalCellInfos);
+               if (wasCustomGridModeOn && result == false) {
+                       model.enterCustomGridMode();
+               }
                model.fireGridChanged(new GridChangedEvent(model, 0, 0, (short)0));
+               return result;
        }
 
        public int[] getCellInfosFromModel() {
index 879a72b..0e4892b 100644 (file)
@@ -77,12 +77,24 @@ public class GridModel implements Cloneable {
                newGrid();
        }
 
-       public void resetGridModelFromShorts(short[] externalCellInfos) {
-               cellInfos = new short[81];
+       public boolean resetGridModelFromShorts(short[] externalCellInfos) {
+               short[] oldCellInfos = new short[81];
+               for (int i=0; i<81; i++) {
+                       oldCellInfos[i] = cellInfos[i];
+               }
                
+               cellInfos = new short[81];
                for (int i=0; i<81; i++) {
                        cellInfos[i] = externalCellInfos[i];
                }
+               if (checkGridValidity().isValid) {
+                       return true;
+               } else {
+                       for (int i=0; i<81; i++) {
+                               cellInfos[i] = oldCellInfos[i];
+                       }
+                       return false;
+               }
        }
        
        private void newGrid() {
@@ -542,10 +554,15 @@ public class GridModel implements Cloneable {
                Integer squareWithErrorY = null;
                
                // Check validity of all lines
+               lines:
                for (int li = 0; isValid && li < 9; li++) {
                        byte[] numbers = new byte[10];
                        for (int co = 0; co < 9; co++) {
                                byte value = getValueAt(li, co);
+                               if (10 <= value) {
+                                       isValid = false;
+                                       break lines;
+                               }
                                if (numbers[value] != 0) {
                                        isValid = false;
                                        lineWithError = Integer.valueOf(li);
index 05f7e2f..45d5951 100644 (file)
@@ -31,6 +31,7 @@ import javax.swing.JFrame;
 import javax.swing.JOptionPane;
 import javax.swing.filechooser.FileFilter;
 
+import net.jankenpoi.sudokuki.model.GridModel.GridValidity;
 import net.jankenpoi.sudokuki.view.GridView;
 
 @SuppressWarnings("serial")
@@ -67,7 +68,6 @@ public class OpenGridAction extends AbstractAction {
                        
                        @Override
                        public String getDescription() {
-                               // TODO Auto-generated method stub
                                return _("Sudokuki grid files");
                        }
                        
@@ -93,8 +93,6 @@ public class OpenGridAction extends AbstractAction {
                try {
                        fis = new FileInputStream(fileToOpen);
                } catch (FileNotFoundException e1) {
-                       // TODO Auto-generated catch block
-                       e1.printStackTrace();
                }
                if (fis == null) {
             JOptionPane.showMessageDialog(frame, "<html>"
@@ -114,17 +112,23 @@ public class OpenGridAction extends AbstractAction {
 
                                externalCellInfos[i] = (short) together;
                        } catch (IOException e1) {
-                               // TODO Auto-generated catch block
-                               e1.printStackTrace();
+                   JOptionPane.showMessageDialog(frame, "<html>"
+                           + "<table border=\"0\">" + "<tr>"
+                           + _("Failed to open the grid<br/>at the selected location.") + "</tr>"
+                           + "</html>", "Sudokuki", JOptionPane.ERROR_MESSAGE);
                        }
                }
-               view.getController().notifyResetGridFromShorts(externalCellInfos);
-               
+               boolean success = view.getController().notifyResetGridFromShorts(externalCellInfos);
+               if (!success) {
+            JOptionPane.showMessageDialog(frame, "<html>"
+                    + "<table border=\"0\">" + "<tr>"
+                    + _("This file is not a valid Sudokuki grid.") + "</tr>"
+                    + "</html>", "Sudokuki", JOptionPane.ERROR_MESSAGE);
+               }
                try {
                        fis.close();
                } catch (IOException e1) {
-                       // TODO Auto-generated catch block
-                       e1.printStackTrace();
+                       System.out.println("An error occured upon FileInputStream close()");
                }
        }
                
index 8a10a3d..8cfc1b3 100644 (file)
@@ -1,20 +1,3 @@
-/*
- * Sudokuki - essential sudoku game
- * Copyright (C) 2007-2012 Sylvain Vedrenne
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
 package net.jankenpoi.sudokuki.ui.swing;
 
 import static net.jankenpoi.i18n.I18n._;
@@ -28,60 +11,47 @@ import java.io.IOException;
 import javax.swing.AbstractAction;
 import javax.swing.JFileChooser;
 import javax.swing.JFrame;
-import javax.swing.filechooser.FileFilter;
+import javax.swing.JOptionPane;
+import javax.swing.filechooser.FileNameExtensionFilter;
 
+import net.jankenpoi.i18n.I18n;
 import net.jankenpoi.sudokuki.view.GridView;
 
 @SuppressWarnings("serial")
 public class SaveAsAction extends AbstractAction {
-
        private final GridView view;
-
        private final JFrame frame;
-       
+
        SaveAsAction(JFrame frame, GridView view, ActionsRepository actions) {
                this.frame = frame;
                this.view = view;
        }
-       
-       @Override
+
        public void actionPerformed(ActionEvent e) {
+               JFileChooser fc = new JFileChooser() {
 
-               final JFileChooser fc = new JFileChooser() {
                        @Override
                        public File getSelectedFile() {
                                File file = super.getSelectedFile();
                                if (file == null) {
-                                       return null;
+                                       return new File("myGrid.skg");
                                }
-                               if (getExtension(file) == null) {
-                                       file = new File(file.getAbsolutePath() + ".skg");
+                               if (!"skg".equals(getExtension(file))) {
+                                       file = new File(String.valueOf(file.getAbsolutePath())
+                                                       + ".skg");
                                }
                                return file;
                        }
                };
-               
-               fc.setDialogTitle(_("Save as..."));
+
+               fc.setDialogTitle(I18n._("Save as..."));
                fc.setAcceptAllFileFilterUsed(false);
-               fc.setFileFilter(new FileFilter() {
-                                               
-                       @Override
-                       public String getDescription() {
-                               return _("Sudokuki grid files");
-                       }
-                       
-                       @Override
-                       public boolean accept(File f) {
-                               String extension = getExtension(f);
-                               if (f.isDirectory() || "skg".equals(extension)) {
-                                       return true;
-                               }
-                               return false;
-                       }
-               });
-               int returnVal = fc.showOpenDialog(frame);
-               
-               if (returnVal != JFileChooser.APPROVE_OPTION) {
+               FileNameExtensionFilter filter = new FileNameExtensionFilter(
+                               I18n._("Sudokuki grid files"), new String[] { "skg" });
+               fc.setFileFilter(filter);
+               int returnVal = fc.showSaveDialog(this.frame);
+
+               if (returnVal != 0) {
                        return;
                }
                File fileToSave = fc.getSelectedFile();
@@ -92,20 +62,26 @@ public class SaveAsAction extends AbstractAction {
                try {
                        fileToSave.createNewFile();
                } catch (IOException e1) {
-                       e1.printStackTrace();
+            JOptionPane.showMessageDialog(frame, "<html>"
+                    + "<table border=\"0\">" + "<tr>"
+                    + _("Failed to save the grid<br/>at the selected location.") + "</tr>"
+                    + "</html>", "Sudokuki", JOptionPane.ERROR_MESSAGE);
                }
                FileOutputStream fos = null;
                try {
                        fos = new FileOutputStream(fileToSave);
                } catch (FileNotFoundException e1) {
-                       e1.printStackTrace();
+            JOptionPane.showMessageDialog(frame, "<html>"
+                    + "<table border=\"0\">" + "<tr>"
+                    + _("Failed to save the grid<br/>at the selected location.") + "</tr>"
+                    + "</html>", "Sudokuki", JOptionPane.ERROR_MESSAGE);
                }
                if (fos == null) {
                        return;
                }
 
-               int[] cellInfos = view.getController().getCellInfosFromModel();
-               for (int i=0; i<cellInfos.length; i++) {
+               int[] cellInfos = this.view.getController().getCellInfosFromModel();
+               for (int i = 0; i < cellInfos.length; i++) {
                        byte lo = (byte) (cellInfos[i] & 0xFF);
                        byte hi = (byte) ((cellInfos[i] & 0xFF00) >> 8);
                        try {
@@ -121,16 +97,15 @@ public class SaveAsAction extends AbstractAction {
                        e1.printStackTrace();
                }
        }
-       
-       private static String getExtension(File f) {
+
+       private static String getExtension(File file) {
                String ext = null;
-               String s = f.getName();
+               String s = file.getName();
                int i = s.lastIndexOf('.');
 
-               if (i > 0 && i < s.length() - 1) {
+               if ((i > 0) && (i < s.length() - 1)) {
                        ext = s.substring(i + 1).toLowerCase();
                }
                return ext;
        }
-
 }