diff options
Diffstat (limited to 'src/jrummikub/view/impl')
-rw-r--r-- | src/jrummikub/view/impl/SettingsPanel.java | 56 |
1 files changed, 47 insertions, 9 deletions
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<List<Type>> playerTypeChoices = new ArrayList<List<Type>>(); + private JTabbedPane tabbedPane; private JPanel playerSetupPanel; private JPanel playerSettingsViewport; @@ -203,6 +209,11 @@ class SettingsPanel extends JPanel implements ISettingsPanel { } @Override + public void setPlayerTypeChoices(List<List<Type>> choices) { + playerTypeChoices = choices; + } + + @Override public void setError(SettingsError error) { switch (error) { case NO_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<Type> 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<Type> 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<Type> 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<Type> choices) { setLayout(new GridBagLayout()); this.playerNumber = playerNumber; createControls(settings); + setChoices(choices); setSettings(settings); } + public void setChoices(List<Type> playerTypeChoices) { + Vector<String> choices = new Vector<String>(); + 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) { |