[Picross-commit] SF.net SVN: picross: [9] trunk/src/picross/grid
Status: Pre-Alpha
Brought to you by:
yvan_norsa
|
From: <yva...@us...> - 2007-06-05 14:44:54
|
Revision: 9
http://picross.svn.sourceforge.net/picross/?rev=9&view=rev
Author: yvan_norsa
Date: 2007-06-05 07:44:56 -0700 (Tue, 05 Jun 2007)
Log Message:
-----------
disable the grid at the end; allows to uncheck boxes
Modified Paths:
--------------
trunk/src/picross/grid/PicrossGridController.java
trunk/src/picross/grid/PicrossGridMediator.java
trunk/src/picross/grid/PicrossGridModel.java
trunk/src/picross/grid/PicrossGridUI.java
Modified: trunk/src/picross/grid/PicrossGridController.java
===================================================================
--- trunk/src/picross/grid/PicrossGridController.java 2007-06-05 11:32:56 UTC (rev 8)
+++ trunk/src/picross/grid/PicrossGridController.java 2007-06-05 14:44:56 UTC (rev 9)
@@ -60,6 +60,11 @@
/** Command indicating the grid is filled. */
public static final String GRID_FILLED_CMD = "GRID_FILLED_CMD";
+ static final String END_ACTION_CMD = "END_ACTION_CMD";
+
+ static final String CHECK_CMD = "CHECK_CMD";
+ static final String UNCHECK_CMD = "UNCHECK_CMD";
+
/*** Static field ***/
/** The class' logger. */
@@ -75,6 +80,27 @@
/** {@inheritDoc} */
public void eventPerformed(SimpleEvent e) {
PicrossGridController.log.debug("eventPerformed(" + e + ")");
+
+ String cmd = e.getCommandName();
+
+ if (cmd.equals(PicrossGridController.GRID_FILLED_CMD)) {
+ this.view.disableGrid();
+ return;
+ }
+
+ if (cmd.equals(PicrossGridController.CHECK_CMD)) {
+ FillCommand command = (FillCommand) e.getCommand();
+ this.view.check(command.getRow(), command.getColumn());
+
+ return;
+ }
+
+ if (cmd.equals(PicrossGridController.UNCHECK_CMD)) {
+ FillCommand command = (FillCommand) e.getCommand();
+ this.view.uncheck(command.getRow(), command.getColumn());
+
+ return;
+ }
}
/*** Methods implanted from the interface MouseListener ***/
@@ -94,7 +120,10 @@
public void mousePressed(MouseEvent e) { }
/** {@inheritDoc} */
- public void mouseReleased(MouseEvent e) { }
+ public void mouseReleased(MouseEvent e) {
+ PicrossGridController.log.debug("mouseReleased()");
+ this.fireEventPerformed(PicrossGridController.END_ACTION_CMD);
+ }
/*** Methods implanted from the interface MouseMotionListener ***/
@@ -115,16 +144,20 @@
* @param e mouse event to handle
*/
private void checkAndFill(MouseEvent e) {
+ //PicrossGridController.log.debug(e);
+
+ if (e.getModifiers() != MouseEvent.BUTTON1_MASK) {
+ return;
+ }
+
Point point = e.getPoint();
if (this.view.isInGrid(point)) {
int row = this.view.getRow(point);
int column = this.view.getColumn(point);
-
+
this.fireEventPerformed(PicrossGridController.FILL_CMD,
new FillCommand(row, column));
-
- this.view.fillBox(row, column);
}
}
Modified: trunk/src/picross/grid/PicrossGridMediator.java
===================================================================
--- trunk/src/picross/grid/PicrossGridMediator.java 2007-06-05 11:32:56 UTC (rev 8)
+++ trunk/src/picross/grid/PicrossGridMediator.java 2007-06-05 14:44:56 UTC (rev 9)
@@ -38,7 +38,7 @@
import javax.swing.JPanel;
-import org.apache.log4j.Logger;
+//import org.apache.log4j.Logger;
/**
* Picross grid mediator.
@@ -49,7 +49,7 @@
/*** Static field ***/
/** Class' logger. */
- private static Logger log = Logger.getLogger(PicrossGridMediator.class);
+ //private static Logger log = Logger.getLogger(PicrossGridMediator.class);
/*** Fields ***/
@@ -73,6 +73,7 @@
PicrossGridController controller = new PicrossGridController();
controller.addSimpleListener(this);
+ this.addSimpleListener(controller);
this.view = new PicrossGridUI(width, height,
this.model.getColData(),
@@ -86,15 +87,21 @@
/** {@inheritDoc} */
public void eventPerformed(SimpleEvent e) {
- PicrossGridMediator.log.debug("eventPerformed(" + e + ")");
+ //PicrossGridMediator.log.debug("eventPerformed(" + e + ")");
String cmd = e.getCommandName();
if (cmd.equals(PicrossGridController.FILL_CMD)) {
FillCommand command = (FillCommand) e.getCommand();
+ this.model.checkBox(command.getRow(), command.getColumn());
- this.model.checkBox(command.getRow(), command.getColumn());
+ return;
}
+
+ if (cmd.equals(PicrossGridController.END_ACTION_CMD)) {
+ this.model.endAction();
+ return;
+ }
}
/*** Method ***/
@@ -104,6 +111,16 @@
this.fireEventPerformed(PicrossGridController.GRID_FILLED_CMD);
}
+ void check(int row, int column) {
+ this.fireEventPerformed(PicrossGridController.CHECK_CMD,
+ new FillCommand(row, column));
+ }
+
+ void uncheck(int row, int column) {
+ this.fireEventPerformed(PicrossGridController.UNCHECK_CMD,
+ new FillCommand(row, column));
+ }
+
/*** Accessor ***/
/**
Modified: trunk/src/picross/grid/PicrossGridModel.java
===================================================================
--- trunk/src/picross/grid/PicrossGridModel.java 2007-06-05 11:32:56 UTC (rev 8)
+++ trunk/src/picross/grid/PicrossGridModel.java 2007-06-05 14:44:56 UTC (rev 9)
@@ -58,7 +58,7 @@
private boolean[][] data;
/** The grid as filled by the user. */
- private boolean[][] checked;
+ private Boolean[][] checked;
/** Columns hints. */
private int[][] colData;
@@ -66,6 +66,8 @@
/** Rows hints. */
private int[][] rowData;
+ private Boolean lastChecked = null;
+
/*** Constructor ***/
/**
@@ -78,14 +80,18 @@
this.mediator = mediator;
this.data = data;
- this.checked = new boolean[this.data.length][this.data[0].length];
+ this.checked = new Boolean[this.data.length][this.data[0].length];
+ for (int i = 0; i < this.checked.length; i++) {
+ for (int j = 0; j < this.checked[i].length; j++) {
+ this.checked[i][j] = Boolean.valueOf(false);
+ }
+ }
+
List<List<Integer>> colRawData = new ArrayList<List<Integer>>();
int max = 0;
for (boolean[] col : data) {
- //PicrossGridModel.log.debug("col.length : " + col.length);
-
List<Integer> current = new ArrayList<Integer>();
int chain = 0;
@@ -105,8 +111,6 @@
current.add(0);
}
- //PicrossGridModel.log.debug("current : " + current);
-
int currentSize = current.size();
if (currentSize > max) {
@@ -116,53 +120,20 @@
colRawData.add(current);
}
- //PicrossGridModel.log.debug("data.length : " + data.length);
- //PicrossGridModel.log.debug("max : " + max);
-
this.colData = new int[data.length][max];
for (int i = 0; i < max; i++) {
- //PicrossGridModel.log.debug("i = " + i);
-
for (int j = 0; j < colRawData.size(); j++) {
- //PicrossGridModel.log.debug("colonne courante.size() : "
- //+ colRawData.get(j).size());
-
if (colRawData.get(j).size() >= (max - i)) {
- //PicrossGridModel.log.debug("this.colData[" + j + "]["
- //+ (max - 1 - i) + "] = " + "colData.get(" + j + ").get("
- //+ (colRawData.get(j).size() - max + i) + ") = "
- //+ colRawData.get(j).get(colRawData.get(j).size()
- //- max + i));
-
this.colData[j][max - 1 - i]
= colRawData.get(j).get(colRawData.get(j).size()
- max + i);
} else {
- //PicrossGridModel.log.debug("this.colData[" + j + "]["
- //+ (max - 1 - i) + "] = -1");
-
this.colData[j][max - 1 - i] = -1;
}
}
}
- /*
- System.out.println("this.colData : ");
-
- for (int i = this.colData[0].length - 1; i >= 0; i--) {
- for (int j = 0; j < this.colData.length; j++) {
- if (this.colData[j][i] == -1) {
- System.out.print(" ");
- } else {
- System.out.print(this.colData[j][i]);
- }
- }
-
- System.out.println("");
- }
- */
- /***/
List<List<Integer>> rowRawData = new ArrayList<List<Integer>>();
max = 0;
@@ -192,58 +163,21 @@
max = currentSize;
}
- //PicrossGridModel.log.debug("current : " + current);
rowRawData.add(current);
}
- /**/
-
- //PicrossGridModel.log.debug("data.length : " + data[0].length);
- //PicrossGridModel.log.debug("max : " + max);
-
this.rowData = new int[data[0].length][max];
for (int i = 0; i < max; i++) {
- //PicrossGridModel.log.debug("i = " + i);
-
for (int j = 0; j < rowRawData.size(); j++) {
- //PicrossGridModel.log.debug("j = " + j);
- //PicrossGridModel.log.debug("ligne courante.size() : "
- //+ rowRawData.get(j).size());
-
if (rowRawData.get(j).size() >= (max - i)) {
- //int index = max - 1 - i;
int index = i - Math.abs(rowRawData.get(j).size() - max);
-
- //System.out.print("this.rowData[" + j + "][" + i + "] = "
- //+ "rowRawData.get(" + j + ").get(" + index + ") = ");
- //System.out.println(rowRawData.get(j).get(index));
-
this.rowData[j][i] = rowRawData.get(j).get(index);
} else {
- //PicrossGridModel.log.debug("this.rowData[" + j + "]["
- //+ i + "] = -1");
-
this.rowData[j][i] = -1;
}
}
}
-
- /*
- System.out.println("this.rowData : ");
-
- for (int i = 0; i < this.rowData.length; i++) {
- for (int j = 0; j < this.rowData[i].length; j++) {
- if (this.rowData[i][j] == -1) {
- System.out.print(" ");
- } else {
- System.out.print(this.rowData[i][j]);
- }
- }
-
- System.out.println("");
- }
- */
}
/*** Method ***/
@@ -255,22 +189,42 @@
* @param column column of the box
*/
void checkBox(int row, int column) {
- this.checked[row][column] = true;
+ if (this.lastChecked == null ||
+ !this.lastChecked.equals(this.checked[row][column])) {
- boolean completed = true;
+ if (!this.checked[row][column]) {
+ //PicrossGridModel.log.debug("checking " + row + "," + column);
- for (int i = 0; i < this.data.length; i++) {
- for (int j = 0; j < this.data[i].length; j++) {
- if (this.data[i][j] != this.checked[i][j]) {
- completed = false;
- break;
+ this.checked[row][column] = true;
+ this.lastChecked = this.checked[row][column];
+
+ this.mediator.check(row, column);
+
+ boolean completed = true;
+
+ for (int i = 0; i < this.data.length; i++) {
+ for (int j = 0; j < this.data[i].length; j++) {
+ if (this.data[i][j] != this.checked[i][j]) {
+ completed = false;
+ break;
+ }
+ }
}
+
+ if (completed) {
+ this.mediator.congratulations();
+ }
+ } else {
+ this.checked[row][column] = false;
+ this.lastChecked = this.checked[row][column];
+
+ this.mediator.uncheck(row, column);
}
}
+ }
- if (completed) {
- this.mediator.congratulations();
- }
+ void endAction() {
+ this.lastChecked = null;
}
/*** Accessors ***/
Modified: trunk/src/picross/grid/PicrossGridUI.java
===================================================================
--- trunk/src/picross/grid/PicrossGridUI.java 2007-06-05 11:32:56 UTC (rev 8)
+++ trunk/src/picross/grid/PicrossGridUI.java 2007-06-05 14:44:56 UTC (rev 9)
@@ -114,6 +114,8 @@
/** Filled boxes. */
private boolean[][] filled;
+ private transient PicrossGridController controller;
+
/*** Constructor ***/
/**
@@ -131,9 +133,11 @@
PicrossGridController controller) {
super();
- this.addMouseListener(controller);
- this.addMouseMotionListener(controller);
+ this.controller = controller;
+ this.addMouseListener(this.controller);
+ this.addMouseMotionListener(this.controller);
+
this.setOpaque(true);
this.setBackground(Color.WHITE);
@@ -214,13 +218,20 @@
for (int j = 0; j < this.width; j++) {
if (this.filled[i][j]) {
+ g.setColor(Color.BLACK);
g.fillRect(x, y,
PicrossGridUI.BOX_WIDTH,
PicrossGridUI.BOX_HEIGHT);
} else {
+ g.setColor(Color.BLACK);
g.drawRect(x, y,
- PicrossGridUI.BOX_WIDTH,
- PicrossGridUI.BOX_HEIGHT);
+ PicrossGridUI.BOX_WIDTH,
+ PicrossGridUI.BOX_HEIGHT);
+
+ g.setColor(Color.WHITE);
+ g.fillRect(x + 1, y + 1,
+ PicrossGridUI.BOX_WIDTH - 1,
+ PicrossGridUI.BOX_HEIGHT - 1);
}
x += PicrossGridUI.BOX_WIDTH;
@@ -272,16 +283,20 @@
return (int) (x / PicrossGridUI.BOX_WIDTH);
}
+
+ void disableGrid() {
+ this.removeMouseListener(this.controller);
+ this.removeMouseMotionListener(this.controller);
+ }
- /**
- * Fills a box in the grid.
- *
- * @param row row of the box
- * @param column column of the box
- */
- void fillBox(int row, int column) {
+ void check(int row, int column) {
this.filled[row][column] = true;
this.repaint();
}
+
+ void uncheck(int row, int column) {
+ this.filled[row][column] = false;
+ this.repaint();
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|