Thread: [Picross-commit] SF.net SVN: picross: [7] trunk/src/picross/grid
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2007-06-05 08:52:11
|
Revision: 7 http://picross.svn.sourceforge.net/picross/?rev=7&view=rev Author: yvan_norsa Date: 2007-06-05 01:52:12 -0700 (Tue, 05 Jun 2007) Log Message: ----------- handles mouse drags Modified Paths: -------------- trunk/src/picross/grid/PicrossGridController.java trunk/src/picross/grid/PicrossGridUI.java Modified: trunk/src/picross/grid/PicrossGridController.java =================================================================== --- trunk/src/picross/grid/PicrossGridController.java 2007-06-05 08:35:50 UTC (rev 6) +++ trunk/src/picross/grid/PicrossGridController.java 2007-06-05 08:52:12 UTC (rev 7) @@ -40,6 +40,7 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; import org.apache.log4j.Logger; @@ -48,7 +49,8 @@ * * @author Y. Norsa */ -class PicrossGridController extends Controller implements MouseListener { +class PicrossGridController extends Controller implements MouseListener, + MouseMotionListener { /*** Constant ***/ /** Fill command. */ @@ -75,17 +77,7 @@ /** {@inheritDoc} */ public void mouseClicked(MouseEvent e) { - Point point = e.getPoint(); - - if (this.view.isInGrid(point)) { - int row = this.view.getRow(point); - int column = this.view.getColumn(point); - - this.fireEventPerformed(PicrossGridController.FILL_CMD, - new FillCommand(row, column)); - - this.view.fillBox(row, column); - } + this.checkAndFill(e); } /** {@inheritDoc} */ @@ -100,6 +92,38 @@ /** {@inheritDoc} */ public void mouseReleased(MouseEvent e) { } + /*** Methods implanted from the interface MouseMotionListener ***/ + + /** {@inheritDoc} */ + public void mouseDragged(MouseEvent e) { + this.checkAndFill(e); + } + + /** {@inheritDoc} */ + public void mouseMoved(MouseEvent e) { } + + /*** Method ***/ + + /** + * 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) { + Point point = e.getPoint(); + + if (this.view.isInGrid(point)) { + int row = this.view.getRow(point); + int column = this.view.getColumn(point); + + this.fireEventPerformed(PicrossGridController.FILL_CMD, + new FillCommand(row, column)); + + this.view.fillBox(row, column); + } + } + /*** Accessor ***/ /** Modified: trunk/src/picross/grid/PicrossGridUI.java =================================================================== --- trunk/src/picross/grid/PicrossGridUI.java 2007-06-05 08:35:50 UTC (rev 6) +++ trunk/src/picross/grid/PicrossGridUI.java 2007-06-05 08:52:12 UTC (rev 7) @@ -38,8 +38,6 @@ import java.awt.Graphics; import java.awt.Point; -import java.awt.event.MouseListener; - import javax.swing.JPanel; import org.apache.log4j.Logger; @@ -125,14 +123,16 @@ * @param height grid height * @param colData columns hints * @param rowData rows hints + * @param controller controller for the grid */ PicrossGridUI(int width, int height, int[][] colData, int[][] rowData, - MouseListener controller) { + PicrossGridController controller) { super(); this.addMouseListener(controller); + this.addMouseMotionListener(controller); this.setOpaque(true); this.setBackground(Color.WHITE); @@ -157,6 +157,9 @@ this.bottomBoundary = this.topBoundary + (this.height * PicrossGridUI.BOX_HEIGHT); + PicrossGridUI.log.debug("rightBoundary : " + this.rightBoundary); + PicrossGridUI.log.debug("bottomBoundary : " + this.bottomBoundary); + this.setPreferredSize(new Dimension(this.rightBoundary + PicrossGridUI.RIGHT_SPACE, this.bottomBoundary @@ -236,11 +239,13 @@ * @return boolean telling if the point is inside the grid */ boolean isInGrid(Point point) { + //PicrossGridUI.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); + return (x >= this.leftBoundary && x < this.rightBoundary + && y >= this.topBoundary && y < this.bottomBoundary); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-05 14:44:54
|
Revision: 9 http://picross.svn.sourceforge.net/picross/?rev=9&view=rev Author: yvan_norsa Date: 2007-06-05 07:44:56 -0700 (Tue, 05 Jun 2007) Log Message: ----------- disable the grid at the end; allows to uncheck boxes Modified Paths: -------------- 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/grid/PicrossGridController.java =================================================================== --- trunk/src/picross/grid/PicrossGridController.java 2007-06-05 11:32:56 UTC (rev 8) +++ trunk/src/picross/grid/PicrossGridController.java 2007-06-05 14:44:56 UTC (rev 9) @@ -60,6 +60,11 @@ /** Command indicating the grid is filled. */ public static final String GRID_FILLED_CMD = "GRID_FILLED_CMD"; + static final String END_ACTION_CMD = "END_ACTION_CMD"; + + static final String CHECK_CMD = "CHECK_CMD"; + static final String UNCHECK_CMD = "UNCHECK_CMD"; + /*** Static field ***/ /** The class' logger. */ @@ -75,6 +80,27 @@ /** {@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()); + + return; + } + + if (cmd.equals(PicrossGridController.UNCHECK_CMD)) { + FillCommand command = (FillCommand) e.getCommand(); + this.view.uncheck(command.getRow(), command.getColumn()); + + return; + } } /*** Methods implanted from the interface MouseListener ***/ @@ -94,7 +120,10 @@ public void mousePressed(MouseEvent e) { } /** {@inheritDoc} */ - public void mouseReleased(MouseEvent e) { } + public void mouseReleased(MouseEvent e) { + PicrossGridController.log.debug("mouseReleased()"); + this.fireEventPerformed(PicrossGridController.END_ACTION_CMD); + } /*** Methods implanted from the interface MouseMotionListener ***/ @@ -115,16 +144,20 @@ * @param e mouse event to handle */ private void checkAndFill(MouseEvent e) { + //PicrossGridController.log.debug(e); + + if (e.getModifiers() != MouseEvent.BUTTON1_MASK) { + return; + } + Point point = e.getPoint(); if (this.view.isInGrid(point)) { int row = this.view.getRow(point); int column = this.view.getColumn(point); - + this.fireEventPerformed(PicrossGridController.FILL_CMD, new FillCommand(row, column)); - - this.view.fillBox(row, column); } } Modified: trunk/src/picross/grid/PicrossGridMediator.java =================================================================== --- trunk/src/picross/grid/PicrossGridMediator.java 2007-06-05 11:32:56 UTC (rev 8) +++ trunk/src/picross/grid/PicrossGridMediator.java 2007-06-05 14:44:56 UTC (rev 9) @@ -38,7 +38,7 @@ import javax.swing.JPanel; -import org.apache.log4j.Logger; +//import org.apache.log4j.Logger; /** * Picross grid mediator. @@ -49,7 +49,7 @@ /*** Static field ***/ /** Class' logger. */ - private static Logger log = Logger.getLogger(PicrossGridMediator.class); + //private static Logger log = Logger.getLogger(PicrossGridMediator.class); /*** Fields ***/ @@ -73,6 +73,7 @@ PicrossGridController controller = new PicrossGridController(); controller.addSimpleListener(this); + this.addSimpleListener(controller); this.view = new PicrossGridUI(width, height, this.model.getColData(), @@ -86,15 +87,21 @@ /** {@inheritDoc} */ public void eventPerformed(SimpleEvent e) { - PicrossGridMediator.log.debug("eventPerformed(" + 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()); - this.model.checkBox(command.getRow(), command.getColumn()); + return; } + + if (cmd.equals(PicrossGridController.END_ACTION_CMD)) { + this.model.endAction(); + return; + } } /*** Method ***/ @@ -104,6 +111,16 @@ this.fireEventPerformed(PicrossGridController.GRID_FILLED_CMD); } + void check(int row, int column) { + this.fireEventPerformed(PicrossGridController.CHECK_CMD, + new FillCommand(row, column)); + } + + void uncheck(int row, int column) { + this.fireEventPerformed(PicrossGridController.UNCHECK_CMD, + new FillCommand(row, column)); + } + /*** Accessor ***/ /** Modified: trunk/src/picross/grid/PicrossGridModel.java =================================================================== --- trunk/src/picross/grid/PicrossGridModel.java 2007-06-05 11:32:56 UTC (rev 8) +++ trunk/src/picross/grid/PicrossGridModel.java 2007-06-05 14:44:56 UTC (rev 9) @@ -58,7 +58,7 @@ private boolean[][] data; /** The grid as filled by the user. */ - private boolean[][] checked; + private Boolean[][] checked; /** Columns hints. */ private int[][] colData; @@ -66,6 +66,8 @@ /** Rows hints. */ private int[][] rowData; + private Boolean lastChecked = null; + /*** Constructor ***/ /** @@ -78,14 +80,18 @@ this.mediator = mediator; this.data = data; - this.checked = new boolean[this.data.length][this.data[0].length]; + this.checked = new Boolean[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] = Boolean.valueOf(false); + } + } + List<List<Integer>> colRawData = new ArrayList<List<Integer>>(); int max = 0; for (boolean[] col : data) { - //PicrossGridModel.log.debug("col.length : " + col.length); - List<Integer> current = new ArrayList<Integer>(); int chain = 0; @@ -105,8 +111,6 @@ current.add(0); } - //PicrossGridModel.log.debug("current : " + current); - int currentSize = current.size(); if (currentSize > max) { @@ -116,53 +120,20 @@ colRawData.add(current); } - //PicrossGridModel.log.debug("data.length : " + data.length); - //PicrossGridModel.log.debug("max : " + max); - this.colData = new int[data.length][max]; for (int i = 0; i < max; i++) { - //PicrossGridModel.log.debug("i = " + i); - for (int j = 0; j < colRawData.size(); j++) { - //PicrossGridModel.log.debug("colonne courante.size() : " - //+ colRawData.get(j).size()); - if (colRawData.get(j).size() >= (max - i)) { - //PicrossGridModel.log.debug("this.colData[" + j + "][" - //+ (max - 1 - i) + "] = " + "colData.get(" + j + ").get(" - //+ (colRawData.get(j).size() - max + i) + ") = " - //+ colRawData.get(j).get(colRawData.get(j).size() - //- max + i)); - this.colData[j][max - 1 - i] = colRawData.get(j).get(colRawData.get(j).size() - max + i); } else { - //PicrossGridModel.log.debug("this.colData[" + j + "][" - //+ (max - 1 - i) + "] = -1"); - this.colData[j][max - 1 - i] = -1; } } } - /* - System.out.println("this.colData : "); - - for (int i = this.colData[0].length - 1; i >= 0; i--) { - for (int j = 0; j < this.colData.length; j++) { - if (this.colData[j][i] == -1) { - System.out.print(" "); - } else { - System.out.print(this.colData[j][i]); - } - } - - System.out.println(""); - } - */ - /***/ List<List<Integer>> rowRawData = new ArrayList<List<Integer>>(); max = 0; @@ -192,58 +163,21 @@ max = currentSize; } - //PicrossGridModel.log.debug("current : " + current); rowRawData.add(current); } - /**/ - - //PicrossGridModel.log.debug("data.length : " + data[0].length); - //PicrossGridModel.log.debug("max : " + max); - this.rowData = new int[data[0].length][max]; for (int i = 0; i < max; i++) { - //PicrossGridModel.log.debug("i = " + i); - for (int j = 0; j < rowRawData.size(); j++) { - //PicrossGridModel.log.debug("j = " + j); - //PicrossGridModel.log.debug("ligne courante.size() : " - //+ rowRawData.get(j).size()); - if (rowRawData.get(j).size() >= (max - i)) { - //int index = max - 1 - i; int index = i - Math.abs(rowRawData.get(j).size() - max); - - //System.out.print("this.rowData[" + j + "][" + i + "] = " - //+ "rowRawData.get(" + j + ").get(" + index + ") = "); - //System.out.println(rowRawData.get(j).get(index)); - this.rowData[j][i] = rowRawData.get(j).get(index); } else { - //PicrossGridModel.log.debug("this.rowData[" + j + "][" - //+ i + "] = -1"); - this.rowData[j][i] = -1; } } } - - /* - System.out.println("this.rowData : "); - - for (int i = 0; i < this.rowData.length; i++) { - for (int j = 0; j < this.rowData[i].length; j++) { - if (this.rowData[i][j] == -1) { - System.out.print(" "); - } else { - System.out.print(this.rowData[i][j]); - } - } - - System.out.println(""); - } - */ } /*** Method ***/ @@ -255,22 +189,42 @@ * @param column column of the box */ void checkBox(int row, int column) { - this.checked[row][column] = true; + if (this.lastChecked == null || + !this.lastChecked.equals(this.checked[row][column])) { - boolean completed = true; + if (!this.checked[row][column]) { + //PicrossGridModel.log.debug("checking " + row + "," + column); - 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]) { - completed = false; - break; + this.checked[row][column] = true; + this.lastChecked = this.checked[row][column]; + + this.mediator.check(row, column); + + boolean completed = true; + + 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]) { + completed = false; + break; + } + } } + + if (completed) { + this.mediator.congratulations(); + } + } else { + this.checked[row][column] = false; + this.lastChecked = this.checked[row][column]; + + this.mediator.uncheck(row, column); } } + } - if (completed) { - this.mediator.congratulations(); - } + void endAction() { + this.lastChecked = null; } /*** Accessors ***/ Modified: trunk/src/picross/grid/PicrossGridUI.java =================================================================== --- trunk/src/picross/grid/PicrossGridUI.java 2007-06-05 11:32:56 UTC (rev 8) +++ trunk/src/picross/grid/PicrossGridUI.java 2007-06-05 14:44:56 UTC (rev 9) @@ -114,6 +114,8 @@ /** Filled boxes. */ private boolean[][] filled; + private transient PicrossGridController controller; + /*** Constructor ***/ /** @@ -131,9 +133,11 @@ PicrossGridController controller) { super(); - this.addMouseListener(controller); - this.addMouseMotionListener(controller); + this.controller = controller; + this.addMouseListener(this.controller); + this.addMouseMotionListener(this.controller); + this.setOpaque(true); this.setBackground(Color.WHITE); @@ -214,13 +218,20 @@ 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); + PicrossGridUI.BOX_WIDTH, + PicrossGridUI.BOX_HEIGHT); + + g.setColor(Color.WHITE); + g.fillRect(x + 1, y + 1, + PicrossGridUI.BOX_WIDTH - 1, + PicrossGridUI.BOX_HEIGHT - 1); } x += PicrossGridUI.BOX_WIDTH; @@ -272,16 +283,20 @@ return (int) (x / PicrossGridUI.BOX_WIDTH); } + + void disableGrid() { + this.removeMouseListener(this.controller); + this.removeMouseMotionListener(this.controller); + } - /** - * Fills a box in the grid. - * - * @param row row of the box - * @param column column of the box - */ - void fillBox(int row, int column) { + void check(int row, int column) { this.filled[row][column] = true; this.repaint(); } + + void uncheck(int row, int column) { + this.filled[row][column] = false; + this.repaint(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2008-05-05 08:54:17
|
Revision: 74 http://picross.svn.sourceforge.net/picross/?rev=74&view=rev Author: yvan_norsa Date: 2008-05-05 01:54:15 -0700 (Mon, 05 May 2008) Log Message: ----------- code clean-up Modified Paths: -------------- trunk/src/picross/grid/GridController.java trunk/src/picross/grid/GridMediator.java Modified: trunk/src/picross/grid/GridController.java =================================================================== --- trunk/src/picross/grid/GridController.java 2008-05-05 08:53:08 UTC (rev 73) +++ trunk/src/picross/grid/GridController.java 2008-05-05 08:54:15 UTC (rev 74) @@ -78,12 +78,6 @@ /** Command asking to enable the Erase mode. */ static final String ERASE_MODE_CMD = "ERASE_MODE_CMD"; - /** Checking a box. */ - //static final int CHECK_ACTION = 0; - - /** Crossing a box. */ - //static final int CROSS_ACTION = 1; - /*** Static field ***/ /** The class' logger. */ @@ -224,7 +218,6 @@ if (this.eraseMode) { type = GridAction.EMPTY; } else { - //int type = GridController.modifiersToType(modifiers); type = GridController.modifiersToType(modifiers); } @@ -245,19 +238,15 @@ * @param modifiers mouse event modifiers * @return corresponding action, or -1 */ - //private static int modifiersToType(int modifiers) { private static GridAction modifiersToType(int modifiers) { switch (modifiers) { case MouseEvent.BUTTON1_MASK: - //return GridController.CHECK_ACTION; return GridAction.CHECK; case MouseEvent.BUTTON3_MASK: - //return GridController.CROSS_ACTION; return GridAction.CROSS; default: - //return -1; return GridAction.UNKNOWN; } } Modified: trunk/src/picross/grid/GridMediator.java =================================================================== --- trunk/src/picross/grid/GridMediator.java 2008-05-05 08:53:08 UTC (rev 73) +++ trunk/src/picross/grid/GridMediator.java 2008-05-05 08:54:15 UTC (rev 74) @@ -141,29 +141,28 @@ /*** Methods implanted from the interface IGridMediator ***/ - /** Tells the application mediator the grid has been filled. */ + /** {@inheritDoc} */ + @Override public void congratulations() { this.fireEventPerformed(GridController.GRID_FILLED_CMD); } - /** - * Asks to repaint a box. - * - * @param row row number of the box - * @param column column number of the box - */ + /** {@inheritDoc} */ + @Override public void repaint(int row, int column) { this.fireEventPerformed(GridController.PAINT_CMD, new PaintCommand(row, column)); } - /** Asks to repaint the column hints. */ + /** {@inheritDoc} */ + @Override public void repaintColHints(int column) { this.fireEventPerformed(//GridController.REPAINT_TOP_HINTS_CMD); new RepaintTopHintsCommand(column)); } - /** Asks to repaint the row hints. */ + /** {@inheritDoc} */ + @Override public void repaintRowHints(int row) { this.fireEventPerformed(//GridController.REPAINT_LEFT_HINTS_CMD); new RepaintLeftHintsCommand(row)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-06 12:07:45
|
Revision: 12 http://picross.svn.sourceforge.net/picross/?rev=12&view=rev Author: yvan_norsa Date: 2007-06-06 05:07:47 -0700 (Wed, 06 Jun 2007) Log Message: ----------- allows to directly cross a checked box and vice-versa Modified Paths: -------------- trunk/src/picross/grid/PicrossGridController.java trunk/src/picross/grid/PicrossGridModel.java Modified: trunk/src/picross/grid/PicrossGridController.java =================================================================== --- trunk/src/picross/grid/PicrossGridController.java 2007-06-06 11:42:57 UTC (rev 11) +++ trunk/src/picross/grid/PicrossGridController.java 2007-06-06 12:07:47 UTC (rev 12) @@ -172,6 +172,8 @@ 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)); @@ -189,7 +191,7 @@ case MouseEvent.BUTTON1_MASK: return PicrossGridController.CHECK_ACTION; - case MouseEvent.BUTTON2_MASK: + case MouseEvent.BUTTON3_MASK: return PicrossGridController.CROSS_ACTION; default: Modified: trunk/src/picross/grid/PicrossGridModel.java =================================================================== --- trunk/src/picross/grid/PicrossGridModel.java 2007-06-06 11:42:57 UTC (rev 11) +++ trunk/src/picross/grid/PicrossGridModel.java 2007-06-06 12:07:47 UTC (rev 12) @@ -36,7 +36,7 @@ import java.util.ArrayList; import java.util.List; -//import org.apache.log4j.Logger; +import org.apache.log4j.Logger; /** * The grid model. @@ -52,7 +52,7 @@ /*** Static field ***/ /** The class' logger. */ - //private static Logger log = Logger.getLogger(PicrossGridModel.class); + private static Logger log = Logger.getLogger(PicrossGridModel.class); /*** Fields ***/ @@ -234,9 +234,9 @@ * @param column column of the box */ void checkBox(int row, int column, int type) { - //PicrossGridModel.log.debug("checkBox(" + row + ", " + column + ")"); - //PicrossGridModel.log.debug("lastChecked == null : " - // + (lastChecked == null)); + PicrossGridModel.log.debug("checkBox(" + row + ", " + column + ")"); + //PicrossGridModel.log.debug("lastModified == null : " + // + (lastModified == null)); /* * If we are trying to check the last box we just checked @@ -264,6 +264,7 @@ if (type == PicrossGridController.CHECK_ACTION) { this.boxes[row][column].check(); + this.checkCompleted(); } else { //if (type == PicrossGridController.CROSS_ACTION) { this.boxes[row][column].cross(); } @@ -272,13 +273,36 @@ } else if (!this.boxes[row][column].isEmpty() && (this.lastModified == null || this.lastModified.isEmpty())) { - this.boxes[row][column].empty(); - this.mediator.uncheck(row, column, type); + if (this.boxes[row][column].isChecked()) { + //PicrossGridModel.log.debug("checked"); + + if (type == PicrossGridController.CHECK_ACTION) { + this.boxes[row][column].empty(); + this.mediator.uncheck(row, column, type); + } else { //if (type == PicrossGridController.CROSS_ACTION) { + this.boxes[row][column].cross(); + this.mediator.check(row, column, + PicrossGridController.CROSS_ACTION); + } + } else { //if (this.boxes[row][column].isCrossed())\xA0{ + //PicrossGridModel.log.debug("crossed"); + + if (type == PicrossGridController.CROSS_ACTION) { + this.boxes[row][column].empty(); + this.mediator.uncheck(row, column, type); + } else { + //PicrossGridModel.log.debug("check()"); + + this.boxes[row][column].check(); + this.mediator.check(row, column, + PicrossGridController.CHECK_ACTION); + this.checkCompleted(); + } + } } this.lastModified = this.boxes[row][column]; - this.checkCompleted(); } /** Checks wether the grid is finished. */ 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...> - 2008-04-17 08:50:17
|
Revision: 47 http://picross.svn.sourceforge.net/picross/?rev=47&view=rev Author: yvan_norsa Date: 2008-04-17 01:50:24 -0700 (Thu, 17 Apr 2008) Log Message: ----------- EDT stuff Modified Paths: -------------- trunk/src/picross/grid/GridMediator.java trunk/src/picross/grid/GridUI.java Modified: trunk/src/picross/grid/GridMediator.java =================================================================== --- trunk/src/picross/grid/GridMediator.java 2008-04-16 10:44:37 UTC (rev 46) +++ trunk/src/picross/grid/GridMediator.java 2008-04-17 08:50:24 UTC (rev 47) @@ -38,6 +38,8 @@ import java.io.FileNotFoundException; +import java.lang.reflect.InvocationTargetException; + import javax.swing.JPanel; import javax.swing.SwingUtilities; @@ -89,27 +91,29 @@ final CompletedHints hints = this.model.getCompletedHints(); try { - SwingUtilities.invokeLater(new Runnable() { + SwingUtilities.invokeAndWait(new Runnable() { public void run() { - try { - GridMediator.this.view = new GridUI(width, height, - boxes, - colData, - rowData, - hints, - controller); - } catch (FileNotFoundException fileEx) { - //throw new PicrossException(fileEx); - throw new - RuntimeException(new PicrossException(fileEx)); - } - - controller.setView(GridMediator.this.view); + GridMediator.this.view = new GridUI(width, height, + boxes, + colData, + rowData, + hints, + controller); } }); - } catch (RuntimeException runtimeEx) { - throw ((PicrossException) runtimeEx.getCause()); + } catch (InterruptedException intEx) { + intEx.printStackTrace(); + } catch (InvocationTargetException targetEx) { + targetEx.printStackTrace(); } + + try { + this.view.init(); + } catch (FileNotFoundException fileEx) { + throw new PicrossException(fileEx); + } + + controller.setView(this.view); } /*** Method overloaded from the class Mediateur ***/ Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2008-04-16 10:44:37 UTC (rev 46) +++ trunk/src/picross/grid/GridUI.java 2008-04-17 08:50:24 UTC (rev 47) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (c) 2007 + * Copyright (c) 2007-2008 * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, @@ -214,14 +214,13 @@ * @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) throws FileNotFoundException { + GridController controller) { super(true); this.controller = controller; @@ -240,6 +239,67 @@ this.completedHints = completedHints; + // Contain the state of the grid + this.boxes = boxes; + } + + /*** Method overloaded from JPanel ***/ + + /** {@inheritDoc} */ + protected void paintComponent(Graphics g) { + super.paintComponent(g); + + Graphics2D newG = (Graphics2D) g.create(); + + Rectangle clipRect = newG.getClipBounds(); + + if (this.topHintsRect.intersects(clipRect)) { + this.drawTopHints(newG); + } + + if (this.leftHintsRect.intersects(clipRect)) { + 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); + + 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, newG, + currentRect.x, currentRect.y); + } else { + this.boxes[i][j].getIcon().paintIcon(this, newG, + currentRect.x, + currentRect.y); + } + } + } + } + + // Draws the blocks + newG.setColor(GridUI.BLOCKS_COLOR); + + for (Line2D line : this.blocksLines) { + newG.draw(line); + } + + newG.dispose(); + } + + /*** Methods ***/ + + /** + * Initializes various stuff. + * + * @throws FileNotFoundException if an image is missing + */ + void init() throws FileNotFoundException { // Computes the size of a hint FontRenderContext frc = new FontRenderContext(null, true, true); @@ -299,9 +359,6 @@ this.centerHighHintWidth = (hintBoxWidth / 2) - (highHintWidth / 2); - // Contain the state of the grid - this.boxes = boxes; - for (int i = 0; i < this.width; i++) { for (int j = 0; j < this.height; j++) { /* @@ -332,57 +389,6 @@ + GridUI.BOTTOM_SPACE)); } - /*** Method overloaded from JPanel ***/ - - /** {@inheritDoc} */ - protected void paintComponent(Graphics g) { - super.paintComponent(g); - - Graphics2D newG = (Graphics2D) g.create(); - - Rectangle clipRect = newG.getClipBounds(); - - if (this.topHintsRect.intersects(clipRect)) { - this.drawTopHints(newG); - } - - if (this.leftHintsRect.intersects(clipRect)) { - 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); - - 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, newG, - currentRect.x, currentRect.y); - } else { - this.boxes[i][j].getIcon().paintIcon(this, newG, - currentRect.x, - currentRect.y); - } - } - } - } - - // 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>(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2008-04-18 12:58:01
|
Revision: 56 http://picross.svn.sourceforge.net/picross/?rev=56&view=rev Author: yvan_norsa Date: 2008-04-18 05:58:07 -0700 (Fri, 18 Apr 2008) Log Message: ----------- marks empty rows and columns as completed Modified Paths: -------------- trunk/src/picross/grid/CompletedHints.java trunk/src/picross/grid/GridModel.java Modified: trunk/src/picross/grid/CompletedHints.java =================================================================== --- trunk/src/picross/grid/CompletedHints.java 2008-04-18 11:55:47 UTC (rev 55) +++ trunk/src/picross/grid/CompletedHints.java 2008-04-18 12:58:07 UTC (rev 56) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (c) 2007 + * Copyright (c) 2007-2008 * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, @@ -152,6 +152,17 @@ } /** + * Marks a whole column as complete. + * + * @param col column number + */ + void setCompleteCol(int col) { + for (int i = 0; i < this.completedCols[col].length; i++) { + this.setCompleteColHint(col, i); + } + } + + /** * Tells wether a specific row hint is complete. * * @param x row number @@ -190,7 +201,6 @@ return res; } - /** * Resets the state of a hint. * @@ -210,5 +220,16 @@ void setCompleteRowHint(int row, int index) { this.completedRows[row][index] = true; } + + /** + * Marks a whole row as complete. + * + * @param row row number + */ + void setCompleteRow(int row) { + for (int i = 0; i < this.completedRows[row].length; i++) { + this.setCompleteRowHint(row, i); + } + } } Modified: trunk/src/picross/grid/GridModel.java =================================================================== --- trunk/src/picross/grid/GridModel.java 2008-04-18 11:55:47 UTC (rev 55) +++ trunk/src/picross/grid/GridModel.java 2008-04-18 12:58:07 UTC (rev 56) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (c) 2007 + * Copyright (c) 2007-2008 * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, @@ -36,7 +36,7 @@ import java.util.ArrayList; import java.util.List; -//import org.apache.log4j.Logger; +import org.apache.log4j.Logger; /** * The grid model. @@ -52,7 +52,7 @@ /*** Static field ***/ /** The class' logger. */ - //private static Logger log = Logger.getLogger(GridModel.class); + private static Logger log = Logger.getLogger(GridModel.class); /*** Fields ***/ @@ -260,6 +260,20 @@ this.completedHints = new CompletedHints(data.length, this.colData[0].length, data[0].length, this.rowData[0].length); + + // Marks the empty rows and columns as completed + + for (int i = 0; i < this.rowData.length; i++) { + if (this.emptyRow(i)) { + this.completedHints.setCompleteRow(i); + } + } + + for (int i = 0; i < this.colData.length; i++) { + if (this.emptyCol(i)) { + this.completedHints.setCompleteCol(i); + } + } } /*** Static methods ***/ @@ -414,11 +428,29 @@ } /** + * Checks if a row is empty. + * + * @param row row number + * @return boolean stating wether the row is empty or not + */ + private boolean emptyRow(int row) { + int index = this.getFirstHintIndex(this.rowData[row]); + + return (index == this.getLastHintIndex(this.rowData[row])) + && (this.rowData[row][index] == 0); + } + + /** * Checks if a hint has been completed in a row. * * @param row row number to check */ private void checkRow(int row) { + if (this.emptyRow(row)) { + this.completedHints.setCompleteRow(row); + return; + } + // Contains the completed hints List<Integer> completedRowHints = new ArrayList<Integer>(); @@ -553,6 +585,19 @@ } /** + * Checks if a column is empty. + * + * @param col column number + * @return boolean stating wether the column is empty or not + */ + private boolean emptyCol(int col) { + int index = this.getFirstHintIndex(this.colData[col]); + + return (index == this.getLastHintIndex(this.colData[col])) + && (this.colData[col][index] == 0); + } + + /** * Checks if a hint has been completed in a column. * * @param column column number to check @@ -560,6 +605,11 @@ private void checkColumn(int column) { //GridModel.log.debug("checkColumn(" + column + ")"); + if (this.emptyCol(column)) { + this.completedHints.setCompleteCol(column); + return; + } + List<Integer> completedColHints = new ArrayList<Integer>(); /* for (int i = 0; i < this.colData[column].length; i++) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2008-04-22 12:29:54
|
Revision: 59 http://picross.svn.sourceforge.net/picross/?rev=59&view=rev Author: yvan_norsa Date: 2008-04-22 05:23:45 -0700 (Tue, 22 Apr 2008) Log Message: ----------- wrong copyright Modified Paths: -------------- trunk/src/picross/grid/RepaintLeftHintsCommand.java trunk/src/picross/grid/RepaintTopHintsCommand.java Modified: trunk/src/picross/grid/RepaintLeftHintsCommand.java =================================================================== --- trunk/src/picross/grid/RepaintLeftHintsCommand.java 2008-04-22 12:18:30 UTC (rev 58) +++ trunk/src/picross/grid/RepaintLeftHintsCommand.java 2008-04-22 12:23:45 UTC (rev 59) @@ -1,45 +1,33 @@ /* * $Id$ - * \xC9crit le 22/04/2008 par Y. Norsa * * Copyright (c) 2008 - * 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. */ Modified: trunk/src/picross/grid/RepaintTopHintsCommand.java =================================================================== --- trunk/src/picross/grid/RepaintTopHintsCommand.java 2008-04-22 12:18:30 UTC (rev 58) +++ trunk/src/picross/grid/RepaintTopHintsCommand.java 2008-04-22 12:23:45 UTC (rev 59) @@ -1,45 +1,33 @@ /* * $Id$ - * \xC9crit le 22/04/2008 par Y. Norsa * * Copyright (c) 2008 - * 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...> - 2008-04-23 19:13:54
|
Revision: 63 http://picross.svn.sourceforge.net/picross/?rev=63&view=rev Author: yvan_norsa Date: 2008-04-23 12:13:48 -0700 (Wed, 23 Apr 2008) Log Message: ----------- fixed rollover and highlight end conditions Modified Paths: -------------- trunk/src/picross/grid/GridController.java trunk/src/picross/grid/GridUI.java Modified: trunk/src/picross/grid/GridController.java =================================================================== --- trunk/src/picross/grid/GridController.java 2008-04-23 16:40:40 UTC (rev 62) +++ trunk/src/picross/grid/GridController.java 2008-04-23 19:13:48 UTC (rev 63) @@ -42,7 +42,7 @@ import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; -//import org.apache.log4j.Logger; +import org.apache.log4j.Logger; /** * Grid controller. @@ -84,7 +84,7 @@ /*** Static field ***/ /** The class' logger. */ - //private static Logger log = Logger.getLogger(GridController.class); + private static Logger log = Logger.getLogger(GridController.class); /*** Field ***/ @@ -133,7 +133,11 @@ public void mouseEntered(MouseEvent e) { } /** {@inheritDoc} */ - public void mouseExited(MouseEvent e) { } + public void mouseExited(MouseEvent e) { + //GridController.log.debug("mouseExited()"); + this.view.rolloverEnded(); + this.view.highlightEnded(); + } /** {@inheritDoc} */ public void mousePressed(MouseEvent e) { @@ -203,6 +207,8 @@ new FillCommand(row, column, type)); this.view.rolloverHighlight(row, column); + } else { + this.view.highlightEnded(); } } Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2008-04-23 16:40:40 UTC (rev 62) +++ trunk/src/picross/grid/GridUI.java 2008-04-23 19:13:48 UTC (rev 63) @@ -703,8 +703,18 @@ this.rollover = null; this.repaint(rect); } + + this.highlightEnded(); } + void highlightEnded() { + this.repaintColHints(this.rolloverColumn); + this.repaintRowHints(this.rolloverRow); + + this.rolloverColumn = -1; + this.rolloverRow = -1; + } + /** Repaints top hints. */ void repaintColHints(int col) { if (col < 0 || col >= this.width) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2008-05-05 08:53:37
|
Revision: 73 http://picross.svn.sourceforge.net/picross/?rev=73&view=rev Author: yvan_norsa Date: 2008-05-05 01:53:08 -0700 (Mon, 05 May 2008) Log Message: ----------- added erase mode Modified Paths: -------------- trunk/src/picross/grid/GridAction.java trunk/src/picross/grid/GridController.java trunk/src/picross/grid/GridMediator.java trunk/src/picross/grid/GridModel.java trunk/src/picross/grid/IGridMediator.java trunk/src/picross/grid/tests/IGridMediatorStub.java Modified: trunk/src/picross/grid/GridAction.java =================================================================== --- trunk/src/picross/grid/GridAction.java 2008-04-30 13:47:52 UTC (rev 72) +++ trunk/src/picross/grid/GridAction.java 2008-05-05 08:53:08 UTC (rev 73) @@ -46,6 +46,9 @@ CHECK, /** Crossing a box. */ - CROSS + CROSS, + + /** Erasing a box. */ + EMPTY } Modified: trunk/src/picross/grid/GridController.java =================================================================== --- trunk/src/picross/grid/GridController.java 2008-04-30 13:47:52 UTC (rev 72) +++ trunk/src/picross/grid/GridController.java 2008-05-05 08:53:08 UTC (rev 73) @@ -75,6 +75,9 @@ /** Command asking to repaint the left hints. */ static final String REPAINT_LEFT_HINTS_CMD = "REPAINT_LEFT_HINTS_CMD"; + /** Command asking to enable the Erase mode. */ + static final String ERASE_MODE_CMD = "ERASE_MODE_CMD"; + /** Checking a box. */ //static final int CHECK_ACTION = 0; @@ -86,11 +89,14 @@ /** The class' logger. */ //private static Logger log = Logger.getLogger(GridController.class); - /*** Field ***/ + /*** Fields ***/ /** The view to which the controller is attached. */ private GridUI view = null; + /** Indicates wether the erase mode is "on" or not. */ + private boolean eraseMode; + /*** Method overloaded from the class Controller ***/ /** {@inheritDoc} */ @@ -123,6 +129,11 @@ this.view.repaintRowHints(row); return; } + + if (cmd.equals(GridController.ERASE_MODE_CMD)) { + this.eraseMode = true; + return; + } } /*** Methods implanted from the interface MouseListener ***/ @@ -154,6 +165,7 @@ public void mouseReleased(MouseEvent e) { //GridController.log.debug("mouseReleased()"); this.checkAndFill(e); + this.eraseMode = false; this.fireEventPerformed(GridController.END_ACTION_CMD); } @@ -206,9 +218,16 @@ if (this.view.isInGrid(point)) { int row = this.view.getRow(point); int column = this.view.getColumn(point); - //int type = GridController.modifiersToType(modifiers); - GridAction type = GridController.modifiersToType(modifiers); + GridAction type = GridAction.UNKNOWN; + + if (this.eraseMode) { + type = GridAction.EMPTY; + } else { + //int type = GridController.modifiersToType(modifiers); + type = GridController.modifiersToType(modifiers); + } + //GridController.log.debug("type : " + type); this.fireEventPerformed(GridController.FILL_CMD, Modified: trunk/src/picross/grid/GridMediator.java =================================================================== --- trunk/src/picross/grid/GridMediator.java 2008-04-30 13:47:52 UTC (rev 72) +++ trunk/src/picross/grid/GridMediator.java 2008-05-05 08:53:08 UTC (rev 73) @@ -169,6 +169,12 @@ new RepaintLeftHintsCommand(row)); } + /** {@inheritDoc} */ + @Override + public void setEraseMode() { + this.fireEventPerformed(GridController.ERASE_MODE_CMD); + } + /*** Accessor ***/ /** Modified: trunk/src/picross/grid/GridModel.java =================================================================== --- trunk/src/picross/grid/GridModel.java 2008-04-30 13:47:52 UTC (rev 72) +++ trunk/src/picross/grid/GridModel.java 2008-05-05 08:53:08 UTC (rev 73) @@ -418,6 +418,11 @@ } } + if (!this.boxes[column][row].isEmpty() && type == GridAction.EMPTY) { + this.boxes[column][row].empty(); + this.mediator.repaint(row, column); + } else { + if (this.boxes[column][row].isEmpty() && (this.lastModified == null || !this.lastModified.isEmpty())) { @@ -437,6 +442,7 @@ if (type == GridAction.CHECK) { this.boxes[column][row].empty(); + this.setEraseMode(); } else { //if (type == GridAction.CROSS) { this.boxes[column][row].cross(); } @@ -445,6 +451,7 @@ if (type == GridAction.CROSS) { this.boxes[column][row].empty(); + this.setEraseMode(); } else { //if (type == GridAction.CHECK) { //GridModel.log.debug("check()"); @@ -454,6 +461,7 @@ this.mediator.repaint(row, column); } + } this.lastModified = this.boxes[column][row]; this.checkColumn(column); @@ -461,6 +469,11 @@ this.checkCompleted(); } + /** Enables the erase mode. */ + private void setEraseMode() { + this.mediator.setEraseMode(); + } + /** * Checks if a row is empty. * Modified: trunk/src/picross/grid/IGridMediator.java =================================================================== --- trunk/src/picross/grid/IGridMediator.java 2008-04-30 13:47:52 UTC (rev 72) +++ trunk/src/picross/grid/IGridMediator.java 2008-05-05 08:53:08 UTC (rev 73) @@ -53,5 +53,8 @@ /** Tells the application mediator the grid has been filled. */ void congratulations(); + + /** Enables the erase mode. */ + void setEraseMode(); } Modified: trunk/src/picross/grid/tests/IGridMediatorStub.java =================================================================== --- trunk/src/picross/grid/tests/IGridMediatorStub.java 2008-04-30 13:47:52 UTC (rev 72) +++ trunk/src/picross/grid/tests/IGridMediatorStub.java 2008-05-05 08:53:08 UTC (rev 73) @@ -64,5 +64,7 @@ public void repaintRowHints(int row) { } public void congratulations() { } + + public void setEraseMode() { } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2008-05-07 13:37:14
|
Revision: 80 http://picross.svn.sourceforge.net/picross/?rev=80&view=rev Author: yvan_norsa Date: 2008-05-07 06:37:14 -0700 (Wed, 07 May 2008) Log Message: ----------- disable highlights on success Modified Paths: -------------- trunk/src/picross/grid/GridController.java trunk/src/picross/grid/GridUI.java Modified: trunk/src/picross/grid/GridController.java =================================================================== --- trunk/src/picross/grid/GridController.java 2008-05-07 09:47:16 UTC (rev 79) +++ trunk/src/picross/grid/GridController.java 2008-05-07 13:37:14 UTC (rev 80) @@ -101,7 +101,9 @@ String cmd = e.getCommandName(); if (cmd.equals(GridController.GRID_FILLED_CMD)) { + this.view.rolloverEnded(); this.view.disableGrid(); + return; } @@ -223,10 +225,10 @@ //GridController.log.debug("type : " + type); + this.view.rolloverHighlight(row, column); + this.fireEventPerformed(GridController.FILL_CMD, new FillCommand(row, column, type)); - - this.view.rolloverHighlight(row, column); } else { this.view.highlightEnded(); } Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2008-05-07 09:47:16 UTC (rev 79) +++ trunk/src/picross/grid/GridUI.java 2008-05-07 13:37:14 UTC (rev 80) @@ -523,6 +523,7 @@ */ private void drawTopHints(Graphics g, int col) { //GridUI.log.debug("drawTopHints(g, " + col + ")"); + //GridUI.log.debug("this.rolloverColumn = " + this.rolloverColumn); g.drawImage(this.topHints[col].getBox(), this.topHints[col].getX(), this.topHints[col].getY(), @@ -550,6 +551,9 @@ * @param g the graphics context */ private void drawLeftHints(Graphics g, int row) { + //GridUI.log.debug("drawLeftHints(g, " + row + ")"); + //GridUI.log.debug("this.rolloverRow = " + this.rolloverRow); + g.drawImage(this.leftHints[row].getBox(), this.leftHints[row].getX(), this.leftHints[row].getY(), null); @@ -685,6 +689,8 @@ * @param column column's index to highlight */ void rolloverHighlight(int row, int column) { + //GridUI.log.debug("rolloverHighlight(" + row + ", " + column + ")"); + if ((this.rolloverColumn != column) || (this.rolloverRow != row)) { this.repaintColHints(this.rolloverColumn); this.repaintRowHints(this.rolloverRow); @@ -715,6 +721,8 @@ /** Ends the highlight. */ void highlightEnded() { + //GridUI.log.debug("highlightEnded"); + this.repaintColHints(this.rolloverColumn); this.repaintRowHints(this.rolloverRow); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |