[Picross-commit] SF.net SVN: picross: [46] trunk/src/picross
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2008-04-16 10:44:29
|
Revision: 46 http://picross.svn.sourceforge.net/picross/?rev=46&view=rev Author: yvan_norsa Date: 2008-04-16 03:44:37 -0700 (Wed, 16 Apr 2008) Log Message: ----------- EDT stuff Modified Paths: -------------- trunk/src/picross/PicrossMediator.java trunk/src/picross/app/PicrossApp.java trunk/src/picross/game/GameMediator.java trunk/src/picross/grid/GridMediator.java Modified: trunk/src/picross/PicrossMediator.java =================================================================== --- trunk/src/picross/PicrossMediator.java 2008-04-16 09:32:18 UTC (rev 45) +++ trunk/src/picross/PicrossMediator.java 2008-04-16 10:44:37 UTC (rev 46) @@ -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, @@ -38,6 +38,8 @@ import fr.cle.mmvcs.Mediateur; import fr.cle.mmvcs.SimpleEvent; +import javax.swing.SwingUtilities; + //import org.apache.log4j.Logger; import picross.game.GameMediator; @@ -106,18 +108,29 @@ //this.view.setContent(grid.getView()); //GameMediator game = new picross.game.random.RandomGameMediator(); - GameMediator game = null; + //GameMediator game = null; - try { - game = new picross.game.simple.SimpleGameMediator(); - } catch (PicrossException picrossEx) { - this.view.displayError(picrossEx.getMessage()); - return; - } + Thread worker = new Thread() { + public void run() { + GameMediator game = null; - game.addSimpleListener(this); - this.view.setContent(game.getView()); + try { + game = + new picross.game.simple.SimpleGameMediator(); + } catch (PicrossException picrossEx) { + PicrossMediator.this.view + .displayError(picrossEx.getMessage()); + return; + } + //game.addSimpleListener(this); + //this.view.setContent(game.getView()); + PicrossMediator.this.gameLoaded(game); + } + }; + + worker.start(); + return; } @@ -134,11 +147,26 @@ } } - /*** Method ***/ + /*** Methods ***/ /** Exits the application. */ private void exit() { this.fireEventPerformed(PicrossController.DISPOSE_CMD); } + + /** + * Callback used to display the game view. + * + * @param game game reference + */ + private void gameLoaded(final GameMediator game) { + game.addSimpleListener(this); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + PicrossMediator.this.view.setContent(game.getView()); + } + }); + } } Modified: trunk/src/picross/app/PicrossApp.java =================================================================== --- trunk/src/picross/app/PicrossApp.java 2008-04-16 09:32:18 UTC (rev 45) +++ trunk/src/picross/app/PicrossApp.java 2008-04-16 10:44:37 UTC (rev 46) @@ -66,9 +66,10 @@ * @param args command line parameters */ public static void main(String[] args) { + PicrossApp.setupDebugging(); + SwingUtilities.invokeLater(new Runnable() { public void run() { - PicrossApp.setupDebugging(); new PicrossApp(); } }); Modified: trunk/src/picross/game/GameMediator.java =================================================================== --- trunk/src/picross/game/GameMediator.java 2008-04-16 09:32:18 UTC (rev 45) +++ trunk/src/picross/game/GameMediator.java 2008-04-16 10:44:37 UTC (rev 46) @@ -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, @@ -37,6 +37,7 @@ import fr.cle.mmvcs.SimpleEvent; import javax.swing.JPanel; +import javax.swing.SwingUtilities; //import org.apache.log4j.Logger; @@ -72,14 +73,21 @@ public GameMediator() throws PicrossException { PicrossGrid model = this.initModel(); - int width = model.getWidth(); - int height = model.getHeight(); + final int width = model.getWidth(); + final int height = model.getHeight(); - GridMediator grid = new GridMediator(width, height, + final GridMediator grid = new GridMediator(width, height, model.getData()); grid.addSimpleListener(this); - this.view = this.initView(width, height, grid.getView()); + // The view has to be init'ed on the EDT + SwingUtilities.invokeLater(new Runnable() { + public void run() { + GameMediator.this.view = + GameMediator.this.initView(width, height, + grid.getView()); + } + }); } /*** Abstract methods ***/ Modified: trunk/src/picross/grid/GridMediator.java =================================================================== --- trunk/src/picross/grid/GridMediator.java 2008-04-16 09:32:18 UTC (rev 45) +++ trunk/src/picross/grid/GridMediator.java 2008-04-16 10:44:37 UTC (rev 46) @@ -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, @@ -39,6 +39,7 @@ import java.io.FileNotFoundException; import javax.swing.JPanel; +import javax.swing.SwingUtilities; //import org.apache.log4j.Logger; @@ -73,27 +74,42 @@ * @param data grid content * @throws PicrossException if there is a probleme while building the view */ - public GridMediator(int width, int height, boolean[][] data) + public GridMediator(final int width, final int height, boolean[][] data) throws PicrossException { this.model = new GridModel(this, data); - GridController controller = new GridController(); + final GridController controller = new GridController(); controller.addSimpleListener(this); this.addSimpleListener(controller); + final Box[][] boxes = this.model.getBoxes(); + final int[][] colData = this.model.getColData(); + final int[][] rowData = this.model.getRowData(); + final CompletedHints hints = this.model.getCompletedHints(); + try { - this.view = new GridUI(width, height, - this.model.getBoxes(), - this.model.getColData(), - this.model.getRowData(), - this.model.getCompletedHints(), - controller); - } catch (FileNotFoundException fileEx) { - throw new PicrossException(fileEx); + SwingUtilities.invokeLater(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); + } + }); + } catch (RuntimeException runtimeEx) { + throw ((PicrossException) runtimeEx.getCause()); } - - controller.setView(this.view); } /*** Method overloaded from the class Mediateur ***/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |