[Picross-commit] SF.net SVN: picross: [7] trunk/src/picross/grid
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2007-06-05 08:52:11
|
Revision: 7 http://picross.svn.sourceforge.net/picross/?rev=7&view=rev Author: yvan_norsa Date: 2007-06-05 01:52:12 -0700 (Tue, 05 Jun 2007) Log Message: ----------- handles mouse drags Modified Paths: -------------- trunk/src/picross/grid/PicrossGridController.java trunk/src/picross/grid/PicrossGridUI.java Modified: trunk/src/picross/grid/PicrossGridController.java =================================================================== --- trunk/src/picross/grid/PicrossGridController.java 2007-06-05 08:35:50 UTC (rev 6) +++ trunk/src/picross/grid/PicrossGridController.java 2007-06-05 08:52:12 UTC (rev 7) @@ -40,6 +40,7 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; import org.apache.log4j.Logger; @@ -48,7 +49,8 @@ * * @author Y. Norsa */ -class PicrossGridController extends Controller implements MouseListener { +class PicrossGridController extends Controller implements MouseListener, + MouseMotionListener { /*** Constant ***/ /** Fill command. */ @@ -75,17 +77,7 @@ /** {@inheritDoc} */ public void mouseClicked(MouseEvent e) { - Point point = e.getPoint(); - - if (this.view.isInGrid(point)) { - int row = this.view.getRow(point); - int column = this.view.getColumn(point); - - this.fireEventPerformed(PicrossGridController.FILL_CMD, - new FillCommand(row, column)); - - this.view.fillBox(row, column); - } + this.checkAndFill(e); } /** {@inheritDoc} */ @@ -100,6 +92,38 @@ /** {@inheritDoc} */ public void mouseReleased(MouseEvent e) { } + /*** Methods implanted from the interface MouseMotionListener ***/ + + /** {@inheritDoc} */ + public void mouseDragged(MouseEvent e) { + this.checkAndFill(e); + } + + /** {@inheritDoc} */ + public void mouseMoved(MouseEvent e) { } + + /*** Method ***/ + + /** + * Checks if the mouse current click's location is inside the grid + * and eventually fills the corresponding box. + * + * @param e mouse event to handle + */ + private void checkAndFill(MouseEvent e) { + Point point = e.getPoint(); + + if (this.view.isInGrid(point)) { + int row = this.view.getRow(point); + int column = this.view.getColumn(point); + + this.fireEventPerformed(PicrossGridController.FILL_CMD, + new FillCommand(row, column)); + + this.view.fillBox(row, column); + } + } + /*** Accessor ***/ /** Modified: trunk/src/picross/grid/PicrossGridUI.java =================================================================== --- trunk/src/picross/grid/PicrossGridUI.java 2007-06-05 08:35:50 UTC (rev 6) +++ trunk/src/picross/grid/PicrossGridUI.java 2007-06-05 08:52:12 UTC (rev 7) @@ -38,8 +38,6 @@ import java.awt.Graphics; import java.awt.Point; -import java.awt.event.MouseListener; - import javax.swing.JPanel; import org.apache.log4j.Logger; @@ -125,14 +123,16 @@ * @param height grid height * @param colData columns hints * @param rowData rows hints + * @param controller controller for the grid */ PicrossGridUI(int width, int height, int[][] colData, int[][] rowData, - MouseListener controller) { + PicrossGridController controller) { super(); this.addMouseListener(controller); + this.addMouseMotionListener(controller); this.setOpaque(true); this.setBackground(Color.WHITE); @@ -157,6 +157,9 @@ this.bottomBoundary = this.topBoundary + (this.height * PicrossGridUI.BOX_HEIGHT); + PicrossGridUI.log.debug("rightBoundary : " + this.rightBoundary); + PicrossGridUI.log.debug("bottomBoundary : " + this.bottomBoundary); + this.setPreferredSize(new Dimension(this.rightBoundary + PicrossGridUI.RIGHT_SPACE, this.bottomBoundary @@ -236,11 +239,13 @@ * @return boolean telling if the point is inside the grid */ boolean isInGrid(Point point) { + //PicrossGridUI.log.debug("isInGrid(" + point + ")"); + double x = point.getX(); double y = point.getY(); - return (x >= this.leftBoundary && x <= this.rightBoundary - && y >= this.topBoundary && y <= this.bottomBoundary); + return (x >= this.leftBoundary && x < this.rightBoundary + && y >= this.topBoundary && y < this.bottomBoundary); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |