[Picross-commit] SF.net SVN: picross: [84] trunk/src/picross
Status: Pre-Alpha
Brought to you by:
yvan_norsa
|
From: <yva...@us...> - 2008-05-14 08:54:56
|
Revision: 84
http://picross.svn.sourceforge.net/picross/?rev=84&view=rev
Author: yvan_norsa
Date: 2008-05-14 01:55:01 -0700 (Wed, 14 May 2008)
Log Message:
-----------
added an in-game 'back to menu' button
Modified Paths:
--------------
trunk/src/picross/PicrossController.java
trunk/src/picross/PicrossMediator.java
trunk/src/picross/game/GameMediator.java
trunk/src/picross/game/GameUI.java
trunk/src/picross/game/random/RandomGameController.java
trunk/src/picross/game/random/RandomGameMediator.java
trunk/src/picross/game/random/RandomGameUI.java
trunk/src/picross/properties/messages_picross.properties
trunk/src/picross/properties/messages_picross_fr.properties
Added Paths:
-----------
trunk/src/picross/game/GameController.java
Modified: trunk/src/picross/PicrossController.java
===================================================================
--- trunk/src/picross/PicrossController.java 2008-05-14 07:32:12 UTC (rev 83)
+++ trunk/src/picross/PicrossController.java 2008-05-14 08:55:01 UTC (rev 84)
@@ -36,7 +36,7 @@
import fr.cle.mmvcs.Controller;
import fr.cle.mmvcs.SimpleEvent;
-import org.apache.log4j.Logger;
+//import org.apache.log4j.Logger;
/**
* Application controller.
@@ -55,10 +55,13 @@
/** Exit command. */
public static final String EXIT_CMD = "EXIT_CMD";
+ /** Command used to quit a game. */
+ public static final String QUIT_CMD = "QUIT_CMD";
+
/*** Static field ***/
/** The class's logger. */
- private static Logger log = Logger.getLogger(PicrossController.class);
+ //private static Logger log = Logger.getLogger(PicrossController.class);
/*** Field ***/
@@ -70,7 +73,7 @@
/** {@inheritDoc} */
@Override
public void eventPerformed(SimpleEvent e) {
- PicrossController.log.debug("eventPerformed(" + e + ")");
+ //PicrossController.log.debug("eventPerformed(" + e + ")");
String cmd = e.getCommandName();
Modified: trunk/src/picross/PicrossMediator.java
===================================================================
--- trunk/src/picross/PicrossMediator.java 2008-05-14 07:32:12 UTC (rev 83)
+++ trunk/src/picross/PicrossMediator.java 2008-05-14 08:55:01 UTC (rev 84)
@@ -137,6 +137,11 @@
BundleHelper.getString(this, "victory"));
return;
}
+
+ if (cmd.equals(PicrossController.QUIT_CMD)) {
+ this.displayGameMenu();
+ return;
+ }
}
/*** Methods ***/
Added: trunk/src/picross/game/GameController.java
===================================================================
--- trunk/src/picross/game/GameController.java (rev 0)
+++ trunk/src/picross/game/GameController.java 2008-05-14 08:55:01 UTC (rev 84)
@@ -0,0 +1,79 @@
+/*
+ * $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;
+
+import fr.cle.mmvcs.Controller;
+import fr.cle.mmvcs.SimpleEvent;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+//import org.apache.log4j.Logger;
+
+import picross.PicrossController;
+
+/**
+ * Controller for the game.
+ *
+ * @author Y. Norsa
+ */
+public class GameController extends Controller implements ActionListener {
+ /*** Static field ***/
+
+ /** The class' logger. */
+ //private static Logger log = Logger.getLogger(GameController.class);
+
+ /*** Method overloaded from the class Controller ***/
+
+ /** {@inheritDoc} */
+ @Override
+ public void eventPerformed(SimpleEvent e) { }
+
+ /*** Method implanted from the interface ActionListener ***/
+
+ /** {@inheritDoc} */
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ //GameController.log.debug("actionPerformed(" + e + ")");
+
+ String cmd = e.getActionCommand();
+
+ if (cmd.equals(PicrossController.QUIT_CMD)) {
+ this.fireEventPerformed(cmd);
+
+ return;
+ }
+ }
+}
+
Property changes on: trunk/src/picross/game/GameController.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: trunk/src/picross/game/GameMediator.java
===================================================================
--- trunk/src/picross/game/GameMediator.java 2008-05-14 07:32:12 UTC (rev 83)
+++ trunk/src/picross/game/GameMediator.java 2008-05-14 08:55:01 UTC (rev 84)
@@ -36,6 +36,8 @@
import fr.cle.mmvcs.Mediateur;
import fr.cle.mmvcs.SimpleEvent;
+import java.awt.event.ActionListener;
+
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
@@ -62,21 +64,9 @@
/** The game view. */
private GameUI view;
- /*** Abstract methods ***/
+ /*** Abstrac method ***/
/**
- * Creates the view.
- *
- * @param width the grid width
- * @param height the grid height
- * @param gridView the grid itself
- * @return view containing the grid
- */
- protected GameUI initView(int width, int height, JPanel gridView) {
- return new GameUI(width, height, gridView);
- }
-
- /**
* Creates the model.
*
* @return grid model
@@ -112,17 +102,44 @@
model.getData());
grid.addSimpleListener(this);
+ final GameController controller = this.initController();
+ controller.addSimpleListener(this);
+
// 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());
+ grid.getView(),
+ controller);
}
});
}
/**
+ * Creates the view.
+ *
+ * @param width the grid width
+ * @param height the grid height
+ * @param gridView the grid itself
+ * @param controller controller for the grid buttons
+ * @return view containing the grid
+ */
+ protected GameUI initView(int width, int height, JPanel gridView,
+ ActionListener controller) {
+ return new GameUI(width, height, gridView, controller);
+ }
+
+ /**
+ * Initialises the controller.
+ *
+ * @return the created controller
+ */
+ protected GameController initController() {
+ return new GameController();
+ }
+
+ /**
* Returns the game view.
*
* @return the view
Modified: trunk/src/picross/game/GameUI.java
===================================================================
--- trunk/src/picross/game/GameUI.java 2008-05-14 07:32:12 UTC (rev 83)
+++ trunk/src/picross/game/GameUI.java 2008-05-14 08:55:01 UTC (rev 84)
@@ -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,11 +37,18 @@
import java.awt.BorderLayout;
import java.awt.Color;
+import java.awt.FlowLayout;
+import java.awt.event.ActionListener;
+
import javax.swing.BoxLayout;
+import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
+import javax.swing.JSeparator;
+import picross.PicrossController;
+
/**
* The game UI.
*
@@ -55,8 +62,8 @@
/*** Field ***/
- /** Displays informations about the current game. */
- protected JPanel infosPanel;
+ /** Panel holding the buttons. */
+ private JPanel buttonsPanel;
/*** Constructor ***/
@@ -66,23 +73,59 @@
* @param width the grid width
* @param height the grid height
* @param grid the grid
+ * @param listener listener for the buttons
*/
- public GameUI(int width, int height, JPanel grid) {
+ public GameUI(int width, int height, JPanel grid,
+ ActionListener listener) {
super();
this.setLayout(new BorderLayout());
- this.infosPanel = new JPanel();
- this.infosPanel.setBackground(Color.WHITE);
- this.infosPanel.setLayout(new BoxLayout(this.infosPanel,
- BoxLayout.Y_AXIS));
+ JPanel topPanel = new JPanel(new BorderLayout());
+ topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
+ JPanel contentPanel = new JPanel();
+ contentPanel.setLayout(new BoxLayout(contentPanel,
+ BoxLayout.Y_AXIS));
+
+ JPanel infosPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ infosPanel.setBackground(Color.WHITE);
+
JLabel infos = new JLabel(BundleHelper.getString(this,
"gridSize")
+ " : " + width + "*" + height);
- this.infosPanel.add(infos);
- this.add(this.infosPanel, BorderLayout.NORTH);
+ infosPanel.add(infos);
+
+ topPanel.add(infosPanel);
+ topPanel.add(new JSeparator());
+
+ this.buttonsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ this.buttonsPanel.setBackground(Color.WHITE);
+
+ JButton menuButton = new JButton(BundleHelper.getString(this,
+ "menuButton"));
+ menuButton.addActionListener(listener);
+ menuButton.setActionCommand(PicrossController.QUIT_CMD);
+ this.buttonsPanel.add(menuButton);
+
+ topPanel.add(this.buttonsPanel);
+ topPanel.add(new JSeparator());
+
+ topPanel.add(contentPanel, BorderLayout.LINE_START);
+
+ this.add(topPanel, BorderLayout.PAGE_START);
this.add(grid, BorderLayout.CENTER);
}
+
+ /*** Method ***/
+
+ /**
+ * Helper method to add a button.
+ *
+ * @param button the button to add
+ */
+ protected void addButton(JButton button) {
+ this.buttonsPanel.add(button);
+ }
}
Modified: trunk/src/picross/game/random/RandomGameController.java
===================================================================
--- trunk/src/picross/game/random/RandomGameController.java 2008-05-14 07:32:12 UTC (rev 83)
+++ trunk/src/picross/game/random/RandomGameController.java 2008-05-14 08:55:01 UTC (rev 84)
@@ -33,20 +33,18 @@
package picross.game.random;
-import fr.cle.mmvcs.Controller;
-import fr.cle.mmvcs.SimpleEvent;
-
import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import org.apache.log4j.Logger;
+//import org.apache.log4j.Logger;
+import picross.game.GameController;
+
/**
* Controller for the random game UI.
*
* @author Y. Norsa
*/
-final class RandomGameController extends Controller implements ActionListener {
+final class RandomGameController extends GameController {
/*** Constant ***/
/** Command asking to create another grid. */
@@ -60,20 +58,12 @@
/*** Static field ***/
/** The class' logger. */
- private static Logger log = Logger.getLogger(RandomGameController.class);
+ //private static Logger log = Logger.getLogger(RandomGameController.class);
/*** Method overloaded from the class Controller ***/
/** {@inheritDoc} */
@Override
- public void eventPerformed(SimpleEvent e) {
- RandomGameController.log.debug("eventPerformed(" + e + ")");
- }
-
- /*** Method implanted from the interface ActionListener ***/
-
- /** {@inheritDoc} */
- @Override
public void actionPerformed(ActionEvent e) {
//RandomGameController.log.debug("actionPerformed(" + e + ")");
@@ -81,6 +71,10 @@
if (cmd.equals(RandomGameController.NEXT_CMD)) {
this.fireEventPerformed(cmd);
+
+ return;
}
+
+ super.actionPerformed(e);
}
}
Modified: trunk/src/picross/game/random/RandomGameMediator.java
===================================================================
--- trunk/src/picross/game/random/RandomGameMediator.java 2008-05-14 07:32:12 UTC (rev 83)
+++ trunk/src/picross/game/random/RandomGameMediator.java 2008-05-14 08:55:01 UTC (rev 84)
@@ -35,12 +35,15 @@
import fr.cle.mmvcs.SimpleEvent;
+import java.awt.event.ActionListener;
+
import javax.swing.JPanel;
//import org.apache.log4j.Logger;
import picross.PicrossGrid;
+import picross.game.GameController;
import picross.game.GameMediator;
import picross.game.GameUI;
@@ -59,12 +62,19 @@
/** {@inheritDoc} */
@Override
- protected GameUI initView(int width, int height, JPanel gridView) {
+ protected GameUI initView(int width, int height, JPanel gridView,
+ ActionListener controller) {
+ return new RandomGameUI(width, height, gridView,
+ controller);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected GameController initController() {
RandomGameController controller = new RandomGameController();
controller.addSimpleListener(this);
- return new RandomGameUI(width, height, gridView,
- controller);
+ return controller;
}
/** {@inheritDoc} */
Modified: trunk/src/picross/game/random/RandomGameUI.java
===================================================================
--- trunk/src/picross/game/random/RandomGameUI.java 2008-05-14 07:32:12 UTC (rev 83)
+++ trunk/src/picross/game/random/RandomGameUI.java 2008-05-14 08:55:01 UTC (rev 84)
@@ -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,
@@ -43,7 +43,7 @@
import picross.game.GameUI;
/**
- * UI modifications for a random game.
+ * Custom UI for a random game.
*
* @author Y. Norsa
*/
@@ -65,16 +65,13 @@
*/
RandomGameUI(int width, int height, JPanel grid,
ActionListener controller) {
- super(width, height, grid);
+ super(width, height, grid, controller);
JButton nextButton =
new JButton(BundleHelper.getString(this, "anotherGrid"));
nextButton.addActionListener(controller);
nextButton.setActionCommand(RandomGameController.NEXT_CMD);
- this.infosPanel.add(nextButton);
-
- // FIXME this should not be here
- this.infosPanel.add(new javax.swing.JSeparator());
+ this.addButton(nextButton);
}
}
Modified: trunk/src/picross/properties/messages_picross.properties
===================================================================
--- trunk/src/picross/properties/messages_picross.properties 2008-05-14 07:32:12 UTC (rev 83)
+++ trunk/src/picross/properties/messages_picross.properties 2008-05-14 08:55:01 UTC (rev 84)
@@ -3,6 +3,7 @@
# picross.game.GameUI
gridSize = Size
+menuButton = Back to menu
# picross.game.random.RandomGameUI
anotherGrid = Another grid
Modified: trunk/src/picross/properties/messages_picross_fr.properties
===================================================================
--- trunk/src/picross/properties/messages_picross_fr.properties 2008-05-14 07:32:12 UTC (rev 83)
+++ trunk/src/picross/properties/messages_picross_fr.properties 2008-05-14 08:55:01 UTC (rev 84)
@@ -3,6 +3,7 @@
# picross.game.GameUI
gridSize = Taille
+menuButton = Retour au menu
# picross.game.random.RandomGameUI
anotherGrid = Une autre grille
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|