summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mock/jrummikub/view/MockGameListPanel.java12
-rw-r--r--src/jrummikub/control/network/NetworkControl.java36
-rw-r--r--src/jrummikub/view/IGameListPanel.java22
-rw-r--r--src/jrummikub/view/impl/GameListPanel.java27
-rw-r--r--src/jrummikub/view/impl/SettingsPanel.java17
5 files changed, 55 insertions, 59 deletions
diff --git a/mock/jrummikub/view/MockGameListPanel.java b/mock/jrummikub/view/MockGameListPanel.java
index 1a7bb09..edb1bdc 100644
--- a/mock/jrummikub/view/MockGameListPanel.java
+++ b/mock/jrummikub/view/MockGameListPanel.java
@@ -1,5 +1,7 @@
package jrummikub.view;
+import java.util.List;
+
import jrummikub.util.GameData;
import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
@@ -28,19 +30,13 @@ public class MockGameListPanel implements IGameListPanel {
}
@Override
- public void removeGame(GameData game) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void addGame(GameData game) {
+ public void setChannelName(String name) {
// TODO Auto-generated method stub
}
@Override
- public void setChannelName(String name) {
+ public void setGameList(List<GameData> games) {
// TODO Auto-generated method stub
}
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;
diff --git a/src/jrummikub/view/IGameListPanel.java b/src/jrummikub/view/IGameListPanel.java
index 51d6616..8a05546 100644
--- a/src/jrummikub/view/IGameListPanel.java
+++ b/src/jrummikub/view/IGameListPanel.java
@@ -1,5 +1,7 @@
package jrummikub.view;
+import java.util.List;
+
import jrummikub.util.GameData;
import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
@@ -30,26 +32,12 @@ public interface IGameListPanel {
public IEvent1<GameData> getJoinEvent();
/**
- * Emitted when an open game is removed by the host
- *
- * @param game
- * game data of the open game
- */
- public void removeGame(GameData game);
-
- /**
- * Adds a game to the list of open games
- *
- * @param game
- * game data of the new game
- */
- public void addGame(GameData game);
-
- /**
* Sets the channel name
*
* @param name
- * channel name
+ * channel name
*/
public void setChannelName(String name);
+
+ public void setGameList(List<GameData> games);
}
diff --git a/src/jrummikub/view/impl/GameListPanel.java b/src/jrummikub/view/impl/GameListPanel.java
index 2d07f2e..3041d1a 100644
--- a/src/jrummikub/view/impl/GameListPanel.java
+++ b/src/jrummikub/view/impl/GameListPanel.java
@@ -6,7 +6,7 @@ import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import javax.swing.Box;
@@ -41,7 +41,7 @@ class GameListPanel extends JPanel implements IGameListPanel {
private Event openNewGameEvent = new Event();
private Event cancelEvent = new Event();
- private List<GameData> games = new ArrayList<GameData>();
+ private List<GameData> games = Collections.emptyList();
GameListPanel() {
setLayout(new GridBagLayout());
@@ -123,29 +123,20 @@ class GameListPanel extends JPanel implements IGameListPanel {
}
@Override
- public void addGame(GameData game) {
- if (!games.contains(game)) {
- games.add(game);
- }
-
- updateModel();
- }
+ public void setGameList(List<GameData> games) {
+ this.games = games;
- @Override
- public void removeGame(GameData game) {
- if (games.remove(game)) {
- updateModel();
- }
- }
+ Object currentGame = gameList.getSelectedValue();
- private void updateModel() {
DefaultListModel model = new DefaultListModel();
-
for (GameData game : games) {
model.addElement(game);
}
-
gameList.setModel(model);
+
+ if (games.contains(currentGame)) {
+ gameList.setSelectedValue(currentGame, false);
+ }
}
@Override
diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java
index c7b6387..8daf1fa 100644
--- a/src/jrummikub/view/impl/SettingsPanel.java
+++ b/src/jrummikub/view/impl/SettingsPanel.java
@@ -683,7 +683,6 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
}
private void addDefaultButtons() {
- buttonPanel.removeAll();
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.gridwidth = 1;
@@ -703,7 +702,6 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
}
private void addNetworkSetupButtons() {
- buttonPanel.removeAll();
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.gridwidth = 1;
@@ -719,7 +717,6 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
}
private void addNetworkOfferButtons() {
- buttonPanel.removeAll();
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.gridwidth = 1;
@@ -734,6 +731,16 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
buttonPanel.add(backButton, c);
}
+ private void addNetworkJoinButtons() {
+ GridBagConstraints c = new GridBagConstraints();
+ c.fill = GridBagConstraints.BOTH;
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ c.weightx = 1;
+ c.weighty = 1;
+
+ buttonPanel.add(backButton, c);
+ }
+
private JButton createButton(String title, final Event event) {
JButton button = new JButton(title);
button.addActionListener(new ActionListener() {
@@ -753,6 +760,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
removePlayerSettingsPanel();
}
+ buttonPanel.removeAll();
+
switch (mode) {
case DEFAULT:
addDefaultButtons();
@@ -767,7 +776,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
enableOptions(false);
break;
case NETWORK_JOIN:
- // addNetworkJoinButtons();
+ addNetworkJoinButtons();
enableOptions(false);
break;
}