Move getHandPanel from IPlayerPanel to IView

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@245 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-05-16 22:09:56 +02:00
parent 604ef91282
commit a4f5beb005
8 changed files with 81 additions and 72 deletions

View file

@ -10,18 +10,10 @@ public class MockPlayerPanel implements IPlayerPanel {
/** */ /** */
public MockEvent endTurnEvent = new MockEvent(); public MockEvent endTurnEvent = new MockEvent();
/** */ /** */
public MockHandPanel handPanel = new MockHandPanel();
/** */
public MockEvent sortByGroupsEvent = new MockEvent(); public MockEvent sortByGroupsEvent = new MockEvent();
/** */ /** */
public MockEvent sortByRunsEvent = new MockEvent(); public MockEvent sortByRunsEvent = new MockEvent();
@Override
public IHandPanel getHandPanel() {
// TODO Auto-generated method stub
return handPanel;
}
@Override @Override
public void setTimeLeft(int time) { public void setTimeLeft(int time) {
// TODO Auto-generated method stub // TODO Auto-generated method stub

View file

@ -5,6 +5,7 @@ import java.util.Collection;
import jrummikub.model.Stone; import jrummikub.model.Stone;
import jrummikub.util.IEvent; import jrummikub.util.IEvent;
import jrummikub.util.MockEvent; import jrummikub.util.MockEvent;
/** /**
* Mock class for View * Mock class for View
*/ */
@ -13,6 +14,8 @@ public class MockView implements IView {
public MockPlayerPanel playerPanel = new MockPlayerPanel(); public MockPlayerPanel playerPanel = new MockPlayerPanel();
/** */ /** */
public MockTablePanel tablePanel = new MockTablePanel(); public MockTablePanel tablePanel = new MockTablePanel();
/** */
public MockHandPanel handPanel = new MockHandPanel();
/** */ /** */
public Collection<Stone> selectedStones; public Collection<Stone> selectedStones;
@ -41,6 +44,11 @@ public class MockView implements IView {
return playerPanel; return playerPanel;
} }
@Override
public MockHandPanel getHandPanel() {
return handPanel;
}
@Override @Override
public void setCurrentPlayerName(String playerName) { public void setCurrentPlayerName(String playerName) {
currentPlayerName = playerName; currentPlayerName = playerName;

View file

@ -98,15 +98,15 @@ public class TurnControl {
} }
})); }));
view.getPlayerPanel().getHandPanel().setStones(hand.clone()); view.getHandPanel().setStones(hand.clone());
view.getPlayerPanel().getHandPanel().resetCurrentRow(); view.getHandPanel().resetCurrentRow();
view.enableStartTurnPanel(false); view.enableStartTurnPanel(false);
timer.startTimer(); timer.startTimer();
} }
private void addHandPanelHandlers() { private void addHandPanelHandlers() {
connections.add(view.getPlayerPanel().getHandPanel().getClickEvent() connections.add(view.getHandPanel().getClickEvent()
.add(new IListener1<Position>() { .add(new IListener1<Position>() {
@Override @Override
public void handle(Position pos) { public void handle(Position pos) {
@ -114,7 +114,7 @@ public class TurnControl {
} }
})); }));
connections.add(view.getPlayerPanel().getHandPanel().getStoneClickEvent() connections.add(view.getHandPanel().getStoneClickEvent()
.add(new IListener2<Stone, Boolean>() { .add(new IListener2<Stone, Boolean>() {
@Override @Override
@ -123,7 +123,7 @@ public class TurnControl {
} }
})); }));
connections.add(view.getPlayerPanel().getHandPanel().getRangeClickEvent() connections.add(view.getHandPanel().getRangeClickEvent()
.add(new IListener2<Stone, Boolean>() { .add(new IListener2<Stone, Boolean>() {
@Override @Override
@ -227,7 +227,7 @@ public class TurnControl {
i++; i++;
} }
view.setSelectedStones(selectedStones); view.setSelectedStones(selectedStones);
view.getPlayerPanel().getHandPanel().setStones(hand); view.getHandPanel().setStones(hand);
} }
private void sortStones(Comparator<Stone> comparator) { private void sortStones(Comparator<Stone> comparator) {
@ -250,7 +250,7 @@ public class TurnControl {
} }
} }
view.getPlayerPanel().getHandPanel().setStones(hand); view.getHandPanel().setStones(hand);
} }
private void sortByRuns() { private void sortByRuns() {
@ -307,7 +307,7 @@ public class TurnControl {
selectedStones.clear(); selectedStones.clear();
view.getTablePanel().setStoneSets(table); view.getTablePanel().setStoneSets(table);
view.getPlayerPanel().getHandPanel().setStones(hand); view.getHandPanel().setStones(hand);
view.setSelectedStones(selectedStones); view.setSelectedStones(selectedStones);
} }
@ -433,7 +433,7 @@ public class TurnControl {
selectedStones.clear(); selectedStones.clear();
view.getTablePanel().setStoneSets(table); view.getTablePanel().setStoneSets(table);
view.getPlayerPanel().getHandPanel().setStones(hand); view.getHandPanel().setStones(hand);
view.setSelectedStones(selectedStones); view.setSelectedStones(selectedStones);
} }

View file

@ -6,11 +6,6 @@ import jrummikub.util.IEvent;
* The player panel that contains a player's board and other user interfaces * The player panel that contains a player's board and other user interfaces
*/ */
public interface IPlayerPanel { public interface IPlayerPanel {
/**
* @return the board where the players hand stones are displayed
*/
public IHandPanel getHandPanel();
/** /**
* Sets the time the player has left for his turn * Sets the time the player has left for his turn
* *

View file

@ -16,6 +16,11 @@ public interface IView {
*/ */
public ITablePanel getTablePanel(); public ITablePanel getTablePanel();
/**
* @return the board where the players hand stones are displayed
*/
public IHandPanel getHandPanel();
/** /**
* Returns the player panel * Returns the player panel
* *

View file

@ -49,8 +49,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
private Event sortByRunsEvent = new Event(); private Event sortByRunsEvent = new Event();
private Event endTurnEvent = new Event(); private Event endTurnEvent = new Event();
@Override HandPanel getHandPanel() {
public HandPanel getHandPanel() {
return hand; return hand;
} }

View file

@ -11,6 +11,7 @@ import javax.swing.border.MatteBorder;
import jrummikub.model.Stone; import jrummikub.model.Stone;
import jrummikub.util.IEvent; import jrummikub.util.IEvent;
import jrummikub.view.IHandPanel;
import jrummikub.view.IPlayerPanel; import jrummikub.view.IPlayerPanel;
import jrummikub.view.ITablePanel; import jrummikub.view.ITablePanel;
import jrummikub.view.IView; import jrummikub.view.IView;
@ -38,6 +39,11 @@ public class View extends JFrame implements IView {
return table; return table;
} }
@Override
public IHandPanel getHandPanel() {
return playerPanel.getHandPanel();
}
@Override @Override
public IPlayerPanel getPlayerPanel() { public IPlayerPanel getPlayerPanel() {
return playerPanel; return playerPanel;

View file

@ -85,7 +85,7 @@ public class TurnControlTest {
} }
private void checkHandDisplay(IHand hand) { private void checkHandDisplay(IHand hand) {
Iterator<Pair<Stone, Position>> stoneSetsView = mockView.playerPanel.handPanel.stones Iterator<Pair<Stone, Position>> stoneSetsView = mockView.handPanel.stones
.iterator(); .iterator();
Iterator<Pair<Stone, Position>> stoneSetsModel = hand.iterator(); Iterator<Pair<Stone, Position>> stoneSetsModel = hand.iterator();
@ -131,7 +131,7 @@ public class TurnControlTest {
testControl.startTurn(); testControl.startTurn();
int i = 0; int i = 0;
for (Pair<Stone, Position> pair : mockView.playerPanel.handPanel.stones) { for (Pair<Stone, Position> pair : mockView.handPanel.stones) {
assertSame(stones.get(i), pair); assertSame(stones.get(i), pair);
i++; i++;
} }
@ -193,7 +193,7 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED); Stone firstStone = new Stone(StoneColor.RED);
// Select first stone // Select first stone
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, false); mockView.handPanel.stoneClickEvent.emit(firstStone, false);
mockTimer.timeRunOutEvent.emit(); mockTimer.timeRunOutEvent.emit();
assertCollection(new ArrayList<Stone>()); assertCollection(new ArrayList<Stone>());
@ -207,13 +207,13 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED); Stone firstStone = new Stone(StoneColor.RED);
// Select first stone // Select first stone
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, false); mockView.handPanel.stoneClickEvent.emit(firstStone, false);
assertCollection(Arrays.asList(firstStone)); assertCollection(Arrays.asList(firstStone));
// Select second stone // Select second stone
Stone secondStone = new Stone(StoneColor.BLACK); Stone secondStone = new Stone(StoneColor.BLACK);
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, false); mockView.handPanel.stoneClickEvent.emit(secondStone, false);
assertCollection(Arrays.asList(secondStone)); assertCollection(Arrays.asList(secondStone));
@ -227,18 +227,18 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED); Stone firstStone = new Stone(StoneColor.RED);
// Select first stone // Select first stone
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true); mockView.handPanel.stoneClickEvent.emit(firstStone, true);
assertCollection(Arrays.asList(firstStone)); assertCollection(Arrays.asList(firstStone));
// Select second stone // Select second stone
Stone secondStone = new Stone(StoneColor.BLACK); Stone secondStone = new Stone(StoneColor.BLACK);
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true); mockView.handPanel.stoneClickEvent.emit(secondStone, true);
assertCollection(Arrays.asList(firstStone, secondStone)); assertCollection(Arrays.asList(firstStone, secondStone));
// De-select first stone // De-select first stone
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true); mockView.handPanel.stoneClickEvent.emit(firstStone, true);
assertCollection(Arrays.asList(secondStone)); assertCollection(Arrays.asList(secondStone));
} }
@ -251,8 +251,8 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED); Stone firstStone = new Stone(StoneColor.RED);
Stone secondStone = new Stone(StoneColor.BLACK); Stone secondStone = new Stone(StoneColor.BLACK);
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true); mockView.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true); mockView.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone, mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
false); false);
@ -268,8 +268,8 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED); Stone firstStone = new Stone(StoneColor.RED);
Stone secondStone = new Stone(StoneColor.BLACK); Stone secondStone = new Stone(StoneColor.BLACK);
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true); mockView.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true); mockView.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone, mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
true); true);
@ -285,8 +285,8 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED); Stone firstStone = new Stone(StoneColor.RED);
Stone secondStone = new Stone(StoneColor.BLACK); Stone secondStone = new Stone(StoneColor.BLACK);
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true); mockView.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true); mockView.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone, mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
true); true);
@ -516,8 +516,8 @@ public class TurnControlTest {
mockHand.drop(stone3, new Position(0, 1)); mockHand.drop(stone3, new Position(0, 1));
mockHand.drop(stone4, new Position(1, 1)); mockHand.drop(stone4, new Position(1, 1));
mockView.playerPanel.handPanel.stoneClickEvent.emit(stone3, false); mockView.handPanel.stoneClickEvent.emit(stone3, false);
mockView.playerPanel.handPanel.rangeClickEvent.emit(stone1, true); mockView.handPanel.rangeClickEvent.emit(stone1, true);
assertCollection(Arrays.asList(stone1, stone2, stone3)); assertCollection(Arrays.asList(stone1, stone2, stone3));
} }
@ -536,8 +536,8 @@ public class TurnControlTest {
mockHand.drop(stone3, new Position(0, 1)); mockHand.drop(stone3, new Position(0, 1));
mockHand.drop(stone4, new Position(1, 1)); mockHand.drop(stone4, new Position(1, 1));
mockView.playerPanel.handPanel.stoneClickEvent.emit(stone1, false); mockView.handPanel.stoneClickEvent.emit(stone1, false);
mockView.playerPanel.handPanel.rangeClickEvent.emit(stone3, true); mockView.handPanel.rangeClickEvent.emit(stone3, true);
assertCollection(Arrays.asList(stone1, stone2, stone3)); assertCollection(Arrays.asList(stone1, stone2, stone3));
} }
@ -558,10 +558,10 @@ public class TurnControlTest {
mockHand.drop(stone3, new Position(0, 1)); mockHand.drop(stone3, new Position(0, 1));
mockHand.drop(stone4, new Position(1, 1)); mockHand.drop(stone4, new Position(1, 1));
mockView.playerPanel.handPanel.stoneClickEvent.emit(extraStone, false); mockView.handPanel.stoneClickEvent.emit(extraStone, false);
mockView.playerPanel.handPanel.stoneClickEvent.emit(stone1, true); mockView.handPanel.stoneClickEvent.emit(stone1, true);
mockView.playerPanel.handPanel.rangeClickEvent.emit(stone3, false); mockView.handPanel.rangeClickEvent.emit(stone3, false);
assertCollection(Arrays.asList(extraStone, stone1, stone2, stone3)); assertCollection(Arrays.asList(extraStone, stone1, stone2, stone3));
} }
@ -581,7 +581,7 @@ public class TurnControlTest {
assertCollection(Arrays.asList(stone1)); assertCollection(Arrays.asList(stone1));
// Select second stone // Select second stone
mockView.playerPanel.handPanel.rangeClickEvent.emit(stone2, false); mockView.handPanel.rangeClickEvent.emit(stone2, false);
assertCollection(Arrays.asList(stone1, stone2)); assertCollection(Arrays.asList(stone1, stone2));
@ -603,7 +603,7 @@ public class TurnControlTest {
assertCollection(Arrays.asList(stone1)); assertCollection(Arrays.asList(stone1));
// Select second stone // Select second stone
mockView.playerPanel.handPanel.rangeClickEvent.emit(stone2, true); mockView.handPanel.rangeClickEvent.emit(stone2, true);
assertCollection(Arrays.asList(stone1, stone2)); assertCollection(Arrays.asList(stone1, stone2));
} }
@ -643,7 +643,7 @@ public class TurnControlTest {
table.drop(oldSet2, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0)); mockHand.drop(blueThree, new Position(0, 0));
mockHand.drop(blueFour, new Position(0, 0)); mockHand.drop(blueFour, new Position(0, 0));
mockView.playerPanel.handPanel.stoneClickEvent.emit(blueThree, false); mockView.handPanel.stoneClickEvent.emit(blueThree, false);
mockView.tablePanel.stoneClickEvent.emit(redOne, true); mockView.tablePanel.stoneClickEvent.emit(redOne, true);
mockView.tablePanel.stoneClickEvent.emit(redThree, true); mockView.tablePanel.stoneClickEvent.emit(redThree, true);
mockView.tablePanel.leftConnectorClickEvent.emit(oldSet1); mockView.tablePanel.leftConnectorClickEvent.emit(oldSet1);
@ -705,7 +705,7 @@ public class TurnControlTest {
assertSame(newSet2.get(3), blackFour); assertSame(newSet2.get(3), blackFour);
assertSame(newSet2.get(4), blackFive); assertSame(newSet2.get(4), blackFive);
// versuche, links was wegzunehmen und wieder anzuhängen // versuche, links was wegzunehmen und wieder anzuhängen
mockView.playerPanel.handPanel.stoneClickEvent.emit(blueFour, false); mockView.handPanel.stoneClickEvent.emit(blueFour, false);
mockView.tablePanel.stoneClickEvent.emit(redOne, true); mockView.tablePanel.stoneClickEvent.emit(redOne, true);
mockView.tablePanel.leftConnectorClickEvent.emit(newSet2); mockView.tablePanel.leftConnectorClickEvent.emit(newSet2);
@ -760,7 +760,7 @@ public class TurnControlTest {
table.drop(oldSet2, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0)); mockHand.drop(blueThree, new Position(0, 0));
mockHand.drop(blueFour, new Position(0, 0)); mockHand.drop(blueFour, new Position(0, 0));
mockView.playerPanel.handPanel.stoneClickEvent.emit(blueThree, false); mockView.handPanel.stoneClickEvent.emit(blueThree, false);
mockView.tablePanel.stoneClickEvent.emit(redOne, true); mockView.tablePanel.stoneClickEvent.emit(redOne, true);
mockView.tablePanel.stoneClickEvent.emit(redThree, true); mockView.tablePanel.stoneClickEvent.emit(redThree, true);
mockView.tablePanel.rightConnectorClickEvent.emit(oldSet1); mockView.tablePanel.rightConnectorClickEvent.emit(oldSet1);
@ -822,7 +822,7 @@ public class TurnControlTest {
assertSame(newSet2.get(3), redOne); assertSame(newSet2.get(3), redOne);
assertSame(newSet2.get(4), redThree); assertSame(newSet2.get(4), redThree);
// versuche, rechts was wegzunehmen und wieder anzuhängen // versuche, rechts was wegzunehmen und wieder anzuhängen
mockView.playerPanel.handPanel.stoneClickEvent.emit(blueFour, false); mockView.handPanel.stoneClickEvent.emit(blueFour, false);
mockView.tablePanel.stoneClickEvent.emit(redThree, true); mockView.tablePanel.stoneClickEvent.emit(redThree, true);
mockView.tablePanel.rightConnectorClickEvent.emit(newSet2); mockView.tablePanel.rightConnectorClickEvent.emit(newSet2);
@ -877,7 +877,7 @@ public class TurnControlTest {
table.drop(oldSet2, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0)); mockHand.drop(blueThree, new Position(0, 0));
mockHand.drop(blueFour, new Position(0, 0)); mockHand.drop(blueFour, new Position(0, 0));
mockView.playerPanel.handPanel.stoneClickEvent.emit(blueThree, false); mockView.handPanel.stoneClickEvent.emit(blueThree, false);
mockView.tablePanel.stoneClickEvent.emit(redOne, true); mockView.tablePanel.stoneClickEvent.emit(redOne, true);
mockView.tablePanel.stoneClickEvent.emit(redThree, true); mockView.tablePanel.stoneClickEvent.emit(redThree, true);
mockView.tablePanel.stoneClickEvent.emit(blueTwo, true); mockView.tablePanel.stoneClickEvent.emit(blueTwo, true);
@ -939,6 +939,7 @@ public class TurnControlTest {
checkTableDisplay(table); checkTableDisplay(table);
checkHandDisplay(mockHand); checkHandDisplay(mockHand);
} }
/** */ /** */
@Test @Test
public void testSortByGroups() { public void testSortByGroups() {
@ -1072,14 +1073,15 @@ public class TurnControlTest {
mockHand.drop(firstStone, new Position(0, 0)); mockHand.drop(firstStone, new Position(0, 0));
mockHand.drop(secondStone, new Position(1, 0)); mockHand.drop(secondStone, new Position(1, 0));
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true); mockView.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true); mockView.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.playerPanel.handPanel.clickEvent.emit(new Position(2,0.25f)); mockView.handPanel.clickEvent.emit(new Position(2, 0.25f));
assertCollection(new ArrayList<Stone>()); assertCollection(new ArrayList<Stone>());
Set<Stone> expected = new HashSet<Stone>(Arrays.asList(firstStone, secondStone)); Set<Stone> expected = new HashSet<Stone>(Arrays.asList(firstStone,
secondStone));
assertEquals(expected, mockHand.pickups); assertEquals(expected, mockHand.pickups);
Set<Stone> handStones = new HashSet<Stone>(); Set<Stone> handStones = new HashSet<Stone>();
@ -1089,6 +1091,7 @@ public class TurnControlTest {
} }
assertEquals(expected, handStones); assertEquals(expected, handStones);
} }
/** */ /** */
@Test @Test
public void testDropHandInvalid() { public void testDropHandInvalid() {
@ -1101,15 +1104,16 @@ public class TurnControlTest {
mockHand.drop(firstStone, new Position(0, 0)); mockHand.drop(firstStone, new Position(0, 0));
mockHand.drop(thirdStone, new Position(1, 0)); mockHand.drop(thirdStone, new Position(1, 0));
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true); mockView.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.tablePanel.stoneClickEvent.emit(secondStone, true); mockView.tablePanel.stoneClickEvent.emit(secondStone, true);
mockView.playerPanel.handPanel.stoneClickEvent.emit(thirdStone, true); mockView.handPanel.stoneClickEvent.emit(thirdStone, true);
mockView.playerPanel.handPanel.clickEvent.emit(new Position(2,0.25f)); mockView.handPanel.clickEvent.emit(new Position(2, 0.25f));
assertCollection(Arrays.asList(secondStone)); assertCollection(Arrays.asList(secondStone));
Set<Stone> expected = new HashSet<Stone>(Arrays.asList(firstStone, thirdStone)); Set<Stone> expected = new HashSet<Stone>(Arrays.asList(firstStone,
thirdStone));
assertEquals(expected, mockHand.pickups); assertEquals(expected, mockHand.pickups);
Set<Stone> handStones = new HashSet<Stone>(); Set<Stone> handStones = new HashSet<Stone>();