summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view
diff options
context:
space:
mode:
authorIda Massow <massow@informatik.uni-luebeck.de>2011-06-13 19:22:01 +0200
committerIda Massow <massow@informatik.uni-luebeck.de>2011-06-13 19:22:01 +0200
commita15626ac3b86d3153e32b7b160403c9ab66b1034 (patch)
treeb29862f46e3b2f8ea549a9ccdf1e34a3731c381f /src/jrummikub/view
parent56797840e2c16913627bfa57f2a49d1788443727 (diff)
downloadJRummikub-a15626ac3b86d3153e32b7b160403c9ab66b1034.tar
JRummikub-a15626ac3b86d3153e32b7b160403c9ab66b1034.zip
Liste der Spielertypen ist setzbar
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@422 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/view')
-rw-r--r--src/jrummikub/view/ISettingsPanel.java5
-rw-r--r--src/jrummikub/view/impl/SettingsPanel.java56
2 files changed, 51 insertions, 10 deletions
diff --git a/src/jrummikub/view/ISettingsPanel.java b/src/jrummikub/view/ISettingsPanel.java
index 2e482f0..2b5aa58 100644
--- a/src/jrummikub/view/ISettingsPanel.java
+++ b/src/jrummikub/view/ISettingsPanel.java
@@ -1,6 +1,7 @@
package jrummikub.view;
import java.awt.Color;
+import java.util.List;
import java.util.Set;
import jrummikub.model.GameSettings;
@@ -9,6 +10,7 @@ import jrummikub.model.StoneColor;
import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
import jrummikub.util.IEvent2;
+import jrummikub.util.Pair;
/**
* The panel for the game setup
@@ -201,6 +203,8 @@ public interface ISettingsPanel {
public IEvent getSetVariantChildrenEvent();
public IEvent getBackEvent();
+
+ public void setPlayerTypeChoices(List<List<Type>> choices);
/**
* Specifies the different kinds of settings errors that can be displayed
@@ -223,5 +227,4 @@ public interface ISettingsPanel {
/** Only computer players added */
COMPUTER_PLAYERS_ONLY_WARNING
}
-
} \ No newline at end of file
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) {