package jrummikub.control.network; import java.util.ArrayList; import java.util.List; import jrummikub.util.Connection; import jrummikub.util.Event; import jrummikub.util.IEvent; import jrummikub.util.IListener; import jrummikub.util.IListener1; import jrummikub.util.LoginData; import jrummikub.view.IGameListPanel; import jrummikub.view.IGameListPanel.GameData; import jrummikub.view.IView; public class NetworkControl { private ConnectionControl connectionControl; private IView view; private List connections = new ArrayList(); private Event stopNetworkEvent = new Event(); public NetworkControl(LoginData loginData, final IView view) { this.view = view; connectionControl = new ConnectionControl(loginData); connections.add(connectionControl.getConnectedEvent().add( new IListener() { @Override public void handle() { view.showGameListPanel(true); } })); connections.add(connectionControl.getConnectionFailedEvent().add( new IListener() { @Override public void handle() { // TODO Auto-generated method stub } })); connections.add(view.getGameListPanel().getJoinEvent() .add(new IListener1() { @Override public void handle(GameData value) { // TODO Auto-generated method stub } })); connections.add(view.getGameListPanel().getOpenNewGameEvent() .add(new IListener() { @Override public void handle() { // TODO Auto-generated method stub } })); connections.add(view.getGameListPanel().getCancelEvent() .add(new IListener() { @Override public void handle() { abort(); stopNetworkEvent.emit(); } })); } public void startNetwork() { connectionControl.connect(); } public void abort() { for (Connection c : connections) { c.remove(); } connectionControl.disconnect(); view.showGameListPanel(false); } public IEvent getStopNetworkEvent() { return stopNetworkEvent; } }