[Picross-commit] SF.net SVN: picross: [23] trunk/src/picross/grid/GridUI.java
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2007-06-07 19:05:51
|
Revision: 23 http://picross.svn.sourceforge.net/picross/?rev=23&view=rev Author: yvan_norsa Date: 2007-06-07 12:05:53 -0700 (Thu, 07 Jun 2007) Log Message: ----------- code cleanup Modified Paths: -------------- trunk/src/picross/grid/GridUI.java Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-07 14:57:23 UTC (rev 22) +++ trunk/src/picross/grid/GridUI.java 2007-06-07 19:05:53 UTC (rev 23) @@ -62,8 +62,11 @@ private static final long serialVersionUID = 2050855523399115878L; /** Space left before the top hints. */ - private static final int TOP_HINTS = 10 + 3; + private static final int TOP_HINTS = 13; + /** Space left after the left hints. */ + private static final int LEFT_HINTS = 10; + /** Width occupied by a row hint. */ private static final int ROW_HINT_WIDTH = 10; @@ -76,11 +79,18 @@ /** Height occupied by a column hint. */ private static final int COL_HINT_HEIGHT = 12; - private static final Color HINT_FORE_COLOR = new Color(188, 211, 227); + /** Outline color for the hints boxes. */ + private static final Color HINT_OUTLINE_COLOR = new Color(188, 211, 227); + + /** Background color for the hints boxes. */ private static final Color HINT_FILL_COLOR = new Color(131, 155, 200); + + /** Color of the hints text. */ private static final Color HINT_TEXT_COLOR = new Color(233, 246, 255); - private static final Font HINT_FONT = new Font("Sans Serif", Font.BOLD, 10); + /** Font used for the hints. */ + private static final Font HINT_FONT = + new Font("Sans Serif", Font.BOLD, 10); /** A box width. */ private static final int BOX_WIDTH = 25; @@ -94,6 +104,12 @@ /** Extra space at the bottom of the grid. */ private static final int BOTTOM_SPACE = 5; + /** Text used to compute the hints boxes size. */ + private static final String SAMPLE_HINT = "42"; + + /** Diameter of the arc for hint boxes. */ + private static final int ROUND_DIAMETER = 8; + /*** Static field ***/ /** Class' logger. */ @@ -140,7 +156,8 @@ /** Controller attached to this view. */ private transient GridController controller; - int hintBoxSize; + /** Size of the hints boxes. */ + private int hintBoxSize; /*** Constructor ***/ @@ -173,54 +190,33 @@ this.colData = colData; this.rowData = rowData; - /**/ + // Computes the size of a hint box + FontRenderContext frc = new FontRenderContext(null, true, true); + Rectangle2D textBounds = + GridUI.HINT_FONT.getStringBounds(GridUI.SAMPLE_HINT, frc); - //FontRenderContext frc = g2d.getFontRenderContext(); - FontRenderContext frc = new FontRenderContext(null, true, - true); - Rectangle2D textBounds = - GridUI.HINT_FONT - .getStringBounds("42", frc); + double textWidth = textBounds.getWidth(); + double textHeight = textBounds.getHeight(); - double textWidth = textBounds.getWidth(); - double textHeight = textBounds.getHeight(); + this.hintBoxSize = ((int) (textWidth > textHeight + ? textWidth : textHeight)) + 2; - this.hintBoxSize = (int) (textWidth > textHeight - ? textWidth : textHeight); - //this.bigHintBoxSize = this.hintBoxSize + 3; - this.hintBoxSize += 2; + // Now computes the grid boundaries - /**/ + this.leftBoundary = GridUI.LEFT_HINTS + + (this.rowData[0].length * this.hintBoxSize); - - - /* - this.leftBoundary = - this.rowData[0].length * GridUI.ROW_HINT_WIDTH; - */ - - for (int i = 0; i < this.rowData[0].length; i++) { - int size = (this.rowData[0][i] / 10) + 1; - //this.leftBoundary += size * GridUI.ROW_HINT_WIDTH; - this.leftBoundary += size * this.hintBoxSize; - } - - //this.leftBoundary = 70; - - this.leftBoundary += 10; - this.rightBoundary = this.leftBoundary + (this.width * GridUI.BOX_WIDTH); this.topBoundary = GridUI.TOP_HINTS - //+ (this.colData[0].length * GridUI.COL_HINT_HEIGHT); + (this.colData[0].length * this.hintBoxSize); - //this.topBoundary = 70; - this.bottomBoundary = this.topBoundary + (this.height * GridUI.BOX_HEIGHT); + // Space occupied by the hints + this.topHintsRect = new Rectangle(this.leftBoundary, 0, this.width * GridUI.BOX_WIDTH, this.topBoundary); @@ -280,7 +276,10 @@ for (int j = 0; j < this.colData.length; j++) { if (this.colData[j][i] != GridModel.EMPTY_HINT) { - int hintX = x + (((x + GridUI.COL_HINT_WIDTH) - x) / 2); + // Center the hint + int hintX = x + + (((x + GridUI.COL_HINT_WIDTH) - x) / 2); + this.drawColHint(g2d, this.colData[j][i], hintX, y); } @@ -343,66 +342,85 @@ /*** Methods ***/ - private void drawColHint(Graphics2D g2d, int value, int hintX, int y) { - g2d.setColor(GridUI.HINT_FILL_COLOR); + /** + * Draws a column hint. + * + * @param g2d the graphic context + * @param value hint value + * @param x X coordinate + * @param y Y coordinate + */ + private void drawColHint(Graphics2D g2d, int value, int x, int y) { + this.drawHintBox(g2d, x, y, GridUI.COL_HINT_HEIGHT); + this.setHintPen(g2d); - g2d.fillRoundRect(hintX, - y - GridUI.COL_HINT_HEIGHT, - this.hintBoxSize, - this.hintBoxSize, - 8, 8); - - g2d.setColor(GridUI.HINT_FORE_COLOR); - - g2d.drawRoundRect(hintX, - y - GridUI.COL_HINT_HEIGHT, - this.hintBoxSize, - this.hintBoxSize, - 8, 8); - - g2d.setColor(GridUI.HINT_TEXT_COLOR); - g2d.setFont(GridUI.HINT_FONT); - if (value < 10) { + // Tries to center the hint text g2d.drawString(String.valueOf(value), - hintX + (this.hintBoxSize / 3), + x + (this.hintBoxSize / 3), y); } else { g2d.drawString(String.valueOf(value), - hintX, + x, y); } } - private void drawRowHint(Graphics2D g2d, int value, int hintX, int y) { + /** + * Draws a row hint. + * + * @param g2d the graphic context + * @param value hint value + * @param x X coordinate + * @param y Y coordinate + */ + private void drawRowHint(Graphics2D g2d, int value, int x, int y) { + this.drawHintBox(g2d, x, y, GridUI.ROW_HINT_HEIGHT); + this.setHintPen(g2d); + + if (value < 10) { + g2d.drawString(String.valueOf(value), + x + (this.hintBoxSize / 3) - 1, + y - 3); + } else { + g2d.drawString(String.valueOf(value), + x + 1, + y - 3); + } + } + + /** + * Draws a hint box. + * + * @param g2d the graphic context + * @param x X coordinate + * @param y Y coordinate + * @param hintHeight the hint height + */ + private void drawHintBox(Graphics2D g2d, int x, int y, int hintHeight) { g2d.setColor(GridUI.HINT_FILL_COLOR); - - g2d.fillRoundRect(hintX, - y - GridUI.ROW_HINT_HEIGHT, + g2d.fillRoundRect(x, + y - hintHeight, this.hintBoxSize, this.hintBoxSize, - 8, 8); - - g2d.setColor(GridUI.HINT_FORE_COLOR); + GridUI.ROUND_DIAMETER, GridUI.ROUND_DIAMETER); - g2d.drawRoundRect(hintX, - y - GridUI.ROW_HINT_HEIGHT, + g2d.setColor(GridUI.HINT_OUTLINE_COLOR); + g2d.drawRoundRect(x, + y - hintHeight, this.hintBoxSize, this.hintBoxSize, - 8, 8); + GridUI.ROUND_DIAMETER, GridUI.ROUND_DIAMETER); + } + /** + * Sets the hint color and font. + * + * @param g2d the graphic context + */ + private void setHintPen(Graphics2D g2d) { g2d.setColor(GridUI.HINT_TEXT_COLOR); g2d.setFont(GridUI.HINT_FONT); - - if (value < 10) { - g2d.drawString(String.valueOf(value), - hintX + (this.hintBoxSize / 3) - 1, - y - 3); - } else { - g2d.drawString(String.valueOf(value), - hintX + 1, - y - 3); - } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |