summaryrefslogtreecommitdiffstats
path: root/src/jrummikub
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub')
-rw-r--r--src/jrummikub/control/SettingsControl.java7
-rw-r--r--src/jrummikub/control/network/NetworkSettingsControl.java4
-rw-r--r--src/jrummikub/model/PlayerSettings.java2
-rw-r--r--src/jrummikub/view/ISettingsPanel.java5
-rw-r--r--src/jrummikub/view/impl/SettingsPanel.java56
5 files changed, 62 insertions, 12 deletions
diff --git a/src/jrummikub/control/SettingsControl.java b/src/jrummikub/control/SettingsControl.java
index 4103a38..abcbd5d 100644
--- a/src/jrummikub/control/SettingsControl.java
+++ b/src/jrummikub/control/SettingsControl.java
@@ -2,6 +2,7 @@ package jrummikub.control;
import java.awt.Color;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -41,6 +42,7 @@ public class SettingsControl {
this.view = view;
this.settings = settings;
view.getSettingsPanel().enableNetworkMode(false);
+
}
/**
@@ -295,6 +297,11 @@ public class SettingsControl {
checkSettings();
+ List<List<Type>> choices = new ArrayList<List<Type>>();
+ for (int i = 0; i < settings.getPlayerList().size(); i++) {
+ choices.add(Arrays.asList(Type.HUMAN, Type.COMPUTER));
+ }
+ view.getSettingsPanel().setPlayerTypeChoices(choices);
view.getSettingsPanel().setGameSettings(settings);
}
diff --git a/src/jrummikub/control/network/NetworkSettingsControl.java b/src/jrummikub/control/network/NetworkSettingsControl.java
index 9459986..b9af560 100644
--- a/src/jrummikub/control/network/NetworkSettingsControl.java
+++ b/src/jrummikub/control/network/NetworkSettingsControl.java
@@ -1,9 +1,11 @@
package jrummikub.control.network;
+import java.util.Arrays;
import java.util.UUID;
import jrummikub.control.SettingsControl;
import jrummikub.model.GameSettings;
+import jrummikub.model.PlayerSettings.Type;
import jrummikub.view.IGameListPanel.GameData;
import jrummikub.view.IView;
@@ -28,6 +30,8 @@ public class NetworkSettingsControl extends SettingsControl {
IView view, GameSettings settings) {
super(view, settings);
this.connectionControl = connectionControl;
+ /*view.getSettingsPanel().setPlayerTypeChoices(
+ Arrays.asList(Type.NETWORK, Type.COMPUTER));*/
view.getSettingsPanel().enableNetworkMode(true);
}
diff --git a/src/jrummikub/model/PlayerSettings.java b/src/jrummikub/model/PlayerSettings.java
index 2a152ad..e2fa9ae 100644
--- a/src/jrummikub/model/PlayerSettings.java
+++ b/src/jrummikub/model/PlayerSettings.java
@@ -18,8 +18,6 @@ public class PlayerSettings implements Serializable {
/** */
COMPUTER,
/** */
- VACANT,
- /** */
NETWORK
}
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) {