diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-10 17:32:44 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-10 17:32:44 +0200 |
commit | 8197b36e2b53d17ca4cd501fb5f3975e7bb5cbb8 (patch) | |
tree | bf8d311cd39a06b8e7b93e0ec4fe24fbeedb659a /src/jrummikub/control/ApplicationControl.java | |
parent | ec53437da1d1ddd56fc4a4ba5429d1f3e9c5c558 (diff) | |
download | JRummikub-8197b36e2b53d17ca4cd501fb5f3975e7bb5cbb8.tar JRummikub-8197b36e2b53d17ca4cd501fb5f3975e7bb5cbb8.zip |
Use login control for displaying login panel
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@399 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/control/ApplicationControl.java')
-rw-r--r-- | src/jrummikub/control/ApplicationControl.java | 95 |
1 files changed, 78 insertions, 17 deletions
diff --git a/src/jrummikub/control/ApplicationControl.java b/src/jrummikub/control/ApplicationControl.java index e00952d..895733b 100644 --- a/src/jrummikub/control/ApplicationControl.java +++ b/src/jrummikub/control/ApplicationControl.java @@ -1,5 +1,6 @@ package jrummikub.control; +import jrummikub.control.network.LoginControl; import jrummikub.model.GameSettings; import jrummikub.model.GameState; import jrummikub.model.IRoundState; @@ -14,38 +15,38 @@ import jrummikub.view.IView.BottomPanelType; * game control */ public class ApplicationControl { + private SettingsControl settingsControl; + private LoginControl loginControl; private SaveControl saveControl; - private IView view; private GameControl gameControl; + private IView view; + /** * Creates a new application control * * @param view * the view to use */ - public ApplicationControl(IView view) { + public ApplicationControl(final IView view) { this.view = view; saveControl = new SaveControl(view); + view.getMenuNewGameEvent().add(new IListener() { + @Override + public void handle() { + abortControls(); + startApplication(); + } + }); view.getMenuQuitEvent().add(new IListener() { @Override public void handle() { System.exit(0); } }); - } - /** - * Starts the application by showing the game settings dialog panel - */ - public void startApplication() { - view.showScorePanel(false); - view.setBottomPanel(BottomPanelType.START_GAME_PANEL); - saveControl.setGameSettings(null); - saveControl.setGameState(null); - final SettingsControl settingsControl = new SettingsControl(view, - new GameSettings()); + addLoginControlListeners(); saveControl.getLoadEvent().add( new IListener3<GameSettings, GameState, IRoundState>() { @@ -53,20 +54,80 @@ public class ApplicationControl { @Override public void handle(GameSettings settings, GameState gameState, IRoundState roundState) { - settingsControl.abort(); - if (gameControl != null) { - gameControl.abortGame(); - } + abortControls(); gameControl = new GameControl(settings, saveControl, view); addGameControlListeners(gameControl); gameControl.continueGame(gameState, roundState); } }); + } + + private void addLoginControlListeners() { + view.getNetworkGameEvent().add(new IListener() { + @Override + public void handle() { + if (settingsControl != null) { + settingsControl.abort(); + } + + if (gameControl != null) { + gameControl.abortGame(); + } + + loginControl = new LoginControl(view); + loginControl.getLoginEvent().add( + new IListener3<String, String, String>() { + @Override + public void handle(String userName, String password, + String channelName) { + // TODO Auto-generated method stub + } + }); + loginControl.getCancelEvent().add(new IListener() { + @Override + public void handle() { + startApplication(); + } + }); + loginControl.startLogin(); + } + }); + } + + private void abortControls() { + if (settingsControl != null) { + settingsControl.abort(); + settingsControl = null; + } + + if (gameControl != null) { + gameControl.abortGame(); + gameControl = null; + } + + if (loginControl != null) { + loginControl.abort(); + loginControl = null; + } + } + + /** + * Starts the application by showing the game settings dialog panel + */ + public void startApplication() { + view.showScorePanel(false); + view.setBottomPanel(BottomPanelType.START_GAME_PANEL); + saveControl.setGameSettings(null); + saveControl.setGameState(null); + + settingsControl = new SettingsControl(view, new GameSettings()); settingsControl.getStartGameEvent().add(new IListener1<GameSettings>() { @Override public void handle(GameSettings settings) { + settingsControl = null; + saveControl.setGameSettings(settings); gameControl = new GameControl(settings, saveControl, view); |