Implemented range selecting
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@191 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
daebef77d8
commit
d05b93990f
1 changed files with 40 additions and 0 deletions
|
@ -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);
|
||||
|
|
Reference in a new issue