# HG changeset patch # User Mike Becker # Date 1359211739 -3600 # Node ID f1d7de36b01e49982689c10c94a0ef0436306695 # Parent 93d6c51154a771f046847bd0762217d7870129c8 init project + editable sudoku field diff -r 93d6c51154a7 -r f1d7de36b01e .hgignore --- a/.hgignore Sat Jan 26 14:49:54 2013 +0100 +++ b/.hgignore Sat Jan 26 15:48:59 2013 +0100 @@ -0,0 +1,5 @@ +\.orig\..*$ +\.orig$ +\.chg\..*$ +\.rej$ +\.conflict\~$ diff -r 93d6c51154a7 -r f1d7de36b01e build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/build.xml Sat Jan 26 15:48:59 2013 +0100 @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project Sudoku. + + + diff -r 93d6c51154a7 -r f1d7de36b01e manifest.mf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/manifest.mf Sat Jan 26 15:48:59 2013 +0100 @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff -r 93d6c51154a7 -r f1d7de36b01e nbproject/build-impl.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nbproject/build-impl.xml Sat Jan 26 15:48:59 2013 +0100 @@ -0,0 +1,1400 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 93d6c51154a7 -r f1d7de36b01e nbproject/genfiles.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nbproject/genfiles.properties Sat Jan 26 15:48:59 2013 +0100 @@ -0,0 +1,8 @@ +build.xml.data.CRC32=7c7a460d +build.xml.script.CRC32=0dfebe00 +build.xml.stylesheet.CRC32=28e38971@1.53.1.46 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=7c7a460d +nbproject/build-impl.xml.script.CRC32=2bd010ed +nbproject/build-impl.xml.stylesheet.CRC32=6ddba6b6@1.53.1.46 diff -r 93d6c51154a7 -r f1d7de36b01e nbproject/project.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nbproject/project.properties Sat Jan 26 15:48:59 2013 +0100 @@ -0,0 +1,71 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/Sudoku.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=de.uapcore.sudoku.Sudoku +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff -r 93d6c51154a7 -r f1d7de36b01e nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nbproject/project.xml Sat Jan 26 15:48:59 2013 +0100 @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + Sudoku + + + + + + + + + diff -r 93d6c51154a7 -r f1d7de36b01e src/de/uapcore/sudoku/Field.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/de/uapcore/sudoku/Field.java Sat Jan 26 15:48:59 2013 +0100 @@ -0,0 +1,70 @@ +package de.uapcore.sudoku; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.image.BufferedImage; +import javax.swing.JPanel; + +/** + * + * @author mike + */ +public class Field extends JPanel { + private SudokuTextField[][] cells; + + public Field() { + setBackground(Color.WHITE); + + setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(5, 5, 5, 5); + + cells = new SudokuTextField[9][9]; + for (int x = 0 ; x < 9 ; x++) { + for (int y = 0 ; y < 9 ; y++) { + cells[x][y] = new SudokuTextField(); + c.gridx = x; + c.gridy = y; + add(cells[x][y], c); + } + } + } + + @Override + public void paint(Graphics graphics) { + super.paint(graphics); + final int w = getWidth(); + final int h = getHeight(); + final int cw = w / 9; + final int ch = h / 9; + + BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); + Graphics2D g = img.createGraphics(); + g.setBackground(Color.WHITE); + g.clearRect(0, 0, w, h); + + g.setColor(Color.BLACK); + g.drawRect(1, 1, w-2, h-2); + g.drawRect(2, 2, w-4, h-4); + for (int x = cw ; x < w ; x += cw) { + for (int y = ch ; y < h ; y += ch) { + g.drawLine(x, 2, x, h-2); + g.drawLine(2, y, w-2, y); + if ((x / cw) % 3 == 0) { + g.drawLine(x+1, 2, x+1, h-2); + } + if ((y / ch) % 3 == 0) { + g.drawLine(2, y+1, w-2, y+1); + } + } + } + + graphics.drawImage(img, 0, 0, this); + } + + +} diff -r 93d6c51154a7 -r f1d7de36b01e src/de/uapcore/sudoku/Sudoku.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/de/uapcore/sudoku/Sudoku.java Sat Jan 26 15:48:59 2013 +0100 @@ -0,0 +1,40 @@ +package de.uapcore.sudoku; + +import java.awt.Color; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import javax.swing.JFrame; +import javax.swing.JRootPane; + +/** + * + * @author mike + */ +public class Sudoku extends JFrame { + + public Sudoku() { + super("Sudoku"); + + JRootPane root = getRootPane(); + + root.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(20, 20, 20, 20); + + c.gridx = 0; c.gridy = 0; + root.add(new Field(), c); + + pack(); + root.setBackground(Color.WHITE); + setLocationByPlatform(true); + setDefaultCloseOperation(EXIT_ON_CLOSE); + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + new Sudoku().setVisible(true); + } +} diff -r 93d6c51154a7 -r f1d7de36b01e src/de/uapcore/sudoku/SudokuTextField.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/de/uapcore/sudoku/SudokuTextField.java Sat Jan 26 15:48:59 2013 +0100 @@ -0,0 +1,71 @@ +package de.uapcore.sudoku; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import javax.swing.JTextField; + +/** + * + * @author mike + */ +public class SudokuTextField extends JTextField { + + public SudokuTextField() { + setBorder(null); + setBackground(Color.WHITE); + + setFont(new Font("Dialog", Font.PLAIN, 18)); + setHorizontalAlignment(JTextField.CENTER); + + Dimension dim = new Dimension(40,40); + setPreferredSize(dim); + setMinimumSize(dim); + setMaximumSize(dim); + + addKeyListener(new KeyAdapter() { + private void handle(KeyEvent e) { + if (getText().length() > 0) { + int c = e.getKeyCode(); + if (c != KeyEvent.VK_DELETE && + c != KeyEvent.VK_BACK_SPACE && + !e.isActionKey()) { + e.consume(); + } + } else { + char c = e.getKeyChar(); + if (c < '0' || c > '9') { + e.consume(); + } + } + } + + @Override + public void keyPressed(KeyEvent e) { + handle(e); + } + + @Override + public void keyTyped(KeyEvent e) { + handle(e); + } + + @Override + public void keyReleased(KeyEvent e) { + handle(e); + } + + }); + addFocusListener(new FocusAdapter() { + @Override + public void focusGained(FocusEvent e) { + selectAll(); + } + }); + } + +}