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 MockHandPanel handPanel = new MockHandPanel();
/** */
public MockEvent sortByGroupsEvent = new MockEvent();
/** */
public MockEvent sortByRunsEvent = new MockEvent();
@Override
public IHandPanel getHandPanel() {
// TODO Auto-generated method stub
return handPanel;
}
@Override
public void setTimeLeft(int time) {
// TODO Auto-generated method stub

View file

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

View file

@ -98,15 +98,15 @@ public class TurnControl {
}
}));
view.getPlayerPanel().getHandPanel().setStones(hand.clone());
view.getPlayerPanel().getHandPanel().resetCurrentRow();
view.getHandPanel().setStones(hand.clone());
view.getHandPanel().resetCurrentRow();
view.enableStartTurnPanel(false);
timer.startTimer();
}
private void addHandPanelHandlers() {
connections.add(view.getPlayerPanel().getHandPanel().getClickEvent()
connections.add(view.getHandPanel().getClickEvent()
.add(new IListener1<Position>() {
@Override
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>() {
@Override
@ -123,7 +123,7 @@ public class TurnControl {
}
}));
connections.add(view.getPlayerPanel().getHandPanel().getRangeClickEvent()
connections.add(view.getHandPanel().getRangeClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
@ -227,7 +227,7 @@ public class TurnControl {
i++;
}
view.setSelectedStones(selectedStones);
view.getPlayerPanel().getHandPanel().setStones(hand);
view.getHandPanel().setStones(hand);
}
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() {
@ -307,7 +307,7 @@ public class TurnControl {
selectedStones.clear();
view.getTablePanel().setStoneSets(table);
view.getPlayerPanel().getHandPanel().setStones(hand);
view.getHandPanel().setStones(hand);
view.setSelectedStones(selectedStones);
}
@ -433,7 +433,7 @@ public class TurnControl {
selectedStones.clear();
view.getTablePanel().setStoneSets(table);
view.getPlayerPanel().getHandPanel().setStones(hand);
view.getHandPanel().setStones(hand);
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
*/
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
*

View file

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

View file

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

View file

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

View file

@ -85,7 +85,7 @@ public class TurnControlTest {
}
private void checkHandDisplay(IHand hand) {
Iterator<Pair<Stone, Position>> stoneSetsView = mockView.playerPanel.handPanel.stones
Iterator<Pair<Stone, Position>> stoneSetsView = mockView.handPanel.stones
.iterator();
Iterator<Pair<Stone, Position>> stoneSetsModel = hand.iterator();
@ -131,7 +131,7 @@ public class TurnControlTest {
testControl.startTurn();
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);
i++;
}
@ -193,7 +193,7 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED);
// Select first stone
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, false);
mockView.handPanel.stoneClickEvent.emit(firstStone, false);
mockTimer.timeRunOutEvent.emit();
assertCollection(new ArrayList<Stone>());
@ -207,13 +207,13 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED);
// Select first stone
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, false);
mockView.handPanel.stoneClickEvent.emit(firstStone, false);
assertCollection(Arrays.asList(firstStone));
// Select second stone
Stone secondStone = new Stone(StoneColor.BLACK);
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, false);
mockView.handPanel.stoneClickEvent.emit(secondStone, false);
assertCollection(Arrays.asList(secondStone));
@ -227,18 +227,18 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED);
// Select first stone
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.handPanel.stoneClickEvent.emit(firstStone, true);
assertCollection(Arrays.asList(firstStone));
// Select second stone
Stone secondStone = new Stone(StoneColor.BLACK);
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.handPanel.stoneClickEvent.emit(secondStone, true);
assertCollection(Arrays.asList(firstStone, secondStone));
// De-select first stone
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.handPanel.stoneClickEvent.emit(firstStone, true);
assertCollection(Arrays.asList(secondStone));
}
@ -251,8 +251,8 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED);
Stone secondStone = new Stone(StoneColor.BLACK);
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
false);
@ -268,8 +268,8 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED);
Stone secondStone = new Stone(StoneColor.BLACK);
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
true);
@ -285,8 +285,8 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED);
Stone secondStone = new Stone(StoneColor.BLACK);
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
true);
@ -516,8 +516,8 @@ public class TurnControlTest {
mockHand.drop(stone3, new Position(0, 1));
mockHand.drop(stone4, new Position(1, 1));
mockView.playerPanel.handPanel.stoneClickEvent.emit(stone3, false);
mockView.playerPanel.handPanel.rangeClickEvent.emit(stone1, true);
mockView.handPanel.stoneClickEvent.emit(stone3, false);
mockView.handPanel.rangeClickEvent.emit(stone1, true);
assertCollection(Arrays.asList(stone1, stone2, stone3));
}
@ -536,8 +536,8 @@ public class TurnControlTest {
mockHand.drop(stone3, new Position(0, 1));
mockHand.drop(stone4, new Position(1, 1));
mockView.playerPanel.handPanel.stoneClickEvent.emit(stone1, false);
mockView.playerPanel.handPanel.rangeClickEvent.emit(stone3, true);
mockView.handPanel.stoneClickEvent.emit(stone1, false);
mockView.handPanel.rangeClickEvent.emit(stone3, true);
assertCollection(Arrays.asList(stone1, stone2, stone3));
}
@ -558,10 +558,10 @@ public class TurnControlTest {
mockHand.drop(stone3, new Position(0, 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.playerPanel.handPanel.rangeClickEvent.emit(stone3, false);
mockView.handPanel.stoneClickEvent.emit(stone1, true);
mockView.handPanel.rangeClickEvent.emit(stone3, false);
assertCollection(Arrays.asList(extraStone, stone1, stone2, stone3));
}
@ -581,7 +581,7 @@ public class TurnControlTest {
assertCollection(Arrays.asList(stone1));
// Select second stone
mockView.playerPanel.handPanel.rangeClickEvent.emit(stone2, false);
mockView.handPanel.rangeClickEvent.emit(stone2, false);
assertCollection(Arrays.asList(stone1, stone2));
@ -603,7 +603,7 @@ public class TurnControlTest {
assertCollection(Arrays.asList(stone1));
// Select second stone
mockView.playerPanel.handPanel.rangeClickEvent.emit(stone2, true);
mockView.handPanel.rangeClickEvent.emit(stone2, true);
assertCollection(Arrays.asList(stone1, stone2));
}
@ -643,7 +643,7 @@ public class TurnControlTest {
table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, 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(redThree, true);
mockView.tablePanel.leftConnectorClickEvent.emit(oldSet1);
@ -705,7 +705,7 @@ public class TurnControlTest {
assertSame(newSet2.get(3), blackFour);
assertSame(newSet2.get(4), blackFive);
// 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.leftConnectorClickEvent.emit(newSet2);
@ -760,7 +760,7 @@ public class TurnControlTest {
table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, 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(redThree, true);
mockView.tablePanel.rightConnectorClickEvent.emit(oldSet1);
@ -822,7 +822,7 @@ public class TurnControlTest {
assertSame(newSet2.get(3), redOne);
assertSame(newSet2.get(4), redThree);
// 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.rightConnectorClickEvent.emit(newSet2);
@ -877,7 +877,7 @@ public class TurnControlTest {
table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, 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(redThree, true);
mockView.tablePanel.stoneClickEvent.emit(blueTwo, true);
@ -939,6 +939,7 @@ public class TurnControlTest {
checkTableDisplay(table);
checkHandDisplay(mockHand);
}
/** */
@Test
public void testSortByGroups() {
@ -1060,7 +1061,7 @@ public class TurnControlTest {
checkHandDisplay(mockHand);
}
/** */
@Test
public void testDropHandValid() {
@ -1068,20 +1069,21 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED);
Stone secondStone = new Stone(StoneColor.BLACK);
mockHand.drop(firstStone, new Position(0,0));
mockHand.drop(secondStone, new Position(1,0));
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
mockHand.drop(firstStone, new Position(0, 0));
mockHand.drop(secondStone, new Position(1, 0));
mockView.playerPanel.handPanel.clickEvent.emit(new Position(2,0.25f));
mockView.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.handPanel.clickEvent.emit(new Position(2, 0.25f));
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);
Set<Stone> handStones = new HashSet<Stone>();
for (Pair<Stone, Position> stone : mockHand.stones) {
assertEquals(stone.getSecond().getY(), 0, 0.0001);
@ -1089,6 +1091,7 @@ public class TurnControlTest {
}
assertEquals(expected, handStones);
}
/** */
@Test
public void testDropHandInvalid() {
@ -1097,21 +1100,22 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED);
Stone secondStone = new Stone(StoneColor.BLACK);
Stone thirdStone = new Stone(13, StoneColor.BLACK);
mockHand.drop(firstStone, new Position(0,0));
mockHand.drop(thirdStone, new Position(1,0));
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
mockHand.drop(firstStone, new Position(0, 0));
mockHand.drop(thirdStone, new Position(1, 0));
mockView.handPanel.stoneClickEvent.emit(firstStone, 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));
Set<Stone> expected = new HashSet<Stone>(Arrays.asList(firstStone, thirdStone));
Set<Stone> expected = new HashSet<Stone>(Arrays.asList(firstStone,
thirdStone));
assertEquals(expected, mockHand.pickups);
Set<Stone> handStones = new HashSet<Stone>();
for (Pair<Stone, Position> stone : mockHand.stones) {
assertEquals(stone.getSecond().getY(), 0, 0.0001);
@ -1119,5 +1123,5 @@ public class TurnControlTest {
}
assertEquals(expected, handStones);
}
}