summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-05-09 20:15:19 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-05-09 20:15:19 +0200
commitd05b93990f607f0ee92003dd0e55bfe3b450e359 (patch)
tree0135afbf36f3ea89275f7e0b356c0536a2f44a74
parentdaebef77d892755bdf4287ed5aa63aa0e1ab35ec (diff)
downloadJRummikub-d05b93990f607f0ee92003dd0e55bfe3b450e359.tar
JRummikub-d05b93990f607f0ee92003dd0e55bfe3b450e359.zip
Implemented range selecting
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@191 72836036-5685-4462-b002-a69064685172
-rw-r--r--src/jrummikub/control/TurnControl.java40
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);