[Picross-commit] SF.net SVN: picross: [8] trunk
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2007-06-05 11:32:57
|
Revision: 8 http://picross.svn.sourceforge.net/picross/?rev=8&view=rev Author: yvan_norsa Date: 2007-06-05 04:32:56 -0700 (Tue, 05 Jun 2007) Log Message: ----------- displays a message when the grid is complete Modified Paths: -------------- trunk/bugsFilter.xml trunk/src/picross/PicrossMediator.java trunk/src/picross/PicrossUI.java trunk/src/picross/grid/FillCommand.java trunk/src/picross/grid/PicrossGridController.java trunk/src/picross/grid/PicrossGridMediator.java trunk/src/picross/grid/PicrossGridModel.java Added Paths: ----------- trunk/src/picross/PicrossController.java Modified: trunk/bugsFilter.xml =================================================================== --- trunk/bugsFilter.xml 2007-06-05 08:52:12 UTC (rev 7) +++ trunk/bugsFilter.xml 2007-06-05 11:32:56 UTC (rev 8) @@ -1,5 +1,5 @@ <FindBugsFilter> <Match classregex=".*"> - <Bug pattern="CLI_CONSTANT_LIST_INDEX,S508C_SET_COMP_COLOR" /> + <Bug pattern="LSC_LITERAL_STRING_COMPARISON,CLI_CONSTANT_LIST_INDEX,S508C_SET_COMP_COLOR" /> </Match> </FindBugsFilter> Added: trunk/src/picross/PicrossController.java =================================================================== --- trunk/src/picross/PicrossController.java (rev 0) +++ trunk/src/picross/PicrossController.java 2007-06-05 11:32:56 UTC (rev 8) @@ -0,0 +1,81 @@ +/* + * $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; + +import fr.cle.mmvcs.Controller; +import fr.cle.mmvcs.SimpleEvent; + +import org.apache.log4j.Logger; + +/** + * Application controller. + * + * @author Y. Norsa + */ +class PicrossController extends Controller { + /*** Static field ***/ + + /** The class's logger. */ + private static Logger log = Logger.getLogger(PicrossController.class); + + /*** Field ***/ + + /** The view to which this controller is attached. */ + private PicrossUI view = null; + + /*** Method overloaded from the class Controller ***/ + + /** {@inheritDoc} */ + public void eventPerformed(SimpleEvent e) { + PicrossController.log.debug("eventPerformed(" + e + ")"); + + String cmd = e.getCommandName(); + + if (cmd.equals(PicrossController.MESSAGE_CMD)) { + this.view.displayMessage(e.getComment()); + } + } + + /*** Accessor ***/ + + /** + * Allows to define the view. + * + * @param view the view to which this controller is to be attached + */ + void setView(PicrossUI view) { + this.view = view; + } +} + Property changes on: trunk/src/picross/PicrossController.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/PicrossMediator.java =================================================================== --- trunk/src/picross/PicrossMediator.java 2007-06-05 08:52:12 UTC (rev 7) +++ trunk/src/picross/PicrossMediator.java 2007-06-05 11:32:56 UTC (rev 8) @@ -38,6 +38,7 @@ import org.apache.log4j.Logger; +import picross.grid.PicrossGridController; import picross.grid.PicrossGridMediator; /** @@ -57,11 +58,17 @@ PicrossMediator() { PicrossModel model = new PicrossModel(); + PicrossController controller = new PicrossController(); + this.addSimpleListener(controller); + PicrossGridMediator grid = new PicrossGridMediator(model.getWidth(), model.getHeight(), model.getData()); + grid.addSimpleListener(this); - new PicrossUI(grid.getView()); + PicrossUI view = new PicrossUI(grid.getView()); + + controller.setView(view); } /*** Method overloaded from the Mediateur class ***/ @@ -69,6 +76,13 @@ /** {@inheritDoc} */ public void eventPerformed(SimpleEvent e) { PicrossMediator.log.debug("eventPerformed(" + e + ")"); + + String cmd = e.getCommandName(); + + if (cmd.equals(PicrossGridController.GRID_FILLED_CMD)) { + this.fireEventPerformed(PicrossController.MESSAGE_CMD, + "Congratulations"); + } } } Modified: trunk/src/picross/PicrossUI.java =================================================================== --- trunk/src/picross/PicrossUI.java 2007-06-05 08:52:12 UTC (rev 7) +++ trunk/src/picross/PicrossUI.java 2007-06-05 11:32:56 UTC (rev 8) @@ -34,7 +34,9 @@ package picross; import javax.swing.JFrame; +import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.SwingUtilities; /** * Main window. @@ -60,5 +62,51 @@ this.pack(); this.setVisible(true); } + + /*** Method ***/ + + /** + * Displays a message box. + * + * @param msg message to be displayed + */ + void displayMessage(String msg) { + SwingUtilities.invokeLater(new RunnableDialog(this, msg)); + } + + /** + * Inner class displaying a message asynchronously. + * + * @author Y. Norsa + */ + private static final class RunnableDialog implements Runnable { + /*** Fields ***/ + + /** Parent frame. */ + private JFrame parent; + + /** 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); + } + } } Modified: trunk/src/picross/grid/FillCommand.java =================================================================== --- trunk/src/picross/grid/FillCommand.java 2007-06-05 08:52:12 UTC (rev 7) +++ trunk/src/picross/grid/FillCommand.java 2007-06-05 11:32:56 UTC (rev 8) @@ -66,7 +66,7 @@ /** {@inheritDoc} */ public String toString() { - return this.row + ", " + this.column; + return this.row + "," + this.column; } /*** Accessors ***/ Modified: trunk/src/picross/grid/PicrossGridController.java =================================================================== --- trunk/src/picross/grid/PicrossGridController.java 2007-06-05 08:52:12 UTC (rev 7) +++ trunk/src/picross/grid/PicrossGridController.java 2007-06-05 11:32:56 UTC (rev 8) @@ -49,13 +49,17 @@ * * @author Y. Norsa */ -class PicrossGridController extends Controller implements MouseListener, - MouseMotionListener { - /*** Constant ***/ +public 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"; + /*** Static field ***/ /** The class' logger. */ Modified: trunk/src/picross/grid/PicrossGridMediator.java =================================================================== --- trunk/src/picross/grid/PicrossGridMediator.java 2007-06-05 08:52:12 UTC (rev 7) +++ trunk/src/picross/grid/PicrossGridMediator.java 2007-06-05 11:32:56 UTC (rev 8) @@ -51,8 +51,11 @@ /** Class' logger. */ private static Logger log = Logger.getLogger(PicrossGridMediator.class); - /*** Field ***/ + /*** Fields ***/ + /** The grid model. */ + private PicrossGridModel model; + /** The grid view. */ private PicrossGridUI view; @@ -66,15 +69,14 @@ * @param data grid content */ public PicrossGridMediator(int width, int height, boolean[][] data) { - PicrossGridModel model = new PicrossGridModel(data); + this.model = new PicrossGridModel(this, data); PicrossGridController controller = new PicrossGridController(); controller.addSimpleListener(this); - this.addSimpleListener(controller); this.view = new PicrossGridUI(width, height, - model.getColData(), - model.getRowData(), + this.model.getColData(), + this.model.getRowData(), controller); controller.setView(this.view); @@ -85,8 +87,23 @@ /** {@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()); + } } + /*** Method ***/ + + /** Tells the application mediator the grid has been filled. */ + void congratulations() { + this.fireEventPerformed(PicrossGridController.GRID_FILLED_CMD); + } + /*** Accessor ***/ /** Modified: trunk/src/picross/grid/PicrossGridModel.java =================================================================== --- trunk/src/picross/grid/PicrossGridModel.java 2007-06-05 08:52:12 UTC (rev 7) +++ trunk/src/picross/grid/PicrossGridModel.java 2007-06-05 11:32:56 UTC (rev 8) @@ -51,6 +51,15 @@ /*** Fields ***/ + /** This model's mediator. */ + private PicrossGridMediator mediator; + + /** The original grid. */ + private boolean[][] data; + + /** The grid as filled by the user. */ + private boolean[][] checked; + /** Columns hints. */ private int[][] colData; @@ -62,9 +71,15 @@ /** * Constructor. * + * @param mediator this model's mediator * @param data grid content */ - PicrossGridModel(boolean[][] data) { + PicrossGridModel(PicrossGridMediator mediator, boolean[][] data) { + this.mediator = mediator; + + this.data = data; + this.checked = new boolean[this.data.length][this.data[0].length]; + List<List<Integer>> colRawData = new ArrayList<List<Integer>>(); int max = 0; @@ -231,6 +246,33 @@ */ } + /*** Method ***/ + + /** + * Indicates a box has been checked. + * + * @param row row of the box + * @param column column of the box + */ + void checkBox(int row, int column) { + this.checked[row][column] = true; + + 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(); + } + } + /*** Accessors ***/ /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |