OSDN Git Service

- Fixed item #3520726 "Cannot enter filename when saving a grid on MacOS X"
[sudokuki/sudokuki.git] / src / classes / net / jankenpoi / sudokuki / model / GridModel.java
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);