Use login control for displaying login panel
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@399 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
ec53437da1
commit
8197b36e2b
3 changed files with 100 additions and 33 deletions
|
@ -1,5 +1,6 @@
|
||||||
package jrummikub.control;
|
package jrummikub.control;
|
||||||
|
|
||||||
|
import jrummikub.control.network.LoginControl;
|
||||||
import jrummikub.model.GameSettings;
|
import jrummikub.model.GameSettings;
|
||||||
import jrummikub.model.GameState;
|
import jrummikub.model.GameState;
|
||||||
import jrummikub.model.IRoundState;
|
import jrummikub.model.IRoundState;
|
||||||
|
@ -14,26 +15,101 @@ import jrummikub.view.IView.BottomPanelType;
|
||||||
* game control
|
* game control
|
||||||
*/
|
*/
|
||||||
public class ApplicationControl {
|
public class ApplicationControl {
|
||||||
|
private SettingsControl settingsControl;
|
||||||
|
private LoginControl loginControl;
|
||||||
private SaveControl saveControl;
|
private SaveControl saveControl;
|
||||||
private IView view;
|
|
||||||
private GameControl gameControl;
|
private GameControl gameControl;
|
||||||
|
|
||||||
|
private IView view;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new application control
|
* Creates a new application control
|
||||||
*
|
*
|
||||||
* @param view
|
* @param view
|
||||||
* the view to use
|
* the view to use
|
||||||
*/
|
*/
|
||||||
public ApplicationControl(IView view) {
|
public ApplicationControl(final IView view) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
saveControl = new SaveControl(view);
|
saveControl = new SaveControl(view);
|
||||||
|
|
||||||
|
view.getMenuNewGameEvent().add(new IListener() {
|
||||||
|
@Override
|
||||||
|
public void handle() {
|
||||||
|
abortControls();
|
||||||
|
startApplication();
|
||||||
|
}
|
||||||
|
});
|
||||||
view.getMenuQuitEvent().add(new IListener() {
|
view.getMenuQuitEvent().add(new IListener() {
|
||||||
@Override
|
@Override
|
||||||
public void handle() {
|
public void handle() {
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addLoginControlListeners();
|
||||||
|
|
||||||
|
saveControl.getLoadEvent().add(
|
||||||
|
new IListener3<GameSettings, GameState, IRoundState>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(GameSettings settings, GameState gameState,
|
||||||
|
IRoundState roundState) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,29 +120,14 @@ public class ApplicationControl {
|
||||||
view.setBottomPanel(BottomPanelType.START_GAME_PANEL);
|
view.setBottomPanel(BottomPanelType.START_GAME_PANEL);
|
||||||
saveControl.setGameSettings(null);
|
saveControl.setGameSettings(null);
|
||||||
saveControl.setGameState(null);
|
saveControl.setGameState(null);
|
||||||
final SettingsControl settingsControl = new SettingsControl(view,
|
|
||||||
new GameSettings());
|
|
||||||
|
|
||||||
saveControl.getLoadEvent().add(
|
settingsControl = new SettingsControl(view, new GameSettings());
|
||||||
new IListener3<GameSettings, GameState, IRoundState>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(GameSettings settings, GameState gameState,
|
|
||||||
IRoundState roundState) {
|
|
||||||
settingsControl.abort();
|
|
||||||
if (gameControl != null) {
|
|
||||||
gameControl.abortGame();
|
|
||||||
}
|
|
||||||
gameControl = new GameControl(settings, saveControl, view);
|
|
||||||
addGameControlListeners(gameControl);
|
|
||||||
gameControl.continueGame(gameState, roundState);
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
settingsControl.getStartGameEvent().add(new IListener1<GameSettings>() {
|
settingsControl.getStartGameEvent().add(new IListener1<GameSettings>() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(GameSettings settings) {
|
public void handle(GameSettings settings) {
|
||||||
|
settingsControl = null;
|
||||||
|
|
||||||
saveControl.setGameSettings(settings);
|
saveControl.setGameSettings(settings);
|
||||||
|
|
||||||
gameControl = new GameControl(settings, saveControl, view);
|
gameControl = new GameControl(settings, saveControl, view);
|
||||||
|
|
|
@ -334,16 +334,11 @@ public class SettingsControl {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
view.showSettingsPanel(false);
|
abort();
|
||||||
|
|
||||||
for (Connection c : connections) {
|
|
||||||
c.remove();
|
|
||||||
}
|
|
||||||
startGameEvent.emit(settings);
|
startGameEvent.emit(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void abort() {
|
public void abort() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
view.showSettingsPanel(false);
|
view.showSettingsPanel(false);
|
||||||
for (Connection c : connections) {
|
for (Connection c : connections) {
|
||||||
c.remove();
|
c.remove();
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package jrummikub.control.network;
|
package jrummikub.control.network;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import jrummikub.util.Connection;
|
||||||
import jrummikub.util.Event;
|
import jrummikub.util.Event;
|
||||||
import jrummikub.util.Event3;
|
import jrummikub.util.Event3;
|
||||||
import jrummikub.util.IEvent;
|
import jrummikub.util.IEvent;
|
||||||
|
@ -12,30 +16,30 @@ public class LoginControl {
|
||||||
private IView view;
|
private IView view;
|
||||||
private Event3<String, String, String> loginEvent = new Event3<String, String, String>();
|
private Event3<String, String, String> loginEvent = new Event3<String, String, String>();
|
||||||
private Event cancelEvent = new Event();
|
private Event cancelEvent = new Event();
|
||||||
|
private List<Connection> connections = new ArrayList<Connection>();
|
||||||
|
|
||||||
public LoginControl(final IView view) {
|
public LoginControl(final IView view) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
view.getLoginPanel().getLoginEvent()
|
connections.add(view.getLoginPanel().getLoginEvent()
|
||||||
.add(new IListener3<String, String, String>() {
|
.add(new IListener3<String, String, String>() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(String userName, String password,
|
public void handle(String userName, String password,
|
||||||
String channelName) {
|
String channelName) {
|
||||||
view.showLoginPanel(false);
|
abort();
|
||||||
loginEvent.emit(userName, password, channelName);
|
loginEvent.emit(userName, password, channelName);
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
|
|
||||||
view.getLoginPanel().getCancelEvent().add(new IListener() {
|
connections.add(view.getLoginPanel().getCancelEvent().add(new IListener() {
|
||||||
@Override
|
@Override
|
||||||
public void handle() {
|
public void handle() {
|
||||||
view.showLoginPanel(false);
|
abort();
|
||||||
cancelEvent.emit();
|
cancelEvent.emit();
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startLogin() {
|
public void startLogin() {
|
||||||
view.clearView();
|
|
||||||
view.showLoginPanel(true);
|
view.showLoginPanel(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,4 +51,11 @@ public class LoginControl {
|
||||||
return cancelEvent;
|
return cancelEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void abort() {
|
||||||
|
view.showLoginPanel(false);
|
||||||
|
for (Connection c : connections) {
|
||||||
|
c.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue