From a15626ac3b86d3153e32b7b160403c9ab66b1034 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Mon, 13 Jun 2011 19:22:01 +0200 Subject: Liste der Spielertypen ist setzbar git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@422 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/impl/SettingsPanel.java | 56 +++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 9 deletions(-) (limited to 'src/jrummikub/view/impl') diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java index bd410ac..0292d2c 100644 --- a/src/jrummikub/view/impl/SettingsPanel.java +++ b/src/jrummikub/view/impl/SettingsPanel.java @@ -17,14 +17,17 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Vector; import javax.swing.Box; import javax.swing.BoxLayout; +import javax.swing.DefaultComboBoxModel; import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JCheckBox; @@ -57,10 +60,13 @@ import jrummikub.util.Event2; import jrummikub.util.IEvent; import jrummikub.util.IEvent1; import jrummikub.util.IEvent2; +import jrummikub.util.Pair; import jrummikub.view.ISettingsPanel; @SuppressWarnings("serial") class SettingsPanel extends JPanel implements ISettingsPanel { + private List> playerTypeChoices = new ArrayList>(); + private JTabbedPane tabbedPane; private JPanel playerSetupPanel; private JPanel playerSettingsViewport; @@ -202,6 +208,11 @@ class SettingsPanel extends JPanel implements ISettingsPanel { return backEvent; } + @Override + public void setPlayerTypeChoices(List> choices) { + playerTypeChoices = choices; + } + @Override public void setError(SettingsError error) { switch (error) { @@ -266,7 +277,12 @@ class SettingsPanel extends JPanel implements ISettingsPanel { } for (int i = 0; i < gameSettings.getPlayerList().size(); ++i) { - updatePlayerSettingsPanel(i, gameSettings.getPlayerList().get(i)); + List choices = Collections.emptyList(); + if (i < playerTypeChoices.size()) { + choices = playerTypeChoices.get(i); + } + updatePlayerSettingsPanel(i, gameSettings.getPlayerList().get(i), + choices); } initialMeldThresholdSpinner.setValue(gameSettings @@ -287,16 +303,20 @@ class SettingsPanel extends JPanel implements ISettingsPanel { playerSettingsViewport.revalidate(); } - private void updatePlayerSettingsPanel(int i, PlayerSettings settings) { + private void updatePlayerSettingsPanel(int i, PlayerSettings settings, + List choices) { if (i < playerSettingsPanels.size()) { + playerSettingsPanels.get(i).setChoices(choices); playerSettingsPanels.get(i).setSettings(settings); } else { - addPlayerSettingsPanel(i, settings); + addPlayerSettingsPanel(i, settings, choices); } } - private void addPlayerSettingsPanel(int i, PlayerSettings settings) { - PlayerSettingsPanel panel = new PlayerSettingsPanel(i, settings); + private void addPlayerSettingsPanel(int i, PlayerSettings settings, + List choices) { + PlayerSettingsPanel panel = new PlayerSettingsPanel(i, settings, + choices); playerSettingsPanels.add(panel); playerSettingsViewport.add(panel, playerSettingsViewport.getComponentCount() - 1); @@ -659,15 +679,35 @@ class SettingsPanel extends JPanel implements ISettingsPanel { } } - public PlayerSettingsPanel(int playerNumber, PlayerSettings settings) { + public PlayerSettingsPanel(int playerNumber, PlayerSettings settings, + List choices) { setLayout(new GridBagLayout()); this.playerNumber = playerNumber; createControls(settings); + setChoices(choices); setSettings(settings); } + public void setChoices(List playerTypeChoices) { + Vector choices = new Vector(); + for (Type t : playerTypeChoices) { + switch (t) { + case COMPUTER: + choices.add("Computer"); + break; + case HUMAN: + choices.add("Mensch"); + break; + case NETWORK: + choices.add("Netzwerk"); + break; + } + } + playerType.setModel(new DefaultComboBoxModel(choices)); + } + private void createControls(PlayerSettings settings) { GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c2 = new GridBagConstraints(); @@ -690,9 +730,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel { c2.fill = GridBagConstraints.HORIZONTAL; add(nameField, c2); - String[] choices = { "Mensch", "Computer" }; - - playerType = new JComboBox(choices); + playerType = new JComboBox(); playerType.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { -- cgit v1.2.3