Ticket #5457: SelectAction.java.patch
| File SelectAction.java.patch, 7.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 import java.util.List;20 20 import java.util.Set; 21 21 import java.util.TreeSet; 22 22 … … 337 337 @Override public void mousePressed(MouseEvent e) { 338 338 if(!Main.map.mapView.isActiveLayerVisible()) 339 339 return; 340 340 341 // request focus in order to enable the expected keyboard shortcuts 341 //342 342 Main.map.mapView.requestFocus(); 343 343 344 344 cancelDrawMode = false; … … 346 346 if (e.getButton() != MouseEvent.BUTTON1) 347 347 return; 348 348 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 349 boolean alt = (e.getModifiers() & (ActionEvent.ALT_MASK|InputEvent.ALT_GRAPH_MASK)) != 0;349 /*boolean alt = (e.getModifiers() & (ActionEvent.ALT_MASK|InputEvent.ALT_GRAPH_MASK)) != 0;*/ 350 350 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 351 351 352 352 // We don't want to change to draw tool if the user tries to (de)select … … 359 359 didMove = false; 360 360 initialMoveThresholdExceeded = false; 361 361 362 Collection<OsmPrimitive> osmColl = getNearestCollectionVirtual(e.getPoint(), alt);362 Collection<OsmPrimitive> osmColl = getNearestCollectionVirtual(e.getPoint(), false /*, alt*/); 363 363 364 364 if (ctrl && shift) { 365 365 if (getCurrentDataSet().getSelected().isEmpty()) { … … 420 420 if (mode == Mode.move) { 421 421 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 422 422 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 423 boolean alt = (e.getModifiers() & (ActionEvent.ALT_MASK|InputEvent.ALT_GRAPH_MASK)) != 0 424 || Main.pref.getBoolean("selectaction.rotates", false); 423 425 if (!didMove) { 424 selectPrims( 425 Main.map.mapView.getNearestCollection(e.getPoint(), OsmPrimitive.isSelectablePredicate), 426 shift, ctrl, true, false); 426 Collection<OsmPrimitive> c = Main.map.mapView.getNearestCollection(e.getPoint(), OsmPrimitive.isSelectablePredicate); 427 if (!c.isEmpty() && alt) { 428 if (c.iterator().next() instanceof Node) { 429 // there is at least one node under the cursor: 430 // - make sure (first element of new list) equals (result of getNearestCollection) 431 // - do not consider ways at all, but all nearest nodes 432 c = new ArrayList<OsmPrimitive>(); 433 for (OsmPrimitive p : Main.map.mapView.getAllNearest(e.getPoint(), OsmPrimitive.isSelectablePredicate)) { 434 if (p instanceof Node) { 435 c.add(p); 436 } 437 } 438 } else { 439 // consider all ways.. 440 c = Main.map.mapView.getAllNearest(e.getPoint(), OsmPrimitive.isSelectablePredicate); 441 } 442 } 443 selectPrims(c, shift, ctrl, true, false); 427 444 428 445 // If the user double-clicked a node, change to draw mode 429 List<OsmPrimitive> sel = new ArrayList<OsmPrimitive>(getCurrentDataSet().getSelected());430 if(e.getClickCount() >=2 && sel.size() == 1 && sel.get(0) instanceof Node) {446 c = getCurrentDataSet().getSelected(); 447 if(e.getClickCount() >=2 && c.size() == 1 && c.iterator().next() instanceof Node) { 431 448 // We need to do it like this as otherwise drawAction will see a double 432 449 // click and switch back to SelectMode 433 450 Main.worker.execute(new Runnable(){ … … 500 517 selectPrims(selectionManager.getObjectsInRectangle(r, alt), shift, ctrl, true, true); 501 518 } 502 519 520 private boolean selMorePrims = false; 521 private OsmPrimitive selCycleStart = null; 522 503 523 public void selectPrims(Collection<OsmPrimitive> selectionList, boolean shift, 504 524 boolean ctrl, boolean released, boolean area) { 505 525 DataSet ds = getCurrentDataSet(); 506 526 if ((shift && ctrl) || (ctrl && !released)) 507 527 return; // not allowed together 508 528 529 // toggle through possible objects on mouse release 530 if (released && !area) { 531 if (selectionList.size() > 1) { 532 Collection<OsmPrimitive> coll = ds.getSelected(); 533 534 OsmPrimitive first, foundInDS, node, nxt; 535 first = nxt = selectionList.iterator().next(); 536 foundInDS = node = null; 537 538 for (Iterator<OsmPrimitive> i = selectionList.iterator(); i.hasNext(); ) { 539 if (selMorePrims && shift) { 540 if (!coll.contains(nxt = i.next())) { 541 break; // take first primitive not in dsSel or last if all contained 542 } 543 } else { 544 if (coll.contains(nxt = i.next())) { 545 foundInDS = nxt; 546 if (selMorePrims || ctrl) { 547 ds.clearSelection(nxt); 548 nxt = i.hasNext() ? i.next() : first; 549 } 550 break; // take next primitive of selList 551 } else if (nxt instanceof Node && node == null) { 552 node = nxt; 553 } 554 } 555 } 556 557 if (ctrl) { 558 if (foundInDS != null) { 559 // a member of selList was foundInDS 560 if (!selectionList.contains(selCycleStart)) { 561 selCycleStart = foundInDS; 562 } 563 // check if selCycleStart == prim (equals next(foundInDS)) 564 if (selCycleStart.equals(nxt)) { 565 ds.addSelected(nxt); // cycle complete, prim toggled below 566 selCycleStart = null; // check: might do w/out ?? 567 } 568 } else { 569 // no member of selList was foundInDS (sets were disjunct), setup for new cycle 570 selCycleStart = nxt = (node != null) ? node : first; 571 } 572 } 573 574 selectionList = new ArrayList<OsmPrimitive>(1); // do not modify the passed object.. 575 selectionList.add(nxt); 576 System.out.println("SelectAction:selectPrims(): truncated selList to id=" + nxt.getId()); 577 } 578 } 579 580 // hard-wiring to false due to performance reasons, should do w/out 581 selMorePrims = (released || area) ? false : ds.getSelected().containsAll(selectionList); 582 509 583 if (ctrl) { 510 584 // Ctrl on an item toggles its selection status, 511 585 // but Ctrl on an *area* just clears those items
