From 8c65bafde4ec05718433791915bcbf3c838e90a6 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Thu, 5 May 2011 19:56:47 +0200 Subject: 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 --- src/jrummikub/control/TurnControl.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/jrummikub/control/TurnControl.java b/src/jrummikub/control/TurnControl.java index 417c7b4..840b0e9 100644 --- a/src/jrummikub/control/TurnControl.java +++ b/src/jrummikub/control/TurnControl.java @@ -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 connections = new ArrayList(); 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() { -- cgit v1.2.3