[Picross-commit] SF.net SVN: picross: [48] trunk
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2008-04-17 09:11:23
|
Revision: 48 http://picross.svn.sourceforge.net/picross/?rev=48&view=rev Author: yvan_norsa Date: 2008-04-17 02:11:28 -0700 (Thu, 17 Apr 2008) Log Message: ----------- game menu Modified Paths: -------------- trunk/src/picross/PicrossController.java trunk/src/picross/PicrossMediator.java trunk/src/picross/app/MainMenuAppUI.java trunk/src/picross/game/random/RandomGameMediator.java trunk/src/picross/menus/MainMenuUI.java Added Paths: ----------- trunk/images/en/button-random.png trunk/images/fr/button-random.png trunk/src/picross/menus/GameMenuController.java trunk/src/picross/menus/GameMenuMediator.java trunk/src/picross/menus/GameMenuUI.java trunk/src/picross/menus/MenuUI.java Added: trunk/images/en/button-random.png =================================================================== (Binary files differ) Property changes on: trunk/images/en/button-random.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/images/fr/button-random.png =================================================================== (Binary files differ) Property changes on: trunk/images/fr/button-random.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/src/picross/PicrossController.java =================================================================== --- trunk/src/picross/PicrossController.java 2008-04-17 08:50:24 UTC (rev 47) +++ trunk/src/picross/PicrossController.java 2008-04-17 09:11:28 UTC (rev 48) @@ -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, @@ -44,11 +44,14 @@ * @author Y. Norsa */ public final class PicrossController extends Controller { - /*** Constant ***/ + /*** Constants ***/ /** Play command. */ public static final String PLAY_CMD = "PLAY_CMD"; + /** Random game command. */ + public static final String RANDOM_GAME_CMD = "RANDOM_GAME_CMD"; + /*** Static field ***/ /** The class's logger. */ Modified: trunk/src/picross/PicrossMediator.java =================================================================== --- trunk/src/picross/PicrossMediator.java 2008-04-17 08:50:24 UTC (rev 47) +++ trunk/src/picross/PicrossMediator.java 2008-04-17 09:11:28 UTC (rev 48) @@ -46,6 +46,8 @@ import picross.grid.GridController; +import picross.menus.GameMenuMediator; + import picross.menus.MainMenuController; import picross.menus.MainMenuMediator; @@ -105,32 +107,14 @@ String cmd = e.getCommandName(); if (cmd.equals(PicrossController.PLAY_CMD)) { - //this.view.setContent(grid.getView()); + //this.startGame(); + this.displayGameMenu(); - //GameMediator game = new picross.game.random.RandomGameMediator(); - //GameMediator game = null; + return; + } - 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.addSimpleListener(this); - //this.view.setContent(game.getView()); - PicrossMediator.this.gameLoaded(game); - } - }; - - worker.start(); - + if (cmd.equals(PicrossController.RANDOM_GAME_CMD)) { + this.startRandomGame(); return; } @@ -154,6 +138,68 @@ this.fireEventPerformed(PicrossController.DISPOSE_CMD); } + /** Displays the game menu. */ + private void displayGameMenu() { + GameMenuMediator menu = null; + + try { + menu = new GameMenuMediator(); + } catch (PicrossException picrossEx) { + this.fireEventPerformed(PicrossController.ERROR_CMD, + picrossEx.getMessage()); + + this.exit(); + return; + } + + menu.addSimpleListener(this); + this.view.setContent(menu.getView()); + } + + /** Starts a random game. */ + private void startRandomGame() { + Thread worker = new Thread() { + public void run() { + GameMediator game = null; + + try { + game = + new picross.game.random.RandomGameMediator(); + } catch (PicrossException picrossEx) { + PicrossMediator.this.view + .displayError(picrossEx.getMessage()); + return; + } + + PicrossMediator.this.gameLoaded(game); + } + }; + + worker.start(); + } + + /** Starts a new game. */ + private void startGame() { + 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; + } + + PicrossMediator.this.gameLoaded(game); + } + }; + + worker.start(); + } + /** * Callback used to display the game view. * Modified: trunk/src/picross/app/MainMenuAppUI.java =================================================================== --- trunk/src/picross/app/MainMenuAppUI.java 2008-04-17 08:50:24 UTC (rev 47) +++ trunk/src/picross/app/MainMenuAppUI.java 2008-04-17 09:11:28 UTC (rev 48) @@ -84,17 +84,11 @@ super(controller); - ImageIcon exitIcon = - Picross.getLocalizedImage(MainMenuAppUI.EXIT_BUTTON_IMAGE); - JButton exitButton = new JButton(exitIcon); - exitButton.setActionCommand(MainMenuController.EXIT_CMD); - exitButton.addActionListener(controller); - exitButton.setBorder(null); - exitButton.setBounds(MainMenuAppUI.EXIT_BUTTON_X, - MainMenuAppUI.EXIT_BUTTON_Y, - exitIcon.getIconWidth(), - exitIcon.getIconHeight()); - this.add(exitButton); + this.addButton(MainMenuAppUI.EXIT_BUTTON_IMAGE, + MainMenuController.EXIT_CMD, + controller, + MainMenuAppUI.EXIT_BUTTON_X, + MainMenuAppUI.EXIT_BUTTON_Y); } /*** Methods overloaded from MainMenuUI ***/ Modified: trunk/src/picross/game/random/RandomGameMediator.java =================================================================== --- trunk/src/picross/game/random/RandomGameMediator.java 2008-04-17 08:50:24 UTC (rev 47) +++ trunk/src/picross/game/random/RandomGameMediator.java 2008-04-17 09:11:28 UTC (rev 48) @@ -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, @@ -65,7 +65,7 @@ * @throws PicrossException if there is a problem loading the grid model * or building the view */ - RandomGameMediator() throws PicrossException { + public RandomGameMediator() throws PicrossException { super(); } @@ -92,7 +92,7 @@ String cmd = e.getCommandName(); if (cmd.equals(RandomGameController.NEXT_CMD)) { - this.fireEventPerformed(PicrossController.PLAY_CMD); + this.fireEventPerformed(PicrossController.RANDOM_GAME_CMD); return; } Added: trunk/src/picross/menus/GameMenuController.java =================================================================== --- trunk/src/picross/menus/GameMenuController.java (rev 0) +++ trunk/src/picross/menus/GameMenuController.java 2008-04-17 09:11:28 UTC (rev 48) @@ -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 fr.cle.mmvcs.Controller; +import fr.cle.mmvcs.SimpleEvent; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import picross.PicrossController; + +/** + * Controller for the game menu. + * + * @author Y. Norsa + */ +class GameMenuController extends Controller implements ActionListener { + /*** Method overloaded from the class Controller ***/ + + /** {@inheritDoc} */ + @Override + public void eventPerformed(SimpleEvent e) { } + + /*** Method implanted from the interface ActionListener ***/ + + /** {@inheritDoc} */ + public void actionPerformed(ActionEvent e) { + String cmd = e.getActionCommand(); + + if (cmd.equals(PicrossController.RANDOM_GAME_CMD)) { + this.fireEventPerformed(cmd); + return; + } + } +} + Property changes on: trunk/src/picross/menus/GameMenuController.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/menus/GameMenuMediator.java =================================================================== --- trunk/src/picross/menus/GameMenuMediator.java (rev 0) +++ trunk/src/picross/menus/GameMenuMediator.java 2008-04-17 09:11:28 UTC (rev 48) @@ -0,0 +1,88 @@ +/* + * $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.Mediateur; +import fr.cle.mmvcs.SimpleEvent; + +import java.io.FileNotFoundException; + +import picross.PicrossException; + +/** + * Mediator for the game menu. + * + * @author Y. Norsa + */ +public class GameMenuMediator extends Mediateur { + /*** Field ***/ + + private GameMenuUI view; + + /*** Constructor ***/ + + /** + * Constructor. + */ + public GameMenuMediator() throws PicrossException { + GameMenuController controller = new GameMenuController(); + controller.addSimpleListener(this); + + try { + this.view = new GameMenuUI(controller); + } catch (FileNotFoundException fileEx) { + throw new PicrossException(fileEx); + } + } + + /*** Method overloaded from the Mediateur class ***/ + + /** {@inheritDoc} */ + @Override + public void eventPerformed(SimpleEvent e) { + this.fireEventPerformed(e); + } + + /*** Accessor ***/ + + /** + * Returns the view. + * + * @return the view + */ + public GameMenuUI getView() { + return this.view; + } +} + Property changes on: trunk/src/picross/menus/GameMenuMediator.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/menus/GameMenuUI.java =================================================================== --- trunk/src/picross/menus/GameMenuUI.java (rev 0) +++ trunk/src/picross/menus/GameMenuUI.java 2008-04-17 09:11:28 UTC (rev 48) @@ -0,0 +1,63 @@ +/* + * $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.awt.event.ActionListener; + +import java.io.FileNotFoundException; + +import picross.PicrossController; + +/** + * UI for the game menu. + * + * @author Y. Norsa + */ +class GameMenuUI extends MenuUI { + /*** Constant ***/ + + /** Serialisation ID. */ + private static final long serialVersionUID = 4472277675596865332L; + + /*** Constructor ***/ + + /** + * Constructor. + */ + GameMenuUI(ActionListener listener) throws FileNotFoundException { + this.addButton("button-random.png", PicrossController.RANDOM_GAME_CMD, + listener, 150, 225); + } +} + Property changes on: trunk/src/picross/menus/GameMenuUI.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/menus/MainMenuUI.java =================================================================== --- trunk/src/picross/menus/MainMenuUI.java 2008-04-17 08:50:24 UTC (rev 47) +++ trunk/src/picross/menus/MainMenuUI.java 2008-04-17 09:11:28 UTC (rev 48) @@ -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, @@ -53,23 +53,15 @@ * * @author Y. Norsa */ -public abstract class MainMenuUI extends JPanel { +public abstract class MainMenuUI extends MenuUI { /*** Constants ***/ /** Serialisation ID. */ private static final long serialVersionUID = -505088917693050187L; - /** Background image. */ - private static final String BACKGROUND_IMAGE = "background.png"; - /** Image for the "play" button. */ private static final String PLAY_BUTTON_IMAGE = "button-play.png"; - /*** Field ***/ - - /** Background image. */ - private Image image; - /*** Constructor ***/ /** @@ -79,23 +71,11 @@ * @throws FileNotFoundException if a button image can't be found */ public MainMenuUI(ActionListener controller) throws FileNotFoundException { - ImageIcon icon = Picross.getImage(MainMenuUI.BACKGROUND_IMAGE); - this.setPreferredSize(new Dimension(icon.getIconWidth(), - icon.getIconHeight())); - this.image = icon.getImage(); + super(); - this.setLayout(null); - - ImageIcon playIcon = - Picross.getLocalizedImage(MainMenuUI.PLAY_BUTTON_IMAGE); - JButton playButton = new JButton(playIcon); - playButton.setActionCommand(PicrossController.PLAY_CMD); - playButton.addActionListener(controller); - playButton.setBorder(null); - playButton.setBounds(this.getPlayButtonX(), this.getPlayButtonY(), - playIcon.getIconWidth(), - playIcon.getIconHeight()); - this.add(playButton); + this.addButton(MainMenuUI.PLAY_BUTTON_IMAGE, + PicrossController.PLAY_CMD, controller, + this.getPlayButtonX(), this.getPlayButtonY()); } /*** Abstract methods ***/ @@ -113,14 +93,5 @@ * @return Y position of the "play" button */ protected abstract int getPlayButtonY(); - - /*** Method overloaded from the class JPanel ***/ - - /** {@inheritDoc} */ - protected void paintComponent(Graphics g) { - super.paintComponent(g); - - g.drawImage(this.image, 0, 0, null); - } } Added: trunk/src/picross/menus/MenuUI.java =================================================================== --- trunk/src/picross/menus/MenuUI.java (rev 0) +++ trunk/src/picross/menus/MenuUI.java 2008-04-17 09:11:28 UTC (rev 48) @@ -0,0 +1,117 @@ +/* + * $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.awt.Dimension; +import java.awt.Graphics; +import java.awt.Image; + +import java.awt.event.ActionListener; + +import java.io.FileNotFoundException; + +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JPanel; + +import picross.Picross; + +/** + * Base class for menus. + * + * @author Y. Norsa + */ +abstract class MenuUI extends JPanel { + /*** Constant ***/ + + /** Background image. */ + private static final String BACKGROUND_IMAGE = "background.png"; + + /*** Field ***/ + + /** Background image. */ + private Image image; + + /*** Constructor ***/ + + /** + * Constructor. + * + * @throws FileNotFoundException if the background image can't be found + */ + MenuUI() throws FileNotFoundException { + ImageIcon icon = Picross.getImage(MenuUI.BACKGROUND_IMAGE); + this.setPreferredSize(new Dimension(icon.getIconWidth(), + icon.getIconHeight())); + this.image = icon.getImage(); + + this.setLayout(null); + } + + /*** Method overloaded from the class JPanel ***/ + + /** {@inheritDoc} */ + protected void paintComponent(Graphics g) { + super.paintComponent(g); + + g.drawImage(this.image, 0, 0, null); + } + + /*** M\xE9thod ***/ + + /** + * Helper method to add a button to the menu. + * + * @param image the image name + * @param command the command linked to the button + * @param controller listener for the button + * @param x x position for the button + * @param y y position for the button + * @throws FileNotFoundException if a button image can't be found + */ + protected void addButton(String image, String command, + ActionListener controller, int x, int y) + throws FileNotFoundException { + + ImageIcon buttonIcon = Picross.getLocalizedImage(image); + JButton button = new JButton(buttonIcon); + button.setActionCommand(command); + button.addActionListener(controller); + button.setBorder(null); + button.setBounds(x, y, + buttonIcon.getIconWidth(), + buttonIcon.getIconHeight()); + this.add(button); + } +} Property changes on: trunk/src/picross/menus/MenuUI.java ___________________________________________________________________ Name: svn:keywords + Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |