From 531fe57b17394c931ee968a66104429e69cf60c6 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Fri, 27 May 2011 15:00:28 +0200 Subject: =?UTF-8?q?Test=20f=C3=BCr=20SettingsControl,=203=20neue=20Klassen?= =?UTF-8?q?,=20Mocks=20f=C3=BCr=20SettingPanel,=20lauter=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@285 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/ApplicationControl.java | 42 +++--------- src/jrummikub/control/SettingsControl.java | 54 +++++++++++++++ src/jrummikub/view/ISettingsPanel.java | 36 +++++++--- src/jrummikub/view/impl/SettingsPanel.java | 98 +++++++++++++++++++++++---- 4 files changed, 175 insertions(+), 55 deletions(-) create mode 100644 src/jrummikub/control/SettingsControl.java (limited to 'src') diff --git a/src/jrummikub/control/ApplicationControl.java b/src/jrummikub/control/ApplicationControl.java index b3d432c..8e09853 100644 --- a/src/jrummikub/control/ApplicationControl.java +++ b/src/jrummikub/control/ApplicationControl.java @@ -15,7 +15,7 @@ public class ApplicationControl { * Creates a new application control * * @param view - * the view to use + * the view to use */ public ApplicationControl(IView view) { this.view = view; @@ -25,39 +25,17 @@ public class ApplicationControl { * Starts the application by showing the game settings dialog panel */ public void startApplication() { - view.getSettingsPanel().getSettingsChangeEvent() - .add(new IListener1() { - @Override - public void handle(GameSettings settings) { - checkSettings(settings); - } - }); - view.getSettingsPanel().getStartGameEvent() - .add(new IListener1() { - @Override - public void handle(GameSettings settings) { - startGame(settings); - } - }); + SettingsControl settingsControl = new SettingsControl(view); + settingsControl.getStartGameEvent().add(new IListener1() { - view.showSettingsPanel(true); - } - - private boolean checkSettings(GameSettings settings) { - // TODO Check - // TODO Show error + @Override + public void handle(GameSettings settings) { + GameControl gameControl = new GameControl(settings, view); + gameControl.startGame(); - return true; + } + }); + settingsControl.startSettings(); } - private void startGame(GameSettings settings) { - if (!checkSettings(settings)) { - return; - } - - view.showSettingsPanel(false); - - GameControl gameControl = new GameControl(settings, view); - gameControl.startGame(); - } } diff --git a/src/jrummikub/control/SettingsControl.java b/src/jrummikub/control/SettingsControl.java new file mode 100644 index 0000000..7b96e77 --- /dev/null +++ b/src/jrummikub/control/SettingsControl.java @@ -0,0 +1,54 @@ +package jrummikub.control; + +import jrummikub.model.GameSettings; +import jrummikub.util.Event1; +import jrummikub.util.IEvent1; +import jrummikub.util.IListener1; +import jrummikub.view.IView; + +public class SettingsControl { + private IView view; + private Event1 startGameEvent = new Event1(); + + public SettingsControl(IView view) { + this.view = view; + } + + public IEvent1 getStartGameEvent() { + return startGameEvent; + } + + public void startSettings() { + /* + * view.getSettingsPanel().getSettingsChangeEvent() .add(new + * IListener1() { + * + * @Override public void handle(GameSettings settings) { + * checkSettings(settings); } }); + * view.getSettingsPanel().getStartGameEvent() .add(new + * IListener1() { + * + * @Override public void handle(GameSettings settings) { + * startGame(settings); } }); + */ + + view.showSettingsPanel(true); + } + + private boolean checkSettings(GameSettings settings) { + // TODO Check + // TODO Show error + + return true; + } + + private void startGame(GameSettings settings) { + if (!checkSettings(settings)) { + return; + } + + view.showSettingsPanel(false); + + startGameEvent.emit(settings); + } +} diff --git a/src/jrummikub/view/ISettingsPanel.java b/src/jrummikub/view/ISettingsPanel.java index 4437f58..17830e5 100644 --- a/src/jrummikub/view/ISettingsPanel.java +++ b/src/jrummikub/view/ISettingsPanel.java @@ -1,24 +1,44 @@ package jrummikub.view; +import java.awt.Color; + import jrummikub.model.GameSettings; +import jrummikub.util.IEvent; import jrummikub.util.IEvent1; +import jrummikub.util.IEvent2; /** * The panel for the game setup */ public interface ISettingsPanel { - /** - * The settings change event is emitted whenever the user has changed a game - * settings without starting the game - * - * @return the event - */ - public IEvent1 getSettingsChangeEvent(); + public IEvent getAddPlayerEvent(); + + public IEvent1 getRemovePlayerEvent(); + + public IEvent2 getChangePlayerColorEvent(); + + public IEvent2 getChangePlayerNameEvent(); + + public IEvent1 getChangeInitialMeldThresholdEvent(); /** * the start game event is emitted when the user wants to start the game * * @return the event */ - public IEvent1 getStartGameEvent(); + public IEvent getStartGameEvent(); + + public void setError(SettingsError error); + + public void enableStartGameButton(boolean enable); + + public void enableAddPlayerButton(boolean enable); + + public void enableRemovePlayerButtons(boolean enable); + + public void setGameSettings(GameSettings gameSettings); + + public enum SettingsError { + NO_ERROR, DUPLICATE_PLAYER_NAME, NO_PLAYER_NAME + } } \ No newline at end of file diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java index 7a9347c..03cfd4c 100644 --- a/src/jrummikub/view/impl/SettingsPanel.java +++ b/src/jrummikub/view/impl/SettingsPanel.java @@ -32,7 +32,9 @@ import javax.swing.event.DocumentListener; import jrummikub.model.GameSettings; import jrummikub.model.PlayerSettings; import jrummikub.util.Event1; +import jrummikub.util.IEvent; import jrummikub.util.IEvent1; +import jrummikub.util.IEvent2; import jrummikub.view.ISettingsPanel; @SuppressWarnings("serial") @@ -66,15 +68,13 @@ class SettingsPanel extends JPanel implements ISettingsPanel { private Event1 settingsChangeEvent = new Event1(); private Event1 startGameEvent = new Event1(); - @Override - public IEvent1 getSettingsChangeEvent() { - return settingsChangeEvent; - } - - @Override - public IEvent1 getStartGameEvent() { - return startGameEvent; - } + /* + * @Override public IEvent1 getSettingsChangeEvent() { return + * settingsChangeEvent; } + * + * @Override public IEvent1 getStartGameEvent() { return + * startGameEvent; } + */ private void addPlayerSettings() { // Find unused player name @@ -104,7 +104,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { break; } - PlayerSettingsPanel panel = new PlayerSettingsPanel("Spieler " + num, color); + PlayerSettingsPanel panel = new PlayerSettingsPanel("Spieler " + num, + color); playerSettingsPanels.add(panel); playerSettingsViewport.add(panel, playerSettingsViewport.getComponentCount() - 1); @@ -130,7 +131,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { playerSettingsViewport.add(addPlayerPanel); JButton addPlayerButton = new JButton("+"); - addPlayerButton.setFont(addPlayerButton.getFont().deriveFont(Font.BOLD)); + addPlayerButton + .setFont(addPlayerButton.getFont().deriveFont(Font.BOLD)); addPlayerButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -180,8 +182,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { }); add(startButton, c); - setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder( - 10, 10, 10, 10))); + setBorder(new CompoundBorder(new LineBorder(Color.BLACK), + new EmptyBorder(10, 10, 10, 10))); } private class PlayerSettingsPanel extends JPanel { @@ -200,8 +202,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { } private void updateColor() { - colorButton - .setIcon(ImageUtil.createColorIcon(settings.getColor(), 16, 2)); + colorButton.setIcon(ImageUtil.createColorIcon(settings.getColor(), + 16, 2)); } private void setName() { @@ -333,4 +335,70 @@ class SettingsPanel extends JPanel implements ISettingsPanel { } } } + + @Override + public IEvent getAddPlayerEvent() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IEvent1 getRemovePlayerEvent() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IEvent2 getChangePlayerColorEvent() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IEvent2 getChangePlayerNameEvent() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IEvent1 getChangeInitialMeldThresholdEvent() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setError(SettingsError error) { + // TODO Auto-generated method stub + + } + + @Override + public void enableStartGameButton(boolean enable) { + // TODO Auto-generated method stub + + } + + @Override + public void enableAddPlayerButton(boolean enable) { + // TODO Auto-generated method stub + + } + + @Override + public void enableRemovePlayerButtons(boolean enable) { + // TODO Auto-generated method stub + + } + + @Override + public IEvent getStartGameEvent() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setGameSettings(GameSettings gameSettings) { + // TODO Auto-generated method stub + + } } -- cgit v1.2.3