picross-commit Mailing List for picross (Page 5)
Status: Pre-Alpha
Brought to you by:
yvan_norsa
You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(40) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
|
Feb
|
Mar
|
Apr
(30) |
May
(15) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(10) |
Jul
(3) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
(38) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2020 |
Jan
|
Feb
|
Mar
(1) |
Apr
(2) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <yva...@us...> - 2007-06-17 18:55:45
|
Revision: 41 http://picross.svn.sourceforge.net/picross/?rev=41&view=rev Author: yvan_norsa Date: 2007-06-17 11:55:46 -0700 (Sun, 17 Jun 2007) Log Message: ----------- more tests Modified Paths: -------------- trunk/build.xml trunk/src/picross/PicrossException.java trunk/src/picross/game/simple/XBMModel.java trunk/src/picross/tests/AbstractPicrossGridTest.java Added Paths: ----------- trunk/src/picross/game/simple/XBMException.java trunk/src/picross/game/simple/XBMModelTest.java Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2007-06-15 19:57:57 UTC (rev 40) +++ trunk/build.xml 2007-06-17 18:55:46 UTC (rev 41) @@ -148,8 +148,8 @@ <target name="doc" depends="compile"> - <!-- FIXME test classes which are *not* in a "tests" subpackage - are included in the Javadoc --> + <!-- FIXME test classes which are not in a "tests" subpackage + shouldn't be included in the generated Javadoc --> <javadoc destdir="${doc.dir}" link="http://java.sun.com/j2se/1.5.0/docs/api"> <packageset dir="${src.dir}" Modified: trunk/src/picross/PicrossException.java =================================================================== --- trunk/src/picross/PicrossException.java 2007-06-15 19:57:57 UTC (rev 40) +++ trunk/src/picross/PicrossException.java 2007-06-17 18:55:46 UTC (rev 41) @@ -38,13 +38,13 @@ * * @author Y. Norsa */ -public final class PicrossException extends Exception { +public class PicrossException extends Exception { /*** Constant ***/ /** Serialisation ID. */ private static final long serialVersionUID = 1716838910721477345L; - /*** Constructor ***/ + /*** Constructors ***/ /** * Constructor. @@ -54,5 +54,14 @@ public PicrossException(Throwable cause) { super(cause); } + + /** + * Constructor. + * + * @param msg message describing the exception + */ + public PicrossException(String msg) { + super(msg); + } } Added: trunk/src/picross/game/simple/XBMException.java =================================================================== --- trunk/src/picross/game/simple/XBMException.java (rev 0) +++ trunk/src/picross/game/simple/XBMException.java 2007-06-17 18:55:46 UTC (rev 41) @@ -0,0 +1,68 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.game.simple; + +import picross.PicrossException; + +/** + * Exception thrown when reading an invalid XBM file. + * + * @author Y. Norsa + */ +final class XBMException extends PicrossException { + /*** Constant ***/ + + /** Serialisation ID. */ + private static final long serialVersionUID = 3928727649077087059L; + + /*** Constructors ***/ + + /** + * Constructor. + * + * @param msg message describing the exception + */ + XBMException(String msg) { + super(msg); + } + + /** + * Constructor. + * + * @param cause parent exception + */ + XBMException(Throwable cause) { + super(cause); + } +} Property changes on: trunk/src/picross/game/simple/XBMException.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/game/simple/XBMModel.java =================================================================== --- trunk/src/picross/game/simple/XBMModel.java 2007-06-15 19:57:57 UTC (rev 40) +++ trunk/src/picross/game/simple/XBMModel.java 2007-06-17 18:55:46 UTC (rev 41) @@ -51,6 +51,44 @@ * @author Y. Norsa */ final class XBMModel extends AbstractPicrossModel { + /*** Constants ***/ + + /** Indicates a constant definition. */ + private static final String DEFINE_DIRECTIVE = "#define "; + + /** The width value. */ + private static final String WIDTH_KEYWORD = "width"; + + /** The height value. */ + private static final String HEIGHT_KEYWORD = "height"; + + /** Character before the int value. */ + private static final char VALUE_MARKER = ' '; + + /** The data values. */ + private static final String BITS_KEYWORD = "bits"; + + /** Value separator. */ + private static final String VALUE_SEPARATOR = ","; + + /** String indicating a hex value. */ + private static final String HEX_LEADING = "0x"; + + /** In case of error. */ + private static final int ERROR_VALUE = -1; + + /** Beginning of the actual value. */ + private static final int VALUE_BEGINNING_POS = 2; + + /** End of the actual value. */ + private static final int VALUE_END_POS = 4; + + /** Hexadecimal number radix. */ + private static final int HEX_RADIX = 16; + + /** Length of a byte. */ + private static final int BYTE_LENGTH = 8; + /*** Static field ***/ /** The class' logger. */ @@ -62,11 +100,19 @@ * Constructor. * * @param input XBM file input stream + * @throws IllegalArgumentException if <code>input</code> + * is <code>null</code> * @throws IOException if there is a problem while reading the file + * @throws XBMException if the file isn't a valid XBM file */ - XBMModel(InputStream input) throws IOException { + XBMModel(InputStream input) throws IOException, XBMException, + IllegalArgumentException { super(); + if (input == null) { + throw new IllegalArgumentException("input can't be null"); + } + List<String> byteValues = new ArrayList<String>(); BufferedReader in = new BufferedReader(new InputStreamReader(input)); @@ -75,37 +121,39 @@ try { while ((line = in.readLine()) != null) { - if (line.contains("width")) { - this.width = - Integer.parseInt(line.substring(line - .lastIndexOf(' ')) - .trim()); + if (line.startsWith(XBMModel.DEFINE_DIRECTIVE) + && line.contains(XBMModel.WIDTH_KEYWORD)) { + + this.width = XBMModel.readLineValue(line); + XBMModel.log.debug("width = " + this.width); continue; } - if (line.contains("height")) { - this.height = - Integer.parseInt(line.substring(line - .lastIndexOf(' ')) - .trim()); + if (line.startsWith(XBMModel.DEFINE_DIRECTIVE) + && line.contains(XBMModel.HEIGHT_KEYWORD)) { + + this.height = XBMModel.readLineValue(line); + XBMModel.log.debug("height = " + this.height); continue; } - if (line.contains("bits")) { + if (line.contains(XBMModel.BITS_KEYWORD)) { this.data = new boolean[this.width][this.height]; while ((line = in.readLine()) != null) { - String[] values = line.split(","); + String[] values = line.split(XBMModel.VALUE_SEPARATOR); for (int i = 0; i < values.length; i++) { //XBMModel.log.debug("values[" + i + "] = " //+ values[i]); - if (values[i].contains("0x")) { + if (values[i].contains(XBMModel.HEX_LEADING)) { String byteStr = - values[i].trim().substring(2, 4); + values[i].trim() + .substring(XBMModel.VALUE_BEGINNING_POS, + XBMModel.VALUE_END_POS); byteValues.add(byteStr); } } @@ -122,20 +170,19 @@ } } + if (width <= 0 || height <= 0 || this.data == null) { + throw new XBMException("Invalid XBM file"); + } + int xIndex = 0; int yIndex = 0; for (String byteStr : byteValues) { - int byteVal = Integer.parseInt(byteStr, 16); - String binaryStr = Integer.toBinaryString(byteVal); + String binaryStr = XBMModel.toBits(byteStr); - while (binaryStr.length() < 8) { - binaryStr = "0" + binaryStr; - } - //XBMModel.log.debug(binaryStr); - for (int j = 8 - 1; j >= 0; j--) { + for (int j = XBMModel.BYTE_LENGTH - 1; j >= 0; j--) { //XBMModel.log.debug("this.data[" + yIndex //+ "][" + xIndex + "] = " //+ (binaryStr.charAt(j) == '1' ? true @@ -155,5 +202,45 @@ } } } + + /*** Static methods ***/ + + /** + * Reads a constant value (C-style) in a line. + * + * @param line the line to read + * @return defined value or -1 + * @throws XBMException if the line format is incorrect + */ + private static int readLineValue(String line) throws XBMException { + int spaceIndex = line.lastIndexOf(XBMModel.VALUE_MARKER); + + if (spaceIndex == -1) { + return XBMModel.ERROR_VALUE; + } + + try { + return Integer.parseInt(line.substring(spaceIndex).trim()); + } catch (NumberFormatException numberEx) { + throw new XBMException(numberEx); + } + } + + /** + * Converts a hex value to its binary representation. + * + * @param byteStr the original String + * @return binary representation + */ + private static String toBits(String byteStr) { + int byteVal = Integer.parseInt(byteStr, XBMModel.HEX_RADIX); + String binaryStr = Integer.toBinaryString(byteVal); + + while (binaryStr.length() < XBMModel.BYTE_LENGTH) { + binaryStr = '0' + binaryStr; + } + + return binaryStr; + } } Added: trunk/src/picross/game/simple/XBMModelTest.java =================================================================== --- trunk/src/picross/game/simple/XBMModelTest.java (rev 0) +++ trunk/src/picross/game/simple/XBMModelTest.java 2007-06-17 18:55:46 UTC (rev 41) @@ -0,0 +1,99 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.game.simple; + +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import org.apache.log4j.PropertyConfigurator; + +import org.junit.Assert; +import org.junit.Test; + +import picross.Picross; +import picross.PicrossGrid; + +import picross.tests.AbstractPicrossGridTest; + +/** + * Unit tests for XBMModel. + * + * @author Y. Norsa + */ +public final class XBMModelTest extends AbstractPicrossGridTest { + /*** Static field ***/ + + /** Valid XBM model. */ + private static PicrossGrid realModel; + + /*** Static initialisation block. Loads a valid XBM file. ***/ + static { + PropertyConfigurator.configure("log4j.properties"); + + try { + XBMModelTest.realModel = + new XBMModel(Picross.loadDataFile("blarg.xbm")); + } catch (IOException ioEx) { + throw new ExceptionInInitializerError(ioEx); + } catch (XBMException xbmEx) { + throw new ExceptionInInitializerError(xbmEx); + } + } + + /*** Method overloaded from the class AbstractPicrossGridTest ***/ + + /** {@inheritDoc} */ + protected PicrossGrid getPicrossGrid() { + return XBMModelTest.realModel; + } + + /** + * Tests the XBMModel constructor. + * + * @throws IOException if there is a problem with a stream loading + * @throws XBMException if a file isn't valid + */ + @Test + public void testXBMModel() throws IOException, XBMException { + try { + new XBMModel(null); + Assert.fail("Tried to load a null model"); + } catch (IllegalArgumentException argEx) { } + + try { + new XBMModel(new ByteArrayInputStream("".getBytes())); + Assert.fail("Empty file"); + } catch (XBMException xbmEx) { } + } +} Property changes on: trunk/src/picross/game/simple/XBMModelTest.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/tests/AbstractPicrossGridTest.java =================================================================== --- trunk/src/picross/tests/AbstractPicrossGridTest.java 2007-06-15 19:57:57 UTC (rev 40) +++ trunk/src/picross/tests/AbstractPicrossGridTest.java 2007-06-17 18:55:46 UTC (rev 41) @@ -97,5 +97,18 @@ Assert.assertEquals("data[" + i + "].length = " + data[i].length, height, data[i].length); } + + boolean atLeastOneCheckedBox = false; + + for (int i = 0; i < width; i++) { + for (int j = 0; j < height; j++) { + if (data[i][j]) { + atLeastOneCheckedBox = true; + break; + } + } + } + + Assert.assertTrue("Empty grid", atLeastOneCheckedBox); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-15 19:57:57
|
Revision: 40 http://picross.svn.sourceforge.net/picross/?rev=40&view=rev Author: yvan_norsa Date: 2007-06-15 12:57:57 -0700 (Fri, 15 Jun 2007) Log Message: ----------- javadoc generation, unit tests Modified Paths: -------------- trunk/bugsFilter.xml trunk/build.xml trunk/src/picross/Picross.java trunk/src/picross/PicrossGrid.java trunk/src/picross/app/MainMenuAppUI.java trunk/src/picross/applet/MainMenuAppletUI.java trunk/src/picross/game/GameMediator.java trunk/src/picross/game/random/RandomGameMediator.java trunk/src/picross/game/simple/SimpleGameMediator.java trunk/src/picross/game/simple/XBMModel.java trunk/src/picross/grid/Box.java trunk/src/picross/grid/GridMediator.java trunk/src/picross/grid/GridUI.java trunk/src/picross/menus/MainMenuUI.java Added Paths: ----------- trunk/lib/junit.jar trunk/src/picross/game/random/RandomPicrossModelTest.java trunk/src/picross/game/simple/package.html trunk/src/picross/tests/ trunk/src/picross/tests/AbstractPicrossGridTest.java trunk/src/picross/tests/PicrossTest.java trunk/src/picross/tests/package.html Modified: trunk/bugsFilter.xml =================================================================== --- trunk/bugsFilter.xml 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/bugsFilter.xml 2007-06-15 19:57:57 UTC (rev 40) @@ -1,5 +1,5 @@ <FindBugsFilter> <Match classregex=".*"> - <Bug pattern="DM_CONVERT_CASE,LSC_LITERAL_STRING_COMPARISON,CLI_CONSTANT_LIST_INDEX,S508C_SET_COMP_COLOR,S508C_NO_SETLABELFOR" /> + <Bug pattern="DM_CONVERT_CASE,LSC_LITERAL_STRING_COMPARISON,CLI_CONSTANT_LIST_INDEX,S508C_SET_COMP_COLOR,S508C_NO_SETLABELFOR,DRE_DECLARED_RUNTIME_EXCEPTION" /> </Match> </FindBugsFilter> Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/build.xml 2007-06-15 19:57:57 UTC (rev 40) @@ -7,6 +7,8 @@ value="build" /> <property name="dist.dir" value="dist" /> + <property name="doc.dir" + value="doc" /> <property name="lib.dir" value="lib" /> <property name="src.dir" @@ -17,15 +19,18 @@ <property name="bundleHelper.jar" value="${lib.dir}/bundleHelper.jar" /> + <property name="junit.jar" + value="${lib.dir}/junit.jar" /> + <property name="log4j.jar" + value="${lib.dir}/log4j.jar" /> <property name="mmvcs.jar" value="${lib.dir}/mmvcs.jar" /> - <property name="log4j.jar" - value="${lib.dir}/log4j.jar" /> <target name="-init" depends="-setmode"> <mkdir dir="${build.dir}" /> <mkdir dir="${dist.dir}" /> + <mkdir dir="${doc.dir}" /> </target> <target name="release"> @@ -52,6 +57,7 @@ <pathelement location="${build.dir}" /> <pathelement location="${bundleHelper.jar}" /> + <pathelement location="${junit.jar}" /> <pathelement location="${log4j.jar}" /> <pathelement location="${mmvcs.jar}" /> </path> @@ -103,9 +109,32 @@ </java> </target> + <target name="test" + depends="dist"> + <junit haltonfailure="yes" + filtertrace="off" + showoutput="on" + printsummary="withOutAndErr"> + <formatter type="plain" + usefile="false" /> + + <batchtest fork="yes" + filtertrace="on" + haltonfailure="yes"> + <fileset dir="${src.dir}"> + <include name="**/*Test.java" /> + <exclude name="**/Abstract*Test.java" /> + </fileset> + </batchtest> + + <classpath refid="classpath" /> + </junit> + </target> + <target name="clean"> <delete dir="${build.dir}" /> <delete dir="${dist.dir}" /> + <delete dir="${doc.dir}" /> <delete> <fileset dir="." @@ -117,6 +146,21 @@ <target name="rebuild" depends="clean, dist" /> + <target name="doc" + depends="compile"> + <!-- FIXME test classes which are *not* in a "tests" subpackage + are included in the Javadoc --> + <javadoc destdir="${doc.dir}" + link="http://java.sun.com/j2se/1.5.0/docs/api"> + <packageset dir="${src.dir}" + defaultexcludes="yes"> + <exclude name="**/tests/**" /> + </packageset> + + <classpath refid="classpath" /> + </javadoc> + </target> + <property file="checkstyle.properties" /> <target name="-check-checkstyle"> @@ -137,9 +181,9 @@ <formatter type="xml" tofile="checkstyle.xml" /> - <!-- Pour tous les fichiers source sauf les tests --> <fileset dir="${src.dir}" - includes="**/*.java" /> + includes="**/*.java" + excludes="**/tests/" /> </checkstyle> <xslt in="checkstyle.xml" Added: trunk/lib/junit.jar =================================================================== (Binary files differ) Property changes on: trunk/lib/junit.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Name: svn:keywords + Id Modified: trunk/src/picross/Picross.java =================================================================== --- trunk/src/picross/Picross.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/Picross.java 2007-06-15 19:57:57 UTC (rev 40) @@ -33,9 +33,12 @@ package picross; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.net.URL; + import java.util.Locale; import javax.swing.ImageIcon; @@ -53,6 +56,7 @@ /** Images directory. */ private static final String IMAGES_DIR = "/picross/images/"; + /** Data directory. */ private static final String DATA_DIR = "/picross/data/"; /** Images directory corresponding to the default locale. */ @@ -72,13 +76,33 @@ /*** Static methods ***/ /** + * Loads a file. + * + * @param path file path + * @return URL of the file + * @throws FileNotFoundException if the file can't be found + */ + private static URL getFile(String path) throws FileNotFoundException { + URL fileUrl = Picross.class.getResource(path); + + if (fileUrl == null) { + throw new FileNotFoundException("\"" + path + "\" can't be found"); + } + + return fileUrl; + } + + /** * Loads an image. * * @param path path of the image * @return the image + * @throws FileNotFoundException if the file can't be found */ - private static ImageIcon loadImage(String path) { - return new ImageIcon(Picross.class.getResource(path)); + private static ImageIcon loadImage(String path) + throws FileNotFoundException { + + return new ImageIcon(Picross.getFile(path)); } /** @@ -86,8 +110,17 @@ * * @param name image filename * @return the image + * @throws IllegalArgumentException if <code>name</code> + * is <code>null</code> or empty + * @throws FileNotFoundException if the file can't be found */ - public static ImageIcon getImage(String name) { + public static ImageIcon getImage(String name) + throws IllegalArgumentException, FileNotFoundException { + + if (name == null || name.equals("")) { + throw new IllegalArgumentException("name can't be null or empty"); + } + return Picross.loadImage(Picross.IMAGES_DIR + name); } @@ -96,15 +129,37 @@ * * @param name image filename * @return the image + * @throws IllegalArgumentException if <code>name</code> + * is <code>null</code> or empty + * @throws FileNotFoundException if the file can't be found */ - public static ImageIcon getLocalizedImage(String name) { + public static ImageIcon getLocalizedImage(String name) + throws IllegalArgumentException, FileNotFoundException { + + if (name == null || name.equals("")) { + throw new IllegalArgumentException("name can't be null or empty"); + } + return Picross.loadImage(Picross.LOCAL_IMAGES_PATH + name); } + /** + * Loads a data file. + * + * @param name filename + * @return a stream containing the loaded file + * @throws IllegalArgumentException if <code>name</code> + * is <code>null</code> or empty + * @throws IOException if there is a problem while opening the file + */ public static InputStream loadDataFile(String name) - throws IOException { + throws IllegalArgumentException, IOException { - return Picross.class.getResource(Picross.DATA_DIR + name).openStream(); + if (name == null || name.equals("")) { + throw new IllegalArgumentException("name can't be null or empty"); + } + + return Picross.getFile(Picross.DATA_DIR + name).openStream(); } } Modified: trunk/src/picross/PicrossGrid.java =================================================================== --- trunk/src/picross/PicrossGrid.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/PicrossGrid.java 2007-06-15 19:57:57 UTC (rev 40) @@ -42,21 +42,21 @@ /** * Returns the width. * - * @return grid width + * @return grid width (always > 0) */ int getWidth(); /** * Returns the height. * - * @return grid height + * @return grid height (always > 0) */ int getHeight(); /** * Returns the content. * - * @return grid content + * @return grid content (of size width * height) */ boolean[][] getData(); } Modified: trunk/src/picross/app/MainMenuAppUI.java =================================================================== --- trunk/src/picross/app/MainMenuAppUI.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/app/MainMenuAppUI.java 2007-06-15 19:57:57 UTC (rev 40) @@ -35,6 +35,8 @@ import java.awt.event.ActionListener; +import java.io.FileNotFoundException; + import javax.swing.ImageIcon; import javax.swing.JButton; @@ -75,8 +77,11 @@ * Constructor. * * @param controller controller for the buttons + * @throws FileNotFoundException if a button image can't be found */ - public MainMenuAppUI(ActionListener controller) { + public MainMenuAppUI(ActionListener controller) + throws FileNotFoundException { + super(controller); ImageIcon exitIcon = Modified: trunk/src/picross/applet/MainMenuAppletUI.java =================================================================== --- trunk/src/picross/applet/MainMenuAppletUI.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/applet/MainMenuAppletUI.java 2007-06-15 19:57:57 UTC (rev 40) @@ -37,6 +37,8 @@ import java.awt.event.ActionListener; +import java.io.FileNotFoundException; + import picross.menus.MainMenuUI; /** @@ -62,8 +64,11 @@ * Constructor. * * @param controller controller for the buttons + * @throws FileNotFoundException if a button image can't be found */ - public MainMenuAppletUI(ActionListener controller) { + public MainMenuAppletUI(ActionListener controller) + throws FileNotFoundException { + super(controller); this.setBackground(Color.WHITE); Modified: trunk/src/picross/game/GameMediator.java =================================================================== --- trunk/src/picross/game/GameMediator.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/game/GameMediator.java 2007-06-15 19:57:57 UTC (rev 40) @@ -63,7 +63,12 @@ /*** Constructor ***/ - /** Constructor. */ + /** + * Constructor. + * + * @throws PicrossException if there is a problem loading the grid model + * or building the view + */ public GameMediator() throws PicrossException { PicrossGrid model = this.initModel(); @@ -95,6 +100,7 @@ * Creates the model. * * @return grid model + * @throws PicrossException if there is a problem */ protected abstract PicrossGrid initModel() throws PicrossException; Modified: trunk/src/picross/game/random/RandomGameMediator.java =================================================================== --- trunk/src/picross/game/random/RandomGameMediator.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/game/random/RandomGameMediator.java 2007-06-15 19:57:57 UTC (rev 40) @@ -57,6 +57,14 @@ /** The class' logger. */ //private static Logger log = Logger.getLogger(RandomGameMediator.class); + /*** Constructor ***/ + + /** + * Constructor. + * + * @throws PicrossException if there is a problem loading the grid model + * or building the view + */ RandomGameMediator() throws PicrossException { super(); } Added: trunk/src/picross/game/random/RandomPicrossModelTest.java =================================================================== --- trunk/src/picross/game/random/RandomPicrossModelTest.java (rev 0) +++ trunk/src/picross/game/random/RandomPicrossModelTest.java 2007-06-15 19:57:57 UTC (rev 40) @@ -0,0 +1,59 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.game.random; + +import org.apache.log4j.PropertyConfigurator; + +import picross.PicrossGrid; + +import picross.tests.AbstractPicrossGridTest; + +/** + * Test class for the random model. + * + * @author Y. Norsa + */ +public class RandomPicrossModelTest extends AbstractPicrossGridTest { + /** Static block. */ + static { + PropertyConfigurator.configure("log4j.properties"); + } + + /*** Overloaded method from the class AbstractPicrossGridTest ***/ + + /** {@inheritDoc} */ + protected PicrossGrid getPicrossGrid() { + return new RandomPicrossModel(); + } +} Property changes on: trunk/src/picross/game/random/RandomPicrossModelTest.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/game/simple/SimpleGameMediator.java =================================================================== --- trunk/src/picross/game/simple/SimpleGameMediator.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/game/simple/SimpleGameMediator.java 2007-06-15 19:57:57 UTC (rev 40) @@ -35,8 +35,6 @@ import java.io.IOException; -import javax.swing.JPanel; - import picross.Picross; import picross.PicrossException; import picross.PicrossGrid; @@ -44,26 +42,26 @@ import picross.game.GameMediator; /** + * Mediator for a classic game. + * * @author Y. Norsa */ public final class SimpleGameMediator extends GameMediator { - /*** Constante ***/ + /*** Constructor ***/ - /*** Champ statique ***/ - - /*** Champ ***/ - - /*** Constructeur ***/ - /** - * Constructeur. + * Constructor. + * + * @throws PicrossException if there is a problem loading the grid model + * or building the view */ public SimpleGameMediator() throws PicrossException { super(); } - /*** M\xE9thode ***/ + /*** Method overloaded from the class GameMediator ***/ + /** {@inheritDoc} */ protected PicrossGrid initModel() throws PicrossException { try { return new XBMModel(Picross.loadDataFile("halloween.xbm")); Modified: trunk/src/picross/game/simple/XBMModel.java =================================================================== --- trunk/src/picross/game/simple/XBMModel.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/game/simple/XBMModel.java 2007-06-15 19:57:57 UTC (rev 40) @@ -34,9 +34,9 @@ package picross.game.simple; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -46,21 +46,23 @@ import picross.AbstractPicrossModel; /** + * Class loading a XBM file. + * * @author Y. Norsa */ final class XBMModel extends AbstractPicrossModel { - /*** Constante ***/ + /*** Static field ***/ - /*** Champ statique ***/ - + /** The class' logger. */ private static Logger log = Logger.getLogger(XBMModel.class); - /*** Champ ***/ + /*** Constructor ***/ - /*** Constructeur ***/ - /** - * Constructeur. + * Constructor. + * + * @param input XBM file input stream + * @throws IOException if there is a problem while reading the file */ XBMModel(InputStream input) throws IOException { super(); @@ -130,7 +132,7 @@ while (binaryStr.length() < 8) { binaryStr = "0" + binaryStr; } - + //XBMModel.log.debug(binaryStr); for (int j = 8 - 1; j >= 0; j--) { Added: trunk/src/picross/game/simple/package.html =================================================================== --- trunk/src/picross/game/simple/package.html (rev 0) +++ trunk/src/picross/game/simple/package.html 2007-06-15 19:57:57 UTC (rev 40) @@ -0,0 +1,12 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> + <head> + <!-- + $Id$ + --> + </head> + + <body bgcolor="white"> + Simple game mode. + </body> +</html> Property changes on: trunk/src/picross/game/simple/package.html ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/grid/Box.java =================================================================== --- trunk/src/picross/grid/Box.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/grid/Box.java 2007-06-15 19:57:57 UTC (rev 40) @@ -35,6 +35,8 @@ import java.awt.Rectangle; +import java.io.FileNotFoundException; + import java.util.HashMap; import java.util.Map; import java.util.Random; @@ -113,17 +115,21 @@ */ Box.images = new HashMap<Box.BoxState, ImageIcon[]>(7); - for (Box.BoxState state : Box.BoxState.values()) { - ImageIcon[] img = new ImageIcon[2]; + try { + for (Box.BoxState state : Box.BoxState.values()) { + ImageIcon[] img = new ImageIcon[2]; - String stateImageName = state.toString().toLowerCase(); - img[Box.ICON_INDEX] = Picross.getImage(stateImageName + String stateImageName = state.toString().toLowerCase(); + img[Box.ICON_INDEX] = Picross.getImage(stateImageName + Box.IMAGES_EXT); - img[Box.ROLLOVER_ICON_INDEX] = - Picross.getImage(stateImageName + Box.ROLLOVER_NAME - + Box.IMAGES_EXT); + img[Box.ROLLOVER_ICON_INDEX] = + Picross.getImage(stateImageName + Box.ROLLOVER_NAME + + Box.IMAGES_EXT); - Box.images.put(state, img); + Box.images.put(state, img); + } + } catch (FileNotFoundException fileEx) { + throw new ExceptionInInitializerError(fileEx); } } Modified: trunk/src/picross/grid/GridMediator.java =================================================================== --- trunk/src/picross/grid/GridMediator.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/grid/GridMediator.java 2007-06-15 19:57:57 UTC (rev 40) @@ -36,10 +36,14 @@ import fr.cle.mmvcs.Mediateur; import fr.cle.mmvcs.SimpleEvent; +import java.io.FileNotFoundException; + import javax.swing.JPanel; //import org.apache.log4j.Logger; +import picross.PicrossException; + /** * Picross grid mediator. * @@ -67,20 +71,27 @@ * @param width grid width * @param height grid height * @param data grid content + * @throws PicrossException if there is a probleme while building the view */ - public GridMediator(int width, int height, boolean[][] data) { + public GridMediator(int width, int height, boolean[][] data) + throws PicrossException { + this.model = new GridModel(this, data); GridController controller = new GridController(); controller.addSimpleListener(this); this.addSimpleListener(controller); - this.view = new GridUI(width, height, - this.model.getBoxes(), - this.model.getColData(), - this.model.getRowData(), - this.model.getCompletedHints(), - controller); + try { + this.view = new GridUI(width, height, + this.model.getBoxes(), + this.model.getColData(), + this.model.getRowData(), + this.model.getCompletedHints(), + controller); + } catch (FileNotFoundException fileEx) { + throw new PicrossException(fileEx); + } controller.setView(this.view); } Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/grid/GridUI.java 2007-06-15 19:57:57 UTC (rev 40) @@ -48,6 +48,8 @@ import java.awt.image.BufferedImage; +import java.io.FileNotFoundException; + import java.util.ArrayList; import java.util.List; @@ -212,13 +214,14 @@ * @param rowData rows hints * @param completedHints list of completed hints * @param controller controller for the grid + * @throws FileNotFoundException if an image is missing */ GridUI(int width, int height, Box[][] boxes, int[][] colData, int[][] rowData, CompletedHints completedHints, - GridController controller) { + GridController controller) throws FileNotFoundException { super(true); this.controller = controller; Modified: trunk/src/picross/menus/MainMenuUI.java =================================================================== --- trunk/src/picross/menus/MainMenuUI.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/menus/MainMenuUI.java 2007-06-15 19:57:57 UTC (rev 40) @@ -39,6 +39,8 @@ import java.awt.event.ActionListener; +import java.io.FileNotFoundException; + import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JPanel; @@ -74,8 +76,9 @@ * Constructor. * * @param controller controller for the buttons + * @throws FileNotFoundException if a button image can't be found */ - public MainMenuUI(ActionListener controller) { + public MainMenuUI(ActionListener controller) throws FileNotFoundException { ImageIcon icon = Picross.getImage(MainMenuUI.BACKGROUND_IMAGE); this.setPreferredSize(new Dimension(icon.getIconWidth(), icon.getIconHeight())); @@ -90,7 +93,8 @@ playButton.addActionListener(controller); playButton.setBorder(null); playButton.setBounds(this.getPlayButtonX(), this.getPlayButtonY(), - playIcon.getIconWidth(), playIcon.getIconHeight()); + playIcon.getIconWidth(), + playIcon.getIconHeight()); this.add(playButton); } Added: trunk/src/picross/tests/AbstractPicrossGridTest.java =================================================================== --- trunk/src/picross/tests/AbstractPicrossGridTest.java (rev 0) +++ trunk/src/picross/tests/AbstractPicrossGridTest.java 2007-06-15 19:57:57 UTC (rev 40) @@ -0,0 +1,101 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.tests; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import picross.PicrossGrid; + +/** + * Abstract test class for the PicrossGrid interface. + * + * @author Y. Norsa + */ +public abstract class AbstractPicrossGridTest { + /*** Field ***/ + + /** The instance to test. */ + private PicrossGrid picrossGrid = null; + + /*** Abstract method ***/ + + /** + * Returns an instance. + * + * @return instance to test + */ + protected abstract PicrossGrid getPicrossGrid(); + + /*** Methods ***/ + + /** Performs the instance initialisation. */ + @Before + public void setUp() { + this.picrossGrid = this.getPicrossGrid(); + } + + /** Tests the method getWidth(). */ + @Test + public void testGetWidth() { + int width = this.picrossGrid.getWidth(); + Assert.assertTrue("width = " + width, (width > 0)); + } + + /** Tests the method getHeight(). */ + @Test + public void testGetHeight() { + int height = this.picrossGrid.getHeight(); + Assert.assertTrue("height = " + height, (height > 0)); + } + + /** Tests the method getData(). */ + @Test + public void testGetData() { + boolean[][] data = this.picrossGrid.getData(); + Assert.assertNotNull("data = null", data); + + int width = this.picrossGrid.getWidth(); + int height = this.picrossGrid.getHeight(); + + Assert.assertEquals("data.length = " + data.length, + width, data.length); + + for (int i = 0; i < width; i++) { + Assert.assertEquals("data[" + i + "].length = " + data[i].length, + height, data[i].length); + } + } +} Property changes on: trunk/src/picross/tests/AbstractPicrossGridTest.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/tests/PicrossTest.java =================================================================== --- trunk/src/picross/tests/PicrossTest.java (rev 0) +++ trunk/src/picross/tests/PicrossTest.java 2007-06-15 19:57:57 UTC (rev 40) @@ -0,0 +1,152 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.tests; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; + +import javax.swing.ImageIcon; + +import org.junit.Assert; +import org.junit.Test; + +import picross.Picross; + +/** + * Tests for the static methods of the Picross class. + * + * @author Y. Norsa + */ +public class PicrossTest { + /*** Static method ***/ + + /** + * Helper method to test a loaded icon. + * + * @param icon the icon to test + * @param width the expected icon width + * @param height the expected icon height + */ + private static void testIcon(ImageIcon icon, int width, int height) { + Assert.assertNotNull("icon = null", icon); + + int iconWidth = icon.getIconWidth(); + Assert.assertEquals("width = " + iconWidth, width, iconWidth); + + int iconHeight = icon.getIconHeight(); + Assert.assertEquals("height = " + iconHeight, height, iconHeight); + } + + /*** Methods ***/ + + /** + * Tests the method getImage(). + * + * @throws FileNotFoundException if a file loading fails. + */ + @Test + public void testGetImage() throws FileNotFoundException { + try { + Picross.getImage(null); + Assert.fail("name = null"); + } catch (IllegalArgumentException argEx) { } + + try { + Picross.getImage(""); + Assert.fail("name is empty"); + } catch (IllegalArgumentException argEx) { } + + try { + Picross.getImage("fakeFile"); + Assert.fail("Fake file"); + } catch (FileNotFoundException fileEx) { } + + ImageIcon icon = Picross.getImage("empty.png"); + PicrossTest.testIcon(icon, 25, 25); + } + + /** + * Tests the method getLocalizedImage(). + * + * @throws FileNotFoundException if a file loading fails. + */ + @Test + public void getLocalizedImage() throws FileNotFoundException { + try { + Picross.getLocalizedImage(null); + Assert.fail("name = null"); + } catch (IllegalArgumentException argEx) { } + + try { + Picross.getLocalizedImage(""); + Assert.fail("name is empty"); + } catch (IllegalArgumentException argEx) { } + + try { + Picross.getImage("fakeFile"); + Assert.fail("Fake file"); + } catch (FileNotFoundException fileEx) { } + + ImageIcon icon = Picross.getLocalizedImage("button-play.png"); + PicrossTest.testIcon(icon, 150, 50); + } + + /** + * Tests the method loadDataFile(). + * + * @throws IOException if there is a problem loading the file + */ + @Test + public void testLoadDataFile() throws IOException { + try { + Picross.loadDataFile(null); + Assert.fail("name = null"); + } catch (IllegalArgumentException argEx) { } + + try { + Picross.loadDataFile(""); + Assert.fail("name is empty"); + } catch (IllegalArgumentException argEx) { } + + try { + Picross.loadDataFile("fakeFile"); + Assert.fail("Fake file"); + } catch (FileNotFoundException fileEx) { } + + InputStream in = Picross.loadDataFile("blarg.xbm"); + Assert.assertNotNull("in = null", in); + in.close(); + } +} Property changes on: trunk/src/picross/tests/PicrossTest.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/tests/package.html =================================================================== --- trunk/src/picross/tests/package.html (rev 0) +++ trunk/src/picross/tests/package.html 2007-06-15 19:57:57 UTC (rev 40) @@ -0,0 +1,12 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> + <head> + <!-- + $Id$ + --> + </head> + + <body bgcolor="white"> + Unit tests for package picross. + </body> +</html> Property changes on: trunk/src/picross/tests/package.html ___________________________________________________________________ Name: svn:keywords + Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-14 13:51:02
|
Revision: 39 http://picross.svn.sourceforge.net/picross/?rev=39&view=rev Author: yvan_norsa Date: 2007-06-14 06:51:01 -0700 (Thu, 14 Jun 2007) Log Message: ----------- XBM support Modified Paths: -------------- trunk/build.xml trunk/src/picross/Picross.java trunk/src/picross/PicrossMediator.java trunk/src/picross/game/GameMediator.java trunk/src/picross/game/random/RandomGameMediator.java Added Paths: ----------- trunk/data/ trunk/data/anchor.xbm trunk/data/bart.xbm trunk/data/blarg.xbm trunk/data/bunny.xbm trunk/data/candle.xbm trunk/data/crab.xbm trunk/data/ghost_left.xbm trunk/data/halloween.xbm trunk/data/squares.xbm trunk/src/picross/game/simple/ trunk/src/picross/game/simple/SimpleGameMediator.java trunk/src/picross/game/simple/XBMModel.java Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2007-06-14 09:33:57 UTC (rev 38) +++ trunk/build.xml 2007-06-14 13:51:01 UTC (rev 39) @@ -80,6 +80,10 @@ <fileset dir="images" /> </copy> + <copy todir="${build.dir}/picross/data"> + <fileset dir="data" /> + </copy> + <jar destfile="${jar.name}" basedir="${build.dir}" /> </target> Added: trunk/data/anchor.xbm =================================================================== --- trunk/data/anchor.xbm (rev 0) +++ trunk/data/anchor.xbm 2007-06-14 13:51:01 UTC (rev 39) @@ -0,0 +1,6 @@ +#define anchor.xbm_width 16 +#define anchor.xbm_height 16 +static char anchor.xbm_bits[] = { + 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x80, 0x05, 0x80, 0x05, 0x80, 0x05, + 0x80, 0x03, 0x80, 0x01, 0x9e, 0x79, 0x8e, 0x71, 0x8e, 0x71, 0x8a, 0x51, + 0x90, 0x09, 0xe0, 0x07, 0x80, 0x01, 0x00, 0x00}; Added: trunk/data/bart.xbm =================================================================== --- trunk/data/bart.xbm (rev 0) +++ trunk/data/bart.xbm 2007-06-14 13:51:01 UTC (rev 39) @@ -0,0 +1,27 @@ +#define noname_width 43 +#define noname_height 58 +static char noname_bits[] = { + 0x00,0x00,0x00,0xc4,0x00,0x00,0x00,0x00,0xc0,0xca,0x00,0x00,0x00,0x00,0xc0, + 0xb2,0x00,0x00,0x00,0x00,0x4c,0xb3,0x00,0x00,0x00,0xc0,0x34,0x82,0x00,0x00, + 0x00,0x4c,0x35,0x80,0x00,0x00,0x80,0x54,0x26,0x80,0x00,0x00,0x80,0x67,0x04, + 0x80,0x00,0x00,0xb0,0x4c,0x00,0x80,0x00,0x00,0xd0,0x08,0x00,0x00,0x01,0x00, + 0x90,0x01,0x00,0x00,0x01,0x00,0x17,0x00,0x00,0x00,0x01,0x00,0x39,0x00,0x00, + 0x00,0x01,0x00,0x02,0x00,0x00,0x00,0x01,0x00,0x04,0x00,0x00,0x00,0x02,0x00, + 0x04,0x00,0x00,0x00,0x02,0x00,0x08,0x00,0x00,0x00,0x02,0x00,0x08,0x00,0x00, + 0x00,0x0c,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x1f,0x00, + 0x20,0x00,0x00,0x80,0x20,0x00,0x20,0x00,0x80,0x43,0x40,0x00,0x40,0x00,0x60, + 0x2c,0x80,0x00,0x40,0x00,0x18,0x10,0x80,0x00,0x40,0x00,0x04,0x20,0x8c,0x00, + 0x80,0x00,0x04,0x40,0x8c,0x00,0x80,0x00,0x02,0x40,0x40,0x00,0x00,0x01,0x01, + 0x40,0x70,0x00,0x00,0x01,0xc1,0xc0,0x8f,0x00,0x00,0x02,0xc1,0x40,0x00,0x01, + 0x00,0x02,0x02,0x20,0x00,0x01,0x00,0x02,0x02,0x10,0x00,0x01,0x00,0x04,0x04, + 0x10,0x00,0x01,0x00,0x04,0x08,0x0c,0x80,0x00,0x00,0x04,0xf0,0x03,0x40,0x00, + 0x00,0x08,0x00,0x00,0xbe,0x00,0x00,0x08,0x00,0x00,0x80,0x00,0x00,0x30,0x00, + 0x00,0x80,0x00,0x00,0x48,0x00,0x00,0x00,0x01,0x00,0x04,0x00,0x00,0x00,0x01, + 0x00,0x74,0x00,0x00,0x00,0x02,0x00,0x2a,0x00,0x00,0x00,0x04,0x00,0x6a,0x40, + 0x00,0x00,0x03,0x00,0x04,0x20,0x00,0xc0,0x00,0x00,0x88,0x70,0x00,0x3e,0x00, + 0x00,0x70,0x90,0xff,0x01,0x00,0x00,0x20,0x10,0x80,0x00,0x00,0x00,0x20,0x00, + 0x80,0x00,0x00,0x00,0x20,0x00,0x60,0x00,0x00,0x00,0x20,0x00,0x10,0x00,0x00, + 0x00,0x20,0x00,0x08,0x00,0x00,0x00,0x10,0x00,0x08,0x00,0x00,0x00,0x10,0x00, + 0x08,0x00,0x00,0x00,0x10,0x00,0x08,0x00,0x00,0x00,0x60,0x00,0x08,0x00,0x00, + 0x00,0x80,0x01,0x08,0x00,0x00,0x00,0x00,0x06,0x04,0x00,0x00,0x00,0x00,0xf8, + 0x03,0x00,0x00}; Added: trunk/data/blarg.xbm =================================================================== --- trunk/data/blarg.xbm (rev 0) +++ trunk/data/blarg.xbm 2007-06-14 13:51:01 UTC (rev 39) @@ -0,0 +1,5 @@ +#define test_width 16 +#define test_height 7 +static char test_bits[] = { +0x13, 0x00, 0x15, 0x00, 0x93, 0xcd, 0x55, 0xa5, 0x93, 0xc5, 0x00, 0x80, +0x00, 0x60, }; Added: trunk/data/bunny.xbm =================================================================== --- trunk/data/bunny.xbm (rev 0) +++ trunk/data/bunny.xbm 2007-06-14 13:51:01 UTC (rev 39) @@ -0,0 +1,6 @@ +#define bunny_width 16 +#define bunny_height 16 +static char bunny_bits[] = { + 0x00,0x00,0x00,0x44,0x00,0xee,0x00,0xee,0x00,0xee,0x00,0xee,0x00,0x6c,0x00, + 0x38,0xe0,0x7c,0xf0,0xbd,0xf8,0xff,0xfa,0xff,0xff,0x7f,0xff,0x3f,0xff,0xff, + 0xfa,0xff}; Added: trunk/data/candle.xbm =================================================================== --- trunk/data/candle.xbm (rev 0) +++ trunk/data/candle.xbm 2007-06-14 13:51:01 UTC (rev 39) @@ -0,0 +1,8 @@ +#define noname_width 16 +#define noname_height 33 +static char noname_bits[] = { + 0x00,0x01,0x00,0x03,0x00,0x03,0x00,0x03,0x80,0x06,0x40,0x06,0x40,0x06,0x40, + 0x06,0x40,0x03,0x80,0x01,0xf0,0x0f,0x10,0x0c,0x10,0x0c,0x10,0x0c,0x10,0x0c, + 0x10,0x0c,0x10,0x0c,0x10,0x0c,0x10,0x0c,0x10,0x0c,0x10,0x0c,0x10,0x0c,0x10, + 0x0c,0x10,0x0c,0xfe,0x7f,0x01,0xc0,0x02,0x60,0x0c,0x38,0x10,0x0c,0x10,0x0c, + 0x20,0x06,0x20,0x06,0x10,0x0c}; Added: trunk/data/crab.xbm =================================================================== --- trunk/data/crab.xbm (rev 0) +++ trunk/data/crab.xbm 2007-06-14 13:51:01 UTC (rev 39) @@ -0,0 +1,7 @@ +#define crab_width 16 +#define crab_height 16 + +static char crab_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x70, 0x0e, 0x78, 0x1e, 0x18, 0x18, 0x44, 0x22, + 0xc4, 0x23, 0xf8, 0x1f, 0xe0, 0x07, 0xf8, 0x1f, 0xe4, 0x27, 0xd0, 0x0b, + 0x08, 0x10, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00 }; Added: trunk/data/ghost_left.xbm =================================================================== --- trunk/data/ghost_left.xbm (rev 0) +++ trunk/data/ghost_left.xbm 2007-06-14 13:51:01 UTC (rev 39) @@ -0,0 +1,6 @@ +#define pacman_left_width 16 +#define pacman_left_height 16 +static char pacman_left_bits[] = { + 0xf0,0x07,0x0c,0x18,0x02,0x20,0x3a,0x2e,0x45,0x51,0x5d,0x57,0x5d,0x57,0x5d, + 0x57,0x45,0x51,0x39,0x4e,0x01,0x40,0x01,0x40,0x11,0x44,0x29,0x4a,0x45,0x51, + 0x82,0x20}; Added: trunk/data/halloween.xbm =================================================================== --- trunk/data/halloween.xbm (rev 0) +++ trunk/data/halloween.xbm 2007-06-14 13:51:01 UTC (rev 39) @@ -0,0 +1,6 @@ +#define noname_width 16 +#define noname_height 16 +static char noname_bits[] = { + 0x00,0x03,0x80,0x01,0x80,0x01,0xb8,0x0d,0xf8,0x3f,0xfe,0x7f,0xce,0xf3,0xdf, + 0xf7,0x7f,0xfe,0xff,0xfe,0xff,0xff,0xce,0x67,0x1e,0x70,0x7c,0x3d,0xf0,0x0f, + 0x00,0x00}; Added: trunk/data/squares.xbm =================================================================== --- trunk/data/squares.xbm (rev 0) +++ trunk/data/squares.xbm 2007-06-14 13:51:01 UTC (rev 39) @@ -0,0 +1,6 @@ + #define test_width 16 + #define test_height 16 + static unsigned char test_bits[] = { + 0xff, 0xff, 0x01, 0x80, 0xfd, 0xbf, 0x05, 0xa0, 0xf5, 0xaf, 0x15, 0xa8, + 0xd5, 0xab, 0x55, 0xaa, 0x55, 0xaa, 0xd5, 0xab, 0x15, 0xa8, 0xf5, 0xaf, + 0x05, 0xa0, 0xfd, 0xbf, 0x01, 0x80, 0xff, 0xff}; Modified: trunk/src/picross/Picross.java =================================================================== --- trunk/src/picross/Picross.java 2007-06-14 09:33:57 UTC (rev 38) +++ trunk/src/picross/Picross.java 2007-06-14 13:51:01 UTC (rev 39) @@ -33,6 +33,9 @@ package picross; +import java.io.IOException; +import java.io.InputStream; + import java.util.Locale; import javax.swing.ImageIcon; @@ -50,6 +53,8 @@ /** Images directory. */ private static final String IMAGES_DIR = "/picross/images/"; + private static final String DATA_DIR = "/picross/data/"; + /** Images directory corresponding to the default locale. */ private static final String LOCAL_IMAGES_PATH = Picross.IMAGES_DIR + Locale.getDefault().getLanguage() + "/"; @@ -95,5 +100,11 @@ public static ImageIcon getLocalizedImage(String name) { return Picross.loadImage(Picross.LOCAL_IMAGES_PATH + name); } + + public static InputStream loadDataFile(String name) + throws IOException { + + return Picross.class.getResource(Picross.DATA_DIR + name).openStream(); + } } Modified: trunk/src/picross/PicrossMediator.java =================================================================== --- trunk/src/picross/PicrossMediator.java 2007-06-14 09:33:57 UTC (rev 38) +++ trunk/src/picross/PicrossMediator.java 2007-06-14 13:51:01 UTC (rev 39) @@ -105,7 +105,16 @@ if (cmd.equals(PicrossController.PLAY_CMD)) { //this.view.setContent(grid.getView()); - GameMediator game = new picross.game.random.RandomGameMediator(); + //GameMediator game = new picross.game.random.RandomGameMediator(); + GameMediator game = null; + + try { + game = new picross.game.simple.SimpleGameMediator(); + } catch (PicrossException picrossEx) { + this.view.displayError(picrossEx.getMessage()); + return; + } + game.addSimpleListener(this); this.view.setContent(game.getView()); Modified: trunk/src/picross/game/GameMediator.java =================================================================== --- trunk/src/picross/game/GameMediator.java 2007-06-14 09:33:57 UTC (rev 38) +++ trunk/src/picross/game/GameMediator.java 2007-06-14 13:51:01 UTC (rev 39) @@ -40,6 +40,7 @@ //import org.apache.log4j.Logger; +import picross.PicrossException; import picross.PicrossGrid; import picross.grid.GridMediator; @@ -63,7 +64,7 @@ /*** Constructor ***/ /** Constructor. */ - public GameMediator() { + public GameMediator() throws PicrossException { PicrossGrid model = this.initModel(); int width = model.getWidth(); @@ -86,14 +87,16 @@ * @param gridView the grid itself * @return view containing the grid */ - protected abstract GameUI initView(int width, int height, JPanel gridView); + protected GameUI initView(int width, int height, JPanel gridView) { + return new GameUI(width, height, gridView); + } /** * Creates the model. * * @return grid model */ - protected abstract PicrossGrid initModel(); + protected abstract PicrossGrid initModel() throws PicrossException; /*** Method overloaded from the class Mediator ***/ Modified: trunk/src/picross/game/random/RandomGameMediator.java =================================================================== --- trunk/src/picross/game/random/RandomGameMediator.java 2007-06-14 09:33:57 UTC (rev 38) +++ trunk/src/picross/game/random/RandomGameMediator.java 2007-06-14 13:51:01 UTC (rev 39) @@ -40,6 +40,7 @@ //import org.apache.log4j.Logger; import picross.PicrossController; +import picross.PicrossException; import picross.PicrossGrid; import picross.game.GameMediator; @@ -56,6 +57,10 @@ /** The class' logger. */ //private static Logger log = Logger.getLogger(RandomGameMediator.class); + RandomGameMediator() throws PicrossException { + super(); + } + /*** Methods overloaded from the class GameMediator ***/ /** {@inheritDoc} */ Added: trunk/src/picross/game/simple/SimpleGameMediator.java =================================================================== --- trunk/src/picross/game/simple/SimpleGameMediator.java (rev 0) +++ trunk/src/picross/game/simple/SimpleGameMediator.java 2007-06-14 13:51:01 UTC (rev 39) @@ -0,0 +1,75 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.game.simple; + +import java.io.IOException; + +import javax.swing.JPanel; + +import picross.Picross; +import picross.PicrossException; +import picross.PicrossGrid; + +import picross.game.GameMediator; + +/** + * @author Y. Norsa + */ +public final class SimpleGameMediator extends GameMediator { + /*** Constante ***/ + + /*** Champ statique ***/ + + /*** Champ ***/ + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + public SimpleGameMediator() throws PicrossException { + super(); + } + + /*** M\xE9thode ***/ + + protected PicrossGrid initModel() throws PicrossException { + try { + return new XBMModel(Picross.loadDataFile("halloween.xbm")); + } catch (IOException ioEx) { + throw new PicrossException(ioEx); + } + } +} + Property changes on: trunk/src/picross/game/simple/SimpleGameMediator.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/game/simple/XBMModel.java =================================================================== --- trunk/src/picross/game/simple/XBMModel.java (rev 0) +++ trunk/src/picross/game/simple/XBMModel.java 2007-06-14 13:51:01 UTC (rev 39) @@ -0,0 +1,157 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.game.simple; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.IOException; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import picross.AbstractPicrossModel; + +/** + * @author Y. Norsa + */ +final class XBMModel extends AbstractPicrossModel { + /*** Constante ***/ + + /*** Champ statique ***/ + + private static Logger log = Logger.getLogger(XBMModel.class); + + /*** Champ ***/ + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + XBMModel(InputStream input) throws IOException { + super(); + + List<String> byteValues = new ArrayList<String>(); + + BufferedReader in = new BufferedReader(new InputStreamReader(input)); + + String line = null; + + try { + while ((line = in.readLine()) != null) { + if (line.contains("width")) { + this.width = + Integer.parseInt(line.substring(line + .lastIndexOf(' ')) + .trim()); + XBMModel.log.debug("width = " + this.width); + continue; + } + + if (line.contains("height")) { + this.height = + Integer.parseInt(line.substring(line + .lastIndexOf(' ')) + .trim()); + XBMModel.log.debug("height = " + this.height); + continue; + } + + if (line.contains("bits")) { + this.data = new boolean[this.width][this.height]; + + while ((line = in.readLine()) != null) { + String[] values = line.split(","); + + for (int i = 0; i < values.length; i++) { + //XBMModel.log.debug("values[" + i + "] = " + //+ values[i]); + + if (values[i].contains("0x")) { + String byteStr = + values[i].trim().substring(2, 4); + byteValues.add(byteStr); + } + } + } + } + } + } catch (IOException ioEx) { + throw ioEx; + } finally { + try { + in.close(); + } catch (IOException ioEx) { + XBMModel.log.error(ioEx.getMessage()); + } + } + + int xIndex = 0; + int yIndex = 0; + + for (String byteStr : byteValues) { + int byteVal = Integer.parseInt(byteStr, 16); + String binaryStr = Integer.toBinaryString(byteVal); + + while (binaryStr.length() < 8) { + binaryStr = "0" + binaryStr; + } + + //XBMModel.log.debug(binaryStr); + + for (int j = 8 - 1; j >= 0; j--) { + //XBMModel.log.debug("this.data[" + yIndex + //+ "][" + xIndex + "] = " + //+ (binaryStr.charAt(j) == '1' ? true + //: false)); + + this.data[yIndex++][xIndex] = + (binaryStr.charAt(j) == '1' ? true : false); + + if (yIndex == this.width) { + xIndex++; + yIndex = 0; + } + + if (xIndex == this.height) { + xIndex = 0; + } + } + } + } +} + Property changes on: trunk/src/picross/game/simple/XBMModel.java ___________________________________________________________________ Name: svn:keywords + Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-14 09:33:57
|
Revision: 38 http://picross.svn.sourceforge.net/picross/?rev=38&view=rev Author: yvan_norsa Date: 2007-06-14 02:33:57 -0700 (Thu, 14 Jun 2007) Log Message: ----------- graphics optimisation Modified Paths: -------------- trunk/src/picross/game/GameMediator.java trunk/src/picross/game/GameUI.java trunk/src/picross/game/random/RandomGameController.java trunk/src/picross/game/random/RandomGameMediator.java trunk/src/picross/game/random/RandomGameUI.java trunk/src/picross/grid/GridController.java trunk/src/picross/grid/GridMediator.java trunk/src/picross/grid/GridModel.java trunk/src/picross/grid/GridUI.java Added Paths: ----------- trunk/src/picross/grid/CompletedHints.java Removed Paths: ------------- trunk/src/picross/grid/ClearCommand.java Modified: trunk/src/picross/game/GameMediator.java =================================================================== --- trunk/src/picross/game/GameMediator.java 2007-06-14 05:59:01 UTC (rev 37) +++ trunk/src/picross/game/GameMediator.java 2007-06-14 09:33:57 UTC (rev 38) @@ -38,7 +38,7 @@ import javax.swing.JPanel; -import org.apache.log4j.Logger; +//import org.apache.log4j.Logger; import picross.PicrossGrid; @@ -53,7 +53,7 @@ /*** Static field ***/ /** The class' logger. */ - private static Logger log = Logger.getLogger(GameMediator.class); + //private static Logger log = Logger.getLogger(GameMediator.class); /*** Field ***/ @@ -66,13 +66,14 @@ public GameMediator() { PicrossGrid model = this.initModel(); - GridMediator grid = new GridMediator(model.getWidth(), - model.getHeight(), + int width = model.getWidth(); + int height = model.getHeight(); + + GridMediator grid = new GridMediator(width, height, model.getData()); grid.addSimpleListener(this); - this.view = - this.initView(model.getWidth(), model.getHeight(), grid.getView()); + this.view = this.initView(width, height, grid.getView()); } /*** Abstract methods ***/ @@ -98,7 +99,7 @@ /** {@inheritDoc} */ public void eventPerformed(SimpleEvent e) { - GameMediator.log.debug("eventPerformed(" + e + ")"); + //GameMediator.log.debug("eventPerformed(" + e + ")"); this.fireEventPerformed(e); } Modified: trunk/src/picross/game/GameUI.java =================================================================== --- trunk/src/picross/game/GameUI.java 2007-06-14 05:59:01 UTC (rev 37) +++ trunk/src/picross/game/GameUI.java 2007-06-14 09:33:57 UTC (rev 38) @@ -42,8 +42,6 @@ import javax.swing.JLabel; import javax.swing.JPanel; -import picross.Picross; - /** * The game UI. * Modified: trunk/src/picross/game/random/RandomGameController.java =================================================================== --- trunk/src/picross/game/random/RandomGameController.java 2007-06-14 05:59:01 UTC (rev 37) +++ trunk/src/picross/game/random/RandomGameController.java 2007-06-14 09:33:57 UTC (rev 38) @@ -68,7 +68,7 @@ /** {@inheritDoc} */ public void actionPerformed(ActionEvent e) { - RandomGameController.log.debug("actionPerformed(" + e + ")"); + //RandomGameController.log.debug("actionPerformed(" + e + ")"); String cmd = e.getActionCommand(); Modified: trunk/src/picross/game/random/RandomGameMediator.java =================================================================== --- trunk/src/picross/game/random/RandomGameMediator.java 2007-06-14 05:59:01 UTC (rev 37) +++ trunk/src/picross/game/random/RandomGameMediator.java 2007-06-14 09:33:57 UTC (rev 38) @@ -37,7 +37,7 @@ import javax.swing.JPanel; -import org.apache.log4j.Logger; +//import org.apache.log4j.Logger; import picross.PicrossController; import picross.PicrossGrid; @@ -54,7 +54,7 @@ /*** Static field ***/ /** The class' logger. */ - private static Logger log = Logger.getLogger(RandomGameMediator.class); + //private static Logger log = Logger.getLogger(RandomGameMediator.class); /*** Methods overloaded from the class GameMediator ***/ @@ -74,7 +74,7 @@ /** {@inheritDoc} */ public void eventPerformed(SimpleEvent e) { - RandomGameMediator.log.debug("eventPerformed(" + e + ")"); + //RandomGameMediator.log.debug("eventPerformed(" + e + ")"); String cmd = e.getCommandName(); Modified: trunk/src/picross/game/random/RandomGameUI.java =================================================================== --- trunk/src/picross/game/random/RandomGameUI.java 2007-06-14 05:59:01 UTC (rev 37) +++ trunk/src/picross/game/random/RandomGameUI.java 2007-06-14 09:33:57 UTC (rev 38) @@ -40,8 +40,6 @@ import javax.swing.JButton; import javax.swing.JPanel; -import picross.Picross; - import picross.game.GameUI; /** Deleted: trunk/src/picross/grid/ClearCommand.java =================================================================== --- trunk/src/picross/grid/ClearCommand.java 2007-06-14 05:59:01 UTC (rev 37) +++ trunk/src/picross/grid/ClearCommand.java 2007-06-14 09:33:57 UTC (rev 38) @@ -1,93 +0,0 @@ -/* - * $Id$ - * - * Copyright (c) 2007 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - */ - - -package picross.grid; - -import fr.cle.mmvcs.Command; - -/** - * Command asking to clear hints. - * - * @author Y. Norsa - */ -final class ClearCommand extends Command { - /*** Constants ***/ - - /** Clear a column. */ - static final int COLUMN = 0; - - /** Clear a row. */ - static final int ROW = 1; - - /*** Fields ***/ - - /** Type of hints to clear. */ - private int type; - - /** Number of the column or row. */ - private int pos; - - /*** Constructor ***/ - - /** - * Constructor. - * - * @param type type of hints to clear - * @param pos number of the column or row - */ - ClearCommand(int type, int pos) { - this.type = type; - this.pos = pos; - } - - /*** Accessors ***/ - - /** - * Returns the type of hints to clear. - * - * @return type of hints to clear - */ - int getType() { - return this.type; - } - - /** - * Returns the position of the column or row. - * - * @return position of the number or row - */ - int getPos() { - return this.pos; - } -} - Added: trunk/src/picross/grid/CompletedHints.java =================================================================== --- trunk/src/picross/grid/CompletedHints.java (rev 0) +++ trunk/src/picross/grid/CompletedHints.java 2007-06-14 09:33:57 UTC (rev 38) @@ -0,0 +1,170 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +import java.util.ArrayList; +import java.util.List; + +/** + * This class contains the list of hints, marking those which are completed. + * + * @author Y. Norsa + */ +class CompletedHints { + /*** Fields ***/ + + /** List of completed column hints. */ + private boolean[][] completedCols; + + /** List of completed row hints. */ + private boolean[][] completedRows; + + /*** Constructor ***/ + + /** + * Constructor. + * + * @param colsHintsWidth width of the column hints list + * @param colsHintsHeight height of the column hints list + * @param rowsHintsWidth width of the row hints list + * @param rowsHintsHeight height of the row hints list + */ + CompletedHints(int colsHintsWidth, int colsHintsHeight, + int rowsHintsWidth, int rowsHintsHeight) { + this.completedCols = new boolean[colsHintsWidth][colsHintsHeight]; + this.completedRows = new boolean[rowsHintsWidth][rowsHintsHeight]; + } + + /*** Methods ***/ + + /** + * Tells wether a specific column hint is complete. + * + * @param x column number + * @param y hint position + * @return boolean telling wether the hint is completed + */ + boolean isColHintComplete(int x, int y) { + return this.completedCols[x][y]; + } + + /** + * Returns the list of the completed column hints. + * + * @param column column number + * @return list of completed hints in the column + */ + List<Integer> getCompleteColHints(int column) { + List<Integer> res = new ArrayList<Integer>(); + + for (int i = 0; i < this.completedCols[column].length; i++) { + if (this.completedCols[column][i]) { + res.add(i); + } + } + + return res; + } + + /** + * Resets the state of a hint. + * + * @param col column number + * @param hintIndex hint position + */ + void clearColHint(int col, int hintIndex) { + this.completedCols[col][hintIndex] = false; + } + + /** + * Marks a hint as complete. + * + * @param col column number + * @param index hint position + */ + void setCompleteColHint(int col, int index) { + this.completedCols[col][index] = true; + } + + /** + * Tells wether a specific row hint is complete. + * + * @param x row number + * @param y hint position + * @return boolean telling wether the hint is completed + */ + boolean isRowHintComplete(int x, int y) { + return this.completedRows[x][y]; + } + + /** + * Returns the list of the completed row hints. + * + * @param row row number + * @return list of completed hints in the row + */ + List<Integer> getCompleteRowHints(int row) { + List<Integer> res = new ArrayList<Integer>(); + + for (int i = 0; i < this.completedRows[row].length; i++) { + if (this.completedRows[row][i]) { + res.add(i); + } + } + + return res; + } + + + /** + * Resets the state of a hint. + * + * @param row row number + * @param hintIndex hint position + */ + void clearRowHint(int row, int hintIndex) { + this.completedRows[row][hintIndex] = false; + } + + /** + * Marks a hint as complete. + * + * @param row row number + * @param index hint position + */ + void setCompleteRowHint(int row, int index) { + this.completedRows[row][index] = true; + } +} + Property changes on: trunk/src/picross/grid/CompletedHints.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/grid/GridController.java =================================================================== --- trunk/src/picross/grid/GridController.java 2007-06-14 05:59:01 UTC (rev 37) +++ trunk/src/picross/grid/GridController.java 2007-06-14 09:33:57 UTC (rev 38) @@ -69,9 +69,12 @@ /** Command indicating that a hint has been completed. */ static final String COMPLETED_CMD = "COMPLETED_CMD"; - /** Command asking to clear the completed hints. */ - static final String CLEAR_HINTS_CMD = "CLEAR_HINTS_CMD"; + /** Command asking to repaint the top hints. */ + static final String REPAINT_TOP_HINTS_CMD = "REPAINT_TOP_HINTS_CMD"; + /** Command asking to repaint the left hints. */ + static final String REPAINT_LEFT_HINTS_CMD = "REPAINT_LEFT_HINTS_CMD"; + /** Checking a box. */ static final int CHECK_ACTION = 0; @@ -108,29 +111,13 @@ return; } - if (cmd.equals(GridController.COMPLETED_CMD)) { - CompletedCommand command = (CompletedCommand) e.getCommand(); - - if (command.getType() == CompletedCommand.COLUMN) { - this.view.completedColHint(command.getPosition(), - command.getHintPos()); - } else { //if (command.getType() == CompletedCommand.ROW) { - this.view.completedRowHint(command.getPosition(), - command.getHintPos()); - } - + if (cmd.equals(GridController.REPAINT_TOP_HINTS_CMD)) { + this.view.repaintColHints(); return; } - if (cmd.equals(GridController.CLEAR_HINTS_CMD)) { - ClearCommand command = (ClearCommand) e.getCommand(); - - if (command.getType() == ClearCommand.COLUMN) { - this.view.clearColHints(command.getPos()); - } else { //if (command.getType() == ClearCommand.ROW) { - this.view.clearRowHints(command.getPos()); - } - + if (cmd.equals(GridController.REPAINT_LEFT_HINTS_CMD)) { + this.view.repaintRowHints(); return; } } Modified: trunk/src/picross/grid/GridMediator.java =================================================================== --- trunk/src/picross/grid/GridMediator.java 2007-06-14 05:59:01 UTC (rev 37) +++ trunk/src/picross/grid/GridMediator.java 2007-06-14 09:33:57 UTC (rev 38) @@ -79,6 +79,7 @@ this.model.getBoxes(), this.model.getColData(), this.model.getRowData(), + this.model.getCompletedHints(), controller); controller.setView(this.view); @@ -124,52 +125,16 @@ new PaintCommand(row, column)); } - /** - * Asks to clear a column's hints. - * - * @param column column number - */ - void clearColHints(int column) { - this.fireEventPerformed(GridController.CLEAR_HINTS_CMD, - new ClearCommand(ClearCommand.COLUMN, - column)); + /** Asks to repaint the column hints. */ + void repaintColHints() { + this.fireEventPerformed(GridController.REPAINT_TOP_HINTS_CMD); } - /** - * Ask to mark a column hint as completed. - * - * @param column column number - * @param hintPos position of the hint - */ - void completedColHint(int column, int hintPos) { - this.fireEventPerformed(GridController.COMPLETED_CMD, - new CompletedCommand(CompletedCommand.COLUMN, - column, hintPos)); + /** Asks to repaint the row hints. */ + void repaintRowHints() { + this.fireEventPerformed(GridController.REPAINT_LEFT_HINTS_CMD); } - /** - * Asks to clear a row's hints. - * - * @param row row number - */ - void clearRowHints(int row) { - this.fireEventPerformed(GridController.CLEAR_HINTS_CMD, - new ClearCommand(ClearCommand.ROW, - row)); - } - - /** - * Asks to mark a row hint as completed. - * - * @param row row number - * @param hintPos position of the hint - */ - void completedRowHint(int row, int hintPos) { - this.fireEventPerformed(GridController.COMPLETED_CMD, - new CompletedCommand(CompletedCommand.ROW, - row, hintPos)); - } - /*** Accessor ***/ /** Modified: trunk/src/picross/grid/GridModel.java =================================================================== --- trunk/src/picross/grid/GridModel.java 2007-06-14 05:59:01 UTC (rev 37) +++ trunk/src/picross/grid/GridModel.java 2007-06-14 09:33:57 UTC (rev 38) @@ -77,6 +77,9 @@ /** Rows hints. */ private int[][] rowData; + /** List of completed hints. */ + private CompletedHints completedHints; + /*** Constructor ***/ /** @@ -223,6 +226,10 @@ } } } + + this.completedHints = + new CompletedHints(data.length, this.colData[0].length, + data[0].length, this.rowData[0].length); } /*** Static methods ***/ @@ -366,7 +373,7 @@ */ private void checkRow(int row) { // Contains the completed hints - List<Integer> completedHints = new ArrayList<Integer>(); + List<Integer> completedRowHints = new ArrayList<Integer>(); // Current hint we're looking to complete int currentHintIndex = @@ -390,7 +397,7 @@ if (this.rowData[row][currentHintIndex] == currentChain) { - completedHints.add(currentHintIndex); + completedRowHints.add(currentHintIndex); currentChain = 0; currentHintIndex = @@ -410,7 +417,7 @@ * If this is the case, * we cancel everything */ - completedHints.clear(); + completedRowHints.clear(); break; } } @@ -435,7 +442,7 @@ if (currentHintIndex != -1 && this.rowData[row][currentHintIndex] == currentChain) { - completedHints.add(currentHintIndex); + completedRowHints.add(currentHintIndex); currentChain = 0; } } @@ -455,7 +462,7 @@ if (this.rowData[row][currentHintIndex] == currentChain) { - completedHints.add(currentHintIndex); + completedRowHints.add(currentHintIndex); currentChain = 0; currentHintIndex = @@ -466,7 +473,7 @@ if (currentHintIndex == -1) { for (int i = currentHint; i >= 0; i--) { if (this.boxes[i][row].isChecked()) { - completedHints.clear(); + completedRowHints.clear(); } } @@ -483,11 +490,19 @@ } } - this.mediator.clearRowHints(row); + List<Integer> rowHints = this.completedHints.getCompleteRowHints(row); - for (int index : completedHints) { - this.mediator.completedRowHint(row, index); + for (int hintIndex : rowHints) { + if (!completedRowHints.contains(hintIndex)) { + this.completedHints.clearRowHint(row, hintIndex); + } } + + for (int index : completedRowHints) { + this.completedHints.setCompleteRowHint(row, index); + } + + this.mediator.repaintRowHints(); } /** @@ -498,7 +513,7 @@ private void checkColumn(int column) { //GridModel.log.debug("checkColumn(" + column + ")"); - List<Integer> completedHints = new ArrayList<Integer>(); + List<Integer> completedColHints = new ArrayList<Integer>(); /* for (int i = 0; i < this.colData[column].length; i++) { GridModel.log.debug("this.colData[" + column + "][" + i + "] = " @@ -528,7 +543,7 @@ //GridModel.log.debug("found " + currentChain); - completedHints.add(currentHintIndex); + completedColHints.add(currentHintIndex); currentChain = 0; //GridModel.log.debug("currentHintIndex = " @@ -543,7 +558,7 @@ i++) { if (this.boxes[column][i].isChecked()) { - completedHints.clear(); + completedColHints.clear(); break; } } @@ -568,7 +583,7 @@ //GridModel.log.debug("found " + currentChain); - completedHints.add(currentHintIndex); + completedColHints.add(currentHintIndex); currentChain = 0; } @@ -596,7 +611,7 @@ //GridModel.log.debug("found2 " + currentChain); - completedHints.add(currentHintIndex); + completedColHints.add(currentHintIndex); currentChain = 0; currentHintIndex = @@ -606,7 +621,7 @@ if (currentHintIndex == GridModel.EMPTY_HINT) { for (int i = currentHint; i >= 0; i--) { if (this.boxes[column][i].isChecked()) { - completedHints.clear(); + completedColHints.clear(); } } @@ -623,11 +638,20 @@ } } - this.mediator.clearColHints(column); + List<Integer> colHints = + this.completedHints.getCompleteColHints(column); - for (int index : completedHints) { - this.mediator.completedColHint(column, index); + for (int hintIndex : colHints) { + if (!completedColHints.contains(hintIndex)) { + this.completedHints.clearColHint(column, hintIndex); + } } + + for (int index : completedColHints) { + this.completedHints.setCompleteColHint(column, index); + } + + this.mediator.repaintColHints(); } /** Checks wether the grid is finished. */ @@ -686,5 +710,14 @@ int[][] getRowData() { return this.rowData; } + + /** + * Returns the completed hints. + * + * @return list of completed hints + */ + CompletedHints getCompletedHints() { + return this.completedHints; + } } Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-14 05:59:01 UTC (rev 37) +++ trunk/src/picross/grid/GridUI.java 2007-06-14 09:33:57 UTC (rev 38) @@ -46,6 +46,8 @@ import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; + import java.util.ArrayList; import java.util.List; @@ -150,11 +152,17 @@ /** Rectangle occupied by the top hints. */ private Rectangle topHintsRect; + /** Precomputed image containing the top hints boxes. */ + private transient BufferedImage topHintsBoxes; + /** Rectangle occupied by the left hints. */ private Rectangle leftHintsRect; + /** Precomputed image containing the left hints boxes. */ + private transient BufferedImage leftHintsBoxes; + /** Current state of the grid. */ - private Box[][] boxes; + private transient Box[][] boxes; /** Current rolled-over box. */ private transient Box rollover; @@ -189,12 +197,9 @@ /** Boxes blocks. */ private List<Line2D> blocksLines; - /** Completed column hints. */ - private boolean[][] completedCols; + /** List of completed hints. */ + private transient CompletedHints completedHints; - /** Completed row hints. */ - private boolean[][] completedRows; - /*** Constructor ***/ /** @@ -205,12 +210,14 @@ * @param boxes current state of the grid * @param colData columns hints * @param rowData rows hints + * @param completedHints list of completed hints * @param controller controller for the grid */ GridUI(int width, int height, Box[][] boxes, int[][] colData, int[][] rowData, + CompletedHints completedHints, GridController controller) { super(true); @@ -228,6 +235,8 @@ this.colData = colData; this.rowData = rowData; + this.completedHints = completedHints; + // Computes the size of a hint FontRenderContext frc = new FontRenderContext(null, true, true); @@ -311,10 +320,9 @@ //GridUI.log.debug("bottomBoundary : " + this.bottomBoundary); this.initBlocks(); + this.initTopHints((GridUI.BOX_WIDTH / 2) - (hintBoxWidth / 2)); + this.initLeftHints((GridUI.BOX_HEIGHT / 2) - (hintBoxHeight / 2)); - this.completedCols = new boolean[this.width][this.colData[0].length]; - this.completedRows = new boolean[this.height][this.rowData[0].length]; - this.setPreferredSize(new Dimension(this.rightBoundary + GridUI.RIGHT_SPACE, this.bottomBoundary @@ -424,11 +432,77 @@ } /** + * Precomputes the top hints boxes. + * + * @param topHintsStart coordinate where the boxes begin + */ + private void initTopHints(int topHintsStart) { + this.topHintsBoxes = new BufferedImage(this.topHintsRect.width, + this.topHintsRect.height, + BufferedImage.TYPE_INT_RGB); + Graphics2D g2d = this.topHintsBoxes.createGraphics(); + g2d.setColor(Color.WHITE); + g2d.fillRect(0, 0, this.topHintsRect.width, this.topHintsRect.height); + + int y = 0; + + for (int i = this.colData[0].length - 1; i >= 0; i--) { + int x = topHintsStart; + + for (int j = 0; j < this.colData.length; j++) { + if (this.colData[j][i] != GridModel.EMPTY_HINT) { + this.hintBoxIcon.paintIcon(this, g2d, x, y); + } + + x += GridUI.BOX_WIDTH; + } + + y += this.topHintsDecal; + } + } + + /** + * Precomputes the left hints boxes. + * + * @param leftHintsStart coordinate where the boxes begin + */ + private void initLeftHints(int leftHintsStart) { + this.leftHintsBoxes = new BufferedImage(this.leftHintsRect.width, + this.leftHintsRect.height, + BufferedImage.TYPE_INT_RGB); + Graphics2D g2d = this.leftHintsBoxes.createGraphics(); + g2d.setColor(Color.WHITE); + g2d.fillRect(0, 0, + this.leftHintsRect.width, this.leftHintsRect.height); + + int y = leftHintsStart; + + for (int i = 0; i < this.rowData.length; i++) { + int x = 0; + + for (int j = 0; j < this.rowData[i].length; j++) { + if (this.rowData[i][j] != GridModel.EMPTY_HINT) { + this.hintBoxIcon.paintIcon(this, g2d, x, y); + } + + x += this.leftHintsDecal; + } + + y += GridUI.BOX_HEIGHT; + } + } + + /** * Draws the top hints. * * @param g the graphics context */ private void drawTopHints(Graphics g) { + g.drawImage(this.topHintsBoxes, + this.topHintsRect.x, this.topHintsRect.y, null); + + g.setFont(GridUI.HINT_FONT); + int y = 0; for (int i = this.colData[0].length - 1; i >= 0; i--) { @@ -437,7 +511,7 @@ for (int j = 0; j < this.colData.length; j++) { if (this.colData[j][i] != GridModel.EMPTY_HINT) { this.drawHint(g, this.colData[j][i], x, y, - this.completedCols[j][i]); + this.completedHints.isColHintComplete(j, i)); } x += GridUI.BOX_WIDTH; @@ -453,6 +527,11 @@ * @param g the graphics context */ private void drawLeftHints(Graphics g) { + g.drawImage(this.leftHintsBoxes, + this.leftHintsRect.x, this.leftHintsRect.y, null); + + g.setFont(GridUI.HINT_FONT); + int y = this.leftHintsY; for (int i = 0; i < this.rowData.length; i++) { @@ -461,7 +540,7 @@ for (int j = 0; j < this.rowData[i].length; j++) { if (this.rowData[i][j] != GridModel.EMPTY_HINT) { this.drawHint(g, this.rowData[i][j], x, y, - this.completedRows[i][j]); + this.completedHints.isRowHintComplete(i, j)); } x += this.leftHintsDecal; @@ -481,16 +560,12 @@ */ private void drawHint(Graphics g, int value, int x, int y, boolean complete) { - this.hintBoxIcon.paintIcon(this, g, x, y); - if (complete) { g.setColor(GridUI.COMPLETED_HINT_COLOR); } else { g.setColor(GridUI.HINT_TEXT_COLOR); } - g.setFont(GridUI.HINT_FONT); - y += this.centerHintHeight; if (value < 10) { @@ -587,52 +662,13 @@ } } - /** - * Clears a column completed hints. - * - * @param column column number - */ - void clearColHints(int column) { - for (int i = 0; i < this.completedCols[column].length; i++) { - this.completedCols[column][i] = false; - } - + /** Repaints top hints. */ + void repaintColHints() { this.repaint(this.topHintsRect); } - /** - * Marks a column hint as completed. - * - * @param column the column number - * @param hintPos position of the hint in the column - */ - void completedColHint(int column, int hintPos) { - this.completedCols[column][hintPos] = true; - this.repaint(this.topHintsRect); - } - - /** - * Clears a row completed hints. - * - * @param row row number - */ - void clearRowHints(int row) { - for (int i = 0; i < this.completedRows[row].length; i++) { - this.completedRows[row][i] = false; - } - + /** Repaints left hints. */ + void repaintRowHints() { this.repaint(this.leftHintsRect); } - - /** - * Marks a row hint as completed. - * - * @param row the row number - * @param hintPos position of the hint in the row - */ - void completedRowHint(int row, int hintPos) { - //GridUI.log.debug("completedRowHint(" + row + ", " + hintPos + ")"); - this.completedRows[row][hintPos] = true; - this.repaint(this.leftHintsRect); - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-14 05:59:00
|
Revision: 37 http://picross.svn.sourceforge.net/picross/?rev=37&view=rev Author: yvan_norsa Date: 2007-06-13 22:59:01 -0700 (Wed, 13 Jun 2007) Log Message: ----------- fixed bundleHelper Modified Paths: -------------- trunk/lib/bundleHelper.jar trunk/src/picross/game/GameUI.java trunk/src/picross/game/random/RandomGameUI.java Modified: trunk/lib/bundleHelper.jar =================================================================== (Binary files differ) Modified: trunk/src/picross/game/GameUI.java =================================================================== --- trunk/src/picross/game/GameUI.java 2007-06-13 18:20:44 UTC (rev 36) +++ trunk/src/picross/game/GameUI.java 2007-06-14 05:59:01 UTC (rev 37) @@ -79,8 +79,7 @@ this.infosPanel.setLayout(new BoxLayout(this.infosPanel, BoxLayout.Y_AXIS)); - // FIXME "this" should be usable instead of "Picross.class" - JLabel infos = new JLabel(BundleHelper.getString(Picross.class, + JLabel infos = new JLabel(BundleHelper.getString(this, "gridSize") + " : " + width + "*" + height); this.infosPanel.add(infos); Modified: trunk/src/picross/game/random/RandomGameUI.java =================================================================== --- trunk/src/picross/game/random/RandomGameUI.java 2007-06-13 18:20:44 UTC (rev 36) +++ trunk/src/picross/game/random/RandomGameUI.java 2007-06-14 05:59:01 UTC (rev 37) @@ -70,7 +70,7 @@ super(width, height, grid); JButton nextButton = - new JButton(BundleHelper.getString(Picross.class, "anotherGrid")); + new JButton(BundleHelper.getString(this, "anotherGrid")); nextButton.addActionListener(controller); nextButton.setActionCommand(RandomGameController.NEXT_CMD); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-13 18:20:42
|
Revision: 36 http://picross.svn.sourceforge.net/picross/?rev=36&view=rev Author: yvan_norsa Date: 2007-06-13 11:20:44 -0700 (Wed, 13 Jun 2007) Log Message: ----------- random game, bigger applet Modified Paths: -------------- trunk/applet/index.html trunk/bugsFilter.xml trunk/src/picross/PicrossController.java trunk/src/picross/PicrossMediator.java trunk/src/picross/applet/MainMenuAppletUI.java trunk/src/picross/applet/PicrossApplet.java trunk/src/picross/grid/GridUI.java trunk/src/picross/menus/MainMenuController.java trunk/src/picross/menus/MainMenuUI.java trunk/src/picross/properties/messages_picross.properties trunk/src/picross/properties/messages_picross_fr.properties Added Paths: ----------- trunk/applet/log4j.properties trunk/src/picross/AbstractPicrossModel.java trunk/src/picross/PicrossGrid.java trunk/src/picross/game/ trunk/src/picross/game/GameMediator.java trunk/src/picross/game/GameUI.java trunk/src/picross/game/package.html trunk/src/picross/game/random/ trunk/src/picross/game/random/RandomGameController.java trunk/src/picross/game/random/RandomGameMediator.java trunk/src/picross/game/random/RandomGameUI.java trunk/src/picross/game/random/RandomPicrossModel.java trunk/src/picross/game/random/package.html Removed Paths: ------------- trunk/src/picross/PicrossModel.java Modified: trunk/applet/index.html =================================================================== --- trunk/applet/index.html 2007-06-13 18:01:08 UTC (rev 35) +++ trunk/applet/index.html 2007-06-13 18:20:44 UTC (rev 36) @@ -24,17 +24,17 @@ </comment> <script language="JavaScript" type="text/javascript"><!-- - if (_ie == true) document.writeln('<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = "550" HEIGHT = "400" codebase="http://java.sun.com/update/1.5.0/jinstall-1_5-windows-i586.cab#Version=5,0,0,3"><noembed><xmp>'); + if (_ie == true) document.writeln('<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = "900" HEIGHT = "900" codebase="http://java.sun.com/update/1.5.0/jinstall-1_5-windows-i586.cab#Version=5,0,0,3"><noembed><xmp>'); else if (_ns == true && _ns6 == false) document.writeln('<embed ' + 'type="application/x-java-applet;version=1.5" \ CODE = "picross.applet.PicrossApplet" \ ARCHIVE = "picross.jar,bundleHelper.jar,log4j.jar,mmvcs.jar" \ - WIDTH = "550" \ - HEIGHT = "400" ' + + WIDTH = "900" \ + HEIGHT = "900" ' + 'scriptable=false ' + 'pluginspage="http://java.sun.com/products/plugin/index.html#download"><noembed><xmp>'); //--></script> -<applet CODE = "picross.applet.PicrossApplet" ARCHIVE = "picross.jar,bundleHelper.jar,log4j.jar,mmvcs.jar" WIDTH = "550" HEIGHT = "400"></xmp> +<applet CODE = "picross.applet.PicrossApplet" ARCHIVE = "picross.jar,bundleHelper.jar,log4j.jar,mmvcs.jar" WIDTH = "900" HEIGHT = "900"></xmp> <PARAM NAME = CODE VALUE = "picross.applet.PicrossApplet" > <PARAM NAME = ARCHIVE VALUE = "picross.jar,bundleHelper.jar,log4j.jar,mmvcs.jar" > <param name="type" value="application/x-java-applet;version=1.5"> @@ -46,7 +46,7 @@ </embed> </object> <!-- -<APPLET CODE = "picross.applet.PicrossApplet" ARCHIVE = "picross.jar,bundleHelper.jar,log4j.jar,mmvcs.jar" WIDTH = "550" HEIGHT = "400"> +<APPLET CODE = "picross.applet.PicrossApplet" ARCHIVE = "picross.jar,bundleHelper.jar,log4j.jar,mmvcs.jar" WIDTH = "900" HEIGHT = "900"> </APPLET> Added: trunk/applet/log4j.properties =================================================================== --- trunk/applet/log4j.properties (rev 0) +++ trunk/applet/log4j.properties 2007-06-13 18:20:44 UTC (rev 36) @@ -0,0 +1,3 @@ +log4j.rootCategory=off + + Property changes on: trunk/applet/log4j.properties ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/bugsFilter.xml =================================================================== --- trunk/bugsFilter.xml 2007-06-13 18:01:08 UTC (rev 35) +++ trunk/bugsFilter.xml 2007-06-13 18:20:44 UTC (rev 36) @@ -1,5 +1,5 @@ <FindBugsFilter> <Match classregex=".*"> - <Bug pattern="DM_CONVERT_CASE,LSC_LITERAL_STRING_COMPARISON,CLI_CONSTANT_LIST_INDEX,S508C_SET_COMP_COLOR" /> + <Bug pattern="DM_CONVERT_CASE,LSC_LITERAL_STRING_COMPARISON,CLI_CONSTANT_LIST_INDEX,S508C_SET_COMP_COLOR,S508C_NO_SETLABELFOR" /> </Match> </FindBugsFilter> Copied: trunk/src/picross/AbstractPicrossModel.java (from rev 32, trunk/src/picross/PicrossModel.java) =================================================================== --- trunk/src/picross/AbstractPicrossModel.java (rev 0) +++ trunk/src/picross/AbstractPicrossModel.java 2007-06-13 18:20:44 UTC (rev 36) @@ -0,0 +1,268 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross; + +/** + * Model handling the puzzle data. + * + * @author Y. Norsa + */ +public class AbstractPicrossModel implements PicrossGrid { + /*** Fields ***/ + + /** Grid width. */ + protected int width; + + /** Grid height. */ + protected int height; + + /** Grid content. */ + protected boolean[][] data; + + /*** Constructor ***/ + + /** Constructor. */ + /* + PicrossModel() { + this.width = 19; + this.height = 14; + + this.data = new boolean[this.width][this.height]; + + this.data[0][7] = true; + this.data[0][8] = true; + this.data[0][13] = true; + + this.data[1][6] = true; + this.data[1][7] = true; + this.data[1][8] = true; + this.data[1][9] = true; + this.data[1][12] = true; + this.data[1][13] = true; + + this.data[2][6] = true; + this.data[2][7] = true; + this.data[2][8] = true; + this.data[2][9] = true; + this.data[2][12] = true; + this.data[2][13] = true; + + this.data[3][5] = true; + this.data[3][6] = true; + this.data[3][8] = true; + this.data[3][9] = true; + this.data[3][10] = true; + this.data[3][11] = true; + this.data[3][12] = true; + this.data[3][13] = true; + + this.data[4][5] = true; + this.data[4][6] = true; + this.data[4][7] = true; + this.data[4][8] = true; + this.data[4][9] = true; + this.data[4][10] = true; + this.data[4][11] = true; + this.data[4][12] = true; + this.data[4][13] = true; + + this.data[5][0] = true; + this.data[5][1] = true; + this.data[5][2] = true; + this.data[5][3] = true; + this.data[5][4] = true; + this.data[5][5] = true; + this.data[5][6] = true; + this.data[5][7] = true; + this.data[5][8] = true; + this.data[5][9] = true; + this.data[5][10] = true; + this.data[5][11] = true; + this.data[5][12] = true; + this.data[5][13] = true; + + this.data[6][0] = true; + this.data[6][1] = true; + this.data[6][2] = true; + this.data[6][3] = true; + this.data[6][4] = true; + this.data[6][5] = true; + this.data[6][6] = true; + this.data[6][7] = true; + this.data[6][8] = true; + this.data[6][9] = true; + this.data[6][10] = true; + this.data[6][11] = true; + this.data[6][12] = true; + this.data[6][13] = true; + + this.data[7][1] = true; + this.data[7][2] = true; + this.data[7][3] = true; + this.data[7][4] = true; + this.data[7][5] = true; + this.data[7][6] = true; + this.data[7][7] = true; + this.data[7][8] = true; + this.data[7][9] = true; + this.data[7][10] = true; + this.data[7][11] = true; + this.data[7][12] = true; + this.data[7][13] = true; + + this.data[8][8] = true; + this.data[8][9] = true; + this.data[8][10] = true; + this.data[8][11] = true; + this.data[8][12] = true; + this.data[8][13] = true; + + this.data[9][7] = true; + this.data[9][8] = true; + this.data[9][9] = true; + this.data[9][10] = true; + this.data[9][11] = true; + this.data[9][12] = true; + this.data[9][13] = true; + + this.data[10][7] = true; + this.data[10][8] = true; + this.data[10][9] = true; + this.data[10][10] = true; + this.data[10][11] = true; + this.data[10][12] = true; + this.data[10][13] = true; + + this.data[11][6] = true; + this.data[11][7] = true; + this.data[11][8] = true; + this.data[11][9] = true; + this.data[11][10] = true; + this.data[11][11] = true; + this.data[11][12] = true; + this.data[11][13] = true; + + this.data[12][6] = true; + this.data[12][7] = true; + this.data[12][8] = true; + this.data[12][9] = true; + this.data[12][10] = true; + this.data[12][11] = true; + this.data[12][12] = true; + this.data[12][13] = true; + + this.data[13][6] = true; + this.data[13][7] = true; + this.data[13][8] = true; + this.data[13][9] = true; + this.data[13][10] = true; + this.data[13][11] = true; + this.data[13][12] = true; + this.data[13][13] = true; + + this.data[14][6] = true; + this.data[14][7] = true; + this.data[14][8] = true; + this.data[14][9] = true; + this.data[14][10] = true; + this.data[14][11] = true; + this.data[14][12] = true; + this.data[14][13] = true; + + this.data[15][7] = true; + this.data[15][8] = true; + this.data[15][9] = true; + this.data[15][10] = true; + this.data[15][11] = true; + this.data[15][12] = true; + this.data[15][13] = true; + + this.data[16][9] = true; + this.data[16][10] = true; + this.data[16][11] = true; + this.data[16][12] = true; + this.data[16][13] = true; + + this.data[17][8] = true; + this.data[17][9] = true; + this.data[17][10] = true; + this.data[17][11] = true; + this.data[17][12] = true; + this.data[17][13] = true; + + this.data[18][9] = true; + this.data[18][10] = true; + this.data[18][11] = true; + this.data[18][12] = true; + } + */ + /*** Accessors ***/ + + /** + * Returns the width. + * + * @return grid width + */ + public final int getWidth() { + return this.width; + } + + /** + * Returns the height. + * + * @return grid height + */ + public final int getHeight() { + return this.height; + } + + /** + * Returns the content. + * + * @return grid content + */ + public final boolean[][] getData() { + boolean[][] dataCopy = new boolean[this.data.length][]; + + for (int i = 0; i < this.data.length; i++) { + dataCopy[i] = new boolean[this.data[i].length]; + System.arraycopy(this.data[i], 0, + dataCopy[i], 0, + this.data[i].length); + } + + return dataCopy; + } +} + Modified: trunk/src/picross/PicrossController.java =================================================================== --- trunk/src/picross/PicrossController.java 2007-06-13 18:01:08 UTC (rev 35) +++ trunk/src/picross/PicrossController.java 2007-06-13 18:20:44 UTC (rev 36) @@ -43,7 +43,12 @@ * * @author Y. Norsa */ -final class PicrossController extends Controller { +public final class PicrossController extends Controller { + /*** Constant ***/ + + /** Play command. */ + public static final String PLAY_CMD = "PLAY_CMD"; + /*** Static field ***/ /** The class's logger. */ Added: trunk/src/picross/PicrossGrid.java =================================================================== --- trunk/src/picross/PicrossGrid.java (rev 0) +++ trunk/src/picross/PicrossGrid.java 2007-06-13 18:20:44 UTC (rev 36) @@ -0,0 +1,62 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross; + +/** + * Interface for classes able to provide a grid. + * + * @author Y. Norsa + */ +public interface PicrossGrid { + /** + * Returns the width. + * + * @return grid width + */ + int getWidth(); + + /** + * Returns the height. + * + * @return grid height + */ + int getHeight(); + + /** + * Returns the content. + * + * @return grid content + */ + boolean[][] getData(); +} Property changes on: trunk/src/picross/PicrossGrid.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/PicrossMediator.java =================================================================== --- trunk/src/picross/PicrossMediator.java 2007-06-13 18:01:08 UTC (rev 35) +++ trunk/src/picross/PicrossMediator.java 2007-06-13 18:20:44 UTC (rev 36) @@ -40,8 +40,9 @@ //import org.apache.log4j.Logger; +import picross.game.GameMediator; + import picross.grid.GridController; -import picross.grid.GridMediator; import picross.menus.MainMenuController; import picross.menus.MainMenuMediator; @@ -101,16 +102,13 @@ String cmd = e.getCommandName(); - if (cmd.equals(MainMenuController.PLAY_CMD)) { - PicrossModel model = new PicrossModel(); + if (cmd.equals(PicrossController.PLAY_CMD)) { + //this.view.setContent(grid.getView()); - GridMediator grid = new GridMediator(model.getWidth(), - model.getHeight(), - model.getData()); - grid.addSimpleListener(this); + GameMediator game = new picross.game.random.RandomGameMediator(); + game.addSimpleListener(this); + this.view.setContent(game.getView()); - this.view.setContent(grid.getView()); - return; } @@ -121,7 +119,8 @@ if (cmd.equals(GridController.GRID_FILLED_CMD)) { this.fireEventPerformed(PicrossController.MESSAGE_CMD, - BundleHelper.getString(this, "victory")); + BundleHelper.getString(this, "victory") + + " !"); return; } } Deleted: trunk/src/picross/PicrossModel.java =================================================================== --- trunk/src/picross/PicrossModel.java 2007-06-13 18:01:08 UTC (rev 35) +++ trunk/src/picross/PicrossModel.java 2007-06-13 18:20:44 UTC (rev 36) @@ -1,258 +0,0 @@ -/* - * $Id$ - * - * Copyright (c) 2007 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - */ - - -package picross; - -/** - * Model handling the puzzle data. - * - * @author Y. Norsa - */ -final class PicrossModel { - /*** Fields ***/ - - /** Grid width. */ - private int width; - - /** Grid height. */ - private int height; - - /** Grid content. */ - private boolean[][] data; - - /*** Constructor ***/ - - /** Constructor. */ - PicrossModel() { - this.width = 19; - this.height = 14; - - this.data = new boolean[this.width][this.height]; - - this.data[0][7] = true; - this.data[0][8] = true; - this.data[0][13] = true; - - this.data[1][6] = true; - this.data[1][7] = true; - this.data[1][8] = true; - this.data[1][9] = true; - this.data[1][12] = true; - this.data[1][13] = true; - - this.data[2][6] = true; - this.data[2][7] = true; - this.data[2][8] = true; - this.data[2][9] = true; - this.data[2][12] = true; - this.data[2][13] = true; - - this.data[3][5] = true; - this.data[3][6] = true; - this.data[3][8] = true; - this.data[3][9] = true; - this.data[3][10] = true; - this.data[3][11] = true; - this.data[3][12] = true; - this.data[3][13] = true; - - this.data[4][5] = true; - this.data[4][6] = true; - this.data[4][7] = true; - this.data[4][8] = true; - this.data[4][9] = true; - this.data[4][10] = true; - this.data[4][11] = true; - this.data[4][12] = true; - this.data[4][13] = true; - - this.data[5][0] = true; - this.data[5][1] = true; - this.data[5][2] = true; - this.data[5][3] = true; - this.data[5][4] = true; - this.data[5][5] = true; - this.data[5][6] = true; - this.data[5][7] = true; - this.data[5][8] = true; - this.data[5][9] = true; - this.data[5][10] = true; - this.data[5][11] = true; - this.data[5][12] = true; - this.data[5][13] = true; - - this.data[6][0] = true; - this.data[6][1] = true; - this.data[6][2] = true; - this.data[6][3] = true; - this.data[6][4] = true; - this.data[6][5] = true; - this.data[6][6] = true; - this.data[6][7] = true; - this.data[6][8] = true; - this.data[6][9] = true; - this.data[6][10] = true; - this.data[6][11] = true; - this.data[6][12] = true; - this.data[6][13] = true; - - this.data[7][1] = true; - this.data[7][2] = true; - this.data[7][3] = true; - this.data[7][4] = true; - this.data[7][5] = true; - this.data[7][6] = true; - this.data[7][7] = true; - this.data[7][8] = true; - this.data[7][9] = true; - this.data[7][10] = true; - this.data[7][11] = true; - this.data[7][12] = true; - this.data[7][13] = true; - - this.data[8][8] = true; - this.data[8][9] = true; - this.data[8][10] = true; - this.data[8][11] = true; - this.data[8][12] = true; - this.data[8][13] = true; - - this.data[9][7] = true; - this.data[9][8] = true; - this.data[9][9] = true; - this.data[9][10] = true; - this.data[9][11] = true; - this.data[9][12] = true; - this.data[9][13] = true; - - this.data[10][7] = true; - this.data[10][8] = true; - this.data[10][9] = true; - this.data[10][10] = true; - this.data[10][11] = true; - this.data[10][12] = true; - this.data[10][13] = true; - - this.data[11][6] = true; - this.data[11][7] = true; - this.data[11][8] = true; - this.data[11][9] = true; - this.data[11][10] = true; - this.data[11][11] = true; - this.data[11][12] = true; - this.data[11][13] = true; - - this.data[12][6] = true; - this.data[12][7] = true; - this.data[12][8] = true; - this.data[12][9] = true; - this.data[12][10] = true; - this.data[12][11] = true; - this.data[12][12] = true; - this.data[12][13] = true; - - this.data[13][6] = true; - this.data[13][7] = true; - this.data[13][8] = true; - this.data[13][9] = true; - this.data[13][10] = true; - this.data[13][11] = true; - this.data[13][12] = true; - this.data[13][13] = true; - - this.data[14][6] = true; - this.data[14][7] = true; - this.data[14][8] = true; - this.data[14][9] = true; - this.data[14][10] = true; - this.data[14][11] = true; - this.data[14][12] = true; - this.data[14][13] = true; - - this.data[15][7] = true; - this.data[15][8] = true; - this.data[15][9] = true; - this.data[15][10] = true; - this.data[15][11] = true; - this.data[15][12] = true; - this.data[15][13] = true; - - this.data[16][9] = true; - this.data[16][10] = true; - this.data[16][11] = true; - this.data[16][12] = true; - this.data[16][13] = true; - - this.data[17][8] = true; - this.data[17][9] = true; - this.data[17][10] = true; - this.data[17][11] = true; - this.data[17][12] = true; - this.data[17][13] = true; - - this.data[18][9] = true; - this.data[18][10] = true; - this.data[18][11] = true; - this.data[18][12] = true; - } - - /*** Accessors ***/ - - /** - * Returns the width. - * - * @return grid width - */ - int getWidth() { - return this.width; - } - - /** - * Returns the height. - * - * @return grid height - */ - int getHeight() { - return this.height; - } - - /** - * Returns the content. - * - * @return grid content - */ - boolean[][] getData() { - return this.data; - } -} - Modified: trunk/src/picross/applet/MainMenuAppletUI.java =================================================================== --- trunk/src/picross/applet/MainMenuAppletUI.java 2007-06-13 18:01:08 UTC (rev 35) +++ trunk/src/picross/applet/MainMenuAppletUI.java 2007-06-13 18:20:44 UTC (rev 36) @@ -1,50 +1,40 @@ /* * $Id$ - * \xC9crit le 07/06/2007 par Y. Norsa * * Copyright (c) 2007 - * Projet Carte Lorraine de l'Etudiant (CLE) * - * Universit\xE9 Henri Poincar\xE9, Nancy - * Universit\xE9 Nancy2 - * Institut National Polytechnique de Lorraine - * Universit\xE9 Paul Verlaine, Metz + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". * - * Ce projet regroupe les d\xE9veloppements concernant la production - * et l'exploitation de la Carte Lorraine de l'Etudiant - * (carte \xE0 puce sans contact Mifare). + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. * - * Ce logiciel est r\xE9gi par la licence CeCILL soumise au droit fran\xE7ais et - * respectant les principes de diffusion des logiciels libres. Vous pouvez - * utiliser, modifier et/ou redistribuer ce programme sous les conditions - * de la licence CeCILL telle que diffus\xE9e par le CEA, le CNRS et l'INRIA - * sur le site "http://www.cecill.info". + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. * - * En contrepartie de l'accessibilit\xE9 au code source et des droits de copie, - * de modification et de redistribution accord\xE9s par cette licence, il n'est - * offert aux utilisateurs qu'une garantie limit\xE9e. Pour les m\xEAmes raisons, - * seule une responsabilit\xE9 restreinte p\xE8se sur l'auteur du programme, le - * titulaire des droits patrimoniaux et les conc\xE9dants successifs. - * - * A cet \xE9gard l'attention de l'utilisateur est attir\xE9e sur les risques - * associ\xE9s au chargement, \xE0 l'utilisation, \xE0 la modification et/ou au - * d\xE9veloppement et \xE0 la reproduction du logiciel par l'utilisateur \xE9tant - * donn\xE9 sa sp\xE9cificit\xE9 de logiciel libre, qui peut le rendre complexe \xE0 - * manipuler et qui le r\xE9serve donc \xE0 des d\xE9veloppeurs et des professionnels - * avertis poss\xE9dant des connaissances informatiques approfondies. Les - * utilisateurs sont donc invit\xE9s \xE0 charger et tester l'ad\xE9quation du - * logiciel \xE0 leurs besoins dans des conditions permettant d'assurer la - * s\xE9curit\xE9 de leurs syst\xE8mes et ou de leurs donn\xE9es et, plus g\xE9n\xE9ralement, - * \xE0 l'utiliser et l'exploiter dans les m\xEAmes conditions de s\xE9curit\xE9. - * - * Le fait que vous puissiez acc\xE9der \xE0 cet en-t\xEAte signifie que vous avez - * pris connaissance de la licence CeCILL, et que vous en avez accept\xE9 les - * termes. + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. */ package picross.applet; +import java.awt.Color; + import java.awt.event.ActionListener; import picross.menus.MainMenuUI; @@ -75,6 +65,8 @@ */ public MainMenuAppletUI(ActionListener controller) { super(controller); + + this.setBackground(Color.WHITE); } /*** Methods inherited from the class MainMenuUI ***/ Modified: trunk/src/picross/applet/PicrossApplet.java =================================================================== --- trunk/src/picross/applet/PicrossApplet.java 2007-06-13 18:01:08 UTC (rev 35) +++ trunk/src/picross/applet/PicrossApplet.java 2007-06-13 18:20:44 UTC (rev 36) @@ -33,8 +33,6 @@ package picross.applet; -import java.awt.Color; - import javax.swing.JApplet; import javax.swing.JOptionPane; import javax.swing.JPanel; Added: trunk/src/picross/game/GameMediator.java =================================================================== --- trunk/src/picross/game/GameMediator.java (rev 0) +++ trunk/src/picross/game/GameMediator.java 2007-06-13 18:20:44 UTC (rev 36) @@ -0,0 +1,116 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.game; + +import fr.cle.mmvcs.Mediateur; +import fr.cle.mmvcs.SimpleEvent; + +import javax.swing.JPanel; + +import org.apache.log4j.Logger; + +import picross.PicrossGrid; + +import picross.grid.GridMediator; + +/** + * Handles a game. + * + * @author Y. Norsa + */ +public abstract class GameMediator extends Mediateur { + /*** Static field ***/ + + /** The class' logger. */ + private static Logger log = Logger.getLogger(GameMediator.class); + + /*** Field ***/ + + /** The game view. */ + private GameUI view; + + /*** Constructor ***/ + + /** Constructor. */ + public GameMediator() { + PicrossGrid model = this.initModel(); + + GridMediator grid = new GridMediator(model.getWidth(), + model.getHeight(), + model.getData()); + grid.addSimpleListener(this); + + this.view = + this.initView(model.getWidth(), model.getHeight(), grid.getView()); + } + + /*** Abstract methods ***/ + + /** + * Creates the view. + * + * @param width the grid width + * @param height the grid height + * @param gridView the grid itself + * @return view containing the grid + */ + protected abstract GameUI initView(int width, int height, JPanel gridView); + + /** + * Creates the model. + * + * @return grid model + */ + protected abstract PicrossGrid initModel(); + + /*** Method overloaded from the class Mediator ***/ + + /** {@inheritDoc} */ + public void eventPerformed(SimpleEvent e) { + GameMediator.log.debug("eventPerformed(" + e + ")"); + + this.fireEventPerformed(e); + } + + /*** Method ***/ + + /** + * Returns the game view. + * + * @return the view + */ + public JPanel getView() { + return this.view; + } +} Property changes on: trunk/src/picross/game/GameMediator.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/game/GameUI.java =================================================================== --- trunk/src/picross/game/GameUI.java (rev 0) +++ trunk/src/picross/game/GameUI.java 2007-06-13 18:20:44 UTC (rev 36) @@ -0,0 +1,91 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.game; + +import bundleHelper.BundleHelper; + +import java.awt.BorderLayout; +import java.awt.Color; + +import javax.swing.BoxLayout; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import picross.Picross; + +/** + * The game UI. + * + * @author Y. Norsa + */ +public class GameUI extends JPanel { + /*** Constant ***/ + + /** Serialisation ID. */ + private static final long serialVersionUID = 5888877041010228476L; + + /*** Field ***/ + + /** Displays informations about the current game. */ + protected JPanel infosPanel; + + /*** Constructor ***/ + + /** + * Constructor. + * + * @param width the grid width + * @param height the grid height + * @param grid the grid + */ + public GameUI(int width, int height, JPanel grid) { + super(); + + this.setLayout(new BorderLayout()); + + this.infosPanel = new JPanel(); + this.infosPanel.setBackground(Color.WHITE); + this.infosPanel.setLayout(new BoxLayout(this.infosPanel, + BoxLayout.Y_AXIS)); + + // FIXME "this" should be usable instead of "Picross.class" + JLabel infos = new JLabel(BundleHelper.getString(Picross.class, + "gridSize") + + " : " + width + "*" + height); + this.infosPanel.add(infos); + + this.add(this.infosPanel, BorderLayout.NORTH); + this.add(grid, BorderLayout.CENTER); + } +} Property changes on: trunk/src/picross/game/GameUI.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/game/package.html =================================================================== --- trunk/src/picross/game/package.html (rev 0) +++ trunk/src/picross/game/package.html 2007-06-13 18:20:44 UTC (rev 36) @@ -0,0 +1,12 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> + <head> + <!-- + $Id$ + --> + </head> + + <body bgcolor="white"> + Classes relative to a game. + </body> +</html> Property changes on: trunk/src/picross/game/package.html ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/game/random/RandomGameController.java =================================================================== --- trunk/src/picross/game/random/RandomGameController.java (rev 0) +++ trunk/src/picross/game/random/RandomGameController.java 2007-06-13 18:20:44 UTC (rev 36) @@ -0,0 +1,79 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.game.random; + +import fr.cle.mmvcs.Controller; +import fr.cle.mmvcs.SimpleEvent; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import org.apache.log4j.Logger; + +/** + * Controller for the random game UI. + * + * @author Y. Norsa + */ +final class RandomGameController extends Controller implements ActionListener { + /*** Constant ***/ + + /** Command asking to create another grid. */ + static final String NEXT_CMD = "NEXT_CMD"; + + /*** Static field ***/ + + /** The class' logger. */ + private static Logger log = Logger.getLogger(RandomGameController.class); + + /*** Method overloaded from the class Controller ***/ + + /** {@inheritDoc} */ + public void eventPerformed(SimpleEvent e) { + RandomGameController.log.debug("eventPerformed(" + e + ")"); + } + + /*** Method implanted from the interface ActionListener ***/ + + /** {@inheritDoc} */ + public void actionPerformed(ActionEvent e) { + RandomGameController.log.debug("actionPerformed(" + e + ")"); + + String cmd = e.getActionCommand(); + + if (cmd.equals(RandomGameController.NEXT_CMD)) { + this.fireEventPerformed(cmd); + } + } +} Property changes on: trunk/src/picross/game/random/RandomGameController.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/game/random/RandomGameMediator.java =================================================================== --- trunk/src/picross/game/random/RandomGameMediator.java (rev 0) +++ trunk/src/picross/game/random/RandomGameMediator.java 2007-06-13 18:20:44 UTC (rev 36) @@ -0,0 +1,89 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.game.random; + +import fr.cle.mmvcs.SimpleEvent; + +import javax.swing.JPanel; + +import org.apache.log4j.Logger; + +import picross.PicrossController; +import picross.PicrossGrid; + +import picross.game.GameMediator; +import picross.game.GameUI; + +/** + * This object handles a random grid game. + * + * @author Y. Norsa + */ +public final class RandomGameMediator extends GameMediator { + /*** Static field ***/ + + /** The class' logger. */ + private static Logger log = Logger.getLogger(RandomGameMediator.class); + + /*** Methods overloaded from the class GameMediator ***/ + + /** {@inheritDoc} */ + protected GameUI initView(int width, int height, JPanel gridView) { + RandomGameController controller = new RandomGameController(); + controller.addSimpleListener(this); + + return new RandomGameUI(width, height, gridView, + controller); + } + + /** {@inheritDoc} */ + protected PicrossGrid initModel() { + return new RandomPicrossModel(); + } + + /** {@inheritDoc} */ + public void eventPerformed(SimpleEvent e) { + RandomGameMediator.log.debug("eventPerformed(" + e + ")"); + + String cmd = e.getCommandName(); + + if (cmd.equals(RandomGameController.NEXT_CMD)) { + this.fireEventPerformed(PicrossController.PLAY_CMD); + return; + } + + // We want to relay other events, such as GRID_FILLED_CMD + super.eventPerformed(e); + } +} Property changes on: trunk/src/picross/game/random/RandomGameMediator.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/game/random/RandomGameUI.java =================================================================== --- trunk/src/picross/game/random/RandomGameUI.java (rev 0) +++ trunk/src/picross/game/random/RandomGameUI.java 2007-06-13 18:20:44 UTC (rev 36) @@ -0,0 +1,82 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.game.random; + +import bundleHelper.BundleHelper; + +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JPanel; + +import picross.Picross; + +import picross.game.GameUI; + +/** + * UI modifications for a random game. + * + * @author Y. Norsa + */ +final class RandomGameUI extends GameUI { + /*** Constant ***/ + + /** Serialisation ID. */ + private static final long serialVersionUID = -5378941563835370491L; + + /*** Constructor ***/ + + /** + * Constructor. + * + * @param width the grid width + * @param height the grid height + * @param grid the grid + * @param controller the UI controller + */ + RandomGameUI(int width, int height, JPanel grid, + ActionListener controller) { + super(width, height, grid); + + JButton nextButton = + new JButton(BundleHelper.getString(Picross.class, "anotherGrid")); + nextButton.addActionListener(controller); + nextButton.setActionCommand(RandomGameController.NEXT_CMD); + + this.infosPanel.add(nextButton); + + // FIXME this should not be here + this.infosPanel.add(new javax.swing.JSeparator()); + } +} Property changes on: trunk/src/picross/game/random/RandomGameUI.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/game/random/RandomPicrossModel.java =================================================================== --- trunk/src/picross/game/random/RandomPicrossModel.java (rev 0) +++ trunk/src/picross/game/random/RandomPicrossModel.java 2007-06-13 18:20:44 UTC (rev 36) @@ -0,0 +1,78 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.game.random; + +import java.util.Random; + +import org.apache.log4j.Logger; + +import picross.AbstractPicrossModel; + +/** + * This class provides a random grid. + * + * @author Y. Norsa + */ +final class RandomPicrossModel extends AbstractPicrossModel { + /*** Static field ***/ + + /** The class' logger. */ + private static Logger log = Logger.getLogger(RandomPicrossModel.class); + + /*** Constructor ***/ + + /** Constructor. */ + RandomPicrossModel() { + Random rand = new Random(); + + while (this.width == 0) { + this.width = rand.nextInt(25); + } + + while (this.height == 0) { + this.height = rand.nextInt(25); + } + + RandomPicrossModel.log.debug("this.width = " + this.width + + ", this.height = " + this.height); + + this.data = new boolean[this.width][this.height]; + + for (int i = 0; i < this.width; i++) { + for (int j = 0; j < this.height; j++) { + this.data[i][j] = rand.nextBoolean(); + } + } + } +} Property changes on: trunk/src/picross/game/random/RandomPicrossModel.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/game/random/package.html =================================================================== --- trunk/src/picross/game/random/package.html (rev 0) +++ trunk/src/picross/game/random/package.html 2007-06-13 18:20:44 UTC (rev 36) @@ -0,0 +1,12 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> + <head> + <!-- + $Id$ + --> + </head> + + <body bgcolor="white"> + Random grid game. + </body> +</html> Property changes on: trunk/src/picross/game/random/package.html ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-13 18:01:08 UTC (rev 35) +++ trunk/src/picross/grid/GridUI.java 2007-06-13 18:20:44 UTC (rev 36) @@ -219,8 +219,8 @@ this.addMouseListener(this.controller); this.addMouseMotionListener(this.controller); + this.setBackground(Color.WHITE); this.setOpaque(true); - this.setBackground(Color.WHITE); this.width = width; this.height = height; @@ -253,13 +253,13 @@ // Now computes the grid boundaries this.leftBoundary = GridUI.LEFT_HINTS - + (this.rowData[0].length * leftHintsDecal); + + (this.rowData[0].length * this.leftHintsDecal); this.rightBoundary = this.leftBoundary + (this.width * GridUI.BOX_WIDTH); this.topBoundary = GridUI.TOP_HINTS - + (this.colData[0].length * topHintsDecal); + + (this.colData[0].length * this.topHintsDecal); this.bottomBoundary = this.topBoundary + (this.height * GridUI.BOX_HEIGHT); Modified: trunk/src/picross/menus/MainMenuController.java =================================================================== --- trunk/src/picross/menus/MainMenuController.java 2007-06-13 18:01:08 UTC (rev 35) +++ trunk/src/picross/menus/MainMenuController.java 2007-06-13 18:20:44 UTC (rev 36) @@ -41,17 +41,16 @@ import org.apache.log4j.Logger; +import picross.PicrossController; + /** * Controller for the main menu. * * @author Y. Norsa */ public class MainMenuController extends Controller implements ActionListener { - /*** Constants ***/ + /*** Constant ***/ - /** Play command. */ - public static final String PLAY_CMD = "PLAY_CMD"; - /** Exit command. */ public static final String EXIT_CMD = "EXIT_CMD"; @@ -77,7 +76,7 @@ //javax.swing.JOptionPane.showMessageDialog(null, "click : " + cmd); - if (cmd.equals(MainMenuController.PLAY_CMD) + if (cmd.equals(PicrossController.PLAY_CMD) || cmd.equals(MainMenuController.EXIT_CMD)) { this.fireEventPerformed(cmd); Modified: trunk/src/picross/menus/MainMenuUI.java =================================================================== --- trunk/src/picross/menus/MainMenuUI.java 2007-06-13 18:01:08 UTC (rev 35) +++ trunk/src/picross/menus/MainMenuUI.java 2007-06-13 18:20:44 UTC (rev 36) @@ -44,6 +44,7 @@ import javax.swing.JPanel; import picross.Picross; +import picross.PicrossController; /** * UI for the main menu. @@ -85,7 +86,7 @@ ImageIcon playIcon = Picross.getLocalizedImage(MainMenuUI.PLAY_BUTTON_IMAGE); JButton playButton = new JButton(playIcon); - playButton.setActionCommand(MainMenuController.PLAY_CMD); + playButton.setActionCommand(PicrossController.PLAY_CMD); playButton.addActionListener(controller); playButton.setBorder(null); playButton.setBounds(this.getPlayButtonX(), this.getPlayButtonY(), Modified: trunk/src/picross/properties/messages_picross.properties =================================================================== --- trunk/src/picross/properties/messages_picross.properties 2007-06-13 18:01:08 UTC (rev 35) +++ trunk/src/picross/properties/messages_picross.properties 2007-06-13 18:20:44 UTC (rev 36) @@ -1 +1,8 @@ -victory = Congratulations ! +# picross.PicrossMediator +victory = Congratulations + +# picross.game.GameUI +gridSize = Size + +# picross.game.random.RandomGameUI +anotherGrid = Another grid Modified: trunk/src/picross/properties/messages_picross_fr.properties =================================================================== --- trunk/src/picross/properties/messages_picross_fr.properties 2007-06-13 18:01:08 UTC (rev 35) +++ trunk/src/picross/properties/messages_picross_fr.properties 2007-06-13 18:20:44 UTC (rev 36) @@ -1,2 +1,9 @@ # picross.PicrossMediator -victory = F\xE9licitations ! +victory = F\xE9licitations + +# picross.game.GameUI +gridSize = Taille + +# picross.game.random.RandomGameUI +anotherGrid = Une autre grille + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-13 18:01:09
|
Revision: 35 http://picross.svn.sourceforge.net/picross/?rev=35&view=rev Author: yvan_norsa Date: 2007-06-13 11:01:08 -0700 (Wed, 13 Jun 2007) Log Message: ----------- fixed headers Modified Paths: -------------- trunk/src/picross/applet/PicrossApplet.java trunk/src/picross/grid/Box.java Modified: trunk/src/picross/applet/PicrossApplet.java =================================================================== --- trunk/src/picross/applet/PicrossApplet.java 2007-06-13 15:32:37 UTC (rev 34) +++ trunk/src/picross/applet/PicrossApplet.java 2007-06-13 18:01:08 UTC (rev 35) @@ -33,6 +33,8 @@ package picross.applet; +import java.awt.Color; + import javax.swing.JApplet; import javax.swing.JOptionPane; import javax.swing.JPanel; Modified: trunk/src/picross/grid/Box.java =================================================================== --- trunk/src/picross/grid/Box.java 2007-06-13 15:32:37 UTC (rev 34) +++ trunk/src/picross/grid/Box.java 2007-06-13 18:01:08 UTC (rev 35) @@ -1,45 +1,33 @@ /* * $Id$ - * \xC9crit le 06/06/2007 par Y. Norsa * * Copyright (c) 2007 - * Projet Carte Lorraine de l'Etudiant (CLE) * - * Universit\xE9 Henri Poincar\xE9, Nancy - * Universit\xE9 Nancy2 - * Institut National Polytechnique de Lorraine - * Universit\xE9 Paul Verlaine, Metz + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". * - * Ce projet regroupe les d\xE9veloppements concernant la production - * et l'exploitation de la Carte Lorraine de l'Etudiant - * (carte \xE0 puce sans contact Mifare). + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. * - * Ce logiciel est r\xE9gi par la licence CeCILL soumise au droit fran\xE7ais et - * respectant les principes de diffusion des logiciels libres. Vous pouvez - * utiliser, modifier et/ou redistribuer ce programme sous les conditions - * de la licence CeCILL telle que diffus\xE9e par le CEA, le CNRS et l'INRIA - * sur le site "http://www.cecill.info". + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. * - * En contrepartie de l'accessibilit\xE9 au code source et des droits de copie, - * de modification et de redistribution accord\xE9s par cette licence, il n'est - * offert aux utilisateurs qu'une garantie limit\xE9e. Pour les m\xEAmes raisons, - * seule une responsabilit\xE9 restreinte p\xE8se sur l'auteur du programme, le - * titulaire des droits patrimoniaux et les conc\xE9dants successifs. - * - * A cet \xE9gard l'attention de l'utilisateur est attir\xE9e sur les risques - * associ\xE9s au chargement, \xE0 l'utilisation, \xE0 la modification et/ou au - * d\xE9veloppement et \xE0 la reproduction du logiciel par l'utilisateur \xE9tant - * donn\xE9 sa sp\xE9cificit\xE9 de logiciel libre, qui peut le rendre complexe \xE0 - * manipuler et qui le r\xE9serve donc \xE0 des d\xE9veloppeurs et des professionnels - * avertis poss\xE9dant des connaissances informatiques approfondies. Les - * utilisateurs sont donc invit\xE9s \xE0 charger et tester l'ad\xE9quation du - * logiciel \xE0 leurs besoins dans des conditions permettant d'assurer la - * s\xE9curit\xE9 de leurs syst\xE8mes et ou de leurs donn\xE9es et, plus g\xE9n\xE9ralement, - * \xE0 l'utiliser et l'exploiter dans les m\xEAmes conditions de s\xE9curit\xE9. - * - * Le fait que vous puissiez acc\xE9der \xE0 cet en-t\xEAte signifie que vous avez - * pris connaissance de la licence CeCILL, et que vous en avez accept\xE9 les - * termes. + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-13 15:32:37
|
Revision: 34 http://picross.svn.sourceforge.net/picross/?rev=34&view=rev Author: yvan_norsa Date: 2007-06-13 08:32:37 -0700 (Wed, 13 Jun 2007) Log Message: ----------- fixed blocks and boundaries Modified Paths: -------------- trunk/src/picross/grid/GridUI.java Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-13 15:04:38 UTC (rev 33) +++ trunk/src/picross/grid/GridUI.java 2007-06-13 15:32:37 UTC (rev 34) @@ -247,16 +247,19 @@ int hintBoxWidth = this.hintBoxIcon.getIconWidth(); int hintBoxHeight = this.hintBoxIcon.getIconHeight(); + this.leftHintsDecal = hintBoxWidth + GridUI.HINTS_SPACE; + this.topHintsDecal = hintBoxHeight + GridUI.HINTS_SPACE; + // Now computes the grid boundaries this.leftBoundary = GridUI.LEFT_HINTS - + (this.rowData[0].length * hintBoxWidth); + + (this.rowData[0].length * leftHintsDecal); this.rightBoundary = this.leftBoundary + (this.width * GridUI.BOX_WIDTH); this.topBoundary = GridUI.TOP_HINTS - + (this.colData[0].length * hintBoxHeight); + + (this.colData[0].length * topHintsDecal); this.bottomBoundary = this.topBoundary + (this.height * GridUI.BOX_HEIGHT); @@ -273,13 +276,10 @@ this.topHintsX = this.leftBoundary + (GridUI.BOX_WIDTH / 2) - (hintBoxWidth / 2); - this.topHintsDecal = hintBoxHeight + GridUI.HINTS_SPACE; this.leftHintsY = this.topBoundary + (GridUI.BOX_HEIGHT / 2) - (hintBoxHeight / 2); - this.leftHintsDecal = hintBoxWidth + GridUI.HINTS_SPACE; - this.centerHintHeight = (hintBoxHeight / 2) + (hintHeight / 2); this.centerLowHintWidth = @@ -399,7 +399,7 @@ int i = 1; int currentY = this.topBoundary + boxHeight; - while (i < this.height) { + while ((i + GridUI.BLOCK_HEIGHT) <= this.height) { this.blocksLines.add(new Line2D.Double(this.leftBoundary, currentY, this.rightBoundary, @@ -412,7 +412,7 @@ i = 1; int currentX = this.leftBoundary + boxWidth; - while (i < this.width) { + while ((i + GridUI.BLOCK_WIDTH) <= this.width) { this.blocksLines.add(new Line2D.Double(currentX, this.topBoundary, currentX, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-13 15:04:37
|
Revision: 33 http://picross.svn.sourceforge.net/picross/?rev=33&view=rev Author: yvan_norsa Date: 2007-06-13 08:04:38 -0700 (Wed, 13 Jun 2007) Log Message: ----------- fixed blocks drawing Modified Paths: -------------- trunk/src/picross/grid/GridUI.java Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-12 14:21:43 UTC (rev 32) +++ trunk/src/picross/grid/GridUI.java 2007-06-13 15:04:38 UTC (rev 33) @@ -399,7 +399,7 @@ int i = 1; int currentY = this.topBoundary + boxHeight; - while ((i + GridUI.BLOCK_HEIGHT) < this.height) { + while (i < this.height) { this.blocksLines.add(new Line2D.Double(this.leftBoundary, currentY, this.rightBoundary, @@ -412,7 +412,7 @@ i = 1; int currentX = this.leftBoundary + boxWidth; - while ((i + GridUI.BLOCK_WIDTH) < this.width) { + while (i < this.width) { this.blocksLines.add(new Line2D.Double(currentX, this.topBoundary, currentX, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-12 14:21:44
|
Revision: 32 http://picross.svn.sourceforge.net/picross/?rev=32&view=rev Author: yvan_norsa Date: 2007-06-12 07:21:43 -0700 (Tue, 12 Jun 2007) Log Message: ----------- visually marks completed hints Modified Paths: -------------- trunk/src/picross/PicrossModel.java trunk/src/picross/grid/GridController.java trunk/src/picross/grid/GridMediator.java trunk/src/picross/grid/GridModel.java trunk/src/picross/grid/GridUI.java Added Paths: ----------- trunk/src/picross/grid/ClearCommand.java trunk/src/picross/grid/CompletedCommand.java Modified: trunk/src/picross/PicrossModel.java =================================================================== --- trunk/src/picross/PicrossModel.java 2007-06-11 10:43:20 UTC (rev 31) +++ trunk/src/picross/PicrossModel.java 2007-06-12 14:21:43 UTC (rev 32) @@ -58,13 +58,7 @@ this.height = 14; this.data = new boolean[this.width][this.height]; - /* - for (int i = 0; i < this.width; i++) { - for (int j = 0; j < this.height; j++) { - this.data[i][j] = true; - } - } - */ + this.data[0][7] = true; this.data[0][8] = true; this.data[0][13] = true; Added: trunk/src/picross/grid/ClearCommand.java =================================================================== --- trunk/src/picross/grid/ClearCommand.java (rev 0) +++ trunk/src/picross/grid/ClearCommand.java 2007-06-12 14:21:43 UTC (rev 32) @@ -0,0 +1,93 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +import fr.cle.mmvcs.Command; + +/** + * Command asking to clear hints. + * + * @author Y. Norsa + */ +final class ClearCommand extends Command { + /*** Constants ***/ + + /** Clear a column. */ + static final int COLUMN = 0; + + /** Clear a row. */ + static final int ROW = 1; + + /*** Fields ***/ + + /** Type of hints to clear. */ + private int type; + + /** Number of the column or row. */ + private int pos; + + /*** Constructor ***/ + + /** + * Constructor. + * + * @param type type of hints to clear + * @param pos number of the column or row + */ + ClearCommand(int type, int pos) { + this.type = type; + this.pos = pos; + } + + /*** Accessors ***/ + + /** + * Returns the type of hints to clear. + * + * @return type of hints to clear + */ + int getType() { + return this.type; + } + + /** + * Returns the position of the column or row. + * + * @return position of the number or row + */ + int getPos() { + return this.pos; + } +} + Property changes on: trunk/src/picross/grid/ClearCommand.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/grid/CompletedCommand.java =================================================================== --- trunk/src/picross/grid/CompletedCommand.java (rev 0) +++ trunk/src/picross/grid/CompletedCommand.java 2007-06-12 14:21:43 UTC (rev 32) @@ -0,0 +1,107 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +import fr.cle.mmvcs.Command; + +/** + * Command indicating that a hint has been completed. + * + * @author Y. Norsa + */ +final class CompletedCommand extends Command { + /*** Constants ***/ + + /** A column hint has been completed. */ + static final int COLUMN = 0; + + /** A row hint has been completed. */ + static final int ROW = 1; + + /*** Fields ***/ + + /** Type of hint that has been completed. */ + private int type; + + /** Number of the column or row. */ + private int position; + + /** Position of the hint in the column or row. */ + private int hintPos; + + /*** Constructor ***/ + + /** + * Constructor. + * + * @param type type of hint that has been completed + * @param position number of the column or row + * @param hintPos position of the hint in the column or row + */ + CompletedCommand(int type, int position, int hintPos) { + this.type = type; + this.position = position; + this.hintPos = hintPos; + } + + /*** Accessors ***/ + + /** + * Returns the type of hint that has been completed. + * + * @return type of hint that has been completed + */ + int getType() { + return this.type; + } + + /** + * Returns the number of the column or row. + * + * @return number of the column or row + */ + int getPosition() { + return this.position; + } + + /** + * Returns the position of the hint in the column or row. + * + * @return position of the hint in the column or row + */ + int getHintPos() { + return this.hintPos; + } +} + Property changes on: trunk/src/picross/grid/CompletedCommand.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/grid/GridController.java =================================================================== --- trunk/src/picross/grid/GridController.java 2007-06-11 10:43:20 UTC (rev 31) +++ trunk/src/picross/grid/GridController.java 2007-06-12 14:21:43 UTC (rev 32) @@ -63,15 +63,15 @@ /** Command indicating the action has reached its end. */ static final String END_ACTION_CMD = "END_ACTION_CMD"; - /** Command to check a box. */ - //static final String CHECK_CMD = "CHECK_CMD"; - - /** Command to uncheck a box. */ - //static final String UNCHECK_CMD = "UNCHECK_CMD"; - /** Command asking to repaint part of the grid. */ static final String PAINT_CMD = "PAINT_CMD"; + /** Command indicating that a hint has been completed. */ + static final String COMPLETED_CMD = "COMPLETED_CMD"; + + /** Command asking to clear the completed hints. */ + static final String CLEAR_HINTS_CMD = "CLEAR_HINTS_CMD"; + /** Checking a box. */ static final int CHECK_ACTION = 0; @@ -104,8 +104,35 @@ if (cmd.equals(GridController.PAINT_CMD)) { PaintCommand command = (PaintCommand) e.getCommand(); this.view.repaint(command.getRow(), command.getColumn()); + return; } + + if (cmd.equals(GridController.COMPLETED_CMD)) { + CompletedCommand command = (CompletedCommand) e.getCommand(); + + if (command.getType() == CompletedCommand.COLUMN) { + this.view.completedColHint(command.getPosition(), + command.getHintPos()); + } else { //if (command.getType() == CompletedCommand.ROW) { + this.view.completedRowHint(command.getPosition(), + command.getHintPos()); + } + + return; + } + + if (cmd.equals(GridController.CLEAR_HINTS_CMD)) { + ClearCommand command = (ClearCommand) e.getCommand(); + + if (command.getType() == ClearCommand.COLUMN) { + this.view.clearColHints(command.getPos()); + } else { //if (command.getType() == ClearCommand.ROW) { + this.view.clearRowHints(command.getPos()); + } + + return; + } } /*** Methods implanted from the interface MouseListener ***/ Modified: trunk/src/picross/grid/GridMediator.java =================================================================== --- trunk/src/picross/grid/GridMediator.java 2007-06-11 10:43:20 UTC (rev 31) +++ trunk/src/picross/grid/GridMediator.java 2007-06-12 14:21:43 UTC (rev 32) @@ -124,6 +124,52 @@ new PaintCommand(row, column)); } + /** + * Asks to clear a column's hints. + * + * @param column column number + */ + void clearColHints(int column) { + this.fireEventPerformed(GridController.CLEAR_HINTS_CMD, + new ClearCommand(ClearCommand.COLUMN, + column)); + } + + /** + * Ask to mark a column hint as completed. + * + * @param column column number + * @param hintPos position of the hint + */ + void completedColHint(int column, int hintPos) { + this.fireEventPerformed(GridController.COMPLETED_CMD, + new CompletedCommand(CompletedCommand.COLUMN, + column, hintPos)); + } + + /** + * Asks to clear a row's hints. + * + * @param row row number + */ + void clearRowHints(int row) { + this.fireEventPerformed(GridController.CLEAR_HINTS_CMD, + new ClearCommand(ClearCommand.ROW, + row)); + } + + /** + * Asks to mark a row hint as completed. + * + * @param row row number + * @param hintPos position of the hint + */ + void completedRowHint(int row, int hintPos) { + this.fireEventPerformed(GridController.COMPLETED_CMD, + new CompletedCommand(CompletedCommand.ROW, + row, hintPos)); + } + /*** Accessor ***/ /** Modified: trunk/src/picross/grid/GridModel.java =================================================================== --- trunk/src/picross/grid/GridModel.java 2007-06-11 10:43:20 UTC (rev 31) +++ trunk/src/picross/grid/GridModel.java 2007-06-12 14:21:43 UTC (rev 32) @@ -225,10 +225,67 @@ } } + /*** Static methods ***/ + + /** + * Returns the index of the first non-empty hint. + * + * @param hints hints array + * @return index of the first non-empty hint + */ + private static int getFirstHintIndex(int[] hints) { + return GridModel.getNextHintIndex(0, hints); + } + + /** + * Returns the index of the next non-empty hint. + * + * @param currentIndex start index + * @param hints hints array + * @return index of the next non-empty hint + */ + private static int getNextHintIndex(int currentIndex, int[] hints) { + for (int i = currentIndex; i < hints.length; i++) { + if (hints[i] != GridModel.EMPTY_HINT) { + return i; + } + } + + return GridModel.EMPTY_HINT; + } + + /** + * Returns the index of the last non-empty hint. + * + * @param hints hints array + * @return index of the last non-empty hint + */ + private static int getLastHintIndex(int[] hints) { + return GridModel.getPreviousHintIndex(hints.length - 1, hints); + } + + /** + * Returns the index of the previous non-empty hint. + * + * @param currentIndex start index + * @param hints hints array + * @return index of the previous non-empty hint + */ + private static int getPreviousHintIndex(int currentIndex, int[] hints) { + for (int i = currentIndex; i >= 0; i--) { + if (hints[i] != GridModel.EMPTY_HINT) { + return i; + } + } + + return GridModel.EMPTY_HINT; + } + /*** Methods ***/ /** * Method called during an action. + * TODO rename this method * * @param row row of the box * @param column column of the box @@ -297,9 +354,282 @@ } this.lastModified = this.boxes[column][row]; + this.checkColumn(column); + this.checkRow(row); this.checkCompleted(); } + /** + * Checks if a hint has been completed in a row. + * + * @param row row number to check + */ + private void checkRow(int row) { + // Contains the completed hints + List<Integer> completedHints = new ArrayList<Integer>(); + + // Current hint we're looking to complete + int currentHintIndex = + GridModel.getFirstHintIndex(this.rowData[row]); + + // First from left to right + int currentHint = 0; + + // If the first box is empty, do nothing this time + if (!this.boxes[currentHint][row].isEmpty()) { + // Current chain of checked boxes + int currentChain = 0; + + while (currentHint < this.boxes.length) { + if (this.boxes[currentHint][row].isChecked()) { + currentChain++; + } else { + // We reach the end of a chain + + // And it matches the current hint + if (this.rowData[row][currentHintIndex] + == currentChain) { + + completedHints.add(currentHintIndex); + currentChain = 0; + + currentHintIndex = + GridModel.getNextHintIndex(currentHintIndex + 1, + this.rowData[row]); + + if (currentHintIndex == GridModel.EMPTY_HINT) { + /* + * If this is the last hint, we verify that + * there aren't any extra checked boxes + */ + for (int i = currentHint; i < this.boxes.length; + i++) { + + if (this.boxes[i][row].isChecked()) { + /* + * If this is the case, + * we cancel everything + */ + completedHints.clear(); + break; + } + } + + break; + } + } + + // If there is a blank after a filled hint, we stop there + if (this.boxes[currentHint][row].isEmpty()) { + break; + } + } + + currentHint++; + } + + /* + * If we've reached the end of the row + * and there is a current chain, we mark it as completed + */ + if (currentHintIndex != -1 + && this.rowData[row][currentHintIndex] == currentChain) { + + completedHints.add(currentHintIndex); + currentChain = 0; + } + } + + // Same thing from right to left + currentHintIndex = GridModel.getLastHintIndex(this.rowData[row]); + + currentHint = this.boxes.length - 1; + + if (!this.boxes[currentHint][row].isEmpty()) { + int currentChain = 0; + + while (currentHint >= 0) { + if (this.boxes[currentHint][row].isChecked()) { + currentChain++; + } else { + if (this.rowData[row][currentHintIndex] + == currentChain) { + + completedHints.add(currentHintIndex); + currentChain = 0; + + currentHintIndex = + GridModel.getPreviousHintIndex(currentHintIndex + - 1, + this.rowData[row]); + + if (currentHintIndex == -1) { + for (int i = currentHint; i >= 0; i--) { + if (this.boxes[i][row].isChecked()) { + completedHints.clear(); + } + } + + break; + } + } + + if (this.boxes[currentHint][row].isEmpty()) { + break; + } + } + + currentHint--; + } + } + + this.mediator.clearRowHints(row); + + for (int index : completedHints) { + this.mediator.completedRowHint(row, index); + } + } + + /** + * Checks if a hint has been completed in a column. + * + * @param column column number to check + */ + private void checkColumn(int column) { + //GridModel.log.debug("checkColumn(" + column + ")"); + + List<Integer> completedHints = new ArrayList<Integer>(); + /* + for (int i = 0; i < this.colData[column].length; i++) { + GridModel.log.debug("this.colData[" + column + "][" + i + "] = " + + this.colData[column][i]); + } + */ + //GridModel.log.debug("hint courant :" + //+ this.colData[column][currentHintIndex]); + + int currentHintIndex = + GridModel.getLastHintIndex(this.colData[column]); + + int currentHint = 0; + + if (!this.boxes[column][currentHint].isEmpty()) { + int currentChain = 0; + + while (currentHint < this.boxes[0].length) { + //GridModel.log.debug("dans la boucle, currentHint = " + //+ currentHint + ", currentChain = " + currentChain); + + if (this.boxes[column][currentHint].isChecked()) { + currentChain++; + } else { + if (this.colData[column][currentHintIndex] + == currentChain) { + + //GridModel.log.debug("found " + currentChain); + + completedHints.add(currentHintIndex); + currentChain = 0; + + //GridModel.log.debug("currentHintIndex = " + //+ currentHintIndex); + + currentHintIndex = GridModel + .getPreviousHintIndex(currentHintIndex - 1, + this.colData[column]); + + if (currentHintIndex == GridModel.EMPTY_HINT) { + for (int i = currentHint; i < this.boxes[0].length; + i++) { + + if (this.boxes[column][i].isChecked()) { + completedHints.clear(); + break; + } + } + + break; + } + } + + if (this.boxes[column][currentHint].isEmpty()) { + break; + } + } + + currentHint++; + } + + //GridModel.log.debug("fin de la boucle, currentHint = " + //+ currentHint); + + if (currentHintIndex != GridModel.EMPTY_HINT + && this.colData[column][currentHintIndex] == currentChain) { + + //GridModel.log.debug("found " + currentChain); + + completedHints.add(currentHintIndex); + currentChain = 0; + } + + } + + currentHintIndex = GridModel.getFirstHintIndex(this.colData[column]); + + //GridModel.log.debug("hintCourant2 : " + //+ this.colData[column][currentHintIndex]); + + currentHint = this.boxes[0].length - 1; + + if (!this.boxes[column][currentHint].isEmpty()) { + int currentChain = 0; + + while (currentHint >= 0) { + //GridModel.log.debug("dans la boucle2, currentHint = " + //+ currentHint + ", currentChain = " + currentChain); + + if (this.boxes[column][currentHint].isChecked()) { + currentChain++; + } else { + if (this.colData[column][currentHintIndex] + == currentChain) { + + //GridModel.log.debug("found2 " + currentChain); + + completedHints.add(currentHintIndex); + currentChain = 0; + + currentHintIndex = + GridModel.getNextHintIndex(currentHintIndex + 1, + this.colData[column]); + + if (currentHintIndex == GridModel.EMPTY_HINT) { + for (int i = currentHint; i >= 0; i--) { + if (this.boxes[column][i].isChecked()) { + completedHints.clear(); + } + } + + break; + } + } + + if (this.boxes[column][currentHint].isEmpty()) { + break; + } + } + + currentHint--; + } + } + + this.mediator.clearColHints(column); + + for (int index : completedHints) { + this.mediator.completedColHint(column, index); + } + } + /** Checks wether the grid is finished. */ private void checkCompleted() { boolean completed = true; Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-11 10:43:20 UTC (rev 31) +++ trunk/src/picross/grid/GridUI.java 2007-06-12 14:21:43 UTC (rev 32) @@ -76,6 +76,9 @@ /** Color of the hints text. */ private static final Color HINT_TEXT_COLOR = new Color(233, 246, 255); + /** Color of a completed hint text. */ + private static final Color COMPLETED_HINT_COLOR = new Color(208, 215, 217); + /** Font used for the hints. */ private static final Font HINT_FONT = new Font("Sans Serif", Font.BOLD, 10); @@ -186,6 +189,12 @@ /** Boxes blocks. */ private List<Line2D> blocksLines; + /** Completed column hints. */ + private boolean[][] completedCols; + + /** Completed row hints. */ + private boolean[][] completedRows; + /*** Constructor ***/ /** @@ -303,6 +312,9 @@ this.initBlocks(); + this.completedCols = new boolean[this.width][this.colData[0].length]; + this.completedRows = new boolean[this.height][this.rowData[0].length]; + this.setPreferredSize(new Dimension(this.rightBoundary + GridUI.RIGHT_SPACE, this.bottomBoundary @@ -424,7 +436,8 @@ for (int j = 0; j < this.colData.length; j++) { if (this.colData[j][i] != GridModel.EMPTY_HINT) { - this.drawHint(g, this.colData[j][i], x, y); + this.drawHint(g, this.colData[j][i], x, y, + this.completedCols[j][i]); } x += GridUI.BOX_WIDTH; @@ -447,7 +460,8 @@ for (int j = 0; j < this.rowData[i].length; j++) { if (this.rowData[i][j] != GridModel.EMPTY_HINT) { - this.drawHint(g, this.rowData[i][j], x, y); + this.drawHint(g, this.rowData[i][j], x, y, + this.completedRows[i][j]); } x += this.leftHintsDecal; @@ -465,10 +479,16 @@ * @param x X coordinate * @param y Y coordinate */ - private void drawHint(Graphics g, int value, int x, int y) { + private void drawHint(Graphics g, int value, int x, int y, + boolean complete) { this.hintBoxIcon.paintIcon(this, g, x, y); - g.setColor(GridUI.HINT_TEXT_COLOR); + if (complete) { + g.setColor(GridUI.COMPLETED_HINT_COLOR); + } else { + g.setColor(GridUI.HINT_TEXT_COLOR); + } + g.setFont(GridUI.HINT_FONT); y += this.centerHintHeight; @@ -566,4 +586,53 @@ this.repaint(rect); } } + + /** + * Clears a column completed hints. + * + * @param column column number + */ + void clearColHints(int column) { + for (int i = 0; i < this.completedCols[column].length; i++) { + this.completedCols[column][i] = false; + } + + this.repaint(this.topHintsRect); + } + + /** + * Marks a column hint as completed. + * + * @param column the column number + * @param hintPos position of the hint in the column + */ + void completedColHint(int column, int hintPos) { + this.completedCols[column][hintPos] = true; + this.repaint(this.topHintsRect); + } + + /** + * Clears a row completed hints. + * + * @param row row number + */ + void clearRowHints(int row) { + for (int i = 0; i < this.completedRows[row].length; i++) { + this.completedRows[row][i] = false; + } + + this.repaint(this.leftHintsRect); + } + + /** + * Marks a row hint as completed. + * + * @param row the row number + * @param hintPos position of the hint in the row + */ + void completedRowHint(int row, int hintPos) { + //GridUI.log.debug("completedRowHint(" + row + ", " + hintPos + ")"); + this.completedRows[row][hintPos] = true; + this.repaint(this.leftHintsRect); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-11 10:43:25
|
Revision: 31 http://picross.svn.sourceforge.net/picross/?rev=31&view=rev Author: yvan_norsa Date: 2007-06-11 03:43:20 -0700 (Mon, 11 Jun 2007) Log Message: ----------- fixed a little glitch Modified Paths: -------------- trunk/src/picross/PicrossMediator.java trunk/src/picross/PicrossUI.java trunk/src/picross/app/PicrossAppUI.java trunk/src/picross/applet/PicrossApplet.java trunk/src/picross/grid/GridUI.java Modified: trunk/src/picross/PicrossMediator.java =================================================================== --- trunk/src/picross/PicrossMediator.java 2007-06-11 10:38:34 UTC (rev 30) +++ trunk/src/picross/PicrossMediator.java 2007-06-11 10:43:20 UTC (rev 31) @@ -89,8 +89,8 @@ mediator.addSimpleListener(this); - //this.view = new PicrossUI(mediator.getView()); this.view.setContent(mediator.getView()); + this.view.showUI(); } /*** Method overloaded from the Mediateur class ***/ Modified: trunk/src/picross/PicrossUI.java =================================================================== --- trunk/src/picross/PicrossUI.java 2007-06-11 10:38:34 UTC (rev 30) +++ trunk/src/picross/PicrossUI.java 2007-06-11 10:43:20 UTC (rev 31) @@ -69,6 +69,9 @@ */ String getMainMenuClass(); + /** Method called when the application is displayed. */ + void showUI(); + /** Method called when the application exits. */ void exit(); } Modified: trunk/src/picross/app/PicrossAppUI.java =================================================================== --- trunk/src/picross/app/PicrossAppUI.java 2007-06-11 10:38:34 UTC (rev 30) +++ trunk/src/picross/app/PicrossAppUI.java 2007-06-11 10:43:20 UTC (rev 31) @@ -60,7 +60,7 @@ super("Picross"); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - this.setVisible(true); + //this.setVisible(true); } /*** Methods implanted from the interface PicrossUI ***/ @@ -83,6 +83,11 @@ } /** {@inheritDoc} */ + public void showUI() { + this.setVisible(true); + } + + /** {@inheritDoc} */ public void exit() { this.dispose(); } Modified: trunk/src/picross/applet/PicrossApplet.java =================================================================== --- trunk/src/picross/applet/PicrossApplet.java 2007-06-11 10:38:34 UTC (rev 30) +++ trunk/src/picross/applet/PicrossApplet.java 2007-06-11 10:43:20 UTC (rev 31) @@ -92,7 +92,9 @@ } /** {@inheritDoc} */ - public void exit() { - } + public void showUI() { } + + /** {@inheritDoc} */ + public void exit() { } } Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-11 10:38:34 UTC (rev 30) +++ trunk/src/picross/grid/GridUI.java 2007-06-11 10:43:20 UTC (rev 31) @@ -381,10 +381,9 @@ this.rightBoundary, this.topBoundary)); - int boxWidth = GridUI.BLOCK_WIDTH * GridUI.BOX_WIDTH; int boxHeight = GridUI.BLOCK_HEIGHT * GridUI.BOX_HEIGHT; - + int i = 1; int currentY = this.topBoundary + boxHeight; @@ -397,7 +396,7 @@ currentY += boxHeight; i += GridUI.BLOCK_HEIGHT; } - + i = 1; int currentX = this.leftBoundary + boxWidth; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-11 10:38:35
|
Revision: 30 http://picross.svn.sourceforge.net/picross/?rev=30&view=rev Author: yvan_norsa Date: 2007-06-11 03:38:34 -0700 (Mon, 11 Jun 2007) Log Message: ----------- changed blocks drawing Modified Paths: -------------- trunk/src/picross/grid/GridUI.java Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-11 10:25:17 UTC (rev 29) +++ trunk/src/picross/grid/GridUI.java 2007-06-11 10:38:34 UTC (rev 30) @@ -364,70 +364,52 @@ private void initBlocks() { this.blocksLines = new ArrayList<Line2D>(); + this.blocksLines.add(new Line2D.Double(this.leftBoundary, + this.topBoundary, + this.leftBoundary, + this.bottomBoundary)); + this.blocksLines.add(new Line2D.Double(this.leftBoundary, + this.topBoundary, + this.rightBoundary, + this.topBoundary)); + this.blocksLines.add(new Line2D.Double(this.rightBoundary, + this.bottomBoundary, + this.leftBoundary, + this.bottomBoundary)); + this.blocksLines.add(new Line2D.Double(this.rightBoundary, + this.bottomBoundary, + this.rightBoundary, + this.topBoundary)); + + int boxWidth = GridUI.BLOCK_WIDTH * GridUI.BOX_WIDTH; int boxHeight = GridUI.BLOCK_HEIGHT * GridUI.BOX_HEIGHT; + + int i = 1; + int currentY = this.topBoundary + boxHeight; - int i = 0; - int currentY = this.topBoundary; + while ((i + GridUI.BLOCK_HEIGHT) < this.height) { + this.blocksLines.add(new Line2D.Double(this.leftBoundary, + currentY, + this.rightBoundary, + currentY)); - while (i < this.height) { - int j = 0; - int currentX = this.leftBoundary; - - while (j < this.width) { - if ((i + GridUI.BLOCK_HEIGHT) <= this.height) { - if ((j + GridUI.BLOCK_WIDTH <= this.width)) { - GridUI.addRectToLines(this.blocksLines, - currentX, currentY, - boxWidth, boxHeight); - } else { - GridUI.addRectToLines(this.blocksLines, - currentX, currentY, - (this.width - j) - * GridUI.BOX_WIDTH, - boxHeight); - } - } else { - if ((j + GridUI.BLOCK_WIDTH <= this.width)) { - GridUI.addRectToLines(this.blocksLines, - currentX, currentY, - boxWidth, - (this.height - i) - * GridUI.BOX_HEIGHT); - } else { - GridUI.addRectToLines(this.blocksLines, - currentX, currentY, - (this.width - j) - * GridUI.BOX_WIDTH, - (this.height - i) - * GridUI.BOX_HEIGHT); - } - } - - currentX += boxWidth; - j += GridUI.BLOCK_WIDTH; - } - currentY += boxHeight; i += GridUI.BLOCK_HEIGHT; } - } + + i = 1; + int currentX = this.leftBoundary + boxWidth; - /** - * Add a rectangle lines to a list. - * - * @param lines list to add the lines to - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param width width of the rectangle - * @param height height of the retangle - */ - private static void addRectToLines(List<Line2D> lines, - int x, int y, int width, int height) { - lines.add(new Line2D.Double(x, y, x + width, y)); - lines.add(new Line2D.Double(x, y, x, y + height)); - lines.add(new Line2D.Double(x + width, y + height, x, y + height)); - lines.add(new Line2D.Double(x + width, y + height, x + width, y)); + while ((i + GridUI.BLOCK_WIDTH) < this.width) { + this.blocksLines.add(new Line2D.Double(currentX, + this.topBoundary, + currentX, + this.bottomBoundary)); + + currentX += boxWidth; + i += GridUI.BLOCK_WIDTH; + } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-11 10:25:15
|
Revision: 29 http://picross.svn.sourceforge.net/picross/?rev=29&view=rev Author: yvan_norsa Date: 2007-06-11 03:25:17 -0700 (Mon, 11 Jun 2007) Log Message: ----------- added SF logo Modified Paths: -------------- trunk/applet/index.html Modified: trunk/applet/index.html =================================================================== --- trunk/applet/index.html 2007-06-10 18:53:09 UTC (rev 28) +++ trunk/applet/index.html 2007-06-11 10:25:17 UTC (rev 29) @@ -52,3 +52,9 @@ </APPLET> --> <!--"END_CONVERTED_APPLET"--> +<br /> +<br /> +<a href="http://sourceforge.net/projects/picross"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=197480&type=5" width="210" height="62" border="0" alt="SourceForge.net Logo" /></a> + +</body> +</html> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-10 18:53:09
|
Revision: 28 http://picross.svn.sourceforge.net/picross/?rev=28&view=rev Author: yvan_norsa Date: 2007-06-10 11:53:09 -0700 (Sun, 10 Jun 2007) Log Message: ----------- removed the duplicate boxes Modified Paths: -------------- trunk/src/picross/grid/Box.java trunk/src/picross/grid/GridController.java trunk/src/picross/grid/GridMediator.java trunk/src/picross/grid/GridModel.java trunk/src/picross/grid/GridUI.java Added Paths: ----------- trunk/src/picross/grid/PaintCommand.java Removed Paths: ------------- trunk/src/picross/grid/GridBox.java Modified: trunk/src/picross/grid/Box.java =================================================================== --- trunk/src/picross/grid/Box.java 2007-06-08 12:27:52 UTC (rev 27) +++ trunk/src/picross/grid/Box.java 2007-06-10 18:53:09 UTC (rev 28) @@ -45,8 +45,16 @@ package picross.grid; +import java.awt.Rectangle; + +import java.util.HashMap; +import java.util.Map; import java.util.Random; +import javax.swing.ImageIcon; + +import picross.Picross; + //import org.apache.log4j.Logger; /** @@ -54,7 +62,7 @@ * * @author Y. Norsa */ -class Box { +final class Box { /*** Enum ***/ /** Possibles states of a box. */ @@ -69,7 +77,7 @@ CROSSED } - /*** Statics fields ***/ + /*** Constants ***/ /** The class's logger. */ //private static Logger log = Logger.getLogger(Box.class); @@ -77,18 +85,58 @@ /** Random number generator. */ private static Random rand; + /** Index of the normal icon. */ + private static final int ICON_INDEX = 0; + + /** Index of the rollover icon. */ + private static final int ROLLOVER_ICON_INDEX = 1; + + /** Suffix for rollover icons. */ + private static final String ROLLOVER_NAME = "-rollover"; + + /** Images files extension. */ + private static final String IMAGES_EXT = ".png"; + + /*** Static field ***/ + + /** Map containing the images corresponding to the different states. */ + private static Map<Box.BoxState, ImageIcon[]> images; + /*** Fields ***/ /** State of the box. */ - protected Box.BoxState state; + private Box.BoxState state; /** Pseudo random hash-code. */ - private final int hash; + private int hash; + /** Rectangle occupied by the box. */ + private Rectangle rect; + /*** Static block ***/ - static { Box.rand = new Random(); + + // Fills in the images map + + /* + * We create a too large HashMap so it doesn't grow + * during its initialisation + */ + Box.images = new HashMap<Box.BoxState, ImageIcon[]>(7); + + for (Box.BoxState state : Box.BoxState.values()) { + ImageIcon[] img = new ImageIcon[2]; + + String stateImageName = state.toString().toLowerCase(); + img[Box.ICON_INDEX] = Picross.getImage(stateImageName + + Box.IMAGES_EXT); + img[Box.ROLLOVER_ICON_INDEX] = + Picross.getImage(stateImageName + Box.ROLLOVER_NAME + + Box.IMAGES_EXT); + + Box.images.put(state, img); + } } /*** Constructor ***/ @@ -130,7 +178,7 @@ * * @return boolean telling if the box is checked */ - final boolean isChecked() { + boolean isChecked() { return this.state == Box.BoxState.CHECKED; } @@ -139,7 +187,7 @@ * * @return boolean telling if the box is crossed */ - final boolean isCrossed() { + boolean isCrossed() { return this.state == Box.BoxState.CROSSED; } @@ -148,23 +196,61 @@ * * @return boolean telling if the box is empty */ - final boolean isEmpty() { + boolean isEmpty() { return this.state == Box.BoxState.EMPTY; } /** Empties the box. */ - final void empty() { + void empty() { this.state = Box.BoxState.EMPTY; } /** Checks the box. */ - final void check() { + void check() { this.state = Box.BoxState.CHECKED; } /** Crosses the box. */ - final void cross() { + void cross() { this.state = Box.BoxState.CROSSED; } + + /** + * Returns the icon representing the current state of the box. + * + * @return icon of the state of the box + */ + ImageIcon getIcon() { + return Box.images.get(this.state)[Box.ICON_INDEX]; + } + + /** + * Returns the rollover icon representing the current state of the box. + * + * @return rollover icon of the state of the box + */ + ImageIcon getRolloverIcon() { + return Box.images.get(this.state)[Box.ROLLOVER_ICON_INDEX]; + } + + /*** Accessors ***/ + + /** + * Permits to define the rectangle occupied by the box. + * + * @param rect rectangle of the box + */ + void setRect(Rectangle rect) { + this.rect = rect; + } + + /** + * Returns this box' rectangle. + * + * @return rectangle occupied by this box + */ + Rectangle getRect() { + return this.rect; + } } Deleted: trunk/src/picross/grid/GridBox.java =================================================================== --- trunk/src/picross/grid/GridBox.java 2007-06-08 12:27:52 UTC (rev 27) +++ trunk/src/picross/grid/GridBox.java 2007-06-10 18:53:09 UTC (rev 28) @@ -1,107 +0,0 @@ -package picross.grid; - -import java.awt.Rectangle; - -import java.util.HashMap; -import java.util.Map; - -import javax.swing.ImageIcon; - -import picross.Picross; - -/** - * Graphical representation of a box in the grid. - * - * @author Y. Norsa - */ -final class GridBox extends Box { - /*** Constants ***/ - - /** Index of the normal icon. */ - private static final int ICON_INDEX = 0; - - /** Index of the rollover icon. */ - private static final int ROLLOVER_ICON_INDEX = 1; - - /** Suffix for rollover icons. */ - private static final String ROLLOVER_NAME = "-rollover"; - - /** Images files extension. */ - private static final String IMAGES_EXT = ".png"; - - /*** Static field ***/ - - /** Map containing the images corresponding to the different states. */ - private static Map<Box.BoxState, ImageIcon[]> images; - - /*** Field ***/ - - /** Rectangle occupied by the box. */ - private Rectangle rect; - - // Fills in the images map - static { - /* - * We create a too large HashMap so it doesn't grow - * during its initialisation - */ - GridBox.images = new HashMap<Box.BoxState, ImageIcon[]>(7); - - for (Box.BoxState state : Box.BoxState.values()) { - ImageIcon[] img = new ImageIcon[2]; - - String stateImageName = state.toString().toLowerCase(); - img[GridBox.ICON_INDEX] = Picross.getImage(stateImageName - + GridBox.IMAGES_EXT); - img[GridBox.ROLLOVER_ICON_INDEX] = - Picross.getImage(stateImageName + GridBox.ROLLOVER_NAME - + GridBox.IMAGES_EXT); - - GridBox.images.put(state, img); - } - } - - /*** Constructor ***/ - - /** - * Constructor. - * - * @param rect rectangle occupied by this box - */ - GridBox(Rectangle rect) { - super(); - - this.rect = rect; - } - - /*** Methods ***/ - - /** - * Returns the icon representing the current state of the box. - * - * @return icon of the state of the box - */ - ImageIcon getIcon() { - return GridBox.images.get(this.state)[GridBox.ICON_INDEX]; - } - - /** - * Returns the rollover icon representing the current state of the box. - * - * @return rollover icon of the state of the box - */ - ImageIcon getRolloverIcon() { - return GridBox.images.get(this.state)[GridBox.ROLLOVER_ICON_INDEX]; - } - - /*** Accessor ***/ - - /** - * Returns this box' rectangle. - * - * @return rectangle occupied by this box - */ - Rectangle getRect() { - return this.rect; - } -} Modified: trunk/src/picross/grid/GridController.java =================================================================== --- trunk/src/picross/grid/GridController.java 2007-06-08 12:27:52 UTC (rev 27) +++ trunk/src/picross/grid/GridController.java 2007-06-10 18:53:09 UTC (rev 28) @@ -64,11 +64,14 @@ static final String END_ACTION_CMD = "END_ACTION_CMD"; /** Command to check a box. */ - static final String CHECK_CMD = "CHECK_CMD"; + //static final String CHECK_CMD = "CHECK_CMD"; /** Command to uncheck a box. */ - static final String UNCHECK_CMD = "UNCHECK_CMD"; + //static final String UNCHECK_CMD = "UNCHECK_CMD"; + /** Command asking to repaint part of the grid. */ + static final String PAINT_CMD = "PAINT_CMD"; + /** Checking a box. */ static final int CHECK_ACTION = 0; @@ -98,21 +101,11 @@ return; } - if (cmd.equals(GridController.CHECK_CMD)) { - FillCommand command = (FillCommand) e.getCommand(); - this.view.check(command.getRow(), command.getColumn(), - command.getType()); - + if (cmd.equals(GridController.PAINT_CMD)) { + PaintCommand command = (PaintCommand) e.getCommand(); + this.view.repaint(command.getRow(), command.getColumn()); return; } - - if (cmd.equals(GridController.UNCHECK_CMD)) { - FillCommand command = (FillCommand) e.getCommand(); - this.view.uncheck(command.getRow(), command.getColumn(), - command.getType()); - - return; - } } /*** Methods implanted from the interface MouseListener ***/ Modified: trunk/src/picross/grid/GridMediator.java =================================================================== --- trunk/src/picross/grid/GridMediator.java 2007-06-08 12:27:52 UTC (rev 27) +++ trunk/src/picross/grid/GridMediator.java 2007-06-10 18:53:09 UTC (rev 28) @@ -76,6 +76,7 @@ this.addSimpleListener(controller); this.view = new GridUI(width, height, + this.model.getBoxes(), this.model.getColData(), this.model.getRowData(), controller); @@ -113,27 +114,16 @@ } /** - * Checks a box. + * Asks to repaint a box. * - * @param row row of the box - * @param column column of the box + * @param row row number of the box + * @param column column number of the box */ - void check(int row, int column, int type) { - this.fireEventPerformed(GridController.CHECK_CMD, - new FillCommand(row, column, type)); + void repaint(int row, int column) { + this.fireEventPerformed(GridController.PAINT_CMD, + new PaintCommand(row, column)); } - /** - * Unchecks a box. - * - * @param row row of the box - * @param column column of the box - */ - void uncheck(int row, int column, int type) { - this.fireEventPerformed(GridController.UNCHECK_CMD, - new FillCommand(row, column, type)); - } - /*** Accessor ***/ /** Modified: trunk/src/picross/grid/GridModel.java =================================================================== --- trunk/src/picross/grid/GridModel.java 2007-06-08 12:27:52 UTC (rev 27) +++ trunk/src/picross/grid/GridModel.java 2007-06-10 18:53:09 UTC (rev 28) @@ -268,7 +268,7 @@ this.boxes[column][row].cross(); } - this.mediator.check(row, column, type); + this.mediator.repaint(row, column); } else if (!this.boxes[column][row].isEmpty() && (this.lastModified == null || this.lastModified.isEmpty())) { @@ -278,26 +278,22 @@ if (type == GridController.CHECK_ACTION) { this.boxes[column][row].empty(); - this.mediator.uncheck(row, column, type); } else { //if (type == GridController.CROSS_ACTION) { this.boxes[column][row].cross(); - this.mediator.check(row, column, - GridController.CROSS_ACTION); } } else { //if (this.boxes[column][row].isCrossed()) { //GridModel.log.debug("crossed"); if (type == GridController.CROSS_ACTION) { this.boxes[column][row].empty(); - this.mediator.uncheck(row, column, type); } else { //GridModel.log.debug("check()"); this.boxes[column][row].check(); - this.mediator.check(row, column, - GridController.CHECK_ACTION); } } + + this.mediator.repaint(row, column); } this.lastModified = this.boxes[column][row]; @@ -335,6 +331,15 @@ /*** Accessors ***/ /** + * Returns the boxes. + * + * @return grid boxes + */ + Box[][] getBoxes() { + return this.boxes; + } + + /** * Returns the vertical hints. * * @return columns hints Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-08 12:27:52 UTC (rev 27) +++ trunk/src/picross/grid/GridUI.java 2007-06-10 18:53:09 UTC (rev 28) @@ -151,10 +151,10 @@ private Rectangle leftHintsRect; /** Current state of the grid. */ - private GridBox[][] boxes; + private Box[][] boxes; /** Current rolled-over box. */ - private transient GridBox rollover; + private transient Box rollover; /** Controller attached to this view. */ private transient GridController controller; @@ -193,11 +193,13 @@ * * @param width grid width * @param height grid height + * @param boxes current state of the grid * @param colData columns hints * @param rowData rows hints * @param controller controller for the grid */ GridUI(int width, int height, + Box[][] boxes, int[][] colData, int[][] rowData, GridController controller) { @@ -277,9 +279,8 @@ (hintBoxWidth / 2) - (highHintWidth / 2); // Contain the state of the grid + this.boxes = boxes; - this.boxes = new GridBox[this.width][this.height]; - for (int i = 0; i < this.width; i++) { for (int j = 0; j < this.height; j++) { /* @@ -287,13 +288,13 @@ * so we'll be able * to redraw only what is needed */ - this.boxes[i][j] = - new GridBox(new Rectangle(this.leftBoundary - + (i * GridUI.BOX_WIDTH), - this.topBoundary - + (j * GridUI.BOX_WIDTH), - GridUI.BOX_WIDTH, - GridUI.BOX_HEIGHT)); + this.boxes[i][j] + .setRect(new Rectangle(this.leftBoundary + + (i * GridUI.BOX_WIDTH), + this.topBoundary + + (j * GridUI.BOX_WIDTH), + GridUI.BOX_WIDTH, + GridUI.BOX_HEIGHT)); } } @@ -548,43 +549,12 @@ } /** - * Checks a row. + * Repaints a box. * * @param row row of the box * @param column column of the box */ - void check(int row, int column, int type) { - this.setBoxState(row, column, true, type); - } - - /** - * Unchecks a row. - * - * @param row row of the box - * @param column column of the box - */ - void uncheck(int row, int column, int type) { - this.setBoxState(row, column, false, type); - } - - /** - * Modifies a box and repaints the grid. - * - * @param row row of the box - * @param column column of the box - * @param state new state of the box - */ - private void setBoxState(int row, int column, boolean state, int type) { - if (!state) { - this.boxes[column][row].empty(); - } else { - if (type == GridController.CHECK_ACTION) { - this.boxes[column][row].check(); - } else { //if (type == GridController.CROSS_ACTION) { - this.boxes[column][row].cross(); - } - } - + void repaint(int row, int column) { this.repaint(this.boxes[column][row].getRect()); } Added: trunk/src/picross/grid/PaintCommand.java =================================================================== --- trunk/src/picross/grid/PaintCommand.java (rev 0) +++ trunk/src/picross/grid/PaintCommand.java 2007-06-10 18:53:09 UTC (rev 28) @@ -0,0 +1,85 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +import fr.cle.mmvcs.Command; + +/** + * Command asking to refresh a box in the grid. + * + * @author Y. Norsa + */ +final class PaintCommand extends Command { + /*** Fields ***/ + + /** Row number of the box. */ + private int row; + + /** Column number of the box. */ + private int column; + + /*** Constructor ***/ + + /** + * Constructor. + * + * @param row row number of the box + * @param column column number of the box + */ + PaintCommand(int row, int column) { + this.row = row; + this.column = column; + } + + /*** Accessors ***/ + + /** + * Returns the row of the box. + * + * @return row of the box + */ + int getRow() { + return this.row; + } + + /** + * Returns the column of the box. + * + * @return column of the box + */ + int getColumn() { + return this.column; + } +} + Property changes on: trunk/src/picross/grid/PaintCommand.java ___________________________________________________________________ Name: svn:keywords + Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-08 12:27:54
|
Revision: 27 http://picross.svn.sourceforge.net/picross/?rev=27&view=rev Author: yvan_norsa Date: 2007-06-08 05:27:52 -0700 (Fri, 08 Jun 2007) Log Message: ----------- precomputes the grid blocks Modified Paths: -------------- trunk/src/picross/grid/GridUI.java Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-08 12:07:03 UTC (rev 26) +++ trunk/src/picross/grid/GridUI.java 2007-06-08 12:27:52 UTC (rev 27) @@ -37,13 +37,18 @@ import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; +import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; import java.awt.font.FontRenderContext; +import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; +import java.util.ArrayList; +import java.util.List; + import javax.swing.ImageIcon; import javax.swing.JPanel; @@ -178,6 +183,9 @@ /** Used to center a high hint horizontally. */ private int centerHighHintWidth; + /** Boxes blocks. */ + private List<Line2D> blocksLines; + /*** Constructor ***/ /** @@ -292,6 +300,8 @@ //GridUI.log.debug("rightBoundary : " + this.rightBoundary); //GridUI.log.debug("bottomBoundary : " + this.bottomBoundary); + this.initBlocks(); + this.setPreferredSize(new Dimension(this.rightBoundary + GridUI.RIGHT_SPACE, this.bottomBoundary @@ -304,7 +314,7 @@ protected void paintComponent(Graphics g) { super.paintComponent(g); - Graphics newG = g.create(); + Graphics2D newG = (Graphics2D) g.create(); Rectangle clipRect = newG.getClipBounds(); @@ -317,7 +327,6 @@ } // Paints the boxes - for (int i = 0; i < this.width; i++) { for (int j = 0; j < this.height; j++) { //GridUI.log.debug("currentRect : " + i + "," + j); @@ -341,6 +350,19 @@ // Draws the blocks newG.setColor(GridUI.BLOCKS_COLOR); + for (Line2D line : this.blocksLines) { + newG.draw(line); + } + + newG.dispose(); + } + + /*** Methods ***/ + + /** Precomputes the blocks lines. */ + private void initBlocks() { + this.blocksLines = new ArrayList<Line2D>(); + int boxWidth = GridUI.BLOCK_WIDTH * GridUI.BOX_WIDTH; int boxHeight = GridUI.BLOCK_HEIGHT * GridUI.BOX_HEIGHT; @@ -354,22 +376,30 @@ while (j < this.width) { if ((i + GridUI.BLOCK_HEIGHT) <= this.height) { if ((j + GridUI.BLOCK_WIDTH <= this.width)) { - newG.drawRect(currentX, currentY, - boxWidth, boxHeight); + GridUI.addRectToLines(this.blocksLines, + currentX, currentY, + boxWidth, boxHeight); } else { - newG.drawRect(currentX, currentY, - (this.width - j) * GridUI.BOX_WIDTH, - boxHeight); + GridUI.addRectToLines(this.blocksLines, + currentX, currentY, + (this.width - j) + * GridUI.BOX_WIDTH, + boxHeight); } } else { if ((j + GridUI.BLOCK_WIDTH <= this.width)) { - newG.drawRect(currentX, currentY, - boxWidth, - (this.height - i) * GridUI.BOX_HEIGHT); + GridUI.addRectToLines(this.blocksLines, + currentX, currentY, + boxWidth, + (this.height - i) + * GridUI.BOX_HEIGHT); } else { - newG.drawRect(currentX, currentY, - (this.width - j) * GridUI.BOX_WIDTH, - (this.height - i) * GridUI.BOX_HEIGHT); + GridUI.addRectToLines(this.blocksLines, + currentX, currentY, + (this.width - j) + * GridUI.BOX_WIDTH, + (this.height - i) + * GridUI.BOX_HEIGHT); } } @@ -380,12 +410,25 @@ currentY += boxHeight; i += GridUI.BLOCK_HEIGHT; } + } - newG.dispose(); + /** + * Add a rectangle lines to a list. + * + * @param lines list to add the lines to + * @param x the x coordinate of the rectangle + * @param y the y coordinate of the rectangle + * @param width width of the rectangle + * @param height height of the retangle + */ + private static void addRectToLines(List<Line2D> lines, + int x, int y, int width, int height) { + lines.add(new Line2D.Double(x, y, x + width, y)); + lines.add(new Line2D.Double(x, y, x, y + height)); + lines.add(new Line2D.Double(x + width, y + height, x, y + height)); + lines.add(new Line2D.Double(x + width, y + height, x + width, y)); } - /*** Methods ***/ - /** * Draws the top hints. * @@ -573,4 +616,3 @@ } } } - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-08 12:07:03
|
Revision: 26 http://picross.svn.sourceforge.net/picross/?rev=26&view=rev Author: yvan_norsa Date: 2007-06-08 05:07:03 -0700 (Fri, 08 Jun 2007) Log Message: ----------- hint boxes image, blocks color Modified Paths: -------------- trunk/src/picross/grid/GridUI.java Added Paths: ----------- trunk/images/hint.png Added: trunk/images/hint.png =================================================================== (Binary files differ) Property changes on: trunk/images/hint.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-08 07:41:19 UTC (rev 25) +++ trunk/src/picross/grid/GridUI.java 2007-06-08 12:07:03 UTC (rev 26) @@ -37,19 +37,20 @@ import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; -import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; -import java.awt.RenderingHints; import java.awt.font.FontRenderContext; import java.awt.geom.Rectangle2D; +import javax.swing.ImageIcon; import javax.swing.JPanel; import org.apache.log4j.Logger; +import picross.Picross; + /** * Grid UI. * @@ -62,29 +63,11 @@ private static final long serialVersionUID = 2050855523399115878L; /** Space left before the top hints. */ - private static final int TOP_HINTS = 13; + private static final int TOP_HINTS = 10; /** Space left after the left hints. */ private static final int LEFT_HINTS = 10; - /** Width occupied by a row hint. */ - private static final int ROW_HINT_WIDTH = 10; - - /** Height occupied by a row hint. */ - private static final int ROW_HINT_HEIGHT = 15; - - /** Width occupied by a column hint. */ - private static final int COL_HINT_WIDTH = 5; - - /** Height occupied by a column hint. */ - private static final int COL_HINT_HEIGHT = 12; - - /** Outline color for the hints boxes. */ - private static final Color HINT_OUTLINE_COLOR = new Color(188, 211, 227); - - /** Background color for the hints boxes. */ - private static final Color HINT_FILL_COLOR = new Color(131, 155, 200); - /** Color of the hints text. */ private static final Color HINT_TEXT_COLOR = new Color(233, 246, 255); @@ -104,12 +87,27 @@ /** Extra space at the bottom of the grid. */ private static final int BOTTOM_SPACE = 5; - /** Text used to compute the hints boxes size. */ - private static final String SAMPLE_HINT = "42"; + /** Text used to compute the high hints boxes size. */ + private static final String HIGH_SAMPLE_HINT = "88"; - /** Diameter of the arc for hint boxes. */ - private static final int ROUND_DIAMETER = 8; + /** Text used to compute the low hints boxes size. */ + private static final String LOW_SAMPLE_HINT = "8"; + /** Hint box icon. */ + private static final String HINT_BOX_ICON = "hint.png"; + + /** Space between hint boxes. */ + private static final int HINTS_SPACE = 2; + + /** Boxes blocks color. */ + private static final Color BLOCKS_COLOR = new Color(131, 155, 200); + + /** A block width. */ + private static final int BLOCK_WIDTH = 5; + + /** A block height. */ + private static final int BLOCK_HEIGHT = 5; + /*** Static field ***/ /** Class' logger. */ @@ -156,9 +154,30 @@ /** Controller attached to this view. */ private transient GridController controller; - /** Size of the hints boxes. */ - private int hintBoxSize; + /** Hint box icon. */ + private ImageIcon hintBoxIcon; + /** X coordinate of the beginning of a top hints row. */ + private int topHintsX; + + /** Space left between two top hints. */ + private int topHintsDecal; + + /** Y coordinate of the beginning of a left hints column. */ + private int leftHintsY; + + /** Space left between two left hints. */ + private int leftHintsDecal; + + /** Used to center a hint vertically. */ + private int centerHintHeight; + + /** Used to center a low hint horizontally. */ + private int centerLowHintWidth; + + /** Used to center a high hint horizontally. */ + private int centerHighHintWidth; + /*** Constructor ***/ /** @@ -190,27 +209,35 @@ this.colData = colData; this.rowData = rowData; - // Computes the size of a hint box + // Computes the size of a hint FontRenderContext frc = new FontRenderContext(null, true, true); + + // High hint (> 10) Rectangle2D textBounds = - GridUI.HINT_FONT.getStringBounds(GridUI.SAMPLE_HINT, frc); + GridUI.HINT_FONT.getStringBounds(GridUI.HIGH_SAMPLE_HINT, frc); + int hintHeight = (int) textBounds.getHeight(); + int highHintWidth = (int) textBounds.getWidth(); - double textWidth = textBounds.getWidth(); - double textHeight = textBounds.getHeight(); + // Low hint + textBounds = GridUI.HINT_FONT.getStringBounds(GridUI.LOW_SAMPLE_HINT, + frc); + int lowHintWidth = (int) textBounds.getWidth(); - this.hintBoxSize = ((int) (textWidth > textHeight - ? textWidth : textHeight)) + 2; + this.hintBoxIcon = Picross.getImage(GridUI.HINT_BOX_ICON); + int hintBoxWidth = this.hintBoxIcon.getIconWidth(); + int hintBoxHeight = this.hintBoxIcon.getIconHeight(); + // Now computes the grid boundaries this.leftBoundary = GridUI.LEFT_HINTS - + (this.rowData[0].length * this.hintBoxSize); + + (this.rowData[0].length * hintBoxWidth); this.rightBoundary = this.leftBoundary + (this.width * GridUI.BOX_WIDTH); this.topBoundary = GridUI.TOP_HINTS - + (this.colData[0].length * this.hintBoxSize); + + (this.colData[0].length * hintBoxHeight); this.bottomBoundary = this.topBoundary + (this.height * GridUI.BOX_HEIGHT); @@ -225,6 +252,24 @@ this.height * GridUI.BOX_HEIGHT); + this.topHintsX = this.leftBoundary + + (GridUI.BOX_WIDTH / 2) - (hintBoxWidth / 2); + this.topHintsDecal = hintBoxHeight + GridUI.HINTS_SPACE; + + this.leftHintsY = this.topBoundary + + (GridUI.BOX_HEIGHT / 2) - (hintBoxHeight / 2); + + this.leftHintsDecal = hintBoxWidth + GridUI.HINTS_SPACE; + + this.centerHintHeight = + (hintBoxHeight / 2) + (hintHeight / 2); + this.centerLowHintWidth = + (hintBoxWidth / 2) - (lowHintWidth / 2); + this.centerHighHintWidth = + (hintBoxWidth / 2) - (highHintWidth / 2); + + // Contain the state of the grid + this.boxes = new GridBox[this.width][this.height]; for (int i = 0; i < this.width; i++) { @@ -259,67 +304,20 @@ protected void paintComponent(Graphics g) { super.paintComponent(g); - Rectangle clipRect = g.getClipBounds(); + Graphics newG = g.create(); - if (this.topHintsRect.intersects(clipRect)) { - Graphics2D g2d = (Graphics2D) g.create(); - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); + Rectangle clipRect = newG.getClipBounds(); - //GridUI.log.debug("top hints"); - - int x = 0; - int y = GridUI.TOP_HINTS; - - for (int i = this.colData[0].length - 1; i >= 0; i--) { - x = this.leftBoundary + GridUI.COL_HINT_WIDTH; - - for (int j = 0; j < this.colData.length; j++) { - if (this.colData[j][i] != GridModel.EMPTY_HINT) { - // Center the hint - int hintX = x - + (((x + GridUI.COL_HINT_WIDTH) - x) / 2); - - this.drawColHint(g2d, this.colData[j][i], hintX, y); - } - - x += GridUI.BOX_WIDTH; - } - - y += this.hintBoxSize + 2; - } - - g2d.dispose(); + if (this.topHintsRect.intersects(clipRect)) { + this.drawTopHints(newG); } if (this.leftHintsRect.intersects(clipRect)) { - //GridUI.log.debug("left hints"); - - Graphics2D g2d = (Graphics2D) g.create(); - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - - int y = this.topBoundary; - - for (int i = 0; i < this.rowData.length; i++) { - int x = 0; - - int hintY = y + GridUI.ROW_HINT_HEIGHT; - - for (int j = 0; j < this.rowData[i].length; j++) { - if (this.rowData[i][j] != GridModel.EMPTY_HINT) { - this.drawRowHint(g2d, this.rowData[i][j], x, hintY); - } - - x += this.hintBoxSize + 2; - } - - y += GridUI.BOX_HEIGHT; - } - - g2d.dispose(); + this.drawLeftHints(newG); } + // Paints the boxes + for (int i = 0; i < this.width; i++) { for (int j = 0; j < this.height; j++) { //GridUI.log.debug("currentRect : " + i + "," + j); @@ -329,9 +327,10 @@ if (currentRect.intersects(clipRect)) { if (this.boxes[i][j] == this.rollover) { this.boxes[i][j].getRolloverIcon() - .paintIcon(this, g, currentRect.x, currentRect.y); + .paintIcon(this, newG, + currentRect.x, currentRect.y); } else { - this.boxes[i][j].getIcon().paintIcon(this, g, + this.boxes[i][j].getIcon().paintIcon(this, newG, currentRect.x, currentRect.y); } @@ -339,130 +338,123 @@ } } - g.setColor(Color.RED); + // Draws the blocks + newG.setColor(GridUI.BLOCKS_COLOR); - int currentY = this.topBoundary; - int boxWidth = 5 * GridUI.BOX_WIDTH; - int boxHeight = 5 * GridUI.BOX_HEIGHT; + int boxWidth = GridUI.BLOCK_WIDTH * GridUI.BOX_WIDTH; + int boxHeight = GridUI.BLOCK_HEIGHT * GridUI.BOX_HEIGHT; int i = 0; + int currentY = this.topBoundary; while (i < this.height) { - int currentX = this.leftBoundary; int j = 0; + int currentX = this.leftBoundary; while (j < this.width) { - if ((i + 5) <= this.height) { - if ((j + 5 <= this.width)) { - g.drawRect(currentX, currentY, + if ((i + GridUI.BLOCK_HEIGHT) <= this.height) { + if ((j + GridUI.BLOCK_WIDTH <= this.width)) { + newG.drawRect(currentX, currentY, boxWidth, boxHeight); } else { - g.drawRect(currentX, currentY, + newG.drawRect(currentX, currentY, (this.width - j) * GridUI.BOX_WIDTH, boxHeight); } } else { - if ((j + 5 <= this.width)) { - g.drawRect(currentX, currentY, + if ((j + GridUI.BLOCK_WIDTH <= this.width)) { + newG.drawRect(currentX, currentY, boxWidth, (this.height - i) * GridUI.BOX_HEIGHT); } else { - g.drawRect(currentX, currentY, + newG.drawRect(currentX, currentY, (this.width - j) * GridUI.BOX_WIDTH, (this.height - i) * GridUI.BOX_HEIGHT); } } currentX += boxWidth; - j += 5; + j += GridUI.BLOCK_WIDTH; } currentY += boxHeight; - i += 5; + i += GridUI.BLOCK_HEIGHT; } + + newG.dispose(); } /*** Methods ***/ /** - * Draws a column hint. + * Draws the top hints. * - * @param g2d the graphic context - * @param value hint value - * @param x X coordinate - * @param y Y coordinate + * @param g the graphics context */ - private void drawColHint(Graphics2D g2d, int value, int x, int y) { - this.drawHintBox(g2d, x, y, GridUI.COL_HINT_HEIGHT); - this.setHintPen(g2d); + private void drawTopHints(Graphics g) { + int y = 0; - if (value < 10) { - // Tries to center the hint text - g2d.drawString(String.valueOf(value), - x + (this.hintBoxSize / 3), - y); - } else { - g2d.drawString(String.valueOf(value), - x, - y); + for (int i = this.colData[0].length - 1; i >= 0; i--) { + int x = this.topHintsX; + + for (int j = 0; j < this.colData.length; j++) { + if (this.colData[j][i] != GridModel.EMPTY_HINT) { + this.drawHint(g, this.colData[j][i], x, y); + } + + x += GridUI.BOX_WIDTH; + } + + y += this.topHintsDecal; } } /** - * Draws a row hint. + * Draws the left hints. * - * @param g2d the graphic context - * @param value hint value - * @param x X coordinate - * @param y Y coordinate + * @param g the graphics context */ - private void drawRowHint(Graphics2D g2d, int value, int x, int y) { - this.drawHintBox(g2d, x, y, GridUI.ROW_HINT_HEIGHT); - this.setHintPen(g2d); + private void drawLeftHints(Graphics g) { + int y = this.leftHintsY; - if (value < 10) { - g2d.drawString(String.valueOf(value), - x + (this.hintBoxSize / 3) - 1, - y - 3); - } else { - g2d.drawString(String.valueOf(value), - x + 1, - y - 3); + for (int i = 0; i < this.rowData.length; i++) { + int x = 0; + + for (int j = 0; j < this.rowData[i].length; j++) { + if (this.rowData[i][j] != GridModel.EMPTY_HINT) { + this.drawHint(g, this.rowData[i][j], x, y); + } + + x += this.leftHintsDecal; + } + + y += GridUI.BOX_HEIGHT; } } /** - * Draws a hint box. + * Draws a hint. * - * @param g2d the graphic context + * @param g the graphics context + * @param value hint value * @param x X coordinate * @param y Y coordinate - * @param hintHeight the hint height */ - private void drawHintBox(Graphics2D g2d, int x, int y, int hintHeight) { - g2d.setColor(GridUI.HINT_FILL_COLOR); - g2d.fillRoundRect(x, - y - hintHeight, - this.hintBoxSize, - this.hintBoxSize, - GridUI.ROUND_DIAMETER, GridUI.ROUND_DIAMETER); + private void drawHint(Graphics g, int value, int x, int y) { + this.hintBoxIcon.paintIcon(this, g, x, y); - g2d.setColor(GridUI.HINT_OUTLINE_COLOR); - g2d.drawRoundRect(x, - y - hintHeight, - this.hintBoxSize, - this.hintBoxSize, - GridUI.ROUND_DIAMETER, GridUI.ROUND_DIAMETER); - } + g.setColor(GridUI.HINT_TEXT_COLOR); + g.setFont(GridUI.HINT_FONT); - /** - * Sets the hint color and font. - * - * @param g2d the graphic context - */ - private void setHintPen(Graphics2D g2d) { - g2d.setColor(GridUI.HINT_TEXT_COLOR); - g2d.setFont(GridUI.HINT_FONT); + y += this.centerHintHeight; + + if (value < 10) { + x += this.centerLowHintWidth; + g.drawString(String.valueOf(value), x, y); + } else { + x += this.centerHighHintWidth; + g.drawString(String.valueOf(value), x, y); + } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-08 07:41:18
|
Revision: 25 http://picross.svn.sourceforge.net/picross/?rev=25&view=rev Author: yvan_norsa Date: 2007-06-08 00:41:19 -0700 (Fri, 08 Jun 2007) Log Message: ----------- used HtmlConverter for the html applet code Modified Paths: -------------- trunk/applet/index.html Modified: trunk/applet/index.html =================================================================== --- trunk/applet/index.html 2007-06-07 19:37:17 UTC (rev 24) +++ trunk/applet/index.html 2007-06-08 07:41:19 UTC (rev 25) @@ -8,10 +8,47 @@ <body> <h1>Picross</h1> - <applet code="picross.applet.PicrossApplet" - archive="picross.jar,bundleHelper.jar,log4j.jar,mmvcs.jar" - width="550" - height="400" - cache_option="no" /> - </body> -</html> + <!--"CONVERTED_APPLET"--> +<!-- HTML CONVERTER --> +<script language="JavaScript" type="text/javascript"><!-- + var _info = navigator.userAgent; + var _ns = false; + var _ns6 = false; + var _ie = (_info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0 && _info.indexOf("Windows 3.1") < 0); +//--></script> + <comment> + <script language="JavaScript" type="text/javascript"><!-- + var _ns = (navigator.appName.indexOf("Netscape") >= 0 && ((_info.indexOf("Win") > 0 && _info.indexOf("Win16") < 0 && java.lang.System.getProperty("os.version").indexOf("3.5") < 0) || (_info.indexOf("Sun") > 0) || (_info.indexOf("Linux") > 0) || (_info.indexOf("AIX") > 0) || (_info.indexOf("OS/2") > 0) || (_info.indexOf("IRIX") > 0))); + var _ns6 = ((_ns == true) && (_info.indexOf("Mozilla/5") >= 0)); +//--></script> + </comment> + +<script language="JavaScript" type="text/javascript"><!-- + if (_ie == true) document.writeln('<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = "550" HEIGHT = "400" codebase="http://java.sun.com/update/1.5.0/jinstall-1_5-windows-i586.cab#Version=5,0,0,3"><noembed><xmp>'); + else if (_ns == true && _ns6 == false) document.writeln('<embed ' + + 'type="application/x-java-applet;version=1.5" \ + CODE = "picross.applet.PicrossApplet" \ + ARCHIVE = "picross.jar,bundleHelper.jar,log4j.jar,mmvcs.jar" \ + WIDTH = "550" \ + HEIGHT = "400" ' + + 'scriptable=false ' + + 'pluginspage="http://java.sun.com/products/plugin/index.html#download"><noembed><xmp>'); +//--></script> +<applet CODE = "picross.applet.PicrossApplet" ARCHIVE = "picross.jar,bundleHelper.jar,log4j.jar,mmvcs.jar" WIDTH = "550" HEIGHT = "400"></xmp> + <PARAM NAME = CODE VALUE = "picross.applet.PicrossApplet" > + <PARAM NAME = ARCHIVE VALUE = "picross.jar,bundleHelper.jar,log4j.jar,mmvcs.jar" > + <param name="type" value="application/x-java-applet;version=1.5"> + <param name="scriptable" value="false"> + + +</applet> +</noembed> +</embed> +</object> +<!-- +<APPLET CODE = "picross.applet.PicrossApplet" ARCHIVE = "picross.jar,bundleHelper.jar,log4j.jar,mmvcs.jar" WIDTH = "550" HEIGHT = "400"> + + +</APPLET> +--> +<!--"END_CONVERTED_APPLET"--> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-07 19:37:17
|
Revision: 24 http://picross.svn.sourceforge.net/picross/?rev=24&view=rev Author: yvan_norsa Date: 2007-06-07 12:37:17 -0700 (Thu, 07 Jun 2007) Log Message: ----------- 5x5 boxes groups Modified Paths: -------------- trunk/src/picross/grid/GridUI.java Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-07 19:05:53 UTC (rev 23) +++ trunk/src/picross/grid/GridUI.java 2007-06-07 19:37:17 UTC (rev 24) @@ -338,6 +338,48 @@ } } } + + g.setColor(Color.RED); + + int currentY = this.topBoundary; + int boxWidth = 5 * GridUI.BOX_WIDTH; + int boxHeight = 5 * GridUI.BOX_HEIGHT; + + int i = 0; + + while (i < this.height) { + int currentX = this.leftBoundary; + int j = 0; + + while (j < this.width) { + if ((i + 5) <= this.height) { + if ((j + 5 <= this.width)) { + g.drawRect(currentX, currentY, + boxWidth, boxHeight); + } else { + g.drawRect(currentX, currentY, + (this.width - j) * GridUI.BOX_WIDTH, + boxHeight); + } + } else { + if ((j + 5 <= this.width)) { + g.drawRect(currentX, currentY, + boxWidth, + (this.height - i) * GridUI.BOX_HEIGHT); + } else { + g.drawRect(currentX, currentY, + (this.width - j) * GridUI.BOX_WIDTH, + (this.height - i) * GridUI.BOX_HEIGHT); + } + } + + currentX += boxWidth; + j += 5; + } + + currentY += boxHeight; + i += 5; + } } /*** Methods ***/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-07 19:05:51
|
Revision: 23 http://picross.svn.sourceforge.net/picross/?rev=23&view=rev Author: yvan_norsa Date: 2007-06-07 12:05:53 -0700 (Thu, 07 Jun 2007) Log Message: ----------- code cleanup Modified Paths: -------------- trunk/src/picross/grid/GridUI.java Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-07 14:57:23 UTC (rev 22) +++ trunk/src/picross/grid/GridUI.java 2007-06-07 19:05:53 UTC (rev 23) @@ -62,8 +62,11 @@ private static final long serialVersionUID = 2050855523399115878L; /** Space left before the top hints. */ - private static final int TOP_HINTS = 10 + 3; + private static final int TOP_HINTS = 13; + /** Space left after the left hints. */ + private static final int LEFT_HINTS = 10; + /** Width occupied by a row hint. */ private static final int ROW_HINT_WIDTH = 10; @@ -76,11 +79,18 @@ /** Height occupied by a column hint. */ private static final int COL_HINT_HEIGHT = 12; - private static final Color HINT_FORE_COLOR = new Color(188, 211, 227); + /** Outline color for the hints boxes. */ + private static final Color HINT_OUTLINE_COLOR = new Color(188, 211, 227); + + /** Background color for the hints boxes. */ private static final Color HINT_FILL_COLOR = new Color(131, 155, 200); + + /** Color of the hints text. */ private static final Color HINT_TEXT_COLOR = new Color(233, 246, 255); - private static final Font HINT_FONT = new Font("Sans Serif", Font.BOLD, 10); + /** Font used for the hints. */ + private static final Font HINT_FONT = + new Font("Sans Serif", Font.BOLD, 10); /** A box width. */ private static final int BOX_WIDTH = 25; @@ -94,6 +104,12 @@ /** Extra space at the bottom of the grid. */ private static final int BOTTOM_SPACE = 5; + /** Text used to compute the hints boxes size. */ + private static final String SAMPLE_HINT = "42"; + + /** Diameter of the arc for hint boxes. */ + private static final int ROUND_DIAMETER = 8; + /*** Static field ***/ /** Class' logger. */ @@ -140,7 +156,8 @@ /** Controller attached to this view. */ private transient GridController controller; - int hintBoxSize; + /** Size of the hints boxes. */ + private int hintBoxSize; /*** Constructor ***/ @@ -173,54 +190,33 @@ this.colData = colData; this.rowData = rowData; - /**/ + // Computes the size of a hint box + FontRenderContext frc = new FontRenderContext(null, true, true); + Rectangle2D textBounds = + GridUI.HINT_FONT.getStringBounds(GridUI.SAMPLE_HINT, frc); - //FontRenderContext frc = g2d.getFontRenderContext(); - FontRenderContext frc = new FontRenderContext(null, true, - true); - Rectangle2D textBounds = - GridUI.HINT_FONT - .getStringBounds("42", frc); + double textWidth = textBounds.getWidth(); + double textHeight = textBounds.getHeight(); - double textWidth = textBounds.getWidth(); - double textHeight = textBounds.getHeight(); + this.hintBoxSize = ((int) (textWidth > textHeight + ? textWidth : textHeight)) + 2; - this.hintBoxSize = (int) (textWidth > textHeight - ? textWidth : textHeight); - //this.bigHintBoxSize = this.hintBoxSize + 3; - this.hintBoxSize += 2; + // Now computes the grid boundaries - /**/ + this.leftBoundary = GridUI.LEFT_HINTS + + (this.rowData[0].length * this.hintBoxSize); - - - /* - this.leftBoundary = - this.rowData[0].length * GridUI.ROW_HINT_WIDTH; - */ - - for (int i = 0; i < this.rowData[0].length; i++) { - int size = (this.rowData[0][i] / 10) + 1; - //this.leftBoundary += size * GridUI.ROW_HINT_WIDTH; - this.leftBoundary += size * this.hintBoxSize; - } - - //this.leftBoundary = 70; - - this.leftBoundary += 10; - this.rightBoundary = this.leftBoundary + (this.width * GridUI.BOX_WIDTH); this.topBoundary = GridUI.TOP_HINTS - //+ (this.colData[0].length * GridUI.COL_HINT_HEIGHT); + (this.colData[0].length * this.hintBoxSize); - //this.topBoundary = 70; - this.bottomBoundary = this.topBoundary + (this.height * GridUI.BOX_HEIGHT); + // Space occupied by the hints + this.topHintsRect = new Rectangle(this.leftBoundary, 0, this.width * GridUI.BOX_WIDTH, this.topBoundary); @@ -280,7 +276,10 @@ for (int j = 0; j < this.colData.length; j++) { if (this.colData[j][i] != GridModel.EMPTY_HINT) { - int hintX = x + (((x + GridUI.COL_HINT_WIDTH) - x) / 2); + // Center the hint + int hintX = x + + (((x + GridUI.COL_HINT_WIDTH) - x) / 2); + this.drawColHint(g2d, this.colData[j][i], hintX, y); } @@ -343,66 +342,85 @@ /*** Methods ***/ - private void drawColHint(Graphics2D g2d, int value, int hintX, int y) { - g2d.setColor(GridUI.HINT_FILL_COLOR); + /** + * Draws a column hint. + * + * @param g2d the graphic context + * @param value hint value + * @param x X coordinate + * @param y Y coordinate + */ + private void drawColHint(Graphics2D g2d, int value, int x, int y) { + this.drawHintBox(g2d, x, y, GridUI.COL_HINT_HEIGHT); + this.setHintPen(g2d); - g2d.fillRoundRect(hintX, - y - GridUI.COL_HINT_HEIGHT, - this.hintBoxSize, - this.hintBoxSize, - 8, 8); - - g2d.setColor(GridUI.HINT_FORE_COLOR); - - g2d.drawRoundRect(hintX, - y - GridUI.COL_HINT_HEIGHT, - this.hintBoxSize, - this.hintBoxSize, - 8, 8); - - g2d.setColor(GridUI.HINT_TEXT_COLOR); - g2d.setFont(GridUI.HINT_FONT); - if (value < 10) { + // Tries to center the hint text g2d.drawString(String.valueOf(value), - hintX + (this.hintBoxSize / 3), + x + (this.hintBoxSize / 3), y); } else { g2d.drawString(String.valueOf(value), - hintX, + x, y); } } - private void drawRowHint(Graphics2D g2d, int value, int hintX, int y) { + /** + * Draws a row hint. + * + * @param g2d the graphic context + * @param value hint value + * @param x X coordinate + * @param y Y coordinate + */ + private void drawRowHint(Graphics2D g2d, int value, int x, int y) { + this.drawHintBox(g2d, x, y, GridUI.ROW_HINT_HEIGHT); + this.setHintPen(g2d); + + if (value < 10) { + g2d.drawString(String.valueOf(value), + x + (this.hintBoxSize / 3) - 1, + y - 3); + } else { + g2d.drawString(String.valueOf(value), + x + 1, + y - 3); + } + } + + /** + * Draws a hint box. + * + * @param g2d the graphic context + * @param x X coordinate + * @param y Y coordinate + * @param hintHeight the hint height + */ + private void drawHintBox(Graphics2D g2d, int x, int y, int hintHeight) { g2d.setColor(GridUI.HINT_FILL_COLOR); - - g2d.fillRoundRect(hintX, - y - GridUI.ROW_HINT_HEIGHT, + g2d.fillRoundRect(x, + y - hintHeight, this.hintBoxSize, this.hintBoxSize, - 8, 8); - - g2d.setColor(GridUI.HINT_FORE_COLOR); + GridUI.ROUND_DIAMETER, GridUI.ROUND_DIAMETER); - g2d.drawRoundRect(hintX, - y - GridUI.ROW_HINT_HEIGHT, + g2d.setColor(GridUI.HINT_OUTLINE_COLOR); + g2d.drawRoundRect(x, + y - hintHeight, this.hintBoxSize, this.hintBoxSize, - 8, 8); + GridUI.ROUND_DIAMETER, GridUI.ROUND_DIAMETER); + } + /** + * Sets the hint color and font. + * + * @param g2d the graphic context + */ + private void setHintPen(Graphics2D g2d) { g2d.setColor(GridUI.HINT_TEXT_COLOR); g2d.setFont(GridUI.HINT_FONT); - - if (value < 10) { - g2d.drawString(String.valueOf(value), - hintX + (this.hintBoxSize / 3) - 1, - y - 3); - } else { - g2d.drawString(String.valueOf(value), - hintX + 1, - y - 3); - } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-07 14:57:22
|
Revision: 22 http://picross.svn.sourceforge.net/picross/?rev=22&view=rev Author: yvan_norsa Date: 2007-06-07 07:57:23 -0700 (Thu, 07 Jun 2007) Log Message: ----------- pretty graphics Modified Paths: -------------- trunk/applet/index.html trunk/src/picross/PicrossModel.java trunk/src/picross/grid/GridModel.java trunk/src/picross/grid/GridUI.java Modified: trunk/applet/index.html =================================================================== --- trunk/applet/index.html 2007-06-07 11:29:21 UTC (rev 21) +++ trunk/applet/index.html 2007-06-07 14:57:23 UTC (rev 22) @@ -10,7 +10,8 @@ <applet code="picross.applet.PicrossApplet" archive="picross.jar,bundleHelper.jar,log4j.jar,mmvcs.jar" - width="450" - height="375" /> + width="550" + height="400" + cache_option="no" /> </body> </html> Modified: trunk/src/picross/PicrossModel.java =================================================================== --- trunk/src/picross/PicrossModel.java 2007-06-07 11:29:21 UTC (rev 21) +++ trunk/src/picross/PicrossModel.java 2007-06-07 14:57:23 UTC (rev 22) @@ -54,27 +54,182 @@ /** Constructor. */ PicrossModel() { - this.width = 5; - this.height = 5; + this.width = 19; + this.height = 14; this.data = new boolean[this.width][this.height]; + /* + for (int i = 0; i < this.width; i++) { + for (int j = 0; j < this.height; j++) { + this.data[i][j] = true; + } + } + */ + this.data[0][7] = true; + this.data[0][8] = true; + this.data[0][13] = true; - this.data[0][1] = true; - this.data[0][3] = true; - this.data[1][0] = true; - this.data[1][1] = true; - this.data[1][2] = true; - this.data[1][3] = true; - this.data[1][4] = true; - this.data[2][1] = true; - this.data[2][3] = true; - this.data[3][0] = true; - this.data[3][1] = true; - this.data[3][2] = true; - this.data[3][3] = true; - this.data[3][4] = true; - this.data[4][1] = true; - this.data[4][3] = true; + this.data[1][6] = true; + this.data[1][7] = true; + this.data[1][8] = true; + this.data[1][9] = true; + this.data[1][12] = true; + this.data[1][13] = true; + + this.data[2][6] = true; + this.data[2][7] = true; + this.data[2][8] = true; + this.data[2][9] = true; + this.data[2][12] = true; + this.data[2][13] = true; + + this.data[3][5] = true; + this.data[3][6] = true; + this.data[3][8] = true; + this.data[3][9] = true; + this.data[3][10] = true; + this.data[3][11] = true; + this.data[3][12] = true; + this.data[3][13] = true; + + this.data[4][5] = true; + this.data[4][6] = true; + this.data[4][7] = true; + this.data[4][8] = true; + this.data[4][9] = true; + this.data[4][10] = true; + this.data[4][11] = true; + this.data[4][12] = true; + this.data[4][13] = true; + + this.data[5][0] = true; + this.data[5][1] = true; + this.data[5][2] = true; + this.data[5][3] = true; + this.data[5][4] = true; + this.data[5][5] = true; + this.data[5][6] = true; + this.data[5][7] = true; + this.data[5][8] = true; + this.data[5][9] = true; + this.data[5][10] = true; + this.data[5][11] = true; + this.data[5][12] = true; + this.data[5][13] = true; + + this.data[6][0] = true; + this.data[6][1] = true; + this.data[6][2] = true; + this.data[6][3] = true; + this.data[6][4] = true; + this.data[6][5] = true; + this.data[6][6] = true; + this.data[6][7] = true; + this.data[6][8] = true; + this.data[6][9] = true; + this.data[6][10] = true; + this.data[6][11] = true; + this.data[6][12] = true; + this.data[6][13] = true; + + this.data[7][1] = true; + this.data[7][2] = true; + this.data[7][3] = true; + this.data[7][4] = true; + this.data[7][5] = true; + this.data[7][6] = true; + this.data[7][7] = true; + this.data[7][8] = true; + this.data[7][9] = true; + this.data[7][10] = true; + this.data[7][11] = true; + this.data[7][12] = true; + this.data[7][13] = true; + + this.data[8][8] = true; + this.data[8][9] = true; + this.data[8][10] = true; + this.data[8][11] = true; + this.data[8][12] = true; + this.data[8][13] = true; + + this.data[9][7] = true; + this.data[9][8] = true; + this.data[9][9] = true; + this.data[9][10] = true; + this.data[9][11] = true; + this.data[9][12] = true; + this.data[9][13] = true; + + this.data[10][7] = true; + this.data[10][8] = true; + this.data[10][9] = true; + this.data[10][10] = true; + this.data[10][11] = true; + this.data[10][12] = true; + this.data[10][13] = true; + + this.data[11][6] = true; + this.data[11][7] = true; + this.data[11][8] = true; + this.data[11][9] = true; + this.data[11][10] = true; + this.data[11][11] = true; + this.data[11][12] = true; + this.data[11][13] = true; + + this.data[12][6] = true; + this.data[12][7] = true; + this.data[12][8] = true; + this.data[12][9] = true; + this.data[12][10] = true; + this.data[12][11] = true; + this.data[12][12] = true; + this.data[12][13] = true; + + this.data[13][6] = true; + this.data[13][7] = true; + this.data[13][8] = true; + this.data[13][9] = true; + this.data[13][10] = true; + this.data[13][11] = true; + this.data[13][12] = true; + this.data[13][13] = true; + + this.data[14][6] = true; + this.data[14][7] = true; + this.data[14][8] = true; + this.data[14][9] = true; + this.data[14][10] = true; + this.data[14][11] = true; + this.data[14][12] = true; + this.data[14][13] = true; + + this.data[15][7] = true; + this.data[15][8] = true; + this.data[15][9] = true; + this.data[15][10] = true; + this.data[15][11] = true; + this.data[15][12] = true; + this.data[15][13] = true; + + this.data[16][9] = true; + this.data[16][10] = true; + this.data[16][11] = true; + this.data[16][12] = true; + this.data[16][13] = true; + + this.data[17][8] = true; + this.data[17][9] = true; + this.data[17][10] = true; + this.data[17][11] = true; + this.data[17][12] = true; + this.data[17][13] = true; + + this.data[18][9] = true; + this.data[18][10] = true; + this.data[18][11] = true; + this.data[18][12] = true; } /*** Accessors ***/ Modified: trunk/src/picross/grid/GridModel.java =================================================================== --- trunk/src/picross/grid/GridModel.java 2007-06-07 11:29:21 UTC (rev 21) +++ trunk/src/picross/grid/GridModel.java 2007-06-07 14:57:23 UTC (rev 22) @@ -243,7 +243,7 @@ * (while dragging), do nothing */ if (this.lastModified != null - && this.lastModified == this.boxes[row][column]) { + && this.lastModified == this.boxes[column][row]) { return; } @@ -254,53 +254,53 @@ * (if we are in a checks serie and we are on a box which * is already checked), do nothing */ - if (this.boxes[row][column].equals(this.lastModified)) { + if (this.boxes[column][row].equals(this.lastModified)) { return; } } - if (this.boxes[row][column].isEmpty() + if (this.boxes[column][row].isEmpty() && (this.lastModified == null || !this.lastModified.isEmpty())) { if (type == GridController.CHECK_ACTION) { - this.boxes[row][column].check(); + this.boxes[column][row].check(); } else { //if (type == GridController.CROSS_ACTION) { - this.boxes[row][column].cross(); + this.boxes[column][row].cross(); } this.mediator.check(row, column, type); - } else if (!this.boxes[row][column].isEmpty() + } else if (!this.boxes[column][row].isEmpty() && (this.lastModified == null || this.lastModified.isEmpty())) { - if (this.boxes[row][column].isChecked()) { + if (this.boxes[column][row].isChecked()) { //GridModel.log.debug("checked"); if (type == GridController.CHECK_ACTION) { - this.boxes[row][column].empty(); + this.boxes[column][row].empty(); this.mediator.uncheck(row, column, type); } else { //if (type == GridController.CROSS_ACTION) { - this.boxes[row][column].cross(); + this.boxes[column][row].cross(); this.mediator.check(row, column, GridController.CROSS_ACTION); } - } else { //if (this.boxes[row][column].isCrossed()) { + } else { //if (this.boxes[column][row].isCrossed()) { //GridModel.log.debug("crossed"); if (type == GridController.CROSS_ACTION) { - this.boxes[row][column].empty(); + this.boxes[column][row].empty(); this.mediator.uncheck(row, column, type); } else { //GridModel.log.debug("check()"); - this.boxes[row][column].check(); + this.boxes[column][row].check(); this.mediator.check(row, column, GridController.CHECK_ACTION); } } } - this.lastModified = this.boxes[row][column]; + this.lastModified = this.boxes[column][row]; this.checkCompleted(); } Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-07 11:29:21 UTC (rev 21) +++ trunk/src/picross/grid/GridUI.java 2007-06-07 14:57:23 UTC (rev 22) @@ -35,10 +35,17 @@ import java.awt.Color; import java.awt.Dimension; +import java.awt.Font; import java.awt.Graphics; +import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; +import java.awt.RenderingHints; +import java.awt.font.FontRenderContext; + +import java.awt.geom.Rectangle2D; + import javax.swing.JPanel; import org.apache.log4j.Logger; @@ -55,7 +62,7 @@ private static final long serialVersionUID = 2050855523399115878L; /** Space left before the top hints. */ - private static final int TOP_HINTS = 10; + private static final int TOP_HINTS = 10 + 3; /** Width occupied by a row hint. */ private static final int ROW_HINT_WIDTH = 10; @@ -69,6 +76,12 @@ /** Height occupied by a column hint. */ private static final int COL_HINT_HEIGHT = 12; + private static final Color HINT_FORE_COLOR = new Color(188, 211, 227); + private static final Color HINT_FILL_COLOR = new Color(131, 155, 200); + private static final Color HINT_TEXT_COLOR = new Color(233, 246, 255); + + private static final Font HINT_FONT = new Font("Sans Serif", Font.BOLD, 10); + /** A box width. */ private static final int BOX_WIDTH = 25; @@ -127,6 +140,8 @@ /** Controller attached to this view. */ private transient GridController controller; + int hintBoxSize; + /*** Constructor ***/ /** @@ -158,15 +173,51 @@ this.colData = colData; this.rowData = rowData; - this.leftBoundary = - this.rowData[0].length * GridUI.ROW_HINT_WIDTH; + /**/ + //FontRenderContext frc = g2d.getFontRenderContext(); + FontRenderContext frc = new FontRenderContext(null, true, + true); + Rectangle2D textBounds = + GridUI.HINT_FONT + .getStringBounds("42", frc); + + double textWidth = textBounds.getWidth(); + double textHeight = textBounds.getHeight(); + + this.hintBoxSize = (int) (textWidth > textHeight + ? textWidth : textHeight); + //this.bigHintBoxSize = this.hintBoxSize + 3; + this.hintBoxSize += 2; + + /**/ + + + + /* + this.leftBoundary = + this.rowData[0].length * GridUI.ROW_HINT_WIDTH; + */ + + for (int i = 0; i < this.rowData[0].length; i++) { + int size = (this.rowData[0][i] / 10) + 1; + //this.leftBoundary += size * GridUI.ROW_HINT_WIDTH; + this.leftBoundary += size * this.hintBoxSize; + } + + //this.leftBoundary = 70; + + this.leftBoundary += 10; + this.rightBoundary = this.leftBoundary + (this.width * GridUI.BOX_WIDTH); this.topBoundary = GridUI.TOP_HINTS - + (this.colData[0].length * GridUI.COL_HINT_HEIGHT); + //+ (this.colData[0].length * GridUI.COL_HINT_HEIGHT); + + (this.colData[0].length * this.hintBoxSize); + //this.topBoundary = 70; + this.bottomBoundary = this.topBoundary + (this.height * GridUI.BOX_HEIGHT); @@ -180,8 +231,8 @@ this.boxes = new GridBox[this.width][this.height]; - for (int i = 0; i < this.boxes.length; i++) { - for (int j = 0; j < this.boxes[i].length; j++) { + for (int i = 0; i < this.width; i++) { + for (int j = 0; j < this.height; j++) { /* * We compute here the rectangle corresponding to each box * so we'll be able @@ -189,9 +240,9 @@ */ this.boxes[i][j] = new GridBox(new Rectangle(this.leftBoundary + + (i * GridUI.BOX_WIDTH), + this.topBoundary + (j * GridUI.BOX_WIDTH), - this.topBoundary - + (i * GridUI.BOX_WIDTH), GridUI.BOX_WIDTH, GridUI.BOX_HEIGHT)); } @@ -215,8 +266,12 @@ Rectangle clipRect = g.getClipBounds(); if (this.topHintsRect.intersects(clipRect)) { - GridUI.log.debug("top hints"); + Graphics2D g2d = (Graphics2D) g.create(); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + //GridUI.log.debug("top hints"); + int x = 0; int y = GridUI.TOP_HINTS; @@ -225,40 +280,51 @@ for (int j = 0; j < this.colData.length; j++) { if (this.colData[j][i] != GridModel.EMPTY_HINT) { - g.drawString(String.valueOf(this.colData[j][i]), - x, y); + int hintX = x + (((x + GridUI.COL_HINT_WIDTH) - x) / 2); + this.drawColHint(g2d, this.colData[j][i], hintX, y); } x += GridUI.BOX_WIDTH; } - y += GridUI.COL_HINT_HEIGHT; + y += this.hintBoxSize + 2; } + + g2d.dispose(); } if (this.leftHintsRect.intersects(clipRect)) { - GridUI.log.debug("left hints"); + //GridUI.log.debug("left hints"); + Graphics2D g2d = (Graphics2D) g.create(); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + int y = this.topBoundary; for (int i = 0; i < this.rowData.length; i++) { int x = 0; + int hintY = y + GridUI.ROW_HINT_HEIGHT; + for (int j = 0; j < this.rowData[i].length; j++) { if (this.rowData[i][j] != GridModel.EMPTY_HINT) { - g.drawString(String.valueOf(this.rowData[i][j]), - x, y + GridUI.ROW_HINT_HEIGHT); + this.drawRowHint(g2d, this.rowData[i][j], x, hintY); } - x += GridUI.ROW_HINT_WIDTH; + x += this.hintBoxSize + 2; } y += GridUI.BOX_HEIGHT; } + + g2d.dispose(); } - for (int i = 0; i < this.height; i++) { - for (int j = 0; j < this.width; j++) { + for (int i = 0; i < this.width; i++) { + for (int j = 0; j < this.height; j++) { + //GridUI.log.debug("currentRect : " + i + "," + j); + Rectangle currentRect = this.boxes[i][j].getRect(); if (currentRect.intersects(clipRect)) { @@ -277,6 +343,68 @@ /*** Methods ***/ + private void drawColHint(Graphics2D g2d, int value, int hintX, int y) { + g2d.setColor(GridUI.HINT_FILL_COLOR); + + g2d.fillRoundRect(hintX, + y - GridUI.COL_HINT_HEIGHT, + this.hintBoxSize, + this.hintBoxSize, + 8, 8); + + g2d.setColor(GridUI.HINT_FORE_COLOR); + + g2d.drawRoundRect(hintX, + y - GridUI.COL_HINT_HEIGHT, + this.hintBoxSize, + this.hintBoxSize, + 8, 8); + + g2d.setColor(GridUI.HINT_TEXT_COLOR); + g2d.setFont(GridUI.HINT_FONT); + + if (value < 10) { + g2d.drawString(String.valueOf(value), + hintX + (this.hintBoxSize / 3), + y); + } else { + g2d.drawString(String.valueOf(value), + hintX, + y); + } + } + + private void drawRowHint(Graphics2D g2d, int value, int hintX, int y) { + g2d.setColor(GridUI.HINT_FILL_COLOR); + + g2d.fillRoundRect(hintX, + y - GridUI.ROW_HINT_HEIGHT, + this.hintBoxSize, + this.hintBoxSize, + 8, 8); + + g2d.setColor(GridUI.HINT_FORE_COLOR); + + g2d.drawRoundRect(hintX, + y - GridUI.ROW_HINT_HEIGHT, + this.hintBoxSize, + this.hintBoxSize, + 8, 8); + + g2d.setColor(GridUI.HINT_TEXT_COLOR); + g2d.setFont(GridUI.HINT_FONT); + + if (value < 10) { + g2d.drawString(String.valueOf(value), + hintX + (this.hintBoxSize / 3) - 1, + y - 3); + } else { + g2d.drawString(String.valueOf(value), + hintX + 1, + y - 3); + } + } + /** * This methods tells wether a point is inside the grid or not. * @@ -353,16 +481,16 @@ */ private void setBoxState(int row, int column, boolean state, int type) { if (!state) { - this.boxes[row][column].empty(); + this.boxes[column][row].empty(); } else { if (type == GridController.CHECK_ACTION) { - this.boxes[row][column].check(); + this.boxes[column][row].check(); } else { //if (type == GridController.CROSS_ACTION) { - this.boxes[row][column].cross(); + this.boxes[column][row].cross(); } } - this.repaint(this.boxes[row][column].getRect()); + this.repaint(this.boxes[column][row].getRect()); } /** @@ -375,7 +503,7 @@ //GridUI.log.debug("setRollover(" + row + ", " + column + ")"); this.rolloverEnded(); - this.rollover = this.boxes[row][column]; + this.rollover = this.boxes[column][row]; this.repaint(this.rollover.getRect()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-07 11:29:19
|
Revision: 21 http://picross.svn.sourceforge.net/picross/?rev=21&view=rev Author: yvan_norsa Date: 2007-06-07 04:29:21 -0700 (Thu, 07 Jun 2007) Log Message: ----------- classes renaming Modified Paths: -------------- trunk/src/picross/PicrossMediator.java trunk/src/picross/app/PicrossApp.java Added Paths: ----------- trunk/src/picross/app/PicrossAppUI.java trunk/src/picross/grid/GridController.java trunk/src/picross/grid/GridMediator.java trunk/src/picross/grid/GridModel.java trunk/src/picross/grid/GridUI.java Removed Paths: ------------- trunk/src/picross/app/PicrossFrame.java trunk/src/picross/grid/PicrossGridController.java trunk/src/picross/grid/PicrossGridMediator.java trunk/src/picross/grid/PicrossGridModel.java trunk/src/picross/grid/PicrossGridUI.java Modified: trunk/src/picross/PicrossMediator.java =================================================================== --- trunk/src/picross/PicrossMediator.java 2007-06-07 11:18:40 UTC (rev 20) +++ trunk/src/picross/PicrossMediator.java 2007-06-07 11:29:21 UTC (rev 21) @@ -40,8 +40,8 @@ //import org.apache.log4j.Logger; -import picross.grid.PicrossGridController; -import picross.grid.PicrossGridMediator; +import picross.grid.GridController; +import picross.grid.GridMediator; import picross.menus.MainMenuController; import picross.menus.MainMenuMediator; @@ -104,9 +104,9 @@ if (cmd.equals(MainMenuController.PLAY_CMD)) { PicrossModel model = new PicrossModel(); - PicrossGridMediator grid = - new PicrossGridMediator(model.getWidth(), model.getHeight(), - model.getData()); + GridMediator grid = new GridMediator(model.getWidth(), + model.getHeight(), + model.getData()); grid.addSimpleListener(this); this.view.setContent(grid.getView()); @@ -119,7 +119,7 @@ return; } - if (cmd.equals(PicrossGridController.GRID_FILLED_CMD)) { + if (cmd.equals(GridController.GRID_FILLED_CMD)) { this.fireEventPerformed(PicrossController.MESSAGE_CMD, BundleHelper.getString(this, "victory")); return; Modified: trunk/src/picross/app/PicrossApp.java =================================================================== --- trunk/src/picross/app/PicrossApp.java 2007-06-07 11:18:40 UTC (rev 20) +++ trunk/src/picross/app/PicrossApp.java 2007-06-07 11:29:21 UTC (rev 21) @@ -55,7 +55,7 @@ /** Constructor. */ private PicrossApp() { PropertyConfigurator.configure(PicrossApp.LOG4J_CONFIG); - new PicrossMediator(new PicrossFrame()); + new PicrossMediator(new PicrossAppUI()); } /*** Main method ***/ Copied: trunk/src/picross/app/PicrossAppUI.java (from rev 20, trunk/src/picross/app/PicrossFrame.java) =================================================================== --- trunk/src/picross/app/PicrossAppUI.java (rev 0) +++ trunk/src/picross/app/PicrossAppUI.java 2007-06-07 11:29:21 UTC (rev 21) @@ -0,0 +1,95 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.app; + +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JPanel; + +import picross.PicrossUI; + +/** + * Main window of the application version. + * + * @author Y. Norsa + */ +public final class PicrossAppUI extends JFrame implements PicrossUI { + /*** Constants ***/ + + /** Serialisation ID. */ + private static final long serialVersionUID = -6091243469021691734L; + + /** Main menu class. */ + private static final String MAIN_MENU_CLASS = "picross.app.MainMenuAppUI"; + + /*** Constructor ***/ + + /** Constructor. */ + public PicrossAppUI() { + super("Picross"); + + this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + this.setVisible(true); + } + + /*** Methods implanted from the interface PicrossUI ***/ + + /** {@inheritDoc} */ + public void setContent(JPanel content) { + this.setContentPane(content); + this.pack(); + } + + /** {@inheritDoc} */ + public void displayMessage(String msg) { + JOptionPane.showMessageDialog(this, msg); + } + + /** {@inheritDoc} */ + public void displayError(String msg) { + JOptionPane.showMessageDialog(this, msg, + "Picross", JOptionPane.ERROR_MESSAGE); + } + + /** {@inheritDoc} */ + public void exit() { + this.dispose(); + } + + /** {@inheritDoc} */ + public String getMainMenuClass() { + return PicrossAppUI.MAIN_MENU_CLASS; + } +} + Deleted: trunk/src/picross/app/PicrossFrame.java =================================================================== --- trunk/src/picross/app/PicrossFrame.java 2007-06-07 11:18:40 UTC (rev 20) +++ trunk/src/picross/app/PicrossFrame.java 2007-06-07 11:29:21 UTC (rev 21) @@ -1,95 +0,0 @@ -/* - * $Id$ - * - * Copyright (c) 2007 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - */ - - -package picross.app; - -import javax.swing.JFrame; -import javax.swing.JOptionPane; -import javax.swing.JPanel; - -import picross.PicrossUI; - -/** - * Main window of the application version. - * - * @author Y. Norsa - */ -public final class PicrossFrame extends JFrame implements PicrossUI { - /*** Constants ***/ - - /** Serialisation ID. */ - private static final long serialVersionUID = -6091243469021691734L; - - /** Main menu class. */ - private static final String MAIN_MENU_CLASS = "picross.app.MainMenuAppUI"; - - /*** Constructor ***/ - - /** Constructor. */ - public PicrossFrame() { - super("Picross"); - - this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - this.setVisible(true); - } - - /*** Methods implanted from the interface PicrossUI ***/ - - /** {@inheritDoc} */ - public void setContent(JPanel content) { - this.setContentPane(content); - this.pack(); - } - - /** {@inheritDoc} */ - public void displayMessage(String msg) { - JOptionPane.showMessageDialog(this, msg); - } - - /** {@inheritDoc} */ - public void displayError(String msg) { - JOptionPane.showMessageDialog(this, msg, - "Picross", JOptionPane.ERROR_MESSAGE); - } - - /** {@inheritDoc} */ - public void exit() { - this.dispose(); - } - - /** {@inheritDoc} */ - public String getMainMenuClass() { - return PicrossFrame.MAIN_MENU_CLASS; - } -} - Copied: trunk/src/picross/grid/GridController.java (from rev 19, trunk/src/picross/grid/PicrossGridController.java) =================================================================== --- trunk/src/picross/grid/GridController.java (rev 0) +++ trunk/src/picross/grid/GridController.java 2007-06-07 11:29:21 UTC (rev 21) @@ -0,0 +1,229 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +import fr.cle.mmvcs.Controller; +import fr.cle.mmvcs.SimpleEvent; + +import java.awt.Point; + +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; + +//import org.apache.log4j.Logger; + +/** + * Grid controller. + * + * @author Y. Norsa + */ +public final class GridController extends Controller + implements MouseListener, MouseMotionListener { + + /*** Constants ***/ + + /** Fill command. */ + static final String FILL_CMD = "FILL_CMD"; + + /** Command indicating the grid is filled. */ + public static final String GRID_FILLED_CMD = "GRID_FILLED_CMD"; + + /** Command indicating the action has reached its end. */ + static final String END_ACTION_CMD = "END_ACTION_CMD"; + + /** Command to check a box. */ + static final String CHECK_CMD = "CHECK_CMD"; + + /** Command to uncheck a box. */ + static final String UNCHECK_CMD = "UNCHECK_CMD"; + + /** Checking a box. */ + static final int CHECK_ACTION = 0; + + /** Crossing a box. */ + static final int CROSS_ACTION = 1; + + /*** Static field ***/ + + /** The class' logger. */ + //private static Logger log = Logger.getLogger(GridController.class); + + /*** Field ***/ + + /** The view to which the controller is attached. */ + private GridUI view = null; + + /*** Method overloaded from the class Controller ***/ + + /** {@inheritDoc} */ + public void eventPerformed(SimpleEvent e) { + //GridController.log.debug("eventPerformed(" + e + ")"); + + String cmd = e.getCommandName(); + + if (cmd.equals(GridController.GRID_FILLED_CMD)) { + this.view.disableGrid(); + return; + } + + if (cmd.equals(GridController.CHECK_CMD)) { + FillCommand command = (FillCommand) e.getCommand(); + this.view.check(command.getRow(), command.getColumn(), + command.getType()); + + return; + } + + if (cmd.equals(GridController.UNCHECK_CMD)) { + FillCommand command = (FillCommand) e.getCommand(); + this.view.uncheck(command.getRow(), command.getColumn(), + command.getType()); + + return; + } + } + + /*** Methods implanted from the interface MouseListener ***/ + + /** {@inheritDoc} */ + public void mouseClicked(MouseEvent e) { } + + /** {@inheritDoc} */ + public void mouseEntered(MouseEvent e) { } + + /** {@inheritDoc} */ + public void mouseExited(MouseEvent e) { } + + /** {@inheritDoc} */ + public void mousePressed(MouseEvent e) { + this.view.rolloverEnded(); + } + + /** {@inheritDoc} */ + public void mouseReleased(MouseEvent e) { + //GridController.log.debug("mouseReleased()"); + this.checkAndFill(e); + this.fireEventPerformed(GridController.END_ACTION_CMD); + } + + /*** Methods implanted from the interface MouseMotionListener ***/ + + /** {@inheritDoc} */ + public void mouseDragged(MouseEvent e) { + this.checkAndFill(e); + } + + /** {@inheritDoc} */ + public void mouseMoved(MouseEvent e) { + //GridController.log.debug(e.getPoint()); + + Point point = e.getPoint(); + + if (this.view.isInGrid(point)) { + int row = this.view.getRow(point); + int column = this.view.getColumn(point); + + this.view.setRollover(row, column); + } else { + this.view.rolloverEnded(); + } + + } + + /*** Methods ***/ + + /** + * Checks if the mouse current click's location is inside the grid + * and eventually fills the corresponding box. + * + * @param e mouse event to handle + */ + private void checkAndFill(MouseEvent e) { + //GridController.log.debug(e); + + int modifiers = e.getModifiers(); + + if (modifiers != MouseEvent.BUTTON1_MASK + && modifiers != MouseEvent.BUTTON3_MASK) { + + return; + } + + Point point = e.getPoint(); + + if (this.view.isInGrid(point)) { + int row = this.view.getRow(point); + int column = this.view.getColumn(point); + int type = GridController.modifiersToType(modifiers); + + //GridController.log.debug("type : " + type); + + this.fireEventPerformed(GridController.FILL_CMD, + new FillCommand(row, column, type)); + + } + } + + /** + * Converts a mouse click to an action. + * + * @param modifiers mouse event modifiers + * @return corresponding action, or -1 + */ + private static int modifiersToType(int modifiers) { + switch (modifiers) { + case MouseEvent.BUTTON1_MASK: + return GridController.CHECK_ACTION; + + case MouseEvent.BUTTON3_MASK: + return GridController.CROSS_ACTION; + + default: + return -1; + } + } + + /*** Accessor ***/ + + /** + * Allows to set the view. + * + * @param view view to which this controller is attached + */ + void setView(GridUI view) { + this.view = view; + } +} + Added: trunk/src/picross/grid/GridMediator.java =================================================================== --- trunk/src/picross/grid/GridMediator.java (rev 0) +++ trunk/src/picross/grid/GridMediator.java 2007-06-07 11:29:21 UTC (rev 21) @@ -0,0 +1,148 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +import fr.cle.mmvcs.Mediateur; +import fr.cle.mmvcs.SimpleEvent; + +import javax.swing.JPanel; + +//import org.apache.log4j.Logger; + +/** + * Picross grid mediator. + * + * @author Y. Norsa + */ +public final class GridMediator extends Mediateur { + /*** Static field ***/ + + /** Class' logger. */ + //private static Logger log = Logger.getLogger(GridMediator.class); + + /*** Fields ***/ + + /** The grid model. */ + private GridModel model; + + /** The grid view. */ + private GridUI view; + + /*** Constructor ***/ + + /** + * Constructor. + * + * @param width grid width + * @param height grid height + * @param data grid content + */ + public GridMediator(int width, int height, boolean[][] data) { + this.model = new GridModel(this, data); + + GridController controller = new GridController(); + controller.addSimpleListener(this); + this.addSimpleListener(controller); + + this.view = new GridUI(width, height, + this.model.getColData(), + this.model.getRowData(), + controller); + + controller.setView(this.view); + } + + /*** Method overloaded from the class Mediateur ***/ + + /** {@inheritDoc} */ + public void eventPerformed(SimpleEvent e) { + //GridMediator.log.debug("eventPerformed(" + e + ")"); + + String cmd = e.getCommandName(); + + if (cmd.equals(GridController.FILL_CMD)) { + FillCommand command = (FillCommand) e.getCommand(); + this.model.checkBox(command.getRow(), command.getColumn(), + command.getType()); + + return; + } + + if (cmd.equals(GridController.END_ACTION_CMD)) { + this.model.endAction(); + return; + } + } + + /*** Methods ***/ + + /** Tells the application mediator the grid has been filled. */ + void congratulations() { + this.fireEventPerformed(GridController.GRID_FILLED_CMD); + } + + /** + * Checks a box. + * + * @param row row of the box + * @param column column of the box + */ + void check(int row, int column, int type) { + this.fireEventPerformed(GridController.CHECK_CMD, + new FillCommand(row, column, type)); + } + + /** + * Unchecks a box. + * + * @param row row of the box + * @param column column of the box + */ + void uncheck(int row, int column, int type) { + this.fireEventPerformed(GridController.UNCHECK_CMD, + new FillCommand(row, column, type)); + } + + /*** Accessor ***/ + + /** + * Returns the view. + * + * @return the grid view + */ + public JPanel getView() { + return this.view; + } +} + Property changes on: trunk/src/picross/grid/GridMediator.java ___________________________________________________________________ Name: svn:keywords + Id Copied: trunk/src/picross/grid/GridModel.java (from rev 19, trunk/src/picross/grid/PicrossGridModel.java) =================================================================== --- trunk/src/picross/grid/GridModel.java (rev 0) +++ trunk/src/picross/grid/GridModel.java 2007-06-07 11:29:21 UTC (rev 21) @@ -0,0 +1,355 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +import java.util.ArrayList; +import java.util.List; + +//import org.apache.log4j.Logger; + +/** + * The grid model. + * + * @author Y. Norsa + */ +final class GridModel { + /*** Constant ***/ + + /** Empty hint value. */ + static final int EMPTY_HINT = -1; + + /*** Static field ***/ + + /** The class' logger. */ + //private static Logger log = Logger.getLogger(GridModel.class); + + /*** Fields ***/ + + /** This model's mediator. */ + private GridMediator mediator; + + /** The original grid. */ + private boolean[][] data; + + /** The grid as filled by the user. */ + private Box[][] boxes; + + /** + * The last modified box. Permis to know if we are in a serie or + * a single action. + */ + private Box lastModified = null; + + /** Columns hints. */ + private int[][] colData; + + /** Rows hints. */ + private int[][] rowData; + + /*** Constructor ***/ + + /** + * Constructor. + * + * @param mediator this model's mediator + * @param data grid content + */ + GridModel(GridMediator mediator, boolean[][] data) { + this.mediator = mediator; + + this.data = data; + this.boxes = new Box[this.data.length][this.data[0].length]; + + for (int i = 0; i < this.boxes.length; i++) { + for (int j = 0; j < this.boxes[i].length; j++) { + this.boxes[i][j] = new Box(); + } + } + + // Grid of columns hints + List<List<Integer>> colHints = new ArrayList<List<Integer>>(); + + // Largest number of hints for a column + int max = 0; + + for (boolean[] col : data) { + List<Integer> current = new ArrayList<Integer>(); + + // Current hint + int chain = 0; + + for (boolean cell : col) { + if (cell) { + chain++; + } else if (chain > 0) { + // We've reached the end of a series of checked boxes + current.add(chain); + chain = 0; + } + } + + if (chain > 0) { + current.add(chain); + } else if (current.size() == 0) { + // If this column is empty, we add a "0" hint + current.add(0); + } + + int currentSize = current.size(); + + if (currentSize > max) { + max = currentSize; + } + + colHints.add(current); + } + + /* + * Final array containing the hints, in the following form : + * + * 1 + * 0 2 1 + * + * Which corresponds to the following grid : + * + * |-----| + * |_|X|_| + * |_|_|X| + * |_|X|_| + * |_|X|_| + * |-----| + */ + this.colData = new int[data.length][max]; + + for (int i = 0; i < max; i++) { + // Minimal number of hints for the current column to be considered + int ref = max - i; + + // Current hint row + int currentRow = ref - 1; + + for (int j = 0; j < colHints.size(); j++) { + List<Integer> currentCol = colHints.get(j); + int size = currentCol.size(); + + if (size >= ref) { + this.colData[j][currentRow] = currentCol.get(size - ref); + } else { + this.colData[j][currentRow] = GridModel.EMPTY_HINT; + } + } + } + + // Same operations as for the columns, basically + + List<List<Integer>> rowHints = new ArrayList<List<Integer>>(); + max = 0; + + for (int i = 0; i < data[0].length; i++) { + List<Integer> current = new ArrayList<Integer>(); + + int chain = 0; + + for (int j = 0; j < data.length; j++) { + if (data[j][i]) { + chain++; + } else if (chain > 0) { + current.add(chain); + chain = 0; + } + } + + if (chain > 0) { + current.add(chain); + } else if (current.size() == 0) { + current.add(0); + } + + int currentSize = current.size(); + + if (currentSize > max) { + max = currentSize; + } + + rowHints.add(current); + } + + this.rowData = new int[data[0].length][max]; + int nbRows = rowHints.size(); + + for (int i = 0; i < max; i++) { + int ref = max - i; + + for (int j = 0; j < nbRows; j++) { + List<Integer> currentRow = rowHints.get(j); + int size = currentRow.size(); + + if (size >= ref) { + this.rowData[j][i] = + currentRow.get(i - Math.abs(size - max)); + } else { + this.rowData[j][i] = GridModel.EMPTY_HINT; + } + } + } + } + + /*** Methods ***/ + + /** + * Method called during an action. + * + * @param row row of the box + * @param column column of the box + */ + void checkBox(int row, int column, int type) { + //GridModel.log.debug("checkBox(" + row + ", " + column + ")"); + //GridModel.log.debug("lastModified == null : " + // + (lastModified == null)); + + /* + * If we are trying to check the last box we just checked + * (while dragging), do nothing + */ + if (this.lastModified != null + && this.lastModified == this.boxes[row][column]) { + + return; + } + + if (this.lastModified != null) { + /* + * If we are in a box which is in the same state as our aim + * (if we are in a checks serie and we are on a box which + * is already checked), do nothing + */ + if (this.boxes[row][column].equals(this.lastModified)) { + return; + } + } + + if (this.boxes[row][column].isEmpty() + && (this.lastModified == null || !this.lastModified.isEmpty())) { + + if (type == GridController.CHECK_ACTION) { + this.boxes[row][column].check(); + } else { //if (type == GridController.CROSS_ACTION) { + this.boxes[row][column].cross(); + } + + this.mediator.check(row, column, type); + } else if (!this.boxes[row][column].isEmpty() + && (this.lastModified == null + || this.lastModified.isEmpty())) { + + if (this.boxes[row][column].isChecked()) { + //GridModel.log.debug("checked"); + + if (type == GridController.CHECK_ACTION) { + this.boxes[row][column].empty(); + this.mediator.uncheck(row, column, type); + } else { //if (type == GridController.CROSS_ACTION) { + this.boxes[row][column].cross(); + this.mediator.check(row, column, + GridController.CROSS_ACTION); + } + } else { //if (this.boxes[row][column].isCrossed()) { + //GridModel.log.debug("crossed"); + + if (type == GridController.CROSS_ACTION) { + this.boxes[row][column].empty(); + this.mediator.uncheck(row, column, type); + } else { + //GridModel.log.debug("check()"); + + this.boxes[row][column].check(); + this.mediator.check(row, column, + GridController.CHECK_ACTION); + } + } + } + + this.lastModified = this.boxes[row][column]; + this.checkCompleted(); + } + + /** Checks wether the grid is finished. */ + private void checkCompleted() { + boolean completed = true; + + for (int i = 0; i < this.data.length; i++) { + for (int j = 0; j < this.data[i].length; j++) { + boolean isCurrentBoxChecked = this.boxes[i][j].isChecked(); + + if ((this.data[i][j] && !isCurrentBoxChecked) + || (!this.data[i][j] && isCurrentBoxChecked)) { + + completed = false; + break; + } + } + } + + if (completed) { + this.mediator.congratulations(); + } + } + + /** Indicates the current action has come to an end. */ + void endAction() { + //this.lastChecked = null; + this.lastModified = null; + } + + /*** Accessors ***/ + + /** + * Returns the vertical hints. + * + * @return columns hints + */ + int[][] getColData() { + return this.colData; + } + + /** + * Returns the horizontal hints. + * + * @return rows hints + */ + int[][] getRowData() { + return this.rowData; + } +} + Copied: trunk/src/picross/grid/GridUI.java (from rev 19, trunk/src/picross/grid/PicrossGridUI.java) =================================================================== --- trunk/src/picross/grid/GridUI.java (rev 0) +++ trunk/src/picross/grid/GridUI.java 2007-06-07 11:29:21 UTC (rev 21) @@ -0,0 +1,396 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Point; +import java.awt.Rectangle; + +import javax.swing.JPanel; + +import org.apache.log4j.Logger; + +/** + * Grid UI. + * + * @author Y. Norsa + */ +final class GridUI extends JPanel { + /*** Constants ***/ + + /** Serialisation ID. */ + private static final long serialVersionUID = 2050855523399115878L; + + /** Space left before the top hints. */ + private static final int TOP_HINTS = 10; + + /** Width occupied by a row hint. */ + private static final int ROW_HINT_WIDTH = 10; + + /** Height occupied by a row hint. */ + private static final int ROW_HINT_HEIGHT = 15; + + /** Width occupied by a column hint. */ + private static final int COL_HINT_WIDTH = 5; + + /** Height occupied by a column hint. */ + private static final int COL_HINT_HEIGHT = 12; + + /** A box width. */ + private static final int BOX_WIDTH = 25; + + /** A box height. */ + private static final int BOX_HEIGHT = 25; + + /** Extra space at the right end of the grid. */ + private static final int RIGHT_SPACE = 5; + + /** Extra space at the bottom of the grid. */ + private static final int BOTTOM_SPACE = 5; + + /*** Static field ***/ + + /** Class' logger. */ + private static Logger log = Logger.getLogger(GridUI.class); + + /*** Fields ***/ + + /** Grid width. */ + private int width; + + /** Grid height. */ + private int height; + + /** Columns hints. */ + private int[][] colData; + + /** Rows hints. */ + private int[][] rowData; + + /** Amount of space left before the grid. */ + private int leftBoundary; + + /** Position of the right end of the grid. */ + private int rightBoundary; + + /** Amount of space left before the grid. */ + private int topBoundary; + + /** Position of the bottom end of the grid. */ + private int bottomBoundary; + + /** Rectangle occupied by the top hints. */ + private Rectangle topHintsRect; + + /** Rectangle occupied by the left hints. */ + private Rectangle leftHintsRect; + + /** Current state of the grid. */ + private GridBox[][] boxes; + + /** Current rolled-over box. */ + private transient GridBox rollover; + + /** Controller attached to this view. */ + private transient GridController controller; + + /*** Constructor ***/ + + /** + * Constructor. + * + * @param width grid width + * @param height grid height + * @param colData columns hints + * @param rowData rows hints + * @param controller controller for the grid + */ + GridUI(int width, int height, + int[][] colData, + int[][] rowData, + GridController controller) { + super(true); + + this.controller = controller; + + this.addMouseListener(this.controller); + this.addMouseMotionListener(this.controller); + + this.setOpaque(true); + this.setBackground(Color.WHITE); + + this.width = width; + this.height = height; + + this.colData = colData; + this.rowData = rowData; + + this.leftBoundary = + this.rowData[0].length * GridUI.ROW_HINT_WIDTH; + + this.rightBoundary = this.leftBoundary + + (this.width * GridUI.BOX_WIDTH); + + this.topBoundary = GridUI.TOP_HINTS + + (this.colData[0].length * GridUI.COL_HINT_HEIGHT); + + this.bottomBoundary = this.topBoundary + + (this.height * GridUI.BOX_HEIGHT); + + this.topHintsRect = new Rectangle(this.leftBoundary, 0, + this.width * GridUI.BOX_WIDTH, + this.topBoundary); + this.leftHintsRect = new Rectangle(0, this.topBoundary, + this.leftBoundary, + this.height + * GridUI.BOX_HEIGHT); + + this.boxes = new GridBox[this.width][this.height]; + + for (int i = 0; i < this.boxes.length; i++) { + for (int j = 0; j < this.boxes[i].length; j++) { + /* + * We compute here the rectangle corresponding to each box + * so we'll be able + * to redraw only what is needed + */ + this.boxes[i][j] = + new GridBox(new Rectangle(this.leftBoundary + + (j * GridUI.BOX_WIDTH), + this.topBoundary + + (i * GridUI.BOX_WIDTH), + GridUI.BOX_WIDTH, + GridUI.BOX_HEIGHT)); + } + } + + //GridUI.log.debug("rightBoundary : " + this.rightBoundary); + //GridUI.log.debug("bottomBoundary : " + this.bottomBoundary); + + this.setPreferredSize(new Dimension(this.rightBoundary + + GridUI.RIGHT_SPACE, + this.bottomBoundary + + GridUI.BOTTOM_SPACE)); + } + + /*** Method overloaded from JPanel ***/ + + /** {@inheritDoc} */ + protected void paintComponent(Graphics g) { + super.paintComponent(g); + + Rectangle clipRect = g.getClipBounds(); + + if (this.topHintsRect.intersects(clipRect)) { + GridUI.log.debug("top hints"); + + int x = 0; + int y = GridUI.TOP_HINTS; + + for (int i = this.colData[0].length - 1; i >= 0; i--) { + x = this.leftBoundary + GridUI.COL_HINT_WIDTH; + + for (int j = 0; j < this.colData.length; j++) { + if (this.colData[j][i] != GridModel.EMPTY_HINT) { + g.drawString(String.valueOf(this.colData[j][i]), + x, y); + } + + x += GridUI.BOX_WIDTH; + } + + y += GridUI.COL_HINT_HEIGHT; + } + } + + if (this.leftHintsRect.intersects(clipRect)) { + GridUI.log.debug("left hints"); + + int y = this.topBoundary; + + for (int i = 0; i < this.rowData.length; i++) { + int x = 0; + + for (int j = 0; j < this.rowData[i].length; j++) { + if (this.rowData[i][j] != GridModel.EMPTY_HINT) { + g.drawString(String.valueOf(this.rowData[i][j]), + x, y + GridUI.ROW_HINT_HEIGHT); + } + + x += GridUI.ROW_HINT_WIDTH; + } + + y += GridUI.BOX_HEIGHT; + } + } + + for (int i = 0; i < this.height; i++) { + for (int j = 0; j < this.width; j++) { + Rectangle currentRect = this.boxes[i][j].getRect(); + + if (currentRect.intersects(clipRect)) { + if (this.boxes[i][j] == this.rollover) { + this.boxes[i][j].getRolloverIcon() + .paintIcon(this, g, currentRect.x, currentRect.y); + } else { + this.boxes[i][j].getIcon().paintIcon(this, g, + currentRect.x, + currentRect.y); + } + } + } + } + } + + /*** Methods ***/ + + /** + * This methods tells wether a point is inside the grid or not. + * + * @param point point to be tested + * @return boolean telling if the point is inside the grid + */ + boolean isInGrid(Point point) { + //GridUI.log.debug("isInGrid(" + point + ")"); + + double x = point.getX(); + double y = point.getY(); + + return (x >= this.leftBoundary && x < this.rightBoundary + && y >= this.topBoundary && y < this.bottomBoundary); + } + + /** + * Allows to get the row number corresponding to a point inside the grid. + * + * @param point a point inside the grid + * @return the row corresponding to the point + */ + int getRow(Point point) { + double y = point.getY() - this.topBoundary; + + return (int) (y / GridUI.BOX_HEIGHT); + } + + /** + * Allows to get the column number corresponding to a point + * inside the grid. + * + * @param point a point inside the grid + * @return the column corresponding to the point + */ + int getColumn(Point point) { + double x = point.getX() - this.leftBoundary; + + return (int) (x / GridUI.BOX_WIDTH); + } + + /** Removes the listeners to disable the grid. */ + void disableGrid() { + this.removeMouseListener(this.controller); + this.removeMouseMotionListener(this.controller); + } + + /** + * Checks a row. + * + * @param row row of the box + * @param column column of the box + */ + void check(int row, int column, int type) { + this.setBoxState(row, column, true, type); + } + + /** + * Unchecks a row. + * + * @param row row of the box + * @param column column of the box + */ + void uncheck(int row, int column, int type) { + this.setBoxState(row, column, false, type); + } + + /** + * Modifies a box and repaints the grid. + * + * @param row row of the box + * @param column column of the box + * @param state new state of the box + */ + private void setBoxState(int row, int column, boolean state, int type) { + if (!state) { + this.boxes[row][column].empty(); + } else { + if (type == GridController.CHECK_ACTION) { + this.boxes[row][column].check(); + } else { //if (type == GridController.CROSS_ACTION) { + this.boxes[row][column].cross(); + } + } + + this.repaint(this.boxes[row][column].getRect()); + } + + /** + * Allows to set the current rolled-over box. + * + * @param row row of the box + * @param column column of the box + */ + void setRollover(int row, int column) { + //GridUI.log.debug("setRollover(" + row + ", " + column + ")"); + + this.rolloverEnded(); + this.rollover = this.boxes[row][column]; + this.repaint(this.rollover.getRect()); + } + + /** Indicates that no box is currently rolled over. */ + void rolloverEnded() { + if (this.rollover != null) { + /* + * Save the old rolled-over box so we can draw it + * in its initial state + */ + Rectangle rect = this.rollover.getRect(); + + this.rollover = null; + this.repaint(rect); + } + } +} + Deleted: trunk/src/picross/grid/PicrossGridController.java =================================================================== --- trunk/src/picross/grid/PicrossGridController.java 2007-06-07 11:18:40 UTC (rev 20) +++ trunk/src/picross/grid/PicrossGridController.java 2007-06-07 11:29:21 UTC (rev 21) @@ -1,229 +0,0 @@ -/* - * $Id$ - * - * Copyright (c) 2007 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - */ - - -package picross.grid; - -import fr.cle.mmvcs.Controller; -import fr.cle.mmvcs.SimpleEvent; - -import java.awt.Point; - -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; - -//import org.apache.log4j.Logger; - -/** - * Grid controller. - * - * @author Y. Norsa - */ -public final class PicrossGridController extends Controller - implements MouseListener, MouseMotionListener { - - /*** Constants ***/ - - /** Fill command. */ - static final String FILL_CMD = "FILL_CMD"; - - /** Command indicating the grid is filled. */ - public static final String GRID_FILLED_CMD = "GRID_FILLED_CMD"; - - /** Command indicating the action has reached its end. */ - static final String END_ACTION_CMD = "END_ACTION_CMD"; - - /** Command to check a box. */ - static final String CHECK_CMD = "CHECK_CMD"; - - /** Command to uncheck a box. */ - static final String UNCHECK_CMD = "UNCHECK_CMD"; - - /** Checking a box. */ - static final int CHECK_ACTION = 0; - - /** Crossing a box. */ - static final int CROSS_ACTION = 1; - - /*** Static field ***/ - - /** The class' logger. */ - //private static Logger log = Logger.getLogger(PicrossGridController.class); - - /*** Field ***/ - - /** The view to which the controller is attached. */ - private PicrossGridUI view = null; - - /*** Method overloaded from the class Controller ***/ - - /** {@inheritDoc} */ - public void eventPerformed(SimpleEvent e) { - //PicrossGridController.log.debug("eventPerformed(" + e + ")"); - - String cmd = e.getCommandName(); - - if (cmd.equals(PicrossGridController.GRID_FILLED_CMD)) { - this.view.disableGrid(); - return; - } - - if (cmd.equals(PicrossGridController.CHECK_CMD)) { - FillCommand command = (FillCommand) e.getCommand(); - this.view.check(command.getRow(), command.getColumn(), - command.getType()); - - return; - } - - if (cmd.equals(PicrossGridController.UNCHECK_CMD)) { - FillCommand command = (FillCommand) e.getCommand(); - this.view.uncheck(command.getRow(), command.getColumn(), - command.getType()); - - return; - } - } - - /*** Methods implanted from the interface MouseListener ***/ - - /** {@inheritDoc} */ - public void mouseClicked(MouseEvent e) { } - - /** {@inheritDoc} */ - public void mouseEntered(MouseEvent e) { } - - /** {@inheritDoc} */ - public void mouseExited(MouseEvent e) { } - - /** {@inheritDoc} */ - public void mousePressed(MouseEvent e) { - this.view.rolloverEnded(); - } - - /** {@inheritDoc} */ - public void mouseReleased(MouseEvent e) { - //PicrossGridController.log.debug("mouseReleased()"); - this.checkAndFill(e); - this.fireEventPerformed(PicrossGridController.END_ACTION_CMD); - } - - /*** Methods implanted from the interface MouseMotionListener ***/ - - /** {@inheritDoc} */ - public void mouseDragged(MouseEvent e) { - this.checkAndFill(e); - } - - /** {@inheritDoc} */ - public void mouseMoved(MouseEvent e) { - //PicrossGridController.log.debug(e.getPoint()); - - Point point = e.getPoint(); - - if (this.view.isInGrid(point)) { - int row = this.view.getRow(point); - int column = this.view.getColumn(point); - - this.view.setRollover(row, column); - } else { - this.view.rolloverEnded(); - } - - } - - /*** Methods ***/ - - /** - * Checks if the mouse current click's location is inside the grid - * and eventually fills the corresponding box. - * - * @param e mouse event to handle - */ - private void checkAndFill(MouseEvent e) { - //PicrossGridController.log.debug(e); - - int modifiers = e.getModifiers(); - - if (modifiers != MouseEvent.BUTTON1_MASK - && modifiers != MouseEvent.BUTTON3_MASK) { - - return; - } - - Point point = e.getPoint(); - - if (this.view.isInGrid(point)) { - int row = this.view.getRow(point); - int column = this.view.getColumn(point); - int type = PicrossGridController.modifiersToType(modifiers); - - //PicrossGridController.log.debug("type : " + type); - - this.fireEventPerformed(PicrossGridController.FILL_CMD, - new FillCommand(row, column, type)); - - } - } - - /** - * Converts a mouse click to an action. - * - * @param modifiers mouse event modifiers - * @return corresponding action, or -1 - */ - private static int modifiersToType(int modifiers) { - switch (modifiers) { - case MouseEvent.BUTTON1_MASK: - return PicrossGridController.CHECK_ACTION; - - case MouseEvent.BUTTON3_MASK: - return PicrossGridController.CROSS_ACTION; - - default: - return -1; - } - } - - /*** Accessor ***/ - - /** - * Allows to set the view. - * - * @param view view to which this controller is attached - */ - void setView(PicrossGridUI view) { - this.view = view; - } -} - Deleted: trunk/src/picross/grid/PicrossGridMediator.java =================================================================== --- trunk/src/picross/grid/PicrossGridMediator.java 2007-06-07 11:18:40 UTC (rev 20) +++ trunk/src/picross/grid/PicrossGridMediator.java 2007-06-07 11:29:21 UTC (rev 21) @@ -1,148 +0,0 @@ -/* - * $Id$ - * - * Copyright (c) 2007 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - */ - - -package picross.grid; - -import fr.cle.mmvcs.Mediateur; -import fr.cle.mmvcs.SimpleEvent; - -import javax.swing.JPanel; - -//import org.apache.log4j.Logger; - -/** - * Picross grid mediator. - * - * @author Y. Norsa - */ -public final class PicrossGridMediator extends Mediateur { - /*** Static field ***/ - - /** Class' logger. */ - //private static Logger log = Logger.getLogger(PicrossGridMediator.class); - - /*** Fields ***/ - - /** The grid model. */ - private PicrossGridModel model; - - /** The grid view. */ - private PicrossGridUI view; - - /*** Constructor ***/ - - /** - * Constructor. - * - * @param width grid width - * @param height grid height - * @param data grid content - */ - public PicrossGridMediator(int width, int height, boolean[][] data) { - this.model = new PicrossGridModel(this, data); - - PicrossGridController controller = new PicrossGridController(); - controller.addSimpleListener(this); - this.addSimpleListener(controller); - - this.view = new PicrossGridUI(width, height, - this.model.getColData(), - this.model.getRowData(), - controller); - - controller.setView(this.view); - } - - /*** Method overloaded from the class Mediateur ***/ - - /** {@inheritDoc} */ - public void eventPerformed(SimpleEvent e) { - //PicrossGridMediator.log.debug("eventPerformed(" + e + ")"); - - String cmd = e.getCommandName(); - - if (cmd.equals(PicrossGridController.FILL_CMD)) { - FillCommand command = (FillCommand) e.getCommand(); - this.model.checkBox(command.getRow(), command.getColumn(), - command.getType()); - - return; - } - - if (cmd.equals(PicrossGridController.END_ACTION_CMD)) { - this.model.endAction(); - return; - } - } - - /*** Methods ***/ - - /** Tells the application mediator the grid has been filled. */ - void congratulations() { - this.fireEventPerformed(PicrossGridController.GRID_FILLED_CMD); - } - - /** - * Checks a box. - * - * @param row row of the box - * @param column column of the box - */ - void check(int row, int column, int type) { - this.fireEventPerformed(PicrossGridController.CHECK_CMD, - new FillCommand(row, column, type)); - } - - /** - * Unchecks a box. - * - * @param row row of the box - * @param column column of the box - */ - void uncheck(int row, int column, int type) { - this.fireEventPerformed(PicrossGridController.UNCHECK_CMD, - new FillCommand(row, column, type)); - } - - /*** Accessor ***/ - - /** - * Returns the view. - * - * @return the grid view - */ - public JPanel getView() { - return this.view; - } -} - Deleted: trunk/src/picross/grid/PicrossGridModel.java =================================================================== --- trunk/src/picross/grid/PicrossGridModel.java 2007-06-07 11:18:40 UTC (rev 20) +++ trunk/src/picross/grid/PicrossGridModel.java 2007-06-07 11:29:21 UTC (rev 21) @@ -1,355 +0,0 @@ -/* - * $Id$ - * - * Copyright (c) 2007 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - */ - - -package picross.grid; - -import java.util.ArrayList; -import java.util.List; - -//import org.apache.log4j.Logger; - -/** - * The grid model. - * - * @author Y. Norsa - */ -final class PicrossGridModel { - /*** Constant ***/ - - /** Empty hint value. */ - static final int EMPTY_HINT = -1; - - /*** Static field ***/ - - /** The class' logger. */ - //private static Logger log = Logger.getLogger(PicrossGridModel.class); - - /*** Fields ***/ - - /** This model's mediator. */ - private PicrossGridMediator mediator; - - /** The original grid. */ - private boolean[][] data; - - /** The grid as filled by the user. */ - private Box[][] boxes; - - /** - * The last modified box. Permis to know if we are in a serie or - * a single action. - */ - private Box lastModified = null; - - /** Columns hints. */ - private int[][] colData; - - /** Rows hints. */ - private int[][] rowData; - - /*** Constructor ***/ - - /** - * Constructor. - * - * @param mediator this model's mediator - * @param data gr... [truncated message content] |
From: <yva...@us...> - 2007-06-07 11:18:40
|
Revision: 20 http://picross.svn.sourceforge.net/picross/?rev=20&view=rev Author: yvan_norsa Date: 2007-06-07 04:18:40 -0700 (Thu, 07 Jun 2007) Log Message: ----------- applet version Modified Paths: -------------- trunk/build.xml trunk/src/picross/Picross.java trunk/src/picross/PicrossController.java trunk/src/picross/PicrossMediator.java trunk/src/picross/PicrossUI.java trunk/src/picross/grid/GridBox.java trunk/src/picross/menus/MainMenuController.java trunk/src/picross/menus/MainMenuMediator.java trunk/src/picross/menus/MainMenuUI.java Added Paths: ----------- trunk/applet/ trunk/applet/index.html trunk/images/crossed-rollover.png trunk/src/picross/PicrossException.java trunk/src/picross/app/ trunk/src/picross/app/MainMenuAppUI.java trunk/src/picross/app/PicrossApp.java trunk/src/picross/app/PicrossFrame.java trunk/src/picross/app/package.html trunk/src/picross/applet/ trunk/src/picross/applet/MainMenuAppletUI.java trunk/src/picross/applet/PicrossApplet.java trunk/src/picross/applet/package.html Added: trunk/applet/index.html =================================================================== --- trunk/applet/index.html (rev 0) +++ trunk/applet/index.html 2007-06-07 11:18:40 UTC (rev 20) @@ -0,0 +1,16 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> + <head> + <title>Picross</title> + <meta name="author" content="Yvan Norsa"> + </head> + + <body> + <h1>Picross</h1> + + <applet code="picross.applet.PicrossApplet" + archive="picross.jar,bundleHelper.jar,log4j.jar,mmvcs.jar" + width="450" + height="375" /> + </body> +</html> Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2007-06-07 04:22:39 UTC (rev 19) +++ trunk/build.xml 2007-06-07 11:18:40 UTC (rev 20) @@ -2,14 +2,19 @@ encoding="ISO-8859-1"?> <project name="picross" - default="run"> + default="dist"> <property name="build.dir" value="build" /> + <property name="dist.dir" + value="dist" /> <property name="lib.dir" value="lib" /> <property name="src.dir" value="src" /> + <property name="jar.name" + value="${dist.dir}/${ant.project.name}.jar" /> + <property name="bundleHelper.jar" value="${lib.dir}/bundleHelper.jar" /> <property name="mmvcs.jar" @@ -20,6 +25,7 @@ <target name="-init" depends="-setmode"> <mkdir dir="${build.dir}" /> + <mkdir dir="${dist.dir}" /> </target> <target name="release"> @@ -61,26 +67,41 @@ <classpath refid="classpath" /> </javac> + </target> + <target name="dist" + depends="compile"> <copy todir="${build.dir}/picross/properties" failonerror="false"> <fileset dir="${src.dir}/picross/properties" /> </copy> + <copy todir="${build.dir}/picross/images"> + <fileset dir="images" /> + </copy> + + <jar destfile="${jar.name}" + basedir="${build.dir}" /> </target> <target name="run" - depends="compile"> - <java classname="picross.Picross" + depends="dist"> + <java classname="picross.app.PicrossApp" failonerror="true" fork="true" dir="."> - <classpath refid="classpath" /> + <classpath> + <pathelement location="${jar.name}" /> + <pathelement location="${bundleHelper.jar}" /> + <pathelement location="${log4j.jar}" /> + <pathelement location="${mmvcs.jar}" /> + </classpath> </java> </target> <target name="clean"> <delete dir="${build.dir}" /> + <delete dir="${dist.dir}" /> <delete> <fileset dir="." @@ -90,7 +111,7 @@ </target> <target name="rebuild" - depends="clean, compile" /> + depends="clean, dist" /> <property file="checkstyle.properties" /> Added: trunk/images/crossed-rollover.png =================================================================== --- trunk/images/crossed-rollover.png (rev 0) +++ trunk/images/crossed-rollover.png 2007-06-07 11:18:40 UTC (rev 20) @@ -0,0 +1 @@ +link crossed.png \ No newline at end of file Property changes on: trunk/images/crossed-rollover.png ___________________________________________________________________ Name: svn:special + * Modified: trunk/src/picross/Picross.java =================================================================== --- trunk/src/picross/Picross.java 2007-06-07 04:22:39 UTC (rev 19) +++ trunk/src/picross/Picross.java 2007-06-07 11:18:40 UTC (rev 20) @@ -33,59 +33,49 @@ package picross; -import java.io.File; - import java.util.Locale; import javax.swing.ImageIcon; -import javax.swing.SwingUtilities; -import org.apache.log4j.PropertyConfigurator; +//import org.apache.log4j.Logger; /** - * Application main class. + * Helper class. * * @author Y. Norsa */ public final class Picross { /*** Constants ***/ - /** Log4j config file. */ - private static final String LOG4J_CONFIG = "log4j.properties"; - /** Images directory. */ - private static final String IMAGES_DIR = "images" + File.separator; + private static final String IMAGES_DIR = "/picross/images/"; /** Images directory corresponding to the default locale. */ private static final String LOCAL_IMAGES_PATH = Picross.IMAGES_DIR - + Locale.getDefault().getLanguage() + File.separator; + + Locale.getDefault().getLanguage() + "/"; - /*** Constructor ***/ + /*** Static field ***/ - /** Constructor. */ - private Picross() { - PropertyConfigurator.configure(Picross.LOG4J_CONFIG); + /** The class' logger. */ + //private static Logger log = Logger.getLogger(Picross.class); - new PicrossMediator(); - } + /*** Constructor ***/ - /*** Main method ***/ + /** Fake constructor. */ + private Picross() { } + /*** Static methods ***/ + /** - * Application main method. + * Loads an image. * - * @param args command line parameters + * @param path path of the image + * @return the image */ - public static void main(String[] args) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - new Picross(); - } - }); + private static ImageIcon loadImage(String path) { + return new ImageIcon(Picross.class.getResource(path)); } - /*** Static methods ***/ - /** * Returns an image. * @@ -93,7 +83,7 @@ * @return the image */ public static ImageIcon getImage(String name) { - return new ImageIcon(Picross.IMAGES_DIR + name); + return Picross.loadImage(Picross.IMAGES_DIR + name); } /** @@ -103,7 +93,7 @@ * @return the image */ public static ImageIcon getLocalizedImage(String name) { - return new ImageIcon(Picross.LOCAL_IMAGES_PATH + name); + return Picross.loadImage(Picross.LOCAL_IMAGES_PATH + name); } } Modified: trunk/src/picross/PicrossController.java =================================================================== --- trunk/src/picross/PicrossController.java 2007-06-07 04:22:39 UTC (rev 19) +++ trunk/src/picross/PicrossController.java 2007-06-07 11:18:40 UTC (rev 20) @@ -64,7 +64,18 @@ if (cmd.equals(PicrossController.MESSAGE_CMD)) { this.view.displayMessage(e.getComment()); + return; } + + if (cmd.equals(PicrossController.ERROR_CMD)) { + this.view.displayError(e.getComment()); + return; + } + + if (cmd.equals(PicrossController.DISPOSE_CMD)) { + this.view.exit(); + return; + } } /*** Accessor ***/ Added: trunk/src/picross/PicrossException.java =================================================================== --- trunk/src/picross/PicrossException.java (rev 0) +++ trunk/src/picross/PicrossException.java 2007-06-07 11:18:40 UTC (rev 20) @@ -0,0 +1,58 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross; + +/** + * General exception. + * + * @author Y. Norsa + */ +public final class PicrossException extends Exception { + /*** Constant ***/ + + /** Serialisation ID. */ + private static final long serialVersionUID = 1716838910721477345L; + + /*** Constructor ***/ + + /** + * Constructor. + * + * @param cause parent exception + */ + public PicrossException(Throwable cause) { + super(cause); + } +} + Property changes on: trunk/src/picross/PicrossException.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/PicrossMediator.java =================================================================== --- trunk/src/picross/PicrossMediator.java 2007-06-07 04:22:39 UTC (rev 19) +++ trunk/src/picross/PicrossMediator.java 2007-06-07 11:18:40 UTC (rev 20) @@ -51,33 +51,46 @@ * * @author Y. Norsa */ -final class PicrossMediator extends Mediateur { +public final class PicrossMediator extends Mediateur { /*** Static field ***/ /** Class' logger. */ //private static Logger log = Logger.getLogger(PicrossMediator.class); - /*** Fields ***/ + /*** Field ***/ - /** The view's controller. */ - private PicrossController controller; - /** Main view. */ private PicrossUI view; /*** Constructor ***/ /** Constructor. */ - PicrossMediator() { + public PicrossMediator(PicrossUI view) { BundleHelper.loadBundle("picross.properties.messages_picross"); - this.controller = new PicrossController(); - this.addSimpleListener(this.controller); + this.view = view; - MainMenuMediator mediator = new MainMenuMediator(); + PicrossController controller = new PicrossController(); + controller.setView(view); + + this.addSimpleListener(controller); + + MainMenuMediator mediator = null; + + try { + mediator = new MainMenuMediator(view); + } catch (PicrossException picrossEx) { + this.fireEventPerformed(PicrossController.ERROR_CMD, + picrossEx.getMessage()); + + this.exit(); + return; + } + mediator.addSimpleListener(this); - this.view = new PicrossUI(mediator.getView()); + //this.view = new PicrossUI(mediator.getView()); + this.view.setContent(mediator.getView()); } /*** Method overloaded from the Mediateur class ***/ @@ -97,13 +110,12 @@ grid.addSimpleListener(this); this.view.setContent(grid.getView()); - this.controller.setView(this.view); return; } if (cmd.equals(MainMenuController.EXIT_CMD)) { - this.view.dispose(); + this.exit(); return; } @@ -113,5 +125,12 @@ return; } } + + /*** Method ***/ + + /** Exits the application. */ + private void exit() { + this.fireEventPerformed(PicrossController.DISPOSE_CMD); + } } Modified: trunk/src/picross/PicrossUI.java =================================================================== --- trunk/src/picross/PicrossUI.java 2007-06-07 04:22:39 UTC (rev 19) +++ trunk/src/picross/PicrossUI.java 2007-06-07 11:18:40 UTC (rev 20) @@ -33,87 +33,43 @@ package picross; -import javax.swing.JFrame; -import javax.swing.JOptionPane; import javax.swing.JPanel; -import javax.swing.SwingUtilities; /** * Main window. * * @author Y. Norsa */ -final class PicrossUI extends JFrame { - /*** Constant ***/ - - /** Serialisation ID. */ - private static final long serialVersionUID = -6091243469021691734L; - - /*** Constructor ***/ - - /** Constructor. */ - PicrossUI(JPanel content) { - super("Picross"); - - this.setContent(content); - this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - this.setVisible(true); - } - - /*** Method ***/ - +public interface PicrossUI { /** - * Sets the frame panel and resizes the window. + * Sets the content panel. * * @param content new content panel */ - void setContent(JPanel content) { - this.setContentPane(content); - this.pack(); - } + void setContent(JPanel content); /** * Displays a message box. * * @param msg message to be displayed */ - void displayMessage(String msg) { - SwingUtilities.invokeLater(new RunnableDialog(this, msg)); - } + void displayMessage(String msg); /** - * Inner class displaying a message asynchronously. + * Displays an error message. * - * @author Y. Norsa + * @param msg error message */ - private static final class RunnableDialog implements Runnable { - /*** Fields ***/ + void displayError(String msg); - /** Parent frame. */ - private JFrame parent; + /** + * Returns the name of the main menu class. + * + * @return name of the main menu class + */ + String getMainMenuClass(); - /** Message to be displayed. */ - private String msg; - - /*** Constructor ***/ - - /** - * Constructor. - * - * @param parent parent frame - * @param msg message to be displayed - */ - private RunnableDialog(JFrame parent, String msg) { - this.parent = parent; - this.msg = msg; - } - - /*** Method implanted from the interface Runnable ***/ - - /** {@inheritDoc} */ - public void run() { - JOptionPane.showMessageDialog(this.parent, this.msg); - } - } + /** Method called when the application exits. */ + void exit(); } Added: trunk/src/picross/app/MainMenuAppUI.java =================================================================== --- trunk/src/picross/app/MainMenuAppUI.java (rev 0) +++ trunk/src/picross/app/MainMenuAppUI.java 2007-06-07 11:18:40 UTC (rev 20) @@ -0,0 +1,108 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.app; + +import java.awt.event.ActionListener; + +import javax.swing.ImageIcon; +import javax.swing.JButton; + +import picross.Picross; + +import picross.menus.MainMenuController; +import picross.menus.MainMenuUI; + +/** + * Main menu for the application version. + * + * @author Y. Norsa + */ +public final class MainMenuAppUI extends MainMenuUI { + /*** Constans ***/ + + /** Serialisation ID. */ + private static final long serialVersionUID = 8153436550520127667L; + + /** "Play" button X coordinate. */ + private static final int PLAY_BUTTON_X = 50; + + /** "Play" button Y coordinate. */ + private static final int PLAY_BUTTON_Y = 225; + + /** Image for the "exit" button. */ + private static final String EXIT_BUTTON_IMAGE = "button-exit.png"; + + /** "Exit" button X coordinate. */ + private static final int EXIT_BUTTON_X = 250; + + /** "Exit" button Y coordinate. */ + private static final int EXIT_BUTTON_Y = 225; + + /*** Constructor ***/ + + /** + * Constructor. + * + * @param controller controller for the buttons + */ + public MainMenuAppUI(ActionListener controller) { + super(controller); + + ImageIcon exitIcon = + Picross.getLocalizedImage(MainMenuAppUI.EXIT_BUTTON_IMAGE); + JButton exitButton = new JButton(exitIcon); + exitButton.setActionCommand(MainMenuController.EXIT_CMD); + exitButton.addActionListener(controller); + exitButton.setBorder(null); + exitButton.setBounds(MainMenuAppUI.EXIT_BUTTON_X, + MainMenuAppUI.EXIT_BUTTON_Y, + exitIcon.getIconWidth(), + exitIcon.getIconHeight()); + this.add(exitButton); + } + + /*** Methods overloaded from MainMenuUI ***/ + + /** {@inheritDoc} */ + protected int getPlayButtonX() { + return MainMenuAppUI.PLAY_BUTTON_X; + } + + /** {@inheritDoc} */ + protected int getPlayButtonY() { + return MainMenuAppUI.PLAY_BUTTON_Y; + } +} + + Property changes on: trunk/src/picross/app/MainMenuAppUI.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/app/PicrossApp.java =================================================================== --- trunk/src/picross/app/PicrossApp.java (rev 0) +++ trunk/src/picross/app/PicrossApp.java 2007-06-07 11:18:40 UTC (rev 20) @@ -0,0 +1,76 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.app; + +import javax.swing.SwingUtilities; + +import org.apache.log4j.PropertyConfigurator; + +import picross.PicrossMediator; + +/** + * Main class of the application version. + * + * @author Y. Norsa + */ +public final class PicrossApp { + /*** Constant ***/ + + /** Log4j config file. */ + private static final String LOG4J_CONFIG = "log4j.properties"; + + /** Constructor. */ + + /** Constructor. */ + private PicrossApp() { + PropertyConfigurator.configure(PicrossApp.LOG4J_CONFIG); + new PicrossMediator(new PicrossFrame()); + } + + /*** Main method ***/ + + /** + * Application main method. + * + * @param args command line parameters + */ + public static void main(String[] args) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + new PicrossApp(); + } + }); + } +} + Property changes on: trunk/src/picross/app/PicrossApp.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/app/PicrossFrame.java =================================================================== --- trunk/src/picross/app/PicrossFrame.java (rev 0) +++ trunk/src/picross/app/PicrossFrame.java 2007-06-07 11:18:40 UTC (rev 20) @@ -0,0 +1,95 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.app; + +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JPanel; + +import picross.PicrossUI; + +/** + * Main window of the application version. + * + * @author Y. Norsa + */ +public final class PicrossFrame extends JFrame implements PicrossUI { + /*** Constants ***/ + + /** Serialisation ID. */ + private static final long serialVersionUID = -6091243469021691734L; + + /** Main menu class. */ + private static final String MAIN_MENU_CLASS = "picross.app.MainMenuAppUI"; + + /*** Constructor ***/ + + /** Constructor. */ + public PicrossFrame() { + super("Picross"); + + this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + this.setVisible(true); + } + + /*** Methods implanted from the interface PicrossUI ***/ + + /** {@inheritDoc} */ + public void setContent(JPanel content) { + this.setContentPane(content); + this.pack(); + } + + /** {@inheritDoc} */ + public void displayMessage(String msg) { + JOptionPane.showMessageDialog(this, msg); + } + + /** {@inheritDoc} */ + public void displayError(String msg) { + JOptionPane.showMessageDialog(this, msg, + "Picross", JOptionPane.ERROR_MESSAGE); + } + + /** {@inheritDoc} */ + public void exit() { + this.dispose(); + } + + /** {@inheritDoc} */ + public String getMainMenuClass() { + return PicrossFrame.MAIN_MENU_CLASS; + } +} + Property changes on: trunk/src/picross/app/PicrossFrame.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/app/package.html =================================================================== --- trunk/src/picross/app/package.html (rev 0) +++ trunk/src/picross/app/package.html 2007-06-07 11:18:40 UTC (rev 20) @@ -0,0 +1,12 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> + <head> + <!-- + $Id$ + --> + </head> + + <body bgcolor="white"> + Classes for the application version. + </body> +</html> Property changes on: trunk/src/picross/app/package.html ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/applet/MainMenuAppletUI.java =================================================================== --- trunk/src/picross/applet/MainMenuAppletUI.java (rev 0) +++ trunk/src/picross/applet/MainMenuAppletUI.java 2007-06-07 11:18:40 UTC (rev 20) @@ -0,0 +1,92 @@ +/* + * $Id$ + * \xC9crit le 07/06/2007 par Y. Norsa + * + * Copyright (c) 2007 + * Projet Carte Lorraine de l'Etudiant (CLE) + * + * Universit\xE9 Henri Poincar\xE9, Nancy + * Universit\xE9 Nancy2 + * Institut National Polytechnique de Lorraine + * Universit\xE9 Paul Verlaine, Metz + * + * Ce projet regroupe les d\xE9veloppements concernant la production + * et l'exploitation de la Carte Lorraine de l'Etudiant + * (carte \xE0 puce sans contact Mifare). + * + * Ce logiciel est r\xE9gi par la licence CeCILL soumise au droit fran\xE7ais et + * respectant les principes de diffusion des logiciels libres. Vous pouvez + * utiliser, modifier et/ou redistribuer ce programme sous les conditions + * de la licence CeCILL telle que diffus\xE9e par le CEA, le CNRS et l'INRIA + * sur le site "http://www.cecill.info". + * + * En contrepartie de l'accessibilit\xE9 au code source et des droits de copie, + * de modification et de redistribution accord\xE9s par cette licence, il n'est + * offert aux utilisateurs qu'une garantie limit\xE9e. Pour les m\xEAmes raisons, + * seule une responsabilit\xE9 restreinte p\xE8se sur l'auteur du programme, le + * titulaire des droits patrimoniaux et les conc\xE9dants successifs. + * + * A cet \xE9gard l'attention de l'utilisateur est attir\xE9e sur les risques + * associ\xE9s au chargement, \xE0 l'utilisation, \xE0 la modification et/ou au + * d\xE9veloppement et \xE0 la reproduction du logiciel par l'utilisateur \xE9tant + * donn\xE9 sa sp\xE9cificit\xE9 de logiciel libre, qui peut le rendre complexe \xE0 + * manipuler et qui le r\xE9serve donc \xE0 des d\xE9veloppeurs et des professionnels + * avertis poss\xE9dant des connaissances informatiques approfondies. Les + * utilisateurs sont donc invit\xE9s \xE0 charger et tester l'ad\xE9quation du + * logiciel \xE0 leurs besoins dans des conditions permettant d'assurer la + * s\xE9curit\xE9 de leurs syst\xE8mes et ou de leurs donn\xE9es et, plus g\xE9n\xE9ralement, + * \xE0 l'utiliser et l'exploiter dans les m\xEAmes conditions de s\xE9curit\xE9. + * + * Le fait que vous puissiez acc\xE9der \xE0 cet en-t\xEAte signifie que vous avez + * pris connaissance de la licence CeCILL, et que vous en avez accept\xE9 les + * termes. + */ + + +package picross.applet; + +import java.awt.event.ActionListener; + +import picross.menus.MainMenuUI; + +/** + * Main menu for the applet version. + * + * @author Y. Norsa + */ +public final class MainMenuAppletUI extends MainMenuUI { + /*** Constants ***/ + + /** Serialisation ID. */ + private static final long serialVersionUID = 5820728724819549202L; + + /** "Play" button X coordinate. */ + private static final int PLAY_BUTTON_X = 149; + + /** "Play" button Y coordinate. */ + private static final int PLAY_BUTTON_Y = 225; + + /*** Constructor ***/ + + /** + * Constructor. + * + * @param controller controller for the buttons + */ + public MainMenuAppletUI(ActionListener controller) { + super(controller); + } + + /*** Methods inherited from the class MainMenuUI ***/ + + /** {@inheritDoc} */ + protected int getPlayButtonX() { + return MainMenuAppletUI.PLAY_BUTTON_X; + } + + /** {@inheritDoc} */ + protected int getPlayButtonY() { + return MainMenuAppletUI.PLAY_BUTTON_Y; + } +} + Property changes on: trunk/src/picross/applet/MainMenuAppletUI.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/applet/PicrossApplet.java =================================================================== --- trunk/src/picross/applet/PicrossApplet.java (rev 0) +++ trunk/src/picross/applet/PicrossApplet.java 2007-06-07 11:18:40 UTC (rev 20) @@ -0,0 +1,98 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.applet; + +import javax.swing.JApplet; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +import picross.PicrossMediator; +import picross.PicrossUI; + +/** + * Main class of the applet version. + * + * @author Y. Norsa + */ +public final class PicrossApplet extends JApplet implements PicrossUI { + /*** Constants ***/ + + /** Serialisation ID. */ + private static final long serialVersionUID = 2701753715418652408L; + + /** Main menu class. */ + private static final String MAIN_MENU_CLASS = + "picross.applet.MainMenuAppletUI"; + + /*** Methods overloaded from the class JApplet ***/ + + /** {@inheritDoc} */ + public void init() { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + new PicrossMediator(PicrossApplet.this); + } + }); + } + + /*** Methods implanted from the interface PicrossUI ***/ + + /** {@inheritDoc} */ + public String getMainMenuClass() { + return PicrossApplet.MAIN_MENU_CLASS; + } + + /** {@inheritDoc} */ + public void displayMessage(String msg) { + JOptionPane.showMessageDialog(this, msg); + } + + /** {@inheritDoc} */ + public void displayError(String msg) { + JOptionPane.showMessageDialog(this, msg, + "Picross", JOptionPane.ERROR_MESSAGE); + } + + /** {@inheritDoc} */ + public void setContent(JPanel content) { + this.setContentPane(content); + this.validate(); + } + + /** {@inheritDoc} */ + public void exit() { + } +} + Property changes on: trunk/src/picross/applet/PicrossApplet.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/applet/package.html =================================================================== --- trunk/src/picross/applet/package.html (rev 0) +++ trunk/src/picross/applet/package.html 2007-06-07 11:18:40 UTC (rev 20) @@ -0,0 +1,12 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> + <head> + <!-- + $Id$ + --> + </head> + + <body bgcolor="white"> + Classes for the applet version. + </body> +</html> Property changes on: trunk/src/picross/applet/package.html ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/grid/GridBox.java =================================================================== --- trunk/src/picross/grid/GridBox.java 2007-06-07 04:22:39 UTC (rev 19) +++ trunk/src/picross/grid/GridBox.java 2007-06-07 11:18:40 UTC (rev 20) @@ -59,10 +59,6 @@ GridBox.images.put(state, img); } - - // We don't have a rollover icon for crossed boxes - GridBox.images.get(Box.BoxState.CROSSED)[GridBox.ROLLOVER_ICON_INDEX] = - GridBox.images.get(Box.BoxState.CROSSED)[GridBox.ICON_INDEX]; } /*** Constructor ***/ Modified: trunk/src/picross/menus/MainMenuController.java =================================================================== --- trunk/src/picross/menus/MainMenuController.java 2007-06-07 04:22:39 UTC (rev 19) +++ trunk/src/picross/menus/MainMenuController.java 2007-06-07 11:18:40 UTC (rev 20) @@ -75,6 +75,8 @@ String cmd = e.getActionCommand(); + //javax.swing.JOptionPane.showMessageDialog(null, "click : " + cmd); + if (cmd.equals(MainMenuController.PLAY_CMD) || cmd.equals(MainMenuController.EXIT_CMD)) { Modified: trunk/src/picross/menus/MainMenuMediator.java =================================================================== --- trunk/src/picross/menus/MainMenuMediator.java 2007-06-07 04:22:39 UTC (rev 19) +++ trunk/src/picross/menus/MainMenuMediator.java 2007-06-07 11:18:40 UTC (rev 20) @@ -36,8 +36,15 @@ import fr.cle.mmvcs.Mediateur; import fr.cle.mmvcs.SimpleEvent; +import java.awt.event.ActionListener; + +import java.lang.reflect.InvocationTargetException; + import org.apache.log4j.Logger; +import picross.PicrossException; +import picross.PicrossUI; + /** * Mediator for the main menu. * @@ -56,12 +63,29 @@ /*** Constructor ***/ - /** Constructor. */ - public MainMenuMediator() { + /** + * Constructor. + * + * @throws PicrossException if the instantiation of the main menu UI fails + */ + public MainMenuMediator(PicrossUI ui) throws PicrossException { MainMenuController controller = new MainMenuController(); controller.addSimpleListener(this); - this.view = new MainMenuUI(controller); + try { + this.view = (MainMenuUI) Class.forName(ui.getMainMenuClass()) + .getConstructor(ActionListener.class).newInstance(controller); + } catch (ClassNotFoundException classEx) { + throw new PicrossException(classEx); + } catch (NoSuchMethodException methodEx) { + throw new PicrossException(methodEx); + } catch (InstantiationException instantiationEx) { + throw new PicrossException(instantiationEx); + } catch (IllegalAccessException accessEx) { + throw new PicrossException(accessEx); + } catch (InvocationTargetException targetEx) { + throw new PicrossException(targetEx.getCause()); + } } /*** Method overloaded from the class Mediateur ***/ @@ -69,6 +93,7 @@ /** {@inheritDoc} */ public void eventPerformed(SimpleEvent e) { MainMenuMediator.log.debug("eventPerformed(" + e + ")"); + this.fireEventPerformed(e); } Modified: trunk/src/picross/menus/MainMenuUI.java =================================================================== --- trunk/src/picross/menus/MainMenuUI.java 2007-06-07 04:22:39 UTC (rev 19) +++ trunk/src/picross/menus/MainMenuUI.java 2007-06-07 11:18:40 UTC (rev 20) @@ -50,7 +50,7 @@ * * @author Y. Norsa */ -class MainMenuUI extends JPanel { +public abstract class MainMenuUI extends JPanel { /*** Constants ***/ /** Serialisation ID. */ @@ -62,21 +62,6 @@ /** Image for the "play" button. */ private static final String PLAY_BUTTON_IMAGE = "button-play.png"; - /** "Play" button X coordinate. */ - private static final int PLAY_BUTTON_X = 50; - - /** "Play" button Y coordinate. */ - private static final int PLAY_BUTTON_Y = 225; - - /** Image for the "exit" button. */ - private static final String EXIT_BUTTON_IMAGE = "button-exit.png"; - - /** "Exit" button X coordinate. */ - private static final int EXIT_BUTTON_X = 250; - - /** "Exit" button Y coordinate. */ - private static final int EXIT_BUTTON_Y = 225; - /*** Field ***/ /** Background image. */ @@ -89,7 +74,7 @@ * * @param controller controller for the buttons */ - MainMenuUI(ActionListener controller) { + public MainMenuUI(ActionListener controller) { ImageIcon icon = Picross.getImage(MainMenuUI.BACKGROUND_IMAGE); this.setPreferredSize(new Dimension(icon.getIconWidth(), icon.getIconHeight())); @@ -103,21 +88,27 @@ playButton.setActionCommand(MainMenuController.PLAY_CMD); playButton.addActionListener(controller); playButton.setBorder(null); - playButton.setBounds(MainMenuUI.PLAY_BUTTON_X, MainMenuUI.PLAY_BUTTON_Y, + playButton.setBounds(this.getPlayButtonX(), this.getPlayButtonY(), playIcon.getIconWidth(), playIcon.getIconHeight()); this.add(playButton); - - ImageIcon exitIcon = - Picross.getLocalizedImage(MainMenuUI.EXIT_BUTTON_IMAGE); - JButton exitButton = new JButton(exitIcon); - exitButton.setActionCommand(MainMenuController.EXIT_CMD); - exitButton.addActionListener(controller); - exitButton.setBorder(null); - exitButton.setBounds(MainMenuUI.EXIT_BUTTON_X, MainMenuUI.EXIT_BUTTON_Y, - exitIcon.getIconWidth(), exitIcon.getIconHeight()); - this.add(exitButton); } + /*** Abstract methods ***/ + + /** + * Returns the "play" button X position. + * + * @return X position of the "play" button + */ + protected abstract int getPlayButtonX(); + + /** + * Returns the "play" button Y position. + * + * @return Y position of the "play" button + */ + protected abstract int getPlayButtonY(); + /*** Method overloaded from the class JPanel ***/ /** {@inheritDoc} */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-07 04:22:38
|
Revision: 19 http://picross.svn.sourceforge.net/picross/?rev=19&view=rev Author: yvan_norsa Date: 2007-06-06 21:22:39 -0700 (Wed, 06 Jun 2007) Log Message: ----------- fixed the findbugs task Modified Paths: -------------- trunk/build.xml Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2007-06-06 19:14:19 UTC (rev 18) +++ trunk/build.xml 2007-06-07 04:22:39 UTC (rev 19) @@ -144,7 +144,8 @@ <target name="findbugs" depends="-check-findbugs,rebuild"> <taskdef name="findbugs" - classname="edu.umd.cs.findbugs.anttask.FindBugsTask" /> + classname="edu.umd.cs.findbugs.anttask.FindBugsTask" + classpath="${env.FINDBUGS_HOME}/lib/findbugs-ant.jar" /> <findbugs home="${env.FINDBUGS_HOME}" reportLevel="low" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-06 19:14:24
|
Revision: 18 http://picross.svn.sourceforge.net/picross/?rev=18&view=rev Author: yvan_norsa Date: 2007-06-06 12:14:19 -0700 (Wed, 06 Jun 2007) Log Message: ----------- added rollover icons Modified Paths: -------------- trunk/src/picross/PicrossMediator.java trunk/src/picross/grid/Box.java trunk/src/picross/grid/PicrossGridController.java trunk/src/picross/grid/PicrossGridModel.java trunk/src/picross/grid/PicrossGridUI.java trunk/src/picross/menus/MainMenuUI.java Added Paths: ----------- trunk/images/checked-rollover.png trunk/images/empty-rollover.png trunk/src/picross/grid/GridBox.java Added: trunk/images/checked-rollover.png =================================================================== (Binary files differ) Property changes on: trunk/images/checked-rollover.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/images/empty-rollover.png =================================================================== (Binary files differ) Property changes on: trunk/images/empty-rollover.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/src/picross/PicrossMediator.java =================================================================== --- trunk/src/picross/PicrossMediator.java 2007-06-06 15:08:52 UTC (rev 17) +++ trunk/src/picross/PicrossMediator.java 2007-06-06 19:14:19 UTC (rev 18) @@ -38,7 +38,7 @@ import fr.cle.mmvcs.Mediateur; import fr.cle.mmvcs.SimpleEvent; -import org.apache.log4j.Logger; +//import org.apache.log4j.Logger; import picross.grid.PicrossGridController; import picross.grid.PicrossGridMediator; @@ -55,7 +55,7 @@ /*** Static field ***/ /** Class' logger. */ - private static Logger log = Logger.getLogger(PicrossMediator.class); + //private static Logger log = Logger.getLogger(PicrossMediator.class); /*** Fields ***/ @@ -84,7 +84,7 @@ /** {@inheritDoc} */ public void eventPerformed(SimpleEvent e) { - PicrossMediator.log.debug("eventPerformed(" + e + ")"); + //PicrossMediator.log.debug("eventPerformed(" + e + ")"); String cmd = e.getCommandName(); Modified: trunk/src/picross/grid/Box.java =================================================================== --- trunk/src/picross/grid/Box.java 2007-06-06 15:08:52 UTC (rev 17) +++ trunk/src/picross/grid/Box.java 2007-06-06 19:14:19 UTC (rev 18) @@ -45,26 +45,20 @@ package picross.grid; -import java.awt.Image; - -import java.util.HashMap; -import java.util.Map; import java.util.Random; //import org.apache.log4j.Logger; -import picross.Picross; - /** * Representation of a box in the grid. * * @author Y. Norsa */ -final class Box { +class Box { /*** Enum ***/ /** Possibles states of a box. */ - private enum BoxState { + enum BoxState { /** An empty box. */ EMPTY, @@ -75,11 +69,6 @@ CROSSED } - /*** Constant ***/ - - /** Images files extension. */ - private static final String IMAGES_EXT = ".png"; - /*** Statics fields ***/ /** The class's logger. */ @@ -88,37 +77,25 @@ /** Random number generator. */ private static Random rand; - /** Map containing the images corresponding to the different states. */ - private static Map<Box.BoxState, Image> images; - /*** Fields ***/ /** State of the box. */ - private Box.BoxState state; + protected Box.BoxState state; /** Pseudo random hash-code. */ - private int hash; + private final int hash; /*** Static block ***/ - // Fills in the images map static { Box.rand = new Random(); - - Box.images = new HashMap<Box.BoxState, Image>(); - - for (Box.BoxState state : Box.BoxState.values()) { - Box.images.put(state, Picross - .getImage(state.toString().toLowerCase() - + Box.IMAGES_EXT).getImage()); - } } /*** Constructor ***/ /** Constructor. */ Box() { - this.state = Box.BoxState.EMPTY; + this.empty(); this.hash = Box.rand.nextInt(); } @@ -153,7 +130,7 @@ * * @return boolean telling if the box is checked */ - boolean isChecked() { + final boolean isChecked() { return this.state == Box.BoxState.CHECKED; } @@ -162,7 +139,7 @@ * * @return boolean telling if the box is crossed */ - boolean isCrossed() { + final boolean isCrossed() { return this.state == Box.BoxState.CROSSED; } @@ -171,33 +148,23 @@ * * @return boolean telling if the box is empty */ - boolean isEmpty() { + final boolean isEmpty() { return this.state == Box.BoxState.EMPTY; } /** Empties the box. */ - void empty() { + final void empty() { this.state = Box.BoxState.EMPTY; } /** Checks the box. */ - void check() { + final void check() { this.state = Box.BoxState.CHECKED; } /** Crosses the box. */ - void cross() { + final void cross() { this.state = Box.BoxState.CROSSED; } - - /** - * Returns the image associated with the box's state. - * - * @return the image corresponding to the box's state - */ - Image getImage() { - //Box.log.debug("return " + Box.images.get(this.state)); - return Box.images.get(this.state); - } } Added: trunk/src/picross/grid/GridBox.java =================================================================== --- trunk/src/picross/grid/GridBox.java (rev 0) +++ trunk/src/picross/grid/GridBox.java 2007-06-06 19:14:19 UTC (rev 18) @@ -0,0 +1,111 @@ +package picross.grid; + +import java.awt.Rectangle; + +import java.util.HashMap; +import java.util.Map; + +import javax.swing.ImageIcon; + +import picross.Picross; + +/** + * Graphical representation of a box in the grid. + * + * @author Y. Norsa + */ +final class GridBox extends Box { + /*** Constants ***/ + + /** Index of the normal icon. */ + private static final int ICON_INDEX = 0; + + /** Index of the rollover icon. */ + private static final int ROLLOVER_ICON_INDEX = 1; + + /** Suffix for rollover icons. */ + private static final String ROLLOVER_NAME = "-rollover"; + + /** Images files extension. */ + private static final String IMAGES_EXT = ".png"; + + /*** Static field ***/ + + /** Map containing the images corresponding to the different states. */ + private static Map<Box.BoxState, ImageIcon[]> images; + + /*** Field ***/ + + /** Rectangle occupied by the box. */ + private Rectangle rect; + + // Fills in the images map + static { + /* + * We create a too large HashMap so it doesn't grow + * during its initialisation + */ + GridBox.images = new HashMap<Box.BoxState, ImageIcon[]>(7); + + for (Box.BoxState state : Box.BoxState.values()) { + ImageIcon[] img = new ImageIcon[2]; + + String stateImageName = state.toString().toLowerCase(); + img[GridBox.ICON_INDEX] = Picross.getImage(stateImageName + + GridBox.IMAGES_EXT); + img[GridBox.ROLLOVER_ICON_INDEX] = + Picross.getImage(stateImageName + GridBox.ROLLOVER_NAME + + GridBox.IMAGES_EXT); + + GridBox.images.put(state, img); + } + + // We don't have a rollover icon for crossed boxes + GridBox.images.get(Box.BoxState.CROSSED)[GridBox.ROLLOVER_ICON_INDEX] = + GridBox.images.get(Box.BoxState.CROSSED)[GridBox.ICON_INDEX]; + } + + /*** Constructor ***/ + + /** + * Constructor. + * + * @param rect rectangle occupied by this box + */ + GridBox(Rectangle rect) { + super(); + + this.rect = rect; + } + + /*** Methods ***/ + + /** + * Returns the icon representing the current state of the box. + * + * @return icon of the state of the box + */ + ImageIcon getIcon() { + return GridBox.images.get(this.state)[GridBox.ICON_INDEX]; + } + + /** + * Returns the rollover icon representing the current state of the box. + * + * @return rollover icon of the state of the box + */ + ImageIcon getRolloverIcon() { + return GridBox.images.get(this.state)[GridBox.ROLLOVER_ICON_INDEX]; + } + + /*** Accessor ***/ + + /** + * Returns this box' rectangle. + * + * @return rectangle occupied by this box + */ + Rectangle getRect() { + return this.rect; + } +} Property changes on: trunk/src/picross/grid/GridBox.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/grid/PicrossGridController.java =================================================================== --- trunk/src/picross/grid/PicrossGridController.java 2007-06-06 15:08:52 UTC (rev 17) +++ trunk/src/picross/grid/PicrossGridController.java 2007-06-06 19:14:19 UTC (rev 18) @@ -127,7 +127,9 @@ public void mouseExited(MouseEvent e) { } /** {@inheritDoc} */ - public void mousePressed(MouseEvent e) { } + public void mousePressed(MouseEvent e) { + this.view.rolloverEnded(); + } /** {@inheritDoc} */ public void mouseReleased(MouseEvent e) { @@ -144,8 +146,22 @@ } /** {@inheritDoc} */ - public void mouseMoved(MouseEvent e) { } + public void mouseMoved(MouseEvent e) { + //PicrossGridController.log.debug(e.getPoint()); + Point point = e.getPoint(); + + if (this.view.isInGrid(point)) { + int row = this.view.getRow(point); + int column = this.view.getColumn(point); + + this.view.setRollover(row, column); + } else { + this.view.rolloverEnded(); + } + + } + /*** Methods ***/ /** Modified: trunk/src/picross/grid/PicrossGridModel.java =================================================================== --- trunk/src/picross/grid/PicrossGridModel.java 2007-06-06 15:08:52 UTC (rev 17) +++ trunk/src/picross/grid/PicrossGridModel.java 2007-06-06 19:14:19 UTC (rev 18) @@ -284,7 +284,7 @@ this.mediator.check(row, column, PicrossGridController.CROSS_ACTION); } - } else { //if (this.boxes[row][column].isCrossed())\xA0{ + } else { //if (this.boxes[row][column].isCrossed()) { //PicrossGridModel.log.debug("crossed"); if (type == PicrossGridController.CROSS_ACTION) { Modified: trunk/src/picross/grid/PicrossGridUI.java =================================================================== --- trunk/src/picross/grid/PicrossGridUI.java 2007-06-06 15:08:52 UTC (rev 17) +++ trunk/src/picross/grid/PicrossGridUI.java 2007-06-06 19:14:19 UTC (rev 18) @@ -37,10 +37,11 @@ import java.awt.Dimension; import java.awt.Graphics; import java.awt.Point; +import java.awt.Rectangle; import javax.swing.JPanel; -//import org.apache.log4j.Logger; +import org.apache.log4j.Logger; /** * Grid UI. @@ -83,7 +84,7 @@ /*** Static field ***/ /** Class' logger. */ - //private static Logger log = Logger.getLogger(PicrossGridUI.class); + private static Logger log = Logger.getLogger(PicrossGridUI.class); /*** Fields ***/ @@ -111,9 +112,18 @@ /** Position of the bottom end of the grid. */ private int bottomBoundary; + /** Rectangle occupied by the top hints. */ + private Rectangle topHintsRect; + + /** Rectangle occupied by the left hints. */ + private Rectangle leftHintsRect; + /** Current state of the grid. */ - private Box[][] boxes; + private GridBox[][] boxes; + /** Current rolled-over box. */ + private transient GridBox rollover; + /** Controller attached to this view. */ private transient PicrossGridController controller; @@ -132,7 +142,7 @@ int[][] colData, int[][] rowData, PicrossGridController controller) { - super(); + super(true); this.controller = controller; @@ -148,14 +158,6 @@ this.colData = colData; this.rowData = rowData; - this.boxes = new Box[this.width][this.height]; - - for (int i = 0; i < this.boxes.length; i++) { - for (int j = 0; j < this.boxes[i].length; j++) { - this.boxes[i][j] = new Box(); - } - } - this.leftBoundary = this.rowData[0].length * PicrossGridUI.ROW_HINT_WIDTH; @@ -168,6 +170,33 @@ this.bottomBoundary = this.topBoundary + (this.height * PicrossGridUI.BOX_HEIGHT); + this.topHintsRect = new Rectangle(this.leftBoundary, 0, + this.width * PicrossGridUI.BOX_WIDTH, + this.topBoundary); + this.leftHintsRect = new Rectangle(0, this.topBoundary, + this.leftBoundary, + this.height + * PicrossGridUI.BOX_HEIGHT); + + this.boxes = new GridBox[this.width][this.height]; + + for (int i = 0; i < this.boxes.length; i++) { + for (int j = 0; j < this.boxes[i].length; j++) { + /* + * We compute here the rectangle corresponding to each box + * so we'll be able + * to redraw only what is needed + */ + this.boxes[i][j] = + new GridBox(new Rectangle(this.leftBoundary + + (j * PicrossGridUI.BOX_WIDTH), + this.topBoundary + + (i * PicrossGridUI.BOX_WIDTH), + PicrossGridUI.BOX_WIDTH, + PicrossGridUI.BOX_HEIGHT)); + } + } + //PicrossGridUI.log.debug("rightBoundary : " + this.rightBoundary); //PicrossGridUI.log.debug("bottomBoundary : " + this.bottomBoundary); @@ -180,55 +209,69 @@ /*** Method overloaded from JPanel ***/ /** {@inheritDoc} */ - public void paintComponent(Graphics g) { + protected void paintComponent(Graphics g) { super.paintComponent(g); - int x = 0; - int y = PicrossGridUI.TOP_HINTS; + Rectangle clipRect = g.getClipBounds(); - for (int i = this.colData[0].length - 1; i >= 0; i--) { - x = this.leftBoundary + PicrossGridUI.COL_HINT_WIDTH; + if (this.topHintsRect.intersects(clipRect)) { + PicrossGridUI.log.debug("top hints"); - for (int j = 0; j < this.colData.length; j++) { - if (this.colData[j][i] != PicrossGridModel.EMPTY_HINT) { - g.drawString(String.valueOf(this.colData[j][i]), - x, y); + int x = 0; + int y = PicrossGridUI.TOP_HINTS; + + for (int i = this.colData[0].length - 1; i >= 0; i--) { + x = this.leftBoundary + PicrossGridUI.COL_HINT_WIDTH; + + for (int j = 0; j < this.colData.length; j++) { + if (this.colData[j][i] != PicrossGridModel.EMPTY_HINT) { + g.drawString(String.valueOf(this.colData[j][i]), + x, y); + } + + x += PicrossGridUI.BOX_WIDTH; } - x += PicrossGridUI.BOX_WIDTH; + y += PicrossGridUI.COL_HINT_HEIGHT; } - - y += PicrossGridUI.COL_HINT_HEIGHT; } - int gridY = y; + if (this.leftHintsRect.intersects(clipRect)) { + PicrossGridUI.log.debug("left hints"); - for (int i = 0; i < this.rowData.length; i++) { - x = 0; + int y = this.topBoundary; - for (int j = 0; j < this.rowData[i].length; j++) { - if (this.rowData[i][j] != PicrossGridModel.EMPTY_HINT) { - g.drawString(String.valueOf(this.rowData[i][j]), - x, y + PicrossGridUI.ROW_HINT_HEIGHT); + for (int i = 0; i < this.rowData.length; i++) { + int x = 0; + + for (int j = 0; j < this.rowData[i].length; j++) { + if (this.rowData[i][j] != PicrossGridModel.EMPTY_HINT) { + g.drawString(String.valueOf(this.rowData[i][j]), + x, y + PicrossGridUI.ROW_HINT_HEIGHT); + } + + x += PicrossGridUI.ROW_HINT_WIDTH; } - x += PicrossGridUI.ROW_HINT_WIDTH; + y += PicrossGridUI.BOX_HEIGHT; } - - y += PicrossGridUI.BOX_HEIGHT; } - y = gridY; - for (int i = 0; i < this.height; i++) { - x = this.leftBoundary; + for (int j = 0; j < this.width; j++) { + Rectangle currentRect = this.boxes[i][j].getRect(); - for (int j = 0; j < this.width; j++) { - g.drawImage(this.boxes[i][j].getImage(), x, y, null); - x += PicrossGridUI.BOX_WIDTH; + if (currentRect.intersects(clipRect)) { + if (this.boxes[i][j] == this.rollover) { + this.boxes[i][j].getRolloverIcon() + .paintIcon(this, g, currentRect.x, currentRect.y); + } else { + this.boxes[i][j].getIcon().paintIcon(this, g, + currentRect.x, + currentRect.y); + } + } } - - y += PicrossGridUI.BOX_HEIGHT; } } @@ -319,7 +362,35 @@ } } - this.repaint(); + this.repaint(this.boxes[row][column].getRect()); } + + /** + * Allows to set the current rolled-over box. + * + * @param row row of the box + * @param column column of the box + */ + void setRollover(int row, int column) { + //PicrossGridUI.log.debug("setRollover(" + row + ", " + column + ")"); + + this.rolloverEnded(); + this.rollover = this.boxes[row][column]; + this.repaint(this.rollover.getRect()); + } + + /** Indicates that no box is currently rolled over. */ + void rolloverEnded() { + if (this.rollover != null) { + /* + * Save the old rolled-over box so we can draw it + * in its initial state + */ + Rectangle rect = this.rollover.getRect(); + + this.rollover = null; + this.repaint(rect); + } + } } Modified: trunk/src/picross/menus/MainMenuUI.java =================================================================== --- trunk/src/picross/menus/MainMenuUI.java 2007-06-06 15:08:52 UTC (rev 17) +++ trunk/src/picross/menus/MainMenuUI.java 2007-06-06 19:14:19 UTC (rev 18) @@ -121,7 +121,7 @@ /*** Method overloaded from the class JPanel ***/ /** {@inheritDoc} */ - public void paintComponent(Graphics g) { + protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(this.image, 0, 0, null); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-06 15:09:05
|
Revision: 17 http://picross.svn.sourceforge.net/picross/?rev=17&view=rev Author: yvan_norsa Date: 2007-06-06 08:08:52 -0700 (Wed, 06 Jun 2007) Log Message: ----------- english buttons Modified Paths: -------------- trunk/images/en/button-exit.png trunk/images/en/button-play.png Modified: trunk/images/en/button-exit.png =================================================================== (Binary files differ) Modified: trunk/images/en/button-play.png =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |