[Picross-commit] SF.net SVN: picross: [47] trunk/src/picross/grid
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2008-04-17 08:50:17
|
Revision: 47 http://picross.svn.sourceforge.net/picross/?rev=47&view=rev Author: yvan_norsa Date: 2008-04-17 01:50:24 -0700 (Thu, 17 Apr 2008) Log Message: ----------- EDT stuff Modified Paths: -------------- trunk/src/picross/grid/GridMediator.java trunk/src/picross/grid/GridUI.java Modified: trunk/src/picross/grid/GridMediator.java =================================================================== --- trunk/src/picross/grid/GridMediator.java 2008-04-16 10:44:37 UTC (rev 46) +++ trunk/src/picross/grid/GridMediator.java 2008-04-17 08:50:24 UTC (rev 47) @@ -38,6 +38,8 @@ import java.io.FileNotFoundException; +import java.lang.reflect.InvocationTargetException; + import javax.swing.JPanel; import javax.swing.SwingUtilities; @@ -89,27 +91,29 @@ final CompletedHints hints = this.model.getCompletedHints(); try { - SwingUtilities.invokeLater(new Runnable() { + SwingUtilities.invokeAndWait(new Runnable() { public void run() { - try { - GridMediator.this.view = new GridUI(width, height, - boxes, - colData, - rowData, - hints, - controller); - } catch (FileNotFoundException fileEx) { - //throw new PicrossException(fileEx); - throw new - RuntimeException(new PicrossException(fileEx)); - } - - controller.setView(GridMediator.this.view); + GridMediator.this.view = new GridUI(width, height, + boxes, + colData, + rowData, + hints, + controller); } }); - } catch (RuntimeException runtimeEx) { - throw ((PicrossException) runtimeEx.getCause()); + } catch (InterruptedException intEx) { + intEx.printStackTrace(); + } catch (InvocationTargetException targetEx) { + targetEx.printStackTrace(); } + + try { + this.view.init(); + } catch (FileNotFoundException fileEx) { + throw new PicrossException(fileEx); + } + + controller.setView(this.view); } /*** Method overloaded from the class Mediateur ***/ Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2008-04-16 10:44:37 UTC (rev 46) +++ trunk/src/picross/grid/GridUI.java 2008-04-17 08:50:24 UTC (rev 47) @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (c) 2007 + * Copyright (c) 2007-2008 * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, @@ -214,14 +214,13 @@ * @param rowData rows hints * @param completedHints list of completed hints * @param controller controller for the grid - * @throws FileNotFoundException if an image is missing */ GridUI(int width, int height, Box[][] boxes, int[][] colData, int[][] rowData, CompletedHints completedHints, - GridController controller) throws FileNotFoundException { + GridController controller) { super(true); this.controller = controller; @@ -240,6 +239,67 @@ this.completedHints = completedHints; + // Contain the state of the grid + this.boxes = boxes; + } + + /*** Method overloaded from JPanel ***/ + + /** {@inheritDoc} */ + protected void paintComponent(Graphics g) { + super.paintComponent(g); + + Graphics2D newG = (Graphics2D) g.create(); + + Rectangle clipRect = newG.getClipBounds(); + + if (this.topHintsRect.intersects(clipRect)) { + this.drawTopHints(newG); + } + + if (this.leftHintsRect.intersects(clipRect)) { + this.drawLeftHints(newG); + } + + // Paints the boxes + for (int i = 0; i < this.width; i++) { + for (int j = 0; j < this.height; j++) { + //GridUI.log.debug("currentRect : " + i + "," + j); + + Rectangle currentRect = this.boxes[i][j].getRect(); + + if (currentRect.intersects(clipRect)) { + if (this.boxes[i][j] == this.rollover) { + this.boxes[i][j].getRolloverIcon() + .paintIcon(this, newG, + currentRect.x, currentRect.y); + } else { + this.boxes[i][j].getIcon().paintIcon(this, newG, + currentRect.x, + currentRect.y); + } + } + } + } + + // Draws the blocks + newG.setColor(GridUI.BLOCKS_COLOR); + + for (Line2D line : this.blocksLines) { + newG.draw(line); + } + + newG.dispose(); + } + + /*** Methods ***/ + + /** + * Initializes various stuff. + * + * @throws FileNotFoundException if an image is missing + */ + void init() throws FileNotFoundException { // Computes the size of a hint FontRenderContext frc = new FontRenderContext(null, true, true); @@ -299,9 +359,6 @@ this.centerHighHintWidth = (hintBoxWidth / 2) - (highHintWidth / 2); - // Contain the state of the grid - this.boxes = boxes; - for (int i = 0; i < this.width; i++) { for (int j = 0; j < this.height; j++) { /* @@ -332,57 +389,6 @@ + GridUI.BOTTOM_SPACE)); } - /*** Method overloaded from JPanel ***/ - - /** {@inheritDoc} */ - protected void paintComponent(Graphics g) { - super.paintComponent(g); - - Graphics2D newG = (Graphics2D) g.create(); - - Rectangle clipRect = newG.getClipBounds(); - - if (this.topHintsRect.intersects(clipRect)) { - this.drawTopHints(newG); - } - - if (this.leftHintsRect.intersects(clipRect)) { - this.drawLeftHints(newG); - } - - // Paints the boxes - for (int i = 0; i < this.width; i++) { - for (int j = 0; j < this.height; j++) { - //GridUI.log.debug("currentRect : " + i + "," + j); - - Rectangle currentRect = this.boxes[i][j].getRect(); - - if (currentRect.intersects(clipRect)) { - if (this.boxes[i][j] == this.rollover) { - this.boxes[i][j].getRolloverIcon() - .paintIcon(this, newG, - currentRect.x, currentRect.y); - } else { - this.boxes[i][j].getIcon().paintIcon(this, newG, - currentRect.x, - currentRect.y); - } - } - } - } - - // Draws the blocks - newG.setColor(GridUI.BLOCKS_COLOR); - - for (Line2D line : this.blocksLines) { - newG.draw(line); - } - - newG.dispose(); - } - - /*** Methods ***/ - /** Precomputes the blocks lines. */ private void initBlocks() { this.blocksLines = new ArrayList<Line2D>(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |