From c84bebceb7690410c33ae15f61ca2e01c79342b8 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 14 Jun 2011 17:57:19 +0200 Subject: 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 --- src/jrummikub/view/IGameListPanel.java | 22 +++++----------------- src/jrummikub/view/impl/GameListPanel.java | 27 +++++++++------------------ src/jrummikub/view/impl/SettingsPanel.java | 17 +++++++++++++---- 3 files changed, 27 insertions(+), 39 deletions(-) (limited to 'src/jrummikub/view') 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; @@ -29,27 +31,13 @@ public interface IGameListPanel { */ public IEvent1 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 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 games = new ArrayList(); + private List 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 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; } -- cgit v1.2.3