Fix some GUI bugs in network related panels
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@439 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
99c3d48f10
commit
c84bebceb7
5 changed files with 59 additions and 63 deletions
|
@ -1,5 +1,7 @@
|
||||||
package jrummikub.view;
|
package jrummikub.view;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import jrummikub.util.GameData;
|
import jrummikub.util.GameData;
|
||||||
import jrummikub.util.IEvent;
|
import jrummikub.util.IEvent;
|
||||||
import jrummikub.util.IEvent1;
|
import jrummikub.util.IEvent1;
|
||||||
|
@ -27,22 +29,16 @@ public class MockGameListPanel implements IGameListPanel {
|
||||||
return joinEvent;
|
return joinEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeGame(GameData game) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addGame(GameData game) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setChannelName(String name) {
|
public void setChannelName(String name) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setGameList(List<GameData> games) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ public class NetworkControl {
|
||||||
private GameOfferControl gameOfferControl;
|
private GameOfferControl gameOfferControl;
|
||||||
private GameJoinControl gameJoinControl;
|
private GameJoinControl gameJoinControl;
|
||||||
|
|
||||||
|
private List<UUID> games = new ArrayList<UUID>();
|
||||||
private Map<UUID, GameData> gameMap = new HashMap<UUID, GameData>();
|
private Map<UUID, GameData> gameMap = new HashMap<UUID, GameData>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,29 +108,30 @@ public class NetworkControl {
|
||||||
connections.add(connectionControl.getGameOfferEvent().add(
|
connections.add(connectionControl.getGameOfferEvent().add(
|
||||||
new IListener1<GameData>() {
|
new IListener1<GameData>() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(GameData value) {
|
public void handle(GameData gameData) {
|
||||||
GameData game = gameMap.get(value.getGameID());
|
UUID uuid = gameData.getGameID();
|
||||||
|
|
||||||
|
GameData game = gameMap.get(uuid);
|
||||||
|
|
||||||
if (game == null) {
|
if (game == null) {
|
||||||
game = value;
|
game = gameData;
|
||||||
gameMap.put(value.getGameID(), value);
|
gameMap.put(uuid, gameData);
|
||||||
|
games.add(uuid);
|
||||||
} else {
|
} else {
|
||||||
game.setGameSettings(value.getGameSettings());
|
game.setGameSettings(gameData.getGameSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
view.getGameListPanel().addGame(game);
|
updateGameList();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
connections.add(connectionControl.getGameWithdrawalEvent().add(
|
connections.add(connectionControl.getGameWithdrawalEvent().add(
|
||||||
new IListener1<UUID>() {
|
new IListener1<UUID>() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(UUID value) {
|
public void handle(UUID uuid) {
|
||||||
GameData game = gameMap.get(value);
|
games.remove(uuid);
|
||||||
|
gameMap.remove(uuid);
|
||||||
|
|
||||||
if (game != null) {
|
updateGameList();
|
||||||
view.getGameListPanel().removeGame(game);
|
|
||||||
gameMap.remove(value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
connections.add(connectionControl.getGameJoinAckEvent().add(
|
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) {
|
private void createGameJoinControl(UUID uuid) {
|
||||||
if (gameJoinControl != null) {
|
if (gameJoinControl != null) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package jrummikub.view;
|
package jrummikub.view;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import jrummikub.util.GameData;
|
import jrummikub.util.GameData;
|
||||||
import jrummikub.util.IEvent;
|
import jrummikub.util.IEvent;
|
||||||
import jrummikub.util.IEvent1;
|
import jrummikub.util.IEvent1;
|
||||||
|
@ -29,22 +31,6 @@ public interface IGameListPanel {
|
||||||
*/
|
*/
|
||||||
public IEvent1<GameData> getJoinEvent();
|
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
|
* Sets the channel name
|
||||||
*
|
*
|
||||||
|
@ -52,4 +38,6 @@ public interface IGameListPanel {
|
||||||
* channel name
|
* channel name
|
||||||
*/
|
*/
|
||||||
public void setChannelName(String name);
|
public void setChannelName(String name);
|
||||||
|
|
||||||
|
public void setGameList(List<GameData> games);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import java.awt.GridBagConstraints;
|
||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.util.ArrayList;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.Box;
|
import javax.swing.Box;
|
||||||
|
@ -41,7 +41,7 @@ class GameListPanel extends JPanel implements IGameListPanel {
|
||||||
private Event openNewGameEvent = new Event();
|
private Event openNewGameEvent = new Event();
|
||||||
private Event cancelEvent = new Event();
|
private Event cancelEvent = new Event();
|
||||||
|
|
||||||
private List<GameData> games = new ArrayList<GameData>();
|
private List<GameData> games = Collections.emptyList();
|
||||||
|
|
||||||
GameListPanel() {
|
GameListPanel() {
|
||||||
setLayout(new GridBagLayout());
|
setLayout(new GridBagLayout());
|
||||||
|
@ -123,29 +123,20 @@ class GameListPanel extends JPanel implements IGameListPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addGame(GameData game) {
|
public void setGameList(List<GameData> games) {
|
||||||
if (!games.contains(game)) {
|
this.games = games;
|
||||||
games.add(game);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateModel();
|
Object currentGame = gameList.getSelectedValue();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeGame(GameData game) {
|
|
||||||
if (games.remove(game)) {
|
|
||||||
updateModel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateModel() {
|
|
||||||
DefaultListModel model = new DefaultListModel();
|
DefaultListModel model = new DefaultListModel();
|
||||||
|
|
||||||
for (GameData game : games) {
|
for (GameData game : games) {
|
||||||
model.addElement(game);
|
model.addElement(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
gameList.setModel(model);
|
gameList.setModel(model);
|
||||||
|
|
||||||
|
if (games.contains(currentGame)) {
|
||||||
|
gameList.setSelectedValue(currentGame, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -683,7 +683,6 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addDefaultButtons() {
|
private void addDefaultButtons() {
|
||||||
buttonPanel.removeAll();
|
|
||||||
GridBagConstraints c = new GridBagConstraints();
|
GridBagConstraints c = new GridBagConstraints();
|
||||||
c.fill = GridBagConstraints.BOTH;
|
c.fill = GridBagConstraints.BOTH;
|
||||||
c.gridwidth = 1;
|
c.gridwidth = 1;
|
||||||
|
@ -703,7 +702,6 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNetworkSetupButtons() {
|
private void addNetworkSetupButtons() {
|
||||||
buttonPanel.removeAll();
|
|
||||||
GridBagConstraints c = new GridBagConstraints();
|
GridBagConstraints c = new GridBagConstraints();
|
||||||
c.fill = GridBagConstraints.BOTH;
|
c.fill = GridBagConstraints.BOTH;
|
||||||
c.gridwidth = 1;
|
c.gridwidth = 1;
|
||||||
|
@ -719,7 +717,6 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNetworkOfferButtons() {
|
private void addNetworkOfferButtons() {
|
||||||
buttonPanel.removeAll();
|
|
||||||
GridBagConstraints c = new GridBagConstraints();
|
GridBagConstraints c = new GridBagConstraints();
|
||||||
c.fill = GridBagConstraints.BOTH;
|
c.fill = GridBagConstraints.BOTH;
|
||||||
c.gridwidth = 1;
|
c.gridwidth = 1;
|
||||||
|
@ -734,6 +731,16 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
|
||||||
buttonPanel.add(backButton, c);
|
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) {
|
private JButton createButton(String title, final Event event) {
|
||||||
JButton button = new JButton(title);
|
JButton button = new JButton(title);
|
||||||
button.addActionListener(new ActionListener() {
|
button.addActionListener(new ActionListener() {
|
||||||
|
@ -753,6 +760,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
|
||||||
removePlayerSettingsPanel();
|
removePlayerSettingsPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buttonPanel.removeAll();
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case DEFAULT:
|
case DEFAULT:
|
||||||
addDefaultButtons();
|
addDefaultButtons();
|
||||||
|
@ -767,7 +776,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
|
||||||
enableOptions(false);
|
enableOptions(false);
|
||||||
break;
|
break;
|
||||||
case NETWORK_JOIN:
|
case NETWORK_JOIN:
|
||||||
// addNetworkJoinButtons();
|
addNetworkJoinButtons();
|
||||||
enableOptions(false);
|
enableOptions(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue