[Picross-commit] SF.net SVN: picross: [52] trunk
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2008-04-18 07:42:14
|
Revision: 52 http://picross.svn.sourceforge.net/picross/?rev=52&view=rev Author: yvan_norsa Date: 2008-04-18 00:42:20 -0700 (Fri, 18 Apr 2008) Log Message: ----------- level selection menu Modified Paths: -------------- trunk/build.xml trunk/lib/mmvcs.jar trunk/src/picross/Picross.java trunk/src/picross/PicrossController.java trunk/src/picross/PicrossMediator.java trunk/src/picross/game/GameMediator.java trunk/src/picross/game/random/RandomGameMediator.java trunk/src/picross/game/simple/SimpleGameMediator.java trunk/src/picross/menus/GameMenuUI.java trunk/src/picross/menus/MenuController.java trunk/src/picross/menus/MenuMediator.java trunk/src/picross/menus/MenuUI.java Added Paths: ----------- trunk/data/contents.txt trunk/images/en/button-select.png trunk/images/fr/button-select.png trunk/lib/simpleButton.jar trunk/src/picross/menus/LevelMenuMediator.java trunk/src/picross/menus/LevelMenuModel.java trunk/src/picross/menus/LevelMenuUI.java Removed Paths: ------------- trunk/data/anchor.xbm trunk/data/bart.xbm trunk/data/blarg.xbm trunk/data/candle.xbm trunk/data/crab.xbm trunk/data/ghost_left.xbm Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2008-04-18 07:32:24 UTC (rev 51) +++ trunk/build.xml 2008-04-18 07:42:20 UTC (rev 52) @@ -27,6 +27,8 @@ value="${lib.dir}/log4j.jar" /> <property name="mmvcs.jar" value="${lib.dir}/mmvcs.jar" /> + <property name="simpleButton.jar" + value="${lib.dir}/simpleButton.jar" /> <target name="-init" depends="-setmode"> @@ -62,6 +64,7 @@ <pathelement location="${junit.jar}" /> <pathelement location="${log4j.jar}" /> <pathelement location="${mmvcs.jar}" /> + <pathelement location="${simpleButton.jar}" /> </path> <target name="compile" @@ -107,6 +110,7 @@ <pathelement location="${bundleHelper.jar}" /> <pathelement location="${log4j.jar}" /> <pathelement location="${mmvcs.jar}" /> + <pathelement location="${simpleButton.jar}" /> </classpath> </java> </target> @@ -123,6 +127,7 @@ <pathelement location="${log4j.jar}" /> <pathelement location="${mmvcs.jar}" /> <pathelement location="${debug.jar}" /> + <pathelement location="${simpleButton.jar}" /> </classpath> </java> </target> Deleted: trunk/data/anchor.xbm =================================================================== --- trunk/data/anchor.xbm 2008-04-18 07:32:24 UTC (rev 51) +++ trunk/data/anchor.xbm 2008-04-18 07:42:20 UTC (rev 52) @@ -1,6 +0,0 @@ -#define anchor.xbm_width 16 -#define anchor.xbm_height 16 -static char anchor.xbm_bits[] = { - 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x80, 0x05, 0x80, 0x05, 0x80, 0x05, - 0x80, 0x03, 0x80, 0x01, 0x9e, 0x79, 0x8e, 0x71, 0x8e, 0x71, 0x8a, 0x51, - 0x90, 0x09, 0xe0, 0x07, 0x80, 0x01, 0x00, 0x00}; Deleted: trunk/data/bart.xbm =================================================================== --- trunk/data/bart.xbm 2008-04-18 07:32:24 UTC (rev 51) +++ trunk/data/bart.xbm 2008-04-18 07:42:20 UTC (rev 52) @@ -1,27 +0,0 @@ -#define noname_width 43 -#define noname_height 58 -static char noname_bits[] = { - 0x00,0x00,0x00,0xc4,0x00,0x00,0x00,0x00,0xc0,0xca,0x00,0x00,0x00,0x00,0xc0, - 0xb2,0x00,0x00,0x00,0x00,0x4c,0xb3,0x00,0x00,0x00,0xc0,0x34,0x82,0x00,0x00, - 0x00,0x4c,0x35,0x80,0x00,0x00,0x80,0x54,0x26,0x80,0x00,0x00,0x80,0x67,0x04, - 0x80,0x00,0x00,0xb0,0x4c,0x00,0x80,0x00,0x00,0xd0,0x08,0x00,0x00,0x01,0x00, - 0x90,0x01,0x00,0x00,0x01,0x00,0x17,0x00,0x00,0x00,0x01,0x00,0x39,0x00,0x00, - 0x00,0x01,0x00,0x02,0x00,0x00,0x00,0x01,0x00,0x04,0x00,0x00,0x00,0x02,0x00, - 0x04,0x00,0x00,0x00,0x02,0x00,0x08,0x00,0x00,0x00,0x02,0x00,0x08,0x00,0x00, - 0x00,0x0c,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x1f,0x00, - 0x20,0x00,0x00,0x80,0x20,0x00,0x20,0x00,0x80,0x43,0x40,0x00,0x40,0x00,0x60, - 0x2c,0x80,0x00,0x40,0x00,0x18,0x10,0x80,0x00,0x40,0x00,0x04,0x20,0x8c,0x00, - 0x80,0x00,0x04,0x40,0x8c,0x00,0x80,0x00,0x02,0x40,0x40,0x00,0x00,0x01,0x01, - 0x40,0x70,0x00,0x00,0x01,0xc1,0xc0,0x8f,0x00,0x00,0x02,0xc1,0x40,0x00,0x01, - 0x00,0x02,0x02,0x20,0x00,0x01,0x00,0x02,0x02,0x10,0x00,0x01,0x00,0x04,0x04, - 0x10,0x00,0x01,0x00,0x04,0x08,0x0c,0x80,0x00,0x00,0x04,0xf0,0x03,0x40,0x00, - 0x00,0x08,0x00,0x00,0xbe,0x00,0x00,0x08,0x00,0x00,0x80,0x00,0x00,0x30,0x00, - 0x00,0x80,0x00,0x00,0x48,0x00,0x00,0x00,0x01,0x00,0x04,0x00,0x00,0x00,0x01, - 0x00,0x74,0x00,0x00,0x00,0x02,0x00,0x2a,0x00,0x00,0x00,0x04,0x00,0x6a,0x40, - 0x00,0x00,0x03,0x00,0x04,0x20,0x00,0xc0,0x00,0x00,0x88,0x70,0x00,0x3e,0x00, - 0x00,0x70,0x90,0xff,0x01,0x00,0x00,0x20,0x10,0x80,0x00,0x00,0x00,0x20,0x00, - 0x80,0x00,0x00,0x00,0x20,0x00,0x60,0x00,0x00,0x00,0x20,0x00,0x10,0x00,0x00, - 0x00,0x20,0x00,0x08,0x00,0x00,0x00,0x10,0x00,0x08,0x00,0x00,0x00,0x10,0x00, - 0x08,0x00,0x00,0x00,0x10,0x00,0x08,0x00,0x00,0x00,0x60,0x00,0x08,0x00,0x00, - 0x00,0x80,0x01,0x08,0x00,0x00,0x00,0x00,0x06,0x04,0x00,0x00,0x00,0x00,0xf8, - 0x03,0x00,0x00}; Deleted: trunk/data/blarg.xbm =================================================================== --- trunk/data/blarg.xbm 2008-04-18 07:32:24 UTC (rev 51) +++ trunk/data/blarg.xbm 2008-04-18 07:42:20 UTC (rev 52) @@ -1,5 +0,0 @@ -#define test_width 16 -#define test_height 7 -static char test_bits[] = { -0x13, 0x00, 0x15, 0x00, 0x93, 0xcd, 0x55, 0xa5, 0x93, 0xc5, 0x00, 0x80, -0x00, 0x60, }; Deleted: trunk/data/candle.xbm =================================================================== --- trunk/data/candle.xbm 2008-04-18 07:32:24 UTC (rev 51) +++ trunk/data/candle.xbm 2008-04-18 07:42:20 UTC (rev 52) @@ -1,8 +0,0 @@ -#define noname_width 16 -#define noname_height 33 -static char noname_bits[] = { - 0x00,0x01,0x00,0x03,0x00,0x03,0x00,0x03,0x80,0x06,0x40,0x06,0x40,0x06,0x40, - 0x06,0x40,0x03,0x80,0x01,0xf0,0x0f,0x10,0x0c,0x10,0x0c,0x10,0x0c,0x10,0x0c, - 0x10,0x0c,0x10,0x0c,0x10,0x0c,0x10,0x0c,0x10,0x0c,0x10,0x0c,0x10,0x0c,0x10, - 0x0c,0x10,0x0c,0xfe,0x7f,0x01,0xc0,0x02,0x60,0x0c,0x38,0x10,0x0c,0x10,0x0c, - 0x20,0x06,0x20,0x06,0x10,0x0c}; Added: trunk/data/contents.txt =================================================================== --- trunk/data/contents.txt (rev 0) +++ trunk/data/contents.txt 2008-04-18 07:42:20 UTC (rev 52) @@ -0,0 +1,3 @@ +bunny.xbm +halloween.xbm +squares.xbm Deleted: trunk/data/crab.xbm =================================================================== --- trunk/data/crab.xbm 2008-04-18 07:32:24 UTC (rev 51) +++ trunk/data/crab.xbm 2008-04-18 07:42:20 UTC (rev 52) @@ -1,7 +0,0 @@ -#define crab_width 16 -#define crab_height 16 - -static char crab_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x70, 0x0e, 0x78, 0x1e, 0x18, 0x18, 0x44, 0x22, - 0xc4, 0x23, 0xf8, 0x1f, 0xe0, 0x07, 0xf8, 0x1f, 0xe4, 0x27, 0xd0, 0x0b, - 0x08, 0x10, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00 }; Deleted: trunk/data/ghost_left.xbm =================================================================== --- trunk/data/ghost_left.xbm 2008-04-18 07:32:24 UTC (rev 51) +++ trunk/data/ghost_left.xbm 2008-04-18 07:42:20 UTC (rev 52) @@ -1,6 +0,0 @@ -#define pacman_left_width 16 -#define pacman_left_height 16 -static char pacman_left_bits[] = { - 0xf0,0x07,0x0c,0x18,0x02,0x20,0x3a,0x2e,0x45,0x51,0x5d,0x57,0x5d,0x57,0x5d, - 0x57,0x45,0x51,0x39,0x4e,0x01,0x40,0x01,0x40,0x11,0x44,0x29,0x4a,0x45,0x51, - 0x82,0x20}; Added: trunk/images/en/button-select.png =================================================================== (Binary files differ) Property changes on: trunk/images/en/button-select.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Name: svn:keywords + Id Added: trunk/images/fr/button-select.png =================================================================== (Binary files differ) Property changes on: trunk/images/fr/button-select.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Name: svn:keywords + Id Modified: trunk/lib/mmvcs.jar =================================================================== (Binary files differ) Added: trunk/lib/simpleButton.jar =================================================================== (Binary files differ) Property changes on: trunk/lib/simpleButton.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Name: svn:keywords + Id Modified: trunk/src/picross/Picross.java =================================================================== --- trunk/src/picross/Picross.java 2008-04-18 07:32:24 UTC (rev 51) +++ trunk/src/picross/Picross.java 2008-04-18 07:42:20 UTC (rev 52) @@ -33,17 +33,21 @@ package picross; +import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.net.URL; +import java.util.ArrayList; +import java.util.List; import java.util.Locale; import javax.swing.ImageIcon; -//import org.apache.log4j.Logger; +import org.apache.log4j.Logger; /** * Helper class. @@ -66,7 +70,7 @@ /*** Static field ***/ /** The class' logger. */ - //private static Logger log = Logger.getLogger(Picross.class); + private static Logger log = Logger.getLogger(Picross.class); /*** Constructor ***/ @@ -163,5 +167,27 @@ return Picross.getFile(Picross.DATA_DIR + name).openStream(); } + + public static List<String> listDataFiles() throws IOException { + List<String> list = new ArrayList<String>(); + + BufferedReader in = null; + + try { + in = new BufferedReader(new InputStreamReader(Picross.loadDataFile("contents.txt"))); + + String line = null; + + while ((line = in.readLine()) != null) { + list.add(line); + } + } catch (IOException ioEx) { + throw ioEx; + } finally { + in.close(); + } + + return list; + } } Modified: trunk/src/picross/PicrossController.java =================================================================== --- trunk/src/picross/PicrossController.java 2008-04-18 07:32:24 UTC (rev 51) +++ trunk/src/picross/PicrossController.java 2008-04-18 07:42:20 UTC (rev 52) @@ -55,6 +55,8 @@ /** Select level command. */ public static final String SELECT_LEVEL_CMD = "SELECT_LEVEL_CMD"; + public static final String LEVEL_CMD = "LEVEL_CMD"; + /** Exit command. */ public static final String EXIT_CMD = "EXIT_CMD"; Modified: trunk/src/picross/PicrossMediator.java =================================================================== --- trunk/src/picross/PicrossMediator.java 2008-04-18 07:32:24 UTC (rev 51) +++ trunk/src/picross/PicrossMediator.java 2008-04-18 07:42:20 UTC (rev 52) @@ -38,17 +38,24 @@ import fr.cle.mmvcs.Mediateur; import fr.cle.mmvcs.SimpleEvent; +import java.lang.reflect.InvocationTargetException; + import javax.swing.SwingUtilities; -//import org.apache.log4j.Logger; +import org.apache.log4j.Logger; import picross.game.GameMediator; +import picross.game.random.RandomGameMediator; + +import picross.game.simple.SimpleGameMediator; + import picross.grid.GridController; import picross.menus.GameMenuMediator; - +import picross.menus.LevelMenuMediator; import picross.menus.MainMenuMediator; +import picross.menus.MenuMediator; /** * Application mediator. @@ -59,7 +66,7 @@ /*** Static field ***/ /** Class' logger. */ - //private static Logger log = Logger.getLogger(PicrossMediator.class); + private static Logger log = Logger.getLogger(PicrossMediator.class); /*** Field ***/ @@ -76,24 +83,10 @@ PicrossController controller = new PicrossController(); controller.setView(view); - this.addSimpleListener(controller); - MainMenuMediator mediator = null; + this.displayMenu(MainMenuMediator.class); - try { - mediator = new MainMenuMediator(this.view); - } catch (PicrossException picrossEx) { - this.fireEventPerformed(PicrossController.ERROR_CMD, - picrossEx.getMessage()); - - this.exit(); - return; - } - - mediator.addSimpleListener(this); - - this.view.setContent(mediator.getView()); this.view.showUI(); } @@ -117,6 +110,16 @@ return; } + if (cmd.equals(PicrossController.SELECT_LEVEL_CMD)) { + this.displaySelectLevelMenu(); + return; + } + + if (cmd.equals(PicrossController.LEVEL_CMD)) { + this.startGame(e.getComment()); + return; + } + if (cmd.equals(PicrossController.EXIT_CMD)) { this.exit(); return; @@ -139,10 +142,36 @@ /** Displays the game menu. */ private void displayGameMenu() { - GameMenuMediator menu = null; + this.displayMenu(GameMenuMediator.class); + } + /** Displays the level selection menu. */ + private void displaySelectLevelMenu() { + this.displayMenu(LevelMenuMediator.class); + } + + /** + * Helper method to display a menu. + * + * @param menuClass the menu's mediator class + */ + private void displayMenu(Class<? extends MenuMediator> menuClass) { + MenuMediator menu = null; + try { - menu = new GameMenuMediator(this.view); + try { + menu = menuClass.getConstructor(PicrossUI.class) + .newInstance(this.view); + } catch (NoSuchMethodException methodEx) { + throw new PicrossException(methodEx); + } catch (InstantiationException instantiationEx) { + throw new PicrossException(instantiationEx); + } catch (IllegalAccessException accessEx) { + throw new PicrossException(accessEx); + } catch (InvocationTargetException targetEx) { + targetEx.printStackTrace(); + throw (PicrossException) targetEx.getCause(); + } } catch (PicrossException picrossEx) { this.fireEventPerformed(PicrossController.ERROR_CMD, picrossEx.getMessage()); @@ -162,15 +191,13 @@ GameMediator game = null; try { - game = - new picross.game.random.RandomGameMediator(); + game = new RandomGameMediator(); + PicrossMediator.this.gameLoaded(game); } catch (PicrossException picrossEx) { PicrossMediator.this.view .displayError(picrossEx.getMessage()); return; } - - PicrossMediator.this.gameLoaded(game); } }; @@ -178,21 +205,25 @@ } /** Starts a new game. */ - private void startGame() { + private void startGame(final String level) { + PicrossMediator.log.debug("startGame(" + level + ")"); + Thread worker = new Thread() { public void run() { GameMediator game = null; try { - game = - new picross.game.simple.SimpleGameMediator(); - } catch (PicrossException picrossEx) { - PicrossMediator.this.view - .displayError(picrossEx.getMessage()); - return; + game = new SimpleGameMediator(level); + PicrossMediator.this.gameLoaded(game); + } catch (final PicrossException picrossEx) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + PicrossMediator.this.view + .displayError(picrossEx.getMessage()); + return; + } + }); } - - PicrossMediator.this.gameLoaded(game); } }; Modified: trunk/src/picross/game/GameMediator.java =================================================================== --- trunk/src/picross/game/GameMediator.java 2008-04-18 07:32:24 UTC (rev 51) +++ trunk/src/picross/game/GameMediator.java 2008-04-18 07:42:20 UTC (rev 52) @@ -70,7 +70,8 @@ * @throws PicrossException if there is a problem loading the grid model * or building the view */ - public GameMediator() throws PicrossException { + //public GameMediator() throws PicrossException { + protected void init() throws PicrossException { PicrossGrid model = this.initModel(); final int width = model.getWidth(); Modified: trunk/src/picross/game/random/RandomGameMediator.java =================================================================== --- trunk/src/picross/game/random/RandomGameMediator.java 2008-04-18 07:32:24 UTC (rev 51) +++ trunk/src/picross/game/random/RandomGameMediator.java 2008-04-18 07:42:20 UTC (rev 52) @@ -66,7 +66,8 @@ * or building the view */ public RandomGameMediator() throws PicrossException { - super(); + //super(); + this.init(); } /*** Methods overloaded from the class GameMediator ***/ Modified: trunk/src/picross/game/simple/SimpleGameMediator.java =================================================================== --- trunk/src/picross/game/simple/SimpleGameMediator.java 2008-04-18 07:32:24 UTC (rev 51) +++ trunk/src/picross/game/simple/SimpleGameMediator.java 2008-04-18 07:42:20 UTC (rev 52) @@ -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, @@ -47,6 +47,8 @@ * @author Y. Norsa */ public final class SimpleGameMediator extends GameMediator { + private String level; + /*** Constructor ***/ /** @@ -55,8 +57,11 @@ * @throws PicrossException if there is a problem loading the grid model * or building the view */ - public SimpleGameMediator() throws PicrossException { - super(); + public SimpleGameMediator(String levelName) throws PicrossException { + //super(); + + this.level = levelName; + this.init(); } /*** Method overloaded from the class GameMediator ***/ @@ -64,7 +69,7 @@ /** {@inheritDoc} */ protected PicrossGrid initModel() throws PicrossException { try { - return new XBMModel(Picross.loadDataFile("halloween.xbm")); + return new XBMModel(Picross.loadDataFile(this.level)); } catch (IOException ioEx) { throw new PicrossException(ioEx); } Modified: trunk/src/picross/menus/GameMenuUI.java =================================================================== --- trunk/src/picross/menus/GameMenuUI.java 2008-04-18 07:32:24 UTC (rev 51) +++ trunk/src/picross/menus/GameMenuUI.java 2008-04-18 07:42:20 UTC (rev 52) @@ -59,19 +59,34 @@ /** "Random" button Y coordinate. */ private static final int RANDOM_BUTTON_Y = 175; + /** Image for the "select" button. */ + private static final String SELECT_BUTTON_IMAGE = "button-select.png"; + + /** "Select" button X coordinate. */ + private static final int SELECT_BUTTON_X = 150; + + /** "Select" button Y coordinate. */ + private static final int SELECT_BUTTON_Y = 250; + /*** Constructor ***/ /** * Constructor. * - * @param listener listener for the button - * @throws MissingImageException if the button image can't be found + * @param listener listener for the buttons + * @throws MissingImageException if a button image can't be found */ GameMenuUI(ActionListener listener) { + super(); + this.addButton(GameMenuUI.RANDOM_BUTTON_IMAGE, PicrossController.RANDOM_GAME_CMD, listener, GameMenuUI.RANDOM_BUTTON_X, GameMenuUI.RANDOM_BUTTON_Y); + this.addButton(GameMenuUI.SELECT_BUTTON_IMAGE, + PicrossController.SELECT_LEVEL_CMD, + listener, + GameMenuUI.SELECT_BUTTON_X, GameMenuUI.SELECT_BUTTON_Y); } } Added: trunk/src/picross/menus/LevelMenuMediator.java =================================================================== --- trunk/src/picross/menus/LevelMenuMediator.java (rev 0) +++ trunk/src/picross/menus/LevelMenuMediator.java 2008-04-18 07:42:20 UTC (rev 52) @@ -0,0 +1,68 @@ +/* + * $Id$ + * + * Copyright (c) 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, + * 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.menus; + +import picross.PicrossException; +import picross.PicrossUI; + +/** + * Level selection menu. + * + * @author Y. Norsa + */ +public class LevelMenuMediator extends MenuMediator { + /*** Constructor ***/ + + /** + * Constructor. + * + * @param ui reference to the main UI + * @throws PicrossException if the instantiation of the view fails + */ + public LevelMenuMediator(PicrossUI ui) throws PicrossException { + super(ui); + } + + /*** Method overloaded from the class MenuMediator ***/ + + /** {@inheritDoc} */ + @Override + protected MenuUI initView(PicrossUI ui, MenuController controller) + throws PicrossException { + + LevelMenuModel model = new LevelMenuModel(); + return new LevelMenuUI(controller, model.getLevelsList()); + } +} + Property changes on: trunk/src/picross/menus/LevelMenuMediator.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/menus/LevelMenuModel.java =================================================================== --- trunk/src/picross/menus/LevelMenuModel.java (rev 0) +++ trunk/src/picross/menus/LevelMenuModel.java 2008-04-18 07:42:20 UTC (rev 52) @@ -0,0 +1,80 @@ +/* + * $Id$ + * + * Copyright (c) 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, + * 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.menus; + +import java.io.IOException; + +import java.util.List; + +import picross.Picross; +import picross.PicrossException; + +/** + * Model for the level selection menu. + * + * @author Y. Norsa + */ +class LevelMenuModel { + /*** Field ***/ + + /** Level list. */ + private List<String> levels; + + /*** Constructor ***/ + + /** + * Constructor. + * + * @throws PicrossException if an error arises during the levels listing + */ + LevelMenuModel() throws PicrossException { + try { + this.levels = Picross.listDataFiles(); + } catch (IOException ioEx) { + throw new PicrossException(ioEx); + } + } + + /*** Method ***/ + + /** + * Returns the levels list. + * + * @return list of the level files + */ + List<String> getLevelsList() { + return this.levels; + } +} + Property changes on: trunk/src/picross/menus/LevelMenuModel.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/menus/LevelMenuUI.java =================================================================== --- trunk/src/picross/menus/LevelMenuUI.java (rev 0) +++ trunk/src/picross/menus/LevelMenuUI.java 2008-04-18 07:42:20 UTC (rev 52) @@ -0,0 +1,82 @@ +/* + * $Id$ + * + * Copyright (c) 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, + * 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.menus; + +import fr.cle.mmvcs.SimpleEvent; +import fr.cle.mmvcs.SimpleListener; + +import java.util.List; + +import picross.PicrossController; + +/** + * UI for the level selection menu. + * + * @author Y. Norsa + */ +class LevelMenuUI extends MenuUI { + /*** Constant ***/ + + /** Serialisation ID. */ + private static final long serialVersionUID = 6178785913505637523L; + + /*** Constructor ***/ + + /** + * Constructor. + * + * @param listener listener for the buttons + * @param levels levels list + */ + LevelMenuUI(SimpleListener listener, List<String> levels) { + super(); + + int x = 50; + int y = 150; + + for (String level : levels) { + SimpleEvent event = new SimpleEvent(PicrossController.LEVEL_CMD, + level); + this.addSimpleButton(level, event, listener, x, y); + + y += 75; + + if (y == 375) { + x = 250; + y = 150; + } + } + } +} + Property changes on: trunk/src/picross/menus/LevelMenuUI.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/menus/MenuController.java =================================================================== --- trunk/src/picross/menus/MenuController.java 2008-04-18 07:32:24 UTC (rev 51) +++ trunk/src/picross/menus/MenuController.java 2008-04-18 07:42:20 UTC (rev 52) @@ -48,6 +48,7 @@ /** {@inheritDoc} */ @Override public void eventPerformed(SimpleEvent e) { + this.fireEventPerformed(e); } /*** Method implanted from the interface ActionListener ***/ Modified: trunk/src/picross/menus/MenuMediator.java =================================================================== --- trunk/src/picross/menus/MenuMediator.java 2008-04-18 07:32:24 UTC (rev 51) +++ trunk/src/picross/menus/MenuMediator.java 2008-04-18 07:42:20 UTC (rev 52) @@ -46,7 +46,7 @@ * * @author Y. Norsa */ -abstract class MenuMediator extends Mediateur { +public abstract class MenuMediator extends Mediateur { /*** Static field ***/ /** This class' logger. */ Modified: trunk/src/picross/menus/MenuUI.java =================================================================== --- trunk/src/picross/menus/MenuUI.java 2008-04-18 07:32:24 UTC (rev 51) +++ trunk/src/picross/menus/MenuUI.java 2008-04-18 07:42:20 UTC (rev 52) @@ -33,6 +33,11 @@ package picross.menus; +import fr.cle.core.gui.SimpleButton; + +import fr.cle.mmvcs.SimpleEvent; +import fr.cle.mmvcs.SimpleListener; + import java.awt.Dimension; import java.awt.Graphics; import java.awt.Image; @@ -123,9 +128,26 @@ button.setActionCommand(command); button.addActionListener(controller); button.setBorder(null); + /* button.setBounds(x, y, buttonIcon.getIconWidth(), buttonIcon.getIconHeight()); this.add(button); + */ + this.putButton(button, x, y, buttonIcon.getIconWidth(), buttonIcon.getIconHeight()); } + + protected void addSimpleButton(String label, SimpleEvent event, + SimpleListener listener, + int x, int y) { + SimpleButton<JButton> button = new SimpleButton<JButton>(label, event) { }; + button.addSimpleListener(listener); + + this.putButton(button.getButton(), x, y, 150, 50); + } + + private void putButton(JButton button, int x, int y, int width, int height) { + button.setBounds(x, y, width, height); + this.add(button); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |