[Picross-commit] SF.net SVN: picross: [6] trunk/src/picross
Status: Pre-Alpha
Brought to you by:
yvan_norsa
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. |