[Picross-commit] SF.net SVN: picross: [11] trunk
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2007-06-06 11:42:56
|
Revision: 11 http://picross.svn.sourceforge.net/picross/?rev=11&view=rev Author: yvan_norsa Date: 2007-06-06 04:42:57 -0700 (Wed, 06 Jun 2007) Log Message: ----------- added images and crosses Modified Paths: -------------- trunk/bugsFilter.xml trunk/src/picross/grid/FillCommand.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 Added Paths: ----------- trunk/images/ trunk/images/checked.png trunk/images/crossed.png trunk/images/empty.png trunk/src/picross/grid/Box.java Modified: trunk/bugsFilter.xml =================================================================== --- trunk/bugsFilter.xml 2007-06-06 08:27:54 UTC (rev 10) +++ trunk/bugsFilter.xml 2007-06-06 11:42:57 UTC (rev 11) @@ -1,5 +1,5 @@ <FindBugsFilter> <Match classregex=".*"> - <Bug pattern="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" /> </Match> </FindBugsFilter> Added: trunk/images/checked.png =================================================================== (Binary files differ) Property changes on: trunk/images/checked.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/images/crossed.png =================================================================== (Binary files differ) Property changes on: trunk/images/crossed.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/images/empty.png =================================================================== (Binary files differ) Property changes on: trunk/images/empty.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/src/picross/grid/Box.java =================================================================== --- trunk/src/picross/grid/Box.java (rev 0) +++ trunk/src/picross/grid/Box.java 2007-06-06 11:42:57 UTC (rev 11) @@ -0,0 +1,211 @@ +/* + * $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 + * + * 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.grid; + +import java.awt.Image; + +import java.io.File; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +import javax.swing.ImageIcon; + +//import org.apache.log4j.Logger; + +/** + * Representation of a box in the grid. + * + * @author Y. Norsa + */ +final class Box { + /*** Enum ***/ + + /** Possibles states of a box. */ + private enum BoxState { + /** An empty box. */ + EMPTY, + + /** A checked box. */ + CHECKED, + + /** A crossed box. */ + CROSSED + } + + /*** Constants ***/ + + /** Directory containing the images. */ + private static final String IMAGES_DIR = "images"; + + /** Images files extension. */ + private static final String IMAGES_EXT = ".png"; + + /*** Statics fields ***/ + + /** The class's logger. */ + //private static Logger log = Logger.getLogger(Box.class); + + /** 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; + + /** Pseudo random hash-code. */ + private int hash; + + /*** Static block ***/ + + // Fills in the images map + static { + Box.rand = new Random(); + + Box.images = new HashMap<Box.BoxState, Image>(); + + String path = Box.IMAGES_DIR + File.separator; + + for (Box.BoxState state : Box.BoxState.values()) { + Box.images.put(state, new ImageIcon(path + + state.toString() + .toLowerCase() + + Box.IMAGES_EXT).getImage()); + } + } + + /*** Constructor ***/ + + /** Constructor. */ + Box() { + this.state = Box.BoxState.EMPTY; + this.hash = Box.rand.nextInt(); + } + + /*** Methods overloaded from the class Object ***/ + + /** {@inheritDoc} */ + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + + if (obj == this) { + return true; + } + + if (!(obj instanceof Box)) { + return false; + } + + return (this.state == ((Box) obj).state); + } + + /** {@inheritDoc} */ + public int hashCode() { + return this.hash; + } + + /*** Methods ***/ + + /** + * Permits to know if the box is checked. + * + * @return boolean telling if the box is checked + */ + boolean isChecked() { + return this.state == Box.BoxState.CHECKED; + } + + /** + * Permits to know if the box is crossed. + * + * @return boolean telling if the box is crossed + */ + boolean isCrossed() { + return this.state == Box.BoxState.CROSSED; + } + + /** + * Permits to know if the box is empty. + * + * @return boolean telling if the box is empty + */ + boolean isEmpty() { + return this.state == Box.BoxState.EMPTY; + } + + /** Empties the box. */ + void empty() { + this.state = Box.BoxState.EMPTY; + } + + /** Checks the box. */ + void check() { + this.state = Box.BoxState.CHECKED; + } + + /** Crosses the box. */ + 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); + } +} + Property changes on: trunk/src/picross/grid/Box.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/grid/FillCommand.java =================================================================== --- trunk/src/picross/grid/FillCommand.java 2007-06-06 08:27:54 UTC (rev 10) +++ trunk/src/picross/grid/FillCommand.java 2007-06-06 11:42:57 UTC (rev 11) @@ -49,6 +49,9 @@ /** Column of the box to fill. */ private int column; + /** Type of the action. */ + private int type; + /*** Constructor ***/ /** @@ -56,10 +59,12 @@ * * @param row row of the box to fill * @param column column of the box to fill + * @param type type of the action */ - FillCommand(int row, int column) { + FillCommand(int row, int column, int type) { this.row = row; this.column = column; + this.type = type; } /*** Method overloaded from the class Command ***/ @@ -88,5 +93,14 @@ int getColumn() { return this.column; } + + /** + * Return the type. + * + * @return type of the action + */ + int getType() { + return this.type; + } } Modified: trunk/src/picross/grid/PicrossGridController.java =================================================================== --- trunk/src/picross/grid/PicrossGridController.java 2007-06-06 08:27:54 UTC (rev 10) +++ trunk/src/picross/grid/PicrossGridController.java 2007-06-06 11:42:57 UTC (rev 11) @@ -69,6 +69,12 @@ /** 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. */ @@ -94,14 +100,16 @@ if (cmd.equals(PicrossGridController.CHECK_CMD)) { FillCommand command = (FillCommand) e.getCommand(); - this.view.check(command.getRow(), command.getColumn()); + 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()); + this.view.uncheck(command.getRow(), command.getColumn(), + command.getType()); return; } @@ -138,7 +146,7 @@ /** {@inheritDoc} */ public void mouseMoved(MouseEvent e) { } - /*** Method ***/ + /*** Methods ***/ /** * Checks if the mouse current click's location is inside the grid @@ -149,7 +157,11 @@ private void checkAndFill(MouseEvent e) { //PicrossGridController.log.debug(e); - if (e.getModifiers() != MouseEvent.BUTTON1_MASK) { + int modifiers = e.getModifiers(); + + if (modifiers != MouseEvent.BUTTON1_MASK + && modifiers != MouseEvent.BUTTON3_MASK) { + return; } @@ -158,12 +170,33 @@ if (this.view.isInGrid(point)) { int row = this.view.getRow(point); int column = this.view.getColumn(point); + int type = PicrossGridController.modifiersToType(modifiers); this.fireEventPerformed(PicrossGridController.FILL_CMD, - new FillCommand(row, column)); + 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.BUTTON2_MASK: + return PicrossGridController.CROSS_ACTION; + + default: + return -1; + } + } + /*** Accessor ***/ /** Modified: trunk/src/picross/grid/PicrossGridMediator.java =================================================================== --- trunk/src/picross/grid/PicrossGridMediator.java 2007-06-06 08:27:54 UTC (rev 10) +++ trunk/src/picross/grid/PicrossGridMediator.java 2007-06-06 11:42:57 UTC (rev 11) @@ -93,7 +93,8 @@ if (cmd.equals(PicrossGridController.FILL_CMD)) { FillCommand command = (FillCommand) e.getCommand(); - this.model.checkBox(command.getRow(), command.getColumn()); + this.model.checkBox(command.getRow(), command.getColumn(), + command.getType()); return; } @@ -117,9 +118,9 @@ * @param row row of the box * @param column column of the box */ - void check(int row, int column) { + void check(int row, int column, int type) { this.fireEventPerformed(PicrossGridController.CHECK_CMD, - new FillCommand(row, column)); + new FillCommand(row, column, type)); } /** @@ -128,9 +129,9 @@ * @param row row of the box * @param column column of the box */ - void uncheck(int row, int column) { + void uncheck(int row, int column, int type) { this.fireEventPerformed(PicrossGridController.UNCHECK_CMD, - new FillCommand(row, column)); + new FillCommand(row, column, type)); } /*** Accessor ***/ Modified: trunk/src/picross/grid/PicrossGridModel.java =================================================================== --- trunk/src/picross/grid/PicrossGridModel.java 2007-06-06 08:27:54 UTC (rev 10) +++ trunk/src/picross/grid/PicrossGridModel.java 2007-06-06 11:42:57 UTC (rev 11) @@ -63,13 +63,13 @@ private boolean[][] data; /** The grid as filled by the user. */ - private DummyBoolean[][] checked; + private Box[][] boxes; /** * The last modified box. Permis to know if we are in a serie or * a single action. */ - private DummyBoolean lastChecked = null; + private Box lastModified = null; /** Columns hints. */ private int[][] colData; @@ -89,11 +89,11 @@ this.mediator = mediator; this.data = data; - this.checked = new DummyBoolean[this.data.length][this.data[0].length]; + this.boxes = new Box[this.data.length][this.data[0].length]; - for (int i = 0; i < this.checked.length; i++) { - for (int j = 0; j < this.checked[i].length; j++) { - this.checked[i][j] = new DummyBoolean(false); + 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(); } } @@ -233,7 +233,7 @@ * @param row row of the box * @param column column of the box */ - void checkBox(int row, int column) { + void checkBox(int row, int column, int type) { //PicrossGridModel.log.debug("checkBox(" + row + ", " + column + ")"); //PicrossGridModel.log.debug("lastChecked == null : " // + (lastChecked == null)); @@ -242,42 +242,42 @@ * If we are trying to check the last box we just checked * (while dragging), do nothing */ - if (this.lastChecked != null - && this.lastChecked == this.checked[row][column]) { + if (this.lastModified != null + && this.lastModified == this.boxes[row][column]) { return; } - boolean currentValue = this.checked[row][column].getValue(); - - /* - * The value of the last checked box tells us if we are in - * a checks serie or a uncheck serie - */ - boolean lastValue = false; - - if (this.lastChecked != null) { - lastValue = this.lastChecked.getValue(); - + 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 (currentValue == lastValue) { + if (this.boxes[row][column].equals(this.lastModified)) { return; } } - if (!currentValue && (this.lastChecked == null || lastValue)) { - this.checked[row][column].setValue(true); - this.mediator.check(row, column); - } else if (currentValue && (this.lastChecked == null || !lastValue)) { - this.checked[row][column].setValue(false); - this.mediator.uncheck(row, column); + if (this.boxes[row][column].isEmpty() + && (this.lastModified == null || !this.lastModified.isEmpty())) { + + if (type == PicrossGridController.CHECK_ACTION) { + this.boxes[row][column].check(); + } else { //if (type == PicrossGridController.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())) { + this.boxes[row][column].empty(); + + this.mediator.uncheck(row, column, type); } - this.lastChecked = this.checked[row][column]; + this.lastModified = this.boxes[row][column]; this.checkCompleted(); } @@ -287,7 +287,7 @@ for (int i = 0; i < this.data.length; i++) { for (int j = 0; j < this.data[i].length; j++) { - if (this.data[i][j] != this.checked[i][j].getValue()) { + if (this.data[i][j] && !this.boxes[i][j].isChecked()) { completed = false; break; } @@ -301,7 +301,8 @@ /** Indicates the current action has come to an end. */ void endAction() { - this.lastChecked = null; + //this.lastChecked = null; + this.lastModified = null; } /*** Accessors ***/ @@ -323,49 +324,5 @@ int[][] getRowData() { return this.rowData; } - - /** - * This class is a wrapper for boolean, allowing us to do reference - * comparisons. - * - * @author Y. Norsa - */ - private static final class DummyBoolean { - /*** Field ***/ - - /** The value being held. */ - private boolean value; - - /*** Constructor ***/ - - /** - * Constructor. - * - * @param value the value to hold - */ - private DummyBoolean(boolean value) { - this.value = value; - } - - /*** Accessors ***/ - - /** - * Returns the value. - * - * @return held value - */ - private boolean getValue() { - return this.value; - } - - /** - * Allows to set the value. - * - * @param value new value to hold - */ - private void setValue(boolean value) { - this.value = value; - } - } } Modified: trunk/src/picross/grid/PicrossGridUI.java =================================================================== --- trunk/src/picross/grid/PicrossGridUI.java 2007-06-06 08:27:54 UTC (rev 10) +++ trunk/src/picross/grid/PicrossGridUI.java 2007-06-06 11:42:57 UTC (rev 11) @@ -111,8 +111,8 @@ /** Position of the bottom end of the grid. */ private int bottomBoundary; - /** Filled boxes. */ - private boolean[][] filled; + /** Current state of the grid. */ + private Box[][] boxes; /** Controller attached to this view. */ private transient PicrossGridController controller; @@ -148,8 +148,14 @@ this.colData = colData; this.rowData = rowData; - this.filled = new boolean[this.width][this.height]; + 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; @@ -218,23 +224,7 @@ x = this.leftBoundary; for (int j = 0; j < this.width; j++) { - if (this.filled[i][j]) { - g.setColor(Color.BLACK); - g.fillRect(x, y, - PicrossGridUI.BOX_WIDTH, - PicrossGridUI.BOX_HEIGHT); - } else { - g.setColor(Color.BLACK); - g.drawRect(x, y, - PicrossGridUI.BOX_WIDTH, - PicrossGridUI.BOX_HEIGHT); - - g.setColor(Color.WHITE); - g.fillRect(x + 1, y + 1, - PicrossGridUI.BOX_WIDTH - 1, - PicrossGridUI.BOX_HEIGHT - 1); - } - + g.drawImage(this.boxes[i][j].getImage(), x, y, null); x += PicrossGridUI.BOX_WIDTH; } @@ -297,8 +287,8 @@ * @param row row of the box * @param column column of the box */ - void check(int row, int column) { - this.setBoxState(row, column, true); + void check(int row, int column, int type) { + this.setBoxState(row, column, true, type); } /** @@ -307,8 +297,8 @@ * @param row row of the box * @param column column of the box */ - void uncheck(int row, int column) { - this.setBoxState(row, column, false); + void uncheck(int row, int column, int type) { + this.setBoxState(row, column, false, type); } /** @@ -318,8 +308,17 @@ * @param column column of the box * @param state new state of the box */ - private void setBoxState(int row, int column, boolean state) { - this.filled[row][column] = state; + private void setBoxState(int row, int column, boolean state, int type) { + if (!state) { + this.boxes[row][column].empty(); + } else { + if (type == PicrossGridController.CHECK_ACTION) { + this.boxes[row][column].check(); + } else { //if (type == PicrossGridController.CROSS_ACTION) { + this.boxes[row][column].cross(); + } + } + this.repaint(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |