diff options
Diffstat (limited to 'src/jrummikub')
-rw-r--r-- | src/jrummikub/control/TurnControl.java | 40 |
1 files changed, 40 insertions, 0 deletions
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<Stone, Boolean>() { + + @Override + public void handle(Stone stone, Boolean collect) { + tableRangeClick(stone, collect); + } + })); connections.add(view.getTablePanel().getClickEvent() .add(new IListener1<Position>() { @@ -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<Stone> setStones = new ArrayList<Stone>(); + 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<Stone> stones = new LinkedList<Stone>(); Position pos = table.getPosition(set); |