[Picross-commit] SF.net SVN: picross: [78] trunk
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2008-05-07 09:34:48
|
Revision: 78 http://picross.svn.sourceforge.net/picross/?rev=78&view=rev Author: yvan_norsa Date: 2008-05-07 02:34:52 -0700 (Wed, 07 May 2008) Log Message: ----------- 'back button'; scroll for level selection Modified Paths: -------------- trunk/src/picross/game/simple/LevelMenuController.java trunk/src/picross/game/simple/LevelMenuMediator.java trunk/src/picross/game/simple/LevelMenuUI.java trunk/src/picross/menus/MenuController.java trunk/src/picross/menus/MenuUI.java Added Paths: ----------- trunk/images/en/button-back.png trunk/images/fr/button-back.png trunk/src/picross/game/simple/SizesListCommand.java Added: trunk/images/en/button-back.png =================================================================== (Binary files differ) Property changes on: trunk/images/en/button-back.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/images/fr/button-back.png =================================================================== (Binary files differ) Property changes on: trunk/images/fr/button-back.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/src/picross/game/simple/LevelMenuController.java =================================================================== --- trunk/src/picross/game/simple/LevelMenuController.java 2008-05-05 09:34:00 UTC (rev 77) +++ trunk/src/picross/game/simple/LevelMenuController.java 2008-05-07 09:34:52 UTC (rev 78) @@ -37,6 +37,10 @@ import org.apache.log4j.Logger; +import picross.PicrossController; + +import picross.game.GameCommand; + import picross.menus.MenuController; /** @@ -70,10 +74,14 @@ String cmd = e.getCommandName(); - if (cmd.equals(picross.game.GameCommand.GAME_CMD)) { + if (cmd.equals(GameCommand.GAME_CMD)) { return; } + if (cmd.equals(PicrossController.PLAY_CMD)) { + return; + } + if (cmd.equals(LevelMenuController.LEVELS_LIST_CMD)) { LevelsListCommand command = (LevelsListCommand) e.getCommand(); ((LevelMenuUI) this.getView()).displayLevels(this, @@ -82,6 +90,14 @@ return; } + if (cmd.equals(SizesListCommand.SIZES_CMD)) { + SizesListCommand command = (SizesListCommand) e.getCommand(); + ((LevelMenuUI) this.getView()).displaySizes(this, + command.getSizes()); + + return; + } + super.eventPerformed(e); } } Modified: trunk/src/picross/game/simple/LevelMenuMediator.java =================================================================== --- trunk/src/picross/game/simple/LevelMenuMediator.java 2008-05-05 09:34:00 UTC (rev 77) +++ trunk/src/picross/game/simple/LevelMenuMediator.java 2008-05-07 09:34:52 UTC (rev 78) @@ -114,6 +114,12 @@ return; } + if (cmd.equals(MenuController.BACK_CMD)) { + this.fireEventPerformed(new SizesListCommand(this.model + .getSizesList())); + return; + } + super.eventPerformed(e); } Modified: trunk/src/picross/game/simple/LevelMenuUI.java =================================================================== --- trunk/src/picross/game/simple/LevelMenuUI.java 2008-05-05 09:34:00 UTC (rev 77) +++ trunk/src/picross/game/simple/LevelMenuUI.java 2008-05-07 09:34:52 UTC (rev 78) @@ -34,12 +34,25 @@ package picross.game.simple; import fr.cle.mmvcs.SimpleEvent; -import fr.cle.mmvcs.SimpleListener; import java.awt.Dimension; +import java.awt.event.ActionListener; + import java.util.List; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JPanel; +import javax.swing.JScrollPane; + +import picross.Picross; + +import picross.PicrossController; + +import picross.menus.MenuController; import picross.menus.MenuUI; /** @@ -61,9 +74,23 @@ * @param listener listener for the buttons * @param sizes available grid sizes */ - LevelMenuUI(SimpleListener listener, List<Dimension> sizes) { + LevelMenuUI(MenuController listener, List<Dimension> sizes) { super(); + this.displaySizes(listener, sizes); + } + + /*** Method ***/ + + /** + * Displays the available level sizes. + * + * @param listener listener for the buttons + * @param sizes grid sizes + */ + void displaySizes(MenuController listener, List<Dimension> sizes) { + this.removeAll(); + int x = 150; int y = 150; @@ -82,36 +109,76 @@ y = 150; } } + + this.addBackButton(listener, PicrossController.PLAY_CMD); + + this.repaint(); } - /*** Method ***/ - /** * Displays the levels list. * * @param listener listener for the buttons * @param levels levels to display */ - void displayLevels(SimpleListener listener, List<String> levels) { + void displayLevels(MenuController listener, List<String> levels) { this.removeAll(); - int x = 50; - int y = 150; - for (String level : levels) { + JPanel panel = new JPanel(); + panel.setOpaque(false); + panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); + + int nbLevels = levels.size(); + + for (int i = 0; i < nbLevels; i++) { + String level = levels.get(i); + SimpleEvent event = new SimpleEvent(LevelMenuController.LEVEL_CMD, level); - this.addSimpleButton(level, event, listener, x, y); - y += 75; + panel.add(this.createSimpleButton(level, event, listener) + .getButton()); - if (y == 375) { - x = 250; - y = 150; + if (i != (nbLevels - 1)) { + panel.add(Box.createRigidArea(new Dimension(0, 20))); } } + JScrollPane scrollPane = new JScrollPane(panel); + scrollPane.setOpaque(false); + scrollPane.setBorder(null); + scrollPane.setBounds(150, 120, 294, 200); + + scrollPane.getViewport().setOpaque(false); + + this.add(scrollPane); + + this.addBackButton(listener, MenuController.BACK_CMD); + + this.revalidate(); this.repaint(); } + + /** + * Adds a "back" button. + * + * @param listener listener for the button + * @param command command associated to the button + */ + private void addBackButton(ActionListener listener, String command) { + ImageIcon backIcon = Picross.getLocalizedImage("button-back.png"); + + JButton backButton = new JButton(backIcon); + backButton.setActionCommand(command); + backButton.addActionListener(listener); + + backButton.setBorder(null); + backButton.setBounds(7, 318, + backIcon.getIconWidth(), + backIcon.getIconHeight()); + + this.add(backButton); + } } Added: trunk/src/picross/game/simple/SizesListCommand.java =================================================================== --- trunk/src/picross/game/simple/SizesListCommand.java (rev 0) +++ trunk/src/picross/game/simple/SizesListCommand.java 2008-05-07 09:34:52 UTC (rev 78) @@ -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.game.simple; + +import fr.cle.mmvcs.NamedCommand; + +import java.awt.Dimension; + +import java.util.List; + +/** + * Command used to display the available grid sizes. + * + * @author Y. Norsa + */ +final class SizesListCommand extends NamedCommand { + /*** Constant ***/ + + /** Command used to display the grid sizes. */ + static final String SIZES_CMD = "SIZES_CMD"; + + /*** Field ***/ + + /** The sizes list. */ + private List<Dimension> sizes; + + /*** Constructor ***/ + + /** + * Constructor. + * + * @param sizesList the sizes list + */ + SizesListCommand(List<Dimension> sizesList) { + super(SizesListCommand.SIZES_CMD); + + this.sizes = sizesList; + } + + /*** Accessor ***/ + + /** + * Return the sizes list. + * + * @return available grid sizes + */ + List<Dimension> getSizes() { + return this.sizes; + } +} + Property changes on: trunk/src/picross/game/simple/SizesListCommand.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/menus/MenuController.java =================================================================== --- trunk/src/picross/menus/MenuController.java 2008-05-05 09:34:00 UTC (rev 77) +++ trunk/src/picross/menus/MenuController.java 2008-05-07 09:34:52 UTC (rev 78) @@ -47,6 +47,11 @@ * @author Y. Norsa */ public class MenuController extends Controller implements ActionListener { + /*** Constant ***/ + + /** Command used to redisplay the previous menu. */ + public static final String BACK_CMD = "BACK_CMD"; + /*** Static field ***/ /** The class' logger. */ Modified: trunk/src/picross/menus/MenuUI.java =================================================================== --- trunk/src/picross/menus/MenuUI.java 2008-05-05 09:34:00 UTC (rev 77) +++ trunk/src/picross/menus/MenuUI.java 2008-05-07 09:34:52 UTC (rev 78) @@ -149,19 +149,41 @@ SimpleListener listener, int x, int y) { PicrossButton button = + this.createSimpleButton(label, event, listener); + this.putButton(button.getButton(), x, y, 150, 50); + } + + /** + * Helper method to create a button. + * + * @param label the button's label + * @param event the event linked to the button + * @param listener listener for the button + * @return the created button + */ + protected final PicrossButton createSimpleButton(String label, + SimpleEvent event, + SimpleListener listener) { + PicrossButton button = new PicrossButton(label, Picross.getImage("empty-button.png"), event); button.addSimpleListener(listener); JButton realButton = button.getButton(); + realButton.setHorizontalTextPosition(JButton.CENTER); realButton.setVerticalTextPosition(JButton.CENTER); - + realButton.setFont(realButton.getFont() .deriveFont(MenuUI.BUTTON_TEXT_SIZE)); realButton.setForeground(Color.WHITE); - this.putButton(realButton, x, y, 150, 50); + Dimension dim = new Dimension(150, 50); + realButton.setMinimumSize(dim); + realButton.setMaximumSize(dim); + realButton.setPreferredSize(dim); + + return button; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |