Changed TurnControl to use Connections to remove listeners
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@153 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
5917f88a02
commit
8c65bafde4
1 changed files with 11 additions and 5 deletions
|
@ -1,7 +1,11 @@
|
|||
package jrummikub.control;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import jrummikub.model.IHand;
|
||||
import jrummikub.model.ITable;
|
||||
import jrummikub.util.Connection;
|
||||
import jrummikub.util.Event;
|
||||
import jrummikub.util.IEvent;
|
||||
import jrummikub.util.IListener;
|
||||
|
@ -13,7 +17,7 @@ public class TurnControl {
|
|||
private ITurnTimer timer;
|
||||
private IView view;
|
||||
private Event endOfTurnEvent = new Event();
|
||||
IListener endOfTurnListener;
|
||||
List<Connection> connections = new ArrayList<Connection>();
|
||||
|
||||
public TurnControl(IHand hand, ITable table, IView view) {
|
||||
this.hand = hand;
|
||||
|
@ -32,15 +36,15 @@ public class TurnControl {
|
|||
|
||||
public void startTurn() {
|
||||
|
||||
endOfTurnListener = new IListener() {
|
||||
IListener endOfTurnListener = new IListener() {
|
||||
|
||||
@Override
|
||||
public void handle() {
|
||||
endOfTurn();
|
||||
}
|
||||
};
|
||||
timer.getTimeRunOutEvent().add(endOfTurnListener);
|
||||
view.getPlayerPanel().getEndTurnEvent().add(endOfTurnListener);
|
||||
connections.add(timer.getTimeRunOutEvent().add(endOfTurnListener));
|
||||
connections.add(view.getPlayerPanel().getEndTurnEvent().add(endOfTurnListener));
|
||||
|
||||
view.getPlayerPanel().getHandPanel().setStones(hand.clone());
|
||||
view.enableStartTurnPanel(false);
|
||||
|
@ -59,7 +63,9 @@ public class TurnControl {
|
|||
private void endOfTurn() {
|
||||
timer.stopTimer();
|
||||
endOfTurnEvent.emit();
|
||||
view.getPlayerPanel().getEndTurnEvent().remove(endOfTurnListener);
|
||||
for (Connection c : connections) {
|
||||
c.remove();
|
||||
}
|
||||
}
|
||||
|
||||
public IEvent getEndOfTurnEvent() {
|
||||
|
|
Reference in a new issue