[Picross-commit] SF.net SVN: picross: [38] trunk/src/picross
Status: Pre-Alpha
Brought to you by:
yvan_norsa
|
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, this.colData[j][i], x, y,
- this.completedCols[j][i]);
+ this.completedHints.isColHintComplete(j, i));
}
x += GridUI.BOX_WIDTH;
@@ -453,6 +527,11 @@
* @param g the graphics context
*/
private void drawLeftHints(Graphics g) {
+ g.drawImage(this.leftHintsBoxes,
+ this.leftHintsRect.x, this.leftHintsRect.y, null);
+
+ g.setFont(GridUI.HINT_FONT);
+
int y = this.leftHintsY;
for (int i = 0; i < this.rowData.length; i++) {
@@ -461,7 +540,7 @@
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.completedRows[i][j]);
+ this.completedHints.isRowHintComplete(i, j));
}
x += this.leftHintsDecal;
@@ -481,16 +560,12 @@
*/
private void drawHint(Graphics g, int value, int x, int y,
boolean complete) {
- this.hintBoxIcon.paintIcon(this, g, x, y);
-
if (complete) {
g.setColor(GridUI.COMPLETED_HINT_COLOR);
} else {
g.setColor(GridUI.HINT_TEXT_COLOR);
}
- g.setFont(GridUI.HINT_FONT);
-
y += this.centerHintHeight;
if (value < 10) {
@@ -587,52 +662,13 @@
}
}
- /**
- * 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;
- }
-
+ /** Repaints top hints. */
+ void repaintColHints() {
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;
- }
-
+ /** Repaints left hints. */
+ void repaintRowHints() {
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.
|