1.1 --- a/src/de/uapcore/sudoku/Field.java Fri Feb 01 10:18:47 2013 +0100 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,182 +0,0 @@ 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.Color; 1.33 -import java.awt.Graphics; 1.34 -import java.awt.Graphics2D; 1.35 -import java.awt.GridBagConstraints; 1.36 -import java.awt.GridBagLayout; 1.37 -import java.awt.Insets; 1.38 -import java.awt.image.BufferedImage; 1.39 -import javax.swing.JPanel; 1.40 - 1.41 -/** 1.42 - * 1.43 - * @author mike 1.44 - */ 1.45 -public final class Field extends JPanel { 1.46 - private SudokuTextField[][] cells; 1.47 - 1.48 - public Field() { 1.49 - setBackground(Color.WHITE); 1.50 - 1.51 - setLayout(new GridBagLayout()); 1.52 - GridBagConstraints c = new GridBagConstraints(); 1.53 - c.insets = new Insets(5, 5, 5, 5); 1.54 - 1.55 - cells = new SudokuTextField[9][9]; 1.56 - for (int x = 0 ; x < 9 ; x++) { 1.57 - for (int y = 0 ; y < 9 ; y++) { 1.58 - cells[x][y] = new SudokuTextField(); 1.59 - c.gridx = x; 1.60 - c.gridy = y; 1.61 - add(cells[x][y], c); 1.62 - } 1.63 - } 1.64 - } 1.65 - 1.66 - @Override 1.67 - public void paint(Graphics graphics) { 1.68 - final int w = getWidth(); 1.69 - final int h = getHeight(); 1.70 - final int cw = w / 9; 1.71 - final int ch = h / 9; 1.72 - 1.73 - BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); 1.74 - Graphics2D g = img.createGraphics(); 1.75 - g.setBackground(Color.WHITE); 1.76 - g.clearRect(0, 0, w, h); 1.77 - 1.78 - g.setColor(Color.BLACK); 1.79 - g.drawRect(1, 1, w-2, h-2); 1.80 - g.drawRect(2, 2, w-4, h-4); 1.81 - for (int x = cw ; x < w ; x += cw) { 1.82 - for (int y = ch ; y < h ; y += ch) { 1.83 - g.drawLine(x, 2, x, h-2); 1.84 - g.drawLine(2, y, w-2, y); 1.85 - if ((x / cw) % 3 == 0) { 1.86 - g.drawLine(x+1, 2, x+1, h-2); 1.87 - } 1.88 - if ((y / ch) % 3 == 0) { 1.89 - g.drawLine(2, y+1, w-2, y+1); 1.90 - } 1.91 - } 1.92 - } 1.93 - 1.94 - graphics.drawImage(img, 0, 0, this); 1.95 - super.paintChildren(graphics); 1.96 - } 1.97 - 1.98 - public boolean isCellEmpty(int x, int y) { 1.99 - return getCellValue(x, y) == 0; 1.100 - } 1.101 - 1.102 - public int getCellValue(int x, int y) { 1.103 - return cells[x][y].getValue(); 1.104 - } 1.105 - 1.106 - public void setCellValue(int x, int y, int v) { 1.107 - cells[x][y].setValue(v); 1.108 - } 1.109 - 1.110 - public void clearCellValue(int x, int y) { 1.111 - setCellValue(x, y, 0); 1.112 - } 1.113 - 1.114 - public void setCellModified(int x, int y, boolean modified) { 1.115 - cells[x][y].setModified(modified); 1.116 - } 1.117 - 1.118 - public void setAllCellsModified(boolean modified) { 1.119 - for (int x = 0 ; x < 9 ; x++) { 1.120 - for (int y = 0 ; y < 9 ; y++) { 1.121 - cells[x][y].setModified(modified); 1.122 - } 1.123 - } 1.124 - } 1.125 - 1.126 - public boolean isAnyCellModified() { 1.127 - for (int x = 0 ; x < 9 ; x++) { 1.128 - for (int y = 0 ; y < 9 ; y++) { 1.129 - if (cells[x][y].isModified()) { 1.130 - return true; 1.131 - } 1.132 - } 1.133 - } 1.134 - return false; 1.135 - } 1.136 - 1.137 - public void clear() { 1.138 - for (int x = 0 ; x < 9 ; x++) { 1.139 - for (int y = 0 ; y < 9 ; y++) { 1.140 - cells[x][y].setValue(0); 1.141 - } 1.142 - } 1.143 - } 1.144 - 1.145 - public int[][] getSquare(int x, int y) { 1.146 - if (x < 0 || x > 2 || y < 0 || y > 2) { 1.147 - throw new IllegalArgumentException("Invalid square coordinates"); 1.148 - } 1.149 - int[][] square = new int[3][3]; 1.150 - 1.151 - for (int u = 0 ; u < 3 ; u++) { 1.152 - for (int v = 0 ; v < 3 ; v++) { 1.153 - square[u][v] = getCellValue(3*x+u, 3*y+v); 1.154 - } 1.155 - } 1.156 - 1.157 - return square; 1.158 - } 1.159 - 1.160 - public int[] getRow(int y) { 1.161 - if (y < 0 || y > 8) { 1.162 - throw new IllegalArgumentException("Invalid row number"); 1.163 - } 1.164 - int row[] = new int[9]; 1.165 - 1.166 - for (int x = 0 ; x < 9 ; x++) { 1.167 - row[x] = getCellValue(x, y); 1.168 - } 1.169 - 1.170 - return row; 1.171 - } 1.172 - 1.173 - public int[] getColumn(int x) { 1.174 - if (x < 0 || x > 8) { 1.175 - throw new IllegalArgumentException("Invalid column number"); 1.176 - } 1.177 - int column[] = new int[9]; 1.178 - 1.179 - for (int y = 0 ; y < 9 ; y++) { 1.180 - column[y] = getCellValue(x, y); 1.181 - } 1.182 - 1.183 - return column; 1.184 - } 1.185 -}