summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-06-18 03:23:30 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-06-18 03:23:30 +0200
commitc50fd5d7016354fbd462078e7ae296e2bc5ed86e (patch)
tree3c97fc9e4715f80431da29fe6c46cfd83bd4cf7f
parent325802a215562eef9effef943cd8094c0369daaf (diff)
downloadJRummikub-c50fd5d7016354fbd462078e7ae296e2bc5ed86e.tar
JRummikub-c50fd5d7016354fbd462078e7ae296e2bc5ed86e.zip
Created IConnectionControl and preliminary MockConnectionControl
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@460 72836036-5685-4462-b002-a69064685172
-rw-r--r--mock/jrummikub/control/network/MockConnectionControl.java147
-rw-r--r--src/jrummikub/control/network/AbstractGameBeginControl.java6
-rw-r--r--src/jrummikub/control/network/ConnectionControl.java90
-rw-r--r--src/jrummikub/control/network/GameJoinControl.java3
-rw-r--r--src/jrummikub/control/network/GameOfferControl.java2
-rw-r--r--src/jrummikub/control/network/IConnectionControl.java51
-rw-r--r--src/jrummikub/control/network/NetworkControl.java38
-rw-r--r--src/jrummikub/control/network/NetworkSettingsControl.java11
8 files changed, 283 insertions, 65 deletions
diff --git a/mock/jrummikub/control/network/MockConnectionControl.java b/mock/jrummikub/control/network/MockConnectionControl.java
new file mode 100644
index 0000000..5dec5e2
--- /dev/null
+++ b/mock/jrummikub/control/network/MockConnectionControl.java
@@ -0,0 +1,147 @@
+package jrummikub.control.network;
+
+import java.awt.Color;
+import java.util.UUID;
+
+import jrummikub.util.GameData;
+import jrummikub.util.IEvent;
+import jrummikub.util.IEvent1;
+import jrummikub.util.IEvent2;
+import jrummikub.util.MockEvent;
+import jrummikub.util.MockEvent1;
+import jrummikub.util.MockEvent2;
+
+public class MockConnectionControl implements IConnectionControl {
+ /** */
+ public String nickname;
+ /** */
+ public MockEvent connectedEvent = new MockEvent();
+ /** */
+ public MockEvent connectionFailedEvent = new MockEvent();
+ /** */
+ public MockEvent1<GameData> gameOfferEvent = new MockEvent1<GameData>();
+ /** */
+ public MockEvent1<UUID> gameWithdrawalEvent = new MockEvent1<UUID>();
+ /** */
+ public MockEvent1<String> gameJoinEvent = new MockEvent1<String>();
+ /** */
+ public MockEvent1<String> gameLeaveEvent = new MockEvent1<String>();
+ /** */
+ public MockEvent1<Boolean> gameJoinAckEvent = new MockEvent1<Boolean>();
+ /** */
+ public MockEvent2<String, Color> changeColorEvent = new MockEvent2<String, Color>();
+ /** */
+ public GameData currentGame;
+ /** */
+ public GameData offeredGame;
+ /** */
+ public boolean connected;
+ /** */
+ public boolean failOnConnect;
+
+ @Override
+ public String getNickname() {
+ return nickname;
+ }
+
+ @Override
+ public void connect() {
+ if (failOnConnect) {
+ connectionFailedEvent.emit();
+ } else {
+ connected = true;
+ connectedEvent.emit();
+ }
+ }
+
+ @Override
+ public void disconnect() {
+ connected = false;
+ }
+
+ @Override
+ public IEvent getConnectedEvent() {
+ return connectedEvent;
+ }
+
+ @Override
+ public IEvent getConnectionFailedEvent() {
+ return connectionFailedEvent;
+ }
+
+ @Override
+ public IEvent1<GameData> getGameOfferEvent() {
+ return gameOfferEvent;
+ }
+
+ @Override
+ public IEvent1<UUID> getGameWithdrawalEvent() {
+ return gameWithdrawalEvent;
+ }
+
+ @Override
+ public IEvent1<String> getGameJoinEvent() {
+ return gameJoinEvent;
+ }
+
+ @Override
+ public IEvent1<String> getGameLeaveEvent() {
+ return gameLeaveEvent;
+ }
+
+ @Override
+ public IEvent1<Boolean> getGameJoinAckEvent() {
+ return gameJoinAckEvent;
+ }
+
+ @Override
+ public IEvent2<String, Color> getChangeColorEvent() {
+ return changeColorEvent;
+ }
+
+ @Override
+ public void offerGame(GameData data) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void withdrawGame() {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public GameData getCurrentGame() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setCurrentGame(GameData game) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void joinGame(GameData game) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void leaveGame() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void ackJoinGame(String recipient, boolean ack) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void changeColor(Color color) {
+ // TODO Auto-generated method stub
+
+ }
+}
diff --git a/src/jrummikub/control/network/AbstractGameBeginControl.java b/src/jrummikub/control/network/AbstractGameBeginControl.java
index d938f58..598126a 100644
--- a/src/jrummikub/control/network/AbstractGameBeginControl.java
+++ b/src/jrummikub/control/network/AbstractGameBeginControl.java
@@ -21,11 +21,11 @@ import jrummikub.view.IView;
public abstract class AbstractGameBeginControl {
protected List<Connection> connections = new ArrayList<Connection>();
protected GameData gameData;
- protected ConnectionControl connectionControl;
+ protected IConnectionControl connectionControl;
protected IView view;
protected Event backEvent = new Event();
- public AbstractGameBeginControl(ConnectionControl connection, IView view,
+ public AbstractGameBeginControl(IConnectionControl connection, IView view,
final GameData gameData, SettingsMode settingsMode) {
this.connectionControl = connection;
this.view = view;
@@ -81,7 +81,7 @@ public abstract class AbstractGameBeginControl {
}
protected abstract void goBack();
-
+
public Event getBackEvent() {
return backEvent;
}
diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java
index 57e0cc6..ca8537d 100644
--- a/src/jrummikub/control/network/ConnectionControl.java
+++ b/src/jrummikub/control/network/ConnectionControl.java
@@ -32,7 +32,7 @@ import org.jivesoftware.smack.util.Base64;
import org.jivesoftware.smackx.muc.DiscussionHistory;
import org.jivesoftware.smackx.muc.MultiUserChat;
-class ConnectionControl {
+class ConnectionControl implements IConnectionControl {
private final static String ELEMENT_NAME = "rummikub";
private final static String NAMESPACE = "http://home.universe-factory.net/rummikub/";
@@ -61,15 +61,18 @@ class ConnectionControl {
this.loginData = loginData;
}
- String getNickname() {
+ @Override
+ public String getNickname() {
return muc.getNickname();
}
- void connect() {
+ @Override
+ public void connect() {
new Thread(new ConnectRunner()).start();
}
- void disconnect() {
+ @Override
+ public void disconnect() {
connectedEvent = new Event();
connectionFailedEvent = new Event();
new Thread(new Runnable() {
@@ -85,45 +88,55 @@ class ConnectionControl {
}).start();
}
- IEvent getConnectedEvent() {
+ @Override
+ public IEvent getConnectedEvent() {
return connectedEvent;
}
- IEvent getConnectionFailedEvent() {
+ @Override
+ public IEvent getConnectionFailedEvent() {
return connectionFailedEvent;
}
- IEvent1<GameData> getGameOfferEvent() {
+ @Override
+ public IEvent1<GameData> getGameOfferEvent() {
return gameOfferEvent;
}
- IEvent1<UUID> getGameWithdrawalEvent() {
+ @Override
+ public IEvent1<UUID> getGameWithdrawalEvent() {
return gameWithdrawalEvent;
}
- IEvent1<String> getGameJoinEvent() {
+ @Override
+ public IEvent1<String> getGameJoinEvent() {
return gameJoinEvent;
}
- IEvent1<String> getGameLeaveEvent() {
+ @Override
+ public IEvent1<String> getGameLeaveEvent() {
return gameLeaveEvent;
}
- IEvent1<Boolean> getGameJoinAckEvent() {
+ @Override
+ public IEvent1<Boolean> getGameJoinAckEvent() {
return gameJoinAckEvent;
}
- IEvent2<String, Color> getChangeColorEvent() {
+ @Override
+ public IEvent2<String, Color> getChangeColorEvent() {
return changeColorEvent;
}
- void offerGame(GameData data) {
+ @Override
+ public void offerGame(GameData data) {
offeredGame = data;
currentGame = data;
sendGameOffer();
}
- void withdrawGame() {
+ @Override
+ public void withdrawGame() {
offeredGame = null;
final UUID uuid = currentGame.getGameID();
currentGame = null;
@@ -131,65 +144,70 @@ class ConnectionControl {
@Override
public Message send() {
DefaultPacketExtension extension = createJRummikubExtension();
-
+
extension.setValue("messageType", "game_withdrawal");
extension.setValue("uuid", uuid.toString());
-
+
return createMessage(extension);
}
}).start();
}
- GameData getCurrentGame() {
+ @Override
+ public GameData getCurrentGame() {
return currentGame;
}
- void setCurrentGame(GameData game) {
+ @Override
+ public void setCurrentGame(GameData game) {
this.currentGame = game;
}
- void joinGame(final GameData game) {
+ @Override
+ public void joinGame(final GameData game) {
setCurrentGame(game);
new Thread(new SendRunner() {
@Override
public Message send() {
DefaultPacketExtension extension = createJRummikubExtension();
-
+
extension.setValue("messageType", "game_join");
extension.setValue("uuid", game.getGameID().toString());
-
+
return createMessage(extension);
}
}).start();
}
- void leaveGame() {
+ @Override
+ public void leaveGame() {
final UUID uuid = currentGame.getGameID();
currentGame = null;
new Thread(new SendRunner() {
@Override
public Message send() {
DefaultPacketExtension extension = createJRummikubExtension();
-
+
extension.setValue("messageType", "game_leave");
extension.setValue("uuid", uuid.toString());
-
+
return createMessage(extension);
}
}).start();
}
- void ackJoinGame(final String recipient, final boolean ack) {
+ @Override
+ public void ackJoinGame(final String recipient, final boolean ack) {
final UUID uuid = currentGame.getGameID();
new Thread(new SendRunner() {
@Override
public Message send() {
DefaultPacketExtension extension = createJRummikubExtension();
-
+
extension.setValue("messageType", "game_join_ack");
extension.setValue("uuid", uuid.toString());
extension.setValue("ack", Boolean.toString(ack));
-
+
Message message = createMessage(extension);
message.setType(Message.Type.normal);
message.setTo(muc.getRoom() + "/" + recipient);
@@ -198,21 +216,23 @@ class ConnectionControl {
}).start();
}
- void changeColor(final Color color) {
+ @Override
+ public void changeColor(final Color color) {
final UUID uuid = currentGame.getGameID();
new Thread(new SendRunner() {
@Override
public Message send() {
DefaultPacketExtension extension = createJRummikubExtension();
-
+
extension.setValue("messageType", "change_color");
extension.setValue("uuid", uuid.toString());
- extension.setValue("color", Base64.encodeObject(color, Base64.GZIP));
-
+ extension.setValue("color",
+ Base64.encodeObject(color, Base64.GZIP));
+
return createMessage(extension);
}
}).start();
-
+
}
private void sendGameOffer() {
@@ -231,15 +251,15 @@ class ConnectionControl {
}
}).start();
}
-
+
private void requestGames() {
new Thread(new SendRunner() {
@Override
public Message send() {
DefaultPacketExtension extension = createJRummikubExtension();
-
+
extension.setValue("messageType", "game_request");
-
+
return createMessage(extension);
}
});
diff --git a/src/jrummikub/control/network/GameJoinControl.java b/src/jrummikub/control/network/GameJoinControl.java
index d4a31d3..4adc61d 100644
--- a/src/jrummikub/control/network/GameJoinControl.java
+++ b/src/jrummikub/control/network/GameJoinControl.java
@@ -5,7 +5,6 @@ import java.util.UUID;
import jrummikub.model.GameSettings;
import jrummikub.model.PlayerSettings;
import jrummikub.model.PlayerSettings.Type;
-import jrummikub.util.Event;
import jrummikub.util.GameData;
import jrummikub.util.IListener1;
import jrummikub.view.ISettingsPanel.SettingsMode;
@@ -13,7 +12,7 @@ import jrummikub.view.IView;
public class GameJoinControl extends AbstractGameBeginControl {
- public GameJoinControl(final ConnectionControl connectionControl,
+ public GameJoinControl(final IConnectionControl connectionControl,
final GameData gameData, final IView view) {
super(connectionControl, view, gameData, SettingsMode.NETWORK_JOIN);
diff --git a/src/jrummikub/control/network/GameOfferControl.java b/src/jrummikub/control/network/GameOfferControl.java
index 7e3241f..af060fd 100644
--- a/src/jrummikub/control/network/GameOfferControl.java
+++ b/src/jrummikub/control/network/GameOfferControl.java
@@ -13,7 +13,7 @@ import jrummikub.view.IView;
public class GameOfferControl extends AbstractGameBeginControl {
- public GameOfferControl(final ConnectionControl connectionControl,
+ public GameOfferControl(final IConnectionControl connectionControl,
final GameSettings settings, final IView view) {
super(connectionControl, view,
new GameData(UUID.randomUUID(), settings),
diff --git a/src/jrummikub/control/network/IConnectionControl.java b/src/jrummikub/control/network/IConnectionControl.java
new file mode 100644
index 0000000..6d0bab4
--- /dev/null
+++ b/src/jrummikub/control/network/IConnectionControl.java
@@ -0,0 +1,51 @@
+package jrummikub.control.network;
+
+import java.awt.Color;
+import java.util.UUID;
+
+import jrummikub.util.GameData;
+import jrummikub.util.IEvent;
+import jrummikub.util.IEvent1;
+import jrummikub.util.IEvent2;
+
+interface IConnectionControl {
+
+ public String getNickname();
+
+ public void connect();
+
+ public void disconnect();
+
+ public IEvent getConnectedEvent();
+
+ public IEvent getConnectionFailedEvent();
+
+ public IEvent1<GameData> getGameOfferEvent();
+
+ public IEvent1<UUID> getGameWithdrawalEvent();
+
+ public IEvent1<String> getGameJoinEvent();
+
+ public IEvent1<String> getGameLeaveEvent();
+
+ public IEvent1<Boolean> getGameJoinAckEvent();
+
+ public IEvent2<String, Color> getChangeColorEvent();
+
+ public void offerGame(GameData data);
+
+ public void withdrawGame();
+
+ public GameData getCurrentGame();
+
+ public void setCurrentGame(GameData game);
+
+ public void joinGame(final GameData game);
+
+ public void leaveGame();
+
+ public void ackJoinGame(final String recipient, final boolean ack);
+
+ public void changeColor(final Color color);
+
+} \ No newline at end of file
diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java
index 0a7ea8d..95f48a4 100644
--- a/src/jrummikub/control/network/NetworkControl.java
+++ b/src/jrummikub/control/network/NetworkControl.java
@@ -13,7 +13,6 @@ import jrummikub.util.GameData;
import jrummikub.util.IEvent;
import jrummikub.util.IListener;
import jrummikub.util.IListener1;
-import jrummikub.util.IListener2;
import jrummikub.util.LoginData;
import jrummikub.view.IView;
@@ -21,7 +20,7 @@ import jrummikub.view.IView;
* Class dealing with network connection, offering and choice of network games
*/
public class NetworkControl {
- private ConnectionControl connectionControl;
+ private IConnectionControl connectionControl;
private IView view;
private List<Connection> connections = new ArrayList<Connection>();
private Event stopNetworkEvent = new Event();
@@ -37,9 +36,9 @@ public class NetworkControl {
* Creates a new network control
*
* @param loginData
- * user's login data
+ * user's login data
* @param view
- * for events and handlers
+ * for events and handlers
*/
public NetworkControl(final LoginData loginData, final IView view) {
this.view = view;
@@ -82,19 +81,21 @@ public class NetworkControl {
* Adds the listeners for connection control events
*
* @param loginData
- * player's login data
+ * player's login data
* @param view
- * view for events
+ * view for events
*/
public void addConnectionControlListeners(final LoginData loginData,
final IView view) {
- connections.add(connectionControl.getConnectedEvent().add(new IListener() {
- @Override
- public void handle() {
- view.getGameListPanel().setChannelName(loginData.getChannelName());
- view.showGameListPanel(true);
- }
- }));
+ connections.add(connectionControl.getConnectedEvent().add(
+ new IListener() {
+ @Override
+ public void handle() {
+ view.getGameListPanel().setChannelName(
+ loginData.getChannelName());
+ view.showGameListPanel(true);
+ }
+ }));
connections.add(connectionControl.getConnectionFailedEvent().add(
new IListener() {
@@ -165,10 +166,10 @@ public class NetworkControl {
GameData gameData = connectionControl.getCurrentGame();
gameJoinControl = new GameJoinControl(connectionControl, gameData, view);
- gameJoinControl.getBackEvent().add(new IListener() {
+ gameJoinControl.getBackEvent().add(new IListener() {
@Override
public void handle() {
- gameJoinControl=null;
+ gameJoinControl = null;
view.showGameListPanel(true);
}
});
@@ -242,11 +243,12 @@ public class NetworkControl {
if (gameOfferControl != null) {
return;
}
- gameOfferControl = new GameOfferControl(connectionControl, settings, view);
- gameOfferControl.getBackEvent().add(new IListener() {
+ gameOfferControl = new GameOfferControl(connectionControl, settings,
+ view);
+ gameOfferControl.getBackEvent().add(new IListener() {
@Override
public void handle() {
- gameOfferControl=null;
+ gameOfferControl = null;
view.showGameListPanel(true);
}
});
diff --git a/src/jrummikub/control/network/NetworkSettingsControl.java b/src/jrummikub/control/network/NetworkSettingsControl.java
index d9871d9..41cf5f8 100644
--- a/src/jrummikub/control/network/NetworkSettingsControl.java
+++ b/src/jrummikub/control/network/NetworkSettingsControl.java
@@ -48,16 +48,16 @@ public class NetworkSettingsControl extends AbstractSettingsControl {
addListeners();
- connections.add(view.getSettingsPanel().getOfferGameEvent().add(
- new IListener() {
+ connections.add(view.getSettingsPanel().getOfferGameEvent()
+ .add(new IListener() {
@Override
public void handle() {
offerGame();
}
}));
- connections.add(view.getSettingsPanel().getBackEvent().add(
- new IListener() {
+ connections.add(view.getSettingsPanel().getBackEvent()
+ .add(new IListener() {
@Override
public void handle() {
abort();
@@ -96,8 +96,7 @@ public class NetworkSettingsControl extends AbstractSettingsControl {
@Override
protected void update() {
- view
- .getSettingsPanel()
+ view.getSettingsPanel()
.enableAddPlayerButton(
settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length);