summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-05-29 22:24:48 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-05-29 22:24:48 +0200
commitf3f52956f711658f42ef753b7ff46728da67aa54 (patch)
treee6229af2028d46a9ac524a613754e0473de899ff
parentd9b651828aedbd9eb80f534842356d5200c644ee (diff)
downloadJRummikub-f3f52956f711658f42ef753b7ff46728da67aa54.tar
JRummikub-f3f52956f711658f42ef753b7ff46728da67aa54.zip
Tested and implemented player type selection in the settings panel
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@317 72836036-5685-4462-b002-a69064685172
-rw-r--r--mock/jrummikub/view/MockSettingsPanel.java10
-rw-r--r--src/jrummikub/control/SettingsControl.java14
-rw-r--r--src/jrummikub/view/ISettingsPanel.java10
-rw-r--r--src/jrummikub/view/impl/SettingsPanel.java14
-rw-r--r--test/jrummikub/control/SettingsControlTest.java16
5 files changed, 59 insertions, 5 deletions
diff --git a/mock/jrummikub/view/MockSettingsPanel.java b/mock/jrummikub/view/MockSettingsPanel.java
index 5e3a736..2140e05 100644
--- a/mock/jrummikub/view/MockSettingsPanel.java
+++ b/mock/jrummikub/view/MockSettingsPanel.java
@@ -2,6 +2,8 @@ package jrummikub.view;
import java.awt.Color;
+import jrummikub.control.turn.TurnControlFactory;
+import jrummikub.control.turn.TurnControlFactory.Type;
import jrummikub.model.GameSettings;
import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
@@ -21,6 +23,8 @@ public class MockSettingsPanel implements ISettingsPanel {
public MockEvent2<Integer, Color> changePlayerColorEvent = new MockEvent2<Integer, Color>();
/** */
public MockEvent2<Integer, String> changePlayerNameEvent = new MockEvent2<Integer, String>();
+ /** */
+ public MockEvent2<Integer, TurnControlFactory.Type> changePlayerTypeEvent = new MockEvent2<Integer, TurnControlFactory.Type>();
/** */
public MockEvent startGameEvent = new MockEvent();
/** */
@@ -43,7 +47,6 @@ public class MockSettingsPanel implements ISettingsPanel {
public int initialMeldThreshold;
/** */
public int jokerNumber;
-
@Override
public IEvent getAddPlayerEvent() {
return addPlayerEvent;
@@ -119,4 +122,9 @@ public class MockSettingsPanel implements ISettingsPanel {
this.jokerNumber = jokerNumber;
}
+ @Override
+ public IEvent2<Integer, Type> getChangePlayerTypeEvent() {
+ return changePlayerTypeEvent;
+ }
+
}
diff --git a/src/jrummikub/control/SettingsControl.java b/src/jrummikub/control/SettingsControl.java
index dfaa552..ffd1911 100644
--- a/src/jrummikub/control/SettingsControl.java
+++ b/src/jrummikub/control/SettingsControl.java
@@ -4,6 +4,8 @@ import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
+import jrummikub.control.turn.TurnControlFactory;
+import jrummikub.control.turn.TurnControlFactory.Type;
import jrummikub.model.GameSettings;
import jrummikub.model.PlayerSettings;
import jrummikub.util.Connection;
@@ -118,6 +120,13 @@ public class SettingsControl {
setPlayerName(i, name);
}
}));
+ connections.add(view.getSettingsPanel().getChangePlayerTypeEvent()
+ .add(new IListener2<Integer, TurnControlFactory.Type>() {
+ @Override
+ public void handle(Integer i, TurnControlFactory.Type type) {
+ setPlayerType(i, type);
+ }
+ }));
}
private void addPlayer() {
@@ -186,6 +195,11 @@ public class SettingsControl {
update();
}
+ private void setPlayerType(Integer i, Type type) {
+ settings.getPlayerList().get(i).setTurnControlType(type);
+ update();
+ }
+
private void update() {
view.getSettingsPanel().enableRemovePlayerButtons(
settings.getPlayerList().size() > 2);
diff --git a/src/jrummikub/view/ISettingsPanel.java b/src/jrummikub/view/ISettingsPanel.java
index 28faec6..cc1431d 100644
--- a/src/jrummikub/view/ISettingsPanel.java
+++ b/src/jrummikub/view/ISettingsPanel.java
@@ -2,6 +2,8 @@ package jrummikub.view;
import java.awt.Color;
+import jrummikub.control.turn.TurnControlFactory;
+import jrummikub.control.turn.TurnControlFactory.Type;
import jrummikub.model.GameSettings;
import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
@@ -65,6 +67,14 @@ public interface ISettingsPanel {
public IEvent2<Integer, String> getChangePlayerNameEvent();
/**
+ * The change player color event is emitted when the user wants change a
+ * player's type
+ *
+ * @return the event
+ */
+ public IEvent2<Integer, TurnControlFactory.Type> getChangePlayerTypeEvent();
+
+ /**
* The change initial meld threshold event is emitted when the user wants
* change the initial meld threshold
*
diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java
index a96c5a7..02dfc10 100644
--- a/src/jrummikub/view/impl/SettingsPanel.java
+++ b/src/jrummikub/view/impl/SettingsPanel.java
@@ -41,6 +41,7 @@ import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import jrummikub.control.turn.TurnControlFactory;
+import jrummikub.control.turn.TurnControlFactory.Type;
import jrummikub.model.GameSettings;
import jrummikub.model.PlayerSettings;
import jrummikub.util.Event;
@@ -312,10 +313,12 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
nameField.setText(settings.getName());
}
// playerType.setSelectedIndex(0);
- playerType.setSelectedIndex(Arrays.binarySearch(
+ int index = Arrays.binarySearch(
TurnControlFactory.Type.values(),
- settings.getTurnControlType()));
-
+ settings.getTurnControlType());
+ if (index != playerType.getSelectedIndex()) {
+ playerType.setSelectedIndex(index);
+ }
colorButton.setIcon(ImageUtil.createColorIcon(settings.getColor(),
16, 2));
}
@@ -494,4 +497,9 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
public void setJokerNumber(int jokerNumber) {
jokerNumberSpinner.setValue(jokerNumber);
}
+
+ @Override
+ public IEvent2<Integer, Type> getChangePlayerTypeEvent() {
+ return changePlayerTypeEvent;
+ }
}
diff --git a/test/jrummikub/control/SettingsControlTest.java b/test/jrummikub/control/SettingsControlTest.java
index fef6b28..65c4c29 100644
--- a/test/jrummikub/control/SettingsControlTest.java
+++ b/test/jrummikub/control/SettingsControlTest.java
@@ -4,6 +4,7 @@ import static org.junit.Assert.*;
import java.awt.Color;
+import jrummikub.control.turn.TurnControlFactory;
import jrummikub.model.GameSettings;
import jrummikub.util.IListener1;
import jrummikub.view.ISettingsPanel;
@@ -194,5 +195,18 @@ public class SettingsControlTest {
view.settingsPanel.startGameEvent.emit();
assertEquals(25, gameSettings.getJokerNumber());
}
-
+
+ /** */
+ @Test
+ public void typeChangeTest() {
+ view.settingsPanel.changePlayerTypeEvent.emit(0, TurnControlFactory.Type.COMPUTER);
+ view.settingsPanel.changePlayerTypeEvent.emit(1, TurnControlFactory.Type.COMPUTER);
+ view.settingsPanel.changePlayerTypeEvent.emit(1, TurnControlFactory.Type.HUMAN);
+ view.settingsPanel.startGameEvent.emit();
+ assertNotNull(gameSettings);
+ assertEquals(2, gameSettings.getPlayerList().size());
+ assertSame(TurnControlFactory.Type.COMPUTER, gameSettings.getPlayerList().get(0).getTurnControlType());
+ assertSame(TurnControlFactory.Type.HUMAN, gameSettings.getPlayerList().get(1).getTurnControlType());
+ }
+
}