summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/network/NetworkControl.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/control/network/NetworkControl.java')
-rw-r--r--src/jrummikub/control/network/NetworkControl.java36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java
index dd4a949..a89e77d 100644
--- a/src/jrummikub/control/network/NetworkControl.java
+++ b/src/jrummikub/control/network/NetworkControl.java
@@ -30,6 +30,7 @@ public class NetworkControl {
private GameOfferControl gameOfferControl;
private GameJoinControl gameJoinControl;
+ private List<UUID> games = new ArrayList<UUID>();
private Map<UUID, GameData> gameMap = new HashMap<UUID, GameData>();
/**
@@ -107,29 +108,30 @@ public class NetworkControl {
connections.add(connectionControl.getGameOfferEvent().add(
new IListener1<GameData>() {
@Override
- public void handle(GameData value) {
- GameData game = gameMap.get(value.getGameID());
+ public void handle(GameData gameData) {
+ UUID uuid = gameData.getGameID();
+
+ GameData game = gameMap.get(uuid);
if (game == null) {
- game = value;
- gameMap.put(value.getGameID(), value);
+ game = gameData;
+ gameMap.put(uuid, gameData);
+ games.add(uuid);
} else {
- game.setGameSettings(value.getGameSettings());
+ game.setGameSettings(gameData.getGameSettings());
}
- view.getGameListPanel().addGame(game);
+ updateGameList();
}
}));
connections.add(connectionControl.getGameWithdrawalEvent().add(
new IListener1<UUID>() {
@Override
- public void handle(UUID value) {
- GameData game = gameMap.get(value);
+ public void handle(UUID uuid) {
+ games.remove(uuid);
+ gameMap.remove(uuid);
- if (game != null) {
- view.getGameListPanel().removeGame(game);
- gameMap.remove(value);
- }
+ updateGameList();
}
}));
connections.add(connectionControl.getGameJoinAckEvent().add(
@@ -147,6 +149,16 @@ public class NetworkControl {
}));
}
+ private void updateGameList() {
+ List<GameData> gameList = new ArrayList<GameData>();
+
+ for (UUID uuid : games) {
+ gameList.add(gameMap.get(uuid));
+ }
+
+ view.getGameListPanel().setGameList(gameList);
+ }
+
private void createGameJoinControl(UUID uuid) {
if (gameJoinControl != null) {
return;