From d05b93990f607f0ee92003dd0e55bfe3b450e359 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Mon, 9 May 2011 20:15:19 +0200 Subject: Implemented range selecting git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@191 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/TurnControl.java | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/jrummikub') diff --git a/src/jrummikub/control/TurnControl.java b/src/jrummikub/control/TurnControl.java index a208ede..cb18f5e 100644 --- a/src/jrummikub/control/TurnControl.java +++ b/src/jrummikub/control/TurnControl.java @@ -98,6 +98,14 @@ public class TurnControl { tableSetClick(stone, collect); } })); + connections.add(view.getTablePanel().getRangeClickEvent() + .add(new IListener2() { + + @Override + public void handle(Stone stone, Boolean collect) { + tableRangeClick(stone, collect); + } + })); connections.add(view.getTablePanel().getClickEvent() .add(new IListener1() { @@ -197,6 +205,38 @@ public class TurnControl { view.setSelectedStones(selectedStones); } + private void tableRangeClick(Stone stone, Boolean collect) { + if (selectedStones.isEmpty()) { + stoneClick(stone, collect); + return; + } + Stone lastStone = selectedStones.get(selectedStones.size()-1); + StoneSet lastSet = table.findStoneSet(lastStone); + StoneSet selectedSet = table.findStoneSet(stone); + if (lastSet != selectedSet) { + stoneClick(stone, collect); + return; + } + List setStones = new ArrayList(); + for (Stone s : selectedSet) { + setStones.add(s); + } + int firstIndex = setStones.indexOf(lastStone); + int lastIndex = setStones.indexOf(stone); + if (firstIndex > lastIndex) { + int temp = firstIndex; + firstIndex = lastIndex; + lastIndex = temp; + } + for (int i = firstIndex; i <= lastIndex; i++) { + Stone s = setStones.get(i); + selectedStones.remove(s); + selectedStones.add(s); + } + + view.setSelectedStones(selectedStones); + } + private void connectorClick(StoneSet set, boolean right) { List stones = new LinkedList(); Position pos = table.getPosition(set); -- cgit v1.2.3