Ticket #5457: SelectAction.java.r3529.patch
| File SelectAction.java.r3529.patch, 5.4 KB (added by , 16 years ago) |
|---|
-
src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
15 15 import java.util.Collection; 16 16 import java.util.Collections; 17 17 import java.util.HashSet; 18 import java.util.Iterator; 18 19 import java.util.LinkedList; 19 20 import java.util.List; 20 21 import java.util.Set; … … 372 373 // selected object (this would break moving of selected groups). 373 374 // We'll do that later in mouseReleased if the user didn't try to 374 375 // move. 376 System.out.println("SelectAction:mousePressed(): id=" + 377 osmColl.iterator().next().getId() + " in sel? " + 378 getCurrentDataSet().getSelected().containsAll(osmColl)); 375 379 selectPrims(osmColl, 376 380 shift || getCurrentDataSet().getSelected().containsAll(osmColl), 377 381 ctrl, false, false); … … 422 426 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 423 427 if (!didMove) { 424 428 selectPrims( 425 Main.map.mapView.get NearestCollection(e.getPoint(), OsmPrimitive.isSelectablePredicate),429 Main.map.mapView.getAllNearest(e.getPoint(), OsmPrimitive.isSelectablePredicate), 426 430 shift, ctrl, true, false); 427 431 428 432 // If the user double-clicked a node, change to draw mode … … 500 504 selectPrims(selectionManager.getObjectsInRectangle(r, alt), shift, ctrl, true, true); 501 505 } 502 506 507 private boolean lookForMore = false; 508 private OsmPrimitive ctrlStart = null; 509 503 510 public void selectPrims(Collection<OsmPrimitive> selectionList, boolean shift, 504 511 boolean ctrl, boolean released, boolean area) { 505 512 DataSet ds = getCurrentDataSet(); 506 513 if ((shift && ctrl) || (ctrl && !released)) 507 514 return; // not allowed together 508 515 516 // toggle through possible objects on mouse release 517 if (released && !area) { 518 if (selectionList.size() > 1) { 519 Collection<OsmPrimitive> coll = ds.getSelected(); 520 OsmPrimitive o = selectionList.iterator().next(), first = o, fsel = null; 521 522 for (Iterator<OsmPrimitive> i = selectionList.iterator(); i.hasNext(); ) { 523 if (lookForMore && shift) { 524 if (!coll.contains(o = i.next())) { 525 break; // take first not in dsSel (or last) 526 } 527 } else { 528 if (coll.contains(o = i.next())) { 529 fsel = o; 530 if (lookForMore || ctrl) { 531 ds.clearSelection(o); 532 o = i.hasNext() ? i.next() : first; 533 } 534 break; // take first found 535 } 536 } 537 } 538 539 if (ctrl) { 540 if (fsel != null) { 541 // fsel was found in dsSel, succ(fsel) == o holds 542 if (ctrlStart == null) { 543 ctrlStart = fsel; 544 } 545 if (o.equals(ctrlStart)) { 546 // user clicked his way through all possible completions 547 // now add o, so we also get a deselect step in rotation 548 ds.addSelected(o); 549 ctrlStart = null; 550 } 551 } else { 552 // selList and dsSel were disjunct, take o (first in rotation) 553 ctrlStart = o; 554 } 555 } else { 556 ctrlStart = null; 557 } 558 559 selectionList.clear(); 560 selectionList.add(o); 561 System.out.println("SelectAction:selectPrims(): truncating selList to id=" + o.getId()); 562 } 563 } 564 509 565 if (ctrl) { 510 566 // Ctrl on an item toggles its selection status, 511 567 // but Ctrl on an *area* just clears those items 512 568 // out of the selection. 513 569 if (area) { 514 570 ds.clearSelection(selectionList); 571 System.out.println("SelectAction:selectPrims(): clearing selList from dsSel"); 515 572 } else { 516 573 ds.toggleSelected(selectionList); 574 System.out.println("SelectAction:selectPrims(): toggling selList in dsSel"); 517 575 } 518 576 } else { 577 // hard-wiring to false due to performance reasons, should do w/out 578 lookForMore = (released || area) ? false : ds.getSelected().containsAll(selectionList); 579 519 580 // plain clicks with no modifiers 520 581 if (!shift) { 521 582 ds.setSelected(selectionList); 583 System.out.println("SelectAction:selectPrims(): replacing dsSel w/ selList"); 522 584 } else { 523 585 // add things to an 524 586 // existing selection. 525 587 ds.addSelected(selectionList); 588 System.out.println("SelectAction:selectPrims(): adding selList to dsSel"); 526 589 } 527 590 } 528 591 }
