Thread: [Picross-commit] SF.net SVN: picross: [3] trunk/src/picross
Status: Pre-Alpha
Brought to you by:
yvan_norsa
|
From: <yva...@us...> - 2007-06-05 06:52:52
|
Revision: 3
http://picross.svn.sourceforge.net/picross/?rev=3&view=rev
Author: yvan_norsa
Date: 2007-06-04 23:52:53 -0700 (Mon, 04 Jun 2007)
Log Message:
-----------
packages javadoc
Added Paths:
-----------
trunk/src/picross/grid/package.html
trunk/src/picross/package.html
Added: trunk/src/picross/grid/package.html
===================================================================
--- trunk/src/picross/grid/package.html (rev 0)
+++ trunk/src/picross/grid/package.html 2007-06-05 06:52:53 UTC (rev 3)
@@ -0,0 +1,12 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+ <head>
+ <!--
+ $Id$
+ -->
+ </head>
+
+ <body bgcolor="white">
+ Classes modelling the puzzle grid.
+ </body>
+</html>
Property changes on: trunk/src/picross/grid/package.html
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/src/picross/package.html
===================================================================
--- trunk/src/picross/package.html (rev 0)
+++ trunk/src/picross/package.html 2007-06-05 06:52:53 UTC (rev 3)
@@ -0,0 +1,12 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+ <head>
+ <!--
+ $Id$
+ -->
+ </head>
+
+ <body bgcolor="white">
+ Provides the base classes for Picross.
+ </body>
+</html>
Property changes on: trunk/src/picross/package.html
___________________________________________________________________
Name: svn:keywords
+ Id
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yva...@us...> - 2007-06-05 06:53:16
|
Revision: 4
http://picross.svn.sourceforge.net/picross/?rev=4&view=rev
Author: yvan_norsa
Date: 2007-06-04 23:53:14 -0700 (Mon, 04 Jun 2007)
Log Message:
-----------
removed trailing spaces
Modified Paths:
--------------
trunk/src/picross/Picross.java
trunk/src/picross/PicrossMediator.java
trunk/src/picross/PicrossModel.java
trunk/src/picross/PicrossUI.java
trunk/src/picross/grid/PicrossGridMediator.java
trunk/src/picross/grid/PicrossGridModel.java
trunk/src/picross/grid/PicrossGridUI.java
Modified: trunk/src/picross/Picross.java
===================================================================
--- trunk/src/picross/Picross.java 2007-06-05 06:52:53 UTC (rev 3)
+++ trunk/src/picross/Picross.java 2007-06-05 06:53:14 UTC (rev 4)
@@ -4,16 +4,16 @@
* 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,
+ * 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".
- *
+ * "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.
+ * liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
@@ -22,9 +22,9 @@
* 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.
+ * 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.
Modified: trunk/src/picross/PicrossMediator.java
===================================================================
--- trunk/src/picross/PicrossMediator.java 2007-06-05 06:52:53 UTC (rev 3)
+++ trunk/src/picross/PicrossMediator.java 2007-06-05 06:53:14 UTC (rev 4)
@@ -4,16 +4,16 @@
* 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,
+ * 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".
- *
+ * "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.
+ * liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
@@ -22,9 +22,9 @@
* 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.
+ * 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.
Modified: trunk/src/picross/PicrossModel.java
===================================================================
--- trunk/src/picross/PicrossModel.java 2007-06-05 06:52:53 UTC (rev 3)
+++ trunk/src/picross/PicrossModel.java 2007-06-05 06:53:14 UTC (rev 4)
@@ -4,16 +4,16 @@
* 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,
+ * 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".
- *
+ * "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.
+ * liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
@@ -22,9 +22,9 @@
* 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.
+ * 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.
Modified: trunk/src/picross/PicrossUI.java
===================================================================
--- trunk/src/picross/PicrossUI.java 2007-06-05 06:52:53 UTC (rev 3)
+++ trunk/src/picross/PicrossUI.java 2007-06-05 06:53:14 UTC (rev 4)
@@ -4,16 +4,16 @@
* 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,
+ * 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".
- *
+ * "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.
+ * liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
@@ -22,9 +22,9 @@
* 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.
+ * 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.
Modified: trunk/src/picross/grid/PicrossGridMediator.java
===================================================================
--- trunk/src/picross/grid/PicrossGridMediator.java 2007-06-05 06:52:53 UTC (rev 3)
+++ trunk/src/picross/grid/PicrossGridMediator.java 2007-06-05 06:53:14 UTC (rev 4)
@@ -4,16 +4,16 @@
* 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,
+ * 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".
- *
+ * "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.
+ * liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
@@ -22,9 +22,9 @@
* 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.
+ * 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.
Modified: trunk/src/picross/grid/PicrossGridModel.java
===================================================================
--- trunk/src/picross/grid/PicrossGridModel.java 2007-06-05 06:52:53 UTC (rev 3)
+++ trunk/src/picross/grid/PicrossGridModel.java 2007-06-05 06:53:14 UTC (rev 4)
@@ -4,16 +4,16 @@
* 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,
+ * 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".
- *
+ * "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.
+ * liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
@@ -22,9 +22,9 @@
* 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.
+ * 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.
Modified: trunk/src/picross/grid/PicrossGridUI.java
===================================================================
--- trunk/src/picross/grid/PicrossGridUI.java 2007-06-05 06:52:53 UTC (rev 3)
+++ trunk/src/picross/grid/PicrossGridUI.java 2007-06-05 06:53:14 UTC (rev 4)
@@ -4,16 +4,16 @@
* 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,
+ * 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".
- *
+ * "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.
+ * liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
@@ -22,9 +22,9 @@
* 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.
+ * 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.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yva...@us...> - 2007-06-05 08:35:50
|
Revision: 6
http://picross.svn.sourceforge.net/picross/?rev=6&view=rev
Author: yvan_norsa
Date: 2007-06-05 01:35:50 -0700 (Tue, 05 Jun 2007)
Log Message:
-----------
first interaction handling
Modified Paths:
--------------
trunk/src/picross/PicrossModel.java
trunk/src/picross/grid/PicrossGridMediator.java
trunk/src/picross/grid/PicrossGridUI.java
Added Paths:
-----------
trunk/src/picross/grid/FillCommand.java
trunk/src/picross/grid/PicrossGridController.java
Modified: trunk/src/picross/PicrossModel.java
===================================================================
--- trunk/src/picross/PicrossModel.java 2007-06-05 07:37:02 UTC (rev 5)
+++ trunk/src/picross/PicrossModel.java 2007-06-05 08:35:50 UTC (rev 6)
@@ -59,15 +59,22 @@
this.data = new boolean[this.width][this.height];
- this.data[0][0] = true;
- this.data[0][4] = true;
+ this.data[0][1] = true;
+ this.data[0][3] = true;
+ this.data[1][0] = true;
this.data[1][1] = true;
+ this.data[1][2] = true;
this.data[1][3] = true;
- this.data[2][2] = true;
+ this.data[1][4] = true;
+ this.data[2][1] = true;
+ this.data[2][3] = true;
+ this.data[3][0] = true;
this.data[3][1] = true;
+ this.data[3][2] = true;
this.data[3][3] = true;
- this.data[4][0] = true;
- this.data[4][4] = true;
+ this.data[3][4] = true;
+ this.data[4][1] = true;
+ this.data[4][3] = true;
}
/*** Accessors ***/
Added: trunk/src/picross/grid/FillCommand.java
===================================================================
--- trunk/src/picross/grid/FillCommand.java (rev 0)
+++ trunk/src/picross/grid/FillCommand.java 2007-06-05 08:35:50 UTC (rev 6)
@@ -0,0 +1,92 @@
+/*
+ * $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 containing informations about the box to fill.
+ *
+ * @author Y. Norsa
+ */
+class FillCommand extends Command {
+ /*** Fields ***/
+
+ /** Row of the box to fill. */
+ private int row;
+
+ /** Column of the box to fill. */
+ private int column;
+
+ /*** Constructor ***/
+
+ /**
+ * Constructor.
+ *
+ * @param row row of the box to fill
+ * @param column column of the box to fill
+ */
+ FillCommand(int row, int column) {
+ this.row = row;
+ this.column = column;
+ }
+
+ /*** Method overloaded from the class Command ***/
+
+ /** {@inheritDoc} */
+ public String toString() {
+ return this.row + ", " + this.column;
+ }
+
+ /*** Accessors ***/
+
+ /**
+ * Returns the row.
+ *
+ * @return row of the box to fill
+ */
+ int getRow() {
+ return this.row;
+ }
+
+ /**
+ * Returns the column.
+ *
+ * @return column of the box to fill
+ */
+ int getColumn() {
+ return this.column;
+ }
+}
+
Property changes on: trunk/src/picross/grid/FillCommand.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/src/picross/grid/PicrossGridController.java
===================================================================
--- trunk/src/picross/grid/PicrossGridController.java (rev 0)
+++ trunk/src/picross/grid/PicrossGridController.java 2007-06-05 08:35:50 UTC (rev 6)
@@ -0,0 +1,114 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 2007
+ *
+ * This software is governed by the CeCILL license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ */
+
+
+package picross.grid;
+
+import fr.cle.mmvcs.Controller;
+import fr.cle.mmvcs.SimpleEvent;
+
+import java.awt.Point;
+
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Grid controller.
+ *
+ * @author Y. Norsa
+ */
+class PicrossGridController extends Controller implements MouseListener {
+ /*** Constant ***/
+
+ /** Fill command. */
+ static final String FILL_CMD = "FILL_CMD";
+
+ /*** Static field ***/
+
+ /** The class' logger. */
+ private static Logger log = Logger.getLogger(PicrossGridController.class);
+
+ /*** Field ***/
+
+ /** The view to which the controller is attached. */
+ private PicrossGridUI view = null;
+
+ /*** Method overloaded from the class Controller ***/
+
+ /** {@inheritDoc} */
+ public void eventPerformed(SimpleEvent e) {
+ PicrossGridController.log.debug("eventPerformed(" + e + ")");
+ }
+
+ /*** Methods implanted from the interface MouseListener ***/
+
+ /** {@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);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void mouseEntered(MouseEvent e) { }
+
+ /** {@inheritDoc} */
+ public void mouseExited(MouseEvent e) { }
+
+ /** {@inheritDoc} */
+ public void mousePressed(MouseEvent e) { }
+
+ /** {@inheritDoc} */
+ public void mouseReleased(MouseEvent e) { }
+
+ /*** Accessor ***/
+
+ /**
+ * Allows to set the view.
+ *
+ * @param view view to which this controller is attached
+ */
+ void setView(PicrossGridUI view) {
+ this.view = view;
+ }
+}
+
Property changes on: trunk/src/picross/grid/PicrossGridController.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: trunk/src/picross/grid/PicrossGridMediator.java
===================================================================
--- trunk/src/picross/grid/PicrossGridMediator.java 2007-06-05 07:37:02 UTC (rev 5)
+++ trunk/src/picross/grid/PicrossGridMediator.java 2007-06-05 08:35:50 UTC (rev 6)
@@ -54,7 +54,7 @@
/*** Field ***/
/** The grid view. */
- private JPanel view;
+ private PicrossGridUI view;
/*** Constructor ***/
@@ -68,10 +68,16 @@
public PicrossGridMediator(int width, int height, boolean[][] data) {
PicrossGridModel model = new PicrossGridModel(data);
+ PicrossGridController controller = new PicrossGridController();
+ controller.addSimpleListener(this);
+ this.addSimpleListener(controller);
+
this.view = new PicrossGridUI(width, height,
model.getColData(),
model.getRowData(),
- data);
+ controller);
+
+ controller.setView(this.view);
}
/*** Method overloaded from the class Mediateur ***/
Modified: trunk/src/picross/grid/PicrossGridUI.java
===================================================================
--- trunk/src/picross/grid/PicrossGridUI.java 2007-06-05 07:37:02 UTC (rev 5)
+++ trunk/src/picross/grid/PicrossGridUI.java 2007-06-05 08:35:50 UTC (rev 6)
@@ -36,7 +36,10 @@
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
+import java.awt.Point;
+import java.awt.event.MouseListener;
+
import javax.swing.JPanel;
import org.apache.log4j.Logger;
@@ -93,16 +96,26 @@
private int height;
/** Columns hints. */
- private int[][] listePassages;
+ private int[][] colData;
/** Rows hints. */
- private int[][] listePassages2;
+ private int[][] rowData;
- private boolean[][] data;
-
- /** Amount of space left before columns hints and the grid. */
+ /** Amount of space left before the grid. */
private int leftBoundary;
+ /** Position of the right end of the grid. */
+ private int rightBoundary;
+
+ /** Amount of space left before the grid. */
+ private int topBoundary;
+
+ /** Position of the bottom end of the grid. */
+ private int bottomBoundary;
+
+ /** Filled boxes. */
+ private boolean[][] filled;
+
/*** Constructor ***/
/**
@@ -116,32 +129,37 @@
PicrossGridUI(int width, int height,
int[][] colData,
int[][] rowData,
- boolean[][] data) {
+ MouseListener controller) {
super();
+ this.addMouseListener(controller);
+
this.setOpaque(true);
this.setBackground(Color.WHITE);
this.width = width;
this.height = height;
- this.listePassages = colData;
- this.listePassages2 = rowData;
+ this.colData = colData;
+ this.rowData = rowData;
- this.data = data;
+ this.filled = new boolean[this.width][this.height];
this.leftBoundary =
- this.listePassages2[0].length * PicrossGridUI.ROW_HINT_WIDTH;
+ this.rowData[0].length * PicrossGridUI.ROW_HINT_WIDTH;
- this.setPreferredSize(new Dimension(this.leftBoundary
- + (this.width
- * PicrossGridUI.BOX_WIDTH)
+ this.rightBoundary = this.leftBoundary
+ + (this.width * PicrossGridUI.BOX_WIDTH);
+
+ this.topBoundary = PicrossGridUI.TOP_HINTS
+ + (this.colData[0].length * PicrossGridUI.COL_HINT_HEIGHT);
+
+ this.bottomBoundary = this.topBoundary
+ + (this.height * PicrossGridUI.BOX_HEIGHT);
+
+ this.setPreferredSize(new Dimension(this.rightBoundary
+ PicrossGridUI.RIGHT_SPACE,
- PicrossGridUI.TOP_HINTS
- + (this.listePassages[0].length
- * PicrossGridUI.COL_HINT_HEIGHT)
- + (this.height
- * PicrossGridUI.BOX_HEIGHT)
+ this.bottomBoundary
+ PicrossGridUI.BOTTOM_SPACE));
}
@@ -154,12 +172,12 @@
int x = 0;
int y = PicrossGridUI.TOP_HINTS;
- for (int i = this.listePassages[0].length - 1; i >= 0; i--) {
+ for (int i = this.colData[0].length - 1; i >= 0; i--) {
x = this.leftBoundary + PicrossGridUI.COL_HINT_WIDTH;
- for (int j = 0; j < this.listePassages.length; j++) {
- if (this.listePassages[j][i] != -1) {
- g.drawString(String.valueOf(this.listePassages[j][i]),
+ for (int j = 0; j < this.colData.length; j++) {
+ if (this.colData[j][i] != -1) {
+ g.drawString(String.valueOf(this.colData[j][i]),
x, y);
}
@@ -171,12 +189,12 @@
int gridY = y;
- for (int i = 0; i < this.listePassages2.length; i++) {
+ for (int i = 0; i < this.rowData.length; i++) {
x = 0;
- for (int j = 0; j < this.listePassages2[i].length; j++) {
- if (this.listePassages2[i][j] != -1) {
- g.drawString(String.valueOf(this.listePassages2[i][j]),
+ for (int j = 0; j < this.rowData[i].length; j++) {
+ if (this.rowData[i][j] != -1) {
+ g.drawString(String.valueOf(this.rowData[i][j]),
x, y + PicrossGridUI.ROW_HINT_HEIGHT);
}
@@ -192,13 +210,14 @@
x = this.leftBoundary;
for (int j = 0; j < this.width; j++) {
- if (!this.data[j][i]) {
- g.drawRect(x, y,
- PicrossGridUI.BOX_WIDTH, PicrossGridUI.BOX_HEIGHT);
- } else {
+ if (this.filled[i][j]) {
g.fillRect(x, y,
PicrossGridUI.BOX_WIDTH,
PicrossGridUI.BOX_HEIGHT);
+ } else {
+ g.drawRect(x, y,
+ PicrossGridUI.BOX_WIDTH,
+ PicrossGridUI.BOX_HEIGHT);
}
x += PicrossGridUI.BOX_WIDTH;
@@ -207,5 +226,57 @@
y += PicrossGridUI.BOX_HEIGHT;
}
}
+
+ /*** Methods ***/
+
+ /**
+ * This methods tells wether a point is inside the grid or not.
+ *
+ * @param point point to be tested
+ * @return boolean telling if the point is inside the grid
+ */
+ boolean isInGrid(Point point) {
+ double x = point.getX();
+ double y = point.getY();
+
+ return (x >= this.leftBoundary && x <= this.rightBoundary
+ && y >= this.topBoundary && y <= this.bottomBoundary);
+ }
+
+ /**
+ * Allows to get the row number corresponding to a point inside the grid.
+ *
+ * @param point a point inside the grid
+ * @return the row corresponding to the point
+ */
+ int getRow(Point point) {
+ double y = point.getY() - this.topBoundary;
+
+ return (int) (y / PicrossGridUI.BOX_HEIGHT);
+ }
+
+ /**
+ * Allows to get the column number corresponding to a point
+ * inside the grid.
+ *
+ * @param point a point inside the grid
+ * @return the column corresponding to the point
+ */
+ int getColumn(Point point) {
+ double x = point.getX() - this.leftBoundary;
+
+ return (int) (x / PicrossGridUI.BOX_WIDTH);
+ }
+
+ /**
+ * Fills a box in the grid.
+ *
+ * @param row row of the box
+ * @param column column of the box
+ */
+ void fillBox(int row, int column) {
+ this.filled[row][column] = true;
+ this.repaint();
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yva...@us...> - 2007-06-07 11:29:19
|
Revision: 21
http://picross.svn.sourceforge.net/picross/?rev=21&view=rev
Author: yvan_norsa
Date: 2007-06-07 04:29:21 -0700 (Thu, 07 Jun 2007)
Log Message:
-----------
classes renaming
Modified Paths:
--------------
trunk/src/picross/PicrossMediator.java
trunk/src/picross/app/PicrossApp.java
Added Paths:
-----------
trunk/src/picross/app/PicrossAppUI.java
trunk/src/picross/grid/GridController.java
trunk/src/picross/grid/GridMediator.java
trunk/src/picross/grid/GridModel.java
trunk/src/picross/grid/GridUI.java
Removed Paths:
-------------
trunk/src/picross/app/PicrossFrame.java
trunk/src/picross/grid/PicrossGridController.java
trunk/src/picross/grid/PicrossGridMediator.java
trunk/src/picross/grid/PicrossGridModel.java
trunk/src/picross/grid/PicrossGridUI.java
Modified: trunk/src/picross/PicrossMediator.java
===================================================================
--- trunk/src/picross/PicrossMediator.java 2007-06-07 11:18:40 UTC (rev 20)
+++ trunk/src/picross/PicrossMediator.java 2007-06-07 11:29:21 UTC (rev 21)
@@ -40,8 +40,8 @@
//import org.apache.log4j.Logger;
-import picross.grid.PicrossGridController;
-import picross.grid.PicrossGridMediator;
+import picross.grid.GridController;
+import picross.grid.GridMediator;
import picross.menus.MainMenuController;
import picross.menus.MainMenuMediator;
@@ -104,9 +104,9 @@
if (cmd.equals(MainMenuController.PLAY_CMD)) {
PicrossModel model = new PicrossModel();
- PicrossGridMediator grid =
- new PicrossGridMediator(model.getWidth(), model.getHeight(),
- model.getData());
+ GridMediator grid = new GridMediator(model.getWidth(),
+ model.getHeight(),
+ model.getData());
grid.addSimpleListener(this);
this.view.setContent(grid.getView());
@@ -119,7 +119,7 @@
return;
}
- if (cmd.equals(PicrossGridController.GRID_FILLED_CMD)) {
+ if (cmd.equals(GridController.GRID_FILLED_CMD)) {
this.fireEventPerformed(PicrossController.MESSAGE_CMD,
BundleHelper.getString(this, "victory"));
return;
Modified: trunk/src/picross/app/PicrossApp.java
===================================================================
--- trunk/src/picross/app/PicrossApp.java 2007-06-07 11:18:40 UTC (rev 20)
+++ trunk/src/picross/app/PicrossApp.java 2007-06-07 11:29:21 UTC (rev 21)
@@ -55,7 +55,7 @@
/** Constructor. */
private PicrossApp() {
PropertyConfigurator.configure(PicrossApp.LOG4J_CONFIG);
- new PicrossMediator(new PicrossFrame());
+ new PicrossMediator(new PicrossAppUI());
}
/*** Main method ***/
Copied: trunk/src/picross/app/PicrossAppUI.java (from rev 20, trunk/src/picross/app/PicrossFrame.java)
===================================================================
--- trunk/src/picross/app/PicrossAppUI.java (rev 0)
+++ trunk/src/picross/app/PicrossAppUI.java 2007-06-07 11:29:21 UTC (rev 21)
@@ -0,0 +1,95 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 2007
+ *
+ * This software is governed by the CeCILL license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ */
+
+
+package picross.app;
+
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+
+import picross.PicrossUI;
+
+/**
+ * Main window of the application version.
+ *
+ * @author Y. Norsa
+ */
+public final class PicrossAppUI extends JFrame implements PicrossUI {
+ /*** Constants ***/
+
+ /** Serialisation ID. */
+ private static final long serialVersionUID = -6091243469021691734L;
+
+ /** Main menu class. */
+ private static final String MAIN_MENU_CLASS = "picross.app.MainMenuAppUI";
+
+ /*** Constructor ***/
+
+ /** Constructor. */
+ public PicrossAppUI() {
+ super("Picross");
+
+ this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ this.setVisible(true);
+ }
+
+ /*** Methods implanted from the interface PicrossUI ***/
+
+ /** {@inheritDoc} */
+ public void setContent(JPanel content) {
+ this.setContentPane(content);
+ this.pack();
+ }
+
+ /** {@inheritDoc} */
+ public void displayMessage(String msg) {
+ JOptionPane.showMessageDialog(this, msg);
+ }
+
+ /** {@inheritDoc} */
+ public void displayError(String msg) {
+ JOptionPane.showMessageDialog(this, msg,
+ "Picross", JOptionPane.ERROR_MESSAGE);
+ }
+
+ /** {@inheritDoc} */
+ public void exit() {
+ this.dispose();
+ }
+
+ /** {@inheritDoc} */
+ public String getMainMenuClass() {
+ return PicrossAppUI.MAIN_MENU_CLASS;
+ }
+}
+
Deleted: trunk/src/picross/app/PicrossFrame.java
===================================================================
--- trunk/src/picross/app/PicrossFrame.java 2007-06-07 11:18:40 UTC (rev 20)
+++ trunk/src/picross/app/PicrossFrame.java 2007-06-07 11:29:21 UTC (rev 21)
@@ -1,95 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (c) 2007
- *
- * This software is governed by the CeCILL license under French law and
- * abiding by the rules of distribution of free software. You can use,
- * modify and/ or redistribute the software under the terms of the CeCILL
- * license as circulated by CEA, CNRS and INRIA at the following URL
- * "http://www.cecill.info".
- *
- * As a counterpart to the access to the source code and rights to copy,
- * modify and redistribute granted by the license, users are provided only
- * with a limited warranty and the software's author, the holder of the
- * economic rights, and the successive licensors have only limited
- * liability.
- *
- * In this respect, the user's attention is drawn to the risks associated
- * with loading, using, modifying and/or developing or reproducing the
- * software by the user in light of its specific status of free software,
- * that may mean that it is complicated to manipulate, and that also
- * therefore means that it is reserved for developers and experienced
- * professionals having in-depth computer knowledge. Users are therefore
- * encouraged to load and test the software's suitability as regards their
- * requirements in conditions enabling the security of their systems and/or
- * data to be ensured and, more generally, to use and operate it in the
- * same conditions as regards security.
- *
- * The fact that you are presently reading this means that you have had
- * knowledge of the CeCILL license and that you accept its terms.
- */
-
-
-package picross.app;
-
-import javax.swing.JFrame;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-
-import picross.PicrossUI;
-
-/**
- * Main window of the application version.
- *
- * @author Y. Norsa
- */
-public final class PicrossFrame extends JFrame implements PicrossUI {
- /*** Constants ***/
-
- /** Serialisation ID. */
- private static final long serialVersionUID = -6091243469021691734L;
-
- /** Main menu class. */
- private static final String MAIN_MENU_CLASS = "picross.app.MainMenuAppUI";
-
- /*** Constructor ***/
-
- /** Constructor. */
- public PicrossFrame() {
- super("Picross");
-
- this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- this.setVisible(true);
- }
-
- /*** Methods implanted from the interface PicrossUI ***/
-
- /** {@inheritDoc} */
- public void setContent(JPanel content) {
- this.setContentPane(content);
- this.pack();
- }
-
- /** {@inheritDoc} */
- public void displayMessage(String msg) {
- JOptionPane.showMessageDialog(this, msg);
- }
-
- /** {@inheritDoc} */
- public void displayError(String msg) {
- JOptionPane.showMessageDialog(this, msg,
- "Picross", JOptionPane.ERROR_MESSAGE);
- }
-
- /** {@inheritDoc} */
- public void exit() {
- this.dispose();
- }
-
- /** {@inheritDoc} */
- public String getMainMenuClass() {
- return PicrossFrame.MAIN_MENU_CLASS;
- }
-}
-
Copied: trunk/src/picross/grid/GridController.java (from rev 19, trunk/src/picross/grid/PicrossGridController.java)
===================================================================
--- trunk/src/picross/grid/GridController.java (rev 0)
+++ trunk/src/picross/grid/GridController.java 2007-06-07 11:29:21 UTC (rev 21)
@@ -0,0 +1,229 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 2007
+ *
+ * This software is governed by the CeCILL license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ */
+
+
+package picross.grid;
+
+import fr.cle.mmvcs.Controller;
+import fr.cle.mmvcs.SimpleEvent;
+
+import java.awt.Point;
+
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+
+//import org.apache.log4j.Logger;
+
+/**
+ * Grid controller.
+ *
+ * @author Y. Norsa
+ */
+public final class GridController extends Controller
+ implements MouseListener, MouseMotionListener {
+
+ /*** Constants ***/
+
+ /** Fill command. */
+ static final String FILL_CMD = "FILL_CMD";
+
+ /** Command indicating the grid is filled. */
+ public static final String GRID_FILLED_CMD = "GRID_FILLED_CMD";
+
+ /** Command indicating the action has reached its end. */
+ static final String END_ACTION_CMD = "END_ACTION_CMD";
+
+ /** Command to check a box. */
+ static final String CHECK_CMD = "CHECK_CMD";
+
+ /** Command to uncheck a box. */
+ static final String UNCHECK_CMD = "UNCHECK_CMD";
+
+ /** Checking a box. */
+ static final int CHECK_ACTION = 0;
+
+ /** Crossing a box. */
+ static final int CROSS_ACTION = 1;
+
+ /*** Static field ***/
+
+ /** The class' logger. */
+ //private static Logger log = Logger.getLogger(GridController.class);
+
+ /*** Field ***/
+
+ /** The view to which the controller is attached. */
+ private GridUI view = null;
+
+ /*** Method overloaded from the class Controller ***/
+
+ /** {@inheritDoc} */
+ public void eventPerformed(SimpleEvent e) {
+ //GridController.log.debug("eventPerformed(" + e + ")");
+
+ String cmd = e.getCommandName();
+
+ if (cmd.equals(GridController.GRID_FILLED_CMD)) {
+ this.view.disableGrid();
+ return;
+ }
+
+ if (cmd.equals(GridController.CHECK_CMD)) {
+ FillCommand command = (FillCommand) e.getCommand();
+ this.view.check(command.getRow(), command.getColumn(),
+ command.getType());
+
+ return;
+ }
+
+ if (cmd.equals(GridController.UNCHECK_CMD)) {
+ FillCommand command = (FillCommand) e.getCommand();
+ this.view.uncheck(command.getRow(), command.getColumn(),
+ command.getType());
+
+ return;
+ }
+ }
+
+ /*** Methods implanted from the interface MouseListener ***/
+
+ /** {@inheritDoc} */
+ public void mouseClicked(MouseEvent e) { }
+
+ /** {@inheritDoc} */
+ public void mouseEntered(MouseEvent e) { }
+
+ /** {@inheritDoc} */
+ public void mouseExited(MouseEvent e) { }
+
+ /** {@inheritDoc} */
+ public void mousePressed(MouseEvent e) {
+ this.view.rolloverEnded();
+ }
+
+ /** {@inheritDoc} */
+ public void mouseReleased(MouseEvent e) {
+ //GridController.log.debug("mouseReleased()");
+ this.checkAndFill(e);
+ this.fireEventPerformed(GridController.END_ACTION_CMD);
+ }
+
+ /*** Methods implanted from the interface MouseMotionListener ***/
+
+ /** {@inheritDoc} */
+ public void mouseDragged(MouseEvent e) {
+ this.checkAndFill(e);
+ }
+
+ /** {@inheritDoc} */
+ public void mouseMoved(MouseEvent e) {
+ //GridController.log.debug(e.getPoint());
+
+ Point point = e.getPoint();
+
+ if (this.view.isInGrid(point)) {
+ int row = this.view.getRow(point);
+ int column = this.view.getColumn(point);
+
+ this.view.setRollover(row, column);
+ } else {
+ this.view.rolloverEnded();
+ }
+
+ }
+
+ /*** Methods ***/
+
+ /**
+ * Checks if the mouse current click's location is inside the grid
+ * and eventually fills the corresponding box.
+ *
+ * @param e mouse event to handle
+ */
+ private void checkAndFill(MouseEvent e) {
+ //GridController.log.debug(e);
+
+ int modifiers = e.getModifiers();
+
+ if (modifiers != MouseEvent.BUTTON1_MASK
+ && modifiers != MouseEvent.BUTTON3_MASK) {
+
+ return;
+ }
+
+ Point point = e.getPoint();
+
+ if (this.view.isInGrid(point)) {
+ int row = this.view.getRow(point);
+ int column = this.view.getColumn(point);
+ int type = GridController.modifiersToType(modifiers);
+
+ //GridController.log.debug("type : " + type);
+
+ this.fireEventPerformed(GridController.FILL_CMD,
+ new FillCommand(row, column, type));
+
+ }
+ }
+
+ /**
+ * Converts a mouse click to an action.
+ *
+ * @param modifiers mouse event modifiers
+ * @return corresponding action, or -1
+ */
+ private static int modifiersToType(int modifiers) {
+ switch (modifiers) {
+ case MouseEvent.BUTTON1_MASK:
+ return GridController.CHECK_ACTION;
+
+ case MouseEvent.BUTTON3_MASK:
+ return GridController.CROSS_ACTION;
+
+ default:
+ return -1;
+ }
+ }
+
+ /*** Accessor ***/
+
+ /**
+ * Allows to set the view.
+ *
+ * @param view view to which this controller is attached
+ */
+ void setView(GridUI view) {
+ this.view = view;
+ }
+}
+
Added: trunk/src/picross/grid/GridMediator.java
===================================================================
--- trunk/src/picross/grid/GridMediator.java (rev 0)
+++ trunk/src/picross/grid/GridMediator.java 2007-06-07 11:29:21 UTC (rev 21)
@@ -0,0 +1,148 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 2007
+ *
+ * This software is governed by the CeCILL license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ */
+
+
+package picross.grid;
+
+import fr.cle.mmvcs.Mediateur;
+import fr.cle.mmvcs.SimpleEvent;
+
+import javax.swing.JPanel;
+
+//import org.apache.log4j.Logger;
+
+/**
+ * Picross grid mediator.
+ *
+ * @author Y. Norsa
+ */
+public final class GridMediator extends Mediateur {
+ /*** Static field ***/
+
+ /** Class' logger. */
+ //private static Logger log = Logger.getLogger(GridMediator.class);
+
+ /*** Fields ***/
+
+ /** The grid model. */
+ private GridModel model;
+
+ /** The grid view. */
+ private GridUI view;
+
+ /*** Constructor ***/
+
+ /**
+ * Constructor.
+ *
+ * @param width grid width
+ * @param height grid height
+ * @param data grid content
+ */
+ public GridMediator(int width, int height, boolean[][] data) {
+ this.model = new GridModel(this, data);
+
+ GridController controller = new GridController();
+ controller.addSimpleListener(this);
+ this.addSimpleListener(controller);
+
+ this.view = new GridUI(width, height,
+ this.model.getColData(),
+ this.model.getRowData(),
+ controller);
+
+ controller.setView(this.view);
+ }
+
+ /*** Method overloaded from the class Mediateur ***/
+
+ /** {@inheritDoc} */
+ public void eventPerformed(SimpleEvent e) {
+ //GridMediator.log.debug("eventPerformed(" + e + ")");
+
+ String cmd = e.getCommandName();
+
+ if (cmd.equals(GridController.FILL_CMD)) {
+ FillCommand command = (FillCommand) e.getCommand();
+ this.model.checkBox(command.getRow(), command.getColumn(),
+ command.getType());
+
+ return;
+ }
+
+ if (cmd.equals(GridController.END_ACTION_CMD)) {
+ this.model.endAction();
+ return;
+ }
+ }
+
+ /*** Methods ***/
+
+ /** Tells the application mediator the grid has been filled. */
+ void congratulations() {
+ this.fireEventPerformed(GridController.GRID_FILLED_CMD);
+ }
+
+ /**
+ * Checks a box.
+ *
+ * @param row row of the box
+ * @param column column of the box
+ */
+ void check(int row, int column, int type) {
+ this.fireEventPerformed(GridController.CHECK_CMD,
+ new FillCommand(row, column, type));
+ }
+
+ /**
+ * Unchecks a box.
+ *
+ * @param row row of the box
+ * @param column column of the box
+ */
+ void uncheck(int row, int column, int type) {
+ this.fireEventPerformed(GridController.UNCHECK_CMD,
+ new FillCommand(row, column, type));
+ }
+
+ /*** Accessor ***/
+
+ /**
+ * Returns the view.
+ *
+ * @return the grid view
+ */
+ public JPanel getView() {
+ return this.view;
+ }
+}
+
Property changes on: trunk/src/picross/grid/GridMediator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: trunk/src/picross/grid/GridModel.java (from rev 19, trunk/src/picross/grid/PicrossGridModel.java)
===================================================================
--- trunk/src/picross/grid/GridModel.java (rev 0)
+++ trunk/src/picross/grid/GridModel.java 2007-06-07 11:29:21 UTC (rev 21)
@@ -0,0 +1,355 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 2007
+ *
+ * This software is governed by the CeCILL license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ */
+
+
+package picross.grid;
+
+import java.util.ArrayList;
+import java.util.List;
+
+//import org.apache.log4j.Logger;
+
+/**
+ * The grid model.
+ *
+ * @author Y. Norsa
+ */
+final class GridModel {
+ /*** Constant ***/
+
+ /** Empty hint value. */
+ static final int EMPTY_HINT = -1;
+
+ /*** Static field ***/
+
+ /** The class' logger. */
+ //private static Logger log = Logger.getLogger(GridModel.class);
+
+ /*** Fields ***/
+
+ /** This model's mediator. */
+ private GridMediator mediator;
+
+ /** The original grid. */
+ private boolean[][] data;
+
+ /** The grid as filled by the user. */
+ private Box[][] boxes;
+
+ /**
+ * The last modified box. Permis to know if we are in a serie or
+ * a single action.
+ */
+ private Box lastModified = null;
+
+ /** Columns hints. */
+ private int[][] colData;
+
+ /** Rows hints. */
+ private int[][] rowData;
+
+ /*** Constructor ***/
+
+ /**
+ * Constructor.
+ *
+ * @param mediator this model's mediator
+ * @param data grid content
+ */
+ GridModel(GridMediator mediator, boolean[][] data) {
+ this.mediator = mediator;
+
+ this.data = data;
+ this.boxes = new Box[this.data.length][this.data[0].length];
+
+ for (int i = 0; i < this.boxes.length; i++) {
+ for (int j = 0; j < this.boxes[i].length; j++) {
+ this.boxes[i][j] = new Box();
+ }
+ }
+
+ // Grid of columns hints
+ List<List<Integer>> colHints = new ArrayList<List<Integer>>();
+
+ // Largest number of hints for a column
+ int max = 0;
+
+ for (boolean[] col : data) {
+ List<Integer> current = new ArrayList<Integer>();
+
+ // Current hint
+ int chain = 0;
+
+ for (boolean cell : col) {
+ if (cell) {
+ chain++;
+ } else if (chain > 0) {
+ // We've reached the end of a series of checked boxes
+ current.add(chain);
+ chain = 0;
+ }
+ }
+
+ if (chain > 0) {
+ current.add(chain);
+ } else if (current.size() == 0) {
+ // If this column is empty, we add a "0" hint
+ current.add(0);
+ }
+
+ int currentSize = current.size();
+
+ if (currentSize > max) {
+ max = currentSize;
+ }
+
+ colHints.add(current);
+ }
+
+ /*
+ * Final array containing the hints, in the following form :
+ *
+ * 1
+ * 0 2 1
+ *
+ * Which corresponds to the following grid :
+ *
+ * |-----|
+ * |_|X|_|
+ * |_|_|X|
+ * |_|X|_|
+ * |_|X|_|
+ * |-----|
+ */
+ this.colData = new int[data.length][max];
+
+ for (int i = 0; i < max; i++) {
+ // Minimal number of hints for the current column to be considered
+ int ref = max - i;
+
+ // Current hint row
+ int currentRow = ref - 1;
+
+ for (int j = 0; j < colHints.size(); j++) {
+ List<Integer> currentCol = colHints.get(j);
+ int size = currentCol.size();
+
+ if (size >= ref) {
+ this.colData[j][currentRow] = currentCol.get(size - ref);
+ } else {
+ this.colData[j][currentRow] = GridModel.EMPTY_HINT;
+ }
+ }
+ }
+
+ // Same operations as for the columns, basically
+
+ List<List<Integer>> rowHints = new ArrayList<List<Integer>>();
+ max = 0;
+
+ for (int i = 0; i < data[0].length; i++) {
+ List<Integer> current = new ArrayList<Integer>();
+
+ int chain = 0;
+
+ for (int j = 0; j < data.length; j++) {
+ if (data[j][i]) {
+ chain++;
+ } else if (chain > 0) {
+ current.add(chain);
+ chain = 0;
+ }
+ }
+
+ if (chain > 0) {
+ current.add(chain);
+ } else if (current.size() == 0) {
+ current.add(0);
+ }
+
+ int currentSize = current.size();
+
+ if (currentSize > max) {
+ max = currentSize;
+ }
+
+ rowHints.add(current);
+ }
+
+ this.rowData = new int[data[0].length][max];
+ int nbRows = rowHints.size();
+
+ for (int i = 0; i < max; i++) {
+ int ref = max - i;
+
+ for (int j = 0; j < nbRows; j++) {
+ List<Integer> currentRow = rowHints.get(j);
+ int size = currentRow.size();
+
+ if (size >= ref) {
+ this.rowData[j][i] =
+ currentRow.get(i - Math.abs(size - max));
+ } else {
+ this.rowData[j][i] = GridModel.EMPTY_HINT;
+ }
+ }
+ }
+ }
+
+ /*** Methods ***/
+
+ /**
+ * Method called during an action.
+ *
+ * @param row row of the box
+ * @param column column of the box
+ */
+ void checkBox(int row, int column, int type) {
+ //GridModel.log.debug("checkBox(" + row + ", " + column + ")");
+ //GridModel.log.debug("lastModified == null : "
+ // + (lastModified == null));
+
+ /*
+ * If we are trying to check the last box we just checked
+ * (while dragging), do nothing
+ */
+ if (this.lastModified != null
+ && this.lastModified == this.boxes[row][column]) {
+
+ return;
+ }
+
+ if (this.lastModified != null) {
+ /*
+ * If we are in a box which is in the same state as our aim
+ * (if we are in a checks serie and we are on a box which
+ * is already checked), do nothing
+ */
+ if (this.boxes[row][column].equals(this.lastModified)) {
+ return;
+ }
+ }
+
+ if (this.boxes[row][column].isEmpty()
+ && (this.lastModified == null || !this.lastModified.isEmpty())) {
+
+ if (type == GridController.CHECK_ACTION) {
+ this.boxes[row][column].check();
+ } else { //if (type == GridController.CROSS_ACTION) {
+ this.boxes[row][column].cross();
+ }
+
+ this.mediator.check(row, column, type);
+ } else if (!this.boxes[row][column].isEmpty()
+ && (this.lastModified == null
+ || this.lastModified.isEmpty())) {
+
+ if (this.boxes[r...
[truncated message content] |
|
From: <yva...@us...> - 2007-06-12 14:21:44
|
Revision: 32
http://picross.svn.sourceforge.net/picross/?rev=32&view=rev
Author: yvan_norsa
Date: 2007-06-12 07:21:43 -0700 (Tue, 12 Jun 2007)
Log Message:
-----------
visually marks completed hints
Modified Paths:
--------------
trunk/src/picross/PicrossModel.java
trunk/src/picross/grid/GridController.java
trunk/src/picross/grid/GridMediator.java
trunk/src/picross/grid/GridModel.java
trunk/src/picross/grid/GridUI.java
Added Paths:
-----------
trunk/src/picross/grid/ClearCommand.java
trunk/src/picross/grid/CompletedCommand.java
Modified: trunk/src/picross/PicrossModel.java
===================================================================
--- trunk/src/picross/PicrossModel.java 2007-06-11 10:43:20 UTC (rev 31)
+++ trunk/src/picross/PicrossModel.java 2007-06-12 14:21:43 UTC (rev 32)
@@ -58,13 +58,7 @@
this.height = 14;
this.data = new boolean[this.width][this.height];
- /*
- for (int i = 0; i < this.width; i++) {
- for (int j = 0; j < this.height; j++) {
- this.data[i][j] = true;
- }
- }
- */
+
this.data[0][7] = true;
this.data[0][8] = true;
this.data[0][13] = true;
Added: trunk/src/picross/grid/ClearCommand.java
===================================================================
--- trunk/src/picross/grid/ClearCommand.java (rev 0)
+++ trunk/src/picross/grid/ClearCommand.java 2007-06-12 14:21:43 UTC (rev 32)
@@ -0,0 +1,93 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 2007
+ *
+ * This software is governed by the CeCILL license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ */
+
+
+package picross.grid;
+
+import fr.cle.mmvcs.Command;
+
+/**
+ * Command asking to clear hints.
+ *
+ * @author Y. Norsa
+ */
+final class ClearCommand extends Command {
+ /*** Constants ***/
+
+ /** Clear a column. */
+ static final int COLUMN = 0;
+
+ /** Clear a row. */
+ static final int ROW = 1;
+
+ /*** Fields ***/
+
+ /** Type of hints to clear. */
+ private int type;
+
+ /** Number of the column or row. */
+ private int pos;
+
+ /*** Constructor ***/
+
+ /**
+ * Constructor.
+ *
+ * @param type type of hints to clear
+ * @param pos number of the column or row
+ */
+ ClearCommand(int type, int pos) {
+ this.type = type;
+ this.pos = pos;
+ }
+
+ /*** Accessors ***/
+
+ /**
+ * Returns the type of hints to clear.
+ *
+ * @return type of hints to clear
+ */
+ int getType() {
+ return this.type;
+ }
+
+ /**
+ * Returns the position of the column or row.
+ *
+ * @return position of the number or row
+ */
+ int getPos() {
+ return this.pos;
+ }
+}
+
Property changes on: trunk/src/picross/grid/ClearCommand.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/src/picross/grid/CompletedCommand.java
===================================================================
--- trunk/src/picross/grid/CompletedCommand.java (rev 0)
+++ trunk/src/picross/grid/CompletedCommand.java 2007-06-12 14:21:43 UTC (rev 32)
@@ -0,0 +1,107 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 2007
+ *
+ * This software is governed by the CeCILL license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ */
+
+
+package picross.grid;
+
+import fr.cle.mmvcs.Command;
+
+/**
+ * Command indicating that a hint has been completed.
+ *
+ * @author Y. Norsa
+ */
+final class CompletedCommand extends Command {
+ /*** Constants ***/
+
+ /** A column hint has been completed. */
+ static final int COLUMN = 0;
+
+ /** A row hint has been completed. */
+ static final int ROW = 1;
+
+ /*** Fields ***/
+
+ /** Type of hint that has been completed. */
+ private int type;
+
+ /** Number of the column or row. */
+ private int position;
+
+ /** Position of the hint in the column or row. */
+ private int hintPos;
+
+ /*** Constructor ***/
+
+ /**
+ * Constructor.
+ *
+ * @param type type of hint that has been completed
+ * @param position number of the column or row
+ * @param hintPos position of the hint in the column or row
+ */
+ CompletedCommand(int type, int position, int hintPos) {
+ this.type = type;
+ this.position = position;
+ this.hintPos = hintPos;
+ }
+
+ /*** Accessors ***/
+
+ /**
+ * Returns the type of hint that has been completed.
+ *
+ * @return type of hint that has been completed
+ */
+ int getType() {
+ return this.type;
+ }
+
+ /**
+ * Returns the number of the column or row.
+ *
+ * @return number of the column or row
+ */
+ int getPosition() {
+ return this.position;
+ }
+
+ /**
+ * Returns the position of the hint in the column or row.
+ *
+ * @return position of the hint in the column or row
+ */
+ int getHintPos() {
+ return this.hintPos;
+ }
+}
+
Property changes on: trunk/src/picross/grid/CompletedCommand.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: trunk/src/picross/grid/GridController.java
===================================================================
--- trunk/src/picross/grid/GridController.java 2007-06-11 10:43:20 UTC (rev 31)
+++ trunk/src/picross/grid/GridController.java 2007-06-12 14:21:43 UTC (rev 32)
@@ -63,15 +63,15 @@
/** Command indicating the action has reached its end. */
static final String END_ACTION_CMD = "END_ACTION_CMD";
- /** Command to check a box. */
- //static final String CHECK_CMD = "CHECK_CMD";
-
- /** Command to uncheck a box. */
- //static final String UNCHECK_CMD = "UNCHECK_CMD";
-
/** Command asking to repaint part of the grid. */
static final String PAINT_CMD = "PAINT_CMD";
+ /** Command indicating that a hint has been completed. */
+ static final String COMPLETED_CMD = "COMPLETED_CMD";
+
+ /** Command asking to clear the completed hints. */
+ static final String CLEAR_HINTS_CMD = "CLEAR_HINTS_CMD";
+
/** Checking a box. */
static final int CHECK_ACTION = 0;
@@ -104,8 +104,35 @@
if (cmd.equals(GridController.PAINT_CMD)) {
PaintCommand command = (PaintCommand) e.getCommand();
this.view.repaint(command.getRow(), command.getColumn());
+
return;
}
+
+ if (cmd.equals(GridController.COMPLETED_CMD)) {
+ CompletedCommand command = (CompletedCommand) e.getCommand();
+
+ if (command.getType() == CompletedCommand.COLUMN) {
+ this.view.completedColHint(command.getPosition(),
+ command.getHintPos());
+ } else { //if (command.getType() == CompletedCommand.ROW) {
+ this.view.completedRowHint(command.getPosition(),
+ command.getHintPos());
+ }
+
+ return;
+ }
+
+ if (cmd.equals(GridController.CLEAR_HINTS_CMD)) {
+ ClearCommand command = (ClearCommand) e.getCommand();
+
+ if (command.getType() == ClearCommand.COLUMN) {
+ this.view.clearColHints(command.getPos());
+ } else { //if (command.getType() == ClearCommand.ROW) {
+ this.view.clearRowHints(command.getPos());
+ }
+
+ return;
+ }
}
/*** Methods implanted from the interface MouseListener ***/
Modified: trunk/src/picross/grid/GridMediator.java
===================================================================
--- trunk/src/picross/grid/GridMediator.java 2007-06-11 10:43:20 UTC (rev 31)
+++ trunk/src/picross/grid/GridMediator.java 2007-06-12 14:21:43 UTC (rev 32)
@@ -124,6 +124,52 @@
new PaintCommand(row, column));
}
+ /**
+ * Asks to clear a column's hints.
+ *
+ * @param column column number
+ */
+ void clearColHints(int column) {
+ this.fireEventPerformed(GridController.CLEAR_HINTS_CMD,
+ new ClearCommand(ClearCommand.COLUMN,
+ column));
+ }
+
+ /**
+ * Ask to mark a column hint as completed.
+ *
+ * @param column column number
+ * @param hintPos position of the hint
+ */
+ void completedColHint(int column, int hintPos) {
+ this.fireEventPerformed(GridController.COMPLETED_CMD,
+ new CompletedCommand(CompletedCommand.COLUMN,
+ column, hintPos));
+ }
+
+ /**
+ * Asks to clear a row's hints.
+ *
+ * @param row row number
+ */
+ void clearRowHints(int row) {
+ this.fireEventPerformed(GridController.CLEAR_HINTS_CMD,
+ new ClearCommand(ClearCommand.ROW,
+ row));
+ }
+
+ /**
+ * Asks to mark a row hint as completed.
+ *
+ * @param row row number
+ * @param hintPos position of the hint
+ */
+ void completedRowHint(int row, int hintPos) {
+ this.fireEventPerformed(GridController.COMPLETED_CMD,
+ new CompletedCommand(CompletedCommand.ROW,
+ row, hintPos));
+ }
+
/*** Accessor ***/
/**
Modified: trunk/src/picross/grid/GridModel.java
===================================================================
--- trunk/src/picross/grid/GridModel.java 2007-06-11 10:43:20 UTC (rev 31)
+++ trunk/src/picross/grid/GridModel.java 2007-06-12 14:21:43 UTC (rev 32)
@@ -225,10 +225,67 @@
}
}
+ /*** Static methods ***/
+
+ /**
+ * Returns the index of the first non-empty hint.
+ *
+ * @param hints hints array
+ * @return index of the first non-empty hint
+ */
+ private static int getFirstHintIndex(int[] hints) {
+ return GridModel.getNextHintIndex(0, hints);
+ }
+
+ /**
+ * Returns the index of the next non-empty hint.
+ *
+ * @param currentIndex start index
+ * @param hints hints array
+ * @return index of the next non-empty hint
+ */
+ private static int getNextHintIndex(int currentIndex, int[] hints) {
+ for (int i = currentIndex; i < hints.length; i++) {
+ if (hints[i] != GridModel.EMPTY_HINT) {
+ return i;
+ }
+ }
+
+ return GridModel.EMPTY_HINT;
+ }
+
+ /**
+ * Returns the index of the last non-empty hint.
+ *
+ * @param hints hints array
+ * @return index of the last non-empty hint
+ */
+ private static int getLastHintIndex(int[] hints) {
+ return GridModel.getPreviousHintIndex(hints.length - 1, hints);
+ }
+
+ /**
+ * Returns the index of the previous non-empty hint.
+ *
+ * @param currentIndex start index
+ * @param hints hints array
+ * @return index of the previous non-empty hint
+ */
+ private static int getPreviousHintIndex(int currentIndex, int[] hints) {
+ for (int i = currentIndex; i >= 0; i--) {
+ if (hints[i] != GridModel.EMPTY_HINT) {
+ return i;
+ }
+ }
+
+ return GridModel.EMPTY_HINT;
+ }
+
/*** Methods ***/
/**
* Method called during an action.
+ * TODO rename this method
*
* @param row row of the box
* @param column column of the box
@@ -297,9 +354,282 @@
}
this.lastModified = this.boxes[column][row];
+ this.checkColumn(column);
+ this.checkRow(row);
this.checkCompleted();
}
+ /**
+ * Checks if a hint has been completed in a row.
+ *
+ * @param row row number to check
+ */
+ private void checkRow(int row) {
+ // Contains the completed hints
+ List<Integer> completedHints = new ArrayList<Integer>();
+
+ // Current hint we're looking to complete
+ int currentHintIndex =
+ GridModel.getFirstHintIndex(this.rowData[row]);
+
+ // First from left to right
+ int currentHint = 0;
+
+ // If the first box is empty, do nothing this time
+ if (!this.boxes[currentHint][row].isEmpty()) {
+ // Current chain of checked boxes
+ int currentChain = 0;
+
+ while (currentHint < this.boxes.length) {
+ if (this.boxes[currentHint][row].isChecked()) {
+ currentChain++;
+ } else {
+ // We reach the end of a chain
+
+ // And it matches the current hint
+ if (this.rowData[row][currentHintIndex]
+ == currentChain) {
+
+ completedHints.add(currentHintIndex);
+ currentChain = 0;
+
+ currentHintIndex =
+ GridModel.getNextHintIndex(currentHintIndex + 1,
+ this.rowData[row]);
+
+ if (currentHintIndex == GridModel.EMPTY_HINT) {
+ /*
+ * If this is the last hint, we verify that
+ * there aren't any extra checked boxes
+ */
+ for (int i = currentHint; i < this.boxes.length;
+ i++) {
+
+ if (this.boxes[i][row].isChecked()) {
+ /*
+ * If this is the case,
+ * we cancel everything
+ */
+ completedHints.clear();
+ break;
+ }
+ }
+
+ break;
+ }
+ }
+
+ // If there is a blank after a filled hint, we stop there
+ if (this.boxes[currentHint][row].isEmpty()) {
+ break;
+ }
+ }
+
+ currentHint++;
+ }
+
+ /*
+ * If we've reached the end of the row
+ * and there is a current chain, we mark it as completed
+ */
+ if (currentHintIndex != -1
+ && this.rowData[row][currentHintIndex] == currentChain) {
+
+ completedHints.add(currentHintIndex);
+ currentChain = 0;
+ }
+ }
+
+ // Same thing from right to left
+ currentHintIndex = GridModel.getLastHintIndex(this.rowData[row]);
+
+ currentHint = this.boxes.length - 1;
+
+ if (!this.boxes[currentHint][row].isEmpty()) {
+ int currentChain = 0;
+
+ while (currentHint >= 0) {
+ if (this.boxes[currentHint][row].isChecked()) {
+ currentChain++;
+ } else {
+ if (this.rowData[row][currentHintIndex]
+ == currentChain) {
+
+ completedHints.add(currentHintIndex);
+ currentChain = 0;
+
+ currentHintIndex =
+ GridModel.getPreviousHintIndex(currentHintIndex
+ - 1,
+ this.rowData[row]);
+
+ if (currentHintIndex == -1) {
+ for (int i = currentHint; i >= 0; i--) {
+ if (this.boxes[i][row].isChecked()) {
+ completedHints.clear();
+ }
+ }
+
+ break;
+ }
+ }
+
+ if (this.boxes[currentHint][row].isEmpty()) {
+ break;
+ }
+ }
+
+ currentHint--;
+ }
+ }
+
+ this.mediator.clearRowHints(row);
+
+ for (int index : completedHints) {
+ this.mediator.completedRowHint(row, index);
+ }
+ }
+
+ /**
+ * Checks if a hint has been completed in a column.
+ *
+ * @param column column number to check
+ */
+ private void checkColumn(int column) {
+ //GridModel.log.debug("checkColumn(" + column + ")");
+
+ List<Integer> completedHints = new ArrayList<Integer>();
+ /*
+ for (int i = 0; i < this.colData[column].length; i++) {
+ GridModel.log.debug("this.colData[" + column + "][" + i + "] = "
+ + this.colData[column][i]);
+ }
+ */
+ //GridModel.log.debug("hint courant :"
+ //+ this.colData[column][currentHintIndex]);
+
+ int currentHintIndex =
+ GridModel.getLastHintIndex(this.colData[column]);
+
+ int currentHint = 0;
+
+ if (!this.boxes[column][currentHint].isEmpty()) {
+ int currentChain = 0;
+
+ while (currentHint < this.boxes[0].length) {
+ //GridModel.log.debug("dans la boucle, currentHint = "
+ //+ currentHint + ", currentChain = " + currentChain);
+
+ if (this.boxes[column][currentHint].isChecked()) {
+ currentChain++;
+ } else {
+ if (this.colData[column][currentHintIndex]
+ == currentChain) {
+
+ //GridModel.log.debug("found " + currentChain);
+
+ completedHints.add(currentHintIndex);
+ currentChain = 0;
+
+ //GridModel.log.debug("currentHintIndex = "
+ //+ currentHintIndex);
+
+ currentHintIndex = GridModel
+ .getPreviousHintIndex(currentHintIndex - 1,
+ this.colData[column]);
+
+ if (currentHintIndex == GridModel.EMPTY_HINT) {
+ for (int i = currentHint; i < this.boxes[0].length;
+ i++) {
+
+ if (this.boxes[column][i].isChecked()) {
+ completedHints.clear();
+ break;
+ }
+ }
+
+ break;
+ }
+ }
+
+ if (this.boxes[column][currentHint].isEmpty()) {
+ break;
+ }
+ }
+
+ currentHint++;
+ }
+
+ //GridModel.log.debug("fin de la boucle, currentHint = "
+ //+ currentHint);
+
+ if (currentHintIndex != GridModel.EMPTY_HINT
+ && this.colData[column][currentHintIndex] == currentChain) {
+
+ //GridModel.log.debug("found " + currentChain);
+
+ completedHints.add(currentHintIndex);
+ currentChain = 0;
+ }
+
+ }
+
+ currentHintIndex = GridModel.getFirstHintIndex(this.colData[column]);
+
+ //GridModel.log.debug("hintCourant2 : "
+ //+ this.colData[column][currentHintIndex]);
+
+ currentHint = this.boxes[0].length - 1;
+
+ if (!this.boxes[column][currentHint].isEmpty()) {
+ int currentChain = 0;
+
+ while (currentHint >= 0) {
+ //GridModel.log.debug("dans la boucle2, currentHint = "
+ //+ currentHint + ", currentChain = " + currentChain);
+
+ if (this.boxes[column][currentHint].isChecked()) {
+ currentChain++;
+ } else {
+ if (this.colData[column][currentHintIndex]
+ == currentChain) {
+
+ //GridModel.log.debug("found2 " + currentChain);
+
+ completedHints.add(currentHintIndex);
+ currentChain = 0;
+
+ currentHintIndex =
+ GridModel.getNextHintIndex(currentHintIndex + 1,
+ this.colData[column]);
+
+ if (currentHintIndex == GridModel.EMPTY_HINT) {
+ for (int i = currentHint; i >= 0; i--) {
+ if (this.boxes[column][i].isChecked()) {
+ completedHints.clear();
+ }
+ }
+
+ break;
+ }
+ }
+
+ if (this.boxes[column][currentHint].isEmpty()) {
+ break;
+ }
+ }
+
+ currentHint--;
+ }
+ }
+
+ this.mediator.clearColHints(column);
+
+ for (int index : completedHints) {
+ this.mediator.completedColHint(column, index);
+ }
+ }
+
/** Checks wether the grid is finished. */
private void checkCompleted() {
boolean completed = true;
Modified: trunk/src/picross/grid/GridUI.java
===================================================================
--- trunk/src/picross/grid/GridUI.java 2007-06-11 10:43:20 UTC (rev 31)
+++ trunk/src/picross/grid/GridUI.java 2007-06-12 14:21:43 UTC (rev 32)
@@ -76,6 +76,9 @@
/** Color of the hints text. */
private static final Color HINT_TEXT_COLOR = new Color(233, 246, 255);
+ /** Color of a completed hint text. */
+ private static final Color COMPLETED_HINT_COLOR = new Color(208, 215, 217);
+
/** Font used for the hints. */
private static final Font HINT_FONT =
new Font("Sans Serif", Font.BOLD, 10);
@@ -186,6 +189,12 @@
/** Boxes blocks. */
private List<Line2D> blocksLines;
+ /** Completed column hints. */
+ private boolean[][] completedCols;
+
+ /** Completed row hints. */
+ private boolean[][] completedRows;
+
/*** Constructor ***/
/**
@@ -303,6 +312,9 @@
this.initBlocks();
+ this.completedCols = new boolean[this.width][this.colData[0].length];
+ this.completedRows = new boolean[this.height][this.rowData[0].length];
+
this.setPreferredSize(new Dimension(this.rightBoundary
+ GridUI.RIGHT_SPACE,
this.bottomBoundary
@@ -424,7 +436,8 @@
for (int j = 0; j < this.colData.length; j++) {
if (this.colData[j][i] != GridModel.EMPTY_HINT) {
- this.drawHint(g, this.colData[j][i], x, y);
+ this.drawHint(g, this.colData[j][i], x, y,
+ this.completedCols[j][i]);
}
x += GridUI.BOX_WIDTH;
@@ -447,7 +460,8 @@
for (int j = 0; j < this.rowData[i].length; j++) {
if (this.rowData[i][j] != GridModel.EMPTY_HINT) {
- this.drawHint(g, this.rowData[i][j], x, y);
+ this.drawHint(g, this.rowData[i][j], x, y,
+ this.completedRows[i][j]);
}
x += this.leftHintsDecal;
@@ -465,10 +479,16 @@
* @param x X coordinate
* @param y Y coordinate
*/
- private void drawHint(Graphics g, int value, int x, int y) {
+ private void drawHint(Graphics g, int value, int x, int y,
+ boolean complete) {
this.hintBoxIcon.paintIcon(this, g, x, y);
- g.setColor(GridUI.HINT_TEXT_COLOR);
+ if (complete) {
+ g.setColor(GridUI.COMPLETED_HINT_COLOR);
+ } else {
+ g.setColor(GridUI.HINT_TEXT_COLOR);
+ }
+
g.setFont(GridUI.HINT_FONT);
y += this.centerHintHeight;
@@ -566,4 +586,53 @@
this.repaint(rect);
}
}
+
+ /**
+ * Clears a column completed hints.
+ *
+ * @param column column number
+ */
+ void clearColHints(int column) {
+ for (int i = 0; i < this.completedCols[column].length; i++) {
+ this.completedCols[column][i] = false;
+ }
+
+ this.repaint(this.topHintsRect);
+ }
+
+ /**
+ * Marks a column hint as completed.
+ *
+ * @param column the column number
+ * @param hintPos position of the hint in the column
+ */
+ void completedColHint(int column, int hintPos) {
+ this.completedCols[column][hintPos] = true;
+ this.repaint(this.topHintsRect);
+ }
+
+ /**
+ * Clears a row completed hints.
+ *
+ * @param row row number
+ */
+ void clearRowHints(int row) {
+ for (int i = 0; i < this.completedRows[row].length; i++) {
+ this.completedRows[row][i] = false;
+ }
+
+ this.repaint(this.leftHintsRect);
+ }
+
+ /**
+ * Marks a row hint as completed.
+ *
+ * @param row the row number
+ * @param hintPos position of the hint in the row
+ */
+ void completedRowHint(int row, int hintPos) {
+ //GridUI.log.debug("completedRowHint(" + row + ", " + hintPos + ")");
+ this.completedRows[row][hintPos] = true;
+ this.repaint(this.leftHintsRect);
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yva...@us...> - 2007-06-13 18:01:09
|
Revision: 35
http://picross.svn.sourceforge.net/picross/?rev=35&view=rev
Author: yvan_norsa
Date: 2007-06-13 11:01:08 -0700 (Wed, 13 Jun 2007)
Log Message:
-----------
fixed headers
Modified Paths:
--------------
trunk/src/picross/applet/PicrossApplet.java
trunk/src/picross/grid/Box.java
Modified: trunk/src/picross/applet/PicrossApplet.java
===================================================================
--- trunk/src/picross/applet/PicrossApplet.java 2007-06-13 15:32:37 UTC (rev 34)
+++ trunk/src/picross/applet/PicrossApplet.java 2007-06-13 18:01:08 UTC (rev 35)
@@ -33,6 +33,8 @@
package picross.applet;
+import java.awt.Color;
+
import javax.swing.JApplet;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
Modified: trunk/src/picross/grid/Box.java
===================================================================
--- trunk/src/picross/grid/Box.java 2007-06-13 15:32:37 UTC (rev 34)
+++ trunk/src/picross/grid/Box.java 2007-06-13 18:01:08 UTC (rev 35)
@@ -1,45 +1,33 @@
/*
* $Id$
- * \xC9crit le 06/06/2007 par Y. Norsa
*
* Copyright (c) 2007
- * Projet Carte Lorraine de l'Etudiant (CLE)
*
- * Universit\xE9 Henri Poincar\xE9, Nancy
- * Universit\xE9 Nancy2
- * Institut National Polytechnique de Lorraine
- * Universit\xE9 Paul Verlaine, Metz
+ * This software is governed by the CeCILL license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
*
- * Ce projet regroupe les d\xE9veloppements concernant la production
- * et l'exploitation de la Carte Lorraine de l'Etudiant
- * (carte \xE0 puce sans contact Mifare).
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
*
- * Ce logiciel est r\xE9gi par la licence CeCILL soumise au droit fran\xE7ais et
- * respectant les principes de diffusion des logiciels libres. Vous pouvez
- * utiliser, modifier et/ou redistribuer ce programme sous les conditions
- * de la licence CeCILL telle que diffus\xE9e par le CEA, le CNRS et l'INRIA
- * sur le site "http://www.cecill.info".
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
*
- * En contrepartie de l'accessibilit\xE9 au code source et des droits de copie,
- * de modification et de redistribution accord\xE9s par cette licence, il n'est
- * offert aux utilisateurs qu'une garantie limit\xE9e. Pour les m\xEAmes raisons,
- * seule une responsabilit\xE9 restreinte p\xE8se sur l'auteur du programme, le
- * titulaire des droits patrimoniaux et les conc\xE9dants successifs.
- *
- * A cet \xE9gard l'attention de l'utilisateur est attir\xE9e sur les risques
- * associ\xE9s au chargement, \xE0 l'utilisation, \xE0 la modification et/ou au
- * d\xE9veloppement et \xE0 la reproduction du logiciel par l'utilisateur \xE9tant
- * donn\xE9 sa sp\xE9cificit\xE9 de logiciel libre, qui peut le rendre complexe \xE0
- * manipuler et qui le r\xE9serve donc \xE0 des d\xE9veloppeurs et des professionnels
- * avertis poss\xE9dant des connaissances informatiques approfondies. Les
- * utilisateurs sont donc invit\xE9s \xE0 charger et tester l'ad\xE9quation du
- * logiciel \xE0 leurs besoins dans des conditions permettant d'assurer la
- * s\xE9curit\xE9 de leurs syst\xE8mes et ou de leurs donn\xE9es et, plus g\xE9n\xE9ralement,
- * \xE0 l'utiliser et l'exploiter dans les m\xEAmes conditions de s\xE9curit\xE9.
- *
- * Le fait que vous puissiez acc\xE9der \xE0 cet en-t\xEAte signifie que vous avez
- * pris connaissance de la licence CeCILL, et que vous en avez accept\xE9 les
- * termes.
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yva...@us...> - 2008-04-16 10:44:29
|
Revision: 46
http://picross.svn.sourceforge.net/picross/?rev=46&view=rev
Author: yvan_norsa
Date: 2008-04-16 03:44:37 -0700 (Wed, 16 Apr 2008)
Log Message:
-----------
EDT stuff
Modified Paths:
--------------
trunk/src/picross/PicrossMediator.java
trunk/src/picross/app/PicrossApp.java
trunk/src/picross/game/GameMediator.java
trunk/src/picross/grid/GridMediator.java
Modified: trunk/src/picross/PicrossMediator.java
===================================================================
--- trunk/src/picross/PicrossMediator.java 2008-04-16 09:32:18 UTC (rev 45)
+++ trunk/src/picross/PicrossMediator.java 2008-04-16 10:44:37 UTC (rev 46)
@@ -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,
@@ -38,6 +38,8 @@
import fr.cle.mmvcs.Mediateur;
import fr.cle.mmvcs.SimpleEvent;
+import javax.swing.SwingUtilities;
+
//import org.apache.log4j.Logger;
import picross.game.GameMediator;
@@ -106,18 +108,29 @@
//this.view.setContent(grid.getView());
//GameMediator game = new picross.game.random.RandomGameMediator();
- GameMediator game = null;
+ //GameMediator game = null;
- try {
- game = new picross.game.simple.SimpleGameMediator();
- } catch (PicrossException picrossEx) {
- this.view.displayError(picrossEx.getMessage());
- return;
- }
+ Thread worker = new Thread() {
+ public void run() {
+ GameMediator game = null;
- game.addSimpleListener(this);
- this.view.setContent(game.getView());
+ try {
+ game =
+ new picross.game.simple.SimpleGameMediator();
+ } catch (PicrossException picrossEx) {
+ PicrossMediator.this.view
+ .displayError(picrossEx.getMessage());
+ return;
+ }
+ //game.addSimpleListener(this);
+ //this.view.setContent(game.getView());
+ PicrossMediator.this.gameLoaded(game);
+ }
+ };
+
+ worker.start();
+
return;
}
@@ -134,11 +147,26 @@
}
}
- /*** Method ***/
+ /*** Methods ***/
/** Exits the application. */
private void exit() {
this.fireEventPerformed(PicrossController.DISPOSE_CMD);
}
+
+ /**
+ * Callback used to display the game view.
+ *
+ * @param game game reference
+ */
+ private void gameLoaded(final GameMediator game) {
+ game.addSimpleListener(this);
+
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ PicrossMediator.this.view.setContent(game.getView());
+ }
+ });
+ }
}
Modified: trunk/src/picross/app/PicrossApp.java
===================================================================
--- trunk/src/picross/app/PicrossApp.java 2008-04-16 09:32:18 UTC (rev 45)
+++ trunk/src/picross/app/PicrossApp.java 2008-04-16 10:44:37 UTC (rev 46)
@@ -66,9 +66,10 @@
* @param args command line parameters
*/
public static void main(String[] args) {
+ PicrossApp.setupDebugging();
+
SwingUtilities.invokeLater(new Runnable() {
public void run() {
- PicrossApp.setupDebugging();
new PicrossApp();
}
});
Modified: trunk/src/picross/game/GameMediator.java
===================================================================
--- trunk/src/picross/game/GameMediator.java 2008-04-16 09:32:18 UTC (rev 45)
+++ trunk/src/picross/game/GameMediator.java 2008-04-16 10:44:37 UTC (rev 46)
@@ -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,
@@ -37,6 +37,7 @@
import fr.cle.mmvcs.SimpleEvent;
import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
//import org.apache.log4j.Logger;
@@ -72,14 +73,21 @@
public GameMediator() throws PicrossException {
PicrossGrid model = this.initModel();
- int width = model.getWidth();
- int height = model.getHeight();
+ final int width = model.getWidth();
+ final int height = model.getHeight();
- GridMediator grid = new GridMediator(width, height,
+ final GridMediator grid = new GridMediator(width, height,
model.getData());
grid.addSimpleListener(this);
- this.view = this.initView(width, height, grid.getView());
+ // The view has to be init'ed on the EDT
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ GameMediator.this.view =
+ GameMediator.this.initView(width, height,
+ grid.getView());
+ }
+ });
}
/*** Abstract methods ***/
Modified: trunk/src/picross/grid/GridMediator.java
===================================================================
--- trunk/src/picross/grid/GridMediator.java 2008-04-16 09:32:18 UTC (rev 45)
+++ trunk/src/picross/grid/GridMediator.java 2008-04-16 10:44:37 UTC (rev 46)
@@ -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,
@@ -39,6 +39,7 @@
import java.io.FileNotFoundException;
import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
//import org.apache.log4j.Logger;
@@ -73,27 +74,42 @@
* @param data grid content
* @throws PicrossException if there is a probleme while building the view
*/
- public GridMediator(int width, int height, boolean[][] data)
+ public GridMediator(final int width, final int height, boolean[][] data)
throws PicrossException {
this.model = new GridModel(this, data);
- GridController controller = new GridController();
+ final GridController controller = new GridController();
controller.addSimpleListener(this);
this.addSimpleListener(controller);
+ final Box[][] boxes = this.model.getBoxes();
+ final int[][] colData = this.model.getColData();
+ final int[][] rowData = this.model.getRowData();
+ final CompletedHints hints = this.model.getCompletedHints();
+
try {
- this.view = new GridUI(width, height,
- this.model.getBoxes(),
- this.model.getColData(),
- this.model.getRowData(),
- this.model.getCompletedHints(),
- controller);
- } catch (FileNotFoundException fileEx) {
- throw new PicrossException(fileEx);
+ SwingUtilities.invokeLater(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);
+ }
+ });
+ } catch (RuntimeException runtimeEx) {
+ throw ((PicrossException) runtimeEx.getCause());
}
-
- controller.setView(this.view);
}
/*** Method overloaded from the class Mediateur ***/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yva...@us...> - 2008-04-28 09:07:16
|
Revision: 66
http://picross.svn.sourceforge.net/picross/?rev=66&view=rev
Author: yvan_norsa
Date: 2008-04-28 02:07:21 -0700 (Mon, 28 Apr 2008)
Log Message:
-----------
clean-up
Modified Paths:
--------------
trunk/src/picross/PicrossMediator.java
trunk/src/picross/game/simple/SimpleGameMode.java
trunk/src/picross/menus/MenuController.java
trunk/src/picross/menus/MenuMediator.java
trunk/src/picross/menus/MenuUI.java
Added Paths:
-----------
trunk/src/picross/game/simple/LevelMenuController.java
trunk/src/picross/game/simple/LevelMenuMediator.java
trunk/src/picross/game/simple/LevelMenuModel.java
trunk/src/picross/game/simple/LevelMenuUI.java
trunk/src/picross/game/simple/LevelsListCommand.java
trunk/src/picross/game/simple/SelectSizeCommand.java
Removed Paths:
-------------
trunk/src/picross/menus/LevelMenuController.java
trunk/src/picross/menus/LevelMenuMediator.java
trunk/src/picross/menus/LevelMenuModel.java
trunk/src/picross/menus/LevelMenuUI.java
trunk/src/picross/menus/LevelsListCommand.java
trunk/src/picross/menus/SelectSizeCommand.java
Modified: trunk/src/picross/PicrossMediator.java
===================================================================
--- trunk/src/picross/PicrossMediator.java 2008-04-28 08:58:35 UTC (rev 65)
+++ trunk/src/picross/PicrossMediator.java 2008-04-28 09:07:21 UTC (rev 66)
@@ -54,7 +54,7 @@
import picross.grid.GridController;
import picross.menus.GameMenuMediator;
-import picross.menus.LevelMenuMediator;
+//import picross.menus.LevelMenuMediator;
import picross.menus.MainMenuMediator;
import picross.menus.MenuCommand;
import picross.menus.MenuMediator;
@@ -121,10 +121,12 @@
return;
}
+ /*
if (cmd.equals(PicrossController.SELECT_LEVEL_CMD)) {
this.displaySelectLevelMenu();
return;
}
+ */
/*
if (cmd.equals(PicrossController.LEVEL_CMD)) {
@@ -176,9 +178,11 @@
}
/** Displays the level selection menu. */
+ /*
private void displaySelectLevelMenu() {
this.displayMenu(LevelMenuMediator.class);
}
+ */
private void displayWaitScreen() {
this.displayMenu(WaitMenuMediator.class);
Copied: trunk/src/picross/game/simple/LevelMenuController.java (from rev 63, trunk/src/picross/menus/LevelMenuController.java)
===================================================================
--- trunk/src/picross/game/simple/LevelMenuController.java (rev 0)
+++ trunk/src/picross/game/simple/LevelMenuController.java 2008-04-28 09:07:21 UTC (rev 66)
@@ -0,0 +1,89 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 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,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ */
+
+
+package picross.game.simple;
+
+import fr.cle.mmvcs.SimpleEvent;
+
+import picross.menus.MenuController;
+
+import org.apache.log4j.Logger;
+
+/**
+ * @author Y. Norsa
+ */
+class LevelMenuController extends MenuController {
+ /*** Constante ***/
+
+ static final String SIZE_CMD = "SIZE_CMD";
+
+ static final String LEVELS_LIST_CMD = "LEVELS_LIST_CMD";
+
+ /*** Champ statique ***/
+
+ private static Logger log = Logger.getLogger(LevelMenuController.class);
+
+ /*** Champ ***/
+
+ /*** Constructeur ***/
+
+ /**
+ * Constructeur.
+ */
+ /*
+ LevelMenuController() {
+ }
+ */
+
+ /*** M\xE9thode ***/
+
+ public void eventPerformed(SimpleEvent e) {
+ LevelMenuController.log.debug("eventPerformed(" + e + ")");
+
+ String cmd = e.getCommandName();
+
+ if (cmd.equals(picross.game.GameCommand.GAME_CMD)) {
+ return;
+ }
+
+ if (cmd.equals(LevelMenuController.LEVELS_LIST_CMD)) {
+ LevelsListCommand command = (LevelsListCommand) e.getCommand();
+ ((LevelMenuUI) this.getView()).displayLevels(this, command.getList());
+
+ return;
+ }
+
+ super.eventPerformed(e);
+ }
+}
+
Copied: trunk/src/picross/game/simple/LevelMenuMediator.java (from rev 63, trunk/src/picross/menus/LevelMenuMediator.java)
===================================================================
--- trunk/src/picross/game/simple/LevelMenuMediator.java (rev 0)
+++ trunk/src/picross/game/simple/LevelMenuMediator.java 2008-04-28 09:07:21 UTC (rev 66)
@@ -0,0 +1,114 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 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,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ */
+
+
+package picross.game.simple;
+
+import fr.cle.mmvcs.SimpleEvent;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import picross.PicrossException;
+import picross.PicrossUI;
+
+import picross.menus.MenuController;
+import picross.menus.MenuMediator;
+import picross.menus.MenuUI;
+
+/**
+ * Level selection menu.
+ *
+ * @author Y. Norsa
+ */
+public class LevelMenuMediator extends MenuMediator {
+ private static Logger log = Logger.getLogger(LevelMenuMediator.class);
+
+ private LevelMenuModel model;
+
+ /*** Constructor ***/
+
+ /**
+ * Constructor.
+ *
+ * @param ui reference to the main UI
+ * @throws PicrossException if the instantiation of the view fails
+ */
+ public LevelMenuMediator(PicrossUI ui) throws PicrossException {
+ super(ui);
+ }
+
+ /*** Method overloaded from the class MenuMediator ***/
+
+ protected MenuController initController() {
+ MenuController controller = new LevelMenuController();
+ this.addSimpleListener(controller);
+
+ return controller;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected MenuUI initView(PicrossUI ui, MenuController controller)
+ throws PicrossException {
+
+ this.model = new LevelMenuModel();
+ //return new LevelMenuUI(controller, model.getLevelsList());
+ return new LevelMenuUI(controller, this.model.getSizesList());
+ }
+
+ public void eventPerformed(SimpleEvent e) {
+ LevelMenuMediator.log.debug("eventPerformed(" + e + ")");
+
+ String cmd = e.getCommandName();
+
+ if (cmd.equals(LevelMenuController.SIZE_CMD)) {
+ SelectSizeCommand command = (SelectSizeCommand) e.getCommand();
+ this.displayLevels(this.model.getLevels(command.getSize()));
+
+ return;
+ }
+
+ if (cmd.equals(picross.PicrossController.LEVEL_CMD)) {
+ this.fireEventPerformed(new picross.game.GameCommand(new picross.game.simple.SimpleGameMediator(e.getComment())));
+ return;
+ }
+
+ super.eventPerformed(e);
+ }
+
+ private void displayLevels(List<String> levels) {
+ this.fireEventPerformed(new LevelsListCommand(levels));
+ }
+}
+
Copied: trunk/src/picross/game/simple/LevelMenuModel.java (from rev 63, trunk/src/picross/menus/LevelMenuModel.java)
===================================================================
--- trunk/src/picross/game/simple/LevelMenuModel.java (rev 0)
+++ trunk/src/picross/game/simple/LevelMenuModel.java 2008-04-28 09:07:21 UTC (rev 66)
@@ -0,0 +1,110 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 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,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ */
+
+
+package picross.game.simple;
+
+import java.awt.Dimension;
+
+import java.io.IOException;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import picross.Picross;
+import picross.PicrossException;
+
+import picross.game.simple.LevelInfo;
+
+/**
+ * Model for the level selection menu.
+ *
+ * @author Y. Norsa
+ */
+class LevelMenuModel {
+ /*** Field ***/
+
+ /** Level list. */
+ //private List<String> levels;
+
+ private Map<Dimension, List<String>> levels;
+
+ /*** Constructor ***/
+
+ /**
+ * Constructor.
+ *
+ * @throws PicrossException if an error arises during the levels listing
+ */
+ LevelMenuModel() throws PicrossException {
+ this.levels = new HashMap<Dimension, List<String>>();
+
+ List<LevelInfo> infos = null;
+
+ try {
+ //this.levels = Picross.listDataFiles();
+ infos = Picross.listDataFiles();
+ } catch (IOException ioEx) {
+ throw new PicrossException(ioEx);
+ }
+
+ for (LevelInfo info : infos) {
+ Dimension levelSize = info.getDimension();
+ List<String> levelsList = this.levels.get(levelSize);
+
+ if (levelsList == null) {
+ levelsList = new ArrayList<String>();
+ this.levels.put(levelSize, levelsList);
+ }
+
+ levelsList.add(info.getName());
+ }
+ }
+
+ /*** Method ***/
+
+ /**
+ * Returns the levels list.
+ *
+ * @return list of the level files
+ */
+ List<String> getLevels(Dimension size) {
+ return this.levels.get(size);
+ }
+
+ List<Dimension> getSizesList() {
+ return new ArrayList<Dimension>(this.levels.keySet());
+ }
+}
+
Copied: trunk/src/picross/game/simple/LevelMenuUI.java (from rev 64, trunk/src/picross/menus/LevelMenuUI.java)
===================================================================
--- trunk/src/picross/game/simple/LevelMenuUI.java (rev 0)
+++ trunk/src/picross/game/simple/LevelMenuUI.java 2008-04-28 09:07:21 UTC (rev 66)
@@ -0,0 +1,113 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 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,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ */
+
+
+package picross.game.simple;
+
+import fr.cle.mmvcs.SimpleEvent;
+import fr.cle.mmvcs.SimpleListener;
+
+import java.awt.Dimension;
+
+import java.util.List;
+
+import picross.PicrossController;
+
+import picross.menus.MenuUI;
+
+/**
+ * UI for the level selection menu.
+ *
+ * @author Y. Norsa
+ */
+class LevelMenuUI extends MenuUI {
+ /*** Constant ***/
+
+ /** Serialisation ID. */
+ private static final long serialVersionUID = 6178785913505637523L;
+
+ /*** Constructor ***/
+
+ /**
+ * Constructor.
+ *
+ * @param listener listener for the buttons
+ * @param levels levels list
+ */
+ //LevelMenuUI(SimpleListener listener, List<String> levels) {
+ LevelMenuUI(SimpleListener listener, List<Dimension> sizes) {
+ super();
+
+ int x = 150;
+ int y = 150;
+
+ int nbSizes = sizes.size();
+
+ for (int i = 0; i < nbSizes; i++) {
+ Dimension currentDim = sizes.get(i);
+ String size = (int) currentDim.getWidth() + "x"
+ + (int) currentDim.getHeight();
+
+ SimpleEvent event = new SimpleEvent(new SelectSizeCommand(currentDim));
+ this.addSimpleButton(size, event, listener, x, y);
+
+ y += 75;
+
+ if (y == 375) {
+ x = 250;
+ y = 150;
+ }
+ }
+ }
+
+ void displayLevels(SimpleListener listener, List<String> levels) {
+ this.removeAll();
+
+ int x = 50;
+ int y = 150;
+
+ for (String level : levels) {
+ SimpleEvent event = new SimpleEvent(PicrossController.LEVEL_CMD, level);
+ this.addSimpleButton(level, event, listener, x, y);
+
+ y += 75;
+
+ if (y == 375) {
+ x = 250;
+ y = 150;
+ }
+ }
+
+ this.repaint();
+ }
+}
+
Copied: trunk/src/picross/game/simple/LevelsListCommand.java (from rev 63, trunk/src/picross/menus/LevelsListCommand.java)
===================================================================
--- trunk/src/picross/game/simple/LevelsListCommand.java (rev 0)
+++ trunk/src/picross/game/simple/LevelsListCommand.java 2008-04-28 09:07:21 UTC (rev 66)
@@ -0,0 +1,69 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 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,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ */
+
+
+package picross.game.simple;
+
+import fr.cle.mmvcs.NamedCommand;
+
+import java.util.List;
+
+/**
+ * @author Y. Norsa
+ */
+class LevelsListCommand extends NamedCommand {
+ /*** Constante ***/
+
+ /*** Champ statique ***/
+
+ /*** Champ ***/
+
+ private List<String> list;
+
+ /*** Constructeur ***/
+
+ /**
+ * Constructeur.
+ */
+ LevelsListCommand(List<String> levels) {
+ super(LevelMenuController.LEVELS_LIST_CMD);
+
+ this.list = levels;
+ }
+
+ /*** M\xE9thode ***/
+
+ List<String> getList() {
+ return this.list;
+ }
+}
+
Copied: trunk/src/picross/game/simple/SelectSizeCommand.java (from rev 63, trunk/src/picross/menus/SelectSizeCommand.java)
===================================================================
--- trunk/src/picross/game/simple/SelectSizeCommand.java (rev 0)
+++ trunk/src/picross/game/simple/SelectSizeCommand.java 2008-04-28 09:07:21 UTC (rev 66)
@@ -0,0 +1,69 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 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,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ */
+
+
+package picross.game.simple;
+
+import fr.cle.mmvcs.NamedCommand;
+
+import java.awt.Dimension;
+
+/**
+ * @author Y. Norsa
+ */
+class SelectSizeCommand extends NamedCommand {
+ /*** Constante ***/
+
+ /*** Champ statique ***/
+
+ /*** Champ ***/
+
+ private Dimension size;
+
+ /*** Constructeur ***/
+
+ /**
+ * Constructeur.
+ */
+ SelectSizeCommand(Dimension dim) {
+ super(LevelMenuController.SIZE_CMD);
+
+ this.size = dim;
+ }
+
+ /*** M\xE9thode ***/
+
+ Dimension getSize() {
+ return this.size;
+ }
+}
+
Modified: trunk/src/picross/game/simple/SimpleGameMode.java
===================================================================
--- trunk/src/picross/game/simple/SimpleGameMode.java 2008-04-28 08:58:35 UTC (rev 65)
+++ trunk/src/picross/game/simple/SimpleGameMode.java 2008-04-28 09:07:21 UTC (rev 66)
@@ -78,7 +78,7 @@
public SimpleButton<JButton> getButton() {
ImageIcon icon =
Picross.getLocalizedImage(SimpleGameMode.SELECT_BUTTON_IMAGE);
- SimpleEvent event = new SimpleEvent(new picross.menus.MenuCommand(picross.menus.LevelMenuMediator.class));
+ SimpleEvent event = new SimpleEvent(new picross.menus.MenuCommand(LevelMenuMediator.class));
SimpleButton<JButton> button = new SimpleButton<JButton>("", event) { };
button.getButton().setIcon(icon);
Deleted: trunk/src/picross/menus/LevelMenuController.java
===================================================================
--- trunk/src/picross/menus/LevelMenuController.java 2008-04-28 08:58:35 UTC (rev 65)
+++ trunk/src/picross/menus/LevelMenuController.java 2008-04-28 09:07:21 UTC (rev 66)
@@ -1,87 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (c) 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,
- * 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.menus;
-
-import fr.cle.mmvcs.SimpleEvent;
-
-import org.apache.log4j.Logger;
-
-/**
- * @author Y. Norsa
- */
-class LevelMenuController extends MenuController {
- /*** Constante ***/
-
- static final String SIZE_CMD = "SIZE_CMD";
-
- static final String LEVELS_LIST_CMD = "LEVELS_LIST_CMD";
-
- /*** Champ statique ***/
-
- private static Logger log = Logger.getLogger(LevelMenuController.class);
-
- /*** Champ ***/
-
- /*** Constructeur ***/
-
- /**
- * Constructeur.
- */
- /*
- LevelMenuController() {
- }
- */
-
- /*** M\xE9thode ***/
-
- public void eventPerformed(SimpleEvent e) {
- LevelMenuController.log.debug("eventPerformed(" + e + ")");
-
- String cmd = e.getCommandName();
-
- if (cmd.equals(picross.game.GameCommand.GAME_CMD)) {
- return;
- }
-
- if (cmd.equals(LevelMenuController.LEVELS_LIST_CMD)) {
- LevelsListCommand command = (LevelsListCommand) e.getCommand();
- ((LevelMenuUI) this.getView()).displayLevels(this, command.getList());
-
- return;
- }
-
- super.eventPerformed(e);
- }
-}
-
Deleted: trunk/src/picross/menus/LevelMenuMediator.java
===================================================================
--- trunk/src/picross/menus/LevelMenuMediator.java 2008-04-28 08:58:35 UTC (rev 65)
+++ trunk/src/picross/menus/LevelMenuMediator.java 2008-04-28 09:07:21 UTC (rev 66)
@@ -1,110 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (c) 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,
- * 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.menus;
-
-import fr.cle.mmvcs.SimpleEvent;
-
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-import picross.PicrossException;
-import picross.PicrossUI;
-
-/**
- * Level selection menu.
- *
- * @author Y. Norsa
- */
-public class LevelMenuMediator extends MenuMediator {
- private static Logger log = Logger.getLogger(LevelMenuMediator.class);
-
- private LevelMenuModel model;
-
- /*** Constructor ***/
-
- /**
- * Constructor.
- *
- * @param ui reference to the main UI
- * @throws PicrossException if the instantiation of the view fails
- */
- public LevelMenuMediator(PicrossUI ui) throws PicrossException {
- super(ui);
- }
-
- /*** Method overloaded from the class MenuMediator ***/
-
- protected MenuController initController() {
- MenuController controller = new LevelMenuController();
- this.addSimpleListener(controller);
-
- return controller;
- }
-
- /** {@inheritDoc} */
- @Override
- protected MenuUI initView(PicrossUI ui, MenuController controller)
- throws PicrossException {
-
- this.model = new LevelMenuModel();
- //return new LevelMenuUI(controller, model.getLevelsList());
- return new LevelMenuUI(controller, this.model.getSizesList());
- }
-
- public void eventPerformed(SimpleEvent e) {
- LevelMenuMediator.log.debug("eventPerformed(" + e + ")");
-
- String cmd = e.getCommandName();
-
- if (cmd.equals(LevelMenuController.SIZE_CMD)) {
- SelectSizeCommand command = (SelectSizeCommand) e.getCommand();
- this.displayLevels(this.model.getLevels(command.getSize()));
-
- return;
- }
-
- if (cmd.equals(picross.PicrossController.LEVEL_CMD)) {
- this.fireEventPerformed(new picross.game.GameCommand(new picross.game.simple.SimpleGameMediator(e.getComment())));
- return;
- }
-
- super.eventPerformed(e);
- }
-
- private void displayLevels(List<String> levels) {
- this.fireEventPerformed(new LevelsListCommand(levels));
- }
-}
-
Deleted: trunk/src/picross/menus/LevelMenuModel.java
===================================================================
--- trunk/src/picross/menus/LevelMenuModel.java 2008-04-28 08:58:35 UTC (rev 65)
+++ trunk/src/picross/menus/LevelMenuModel.java 2008-04-28 09:07:21 UTC (rev 66)
@@ -1,110 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (c) 2008
- *
- * This software is governed by the CeCILL license under French law and
- * abiding by the rules of distribution of free ...
[truncated message content] |
|
From: <yva...@us...> - 2008-04-28 12:47:11
|
Revision: 68
http://picross.svn.sourceforge.net/picross/?rev=68&view=rev
Author: yvan_norsa
Date: 2008-04-28 05:47:06 -0700 (Mon, 28 Apr 2008)
Log Message:
-----------
findbugs
Modified Paths:
--------------
trunk/src/picross/Picross.java
trunk/src/picross/PicrossMediator.java
trunk/src/picross/app/MainMenuAppUI.java
trunk/src/picross/app/PicrossApp.java
trunk/src/picross/applet/MainMenuAppletUI.java
trunk/src/picross/game/random/RandomGameMode.java
trunk/src/picross/game/simple/LevelMenuMediator.java
trunk/src/picross/game/simple/LevelMenuUI.java
trunk/src/picross/game/simple/SimpleGameMode.java
trunk/src/picross/grid/GridController.java
trunk/src/picross/grid/GridModel.java
trunk/src/picross/grid/GridUI.java
trunk/src/picross/menus/GameMenuMediator.java
trunk/src/picross/menus/MainMenuMediator.java
trunk/src/picross/menus/MainMenuUI.java
trunk/src/picross/menus/MenuMediator.java
trunk/src/picross/menus/MenuUI.java
trunk/src/picross/menus/WaitMenuMediator.java
Added Paths:
-----------
trunk/src/picross/grid/HintBoxInfos.java
trunk/src/picross/menus/PicrossButton.java
Modified: trunk/src/picross/Picross.java
===================================================================
--- trunk/src/picross/Picross.java 2008-04-28 12:33:55 UTC (rev 67)
+++ trunk/src/picross/Picross.java 2008-04-28 12:47:06 UTC (rev 68)
@@ -47,7 +47,7 @@
import javax.swing.ImageIcon;
-import org.apache.log4j.Logger;
+//import org.apache.log4j.Logger;
import picross.game.simple.FileInfo;
import picross.game.simple.LevelInfo;
@@ -73,7 +73,7 @@
/*** Static field ***/
/** The class' logger. */
- private static Logger log = Logger.getLogger(Picross.class);
+ //private static Logger log = Logger.getLogger(Picross.class);
/*** Constructor ***/
Modified: trunk/src/picross/PicrossMediator.java
===================================================================
--- trunk/src/picross/PicrossMediator.java 2008-04-28 12:33:55 UTC (rev 67)
+++ trunk/src/picross/PicrossMediator.java 2008-04-28 12:47:06 UTC (rev 68)
@@ -42,14 +42,14 @@
import javax.swing.SwingUtilities;
-import org.apache.log4j.Logger;
+//import org.apache.log4j.Logger;
import picross.game.GameCommand;
import picross.game.GameMediator;
import picross.game.random.RandomGameMediator;
-import picross.game.simple.SimpleGameMediator;
+//import picross.game.simple.SimpleGameMediator;
import picross.grid.GridController;
@@ -69,7 +69,7 @@
/*** Static field ***/
/** Class' logger. */
- private static Logger log = Logger.getLogger(PicrossMediator.class);
+ //private static Logger log = Logger.getLogger(PicrossMediator.class);
/*** Field ***/
@@ -116,6 +116,7 @@
}
*/
+ // FIXME doesn't belong here
if (cmd.equals(PicrossController.NEXT_RANDOM_GAME_CMD)) {
this.startRandomGame();
return;
@@ -198,8 +199,8 @@
try {
try {
- menu = menuClass.getConstructor(PicrossUI.class)
- .newInstance(this.view);
+ menu = menuClass.getConstructor()//PicrossUI.class)
+ .newInstance(/*this.view*/);
} catch (NoSuchMethodException methodEx) {
throw new PicrossException(methodEx);
} catch (InstantiationException instantiationEx) {
@@ -207,9 +208,12 @@
} catch (IllegalAccessException accessEx) {
throw new PicrossException(accessEx);
} catch (InvocationTargetException targetEx) {
- targetEx.printStackTrace();
- throw (PicrossException) targetEx.getCause();
+ //targetEx.printStackTrace();
+ //throw (PicrossException) targetEx.getCause();
+ throw new PicrossException(targetEx);
}
+
+ menu.init(this.view);
} catch (PicrossException picrossEx) {
this.fireEventPerformed(PicrossController.ERROR_CMD,
picrossEx.getMessage());
Modified: trunk/src/picross/app/MainMenuAppUI.java
===================================================================
--- trunk/src/picross/app/MainMenuAppUI.java 2008-04-28 12:33:55 UTC (rev 67)
+++ trunk/src/picross/app/MainMenuAppUI.java 2008-04-28 12:47:06 UTC (rev 68)
@@ -79,9 +79,10 @@
* @param controller controller for the buttons
* @throws MissingImageException if a button image can't be found
*/
- public MainMenuAppUI(ActionListener controller) {
- super(controller);
+ protected void init(ActionListener controller) {
+ super.init(controller);
+
this.addButton(MainMenuAppUI.EXIT_BUTTON_IMAGE,
PicrossController.EXIT_CMD,
controller,
Modified: trunk/src/picross/app/PicrossApp.java
===================================================================
--- trunk/src/picross/app/PicrossApp.java 2008-04-28 12:33:55 UTC (rev 67)
+++ trunk/src/picross/app/PicrossApp.java 2008-04-28 12:47:06 UTC (rev 68)
@@ -78,6 +78,7 @@
/*** Static method ***/
/** Tries to load the debugging tools from debug.jar. */
+ @SuppressWarnings("unchecked")
private static void setupDebugging() {
try {
Class managerClass = Class.forName(
Modified: trunk/src/picross/applet/MainMenuAppletUI.java
===================================================================
--- trunk/src/picross/applet/MainMenuAppletUI.java 2008-04-28 12:33:55 UTC (rev 67)
+++ trunk/src/picross/applet/MainMenuAppletUI.java 2008-04-28 12:47:06 UTC (rev 68)
@@ -66,9 +66,10 @@
* @param controller controller for the buttons
* @throws MissingImageException if a button image can't be found
*/
- public MainMenuAppletUI(ActionListener controller) {
- super(controller);
+ protected void init(ActionListener controller) {
+ super.init(controller);
+
this.setBackground(Color.WHITE);
}
Modified: trunk/src/picross/game/random/RandomGameMode.java
===================================================================
--- trunk/src/picross/game/random/RandomGameMode.java 2008-04-28 12:33:55 UTC (rev 67)
+++ trunk/src/picross/game/random/RandomGameMode.java 2008-04-28 12:47:06 UTC (rev 68)
@@ -44,6 +44,8 @@
import picross.game.GameMode;
+import picross.menus.PicrossButton;
+
/**
* @author Y. Norsa
*/
@@ -77,10 +79,10 @@
public SimpleButton<JButton> getButton() {
ImageIcon icon = Picross.getLocalizedImage(RandomGameMode.RANDOM_BUTTON_IMAGE);
SimpleEvent event = new SimpleEvent(new picross.game.GameCommand(new RandomGameMediator()));
- SimpleButton<JButton> button = new SimpleButton<JButton>(null, event) { };
- button.getButton().setIcon(icon);
+ /*PicrossButton button = */return new PicrossButton(icon, event);
+ //button.getButton().setIcon(icon);
- return button;
+ //return button;
}
}
Modified: trunk/src/picross/game/simple/LevelMenuMediator.java
===================================================================
--- trunk/src/picross/game/simple/LevelMenuMediator.java 2008-04-28 12:33:55 UTC (rev 67)
+++ trunk/src/picross/game/simple/LevelMenuMediator.java 2008-04-28 12:47:06 UTC (rev 68)
@@ -54,7 +54,7 @@
public class LevelMenuMediator extends MenuMediator {
private static Logger log = Logger.getLogger(LevelMenuMediator.class);
- private LevelMenuModel model;
+ private LevelMenuModel model = null;
/*** Constructor ***/
@@ -64,9 +64,11 @@
* @param ui reference to the main UI
* @throws PicrossException if the instantiation of the view fails
*/
+ /*
public LevelMenuMediator(PicrossUI ui) throws PicrossException {
super(ui);
}
+ */
/*** Method overloaded from the class MenuMediator ***/
@@ -82,13 +84,21 @@
protected MenuUI initView(PicrossUI ui, MenuController controller)
throws PicrossException {
+ LevelMenuMediator.log.debug("initView()");
+
this.model = new LevelMenuModel();
+
+ LevelMenuMediator.log.debug("this : " + this);
+ LevelMenuMediator.log.debug("this.model : " + this.model);
+
//return new LevelMenuUI(controller, model.getLevelsList());
return new LevelMenuUI(controller, this.model.getSizesList());
}
public void eventPerformed(SimpleEvent e) {
LevelMenuMediator.log.debug("eventPerformed(" + e + ")");
+ LevelMenuMediator.log.debug("this : " + this);
+ LevelMenuMediator.log.debug("this.model : " + this.model);
String cmd = e.getCommandName();
Modified: trunk/src/picross/game/simple/LevelMenuUI.java
===================================================================
--- trunk/src/picross/game/simple/LevelMenuUI.java 2008-04-28 12:33:55 UTC (rev 67)
+++ trunk/src/picross/game/simple/LevelMenuUI.java 2008-04-28 12:47:06 UTC (rev 68)
@@ -61,7 +61,7 @@
* Constructor.
*
* @param listener listener for the buttons
- * @param levels levels list
+ * @param sizes available grid sizes
*/
//LevelMenuUI(SimpleListener listener, List<String> levels) {
LevelMenuUI(SimpleListener listener, List<Dimension> sizes) {
@@ -70,10 +70,11 @@
int x = 150;
int y = 150;
- int nbSizes = sizes.size();
+ //int nbSizes = sizes.size();
- for (int i = 0; i < nbSizes; i++) {
- Dimension currentDim = sizes.get(i);
+ //for (int i = 0; i < nbSizes; i++) {
+ //Dimension currentDim = sizes.get(i);
+ for (Dimension currentDim : sizes) {
String size = (int) currentDim.getWidth() + "x"
+ (int) currentDim.getHeight();
Modified: trunk/src/picross/game/simple/SimpleGameMode.java
===================================================================
--- trunk/src/picross/game/simple/SimpleGameMode.java 2008-04-28 12:33:55 UTC (rev 67)
+++ trunk/src/picross/game/simple/SimpleGameMode.java 2008-04-28 12:47:06 UTC (rev 68)
@@ -41,6 +41,8 @@
import picross.game.GameMode;
+import picross.menus.PicrossButton;
+
import javax.swing.ImageIcon;
import javax.swing.JButton;
@@ -79,10 +81,10 @@
ImageIcon icon =
Picross.getLocalizedImage(SimpleGameMode.SELECT_BUTTON_IMAGE);
SimpleEvent event = new SimpleEvent(new picross.menus.MenuCommand(LevelMenuMediator.class));
- SimpleButton<JButton> button = new SimpleButton<JButton>("", event) { };
- button.getButton().setIcon(icon);
+ /*PicrossButton button = */return new PicrossButton(icon, event);
+ //button.getButton().setIcon(icon);
- return button;
+ //return button;
}
}
Modified: trunk/src/picross/grid/GridController.java
===================================================================
--- trunk/src/picross/grid/GridController.java 2008-04-28 12:33:55 UTC (rev 67)
+++ trunk/src/picross/grid/GridController.java 2008-04-28 12:47:06 UTC (rev 68)
@@ -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 ***/
Modified: trunk/src/picross/grid/GridModel.java
===================================================================
--- trunk/src/picross/grid/GridModel.java 2008-04-28 12:33:55 UTC (rev 67)
+++ trunk/src/picross/grid/GridModel.java 2008-04-28 12:47:06 UTC (rev 68)
@@ -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 ***/
@@ -93,6 +93,8 @@
GridModel(IGridMediator mediator, boolean[][] data)
throws IllegalArgumentException {
+ GridModel.checkModelParams(mediator, data);
+ /*
if (mediator == null) {
throw new IllegalArgumentException("mediator cannot be null");
}
@@ -118,7 +120,7 @@
+ expectedSize);
}
}
-
+ */
this.mediator = mediator;
this.data = data;
@@ -130,6 +132,8 @@
}
}
+ this.colData = GridModel.getColHints(this.data);
+ /*
// Grid of columns hints
List<List<Integer>> colHints = new ArrayList<List<Integer>>();
@@ -167,7 +171,7 @@
colHints.add(current);
}
-
+*/
/*
* Final array containing the hints, in the following form :
*
@@ -183,6 +187,7 @@
* |_|X|_|
* |-----|
*/
+ /*
this.colData = new int[data.length][max];
for (int i = 0; i < max; i++) {
@@ -203,11 +208,14 @@
}
}
}
+*/
+ this.rowData = GridModel.getRowHints(data);
+ /*
// Same operations as for the columns, basically
List<List<Integer>> rowHints = new ArrayList<List<Integer>>();
- max = 0;
+ int max = 0;
for (int i = 0; i < data[0].length; i++) {
List<Integer> current = new ArrayList<Integer>();
@@ -256,6 +264,7 @@
}
}
}
+ */
this.completedHints =
new CompletedHints(data.length, this.colData[0].length,
@@ -278,6 +287,167 @@
/*** Static methods ***/
+ private static void checkModelParams(IGridMediator mediator, boolean[][] data) {
+ if (mediator == null) {
+ throw new IllegalArgumentException("mediator cannot be null");
+ }
+
+ if (data == null) {
+ throw new IllegalArgumentException("data cannot be null");
+ }
+
+ if (data.length == 0) {
+ throw new IllegalArgumentException("data cannot be empty");
+ }
+
+ int expectedSize = data[0].length;
+
+ if (expectedSize == 0) {
+ throw new IllegalArgumentException("data cannot be empty");
+ }
+
+ for (int i = 0; i < data.length; i++) {
+ if (data[i].length == 0 || data[i].length != expectedSize) {
+ throw new IllegalArgumentException("data[i].length "
+ + "is supposed to be "
+ + expectedSize);
+ }
+ }
+ }
+
+ private static int[][] getColHints(boolean[][] data) {
+ // Grid of columns hints
+ List<List<Integer>> colHints = new ArrayList<List<Integer>>();
+
+ // Largest number of hints for a column
+ int max = 0;
+
+ for (boolean[] col : data) {
+ List<Integer> current = new ArrayList<Integer>();
+
+ // Current hint
+ int chain = 0;
+
+ for (boolean cell : col) {
+ if (cell) {
+ chain++;
+ } else if (chain > 0) {
+ // We've reached the end of a series of checked boxes
+ current.add(chain);
+ chain = 0;
+ }
+ }
+
+ if (chain > 0) {
+ current.add(chain);
+ } else if (current.size() == 0) {
+ // If this column is empty, we add a "0" hint
+ current.add(0);
+ }
+
+ int currentSize = current.size();
+
+ if (currentSize > max) {
+ max = currentSize;
+ }
+
+ colHints.add(current);
+ }
+
+ /*
+ * Final array containing the hints, in the following form :
+ *
+ * 1
+ * 0 2 1
+ *
+ * Which corresponds to the following grid :
+ *
+ * |-----|
+ * |_|X|_|
+ * |_|_|X|
+ * |_|X|_|
+ * |_|X|_|
+ * |-----|
+ */
+ int[][] result = new int[data.length][max];
+
+ for (int i = 0; i < max; i++) {
+ // Minimal number of hints for the current column to be considered
+ int ref = max - i;
+
+ // Current hint row
+ int currentRow = ref - 1;
+
+ for (int j = 0; j < colHints.size(); j++) {
+ List<Integer> currentCol = colHints.get(j);
+ int size = currentCol.size();
+
+ if (size >= ref) {
+ result[j][currentRow] = currentCol.get(size - ref);
+ } else {
+ result[j][currentRow] = GridModel.EMPTY_HINT;
+ }
+ }
+ }
+
+ return result;
+ }
+
+ private static int[][] getRowHints(boolean[][] data) {
+ List<List<Integer>> rowHints = new ArrayList<List<Integer>>();
+ int max = 0;
+
+ for (int i = 0; i < data[0].length; i++) {
+ List<Integer> current = new ArrayList<Integer>();
+
+ int chain = 0;
+
+ for (int j = 0; j < data.length; j++) {
+ if (data[j][i]) {
+ chain++;
+ } else if (chain > 0) {
+ current.add(chain);
+ chain = 0;
+ }
+ }
+
+ if (chain > 0) {
+ current.add(chain);
+ } else if (current.size() == 0) {
+ current.add(0);
+ }
+
+ int currentSize = current.size();
+
+ if (currentSize > max) {
+ max = currentSize;
+ }
+
+ rowHints.add(current);
+ }
+
+ int[][] result = new int[data[0].length][max];
+ int nbRows = rowHints.size();
+
+ for (int i = 0; i < max; i++) {
+ int ref = max - i;
+
+ for (int j = 0; j < nbRows; j++) {
+ List<Integer> currentRow = rowHints.get(j);
+ int size = currentRow.size();
+
+ if (size >= ref) {
+ result[j][i] =
+ currentRow.get(i - Math.abs(size - max));
+ } else {
+ result[j][i] = GridModel.EMPTY_HINT;
+ }
+ }
+ }
+
+ return result;
+ }
+
/**
* Returns the index of the first non-empty hint.
*
@@ -434,9 +604,9 @@
* @return boolean stating wether the row is empty or not
*/
private boolean emptyRow(int row) {
- int index = this.getFirstHintIndex(this.rowData[row]);
+ int index = GridModel.getFirstHintIndex(this.rowData[row]);
- return (index == this.getLastHintIndex(this.rowData[row]))
+ return (index == GridModel.getLastHintIndex(this.rowData[row]))
&& (this.rowData[row][index] == 0);
}
@@ -591,9 +761,9 @@
* @return boolean stating wether the column is empty or not
*/
private boolean emptyCol(int col) {
- int index = this.getFirstHintIndex(this.colData[col]);
+ int index = GridModel.getFirstHintIndex(this.colData[col]);
- return (index == this.getLastHintIndex(this.colData[col]))
+ return (index == GridModel.getLastHintIndex(this.colData[col]))
&& (this.colData[col][index] == 0);
}
Modified: trunk/src/picross/grid/GridUI.java
===================================================================
--- trunk/src/picross/grid/GridUI.java 2008-04-28 12:33:55 UTC (rev 67)
+++ trunk/src/picross/grid/GridUI.java 2008-04-28 12:47:06 UTC (rev 68)
@@ -152,17 +152,21 @@
private int bottomBoundary;
/** Rectangles occupied by the top hints. */
- private Rectangle[] topHintsRects;
+ //private Rectangle[] topHintsRects;
/** Precomputed images containing the top hints boxes. */
- private transient BufferedImage[] topHintsBoxes;
+ //private transient BufferedImage[] topHintsBoxes;
+ private transient HintBoxInfos[] topHints;
+
/** Rectangles occupied by the left hints. */
- private Rectangle[] leftHintsRects;
+ //private Rectangle[] leftHintsRects;
/** Precomputed images containing the left hints boxes. */
- private transient BufferedImage[] leftHintsBoxes;
+ //private transient BufferedImage[] leftHintsBoxes;
+ private transient HintBoxInfos[] leftHints;
+
/** Current state of the grid. */
private transient Box[][] boxes;
@@ -253,14 +257,18 @@
Rectangle clipRect = newG.getClipBounds();
- for (int i = 0; i < this.topHintsRects.length; i++) {
- if (this.topHintsRects[i].intersects(clipRect)) {
+ //for (int i = 0; i < this.topHintsRects.length; i++) {
+ for (int i = 0; i < this.topHints.length; i++) {
+ //if (this.topHintsRects[i].intersects(clipRect)) {
+ if (this.topHints[i].intersects(clipRect)) {
this.drawTopHints(newG, i);
}
}
- for (int i = 0; i < this.leftHintsRects.length; i++) {
- if (this.leftHintsRects[i].intersects(clipRect)) {
+ //for (int i = 0; i < this.leftHintsRects.length; i++) {
+ for (int i = 0; i < this.leftHints.length; i++) {
+ //if (this.leftHintsRects[i].intersects(clipRect)) {
+ if (this.leftHints[i].intersects(clipRect)) {
this.drawLeftHints(newG, i);
}
}
@@ -341,20 +349,34 @@
+ (this.height * GridUI.BOX_HEIGHT);
// Space occupied by the hints
- this.topHintsRects = new Rectangle[this.width];
+ //this.topHintsRects = new Rectangle[this.width];
+ this.topHints = new HintBoxInfos[this.width];
- for (int i = 0; i < this.topHintsRects.length; i++) {
- this.topHintsRects[i] =
+ //for (int i = 0; i < this.topHintsRects.length; i++) {
+ for (int i = 0; i < this.topHints.length; i++) {
+ this.topHints[i] = new HintBoxInfos();
+
+ //this.topHintsRects[i] =
+ this.topHints[i].setRect(
new Rectangle(this.leftBoundary + (i * GridUI.BOX_WIDTH), 0,
- GridUI.BOX_WIDTH, this.topBoundary);
+ GridUI.BOX_WIDTH, this.topBoundary)
+ )
+ ;
}
- this.leftHintsRects = new Rectangle[this.height];
+ //this.leftHintsRects = new Rectangle[this.height];
+ this.leftHints = new HintBoxInfos[this.height];
- for (int i = 0; i < this.leftHintsRects.length; i++) {
- this.leftHintsRects[i] =
+ //for (int i = 0; i < this.leftHintsRects.length; i++) {
+ for (int i = 0; i < this.leftHints.length; i++) {
+ this.leftHints[i] = new HintBoxInfos();
+
+ //this.leftHintsRects[i] =
+ this.leftHints[i].setRect(
new Rectangle(0, this.topBoundary + (i * GridUI.BOX_HEIGHT),
- this.leftBoundary, GridUI.BOX_HEIGHT);
+ this.leftBoundary, GridUI.BOX_HEIGHT)
+ )
+ ;
}
this.topHintsX = this.leftBoundary
@@ -457,18 +479,25 @@
* @param topHintsStart coordinate where the boxes begin
*/
private void initTopHints(int topHintsStart) {
- this.topHintsBoxes = new BufferedImage[this.width];
+ //this.topHintsBoxes = new BufferedImage[this.width];
- for (int k = 0; k < this.topHintsBoxes.length; k++) {
- this.topHintsBoxes[k] =
+ //for (int k = 0; k < this.topHintsBoxes.length; k++) {
+ for (int k = 0; k < this.topHints.length; k++) {
+ //this.topHintsBoxes[k] =
+ this.topHints[k].setBox(
new BufferedImage(GridUI.BOX_WIDTH, this.topBoundary,
- BufferedImage.TYPE_INT_RGB);
+ BufferedImage.TYPE_INT_RGB)
+ )
+ ;
- Graphics2D g2d = this.topHintsBoxes[k].createGraphics();
+ //Graphics2D g2d = this.topHintsBoxes[k].createGraphics();
+ Graphics2D g2d = this.topHints[k].createBoxGraphics();
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0,
- this.topHintsRects[k].width,
- this.topHintsRects[k].height);
+ //this.topHintsRects[k].width,
+ this.topHints[k].getWidth(),
+ //this.topHintsRects[k].height);
+ this.topHints[k].getHeight());
int y = 0;
@@ -488,18 +517,25 @@
* @param leftHintsStart coordinate where the boxes begin
*/
private void initLeftHints(int leftHintsStart) {
- this.leftHintsBoxes = new BufferedImage[this.height];
+ //this.leftHintsBoxes = new BufferedImage[this.height];
- for (int k = 0; k < this.leftHintsBoxes.length; k++) {
- this.leftHintsBoxes[k] =
+ //for (int k = 0; k < this.leftHintsBoxes.length; k++) {
+ for (int k = 0; k < this.leftHints.length; k++) {
+ //this.leftHintsBoxes[k] =
+ this.leftHints[k].setBox(
new BufferedImage(this.leftBoundary, GridUI.BOX_HEIGHT,
- BufferedImage.TYPE_INT_RGB);
+ BufferedImage.TYPE_INT_RGB)
+ )
+ ;
- Graphics2D g2d = this.leftHintsBoxes[k].createGraphics();
+ //Graphics2D g2d = this.leftHintsBoxes[k].createGraphics();
+ Graphics2D g2d = this.leftHints[k].createBoxGraphics();
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0,
- this.leftHintsRects[k].width,
- this.leftHintsRects[k].height);
+ //this.leftHintsRects[k].width,
+ this.leftHints[k].getWidth(),
+ //this.leftHintsRects[k].height);
+ this.leftHints[k].getHeight());
int x = 0;
@@ -521,8 +557,10 @@
private void drawTopHints(Graphics g, int col) {
//GridUI.log.debug("drawTopHints(g, " + col + ")");
- g.drawImage(this.topHintsBoxes[col],
- this.topHintsRects[col].x, this.topHintsRects[col].y,
+ g.drawImage(//this.topHintsBoxes[col],
+ this.topHints[col].getBox(),
+ //this.topHintsRects[col].x, this.topHintsRects[col].y,
+ this.topHints[col].getX(), this.topHints[col].getY(),
null);
g.setFont(GridUI.HINT_FONT);
@@ -547,8 +585,10 @@
* @param g the graphics context
*/
private void drawLeftHints(Graphics g, int row) {
- g.drawImage(this.leftHintsBoxes[row],
- this.leftHintsRects[row].x, this.leftHintsRects[row].y,
+ g.drawImage(//this.leftHintsBoxes[row],
+ this.leftHints[row].getBox(),
+ //this.leftHintsRects[row].x, this.leftHintsRects[row].y,
+ this.leftHints[row].getX(), this.leftHints[row].getY(),
null);
g.setFont(GridUI.HINT_FONT);
@@ -721,7 +761,8 @@
return;
}
- this.repaint(this.topHintsRects[col]);
+ //this.repaint(this.topHintsRects[col]);
+ this.repaint(this.topHints[col].getRect());
}
/** Repaints left hints. */
@@ -730,6 +771,7 @@
return;
}
- this.repaint(this.leftHintsRects[row]);
+ //this.repaint(this.leftHintsRects[row]);
+ this.repaint(this.leftHints[row].getRect());
}
}
Added: trunk/src/picross/grid/HintBoxInfos.java
===================================================================
--- trunk/src/picross/grid/HintBoxInfos.java (rev 0)
+++ trunk/src/picross/grid/HintBoxInfos.java 2008-04-28 12:47:06 UTC (rev 68)
@@ -0,0 +1,106 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 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,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ */
+
+
+package picross.grid;
+
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+
+import java.awt.image.BufferedImage;
+
+/**
+ * @author Y. Norsa
+ */
+class HintBoxInfos {
+ /*** Constante ***/
+
+ /*** Champ statique ***/
+
+ /*** Champ ***/
+
+ private Rectangle rect = null;
+ private BufferedImage box = null;
+
+ /*** Const...
[truncated message content] |
|
From: <yva...@us...> - 2008-04-28 13:12:16
|
Revision: 69
http://picross.svn.sourceforge.net/picross/?rev=69&view=rev
Author: yvan_norsa
Date: 2008-04-28 06:12:16 -0700 (Mon, 28 Apr 2008)
Log Message:
-----------
code clean-up
Modified Paths:
--------------
trunk/src/picross/Picross.java
trunk/src/picross/game/simple/LevelMenuModel.java
Added Paths:
-----------
trunk/src/picross/game/simple/FileInfos.java
trunk/src/picross/game/simple/LevelInfos.java
Removed Paths:
-------------
trunk/src/picross/game/simple/FileInfo.java
trunk/src/picross/game/simple/LevelInfo.java
Modified: trunk/src/picross/Picross.java
===================================================================
--- trunk/src/picross/Picross.java 2008-04-28 12:47:06 UTC (rev 68)
+++ trunk/src/picross/Picross.java 2008-04-28 13:12:16 UTC (rev 69)
@@ -49,8 +49,8 @@
//import org.apache.log4j.Logger;
-import picross.game.simple.FileInfo;
-import picross.game.simple.LevelInfo;
+import picross.game.simple.FileInfos;
+import picross.game.simple.LevelInfos;
/**
* Helper class.
@@ -66,6 +66,9 @@
/** Data directory. */
private static final String DATA_DIR = "/picross/data/";
+ /** File containing the data files list. */
+ private static final String DATA_LIST = "contents.txt";
+
/** Images directory corresponding to the default locale. */
private static final String LOCAL_IMAGES_PATH = Picross.IMAGES_DIR
+ Locale.getDefault().getLanguage() + "/";
@@ -123,9 +126,7 @@
* is <code>null</code> or empty
* @throws MissingImageException if the image file can't be found
*/
- public static ImageIcon getImage(String name)
- throws IllegalArgumentException {
-
+ public static ImageIcon getImage(String name) {
if (name == null || name.equals("")) {
throw new IllegalArgumentException("name can't be null or empty");
}
@@ -142,9 +143,7 @@
* is <code>null</code> or empty
* @throws MissingImageException if the image file can't be found
*/
- public static ImageIcon getLocalizedImage(String name)
- throws IllegalArgumentException {
-
+ public static ImageIcon getLocalizedImage(String name) {
if (name == null || name.equals("")) {
throw new IllegalArgumentException("name can't be null or empty");
}
@@ -161,8 +160,7 @@
* is <code>null</code> or empty
* @throws IOException if there is a problem while opening the file
*/
- public static InputStream loadDataFile(String name)
- throws IllegalArgumentException, IOException {
+ public static InputStream loadDataFile(String name) throws IOException {
if (name == null || name.equals("")) {
throw new IllegalArgumentException("name can't be null or empty");
@@ -171,25 +169,29 @@
return Picross.getFile(Picross.DATA_DIR + name).openStream();
}
- //public static List<String> listDataFiles() throws IOException {
- public static List<LevelInfo> listDataFiles() throws IOException {
- //List<String> list = new ArrayList<String>();
- List<LevelInfo> list = new ArrayList<LevelInfo>();
+ /**
+ * Reads the data files list and returns informations about the levels.
+ *
+ * @return informations about the available levels
+ * @throws IOException if a problem occurs during the operation
+ */
+ public static List<LevelInfos> listDataFiles() throws IOException {
+ List<LevelInfos> list = new ArrayList<LevelInfos>();
BufferedReader in = null;
try {
- in = new BufferedReader(new InputStreamReader(Picross.loadDataFile("contents.txt")));
+ in = new
+ BufferedReader(new
+ InputStreamReader(Picross
+ .loadDataFile(Picross
+ .DATA_LIST)));
- String line = null;
+ String line = null;
- while ((line = in.readLine()) != null) {
- //list.add(line);
- String[] lineData = line.split(":");
- String[] sizeData = lineData[1].trim().split("x");
-
- list.add(new FileInfo(lineData[0].trim(), Integer.parseInt(sizeData[0]), Integer.parseInt(sizeData[1])));
- }
+ while ((line = in.readLine()) != null) {
+ list.add(FileInfos.readFileInfos(line));
+ }
} catch (IOException ioEx) {
throw ioEx;
} finally {
Deleted: trunk/src/picross/game/simple/FileInfo.java
===================================================================
--- trunk/src/picross/game/simple/FileInfo.java 2008-04-28 12:47:06 UTC (rev 68)
+++ trunk/src/picross/game/simple/FileInfo.java 2008-04-28 13:12:16 UTC (rev 69)
@@ -1,71 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (c) 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,
- * modify and/ or redistribute the software under the terms of the CeCILL
- * license as circulated by CEA, CNRS and INRIA at the following URL
- * "http://www.cecill.info".
- *
- * As a counterpart to the access to the source code and rights to copy,
- * modify and redistribute granted by the license, users are provided only
- * with a limited warranty and the software's author, the holder of the
- * economic rights, and the successive licensors have only limited
- * liability.
- *
- * In this respect, the user's attention is drawn to the risks associated
- * with loading, using, modifying and/or developing or reproducing the
- * software by the user in light of its specific status of free software,
- * that may mean that it is complicated to manipulate, and that also
- * therefore means that it is reserved for developers and experienced
- * professionals having in-depth computer knowledge. Users are therefore
- * encouraged to load and test the software's suitability as regards their
- * requirements in conditions enabling the security of their systems and/or
- * data to be ensured and, more generally, to use and operate it in the
- * same conditions as regards security.
- *
- * The fact that you are presently reading this means that you have had
- * knowledge of the CeCILL license and that you accept its terms.
- */
-
-
-package picross.game.simple;
-
-import java.awt.Dimension;
-
-/**
- * @author Y. Norsa
- */
-public class FileInfo implements LevelInfo {
- /*** Constante ***/
-
- /*** Champ statique ***/
-
- /*** Champ ***/
-
- private String name;
- private Dimension dimension;
-
- /*** Constructeur ***/
-
- /**
- * Constructeur.
- */
- public FileInfo(String levelName, int width, int height) {
- this.name = levelName;
- this.dimension = new Dimension(width, height);
- }
-
- /*** M\xE9thode ***/
-
- public String getName() {
- return this.name;
- }
-
- public Dimension getDimension() {
- return this.dimension;
- }
-}
-
Copied: trunk/src/picross/game/simple/FileInfos.java (from rev 63, trunk/src/picross/game/simple/FileInfo.java)
===================================================================
--- trunk/src/picross/game/simple/FileInfos.java (rev 0)
+++ trunk/src/picross/game/simple/FileInfos.java 2008-04-28 13:12:16 UTC (rev 69)
@@ -0,0 +1,116 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 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,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ */
+
+
+package picross.game.simple;
+
+import java.awt.Dimension;
+
+/**
+ * Informations about a level file.
+ *
+ * @author Y. Norsa
+ */
+public class FileInfos implements LevelInfos {
+ /*** Constants ***/
+
+ /** String separating the various fields. */
+ private static final String FIELDS_SEPARATOR = ":";
+
+ /** String separating the width from the height. */
+ private static final String SIZE_SEPARATOR = "x";
+
+ /*** Fields ***/
+
+ /** The filename. */
+ private String name;
+
+ /** Grid size. */
+ private Dimension dimension;
+
+ /*** Constructor ***/
+
+ /**
+ * Constructor.
+ *
+ * @param levelName the filename
+ * @param dim grid size
+ */
+ public FileInfos(String levelName, Dimension dim) {
+ this.name = levelName.trim();
+ this.dimension = dim;
+ }
+
+ /*** Static methods ***/
+
+ /**
+ * Parses a line to extract level informations.
+ *
+ * @param line the line to parse
+ * @return level informations
+ */
+ public static FileInfos readFileInfos(String line) {
+ String[] lineData = line.split(FileInfos.FIELDS_SEPARATOR);
+
+ return new FileInfos(lineData[0],
+ FileInfos.readSize(lineData[1]));
+ }
+
+ /**
+ * Parses a line containing the grid size.
+ * Example : "15x10".
+ *
+ * @param sizeString a <code>String</code> describing the grid size
+ * @return parsed size
+ */
+ private static Dimension readSize(String sizeString) {
+ String[] sizeData = sizeString.trim().split(FileInfos.SIZE_SEPARATOR);
+
+ return new Dimension(Integer.parseInt(sizeData[0]),
+ Integer.parseInt(sizeData[1]));
+ }
+
+ /*** Methods implanted from the interface LevelInfos ***/
+
+ /** {@inheritDoc} */
+ @Override
+ public String getName() {
+ return this.name;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Dimension getDimension() {
+ return this.dimension;
+ }
+}
+
Deleted: trunk/src/picross/game/simple/LevelInfo.java
===================================================================
--- trunk/src/picross/game/simple/LevelInfo.java 2008-04-28 12:47:06 UTC (rev 68)
+++ trunk/src/picross/game/simple/LevelInfo.java 2008-04-28 13:12:16 UTC (rev 69)
@@ -1,45 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (c) 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,
- * modify and/ or redistribute the software under the terms of the CeCILL
- * license as circulated by CEA, CNRS and INRIA at the following URL
- * "http://www.cecill.info".
- *
- * As a counterpart to the access to the source code and rights to copy,
- * modify and redistribute granted by the license, users are provided only
- * with a limited warranty and the software's author, the holder of the
- * economic rights, and the successive licensors have only limited
- * liability.
- *
- * In this respect, the user's attention is drawn to the risks associated
- * with loading, using, modifying and/or developing or reproducing the
- * software by the user in light of its specific status of free software,
- * that may mean that it is complicated to manipulate, and that also
- * therefore means that it is reserved for developers and experienced
- * professionals having in-depth computer knowledge. Users are therefore
- * encouraged to load and test the software's suitability as regards their
- * requirements in conditions enabling the security of their systems and/or
- * data to be ensured and, more generally, to use and operate it in the
- * same conditions as regards security.
- *
- * The fact that you are presently reading this means that you have had
- * knowledge of the CeCILL license and that you accept its terms.
- */
-
-
-package picross.game.simple;
-
-import java.awt.Dimension;
-
-/**
- * @author Y. Norsa
- */
-public interface LevelInfo {
- String getName();
- Dimension getDimension();
-}
-
Copied: trunk/src/picross/game/simple/LevelInfos.java (from rev 63, trunk/src/picross/game/simple/LevelInfo.java)
===================================================================
--- trunk/src/picross/game/simple/LevelInfos.java (rev 0)
+++ trunk/src/picross/game/simple/LevelInfos.java 2008-04-28 13:12:16 UTC (rev 69)
@@ -0,0 +1,45 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 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,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ */
+
+
+package picross.game.simple;
+
+import java.awt.Dimension;
+
+/**
+ * @author Y. Norsa
+ */
+public interface LevelInfos {
+ String getName();
+ Dimension getDimension();
+}
+
Modified: trunk/src/picross/game/simple/LevelMenuModel.java
===================================================================
--- trunk/src/picross/game/simple/LevelMenuModel.java 2008-04-28 12:47:06 UTC (rev 68)
+++ trunk/src/picross/game/simple/LevelMenuModel.java 2008-04-28 13:12:16 UTC (rev 69)
@@ -45,7 +45,7 @@
import picross.Picross;
import picross.PicrossException;
-import picross.game.simple.LevelInfo;
+import picross.game.simple.LevelInfos;
/**
* Model for the level selection menu.
@@ -70,7 +70,7 @@
LevelMenuModel() throws PicrossException {
this.levels = new HashMap<Dimension, List<String>>();
- List<LevelInfo> infos = null;
+ List<LevelInfos> infos = null;
try {
//this.levels = Picross.listDataFiles();
@@ -79,7 +79,7 @@
throw new PicrossException(ioEx);
}
- for (LevelInfo info : infos) {
+ for (LevelInfos info : infos) {
Dimension levelSize = info.getDimension();
List<String> levelsList = this.levels.get(levelSize);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yva...@us...> - 2008-04-29 09:32:50
|
Revision: 71
http://picross.svn.sourceforge.net/picross/?rev=71&view=rev
Author: yvan_norsa
Date: 2008-04-29 02:32:57 -0700 (Tue, 29 Apr 2008)
Log Message:
-----------
checkstyle
Modified Paths:
--------------
trunk/src/picross/MissingImageException.java
trunk/src/picross/Picross.java
trunk/src/picross/PicrossController.java
trunk/src/picross/PicrossMediator.java
trunk/src/picross/app/MainMenuAppUI.java
trunk/src/picross/app/PicrossApp.java
trunk/src/picross/app/PicrossAppUI.java
trunk/src/picross/applet/MainMenuAppletUI.java
trunk/src/picross/applet/PicrossApplet.java
trunk/src/picross/game/GameCommand.java
trunk/src/picross/game/GameMediator.java
trunk/src/picross/game/GameMode.java
trunk/src/picross/game/random/RandomGameController.java
trunk/src/picross/game/random/RandomGameMediator.java
trunk/src/picross/game/random/RandomGameMode.java
trunk/src/picross/game/simple/FileInfos.java
trunk/src/picross/game/simple/LevelInfos.java
trunk/src/picross/game/simple/LevelMenuController.java
trunk/src/picross/game/simple/LevelMenuMediator.java
trunk/src/picross/game/simple/LevelMenuModel.java
trunk/src/picross/game/simple/LevelMenuUI.java
trunk/src/picross/game/simple/LevelsListCommand.java
trunk/src/picross/game/simple/SelectSizeCommand.java
trunk/src/picross/game/simple/SimpleGameMediator.java
trunk/src/picross/game/simple/SimpleGameMode.java
trunk/src/picross/grid/CompletedHints.java
trunk/src/picross/grid/FillCommand.java
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/GridUI.java
trunk/src/picross/grid/HintBoxInfos.java
trunk/src/picross/grid/RepaintLeftHintsCommand.java
trunk/src/picross/grid/RepaintTopHintsCommand.java
trunk/src/picross/menus/GameMenuMediator.java
trunk/src/picross/menus/GameMenuModel.java
trunk/src/picross/menus/GameMenuUI.java
trunk/src/picross/menus/MainMenuMediator.java
trunk/src/picross/menus/MainMenuUI.java
trunk/src/picross/menus/MenuCommand.java
trunk/src/picross/menus/MenuController.java
trunk/src/picross/menus/MenuMediator.java
trunk/src/picross/menus/MenuUI.java
trunk/src/picross/menus/PicrossButton.java
trunk/src/picross/menus/WaitMenuMediator.java
trunk/src/picross/menus/WaitMenuUI.java
trunk/src/picross/properties/messages_picross.properties
trunk/src/picross/properties/messages_picross_fr.properties
Modified: trunk/src/picross/MissingImageException.java
===================================================================
--- trunk/src/picross/MissingImageException.java 2008-04-28 13:30:53 UTC (rev 70)
+++ trunk/src/picross/MissingImageException.java 2008-04-29 09:32:57 UTC (rev 71)
@@ -38,7 +38,7 @@
*
* @author Y. Norsa
*/
-public class MissingImageException extends RuntimeException {
+public final class MissingImageException extends RuntimeException {
/*** Constant ***/
/** Serialisation ID. */
Modified: trunk/src/picross/Picross.java
===================================================================
--- trunk/src/picross/Picross.java 2008-04-28 13:30:53 UTC (rev 70)
+++ trunk/src/picross/Picross.java 2008-04-29 09:32:57 UTC (rev 71)
@@ -39,17 +39,12 @@
import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Locale;
import javax.swing.ImageIcon;
//import org.apache.log4j.Logger;
-//import picross.game.simple.FileInfos;
-//import picross.game.simple.LevelInfos;
-
/**
* Helper class.
*
Modified: trunk/src/picross/PicrossController.java
===================================================================
--- trunk/src/picross/PicrossController.java 2008-04-28 13:30:53 UTC (rev 70)
+++ trunk/src/picross/PicrossController.java 2008-04-29 09:32:57 UTC (rev 71)
@@ -49,16 +49,9 @@
/** Play command. */
public static final String PLAY_CMD = "PLAY_CMD";
- /** Random game command. */
- //public static final String RANDOM_GAME_CMD = "RANDOM_GAME_CMD";
+ /** Command used to display a menu. */
+ public static final String MENU_CMD = "MENU_CMD";
- //public static final String NEXT_RANDOM_GAME_CMD = "NEXT_RANDOM_GAME_CMD";
-
- /** Select level command. */
- //public static final String SELECT_LEVEL_CMD = "SELECT_LEVEL_CMD";
-
- //public static final String LEVEL_CMD = "LEVEL_CMD";
-
/** Exit command. */
public static final String EXIT_CMD = "EXIT_CMD";
@@ -75,6 +68,7 @@
/*** Method overloaded from the class Controller ***/
/** {@inheritDoc} */
+ @Override
public void eventPerformed(SimpleEvent e) {
PicrossController.log.debug("eventPerformed(" + e + ")");
Modified: trunk/src/picross/PicrossMediator.java
===================================================================
--- trunk/src/picross/PicrossMediator.java 2008-04-28 13:30:53 UTC (rev 70)
+++ trunk/src/picross/PicrossMediator.java 2008-04-29 09:32:57 UTC (rev 71)
@@ -47,14 +47,9 @@
import picross.game.GameCommand;
import picross.game.GameMediator;
-//import picross.game.random.RandomGameMediator;
-
-//import picross.game.simple.SimpleGameMediator;
-
import picross.grid.GridController;
import picross.menus.GameMenuMediator;
-//import picross.menus.LevelMenuMediator;
import picross.menus.MainMenuMediator;
import picross.menus.MenuCommand;
import picross.menus.MenuMediator;
@@ -71,23 +66,30 @@
/** Class' logger. */
//private static Logger log = Logger.getLogger(PicrossMediator.class);
- /*** Field ***/
+ /*** Fields ***/
/** Main view. */
private PicrossUI view;
+ /**
+ * Boolean used to display a loading screen when we init the grid stuff.
+ */
private boolean firstTime = true;
/*** Constructor ***/
- /** Constructor. */
+ /**
+ * Constructor.
+ *
+ * @param view the main UI
+ */
public PicrossMediator(PicrossUI view) {
BundleHelper.loadBundle("picross.properties.messages_picross");
this.view = view;
PicrossController controller = new PicrossController();
- controller.setView(view);
+ controller.setView(this.view);
this.addSimpleListener(controller);
this.displayMenu(MainMenuMediator.class);
@@ -98,49 +100,18 @@
/*** Method overloaded from the Mediateur class ***/
/** {@inheritDoc} */
+ @Override
public void eventPerformed(SimpleEvent e) {
//PicrossMediator.log.debug("eventPerformed(" + e + ")");
String cmd = e.getCommandName();
if (cmd.equals(PicrossController.PLAY_CMD)) {
- //this.startGame();
this.displayGameMenu();
-
return;
}
- /*
- if (cmd.equals(PicrossController.RANDOM_GAME_CMD)) {
- this.displayWaitScreen();
- this.startRandomGame();
- return;
- }
- */
-
- /*
- if (cmd.equals(PicrossController.NEXT_RANDOM_GAME_CMD)) {
- this.startRandomGame();
- return;
- }
- */
-
- /*
- if (cmd.equals(PicrossController.SELECT_LEVEL_CMD)) {
- this.displaySelectLevelMenu();
- return;
- }
- */
-
- /*
- if (cmd.equals(PicrossController.LEVEL_CMD)) {
- this.displayWaitScreen();
- this.startGame(e.getComment());
- return;
- }
- */
-
- if (cmd.equals("MENU_CMD")) {
+ if (cmd.equals(PicrossController.MENU_CMD)) {
MenuCommand command = (MenuCommand) e.getCommand();
this.displayMenu(command.getMenuClass());
@@ -148,10 +119,7 @@
}
if (cmd.equals(GameCommand.GAME_CMD)) {
- if (this.firstTime) {
- this.displayWaitScreen();
- this.firstTime = false;
- }
+ this.displayWaitScreen();
GameCommand command = (GameCommand) e.getCommand();
this.startGame(command.getGame());
@@ -166,8 +134,7 @@
if (cmd.equals(GridController.GRID_FILLED_CMD)) {
this.fireEventPerformed(PicrossController.MESSAGE_CMD,
- BundleHelper.getString(this, "victory")
- + " !");
+ BundleHelper.getString(this, "victory"));
return;
}
}
@@ -184,15 +151,12 @@
this.displayMenu(GameMenuMediator.class);
}
- /** Displays the level selection menu. */
- /*
- private void displaySelectLevelMenu() {
- this.displayMenu(LevelMenuMediator.class);
- }
- */
-
+ /** Displays the loading screen only the first time. */
private void displayWaitScreen() {
- this.displayMenu(WaitMenuMediator.class);
+ if (this.firstTime) {
+ this.displayMenu(WaitMenuMediator.class);
+ this.firstTime = false;
+ }
}
/**
@@ -205,8 +169,7 @@
try {
try {
- menu = menuClass.getConstructor()//PicrossUI.class)
- .newInstance(/*this.view*/);
+ menu = menuClass.getConstructor().newInstance();
} catch (NoSuchMethodException methodEx) {
throw new PicrossException(methodEx);
} catch (InstantiationException instantiationEx) {
@@ -214,8 +177,6 @@
} catch (IllegalAccessException accessEx) {
throw new PicrossException(accessEx);
} catch (InvocationTargetException targetEx) {
- //targetEx.printStackTrace();
- //throw (PicrossException) targetEx.getCause();
throw new PicrossException(targetEx);
}
@@ -232,74 +193,28 @@
this.view.setContent(menu.getView());
}
+ /**
+ * Method launching a game.
+ *
+ * @param game game the launch
+ */
private void startGame(final GameMediator game) {
Thread worker = new Thread() {
public void run() {
try {
- //game = new RandomGameMediator();
- game.start();
+ game.init();
PicrossMediator.this.gameLoaded(game);
} catch (PicrossException picrossEx) {
PicrossMediator.this.view
.displayError(picrossEx.getMessage());
return;
- }
+ }
}
};
worker.start();
}
- /** Starts a random game. *
- /*
- private void startRandomGame() {
- Thread worker = new Thread() {
- public void run() {
- GameMediator game = null;
-
- try {
- game = new RandomGameMediator();
- game.start();
- PicrossMediator.this.gameLoaded(game);
- } catch (PicrossException picrossEx) {
- PicrossMediator.this.view
- .displayError(picrossEx.getMessage());
- return;
- }
- }
- };
-
- worker.start();
- }
- */
- /** Starts a new game. */
- /*
- private void startGame(final String level) {
- PicrossMediator.log.debug("startGame(" + level + ")");
-
- Thread worker = new Thread() {
- public void run() {
- GameMediator game = null;
-
- try {
- game = new SimpleGameMediator(level);
- PicrossMediator.this.gameLoaded(game);
- } catch (final PicrossException picrossEx) {
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- PicrossMediator.this.view
- .displayError(picrossEx.getMessage());
- return;
- }
- });
- }
- }
- };
-
- worker.start();
- }
- */
-
/**
* Callback used to display the game view.
*
Modified: trunk/src/picross/app/MainMenuAppUI.java
===================================================================
--- trunk/src/picross/app/MainMenuAppUI.java 2008-04-28 13:30:53 UTC (rev 70)
+++ trunk/src/picross/app/MainMenuAppUI.java 2008-04-29 09:32:57 UTC (rev 71)
@@ -35,12 +35,6 @@
import java.awt.event.ActionListener;
-import java.io.FileNotFoundException;
-
-import javax.swing.ImageIcon;
-import javax.swing.JButton;
-
-import picross.Picross;
import picross.PicrossController;
import picross.menus.MainMenuUI;
@@ -51,7 +45,7 @@
* @author Y. Norsa
*/
public final class MainMenuAppUI extends MainMenuUI {
- /*** Constans ***/
+ /*** Constants ***/
/** Serialisation ID. */
private static final long serialVersionUID = 8153436550520127667L;
@@ -71,15 +65,10 @@
/** "Exit" button Y coordinate. */
private static final int EXIT_BUTTON_Y = 225;
- /*** Constructor ***/
+ /*** Methods overloaded from the class MainMenuUI ***/
- /**
- * Constructor.
- *
- * @param controller controller for the buttons
- * @throws MissingImageException if a button image can't be found
- */
-
+ /** {@inheritDoc} */
+ @Override
protected void init(ActionListener controller) {
super.init(controller);
@@ -90,14 +79,14 @@
MainMenuAppUI.EXIT_BUTTON_Y);
}
- /*** Methods overloaded from MainMenuUI ***/
-
/** {@inheritDoc} */
+ @Override
protected int getPlayButtonX() {
return MainMenuAppUI.PLAY_BUTTON_X;
}
/** {@inheritDoc} */
+ @Override
protected int getPlayButtonY() {
return MainMenuAppUI.PLAY_BUTTON_Y;
}
Modified: trunk/src/picross/app/PicrossApp.java
===================================================================
--- trunk/src/picross/app/PicrossApp.java 2008-04-28 13:30:53 UTC (rev 70)
+++ trunk/src/picross/app/PicrossApp.java 2008-04-29 09:32:57 UTC (rev 71)
@@ -90,6 +90,7 @@
.newInstance((Object[]) null);
javax.swing.RepaintManager.setCurrentManager(manag);
} catch (ClassNotFoundException classEx) {
+ // The debug jar isn't here
} catch (NoSuchMethodException methodEx) {
methodEx.printStackTrace();
} catch (InstantiationException instantiationEx) {
@@ -107,6 +108,7 @@
monitorClass.getMethod("initMonitoring");
method.invoke(null);
} catch (ClassNotFoundException classEx) {
+ // The debug jar isn't here
} catch (NoSuchMethodException methodEx) {
methodEx.printStackTrace();
} catch (IllegalAccessException accessEx) {
Modified: trunk/src/picross/app/PicrossAppUI.java
===================================================================
--- trunk/src/picross/app/PicrossAppUI.java 2008-04-28 13:30:53 UTC (rev 70)
+++ trunk/src/picross/app/PicrossAppUI.java 2008-04-29 09:32:57 UTC (rev 71)
@@ -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,
@@ -66,33 +66,39 @@
/*** Methods implanted from the interface PicrossUI ***/
/** {@inheritDoc} */
+ @Override
public void setContent(JPanel content) {
this.setContentPane(content);
this.pack();
}
/** {@inheritDoc} */
+ @Override
public void displayMessage(String msg) {
JOptionPane.showMessageDialog(this, msg);
}
/** {@inheritDoc} */
+ @Override
public void displayError(String msg) {
JOptionPane.showMessageDialog(this, msg,
"Picross", JOptionPane.ERROR_MESSAGE);
}
/** {@inheritDoc} */
+ @Override
public void showUI() {
this.setVisible(true);
}
/** {@inheritDoc} */
+ @Override
public void exit() {
this.dispose();
}
/** {@inheritDoc} */
+ @Override
public String getMainMenuClass() {
return PicrossAppUI.MAIN_MENU_CLASS;
}
Modified: trunk/src/picross/applet/MainMenuAppletUI.java
===================================================================
--- trunk/src/picross/applet/MainMenuAppletUI.java 2008-04-28 13:30:53 UTC (rev 70)
+++ trunk/src/picross/applet/MainMenuAppletUI.java 2008-04-29 09:32:57 UTC (rev 71)
@@ -37,8 +37,6 @@
import java.awt.event.ActionListener;
-import java.io.FileNotFoundException;
-
import picross.menus.MainMenuUI;
/**
@@ -58,29 +56,24 @@
/** "Play" button Y coordinate. */
private static final int PLAY_BUTTON_Y = 225;
- /*** Constructor ***/
+ /*** Methods inherited from the class MainMenuUI ***/
- /**
- * Constructor.
- *
- * @param controller controller for the buttons
- * @throws MissingImageException if a button image can't be found
- */
-
+ /** {@inheritDoc} */
+ @Override
protected void init(ActionListener controller) {
super.init(controller);
this.setBackground(Color.WHITE);
}
- /*** Methods inherited from the class MainMenuUI ***/
-
/** {@inheritDoc} */
+ @Override
protected int getPlayButtonX() {
return MainMenuAppletUI.PLAY_BUTTON_X;
}
/** {@inheritDoc} */
+ @Override
protected int getPlayButtonY() {
return MainMenuAppletUI.PLAY_BUTTON_Y;
}
Modified: trunk/src/picross/applet/PicrossApplet.java
===================================================================
--- trunk/src/picross/applet/PicrossApplet.java 2008-04-28 13:30:53 UTC (rev 70)
+++ trunk/src/picross/applet/PicrossApplet.java 2008-04-29 09:32:57 UTC (rev 71)
@@ -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,
@@ -59,6 +59,7 @@
/*** Methods overloaded from the class JApplet ***/
/** {@inheritDoc} */
+ @Override
public void init() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
@@ -70,31 +71,37 @@
/*** Methods implanted from the interface PicrossUI ***/
/** {@inheritDoc} */
+ @Override
public String getMainMenuClass() {
return PicrossApplet.MAIN_MENU_CLASS;
}
/** {@inheritDoc} */
+ @Override
public void displayMessage(String msg) {
JOptionPane.showMessageDialog(this, msg);
}
/** {@inheritDoc} */
+ @Override
public void displayError(String msg) {
JOptionPane.showMessageDialog(this, msg,
"Picross", JOptionPane.ERROR_MESSAGE);
}
/** {@inheritDoc} */
+ @Override
public void setContent(JPanel content) {
this.setContentPane(content);
this.validate();
}
/** {@inheritDoc} */
+ @Override
public void showUI() { }
/** {@inheritDoc} */
+ @Override
public void exit() { }
}
Modified: trunk/src/picross/game/GameCommand.java
===================================================================
--- trunk/src/picross/game/GameCommand.java 2008-04-28 13:30:53 UTC (rev 70)
+++ trunk/src/picross/game/GameCommand.java 2008-04-29 09:32:57 UTC (rev 71)
@@ -36,23 +36,27 @@
import fr.cle.mmvcs.NamedCommand;
/**
+ * Command used to launch a game.
+ *
* @author Y. Norsa
*/
-public class GameCommand extends NamedCommand {
- /*** Constante ***/
+public final class GameCommand extends NamedCommand {
+ /*** Constant ***/
+ /** Command requiring the game launch. */
public static final String GAME_CMD = "GAME_CMD";
- /*** Champ statique ***/
+ /*** Field ***/
- /*** Champ ***/
-
+ /** The game to launch. */
private GameMediator game;
- /*** Constructeur ***/
+ /*** Constructor ***/
/**
- * Constructeur.
+ * Constructor.
+ *
+ * @param gameMediator the game to launch
*/
public GameCommand(GameMediator gameMediator) {
super(GameCommand.GAME_CMD);
@@ -60,8 +64,13 @@
this.game = gameMediator;
}
- /*** M\xE9thode ***/
+ /*** Accessor ***/
+ /**
+ * Returns the game.
+ *
+ * @return the game to launch
+ */
public GameMediator getGame() {
return this.game;
}
Modified: trunk/src/picross/game/GameMediator.java
===================================================================
--- trunk/src/picross/game/GameMediator.java 2008-04-28 13:30:53 UTC (rev 70)
+++ trunk/src/picross/game/GameMediator.java 2008-04-29 09:32:57 UTC (rev 71)
@@ -62,35 +62,6 @@
/** The game view. */
private GameUI view;
- /*** Constructor ***/
-
- /**
- * Constructor.
- *
- * @throws PicrossException if there is a problem loading the grid model
- * or building the view
- */
- //public GameMediator() throws PicrossException {
- protected void init() throws PicrossException {
- PicrossGrid model = this.initModel();
-
- final int width = model.getWidth();
- final int height = model.getHeight();
-
- final GridMediator grid = new GridMediator(width, height,
- model.getData());
- grid.addSimpleListener(this);
-
- // The view has to be init'ed on the EDT
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- GameMediator.this.view =
- GameMediator.this.initView(width, height,
- grid.getView());
- }
- });
- }
-
/*** Abstract methods ***/
/**
@@ -113,27 +84,50 @@
*/
protected abstract PicrossGrid initModel() throws PicrossException;
- public void start() throws PicrossException {
- this.init();
- }
-
/*** Method overloaded from the class Mediator ***/
/** {@inheritDoc} */
+ @Override
public void eventPerformed(SimpleEvent e) {
//GameMediator.log.debug("eventPerformed(" + e + ")");
this.fireEventPerformed(e);
}
- /*** Method ***/
+ /*** Methods ***/
/**
+ * Inits the game.
+ *
+ * @throws PicrossException if there is a problem loading the grid model
+ * or building the view
+ */
+ public final void init() throws PicrossException {
+ PicrossGrid model = this.initModel();
+
+ final int width = model.getWidth();
+ final int height = model.getHeight();
+
+ final GridMediator grid = new GridMediator(width, height,
+ model.getData());
+ grid.addSimpleListener(this);
+
+ // The view has to be init'ed on the EDT
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ GameMediator.this.view =
+ GameMediator.this.initView(width, height,
+ grid.getView());
+ }
+ });
+ }
+
+ /**
* Returns the game view.
*
* @return the view
*/
- public JPanel getView() {
+ public final JPanel getView() {
return this.view;
}
}
Modified: trunk/src/picross/game/GameMode.java
===================================================================
--- trunk/src/picross/game/GameMode.java 2008-04-28 13:30:53 UTC (rev 70)
+++ trunk/src/picross/game/GameMode.java 2008-04-29 09:32:57 UTC (rev 71)
@@ -38,9 +38,16 @@
import javax.swing.JButton;
/**
+ * Service describing a game mode.
+ *
* @author Y. Norsa
*/
public interface GameMode {
+ /**
+ * Button used to access this game mode.
+ *
+ * @return a button that can be added to a menu
+ */
SimpleButton<JButton> getButton();
}
Modified: trunk/src/picross/game/random/RandomGameController.java
===================================================================
--- trunk/src/picross/game/random/RandomGameController.java 2008-04-28 13:30:53 UTC (rev 70)
+++ trunk/src/picross/game/random/RandomGameController.java 2008-04-29 09:32:57 UTC (rev 71)
@@ -65,6 +65,7 @@
/*** Method overloaded from the class Controller ***/
/** {@inheritDoc} */
+ @Override
public void eventPerformed(SimpleEvent e) {
RandomGameController.log.debug("eventPerformed(" + e + ")");
}
@@ -72,6 +73,7 @@
/*** Method implanted from the interface ActionListener ***/
/** {@inheritDoc} */
+ @Override
public void actionPerformed(ActionEvent e) {
//RandomGameController.log.debug("actionPerformed(" + e + ")");
Modified: trunk/src/picross/game/random/RandomGameMediator.java
===================================================================
--- trunk/src/picross/game/random/RandomGameMediator.java 2008-04-28 13:30:53 UTC (rev 70)
+++ trunk/src/picross/game/random/RandomGameMediator.java 2008-04-29 09:32:57 UTC (rev 71)
@@ -39,8 +39,6 @@
//import org.apache.log4j.Logger;
-import picross.PicrossController;
-import picross.PicrossException;
import picross.PicrossGrid;
import picross.game.GameMediator;
@@ -57,23 +55,10 @@
/** The class' logger. */
//private static Logger log = Logger.getLogger(RandomGameMediator.class);
- /*** Constructor ***/
-
- /**
- * Constructor.
- *
- * @throws PicrossException if there is a problem loading the grid model
- * or building the view
- */
- /*
- public RandomGameMediator() {//throws PicrossException {
- //super();
- //this.init();
- }
- */
/*** Methods overloaded from the class GameMediator ***/
/** {@inheritDoc} */
+ @Override
protected GameUI initView(int width, int height, JPanel gridView) {
RandomGameController controller = new RandomGameController();
controller.addSimpleListener(this);
@@ -83,18 +68,19 @@
}
/** {@inheritDoc} */
+ @Override
protected PicrossGrid initModel() {
return new RandomPicrossModel();
}
/** {@inheritDoc} */
+ @Override
public void eventPerformed(SimpleEvent e) {
//RandomGameMediator.log.debug("eventPerformed(" + e + ")");
String cmd = e.getCommandName();
if (cmd.equals(RandomGameController.NEXT_CMD)) {
- //this.fireEventPerformed(RandomGameController.NEXT_RANDOM_GAME_CMD);
this.fireEventPerformed(RandomGameMode.getRandomGameCommand());
return;
Modified: trunk/src/picross/game/random/RandomGameMode.java
===================================================================
--- trunk/src/picross/game/random/RandomGameMode.java 2008-04-28 13:30:53 UTC (rev 70)
+++ trunk/src/picross/game/random/RandomGameMode.java 2008-04-29 09:32:57 UTC (rev 71)
@@ -48,10 +48,12 @@
import picross.menus.PicrossButton;
/**
+ * Random game mode.
+ *
* @author Y. Norsa
*/
-public class RandomGameMode implements GameMode {
- /*** Constante ***/
+public final class RandomGameMode implements GameMode {
+ /*** Constants ***/
/** Image for the "random" button. */
private static final String RANDOM_BUTTON_IMAGE = "button-random.png";
@@ -62,32 +64,28 @@
/** "Random" button Y coordinate. */
private static final int RANDOM_BUTTON_Y = 175;
- /*** Champ statique ***/
+ /*** Static method ***/
- /*** Champ ***/
-
- /*** Constructeur ***/
-
/**
- * Constructeur.
+ * Returns the command corresponding to a new random grid.
+ *
+ * @return a game command for a new random grid
*/
- /*
- RandomGameMode() {
- }
- */
- /*** M\xE9thode ***/
-
public static GameCommand getRandomGameCommand() {
return new GameCommand(new RandomGameMediator());
}
+ /*** Method implanted from the interface GameMode ***/
+
+ /** {@inheritDoc} */
+ @Override
public SimpleButton<JButton> getButton() {
- ImageIcon icon = Picross.getLocalizedImage(RandomGameMode.RANDOM_BUTTON_IMAGE);
- SimpleEvent event = new SimpleEvent(RandomGameMode.getRandomGameCommand());
- /*PicrossButton button = */return new PicrossButton(icon, event);
- //button.getButton().setIcon(icon);
+ ImageIcon icon =
+ Picross.getLocalizedImage(RandomGameMode.RANDOM_BUTTON_IMAGE);
+ SimpleEvent event =
+ new SimpleEvent(RandomGameMode.getRandomGameCommand());
- //return button;
+ return new PicrossButton(icon, event);
}
}
Modified: trunk/src/picross/game/simple/FileInfos.java
===================================================================
--- trunk/src/picross/game/simple/FileInfos.java 2008-04-28 13:30:53 UTC (rev 70)
+++ trunk/src/picross/game/simple/FileInfos.java 2008-04-29 09:32:57 UTC (rev 71)
@@ -40,7 +40,7 @@
*
* @author Y. Norsa
*/
-public class FileInfos implements LevelInfos {
+public final class FileInfos implements LevelInfos {
/*** Constants ***/
/** String separating the various fields. */
Modified: trunk/src/picross/game/simple/LevelInfos.java
===================================================================
--- trunk/src/picross/game/simple/LevelInfos.java 2008-04-28 13:30:53 UTC (rev 70)
+++ trunk/src/picross/game/simple/LevelInfos.java 2008-04-29 09:32:57 UTC (rev 71)
@@ -36,10 +36,23 @@
import java.awt.Dimension;
/**
+ * Set of informations about a level.
+ *
* @author Y. Norsa
*/
public interface LevelInfos {
+ /**
+ * Returns the level's name.
+ *
+ * @return name of the level
+ */
...
[truncated message content] |
|
From: <yva...@us...> - 2008-05-14 08:54:56
|
Revision: 84
http://picross.svn.sourceforge.net/picross/?rev=84&view=rev
Author: yvan_norsa
Date: 2008-05-14 01:55:01 -0700 (Wed, 14 May 2008)
Log Message:
-----------
added an in-game 'back to menu' button
Modified Paths:
--------------
trunk/src/picross/PicrossController.java
trunk/src/picross/PicrossMediator.java
trunk/src/picross/game/GameMediator.java
trunk/src/picross/game/GameUI.java
trunk/src/picross/game/random/RandomGameController.java
trunk/src/picross/game/random/RandomGameMediator.java
trunk/src/picross/game/random/RandomGameUI.java
trunk/src/picross/properties/messages_picross.properties
trunk/src/picross/properties/messages_picross_fr.properties
Added Paths:
-----------
trunk/src/picross/game/GameController.java
Modified: trunk/src/picross/PicrossController.java
===================================================================
--- trunk/src/picross/PicrossController.java 2008-05-14 07:32:12 UTC (rev 83)
+++ trunk/src/picross/PicrossController.java 2008-05-14 08:55:01 UTC (rev 84)
@@ -36,7 +36,7 @@
import fr.cle.mmvcs.Controller;
import fr.cle.mmvcs.SimpleEvent;
-import org.apache.log4j.Logger;
+//import org.apache.log4j.Logger;
/**
* Application controller.
@@ -55,10 +55,13 @@
/** Exit command. */
public static final String EXIT_CMD = "EXIT_CMD";
+ /** Command used to quit a game. */
+ public static final String QUIT_CMD = "QUIT_CMD";
+
/*** Static field ***/
/** The class's logger. */
- private static Logger log = Logger.getLogger(PicrossController.class);
+ //private static Logger log = Logger.getLogger(PicrossController.class);
/*** Field ***/
@@ -70,7 +73,7 @@
/** {@inheritDoc} */
@Override
public void eventPerformed(SimpleEvent e) {
- PicrossController.log.debug("eventPerformed(" + e + ")");
+ //PicrossController.log.debug("eventPerformed(" + e + ")");
String cmd = e.getCommandName();
Modified: trunk/src/picross/PicrossMediator.java
===================================================================
--- trunk/src/picross/PicrossMediator.java 2008-05-14 07:32:12 UTC (rev 83)
+++ trunk/src/picross/PicrossMediator.java 2008-05-14 08:55:01 UTC (rev 84)
@@ -137,6 +137,11 @@
BundleHelper.getString(this, "victory"));
return;
}
+
+ if (cmd.equals(PicrossController.QUIT_CMD)) {
+ this.displayGameMenu();
+ return;
+ }
}
/*** Methods ***/
Added: trunk/src/picross/game/GameController.java
===================================================================
--- trunk/src/picross/game/GameController.java (rev 0)
+++ trunk/src/picross/game/GameController.java 2008-05-14 08:55:01 UTC (rev 84)
@@ -0,0 +1,79 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 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,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ */
+
+
+package picross.game;
+
+import fr.cle.mmvcs.Controller;
+import fr.cle.mmvcs.SimpleEvent;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+//import org.apache.log4j.Logger;
+
+import picross.PicrossController;
+
+/**
+ * Controller for the game.
+ *
+ * @author Y. Norsa
+ */
+public class GameController extends Controller implements ActionListener {
+ /*** Static field ***/
+
+ /** The class' logger. */
+ //private static Logger log = Logger.getLogger(GameController.class);
+
+ /*** Method overloaded from the class Controller ***/
+
+ /** {@inheritDoc} */
+ @Override
+ public void eventPerformed(SimpleEvent e) { }
+
+ /*** Method implanted from the interface ActionListener ***/
+
+ /** {@inheritDoc} */
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ //GameController.log.debug("actionPerformed(" + e + ")");
+
+ String cmd = e.getActionCommand();
+
+ if (cmd.equals(PicrossController.QUIT_CMD)) {
+ this.fireEventPerformed(cmd);
+
+ return;
+ }
+ }
+}
+
Property changes on: trunk/src/picross/game/GameController.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: trunk/src/picross/game/GameMediator.java
===================================================================
--- trunk/src/picross/game/GameMediator.java 2008-05-14 07:32:12 UTC (rev 83)
+++ trunk/src/picross/game/GameMediator.java 2008-05-14 08:55:01 UTC (rev 84)
@@ -36,6 +36,8 @@
import fr.cle.mmvcs.Mediateur;
import fr.cle.mmvcs.SimpleEvent;
+import java.awt.event.ActionListener;
+
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
@@ -62,21 +64,9 @@
/** The game view. */
private GameUI view;
- /*** Abstract methods ***/
+ /*** Abstrac method ***/
/**
- * Creates the view.
- *
- * @param width the grid width
- * @param height the grid height
- * @param gridView the grid itself
- * @return view containing the grid
- */
- protected GameUI initView(int width, int height, JPanel gridView) {
- return new GameUI(width, height, gridView);
- }
-
- /**
* Creates the model.
*
* @return grid model
@@ -112,17 +102,44 @@
model.getData());
grid.addSimpleListener(this);
+ final GameController controller = this.initController();
+ controller.addSimpleListener(this);
+
// The view has to be init'ed on the EDT
SwingUtilities.invokeLater(new Runnable() {
public void run() {
GameMediator.this.view =
GameMediator.this.initView(width, height,
- grid.getView());
+ grid.getView(),
+ controller);
}
});
}
/**
+ * Creates the view.
+ *
+ * @param width the grid width
+ * @param height the grid height
+ * @param gridView the grid itself
+ * @param controller controller for the grid buttons
+ * @return view containing the grid
+ */
+ protected GameUI initView(int width, int height, JPanel gridView,
+ ActionListener controller) {
+ return new GameUI(width, height, gridView, controller);
+ }
+
+ /**
+ * Initialises the controller.
+ *
+ * @return the created controller
+ */
+ protected GameController initController() {
+ return new GameController();
+ }
+
+ /**
* Returns the game view.
*
* @return the view
Modified: trunk/src/picross/game/GameUI.java
===================================================================
--- trunk/src/picross/game/GameUI.java 2008-05-14 07:32:12 UTC (rev 83)
+++ trunk/src/picross/game/GameUI.java 2008-05-14 08:55:01 UTC (rev 84)
@@ -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,
@@ -37,11 +37,18 @@
import java.awt.BorderLayout;
import java.awt.Color;
+import java.awt.FlowLayout;
+import java.awt.event.ActionListener;
+
import javax.swing.BoxLayout;
+import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
+import javax.swing.JSeparator;
+import picross.PicrossController;
+
/**
* The game UI.
*
@@ -55,8 +62,8 @@
/*** Field ***/
- /** Displays informations about the current game. */
- protected JPanel infosPanel;
+ /** Panel holding the buttons. */
+ private JPanel buttonsPanel;
/*** Constructor ***/
@@ -66,23 +73,59 @@
* @param width the grid width
* @param height the grid height
* @param grid the grid
+ * @param listener listener for the buttons
*/
- public GameUI(int width, int height, JPanel grid) {
+ public GameUI(int width, int height, JPanel grid,
+ ActionListener listener) {
super();
this.setLayout(new BorderLayout());
- this.infosPanel = new JPanel();
- this.infosPanel.setBackground(Color.WHITE);
- this.infosPanel.setLayout(new BoxLayout(this.infosPanel,
- BoxLayout.Y_AXIS));
+ JPanel topPanel = new JPanel(new BorderLayout());
+ topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
+ JPanel contentPanel = new JPanel();
+ contentPanel.setLayout(new BoxLayout(contentPanel,
+ BoxLayout.Y_AXIS));
+
+ JPanel infosPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ infosPanel.setBackground(Color.WHITE);
+
JLabel infos = new JLabel(BundleHelper.getString(this,
"gridSize")
+ " : " + width + "*" + height);
- this.infosPanel.add(infos);
- this.add(this.infosPanel, BorderLayout.NORTH);
+ infosPanel.add(infos);
+
+ topPanel.add(infosPanel);
+ topPanel.add(new JSeparator());
+
+ this.buttonsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ this.buttonsPanel.setBackground(Color.WHITE);
+
+ JButton menuButton = new JButton(BundleHelper.getString(this,
+ "menuButton"));
+ menuButton.addActionListener(listener);
+ menuButton.setActionCommand(PicrossController.QUIT_CMD);
+ this.buttonsPanel.add(menuButton);
+
+ topPanel.add(this.buttonsPanel);
+ topPanel.add(new JSeparator());
+
+ topPanel.add(contentPanel, BorderLayout.LINE_START);
+
+ this.add(topPanel, BorderLayout.PAGE_START);
this.add(grid, BorderLayout.CENTER);
}
+
+ /*** Method ***/
+
+ /**
+ * Helper method to add a button.
+ *
+ * @param button the button to add
+ */
+ protected void addButton(JButton button) {
+ this.buttonsPanel.add(button);
+ }
}
Modified: trunk/src/picross/game/random/RandomGameController.java
===================================================================
--- trunk/src/picross/game/random/RandomGameController.java 2008-05-14 07:32:12 UTC (rev 83)
+++ trunk/src/picross/game/random/RandomGameController.java 2008-05-14 08:55:01 UTC (rev 84)
@@ -33,20 +33,18 @@
package picross.game.random;
-import fr.cle.mmvcs.Controller;
-import fr.cle.mmvcs.SimpleEvent;
-
import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import org.apache.log4j.Logger;
+//import org.apache.log4j.Logger;
+import picross.game.GameController;
+
/**
* Controller for the random game UI.
*
* @author Y. Norsa
*/
-final class RandomGameController extends Controller implements ActionListener {
+final class RandomGameController extends GameController {
/*** Constant ***/
/** Command asking to create another grid. */
@@ -60,20 +58,12 @@
/*** Static field ***/
/** The class' logger. */
- private static Logger log = Logger.getLogger(RandomGameController.class);
+ //private static Logger log = Logger.getLogger(RandomGameController.class);
/*** Method overloaded from the class Controller ***/
/** {@inheritDoc} */
@Override
- public void eventPerformed(SimpleEvent e) {
- RandomGameController.log.debug("eventPerformed(" + e + ")");
- }
-
- /*** Method implanted from the interface ActionListener ***/
-
- /** {@inheritDoc} */
- @Override
public void actionPerformed(ActionEvent e) {
//RandomGameController.log.debug("actionPerformed(" + e + ")");
@@ -81,6 +71,10 @@
if (cmd.equals(RandomGameController.NEXT_CMD)) {
this.fireEventPerformed(cmd);
+
+ return;
}
+
+ super.actionPerformed(e);
}
}
Modified: trunk/src/picross/game/random/RandomGameMediator.java
===================================================================
--- trunk/src/picross/game/random/RandomGameMediator.java 2008-05-14 07:32:12 UTC (rev 83)
+++ trunk/src/picross/game/random/RandomGameMediator.java 2008-05-14 08:55:01 UTC (rev 84)
@@ -35,12 +35,15 @@
import fr.cle.mmvcs.SimpleEvent;
+import java.awt.event.ActionListener;
+
import javax.swing.JPanel;
//import org.apache.log4j.Logger;
import picross.PicrossGrid;
+import picross.game.GameController;
import picross.game.GameMediator;
import picross.game.GameUI;
@@ -59,12 +62,19 @@
/** {@inheritDoc} */
@Override
- protected GameUI initView(int width, int height, JPanel gridView) {
+ protected GameUI initView(int width, int height, JPanel gridView,
+ ActionListener controller) {
+ return new RandomGameUI(width, height, gridView,
+ controller);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected GameController initController() {
RandomGameController controller = new RandomGameController();
controller.addSimpleListener(this);
- return new RandomGameUI(width, height, gridView,
- controller);
+ return controller;
}
/** {@inheritDoc} */
Modified: trunk/src/picross/game/random/RandomGameUI.java
===================================================================
--- trunk/src/picross/game/random/RandomGameUI.java 2008-05-14 07:32:12 UTC (rev 83)
+++ trunk/src/picross/game/random/RandomGameUI.java 2008-05-14 08:55:01 UTC (rev 84)
@@ -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,
@@ -43,7 +43,7 @@
import picross.game.GameUI;
/**
- * UI modifications for a random game.
+ * Custom UI for a random game.
*
* @author Y. Norsa
*/
@@ -65,16 +65,13 @@
*/
RandomGameUI(int width, int height, JPanel grid,
ActionListener controller) {
- super(width, height, grid);
+ super(width, height, grid, controller);
JButton nextButton =
new JButton(BundleHelper.getString(this, "anotherGrid"));
nextButton.addActionListener(controller);
nextButton.setActionCommand(RandomGameController.NEXT_CMD);
- this.infosPanel.add(nextButton);
-
- // FIXME this should not be here
- this.infosPanel.add(new javax.swing.JSeparator());
+ this.addButton(nextButton);
}
}
Modified: trunk/src/picross/properties/messages_picross.properties
===================================================================
--- trunk/src/picross/properties/messages_picross.properties 2008-05-14 07:32:12 UTC (rev 83)
+++ trunk/src/picross/properties/messages_picross.properties 2008-05-14 08:55:01 UTC (rev 84)
@@ -3,6 +3,7 @@
# picross.game.GameUI
gridSize = Size
+menuButton = Back to menu
# picross.game.random.RandomGameUI
anotherGrid = Another grid
Modified: trunk/src/picross/properties/messages_picross_fr.properties
===================================================================
--- trunk/src/picross/properties/messages_picross_fr.properties 2008-05-14 07:32:12 UTC (rev 83)
+++ trunk/src/picross/properties/messages_picross_fr.properties 2008-05-14 08:55:01 UTC (rev 84)
@@ -3,6 +3,7 @@
# picross.game.GameUI
gridSize = Taille
+menuButton = Retour au menu
# picross.game.random.RandomGameUI
anotherGrid = Une autre grille
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yva...@us...> - 2007-06-06 08:27:55
|
Revision: 10
http://picross.svn.sourceforge.net/picross/?rev=10&view=rev
Author: yvan_norsa
Date: 2007-06-06 01:27:54 -0700 (Wed, 06 Jun 2007)
Log Message:
-----------
code cleanup, comments
Modified Paths:
--------------
trunk/src/picross/PicrossController.java
trunk/src/picross/PicrossMediator.java
trunk/src/picross/PicrossModel.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
trunk/src/picross/grid/PicrossGridUI.java
Modified: trunk/src/picross/PicrossController.java
===================================================================
--- trunk/src/picross/PicrossController.java 2007-06-05 14:44:56 UTC (rev 9)
+++ trunk/src/picross/PicrossController.java 2007-06-06 08:27:54 UTC (rev 10)
@@ -43,7 +43,7 @@
*
* @author Y. Norsa
*/
-class PicrossController extends Controller {
+final class PicrossController extends Controller {
/*** Static field ***/
/** The class's logger. */
Modified: trunk/src/picross/PicrossMediator.java
===================================================================
--- trunk/src/picross/PicrossMediator.java 2007-06-05 14:44:56 UTC (rev 9)
+++ trunk/src/picross/PicrossMediator.java 2007-06-06 08:27:54 UTC (rev 10)
@@ -36,7 +36,7 @@
import fr.cle.mmvcs.Mediateur;
import fr.cle.mmvcs.SimpleEvent;
-import org.apache.log4j.Logger;
+//import org.apache.log4j.Logger;
import picross.grid.PicrossGridController;
import picross.grid.PicrossGridMediator;
@@ -46,11 +46,11 @@
*
* @author Y. Norsa
*/
-class PicrossMediator extends Mediateur {
+final class PicrossMediator extends Mediateur {
/*** Static field ***/
/** Class' logger. */
- private static Logger log = Logger.getLogger(PicrossMediator.class);
+ //private static Logger log = Logger.getLogger(PicrossMediator.class);
/*** Constructor ***/
@@ -75,7 +75,7 @@
/** {@inheritDoc} */
public void eventPerformed(SimpleEvent e) {
- PicrossMediator.log.debug("eventPerformed(" + e + ")");
+ //PicrossMediator.log.debug("eventPerformed(" + e + ")");
String cmd = e.getCommandName();
Modified: trunk/src/picross/PicrossModel.java
===================================================================
--- trunk/src/picross/PicrossModel.java 2007-06-05 14:44:56 UTC (rev 9)
+++ trunk/src/picross/PicrossModel.java 2007-06-06 08:27:54 UTC (rev 10)
@@ -38,7 +38,7 @@
*
* @author Y. Norsa
*/
-class PicrossModel {
+final class PicrossModel {
/*** Fields ***/
/** Grid width. */
Modified: trunk/src/picross/PicrossUI.java
===================================================================
--- trunk/src/picross/PicrossUI.java 2007-06-05 14:44:56 UTC (rev 9)
+++ trunk/src/picross/PicrossUI.java 2007-06-06 08:27:54 UTC (rev 10)
@@ -43,7 +43,7 @@
*
* @author Y. Norsa
*/
-class PicrossUI extends JFrame {
+final class PicrossUI extends JFrame {
/*** Constant ***/
/** Serialisation ID. */
Modified: trunk/src/picross/grid/FillCommand.java
===================================================================
--- trunk/src/picross/grid/FillCommand.java 2007-06-05 14:44:56 UTC (rev 9)
+++ trunk/src/picross/grid/FillCommand.java 2007-06-06 08:27:54 UTC (rev 10)
@@ -40,7 +40,7 @@
*
* @author Y. Norsa
*/
-class FillCommand extends Command {
+final class FillCommand extends Command {
/*** Fields ***/
/** Row of the box to fill. */
Modified: trunk/src/picross/grid/PicrossGridController.java
===================================================================
--- trunk/src/picross/grid/PicrossGridController.java 2007-06-05 14:44:56 UTC (rev 9)
+++ trunk/src/picross/grid/PicrossGridController.java 2007-06-06 08:27:54 UTC (rev 10)
@@ -42,14 +42,14 @@
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
-import org.apache.log4j.Logger;
+//import org.apache.log4j.Logger;
/**
* Grid controller.
*
* @author Y. Norsa
*/
-public class PicrossGridController extends Controller
+public final class PicrossGridController extends Controller
implements MouseListener, MouseMotionListener {
/*** Constants ***/
@@ -60,15 +60,19 @@
/** Command indicating the grid is filled. */
public static final String GRID_FILLED_CMD = "GRID_FILLED_CMD";
+ /** Command indicating the action has reached its end. */
static final String END_ACTION_CMD = "END_ACTION_CMD";
+ /** Command to check a box. */
static final String CHECK_CMD = "CHECK_CMD";
+
+ /** Command to uncheck a box. */
static final String UNCHECK_CMD = "UNCHECK_CMD";
/*** Static field ***/
/** The class' logger. */
- private static Logger log = Logger.getLogger(PicrossGridController.class);
+ //private static Logger log = Logger.getLogger(PicrossGridController.class);
/*** Field ***/
@@ -79,7 +83,7 @@
/** {@inheritDoc} */
public void eventPerformed(SimpleEvent e) {
- PicrossGridController.log.debug("eventPerformed(" + e + ")");
+ //PicrossGridController.log.debug("eventPerformed(" + e + ")");
String cmd = e.getCommandName();
@@ -106,9 +110,7 @@
/*** Methods implanted from the interface MouseListener ***/
/** {@inheritDoc} */
- public void mouseClicked(MouseEvent e) {
- this.checkAndFill(e);
- }
+ public void mouseClicked(MouseEvent e) { }
/** {@inheritDoc} */
public void mouseEntered(MouseEvent e) { }
@@ -121,7 +123,8 @@
/** {@inheritDoc} */
public void mouseReleased(MouseEvent e) {
- PicrossGridController.log.debug("mouseReleased()");
+ //PicrossGridController.log.debug("mouseReleased()");
+ this.checkAndFill(e);
this.fireEventPerformed(PicrossGridController.END_ACTION_CMD);
}
@@ -155,7 +158,7 @@
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));
}
Modified: trunk/src/picross/grid/PicrossGridMediator.java
===================================================================
--- trunk/src/picross/grid/PicrossGridMediator.java 2007-06-05 14:44:56 UTC (rev 9)
+++ trunk/src/picross/grid/PicrossGridMediator.java 2007-06-06 08:27:54 UTC (rev 10)
@@ -45,7 +45,7 @@
*
* @author Y. Norsa
*/
-public class PicrossGridMediator extends Mediateur {
+public final class PicrossGridMediator extends Mediateur {
/*** Static field ***/
/** Class' logger. */
@@ -104,18 +104,30 @@
}
}
- /*** Method ***/
+ /*** Methods ***/
/** Tells the application mediator the grid has been filled. */
void congratulations() {
this.fireEventPerformed(PicrossGridController.GRID_FILLED_CMD);
}
+ /**
+ * Checks a box.
+ *
+ * @param row row of the box
+ * @param column column of the box
+ */
void check(int row, int column) {
this.fireEventPerformed(PicrossGridController.CHECK_CMD,
new FillCommand(row, column));
}
+ /**
+ * Unchecks a box.
+ *
+ * @param row row of the box
+ * @param column column of the box
+ */
void uncheck(int row, int column) {
this.fireEventPerformed(PicrossGridController.UNCHECK_CMD,
new FillCommand(row, column));
Modified: trunk/src/picross/grid/PicrossGridModel.java
===================================================================
--- trunk/src/picross/grid/PicrossGridModel.java 2007-06-05 14:44:56 UTC (rev 9)
+++ trunk/src/picross/grid/PicrossGridModel.java 2007-06-06 08:27:54 UTC (rev 10)
@@ -43,7 +43,12 @@
*
* @author Y. Norsa
*/
-class PicrossGridModel {
+final class PicrossGridModel {
+ /*** Constant ***/
+
+ /** Empty hint value. */
+ static final int EMPTY_HINT = -1;
+
/*** Static field ***/
/** The class' logger. */
@@ -58,16 +63,20 @@
private boolean[][] data;
/** The grid as filled by the user. */
- private Boolean[][] checked;
+ private DummyBoolean[][] checked;
+ /**
+ * The last modified box. Permis to know if we are in a serie or
+ * a single action.
+ */
+ private DummyBoolean lastChecked = null;
+
/** Columns hints. */
private int[][] colData;
/** Rows hints. */
private int[][] rowData;
- private Boolean lastChecked = null;
-
/*** Constructor ***/
/**
@@ -80,26 +89,31 @@
this.mediator = mediator;
this.data = data;
- this.checked = new Boolean[this.data.length][this.data[0].length];
+ this.checked = new DummyBoolean[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);
+ this.checked[i][j] = new DummyBoolean(false);
}
}
- List<List<Integer>> colRawData = new ArrayList<List<Integer>>();
+ // Grid of columns hints
+ List<List<Integer>> colHints = new ArrayList<List<Integer>>();
+
+ // Largest number of hints for a column
int max = 0;
for (boolean[] col : data) {
List<Integer> current = new ArrayList<Integer>();
+ // Current hint
int chain = 0;
for (boolean cell : col) {
if (cell) {
chain++;
} else if (chain > 0) {
+ // We've reached the end of a series of checked boxes
current.add(chain);
chain = 0;
}
@@ -108,6 +122,7 @@
if (chain > 0) {
current.add(chain);
} else if (current.size() == 0) {
+ // If this column is empty, we add a "0" hint
current.add(0);
}
@@ -117,24 +132,48 @@
max = currentSize;
}
- colRawData.add(current);
+ colHints.add(current);
}
+ /*
+ * Final array containing the hints, in the following form :
+ *
+ * 1
+ * 0 2 1
+ *
+ * Which corresponds to the following grid :
+ *
+ * |-----|
+ * |_|X|_|
+ * |_|_|X|
+ * |_|X|_|
+ * |_|X|_|
+ * |-----|
+ */
this.colData = new int[data.length][max];
for (int i = 0; i < max; i++) {
- for (int j = 0; j < colRawData.size(); j++) {
- if (colRawData.get(j).size() >= (max - i)) {
- this.colData[j][max - 1 - i]
- = colRawData.get(j).get(colRawData.get(j).size()
- - max + i);
+ // Minimal number of hints for the current column to be considered
+ int ref = max - i;
+
+ // Current hint row
+ int currentRow = ref - 1;
+
+ for (int j = 0; j < colHints.size(); j++) {
+ List<Integer> currentCol = colHints.get(j);
+ int size = currentCol.size();
+
+ if (size >= ref) {
+ this.colData[j][currentRow] = currentCol.get(size - ref);
} else {
- this.colData[j][max - 1 - i] = -1;
+ this.colData[j][currentRow] = PicrossGridModel.EMPTY_HINT;
}
}
}
- List<List<Integer>> rowRawData = new ArrayList<List<Integer>>();
+ // Same operations as for the columns, basically
+
+ List<List<Integer>> rowHints = new ArrayList<List<Integer>>();
max = 0;
for (int i = 0; i < data[0].length; i++) {
@@ -163,66 +202,104 @@
max = currentSize;
}
- rowRawData.add(current);
+ rowHints.add(current);
}
this.rowData = new int[data[0].length][max];
+ int nbRows = rowHints.size();
for (int i = 0; i < max; i++) {
- for (int j = 0; j < rowRawData.size(); j++) {
- if (rowRawData.get(j).size() >= (max - i)) {
- int index = i - Math.abs(rowRawData.get(j).size() - max);
- this.rowData[j][i] = rowRawData.get(j).get(index);
+ int ref = max - i;
+
+ for (int j = 0; j < nbRows; j++) {
+ List<Integer> currentRow = rowHints.get(j);
+ int size = currentRow.size();
+
+ if (size >= ref) {
+ this.rowData[j][i] =
+ currentRow.get(i - Math.abs(size - max));
} else {
- this.rowData[j][i] = -1;
+ this.rowData[j][i] = PicrossGridModel.EMPTY_HINT;
}
}
}
}
- /*** Method ***/
+ /*** Methods ***/
/**
- * Indicates a box has been checked.
+ * Method called during an action.
*
* @param row row of the box
* @param column column of the box
*/
void checkBox(int row, int column) {
- if (this.lastChecked == null ||
- !this.lastChecked.equals(this.checked[row][column])) {
+ //PicrossGridModel.log.debug("checkBox(" + row + ", " + column + ")");
+ //PicrossGridModel.log.debug("lastChecked == null : "
+ // + (lastChecked == null));
- if (!this.checked[row][column]) {
- //PicrossGridModel.log.debug("checking " + row + "," + column);
+ /*
+ * 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]) {
- this.checked[row][column] = true;
- this.lastChecked = this.checked[row][column];
+ return;
+ }
- this.mediator.check(row, column);
+ boolean currentValue = this.checked[row][column].getValue();
- boolean completed = true;
+ /*
+ * The value of the last checked box tells us if we are in
+ * a checks serie or a uncheck serie
+ */
+ boolean lastValue = false;
- 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 (this.lastChecked != null) {
+ lastValue = this.lastChecked.getValue();
- if (completed) {
- this.mediator.congratulations();
+ /*
+ * 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) {
+ 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);
+ }
+
+ this.lastChecked = this.checked[row][column];
+ this.checkCompleted();
+ }
+
+ /** Checks wether the grid is finished. */
+ private void checkCompleted() {
+ boolean completed = true;
+
+ for (int i = 0; i < this.data.length; i++) {
+ for (int j = 0; j < this.data[i].length; j++) {
+ if (this.data[i][j] != this.checked[i][j].getValue()) {
+ completed = false;
+ break;
}
- } else {
- this.checked[row][column] = false;
- this.lastChecked = this.checked[row][column];
-
- this.mediator.uncheck(row, column);
}
}
+
+ if (completed) {
+ this.mediator.congratulations();
+ }
}
+ /** Indicates the current action has come to an end. */
void endAction() {
this.lastChecked = null;
}
@@ -246,5 +323,49 @@
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-05 14:44:56 UTC (rev 9)
+++ trunk/src/picross/grid/PicrossGridUI.java 2007-06-06 08:27:54 UTC (rev 10)
@@ -40,14 +40,14 @@
import javax.swing.JPanel;
-import org.apache.log4j.Logger;
+//import org.apache.log4j.Logger;
/**
* Grid UI.
*
* @author Y. Norsa
*/
-class PicrossGridUI extends JPanel {
+final class PicrossGridUI extends JPanel {
/*** Constants ***/
/** Serialisation ID. */
@@ -83,7 +83,7 @@
/*** Static field ***/
/** Class' logger. */
- private static Logger log = Logger.getLogger(PicrossGridUI.class);
+ //private static Logger log = Logger.getLogger(PicrossGridUI.class);
/*** Fields ***/
@@ -114,6 +114,7 @@
/** Filled boxes. */
private boolean[][] filled;
+ /** Controller attached to this view. */
private transient PicrossGridController controller;
/*** Constructor ***/
@@ -161,8 +162,8 @@
this.bottomBoundary = this.topBoundary
+ (this.height * PicrossGridUI.BOX_HEIGHT);
- PicrossGridUI.log.debug("rightBoundary : " + this.rightBoundary);
- PicrossGridUI.log.debug("bottomBoundary : " + this.bottomBoundary);
+ //PicrossGridUI.log.debug("rightBoundary : " + this.rightBoundary);
+ //PicrossGridUI.log.debug("bottomBoundary : " + this.bottomBoundary);
this.setPreferredSize(new Dimension(this.rightBoundary
+ PicrossGridUI.RIGHT_SPACE,
@@ -183,7 +184,7 @@
x = this.leftBoundary + PicrossGridUI.COL_HINT_WIDTH;
for (int j = 0; j < this.colData.length; j++) {
- if (this.colData[j][i] != -1) {
+ if (this.colData[j][i] != PicrossGridModel.EMPTY_HINT) {
g.drawString(String.valueOf(this.colData[j][i]),
x, y);
}
@@ -200,7 +201,7 @@
x = 0;
for (int j = 0; j < this.rowData[i].length; j++) {
- if (this.rowData[i][j] != -1) {
+ if (this.rowData[i][j] != PicrossGridModel.EMPTY_HINT) {
g.drawString(String.valueOf(this.rowData[i][j]),
x, y + PicrossGridUI.ROW_HINT_HEIGHT);
}
@@ -283,19 +284,42 @@
return (int) (x / PicrossGridUI.BOX_WIDTH);
}
-
+
+ /** Removes the listeners to disable the grid. */
void disableGrid() {
this.removeMouseListener(this.controller);
this.removeMouseMotionListener(this.controller);
}
+ /**
+ * Checks a row.
+ *
+ * @param row row of the box
+ * @param column column of the box
+ */
void check(int row, int column) {
- this.filled[row][column] = true;
- this.repaint();
+ this.setBoxState(row, column, true);
}
+ /**
+ * Unchecks a row.
+ *
+ * @param row row of the box
+ * @param column column of the box
+ */
void uncheck(int row, int column) {
- this.filled[row][column] = false;
+ this.setBoxState(row, column, false);
+ }
+
+ /**
+ * 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) {
+ this.filled[row][column] = state;
this.repaint();
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yva...@us...> - 2007-06-11 10:43:25
|
Revision: 31
http://picross.svn.sourceforge.net/picross/?rev=31&view=rev
Author: yvan_norsa
Date: 2007-06-11 03:43:20 -0700 (Mon, 11 Jun 2007)
Log Message:
-----------
fixed a little glitch
Modified Paths:
--------------
trunk/src/picross/PicrossMediator.java
trunk/src/picross/PicrossUI.java
trunk/src/picross/app/PicrossAppUI.java
trunk/src/picross/applet/PicrossApplet.java
trunk/src/picross/grid/GridUI.java
Modified: trunk/src/picross/PicrossMediator.java
===================================================================
--- trunk/src/picross/PicrossMediator.java 2007-06-11 10:38:34 UTC (rev 30)
+++ trunk/src/picross/PicrossMediator.java 2007-06-11 10:43:20 UTC (rev 31)
@@ -89,8 +89,8 @@
mediator.addSimpleListener(this);
- //this.view = new PicrossUI(mediator.getView());
this.view.setContent(mediator.getView());
+ this.view.showUI();
}
/*** Method overloaded from the Mediateur class ***/
Modified: trunk/src/picross/PicrossUI.java
===================================================================
--- trunk/src/picross/PicrossUI.java 2007-06-11 10:38:34 UTC (rev 30)
+++ trunk/src/picross/PicrossUI.java 2007-06-11 10:43:20 UTC (rev 31)
@@ -69,6 +69,9 @@
*/
String getMainMenuClass();
+ /** Method called when the application is displayed. */
+ void showUI();
+
/** Method called when the application exits. */
void exit();
}
Modified: trunk/src/picross/app/PicrossAppUI.java
===================================================================
--- trunk/src/picross/app/PicrossAppUI.java 2007-06-11 10:38:34 UTC (rev 30)
+++ trunk/src/picross/app/PicrossAppUI.java 2007-06-11 10:43:20 UTC (rev 31)
@@ -60,7 +60,7 @@
super("Picross");
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- this.setVisible(true);
+ //this.setVisible(true);
}
/*** Methods implanted from the interface PicrossUI ***/
@@ -83,6 +83,11 @@
}
/** {@inheritDoc} */
+ public void showUI() {
+ this.setVisible(true);
+ }
+
+ /** {@inheritDoc} */
public void exit() {
this.dispose();
}
Modified: trunk/src/picross/applet/PicrossApplet.java
===================================================================
--- trunk/src/picross/applet/PicrossApplet.java 2007-06-11 10:38:34 UTC (rev 30)
+++ trunk/src/picross/applet/PicrossApplet.java 2007-06-11 10:43:20 UTC (rev 31)
@@ -92,7 +92,9 @@
}
/** {@inheritDoc} */
- public void exit() {
- }
+ public void showUI() { }
+
+ /** {@inheritDoc} */
+ public void exit() { }
}
Modified: trunk/src/picross/grid/GridUI.java
===================================================================
--- trunk/src/picross/grid/GridUI.java 2007-06-11 10:38:34 UTC (rev 30)
+++ trunk/src/picross/grid/GridUI.java 2007-06-11 10:43:20 UTC (rev 31)
@@ -381,10 +381,9 @@
this.rightBoundary,
this.topBoundary));
-
int boxWidth = GridUI.BLOCK_WIDTH * GridUI.BOX_WIDTH;
int boxHeight = GridUI.BLOCK_HEIGHT * GridUI.BOX_HEIGHT;
-
+
int i = 1;
int currentY = this.topBoundary + boxHeight;
@@ -397,7 +396,7 @@
currentY += boxHeight;
i += GridUI.BLOCK_HEIGHT;
}
-
+
i = 1;
int currentX = this.leftBoundary + boxWidth;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yva...@us...> - 2007-06-14 09:33:57
|
Revision: 38
http://picross.svn.sourceforge.net/picross/?rev=38&view=rev
Author: yvan_norsa
Date: 2007-06-14 02:33:57 -0700 (Thu, 14 Jun 2007)
Log Message:
-----------
graphics optimisation
Modified Paths:
--------------
trunk/src/picross/game/GameMediator.java
trunk/src/picross/game/GameUI.java
trunk/src/picross/game/random/RandomGameController.java
trunk/src/picross/game/random/RandomGameMediator.java
trunk/src/picross/game/random/RandomGameUI.java
trunk/src/picross/grid/GridController.java
trunk/src/picross/grid/GridMediator.java
trunk/src/picross/grid/GridModel.java
trunk/src/picross/grid/GridUI.java
Added Paths:
-----------
trunk/src/picross/grid/CompletedHints.java
Removed Paths:
-------------
trunk/src/picross/grid/ClearCommand.java
Modified: trunk/src/picross/game/GameMediator.java
===================================================================
--- trunk/src/picross/game/GameMediator.java 2007-06-14 05:59:01 UTC (rev 37)
+++ trunk/src/picross/game/GameMediator.java 2007-06-14 09:33:57 UTC (rev 38)
@@ -38,7 +38,7 @@
import javax.swing.JPanel;
-import org.apache.log4j.Logger;
+//import org.apache.log4j.Logger;
import picross.PicrossGrid;
@@ -53,7 +53,7 @@
/*** Static field ***/
/** The class' logger. */
- private static Logger log = Logger.getLogger(GameMediator.class);
+ //private static Logger log = Logger.getLogger(GameMediator.class);
/*** Field ***/
@@ -66,13 +66,14 @@
public GameMediator() {
PicrossGrid model = this.initModel();
- GridMediator grid = new GridMediator(model.getWidth(),
- model.getHeight(),
+ int width = model.getWidth();
+ int height = model.getHeight();
+
+ GridMediator grid = new GridMediator(width, height,
model.getData());
grid.addSimpleListener(this);
- this.view =
- this.initView(model.getWidth(), model.getHeight(), grid.getView());
+ this.view = this.initView(width, height, grid.getView());
}
/*** Abstract methods ***/
@@ -98,7 +99,7 @@
/** {@inheritDoc} */
public void eventPerformed(SimpleEvent e) {
- GameMediator.log.debug("eventPerformed(" + e + ")");
+ //GameMediator.log.debug("eventPerformed(" + e + ")");
this.fireEventPerformed(e);
}
Modified: trunk/src/picross/game/GameUI.java
===================================================================
--- trunk/src/picross/game/GameUI.java 2007-06-14 05:59:01 UTC (rev 37)
+++ trunk/src/picross/game/GameUI.java 2007-06-14 09:33:57 UTC (rev 38)
@@ -42,8 +42,6 @@
import javax.swing.JLabel;
import javax.swing.JPanel;
-import picross.Picross;
-
/**
* The game UI.
*
Modified: trunk/src/picross/game/random/RandomGameController.java
===================================================================
--- trunk/src/picross/game/random/RandomGameController.java 2007-06-14 05:59:01 UTC (rev 37)
+++ trunk/src/picross/game/random/RandomGameController.java 2007-06-14 09:33:57 UTC (rev 38)
@@ -68,7 +68,7 @@
/** {@inheritDoc} */
public void actionPerformed(ActionEvent e) {
- RandomGameController.log.debug("actionPerformed(" + e + ")");
+ //RandomGameController.log.debug("actionPerformed(" + e + ")");
String cmd = e.getActionCommand();
Modified: trunk/src/picross/game/random/RandomGameMediator.java
===================================================================
--- trunk/src/picross/game/random/RandomGameMediator.java 2007-06-14 05:59:01 UTC (rev 37)
+++ trunk/src/picross/game/random/RandomGameMediator.java 2007-06-14 09:33:57 UTC (rev 38)
@@ -37,7 +37,7 @@
import javax.swing.JPanel;
-import org.apache.log4j.Logger;
+//import org.apache.log4j.Logger;
import picross.PicrossController;
import picross.PicrossGrid;
@@ -54,7 +54,7 @@
/*** Static field ***/
/** The class' logger. */
- private static Logger log = Logger.getLogger(RandomGameMediator.class);
+ //private static Logger log = Logger.getLogger(RandomGameMediator.class);
/*** Methods overloaded from the class GameMediator ***/
@@ -74,7 +74,7 @@
/** {@inheritDoc} */
public void eventPerformed(SimpleEvent e) {
- RandomGameMediator.log.debug("eventPerformed(" + e + ")");
+ //RandomGameMediator.log.debug("eventPerformed(" + e + ")");
String cmd = e.getCommandName();
Modified: trunk/src/picross/game/random/RandomGameUI.java
===================================================================
--- trunk/src/picross/game/random/RandomGameUI.java 2007-06-14 05:59:01 UTC (rev 37)
+++ trunk/src/picross/game/random/RandomGameUI.java 2007-06-14 09:33:57 UTC (rev 38)
@@ -40,8 +40,6 @@
import javax.swing.JButton;
import javax.swing.JPanel;
-import picross.Picross;
-
import picross.game.GameUI;
/**
Deleted: trunk/src/picross/grid/ClearCommand.java
===================================================================
--- trunk/src/picross/grid/ClearCommand.java 2007-06-14 05:59:01 UTC (rev 37)
+++ trunk/src/picross/grid/ClearCommand.java 2007-06-14 09:33:57 UTC (rev 38)
@@ -1,93 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (c) 2007
- *
- * This software is governed by the CeCILL license under French law and
- * abiding by the rules of distribution of free software. You can use,
- * modify and/ or redistribute the software under the terms of the CeCILL
- * license as circulated by CEA, CNRS and INRIA at the following URL
- * "http://www.cecill.info".
- *
- * As a counterpart to the access to the source code and rights to copy,
- * modify and redistribute granted by the license, users are provided only
- * with a limited warranty and the software's author, the holder of the
- * economic rights, and the successive licensors have only limited
- * liability.
- *
- * In this respect, the user's attention is drawn to the risks associated
- * with loading, using, modifying and/or developing or reproducing the
- * software by the user in light of its specific status of free software,
- * that may mean that it is complicated to manipulate, and that also
- * therefore means that it is reserved for developers and experienced
- * professionals having in-depth computer knowledge. Users are therefore
- * encouraged to load and test the software's suitability as regards their
- * requirements in conditions enabling the security of their systems and/or
- * data to be ensured and, more generally, to use and operate it in the
- * same conditions as regards security.
- *
- * The fact that you are presently reading this means that you have had
- * knowledge of the CeCILL license and that you accept its terms.
- */
-
-
-package picross.grid;
-
-import fr.cle.mmvcs.Command;
-
-/**
- * Command asking to clear hints.
- *
- * @author Y. Norsa
- */
-final class ClearCommand extends Command {
- /*** Constants ***/
-
- /** Clear a column. */
- static final int COLUMN = 0;
-
- /** Clear a row. */
- static final int ROW = 1;
-
- /*** Fields ***/
-
- /** Type of hints to clear. */
- private int type;
-
- /** Number of the column or row. */
- private int pos;
-
- /*** Constructor ***/
-
- /**
- * Constructor.
- *
- * @param type type of hints to clear
- * @param pos number of the column or row
- */
- ClearCommand(int type, int pos) {
- this.type = type;
- this.pos = pos;
- }
-
- /*** Accessors ***/
-
- /**
- * Returns the type of hints to clear.
- *
- * @return type of hints to clear
- */
- int getType() {
- return this.type;
- }
-
- /**
- * Returns the position of the column or row.
- *
- * @return position of the number or row
- */
- int getPos() {
- return this.pos;
- }
-}
-
Added: trunk/src/picross/grid/CompletedHints.java
===================================================================
--- trunk/src/picross/grid/CompletedHints.java (rev 0)
+++ trunk/src/picross/grid/CompletedHints.java 2007-06-14 09:33:57 UTC (rev 38)
@@ -0,0 +1,170 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 2007
+ *
+ * This software is governed by the CeCILL license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/ or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ */
+
+
+package picross.grid;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This class contains the list of hints, marking those which are completed.
+ *
+ * @author Y. Norsa
+ */
+class CompletedHints {
+ /*** Fields ***/
+
+ /** List of completed column hints. */
+ private boolean[][] completedCols;
+
+ /** List of completed row hints. */
+ private boolean[][] completedRows;
+
+ /*** Constructor ***/
+
+ /**
+ * Constructor.
+ *
+ * @param colsHintsWidth width of the column hints list
+ * @param colsHintsHeight height of the column hints list
+ * @param rowsHintsWidth width of the row hints list
+ * @param rowsHintsHeight height of the row hints list
+ */
+ CompletedHints(int colsHintsWidth, int colsHintsHeight,
+ int rowsHintsWidth, int rowsHintsHeight) {
+ this.completedCols = new boolean[colsHintsWidth][colsHintsHeight];
+ this.completedRows = new boolean[rowsHintsWidth][rowsHintsHeight];
+ }
+
+ /*** Methods ***/
+
+ /**
+ * Tells wether a specific column hint is complete.
+ *
+ * @param x column number
+ * @param y hint position
+ * @return boolean telling wether the hint is completed
+ */
+ boolean isColHintComplete(int x, int y) {
+ return this.completedCols[x][y];
+ }
+
+ /**
+ * Returns the list of the completed column hints.
+ *
+ * @param column column number
+ * @return list of completed hints in the column
+ */
+ List<Integer> getCompleteColHints(int column) {
+ List<Integer> res = new ArrayList<Integer>();
+
+ for (int i = 0; i < this.completedCols[column].length; i++) {
+ if (this.completedCols[column][i]) {
+ res.add(i);
+ }
+ }
+
+ return res;
+ }
+
+ /**
+ * Resets the state of a hint.
+ *
+ * @param col column number
+ * @param hintIndex hint position
+ */
+ void clearColHint(int col, int hintIndex) {
+ this.completedCols[col][hintIndex] = false;
+ }
+
+ /**
+ * Marks a hint as complete.
+ *
+ * @param col column number
+ * @param index hint position
+ */
+ void setCompleteColHint(int col, int index) {
+ this.completedCols[col][index] = true;
+ }
+
+ /**
+ * Tells wether a specific row hint is complete.
+ *
+ * @param x row number
+ * @param y hint position
+ * @return boolean telling wether the hint is completed
+ */
+ boolean isRowHintComplete(int x, int y) {
+ return this.completedRows[x][y];
+ }
+
+ /**
+ * Returns the list of the completed row hints.
+ *
+ * @param row row number
+ * @return list of completed hints in the row
+ */
+ List<Integer> getCompleteRowHints(int row) {
+ List<Integer> res = new ArrayList<Integer>();
+
+ for (int i = 0; i < this.completedRows[row].length; i++) {
+ if (this.completedRows[row][i]) {
+ res.add(i);
+ }
+ }
+
+ return res;
+ }
+
+
+ /**
+ * Resets the state of a hint.
+ *
+ * @param row row number
+ * @param hintIndex hint position
+ */
+ void clearRowHint(int row, int hintIndex) {
+ this.completedRows[row][hintIndex] = false;
+ }
+
+ /**
+ * Marks a hint as complete.
+ *
+ * @param row row number
+ * @param index hint position
+ */
+ void setCompleteRowHint(int row, int index) {
+ this.completedRows[row][index] = true;
+ }
+}
+
Property changes on: trunk/src/picross/grid/CompletedHints.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: trunk/src/picross/grid/GridController.java
===================================================================
--- trunk/src/picross/grid/GridController.java 2007-06-14 05:59:01 UTC (rev 37)
+++ trunk/src/picross/grid/GridController.java 2007-06-14 09:33:57 UTC (rev 38)
@@ -69,9 +69,12 @@
/** Command indicating that a hint has been completed. */
static final String COMPLETED_CMD = "COMPLETED_CMD";
- /** Command asking to clear the completed hints. */
- static final String CLEAR_HINTS_CMD = "CLEAR_HINTS_CMD";
+ /** Command asking to repaint the top hints. */
+ static final String REPAINT_TOP_HINTS_CMD = "REPAINT_TOP_HINTS_CMD";
+ /** Command asking to repaint the left hints. */
+ static final String REPAINT_LEFT_HINTS_CMD = "REPAINT_LEFT_HINTS_CMD";
+
/** Checking a box. */
static final int CHECK_ACTION = 0;
@@ -108,29 +111,13 @@
return;
}
- if (cmd.equals(GridController.COMPLETED_CMD)) {
- CompletedCommand command = (CompletedCommand) e.getCommand();
-
- if (command.getType() == CompletedCommand.COLUMN) {
- this.view.completedColHint(command.getPosition(),
- command.getHintPos());
- } else { //if (command.getType() == CompletedCommand.ROW) {
- this.view.completedRowHint(command.getPosition(),
- command.getHintPos());
- }
-
+ if (cmd.equals(GridController.REPAINT_TOP_HINTS_CMD)) {
+ this.view.repaintColHints();
return;
}
- if (cmd.equals(GridController.CLEAR_HINTS_CMD)) {
- ClearCommand command = (ClearCommand) e.getCommand();
-
- if (command.getType() == ClearCommand.COLUMN) {
- this.view.clearColHints(command.getPos());
- } else { //if (command.getType() == ClearCommand.ROW) {
- this.view.clearRowHints(command.getPos());
- }
-
+ if (cmd.equals(GridController.REPAINT_LEFT_HINTS_CMD)) {
+ this.view.repaintRowHints();
return;
}
}
Modified: trunk/src/picross/grid/GridMediator.java
===================================================================
--- trunk/src/picross/grid/GridMediator.java 2007-06-14 05:59:01 UTC (rev 37)
+++ trunk/src/picross/grid/GridMediator.java 2007-06-14 09:33:57 UTC (rev 38)
@@ -79,6 +79,7 @@
this.model.getBoxes(),
this.model.getColData(),
this.model.getRowData(),
+ this.model.getCompletedHints(),
controller);
controller.setView(this.view);
@@ -124,52 +125,16 @@
new PaintCommand(row, column));
}
- /**
- * Asks to clear a column's hints.
- *
- * @param column column number
- */
- void clearColHints(int column) {
- this.fireEventPerformed(GridController.CLEAR_HINTS_CMD,
- new ClearCommand(ClearCommand.COLUMN,
- column));
+ /** Asks to repaint the column hints. */
+ void repaintColHints() {
+ this.fireEventPerformed(GridController.REPAINT_TOP_HINTS_CMD);
}
- /**
- * Ask to mark a column hint as completed.
- *
- * @param column column number
- * @param hintPos position of the hint
- */
- void completedColHint(int column, int hintPos) {
- this.fireEventPerformed(GridController.COMPLETED_CMD,
- new CompletedCommand(CompletedCommand.COLUMN,
- column, hintPos));
+ /** Asks to repaint the row hints. */
+ void repaintRowHints() {
+ this.fireEventPerformed(GridController.REPAINT_LEFT_HINTS_CMD);
}
- /**
- * Asks to clear a row's hints.
- *
- * @param row row number
- */
- void clearRowHints(int row) {
- this.fireEventPerformed(GridController.CLEAR_HINTS_CMD,
- new ClearCommand(ClearCommand.ROW,
- row));
- }
-
- /**
- * Asks to mark a row hint as completed.
- *
- * @param row row number
- * @param hintPos position of the hint
- */
- void completedRowHint(int row, int hintPos) {
- this.fireEventPerformed(GridController.COMPLETED_CMD,
- new CompletedCommand(CompletedCommand.ROW,
- row, hintPos));
- }
-
/*** Accessor ***/
/**
Modified: trunk/src/picross/grid/GridModel.java
===================================================================
--- trunk/src/picross/grid/GridModel.java 2007-06-14 05:59:01 UTC (rev 37)
+++ trunk/src/picross/grid/GridModel.java 2007-06-14 09:33:57 UTC (rev 38)
@@ -77,6 +77,9 @@
/** Rows hints. */
private int[][] rowData;
+ /** List of completed hints. */
+ private CompletedHints completedHints;
+
/*** Constructor ***/
/**
@@ -223,6 +226,10 @@
}
}
}
+
+ this.completedHints =
+ new CompletedHints(data.length, this.colData[0].length,
+ data[0].length, this.rowData[0].length);
}
/*** Static methods ***/
@@ -366,7 +373,7 @@
*/
private void checkRow(int row) {
// Contains the completed hints
- List<Integer> completedHints = new ArrayList<Integer>();
+ List<Integer> completedRowHints = new ArrayList<Integer>();
// Current hint we're looking to complete
int currentHintIndex =
@@ -390,7 +397,7 @@
if (this.rowData[row][currentHintIndex]
== currentChain) {
- completedHints.add(currentHintIndex);
+ completedRowHints.add(currentHintIndex);
currentChain = 0;
currentHintIndex =
@@ -410,7 +417,7 @@
* If this is the case,
* we cancel everything
*/
- completedHints.clear();
+ completedRowHints.clear();
break;
}
}
@@ -435,7 +442,7 @@
if (currentHintIndex != -1
&& this.rowData[row][currentHintIndex] == currentChain) {
- completedHints.add(currentHintIndex);
+ completedRowHints.add(currentHintIndex);
currentChain = 0;
}
}
@@ -455,7 +462,7 @@
if (this.rowData[row][currentHintIndex]
== currentChain) {
- completedHints.add(currentHintIndex);
+ completedRowHints.add(currentHintIndex);
currentChain = 0;
currentHintIndex =
@@ -466,7 +473,7 @@
if (currentHintIndex == -1) {
for (int i = currentHint; i >= 0; i--) {
if (this.boxes[i][row].isChecked()) {
- completedHints.clear();
+ completedRowHints.clear();
}
}
@@ -483,11 +490,19 @@
}
}
- this.mediator.clearRowHints(row);
+ List<Integer> rowHints = this.completedHints.getCompleteRowHints(row);
- for (int index : completedHints) {
- this.mediator.completedRowHint(row, index);
+ for (int hintIndex : rowHints) {
+ if (!completedRowHints.contains(hintIndex)) {
+ this.completedHints.clearRowHint(row, hintIndex);
+ }
}
+
+ for (int index : completedRowHints) {
+ this.completedHints.setCompleteRowHint(row, index);
+ }
+
+ this.mediator.repaintRowHints();
}
/**
@@ -498,7 +513,7 @@
private void checkColumn(int column) {
//GridModel.log.debug("checkColumn(" + column + ")");
- List<Integer> completedHints = new ArrayList<Integer>();
+ List<Integer> completedColHints = new ArrayList<Integer>();
/*
for (int i = 0; i < this.colData[column].length; i++) {
GridModel.log.debug("this.colData[" + column + "][" + i + "] = "
@@ -528,7 +543,7 @@
//GridModel.log.debug("found " + currentChain);
- completedHints.add(currentHintIndex);
+ completedColHints.add(currentHintIndex);
currentChain = 0;
//GridModel.log.debug("currentHintIndex = "
@@ -543,7 +558,7 @@
i++) {
if (this.boxes[column][i].isChecked()) {
- completedHints.clear();
+ completedColHints.clear();
break;
}
}
@@ -568,7 +583,7 @@
//GridModel.log.debug("found " + currentChain);
- completedHints.add(currentHintIndex);
+ completedColHints.add(currentHintIndex);
currentChain = 0;
}
@@ -596,7 +611,7 @@
//GridModel.log.debug("found2 " + currentChain);
- completedHints.add(currentHintIndex);
+ completedColHints.add(currentHintIndex);
currentChain = 0;
currentHintIndex =
@@ -606,7 +621,7 @@
if (currentHintIndex == GridModel.EMPTY_HINT) {
for (int i = currentHint; i >= 0; i--) {
if (this.boxes[column][i].isChecked()) {
- completedHints.clear();
+ completedColHints.clear();
}
}
@@ -623,11 +638,20 @@
}
}
- this.mediator.clearColHints(column);
+ List<Integer> colHints =
+ this.completedHints.getCompleteColHints(column);
- for (int index : completedHints) {
- this.mediator.completedColHint(column, index);
+ for (int hintIndex : colHints) {
+ if (!completedColHints.contains(hintIndex)) {
+ this.completedHints.clearColHint(column, hintIndex);
+ }
}
+
+ for (int index : completedColHints) {
+ this.completedHints.setCompleteColHint(column, index);
+ }
+
+ this.mediator.repaintColHints();
}
/** Checks wether the grid is finished. */
@@ -686,5 +710,14 @@
int[][] getRowData() {
return this.rowData;
}
+
+ /**
+ * Returns the completed hints.
+ *
+ * @return list of completed hints
+ */
+ CompletedHints getCompletedHints() {
+ return this.completedHints;
+ }
}
Modified: trunk/src/picross/grid/GridUI.java
===================================================================
--- trunk/src/picross/grid/GridUI.java 2007-06-14 05:59:01 UTC (rev 37)
+++ trunk/src/picross/grid/GridUI.java 2007-06-14 09:33:57 UTC (rev 38)
@@ -46,6 +46,8 @@
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+
import java.util.ArrayList;
import java.util.List;
@@ -150,11 +152,17 @@
/** Rectangle occupied by the top hints. */
private Rectangle topHintsRect;
+ /** Precomputed image containing the top hints boxes. */
+ private transient BufferedImage topHintsBoxes;
+
/** Rectangle occupied by the left hints. */
private Rectangle leftHintsRect;
+ /** Precomputed image containing the left hints boxes. */
+ private transient BufferedImage leftHintsBoxes;
+
/** Current state of the grid. */
- private Box[][] boxes;
+ private transient Box[][] boxes;
/** Current rolled-over box. */
private transient Box rollover;
@@ -189,12 +197,9 @@
/** Boxes blocks. */
private List<Line2D> blocksLines;
- /** Completed column hints. */
- private boolean[][] completedCols;
+ /** List of completed hints. */
+ private transient CompletedHints completedHints;
- /** Completed row hints. */
- private boolean[][] completedRows;
-
/*** Constructor ***/
/**
@@ -205,12 +210,14 @@
* @param boxes current state of the grid
* @param colData columns hints
* @param rowData rows hints
+ * @param completedHints list of completed hints
* @param controller controller for the grid
*/
GridUI(int width, int height,
Box[][] boxes,
int[][] colData,
int[][] rowData,
+ CompletedHints completedHints,
GridController controller) {
super(true);
@@ -228,6 +235,8 @@
this.colData = colData;
this.rowData = rowData;
+ this.completedHints = completedHints;
+
// Computes the size of a hint
FontRenderContext frc = new FontRenderContext(null, true, true);
@@ -311,10 +320,9 @@
//GridUI.log.debug("bottomBoundary : " + this.bottomBoundary);
this.initBlocks();
+ this.initTopHints((GridUI.BOX_WIDTH / 2) - (hintBoxWidth / 2));
+ this.initLeftHints((GridUI.BOX_HEIGHT / 2) - (hintBoxHeight / 2));
- this.completedCols = new boolean[this.width][this.colData[0].length];
- this.completedRows = new boolean[this.height][this.rowData[0].length];
-
this.setPreferredSize(new Dimension(this.rightBoundary
+ GridUI.RIGHT_SPACE,
this.bottomBoundary
@@ -424,11 +432,77 @@
}
/**
+ * Precomputes the top hints boxes.
+ *
+ * @param topHintsStart coordinate where the boxes begin
+ */
+ private void initTopHints(int topHintsStart) {
+ this.topHintsBoxes = new BufferedImage(this.topHintsRect.width,
+ this.topHintsRect.height,
+ BufferedImage.TYPE_INT_RGB);
+ Graphics2D g2d = this.topHintsBoxes.createGraphics();
+ g2d.setColor(Color.WHITE);
+ g2d.fillRect(0, 0, this.topHintsRect.width, this.topHintsRect.height);
+
+ int y = 0;
+
+ for (int i = this.colData[0].length - 1; i >= 0; i--) {
+ int x = topHintsStart;
+
+ for (int j = 0; j < this.colData.length; j++) {
+ if (this.colData[j][i] != GridModel.EMPTY_HINT) {
+ this.hintBoxIcon.paintIcon(this, g2d, x, y);
+ }
+
+ x += GridUI.BOX_WIDTH;
+ }
+
+ y += this.topHintsDecal;
+ }
+ }
+
+ /**
+ * Precomputes the left hints boxes.
+ *
+ * @param leftHintsStart coordinate where the boxes begin
+ */
+ private void initLeftHints(int leftHintsStart) {
+ this.leftHintsBoxes = new BufferedImage(this.leftHintsRect.width,
+ this.leftHintsRect.height,
+ BufferedImage.TYPE_INT_RGB);
+ Graphics2D g2d = this.leftHintsBoxes.createGraphics();
+ g2d.setColor(Color.WHITE);
+ g2d.fillRect(0, 0,
+ this.leftHintsRect.width, this.leftHintsRect.height);
+
+ int y = leftHintsStart;
+
+ for (int i = 0; i < this.rowData.length; i++) {
+ int x = 0;
+
+ for (int j = 0; j < this.rowData[i].length; j++) {
+ if (this.rowData[i][j] != GridModel.EMPTY_HINT) {
+ this.hintBoxIcon.paintIcon(this, g2d, x, y);
+ }
+
+ x += this.leftHintsDecal;
+ }
+
+ y += GridUI.BOX_HEIGHT;
+ }
+ }
+
+ /**
* Draws the top hints.
*
* @param g the graphics context
*/
private void drawTopHints(Graphics g) {
+ g.drawImage(this.topHintsBoxes,
+ this.topHintsRect.x, this.topHintsRect.y, null);
+
+ g.setFont(GridUI.HINT_FONT);
+
int y = 0;
for (int i = this.colData[0].length - 1; i >= 0; i--) {
@@ -437,7 +511,7 @@
for (int j = 0; j < this.colData.length; j++) {
if (this.colData[j][i] != GridModel.EMPTY_HINT) {
this.drawHint(g, t...
[truncated message content] |
|
From: <yva...@us...> - 2008-04-17 09:38:05
|
Revision: 49
http://picross.svn.sourceforge.net/picross/?rev=49&view=rev
Author: yvan_norsa
Date: 2008-04-17 02:38:09 -0700 (Thu, 17 Apr 2008)
Log Message:
-----------
exception when an image is missing
Modified Paths:
--------------
trunk/src/picross/Picross.java
trunk/src/picross/app/MainMenuAppUI.java
trunk/src/picross/applet/MainMenuAppletUI.java
trunk/src/picross/grid/Box.java
trunk/src/picross/menus/GameMenuMediator.java
trunk/src/picross/menus/GameMenuUI.java
trunk/src/picross/menus/MainMenuUI.java
trunk/src/picross/menus/MenuUI.java
trunk/src/picross/tests/PicrossTest.java
Added Paths:
-----------
trunk/src/picross/MissingImageException.java
Added: trunk/src/picross/MissingImageException.java
===================================================================
--- trunk/src/picross/MissingImageException.java (rev 0)
+++ trunk/src/picross/MissingImageException.java 2008-04-17 09:38:09 UTC (rev 49)
@@ -0,0 +1,58 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 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,
+ * 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;
+
+/**
+ * Exception thrown when an image file is not found.
+ *
+ * @author Y. Norsa
+ */
+public class MissingImageException extends RuntimeException {
+ /*** Constant ***/
+
+ /** Serialisation ID. */
+ private static final long serialVersionUID = 7805399363197308654L;
+
+ /*** Constructor ***/
+
+ /**
+ * Constructor.
+ *
+ * @param cause parent exception
+ */
+ MissingImageException(Throwable cause) {
+ super(cause);
+ }
+}
+
Property changes on: trunk/src/picross/MissingImageException.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: trunk/src/picross/Picross.java
===================================================================
--- trunk/src/picross/Picross.java 2008-04-17 09:11:28 UTC (rev 48)
+++ trunk/src/picross/Picross.java 2008-04-17 09:38:09 UTC (rev 49)
@@ -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,
@@ -97,12 +97,14 @@
*
* @param path path of the image
* @return the image
- * @throws FileNotFoundException if the file can't be found
+ * @throws MissingImageException if the image file can't be found
*/
- private static ImageIcon loadImage(String path)
- throws FileNotFoundException {
-
- return new ImageIcon(Picross.getFile(path));
+ private static ImageIcon loadImage(String path) {
+ try {
+ return new ImageIcon(Picross.getFile(path));
+ } catch (FileNotFoundException fileEx) {
+ throw new MissingImageException(fileEx);
+ }
}
/**
@@ -112,10 +114,10 @@
* @return the image
* @throws IllegalArgumentException if <code>name</code>
* is <code>null</code> or empty
- * @throws FileNotFoundException if the file can't be found
+ * @throws MissingImageException if the image file can't be found
*/
public static ImageIcon getImage(String name)
- throws IllegalArgumentException, FileNotFoundException {
+ throws IllegalArgumentException {
if (name == null || name.equals("")) {
throw new IllegalArgumentException("name can't be null or empty");
@@ -131,10 +133,10 @@
* @return the image
* @throws IllegalArgumentException if <code>name</code>
* is <code>null</code> or empty
- * @throws FileNotFoundException if the file can't be found
+ * @throws MissingImageException if the image file can't be found
*/
public static ImageIcon getLocalizedImage(String name)
- throws IllegalArgumentException, FileNotFoundException {
+ throws IllegalArgumentException {
if (name == null || name.equals("")) {
throw new IllegalArgumentException("name can't be null or empty");
Modified: trunk/src/picross/app/MainMenuAppUI.java
===================================================================
--- trunk/src/picross/app/MainMenuAppUI.java 2008-04-17 09:11:28 UTC (rev 48)
+++ trunk/src/picross/app/MainMenuAppUI.java 2008-04-17 09:38:09 UTC (rev 49)
@@ -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,
@@ -77,11 +77,9 @@
* Constructor.
*
* @param controller controller for the buttons
- * @throws FileNotFoundException if a button image can't be found
+ * @throws MissingImageException if a button image can't be found
*/
- public MainMenuAppUI(ActionListener controller)
- throws FileNotFoundException {
-
+ public MainMenuAppUI(ActionListener controller) {
super(controller);
this.addButton(MainMenuAppUI.EXIT_BUTTON_IMAGE,
Modified: trunk/src/picross/applet/MainMenuAppletUI.java
===================================================================
--- trunk/src/picross/applet/MainMenuAppletUI.java 2008-04-17 09:11:28 UTC (rev 48)
+++ trunk/src/picross/applet/MainMenuAppletUI.java 2008-04-17 09:38:09 UTC (rev 49)
@@ -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,
@@ -64,11 +64,9 @@
* Constructor.
*
* @param controller controller for the buttons
- * @throws FileNotFoundException if a button image can't be found
+ * @throws MissingImageException if a button image can't be found
*/
- public MainMenuAppletUI(ActionListener controller)
- throws FileNotFoundException {
-
+ public MainMenuAppletUI(ActionListener controller) {
super(controller);
this.setBackground(Color.WHITE);
Modified: trunk/src/picross/grid/Box.java
===================================================================
--- trunk/src/picross/grid/Box.java 2008-04-17 09:11:28 UTC (rev 48)
+++ trunk/src/picross/grid/Box.java 2008-04-17 09:38:09 UTC (rev 49)
@@ -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,
@@ -35,14 +35,13 @@
import java.awt.Rectangle;
-import java.io.FileNotFoundException;
-
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import javax.swing.ImageIcon;
+import picross.MissingImageException;
import picross.Picross;
//import org.apache.log4j.Logger;
@@ -128,8 +127,8 @@
Box.images.put(state, img);
}
- } catch (FileNotFoundException fileEx) {
- throw new ExceptionInInitializerError(fileEx);
+ } catch (MissingImageException imageEx) {
+ throw new ExceptionInInitializerError(imageEx);
}
}
Modified: trunk/src/picross/menus/GameMenuMediator.java
===================================================================
--- trunk/src/picross/menus/GameMenuMediator.java 2008-04-17 09:11:28 UTC (rev 48)
+++ trunk/src/picross/menus/GameMenuMediator.java 2008-04-17 09:38:09 UTC (rev 49)
@@ -48,6 +48,7 @@
public class GameMenuMediator extends Mediateur {
/*** Field ***/
+ /** View of the menu. */
private GameMenuUI view;
/*** Constructor ***/
@@ -59,11 +60,7 @@
GameMenuController controller = new GameMenuController();
controller.addSimpleListener(this);
- try {
- this.view = new GameMenuUI(controller);
- } catch (FileNotFoundException fileEx) {
- throw new PicrossException(fileEx);
- }
+ this.view = new GameMenuUI(controller);
}
/*** Method overloaded from the Mediateur class ***/
Modified: trunk/src/picross/menus/GameMenuUI.java
===================================================================
--- trunk/src/picross/menus/GameMenuUI.java 2008-04-17 09:11:28 UTC (rev 48)
+++ trunk/src/picross/menus/GameMenuUI.java 2008-04-17 09:38:09 UTC (rev 49)
@@ -54,8 +54,11 @@
/**
* Constructor.
+ *
+ * @param listener listener for the button
+ * @throws MissingImageException if a button image can't be found
*/
- GameMenuUI(ActionListener listener) throws FileNotFoundException {
+ GameMenuUI(ActionListener listener) {
this.addButton("button-random.png", PicrossController.RANDOM_GAME_CMD,
listener, 150, 225);
}
Modified: trunk/src/picross/menus/MainMenuUI.java
===================================================================
--- trunk/src/picross/menus/MainMenuUI.java 2008-04-17 09:11:28 UTC (rev 48)
+++ trunk/src/picross/menus/MainMenuUI.java 2008-04-17 09:38:09 UTC (rev 49)
@@ -68,9 +68,9 @@
* Constructor.
*
* @param controller controller for the buttons
- * @throws FileNotFoundException if a button image can't be found
+ * @throws MissingImageException if a button image can't be found
*/
- public MainMenuUI(ActionListener controller) throws FileNotFoundException {
+ public MainMenuUI(ActionListener controller) {
super();
this.addButton(MainMenuUI.PLAY_BUTTON_IMAGE,
Modified: trunk/src/picross/menus/MenuUI.java
===================================================================
--- trunk/src/picross/menus/MenuUI.java 2008-04-17 09:11:28 UTC (rev 48)
+++ trunk/src/picross/menus/MenuUI.java 2008-04-17 09:38:09 UTC (rev 49)
@@ -45,6 +45,9 @@
import javax.swing.JButton;
import javax.swing.JPanel;
+import org.apache.log4j.Logger;
+
+import picross.MissingImageException;
import picross.Picross;
/**
@@ -53,11 +56,22 @@
* @author Y. Norsa
*/
abstract class MenuUI extends JPanel {
- /*** Constant ***/
+ /*** Constants ***/
/** Background image. */
private static final String BACKGROUND_IMAGE = "background.png";
+ /** Default width to be used if the background file can't be found. */
+ private static final int DEFAULT_WIDTH = 450;
+
+ /** Default height to be used if the background file can't be found. */
+ private static final int DEFAULT_HEIGHT = 375;
+
+ /*** Static field ***/
+
+ /** This class' logger. */
+ private static Logger log = Logger.getLogger(MenuUI.class);
+
/*** Field ***/
/** Background image. */
@@ -65,16 +79,18 @@
/*** Constructor ***/
- /**
- * Constructor.
- *
- * @throws FileNotFoundException if the background image can't be found
- */
- MenuUI() throws FileNotFoundException {
- ImageIcon icon = Picross.getImage(MenuUI.BACKGROUND_IMAGE);
- this.setPreferredSize(new Dimension(icon.getIconWidth(),
- icon.getIconHeight()));
- this.image = icon.getImage();
+ /** Constructor. */
+ MenuUI() {
+ try {
+ ImageIcon icon = Picross.getImage(MenuUI.BACKGROUND_IMAGE);
+ this.setPreferredSize(new Dimension(icon.getIconWidth(),
+ icon.getIconHeight()));
+ this.image = icon.getImage();
+ } catch (MissingImageException imageEx) {
+ MenuUI.log.info(imageEx.getMessage());
+ this.setPreferredSize(new Dimension(MenuUI.DEFAULT_WIDTH,
+ MenuUI.DEFAULT_HEIGHT));
+ }
this.setLayout(null);
}
@@ -98,12 +114,10 @@
* @param controller listener for the button
* @param x x position for the button
* @param y y position for the button
- * @throws FileNotFoundException if a button image can't be found
+ * @throws MissingImageException if a button image can't be found
*/
protected void addButton(String image, String command,
- ActionListener controller, int x, int y)
- throws FileNotFoundException {
-
+ ActionListener controller, int x, int y) {
ImageIcon buttonIcon = Picross.getLocalizedImage(image);
JButton button = new JButton(buttonIcon);
button.setActionCommand(command);
Modified: trunk/src/picross/tests/PicrossTest.java
===================================================================
--- trunk/src/picross/tests/PicrossTest.java 2008-04-17 09:11:28 UTC (rev 48)
+++ trunk/src/picross/tests/PicrossTest.java 2008-04-17 09:38:09 UTC (rev 49)
@@ -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,
@@ -42,6 +42,7 @@
import org.junit.Assert;
import org.junit.Test;
+import picross.MissingImageException;
import picross.Picross;
/**
@@ -74,10 +75,10 @@
/**
* Tests the method getImage().
*
- * @throws FileNotFoundException if a file loading fails.
+ * @throws MissingImageException if a file loading fails.
*/
@Test
- public void testGetImage() throws FileNotFoundException {
+ public void testGetImage() {
try {
Picross.getImage(null);
Assert.fail("name = null");
@@ -91,7 +92,7 @@
try {
Picross.getImage("fakeFile");
Assert.fail("Fake file");
- } catch (FileNotFoundException fileEx) { }
+ } catch (MissingImageException imageEx) { }
ImageIcon icon = Picross.getImage("empty.png");
PicrossTest.testIcon(icon, 25, 25);
@@ -100,10 +101,10 @@
/**
* Tests the method getLocalizedImage().
*
- * @throws FileNotFoundException if a file loading fails.
+ * @throws MissingImageException if a file loading fails.
*/
@Test
- public void getLocalizedImage() throws FileNotFoundException {
+ public void getLocalizedImage() {
try {
Picross.getLocalizedImage(null);
Assert.fail("name = null");
@@ -117,7 +118,7 @@
try {
Picross.getImage("fakeFile");
Assert.fail("Fake file");
- } catch (FileNotFoundException fileEx) { }
+ } catch (MissingImageException imageEx) { }
ImageIcon icon = Picross.getLocalizedImage("button-play.png");
PicrossTest.testIcon(icon, 150, 50);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yva...@us...> - 2008-04-17 12:05:41
|
Revision: 50
http://picross.svn.sourceforge.net/picross/?rev=50&view=rev
Author: yvan_norsa
Date: 2008-04-17 05:05:40 -0700 (Thu, 17 Apr 2008)
Log Message:
-----------
menus factorisation
Modified Paths:
--------------
trunk/src/picross/PicrossController.java
trunk/src/picross/PicrossMediator.java
trunk/src/picross/app/MainMenuAppUI.java
trunk/src/picross/menus/GameMenuMediator.java
trunk/src/picross/menus/GameMenuUI.java
trunk/src/picross/menus/MainMenuMediator.java
Added Paths:
-----------
trunk/src/picross/menus/MenuController.java
trunk/src/picross/menus/MenuMediator.java
Removed Paths:
-------------
trunk/src/picross/menus/GameMenuController.java
trunk/src/picross/menus/MainMenuController.java
Modified: trunk/src/picross/PicrossController.java
===================================================================
--- trunk/src/picross/PicrossController.java 2008-04-17 09:38:09 UTC (rev 49)
+++ trunk/src/picross/PicrossController.java 2008-04-17 12:05:40 UTC (rev 50)
@@ -52,6 +52,12 @@
/** Random game command. */
public static final String RANDOM_GAME_CMD = "RANDOM_GAME_CMD";
+ /** Select level command. */
+ public static final String SELECT_LEVEL_CMD = "SELECT_LEVEL_CMD";
+
+ /** Exit command. */
+ public static final String EXIT_CMD = "EXIT_CMD";
+
/*** Static field ***/
/** The class's logger. */
Modified: trunk/src/picross/PicrossMediator.java
===================================================================
--- trunk/src/picross/PicrossMediator.java 2008-04-17 09:38:09 UTC (rev 49)
+++ trunk/src/picross/PicrossMediator.java 2008-04-17 12:05:40 UTC (rev 50)
@@ -48,7 +48,6 @@
import picross.menus.GameMenuMediator;
-import picross.menus.MainMenuController;
import picross.menus.MainMenuMediator;
/**
@@ -83,7 +82,7 @@
MainMenuMediator mediator = null;
try {
- mediator = new MainMenuMediator(view);
+ mediator = new MainMenuMediator(this.view);
} catch (PicrossException picrossEx) {
this.fireEventPerformed(PicrossController.ERROR_CMD,
picrossEx.getMessage());
@@ -118,7 +117,7 @@
return;
}
- if (cmd.equals(MainMenuController.EXIT_CMD)) {
+ if (cmd.equals(PicrossController.EXIT_CMD)) {
this.exit();
return;
}
@@ -143,7 +142,7 @@
GameMenuMediator menu = null;
try {
- menu = new GameMenuMediator();
+ menu = new GameMenuMediator(this.view);
} catch (PicrossException picrossEx) {
this.fireEventPerformed(PicrossController.ERROR_CMD,
picrossEx.getMessage());
Modified: trunk/src/picross/app/MainMenuAppUI.java
===================================================================
--- trunk/src/picross/app/MainMenuAppUI.java 2008-04-17 09:38:09 UTC (rev 49)
+++ trunk/src/picross/app/MainMenuAppUI.java 2008-04-17 12:05:40 UTC (rev 50)
@@ -41,8 +41,8 @@
import javax.swing.JButton;
import picross.Picross;
+import picross.PicrossController;
-import picross.menus.MainMenuController;
import picross.menus.MainMenuUI;
/**
@@ -83,7 +83,7 @@
super(controller);
this.addButton(MainMenuAppUI.EXIT_BUTTON_IMAGE,
- MainMenuController.EXIT_CMD,
+ PicrossController.EXIT_CMD,
controller,
MainMenuAppUI.EXIT_BUTTON_X,
MainMenuAppUI.EXIT_BUTTON_Y);
Deleted: trunk/src/picross/menus/GameMenuController.java
===================================================================
--- trunk/src/picross/menus/GameMenuController.java 2008-04-17 09:38:09 UTC (rev 49)
+++ trunk/src/picross/menus/GameMenuController.java 2008-04-17 12:05:40 UTC (rev 50)
@@ -1,68 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (c) 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,
- * 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.menus;
-
-import fr.cle.mmvcs.Controller;
-import fr.cle.mmvcs.SimpleEvent;
-
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-
-import picross.PicrossController;
-
-/**
- * Controller for the game menu.
- *
- * @author Y. Norsa
- */
-class GameMenuController extends Controller implements ActionListener {
- /*** Method overloaded from the class Controller ***/
-
- /** {@inheritDoc} */
- @Override
- public void eventPerformed(SimpleEvent e) { }
-
- /*** Method implanted from the interface ActionListener ***/
-
- /** {@inheritDoc} */
- public void actionPerformed(ActionEvent e) {
- String cmd = e.getActionCommand();
-
- if (cmd.equals(PicrossController.RANDOM_GAME_CMD)) {
- this.fireEventPerformed(cmd);
- return;
- }
- }
-}
-
Modified: trunk/src/picross/menus/GameMenuMediator.java
===================================================================
--- trunk/src/picross/menus/GameMenuMediator.java 2008-04-17 09:38:09 UTC (rev 49)
+++ trunk/src/picross/menus/GameMenuMediator.java 2008-04-17 12:05:40 UTC (rev 50)
@@ -39,47 +39,34 @@
import java.io.FileNotFoundException;
import picross.PicrossException;
+import picross.PicrossUI;
/**
* Mediator for the game menu.
*
* @author Y. Norsa
*/
-public class GameMenuMediator extends Mediateur {
- /*** Field ***/
-
- /** View of the menu. */
- private GameMenuUI view;
-
+public class GameMenuMediator extends MenuMediator {
/*** Constructor ***/
/**
* Constructor.
+ *
+ * @param ui reference to the main UI
+ * @throws PicrossException if the instantiation of the view fails
*/
- public GameMenuMediator() throws PicrossException {
- GameMenuController controller = new GameMenuController();
- controller.addSimpleListener(this);
-
- this.view = new GameMenuUI(controller);
+ public GameMenuMediator(PicrossUI ui) throws PicrossException {
+ super(ui);
}
- /*** Method overloaded from the Mediateur class ***/
+ /*** Method overloaded from the class MenuMediator ***/
- /** {@inheritDoc} */
+ /** {@inheritDoc}\xA0*/
@Override
- public void eventPerformed(SimpleEvent e) {
- this.fireEventPerformed(e);
- }
+ protected MenuUI initView(PicrossUI ui, MenuController controller)
+ throws PicrossException {
- /*** Accessor ***/
-
- /**
- * Returns the view.
- *
- * @return the view
- */
- public GameMenuUI getView() {
- return this.view;
+ return new GameMenuUI(controller);
}
}
Modified: trunk/src/picross/menus/GameMenuUI.java
===================================================================
--- trunk/src/picross/menus/GameMenuUI.java 2008-04-17 09:38:09 UTC (rev 49)
+++ trunk/src/picross/menus/GameMenuUI.java 2008-04-17 12:05:40 UTC (rev 50)
@@ -45,22 +45,33 @@
* @author Y. Norsa
*/
class GameMenuUI extends MenuUI {
- /*** Constant ***/
+ /*** Constants ***/
/** Serialisation ID. */
private static final long serialVersionUID = 4472277675596865332L;
+ /** Image for the "random" button. */
+ private static final String RANDOM_BUTTON_IMAGE = "button-random.png";
+
+ /** "Random" button X coordinate. */
+ private static final int RANDOM_BUTTON_X = 150;
+
+ /** "Random" button Y coordinate. */
+ private static final int RANDOM_BUTTON_Y = 175;
+
/*** Constructor ***/
/**
* Constructor.
*
* @param listener listener for the button
- * @throws MissingImageException if a button image can't be found
+ * @throws MissingImageException if the button image can't be found
*/
GameMenuUI(ActionListener listener) {
- this.addButton("button-random.png", PicrossController.RANDOM_GAME_CMD,
- listener, 150, 225);
+ this.addButton(GameMenuUI.RANDOM_BUTTON_IMAGE,
+ PicrossController.RANDOM_GAME_CMD,
+ listener,
+ GameMenuUI.RANDOM_BUTTON_X, GameMenuUI.RANDOM_BUTTON_Y);
}
}
Deleted: trunk/src/picross/menus/MainMenuController.java
===================================================================
--- trunk/src/picross/menus/MainMenuController.java 2008-04-17 09:38:09 UTC (rev 49)
+++ trunk/src/picross/menus/MainMenuController.java 2008-04-17 12:05:40 UTC (rev 50)
@@ -1,87 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (c) 2007
- *
- * This software is governed by the CeCILL license under French law and
- * abiding by the rules of distribution of free software. You can use,
- * modify and/ or redistribute the software under the terms of the CeCILL
- * license as circulated by CEA, CNRS and INRIA at the following URL
- * "http://www.cecill.info".
- *
- * As a counterpart to the access to the source code and rights to copy,
- * modify and redistribute granted by the license, users are provided only
- * with a limited warranty and the software's author, the holder of the
- * economic rights, and the successive licensors have only limited
- * liability.
- *
- * In this respect, the user's attention is drawn to the risks associated
- * with loading, using, modifying and/or developing or reproducing the
- * software by the user in light of its specific status of free software,
- * that may mean that it is complicated to manipulate, and that also
- * therefore means that it is reserved for developers and experienced
- * professionals having in-depth computer knowledge. Users are therefore
- * encouraged to load and test the software's suitability as regards their
- * requirements in conditions enabling the security of their systems and/or
- * data to be ensured and, more generally, to use and operate it in the
- * same conditions as regards security.
- *
- * The fact that you are presently reading this means that you have had
- * knowledge of the CeCILL license and that you accept its terms.
- */
-
-
-package picross.menus;
-
-import fr.cle.mmvcs.Controller;
-import fr.cle.mmvcs.SimpleEvent;
-
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-
-import org.apache.log4j.Logger;
-
-import picross.PicrossController;
-
-/**
- * Controller for the main menu.
- *
- * @author Y. Norsa
- */
-public class MainMenuController extends Controller implements ActionListener {
- /*** Constant ***/
-
- /** Exit command. */
- public static final String EXIT_CMD = "EXIT_CMD";
-
- /*** Static field ***/
-
- /** The class' logger. */
- private static Logger log = Logger.getLogger(MainMenuController.class);
-
- /*** Method overloaded from the class Controller ***/
-
- /** {@inheritDoc} */
- public void eventPerformed(SimpleEvent e) {
- MainMenuController.log.debug("eventPerformed(" + e + ")");
- }
-
- /*** Method implanted from the interface ActionListener ***/
-
- /** {@inheritDoc} */
- public void actionPerformed(ActionEvent e) {
- //MainMenuController.log.debug("actionPerformed(" + e + ")");
-
- String cmd = e.getActionCommand();
-
- //javax.swing.JOptionPane.showMessageDialog(null, "click : " + cmd);
-
- if (cmd.equals(PicrossController.PLAY_CMD)
- || cmd.equals(MainMenuController.EXIT_CMD)) {
-
- this.fireEventPerformed(cmd);
- return;
- }
- }
-}
-
Modified: trunk/src/picross/menus/MainMenuMediator.java
===================================================================
--- trunk/src/picross/menus/MainMenuMediator.java 2008-04-17 09:38:09 UTC (rev 49)
+++ trunk/src/picross/menus/MainMenuMediator.java 2008-04-17 12:05:40 UTC (rev 50)
@@ -50,30 +50,28 @@
*
* @author Y. Norsa
*/
-public class MainMenuMediator extends Mediateur {
- /*** Static field ***/
-
- /** The class' logger. */
- private static Logger log = Logger.getLogger(MainMenuMediator.class);
-
- /*** Field ***/
-
- /** The menu view. */
- private MainMenuUI view;
-
+public class MainMenuMediator extends MenuMediator {
/*** Constructor ***/
/**
* Constructor.
*
+ * @param ui reference to the main UI
* @throws PicrossException if the instantiation of the main menu UI fails
*/
public MainMenuMediator(PicrossUI ui) throws PicrossException {
- MainMenuController controller = new MainMenuController();
- controller.addSimpleListener(this);
+ super(ui);
+ }
+ /*** Method overloaded from the class MenuMediator ***/
+
+ /** {@inheritDoc} */
+ @Override
+ protected MenuUI initView(PicrossUI ui, MenuController controller)
+ throws PicrossException {
+
try {
- this.view = (MainMenuUI) Class.forName(ui.getMainMenuClass())
+ return (MainMenuUI) Class.forName(ui.getMainMenuClass())
.getConstructor(ActionListener.class).newInstance(controller);
} catch (ClassNotFoundException classEx) {
throw new PicrossException(classEx);
@@ -87,25 +85,5 @@
throw new PicrossException(targetEx.getCause());
}
}
-
- /*** Method overloaded from the class Mediateur ***/
-
- /** {@inheritDoc} */
- public void eventPerformed(SimpleEvent e) {
- MainMenuMediator.log.debug("eventPerformed(" + e + ")");
-
- this.fireEventPerformed(e);
- }
-
- /*** Accessor ***/
-
- /**
- * Returns the view.
- *
- * @return the view
- */
- public MainMenuUI getView() {
- return this.view;
- }
}
Added: trunk/src/picross/menus/MenuController.java
===================================================================
--- trunk/src/picross/menus/MenuController.java (rev 0)
+++ trunk/src/picross/menus/MenuController.java 2008-04-17 12:05:40 UTC (rev 50)
@@ -0,0 +1,61 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 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,
+ * 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.menus;
+
+import fr.cle.mmvcs.Controller;
+import fr.cle.mmvcs.SimpleEvent;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+/**
+ * @author Y. Norsa
+ */
+class MenuController extends Controller implements ActionListener {
+ /*** Method overloaded from the class Controller ***/
+
+ /** {@inheritDoc} */
+ @Override
+ public void eventPerformed(SimpleEvent e) {
+ }
+
+ /*** Method implanted from the interface ActionListener ***/
+
+ /** {@inheritDoc} */
+ public void actionPerformed(ActionEvent e) {
+ String cmd = e.getActionCommand();
+ this.fireEventPerformed(cmd);
+ }
+}
+
Property changes on: trunk/src/picross/menus/MenuController.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/src/picross/menus/MenuMediator.java
===================================================================
--- trunk/src/picross/menus/MenuMediator.java (rev 0)
+++ trunk/src/picross/menus/MenuMediator.java 2008-04-17 12:05:40 UTC (rev 50)
@@ -0,0 +1,108 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 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,
+ * 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.menus;
+
+import fr.cle.mmvcs.Mediateur;
+import fr.cle.mmvcs.SimpleEvent;
+
+import org.apache.log4j.Logger;
+
+import picross.PicrossException;
+import picross.PicrossUI;
+
+/**
+ * Mediator of a menu.
+ *
+ * @author Y. Norsa
+ */
+abstract class MenuMediator extends Mediateur {
+ /*** Static field ***/
+
+ /** This class' logger. */
+ private static Logger log = Logger.getLogger(MenuMediator.class);
+
+ /*** Field ***/
+
+ /** The menu's view. */
+ private MenuUI view;
+
+ /*** Constructor ***/
+
+ /**
+ * Constructor.
+ *
+ * @param ui reference to the main UI
+ * @throws PicrossException if the instantiation of the view fails
+ */
+ MenuMediator(PicrossUI ui) throws PicrossException {
+ MenuController controller = new MenuController();
+ controller.addSimpleListener(this);
+
+ this.view = this.initView(ui, controller);
+ }
+
+ /*** Abstract method ***/
+
+ /**
+ * Builds the menu's view.
+ *
+ * @param ui reference to the main UI
+ * @param controller the controller for the menu
+ * @return the menu's view
+ * @throws PicrossException if a problem arises during the building
+ */
+ protected abstract MenuUI initView(PicrossUI ui, MenuController controller)
+ throws PicrossException;
+
+ /*** Method overloaded from the class Mediateur ***/
+
+ /** {@inheritDoc} */
+ public void eventPerformed(SimpleEvent e) {
+ MenuMediator.log.debug("eventPerformed(" + e + ")");
+
+ this.fireEventPerformed(e);
+ }
+
+ /*** Accessor ***/
+
+ /**
+ * Returns the view.
+ *
+ * @return the view
+ */
+ public MenuUI getView() {
+ return this.view;
+ }
+}
+
Property changes on: trunk/src/picross/menus/MenuMediator.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-28 12:33:49
|
Revision: 67
http://picross.svn.sourceforge.net/picross/?rev=67&view=rev
Author: yvan_norsa
Date: 2008-04-28 05:33:55 -0700 (Mon, 28 Apr 2008)
Log Message:
-----------
fixed tests
Modified Paths:
--------------
trunk/src/picross/game/simple/XBMModelTest.java
trunk/src/picross/tests/PicrossTest.java
Modified: trunk/src/picross/game/simple/XBMModelTest.java
===================================================================
--- trunk/src/picross/game/simple/XBMModelTest.java 2008-04-28 09:07:21 UTC (rev 66)
+++ trunk/src/picross/game/simple/XBMModelTest.java 2008-04-28 12:33:55 UTC (rev 67)
@@ -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,
@@ -63,7 +63,7 @@
try {
XBMModelTest.realModel =
- new XBMModel(Picross.loadDataFile("blarg.xbm"));
+ new XBMModel(Picross.loadDataFile("asterix.xbm"));
} catch (IOException ioEx) {
throw new ExceptionInInitializerError(ioEx);
} catch (XBMException xbmEx) {
Modified: trunk/src/picross/tests/PicrossTest.java
===================================================================
--- trunk/src/picross/tests/PicrossTest.java 2008-04-28 09:07:21 UTC (rev 66)
+++ trunk/src/picross/tests/PicrossTest.java 2008-04-28 12:33:55 UTC (rev 67)
@@ -146,7 +146,7 @@
Assert.fail("Fake file");
} catch (FileNotFoundException fileEx) { }
- InputStream in = Picross.loadDataFile("blarg.xbm");
+ InputStream in = Picross.loadDataFile("asterix.xbm");
Assert.assertNotNull("in = null", in);
in.close();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <yva...@us...> - 2008-04-28 13:33:02
|
Revision: 70
http://picross.svn.sourceforge.net/picross/?rev=70&view=rev
Author: yvan_norsa
Date: 2008-04-28 06:30:53 -0700 (Mon, 28 Apr 2008)
Log Message:
-----------
game modes separation
Modified Paths:
--------------
trunk/src/picross/Picross.java
trunk/src/picross/PicrossController.java
trunk/src/picross/PicrossMediator.java
trunk/src/picross/game/random/RandomGameController.java
trunk/src/picross/game/random/RandomGameMediator.java
trunk/src/picross/game/random/RandomGameMode.java
trunk/src/picross/game/simple/LevelMenuController.java
trunk/src/picross/game/simple/LevelMenuMediator.java
trunk/src/picross/game/simple/LevelMenuModel.java
trunk/src/picross/game/simple/LevelMenuUI.java
Modified: trunk/src/picross/Picross.java
===================================================================
--- trunk/src/picross/Picross.java 2008-04-28 13:12:16 UTC (rev 69)
+++ trunk/src/picross/Picross.java 2008-04-28 13:30:53 UTC (rev 70)
@@ -33,11 +33,9 @@
package picross;
-import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.net.URL;
@@ -49,8 +47,8 @@
//import org.apache.log4j.Logger;
-import picross.game.simple.FileInfos;
-import picross.game.simple.LevelInfos;
+//import picross.game.simple.FileInfos;
+//import picross.game.simple.LevelInfos;
/**
* Helper class.
@@ -66,9 +64,6 @@
/** Data directory. */
private static final String DATA_DIR = "/picross/data/";
- /** File containing the data files list. */
- private static final String DATA_LIST = "contents.txt";
-
/** Images directory corresponding to the default locale. */
private static final String LOCAL_IMAGES_PATH = Picross.IMAGES_DIR
+ Locale.getDefault().getLanguage() + "/";
@@ -168,37 +163,5 @@
return Picross.getFile(Picross.DATA_DIR + name).openStream();
}
-
- /**
- * Reads the data files list and returns informations about the levels.
- *
- * @return informations about the available levels
- * @throws IOException if a problem occurs during the operation
- */
- public static List<LevelInfos> listDataFiles() throws IOException {
- List<LevelInfos> list = new ArrayList<LevelInfos>();
-
- BufferedReader in = null;
-
- try {
- in = new
- BufferedReader(new
- InputStreamReader(Picross
- .loadDataFile(Picross
- .DATA_LIST)));
-
- String line = null;
-
- while ((line = in.readLine()) != null) {
- list.add(FileInfos.readFileInfos(line));
- }
- } catch (IOException ioEx) {
- throw ioEx;
- } finally {
- in.close();
- }
-
- return list;
- }
}
Modified: trunk/src/picross/PicrossController.java
===================================================================
--- trunk/src/picross/PicrossController.java 2008-04-28 13:12:16 UTC (rev 69)
+++ trunk/src/picross/PicrossController.java 2008-04-28 13:30:53 UTC (rev 70)
@@ -50,14 +50,14 @@
public static final String PLAY_CMD = "PLAY_CMD";
/** Random game command. */
- public static final String RANDOM_GAME_CMD = "RANDOM_GAME_CMD";
+ //public static final String RANDOM_GAME_CMD = "RANDOM_GAME_CMD";
- public static final String NEXT_RANDOM_GAME_CMD = "NEXT_RANDOM_GAME_CMD";
+ //public static final String NEXT_RANDOM_GAME_CMD = "NEXT_RANDOM_GAME_CMD";
/** Select level command. */
- public static final String SELECT_LEVEL_CMD = "SELECT_LEVEL_CMD";
+ //public static final String SELECT_LEVEL_CMD = "SELECT_LEVEL_CMD";
- public static final String LEVEL_CMD = "LEVEL_CMD";
+ //public static final String LEVEL_CMD = "LEVEL_CMD";
/** Exit command. */
public static final String EXIT_CMD = "EXIT_CMD";
Modified: trunk/src/picross/PicrossMediator.java
===================================================================
--- trunk/src/picross/PicrossMediator.java 2008-04-28 13:12:16 UTC (rev 69)
+++ trunk/src/picross/PicrossMediator.java 2008-04-28 13:30:53 UTC (rev 70)
@@ -47,7 +47,7 @@
import picross.game.GameCommand;
import picross.game.GameMediator;
-import picross.game.random.RandomGameMediator;
+//import picross.game.random.RandomGameMediator;
//import picross.game.simple.SimpleGameMediator;
@@ -76,6 +76,8 @@
/** Main view. */
private PicrossUI view;
+ private boolean firstTime = true;
+
/*** Constructor ***/
/** Constructor. */
@@ -116,11 +118,12 @@
}
*/
- // FIXME doesn't belong here
+ /*
if (cmd.equals(PicrossController.NEXT_RANDOM_GAME_CMD)) {
this.startRandomGame();
return;
}
+ */
/*
if (cmd.equals(PicrossController.SELECT_LEVEL_CMD)) {
@@ -145,7 +148,10 @@
}
if (cmd.equals(GameCommand.GAME_CMD)) {
- this.displayWaitScreen();
+ if (this.firstTime) {
+ this.displayWaitScreen();
+ this.firstTime = false;
+ }
GameCommand command = (GameCommand) e.getCommand();
this.startGame(command.getGame());
@@ -244,7 +250,8 @@
worker.start();
}
- /** Starts a random game. */
+ /** Starts a random game. *
+ /*
private void startRandomGame() {
Thread worker = new Thread() {
public void run() {
@@ -264,7 +271,7 @@
worker.start();
}
-
+ */
/** Starts a new game. */
/*
private void startGame(final String level) {
Modified: trunk/src/picross/game/random/RandomGameController.java
===================================================================
--- trunk/src/picross/game/random/RandomGameController.java 2008-04-28 13:12:16 UTC (rev 69)
+++ trunk/src/picross/game/random/RandomGameController.java 2008-04-28 13:30:53 UTC (rev 70)
@@ -52,6 +52,11 @@
/** Command asking to create another grid. */
static final String NEXT_CMD = "NEXT_CMD";
+ /** Random game command. */
+ /*public */static final String RANDOM_GAME_CMD = "RANDOM_GAME_CMD";
+
+ //public static final String NEXT_RANDOM_GAME_CMD = "NEXT_RANDOM_GAME_CMD";
+
/*** Static field ***/
/** The class' logger. */
Modified: trunk/src/picross/game/random/RandomGameMediator.java
===================================================================
--- trunk/src/picross/game/random/RandomGameMediator.java 2008-04-28 13:12:16 UTC (rev 69)
+++ trunk/src/picross/game/random/RandomGameMediator.java 2008-04-28 13:30:53 UTC (rev 70)
@@ -65,11 +65,12 @@
* @throws PicrossException if there is a problem loading the grid model
* or building the view
*/
+ /*
public RandomGameMediator() {//throws PicrossException {
//super();
//this.init();
}
-
+ */
/*** Methods overloaded from the class GameMediator ***/
/** {@inheritDoc} */
@@ -93,7 +94,9 @@
String cmd = e.getCommandName();
if (cmd.equals(RandomGameController.NEXT_CMD)) {
- this.fireEventPerformed(PicrossController.NEXT_RANDOM_GAME_CMD);
+ //this.fireEventPerformed(RandomGameController.NEXT_RANDOM_GAME_CMD);
+ this.fireEventPerformed(RandomGameMode.getRandomGameCommand());
+
return;
}
Modified: trunk/src/picross/game/random/RandomGameMode.java
===================================================================
--- trunk/src/picross/game/random/RandomGameMode.java 2008-04-28 13:12:16 UTC (rev 69)
+++ trunk/src/picross/game/random/RandomGameMode.java 2008-04-28 13:30:53 UTC (rev 70)
@@ -42,6 +42,7 @@
import picross.Picross;
+import picross.game.GameCommand;
import picross.game.GameMode;
import picross.menus.PicrossButton;
@@ -76,9 +77,13 @@
*/
/*** M\xE9thode ***/
+ public static GameCommand getRandomGameCommand() {
+ return new GameCommand(new RandomGameMediator());
+ }
+
public SimpleButton<JButton> getButton() {
ImageIcon icon = Picross.getLocalizedImage(RandomGameMode.RANDOM_BUTTON_IMAGE);
- SimpleEvent event = new SimpleEvent(new picross.game.GameCommand(new RandomGameMediator()));
+ SimpleEvent event = new SimpleEvent(RandomGameMode.getRandomGameCommand());
/*PicrossButton button = */return new PicrossButton(icon, event);
//button.getButton().setIcon(icon);
Modified: trunk/src/picross/game/simple/LevelMenuController.java
===================================================================
--- trunk/src/picross/game/simple/LevelMenuController.java 2008-04-28 13:12:16 UTC (rev 69)
+++ trunk/src/picross/game/simple/LevelMenuController.java 2008-04-28 13:30:53 UTC (rev 70)
@@ -49,6 +49,11 @@
static final String LEVELS_LIST_CMD = "LEVELS_LIST_CMD";
+ /** Select level command. */
+ //static final String SELECT_LEVEL_CMD = "SELECT_LEVEL_CMD";
+
+ static final String LEVEL_CMD = "LEVEL_CMD";
+
/*** Champ statique ***/
private static Logger log = Logger.getLogger(LevelMenuController.class);
Modified: trunk/src/picross/game/simple/LevelMenuMediator.java
===================================================================
--- trunk/src/picross/game/simple/LevelMenuMediator.java 2008-04-28 13:12:16 UTC (rev 69)
+++ trunk/src/picross/game/simple/LevelMenuMediator.java 2008-04-28 13:30:53 UTC (rev 70)
@@ -109,7 +109,7 @@
return;
}
- if (cmd.equals(picross.PicrossController.LEVEL_CMD)) {
+ if (cmd.equals(LevelMenuController.LEVEL_CMD)) {
this.fireEventPerformed(new picross.game.GameCommand(new picross.game.simple.SimpleGameMediator(e.getComment())));
return;
}
Modified: trunk/src/picross/game/simple/LevelMenuModel.java
===================================================================
--- trunk/src/picross/game/simple/LevelMenuModel.java 2008-04-28 13:12:16 UTC (rev 69)
+++ trunk/src/picross/game/simple/LevelMenuModel.java 2008-04-28 13:30:53 UTC (rev 70)
@@ -35,7 +35,9 @@
import java.awt.Dimension;
+import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
@@ -53,6 +55,11 @@
* @author Y. Norsa
*/
class LevelMenuModel {
+ /*** Constant ***/
+
+ /** File containing the data files list. */
+ private static final String DATA_LIST = "contents.txt";
+
/*** Field ***/
/** Level list. */
@@ -74,7 +81,8 @@
try {
//this.levels = Picross.listDataFiles();
- infos = Picross.listDataFiles();
+ //infos = Picross.listDataFiles();
+ infos = LevelMenuModel.listDataFiles();
} catch (IOException ioEx) {
throw new PicrossException(ioEx);
}
@@ -92,6 +100,40 @@
}
}
+ /*** Static method ***/
+
+ /**
+ * Reads the data files list and returns informations about the levels.
+ *
+ * @return informations about the available levels
+ * @throws IOException if a problem occurs during the operation
+ */
+ public static List<LevelInfos> listDataFiles() throws IOException {
+ List<LevelInfos> list = new ArrayList<LevelInfos>();
+
+ BufferedReader in = null;
+
+ try {
+ in = new
+ BufferedReader(new
+ InputStreamReader(Picross
+ .loadDataFile(LevelMenuModel
+ .DATA_LIST)));
+
+ String line = null;
+
+ while ((line = in.readLine()) != null) {
+ list.add(FileInfos.readFileInfos(line));
+ }
+ } catch (IOException ioEx) {
+ throw ioEx;
+ } finally {
+ in.close();
+ }
+
+ return list;
+ }
+
/*** Method ***/
/**
Modified: trunk/src/picross/game/simple/LevelMenuUI.java
===================================================================
--- trunk/src/picross/game/simple/LevelMenuUI.java 2008-04-28 13:12:16 UTC (rev 69)
+++ trunk/src/picross/game/simple/LevelMenuUI.java 2008-04-28 13:30:53 UTC (rev 70)
@@ -97,7 +97,7 @@
int y = 150;
for (String level : levels) {
- SimpleEvent event = new SimpleEvent(PicrossController.LEVEL_CMD, level);
+ SimpleEvent event = new SimpleEvent(LevelMenuController.LEVEL_CMD, level);
this.addSimpleButton(level, event, listener, x, y);
y += 75;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|