source: josm/trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java@ 12313

Last change on this file since 12313 was 12313, checked in by michael2402, 7 years ago

Fix #14886: We can't use old move command if there is no edit layer.

  • Property svn:eol-style set to native
File size: 50.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions.mapmode;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6import static org.openstreetmap.josm.tools.I18n.trn;
7
8import java.awt.Cursor;
9import java.awt.Point;
10import java.awt.Rectangle;
11import java.awt.event.KeyEvent;
12import java.awt.event.MouseEvent;
13import java.awt.geom.Point2D;
14import java.util.Collection;
15import java.util.Collections;
16import java.util.HashSet;
17import java.util.Iterator;
18import java.util.LinkedList;
19import java.util.Set;
20
21import javax.swing.JOptionPane;
22
23import org.openstreetmap.josm.Main;
24import org.openstreetmap.josm.actions.MergeNodesAction;
25import org.openstreetmap.josm.command.AddCommand;
26import org.openstreetmap.josm.command.ChangeCommand;
27import org.openstreetmap.josm.command.Command;
28import org.openstreetmap.josm.command.MoveCommand;
29import org.openstreetmap.josm.command.RotateCommand;
30import org.openstreetmap.josm.command.ScaleCommand;
31import org.openstreetmap.josm.command.SequenceCommand;
32import org.openstreetmap.josm.data.coor.EastNorth;
33import org.openstreetmap.josm.data.coor.LatLon;
34import org.openstreetmap.josm.data.osm.DataSet;
35import org.openstreetmap.josm.data.osm.Node;
36import org.openstreetmap.josm.data.osm.OsmPrimitive;
37import org.openstreetmap.josm.data.osm.Way;
38import org.openstreetmap.josm.data.osm.WaySegment;
39import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor;
40import org.openstreetmap.josm.data.osm.visitor.paint.WireframeMapRenderer;
41import org.openstreetmap.josm.gui.ExtendedDialog;
42import org.openstreetmap.josm.gui.MapFrame;
43import org.openstreetmap.josm.gui.MapView;
44import org.openstreetmap.josm.gui.MapViewState.MapViewPoint;
45import org.openstreetmap.josm.gui.SelectionManager;
46import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded;
47import org.openstreetmap.josm.gui.layer.Layer;
48import org.openstreetmap.josm.gui.layer.OsmDataLayer;
49import org.openstreetmap.josm.gui.util.GuiHelper;
50import org.openstreetmap.josm.gui.util.KeyPressReleaseListener;
51import org.openstreetmap.josm.gui.util.ModifierListener;
52import org.openstreetmap.josm.tools.ImageProvider;
53import org.openstreetmap.josm.tools.Pair;
54import org.openstreetmap.josm.tools.Shortcut;
55import org.openstreetmap.josm.tools.Utils;
56
57/**
58 * Move is an action that can move all kind of OsmPrimitives (except keys for now).
59 *
60 * If an selected object is under the mouse when dragging, move all selected objects.
61 * If an unselected object is under the mouse when dragging, it becomes selected
62 * and will be moved.
63 * If no object is under the mouse, move all selected objects (if any)
64 *
65 * On Mac OS X, Ctrl + mouse button 1 simulates right click (map move), so the
66 * feature "selection remove" is disabled on this platform.
67 */
68public class SelectAction extends MapMode implements ModifierListener, KeyPressReleaseListener, SelectionEnded {
69
70 private static final String NORMAL = "normal";
71
72 /**
73 * Select action mode.
74 * @since 7543
75 */
76 public enum Mode {
77 /** "MOVE" means either dragging or select if no mouse movement occurs (i.e. just clicking) */
78 MOVE,
79 /** "ROTATE" allows to apply a rotation transformation on the selected object (see {@link RotateCommand}) */
80 ROTATE,
81 /** "SCALE" allows to apply a scaling transformation on the selected object (see {@link ScaleCommand}) */
82 SCALE,
83 /** "SELECT" means the selection rectangle */
84 SELECT
85 }
86
87 // contains all possible cases the cursor can be in the SelectAction
88 enum SelectActionCursor {
89
90 rect(NORMAL, "selection"),
91 rect_add(NORMAL, "select_add"),
92 rect_rm(NORMAL, "select_remove"),
93 way(NORMAL, "select_way"),
94 way_add(NORMAL, "select_way_add"),
95 way_rm(NORMAL, "select_way_remove"),
96 node(NORMAL, "select_node"),
97 node_add(NORMAL, "select_node_add"),
98 node_rm(NORMAL, "select_node_remove"),
99 virtual_node(NORMAL, "addnode"),
100 scale("scale", null),
101 rotate("rotate", null),
102 merge("crosshair", null),
103 lasso(NORMAL, "rope"),
104 merge_to_node("crosshair", "joinnode"),
105 move(Cursor.MOVE_CURSOR);
106
107 private final Cursor c;
108 SelectActionCursor(String main, String sub) {
109 c = ImageProvider.getCursor(main, sub);
110 }
111
112 SelectActionCursor(int systemCursor) {
113 c = Cursor.getPredefinedCursor(systemCursor);
114 }
115
116 /**
117 * Returns the action cursor.
118 * @return the cursor
119 */
120 public Cursor cursor() {
121 return c;
122 }
123 }
124
125 private boolean lassoMode;
126 private boolean repeatedKeySwitchLassoOption;
127
128 // Cache previous mouse event (needed when only the modifier keys are
129 // pressed but the mouse isn't moved)
130 private MouseEvent oldEvent;
131
132 private Mode mode;
133 private final transient SelectionManager selectionManager;
134 private boolean cancelDrawMode;
135 private boolean drawTargetHighlight;
136 private boolean didMouseDrag;
137 /**
138 * The component this SelectAction is associated with.
139 */
140 private final MapView mv;
141 /**
142 * The old cursor before the user pressed the mouse button.
143 */
144 private Point startingDraggingPos;
145 /**
146 * point where user pressed the mouse to start movement
147 */
148 private EastNorth startEN;
149 /**
150 * The last known position of the mouse.
151 */
152 private Point lastMousePos;
153 /**
154 * The time of the user mouse down event.
155 */
156 private long mouseDownTime;
157 /**
158 * The pressed button of the user mouse down event.
159 */
160 private int mouseDownButton;
161 /**
162 * The time of the user mouse down event.
163 */
164 private long mouseReleaseTime;
165 /**
166 * The time which needs to pass between click and release before something
167 * counts as a move, in milliseconds
168 */
169 private int initialMoveDelay;
170 /**
171 * The screen distance which needs to be travelled before something
172 * counts as a move, in pixels
173 */
174 private int initialMoveThreshold;
175 private boolean initialMoveThresholdExceeded;
176
177 /**
178 * elements that have been highlighted in the previous iteration. Used
179 * to remove the highlight from them again as otherwise the whole data
180 * set would have to be checked.
181 */
182 private transient Set<OsmPrimitive> oldHighlights = new HashSet<>();
183
184 /**
185 * Create a new SelectAction
186 * @param mapFrame The MapFrame this action belongs to.
187 */
188 public SelectAction(MapFrame mapFrame) {
189 super(tr("Select"), "move/move", tr("Select, move, scale and rotate objects"),
190 Shortcut.registerShortcut("mapmode:select", tr("Mode: {0}", tr("Select")), KeyEvent.VK_S, Shortcut.DIRECT),
191 ImageProvider.getCursor("normal", "selection"));
192 mv = mapFrame.mapView;
193 putValue("help", ht("/Action/Select"));
194 selectionManager = new SelectionManager(this, false, mv);
195 }
196
197 @Override
198 public void enterMode() {
199 super.enterMode();
200 mv.addMouseListener(this);
201 mv.addMouseMotionListener(this);
202 mv.setVirtualNodesEnabled(Main.pref.getInteger("mappaint.node.virtual-size", 8) != 0);
203 drawTargetHighlight = Main.pref.getBoolean("draw.target-highlight", true);
204 initialMoveDelay = Main.pref.getInteger("edit.initial-move-delay", 200);
205 initialMoveThreshold = Main.pref.getInteger("edit.initial-move-threshold", 5);
206 repeatedKeySwitchLassoOption = Main.pref.getBoolean("mappaint.select.toggle-lasso-on-repeated-S", true);
207 cycleManager.init();
208 virtualManager.init();
209 // This is required to update the cursors when ctrl/shift/alt is pressed
210 Main.map.keyDetector.addModifierListener(this);
211 Main.map.keyDetector.addKeyListener(this);
212 }
213
214 @Override
215 public void exitMode() {
216 super.exitMode();
217 selectionManager.unregister(mv);
218 mv.removeMouseListener(this);
219 mv.removeMouseMotionListener(this);
220 mv.setVirtualNodesEnabled(false);
221 Main.map.keyDetector.removeModifierListener(this);
222 Main.map.keyDetector.removeKeyListener(this);
223 removeHighlighting();
224 }
225
226 @Override
227 public void modifiersChanged(int modifiers) {
228 if (!Main.isDisplayingMapView() || oldEvent == null) return;
229 if (giveUserFeedback(oldEvent, modifiers)) {
230 mv.repaint();
231 }
232 }
233
234 /**
235 * handles adding highlights and updating the cursor for the given mouse event.
236 * Please note that the highlighting for merging while moving is handled via mouseDragged.
237 * @param e {@code MouseEvent} which should be used as base for the feedback
238 * @return {@code true} if repaint is required
239 */
240 private boolean giveUserFeedback(MouseEvent e) {
241 return giveUserFeedback(e, e.getModifiers());
242 }
243
244 /**
245 * handles adding highlights and updating the cursor for the given mouse event.
246 * Please note that the highlighting for merging while moving is handled via mouseDragged.
247 * @param e {@code MouseEvent} which should be used as base for the feedback
248 * @param modifiers define custom keyboard modifiers if the ones from MouseEvent are outdated or similar
249 * @return {@code true} if repaint is required
250 */
251 private boolean giveUserFeedback(MouseEvent e, int modifiers) {
252 Collection<OsmPrimitive> c = asColl(
253 mv.getNearestNodeOrWay(e.getPoint(), mv.isSelectablePredicate, true));
254
255 updateKeyModifiers(modifiers);
256 determineMapMode(!c.isEmpty());
257
258 Set<OsmPrimitive> newHighlights = new HashSet<>();
259
260 virtualManager.clear();
261 if (mode == Mode.MOVE && !dragInProgress() && virtualManager.activateVirtualNodeNearPoint(e.getPoint())) {
262 DataSet ds = getLayerManager().getEditDataSet();
263 if (ds != null && drawTargetHighlight) {
264 ds.setHighlightedVirtualNodes(virtualManager.virtualWays);
265 }
266 mv.setNewCursor(SelectActionCursor.virtual_node.cursor(), this);
267 // don't highlight anything else if a virtual node will be
268 return repaintIfRequired(newHighlights);
269 }
270
271 mv.setNewCursor(getCursor(c), this);
272
273 // return early if there can't be any highlights
274 if (!drawTargetHighlight || mode != Mode.MOVE || c.isEmpty())
275 return repaintIfRequired(newHighlights);
276
277 // CTRL toggles selection, but if while dragging CTRL means merge
278 final boolean isToggleMode = ctrl && !dragInProgress();
279 for (OsmPrimitive x : c) {
280 // only highlight primitives that will change the selection
281 // when clicked. I.e. don't highlight selected elements unless
282 // we are in toggle mode.
283 if (isToggleMode || !x.isSelected()) {
284 newHighlights.add(x);
285 }
286 }
287 return repaintIfRequired(newHighlights);
288 }
289
290 /**
291 * works out which cursor should be displayed for most of SelectAction's
292 * features. The only exception is the "move" cursor when actually dragging
293 * primitives.
294 * @param nearbyStuff primitives near the cursor
295 * @return the cursor that should be displayed
296 */
297 private Cursor getCursor(Collection<OsmPrimitive> nearbyStuff) {
298 String c = "rect";
299 switch(mode) {
300 case MOVE:
301 if (virtualManager.hasVirtualNode()) {
302 c = "virtual_node";
303 break;
304 }
305 final Iterator<OsmPrimitive> it = nearbyStuff.iterator();
306 final OsmPrimitive osm = it.hasNext() ? it.next() : null;
307
308 if (dragInProgress()) {
309 // only consider merge if ctrl is pressed and there are nodes in
310 // the selection that could be merged
311 if (!ctrl || getLayerManager().getEditDataSet().getSelectedNodes().isEmpty()) {
312 c = "move";
313 break;
314 }
315 // only show merge to node cursor if nearby node and that node is currently
316 // not being dragged
317 final boolean hasTarget = osm instanceof Node && !osm.isSelected();
318 c = hasTarget ? "merge_to_node" : "merge";
319 break;
320 }
321
322 c = (osm instanceof Node) ? "node" : c;
323 c = (osm instanceof Way) ? "way" : c;
324 if (shift) {
325 c += "_add";
326 } else if (ctrl) {
327 c += osm == null || osm.isSelected() ? "_rm" : "_add";
328 }
329 break;
330 case ROTATE:
331 c = "rotate";
332 break;
333 case SCALE:
334 c = "scale";
335 break;
336 case SELECT:
337 if (lassoMode) {
338 c = "lasso";
339 } else {
340 c = "rect" + (shift ? "_add" : (ctrl && !Main.isPlatformOsx() ? "_rm" : ""));
341 }
342 break;
343 }
344 return SelectActionCursor.valueOf(c).cursor();
345 }
346
347 /**
348 * Removes all existing highlights.
349 * @return true if a repaint is required
350 */
351 private boolean removeHighlighting() {
352 boolean needsRepaint = false;
353 DataSet ds = getLayerManager().getEditDataSet();
354 if (ds != null && !ds.getHighlightedVirtualNodes().isEmpty()) {
355 needsRepaint = true;
356 ds.clearHighlightedVirtualNodes();
357 }
358 if (oldHighlights.isEmpty())
359 return needsRepaint;
360
361 for (OsmPrimitive prim : oldHighlights) {
362 prim.setHighlighted(false);
363 }
364 oldHighlights = new HashSet<>();
365 return true;
366 }
367
368 private boolean repaintIfRequired(Set<OsmPrimitive> newHighlights) {
369 if (!drawTargetHighlight)
370 return false;
371
372 boolean needsRepaint = false;
373 for (OsmPrimitive x : newHighlights) {
374 if (oldHighlights.contains(x)) {
375 continue;
376 }
377 needsRepaint = true;
378 x.setHighlighted(true);
379 }
380 oldHighlights.removeAll(newHighlights);
381 for (OsmPrimitive x : oldHighlights) {
382 x.setHighlighted(false);
383 needsRepaint = true;
384 }
385 oldHighlights = newHighlights;
386 return needsRepaint;
387 }
388
389 /**
390 * Look, whether any object is selected. If not, select the nearest node.
391 * If there are no nodes in the dataset, do nothing.
392 *
393 * If the user did not press the left mouse button, do nothing.
394 *
395 * Also remember the starting position of the movement and change the mouse
396 * cursor to movement.
397 */
398 @Override
399 public void mousePressed(MouseEvent e) {
400 mouseDownButton = e.getButton();
401 // return early
402 if (!mv.isActiveLayerVisible() || !(Boolean) this.getValue("active") || mouseDownButton != MouseEvent.BUTTON1)
403 return;
404
405 // left-button mouse click only is processed here
406
407 // request focus in order to enable the expected keyboard shortcuts
408 mv.requestFocus();
409
410 // update which modifiers are pressed (shift, alt, ctrl)
411 updateKeyModifiers(e);
412
413 // We don't want to change to draw tool if the user tries to (de)select
414 // stuff but accidentally clicks in an empty area when selection is empty
415 cancelDrawMode = shift || ctrl;
416 didMouseDrag = false;
417 initialMoveThresholdExceeded = false;
418 mouseDownTime = System.currentTimeMillis();
419 lastMousePos = e.getPoint();
420 startEN = mv.getEastNorth(lastMousePos.x, lastMousePos.y);
421
422 // primitives under cursor are stored in c collection
423
424 OsmPrimitive nearestPrimitive = mv.getNearestNodeOrWay(e.getPoint(), mv.isSelectablePredicate, true);
425
426 determineMapMode(nearestPrimitive != null);
427
428 switch(mode) {
429 case ROTATE:
430 case SCALE:
431 // if nothing was selected, select primitive under cursor for scaling or rotating
432 DataSet ds = getLayerManager().getEditDataSet();
433 if (ds.selectionEmpty()) {
434 ds.setSelected(asColl(nearestPrimitive));
435 }
436
437 // Mode.select redraws when selectPrims is called
438 // Mode.move redraws when mouseDragged is called
439 // Mode.rotate redraws here
440 // Mode.scale redraws here
441 break;
442 case MOVE:
443 // also include case when some primitive is under cursor and no shift+ctrl / alt+ctrl is pressed
444 // so this is not movement, but selection on primitive under cursor
445 if (!cancelDrawMode && nearestPrimitive instanceof Way) {
446 virtualManager.activateVirtualNodeNearPoint(e.getPoint());
447 }
448 OsmPrimitive toSelect = cycleManager.cycleSetup(nearestPrimitive, e.getPoint());
449 selectPrims(asColl(toSelect), false, false);
450 useLastMoveCommandIfPossible();
451 // Schedule a timer to update status line "initialMoveDelay+1" ms in the future
452 GuiHelper.scheduleTimer(initialMoveDelay+1, evt -> updateStatusLine(), false);
453 break;
454 case SELECT:
455 default:
456 if (!(ctrl && Main.isPlatformOsx())) {
457 // start working with rectangle or lasso
458 selectionManager.register(mv, lassoMode);
459 selectionManager.mousePressed(e);
460 break;
461 }
462 }
463 if (giveUserFeedback(e)) {
464 mv.repaint();
465 }
466 updateStatusLine();
467 }
468
469 @Override
470 public void mouseMoved(MouseEvent e) {
471 // Mac OSX simulates with ctrl + mouse 1 the second mouse button hence no dragging events get fired.
472 if (Main.isPlatformOsx() && (mode == Mode.ROTATE || mode == Mode.SCALE)) {
473 mouseDragged(e);
474 return;
475 }
476 oldEvent = e;
477 if (giveUserFeedback(e)) {
478 mv.repaint();
479 }
480 }
481
482 /**
483 * If the left mouse button is pressed, move all currently selected
484 * objects (if one of them is under the mouse) or the current one under the
485 * mouse (which will become selected).
486 */
487 @Override
488 public void mouseDragged(MouseEvent e) {
489 if (!mv.isActiveLayerVisible())
490 return;
491
492 // Swing sends random mouseDragged events when closing dialogs by double-clicking their top-left icon on Windows
493 // Ignore such false events to prevent issues like #7078
494 if (mouseDownButton == MouseEvent.BUTTON1 && mouseReleaseTime > mouseDownTime)
495 return;
496
497 cancelDrawMode = true;
498 if (mode == Mode.SELECT) {
499 // Unregisters selectionManager if ctrl has been pressed after mouse click on Mac OS X in order to move the map
500 if (ctrl && Main.isPlatformOsx()) {
501 selectionManager.unregister(mv);
502 // Make sure correct cursor is displayed
503 mv.setNewCursor(Cursor.MOVE_CURSOR, this);
504 }
505 return;
506 }
507
508 // do not count anything as a move if it lasts less than 100 milliseconds.
509 if ((mode == Mode.MOVE) && (System.currentTimeMillis() - mouseDownTime < initialMoveDelay))
510 return;
511
512 if (mode != Mode.ROTATE && mode != Mode.SCALE && (e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0) {
513 // button is pressed in rotate mode
514 return;
515 }
516
517 if (mode == Mode.MOVE) {
518 // If ctrl is pressed we are in merge mode. Look for a nearby node,
519 // highlight it and adjust the cursor accordingly.
520 final boolean canMerge = ctrl && !getLayerManager().getEditDataSet().getSelectedNodes().isEmpty();
521 final OsmPrimitive p = canMerge ? findNodeToMergeTo(e.getPoint()) : null;
522 boolean needsRepaint = removeHighlighting();
523 if (p != null) {
524 p.setHighlighted(true);
525 oldHighlights.add(p);
526 needsRepaint = true;
527 }
528 mv.setNewCursor(getCursor(asColl(p)), this);
529 // also update the stored mouse event, so we can display the correct cursor
530 // when dragging a node onto another one and then press CTRL to merge
531 oldEvent = e;
532 if (needsRepaint) {
533 mv.repaint();
534 }
535 }
536
537 if (startingDraggingPos == null) {
538 startingDraggingPos = new Point(e.getX(), e.getY());
539 }
540
541 if (lastMousePos == null) {
542 lastMousePos = e.getPoint();
543 return;
544 }
545
546 if (!initialMoveThresholdExceeded) {
547 int dp = (int) lastMousePos.distance(e.getX(), e.getY());
548 if (dp < initialMoveThreshold)
549 return; // ignore small drags
550 initialMoveThresholdExceeded = true; //no more ingnoring uintil nex mouse press
551 }
552 if (e.getPoint().equals(lastMousePos))
553 return;
554
555 EastNorth currentEN = mv.getEastNorth(e.getX(), e.getY());
556
557 if (virtualManager.hasVirtualWaysToBeConstructed()) {
558 virtualManager.createMiddleNodeFromVirtual(currentEN);
559 } else {
560 if (!updateCommandWhileDragging(currentEN)) return;
561 }
562
563 mv.repaint();
564 if (mode != Mode.SCALE) {
565 lastMousePos = e.getPoint();
566 }
567
568 didMouseDrag = true;
569 }
570
571 @Override
572 public void mouseExited(MouseEvent e) {
573 if (removeHighlighting()) {
574 mv.repaint();
575 }
576 }
577
578 @Override
579 public void mouseReleased(MouseEvent e) {
580 if (!mv.isActiveLayerVisible())
581 return;
582
583 startingDraggingPos = null;
584 mouseReleaseTime = System.currentTimeMillis();
585
586 if (mode == Mode.SELECT) {
587 if (e.getButton() != MouseEvent.BUTTON1) {
588 return;
589 }
590 selectionManager.endSelecting(e);
591 selectionManager.unregister(mv);
592
593 // Select Draw Tool if no selection has been made
594 if (!cancelDrawMode && getLayerManager().getEditDataSet().selectionEmpty()) {
595 Main.map.selectDrawTool(true);
596 updateStatusLine();
597 return;
598 }
599 }
600
601 if (mode == Mode.MOVE && e.getButton() == MouseEvent.BUTTON1) {
602 if (!didMouseDrag) {
603 // only built in move mode
604 virtualManager.clear();
605 // do nothing if the click was to short too be recognized as a drag,
606 // but the release position is farther than 10px away from the press position
607 if (lastMousePos == null || lastMousePos.distanceSq(e.getPoint()) < 100) {
608 updateKeyModifiers(e);
609 selectPrims(cycleManager.cyclePrims(), true, false);
610
611 // If the user double-clicked a node, change to draw mode
612 Collection<OsmPrimitive> c = getLayerManager().getEditDataSet().getSelected();
613 if (e.getClickCount() >= 2 && c.size() == 1 && c.iterator().next() instanceof Node) {
614 // We need to do it like this as otherwise drawAction will see a double
615 // click and switch back to SelectMode
616 Main.worker.execute(() -> Main.map.selectDrawTool(true));
617 return;
618 }
619 }
620 } else {
621 confirmOrUndoMovement(e);
622 }
623 }
624
625 mode = null;
626
627 // simply remove any highlights if the middle click popup is active because
628 // the highlights don't depend on the cursor position there. If something was
629 // selected beforehand this would put us into move mode as well, which breaks
630 // the cycling through primitives on top of each other (see #6739).
631 if (e.getButton() == MouseEvent.BUTTON2) {
632 removeHighlighting();
633 } else {
634 giveUserFeedback(e);
635 }
636 updateStatusLine();
637 }
638
639 @Override
640 public void selectionEnded(Rectangle r, MouseEvent e) {
641 updateKeyModifiers(e);
642 selectPrims(selectionManager.getSelectedObjects(alt), true, true);
643 }
644
645 @Override
646 public void doKeyPressed(KeyEvent e) {
647 if (!repeatedKeySwitchLassoOption || !Main.isDisplayingMapView() || !getShortcut().isEvent(e))
648 return;
649 if (Main.isDebugEnabled()) {
650 Main.debug(getClass().getName()+" consuming event "+e);
651 }
652 e.consume();
653 if (!lassoMode) {
654 Main.map.selectMapMode(Main.map.mapModeSelectLasso);
655 } else {
656 Main.map.selectMapMode(Main.map.mapModeSelect);
657 }
658 }
659
660 @Override
661 public void doKeyReleased(KeyEvent e) {
662 // Do nothing
663 }
664
665 /**
666 * sets the mapmode according to key modifiers and if there are any
667 * selectables nearby. Everything has to be pre-determined for this
668 * function; its main purpose is to centralize what the modifiers do.
669 * @param hasSelectionNearby {@code true} if some primitves are selectable nearby
670 */
671 private void determineMapMode(boolean hasSelectionNearby) {
672 if (shift && ctrl) {
673 mode = Mode.ROTATE;
674 } else if (alt && ctrl) {
675 mode = Mode.SCALE;
676 } else if (hasSelectionNearby || dragInProgress()) {
677 mode = Mode.MOVE;
678 } else {
679 mode = Mode.SELECT;
680 }
681 }
682
683 /**
684 * Determines whenever elements have been grabbed and moved (i.e. the initial
685 * thresholds have been exceeded) and is still in progress (i.e. mouse button still pressed)
686 * @return true if a drag is in progress
687 */
688 private boolean dragInProgress() {
689 return didMouseDrag && startingDraggingPos != null;
690 }
691
692 /**
693 * Create or update data modification command while dragging mouse - implementation of
694 * continuous moving, scaling and rotation
695 * @param currentEN - mouse position
696 * @return status of action (<code>true</code> when action was performed)
697 */
698 private boolean updateCommandWhileDragging(EastNorth currentEN) {
699 // Currently we support only transformations which do not affect relations.
700 // So don't add them in the first place to make handling easier
701 DataSet ds = getLayerManager().getEditDataSet();
702 Collection<OsmPrimitive> selection = ds.getSelectedNodesAndWays();
703 if (selection.isEmpty()) { // if nothing was selected to drag, just select nearest node/way to the cursor
704 OsmPrimitive nearestPrimitive = mv.getNearestNodeOrWay(mv.getPoint(startEN), mv.isSelectablePredicate, true);
705 ds.setSelected(nearestPrimitive);
706 }
707
708 Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection);
709 // for these transformations, having only one node makes no sense - quit silently
710 if (affectedNodes.size() < 2 && (mode == Mode.ROTATE || mode == Mode.SCALE)) {
711 return false;
712 }
713 Command c = getLastCommandInDataset(ds);
714 if (mode == Mode.MOVE) {
715 if (startEN == null) return false; // fix #8128
716 ds.beginUpdate();
717 try {
718 if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand) c).getParticipatingPrimitives())) {
719 ((MoveCommand) c).saveCheckpoint();
720 ((MoveCommand) c).applyVectorTo(currentEN);
721 } else {
722 c = new MoveCommand(selection, startEN, currentEN);
723 Main.main.undoRedo.add(c);
724 }
725 for (Node n : affectedNodes) {
726 LatLon ll = n.getCoor();
727 if (ll != null && ll.isOutSideWorld()) {
728 // Revert move
729 ((MoveCommand) c).resetToCheckpoint();
730 // TODO: We might use a simple notification in the lower left corner.
731 JOptionPane.showMessageDialog(
732 Main.parent,
733 tr("Cannot move objects outside of the world."),
734 tr("Warning"),
735 JOptionPane.WARNING_MESSAGE);
736 mv.setNewCursor(cursor, this);
737 return false;
738 }
739 }
740 } finally {
741 ds.endUpdate();
742 }
743 } else {
744 startEN = currentEN; // drag can continue after scaling/rotation
745
746 if (mode != Mode.ROTATE && mode != Mode.SCALE) {
747 return false;
748 }
749
750 ds.beginUpdate();
751 try {
752 if (mode == Mode.ROTATE) {
753 if (c instanceof RotateCommand && affectedNodes.equals(((RotateCommand) c).getTransformedNodes())) {
754 ((RotateCommand) c).handleEvent(currentEN);
755 } else {
756 Main.main.undoRedo.add(new RotateCommand(selection, currentEN));
757 }
758 } else if (mode == Mode.SCALE) {
759 if (c instanceof ScaleCommand && affectedNodes.equals(((ScaleCommand) c).getTransformedNodes())) {
760 ((ScaleCommand) c).handleEvent(currentEN);
761 } else {
762 Main.main.undoRedo.add(new ScaleCommand(selection, currentEN));
763 }
764 }
765
766 Collection<Way> ways = ds.getSelectedWays();
767 if (doesImpactStatusLine(affectedNodes, ways)) {
768 Main.map.statusLine.setDist(ways);
769 }
770 } finally {
771 ds.endUpdate();
772 }
773 }
774 return true;
775 }
776
777 private static boolean doesImpactStatusLine(Collection<Node> affectedNodes, Collection<Way> selectedWays) {
778 for (Way w : selectedWays) {
779 for (Node n : w.getNodes()) {
780 if (affectedNodes.contains(n)) {
781 return true;
782 }
783 }
784 }
785 return false;
786 }
787
788 /**
789 * Adapt last move command (if it is suitable) to work with next drag, started at point startEN
790 */
791 private void useLastMoveCommandIfPossible() {
792 DataSet dataSet = getLayerManager().getEditDataSet();
793 if (dataSet == null) {
794 // It may happen that there is no edit layer.
795 return;
796 }
797 Command c = getLastCommandInDataset(dataSet);
798 Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(dataSet.getSelected());
799 if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand) c).getParticipatingPrimitives())) {
800 // old command was created with different base point of movement, we need to recalculate it
801 ((MoveCommand) c).changeStartPoint(startEN);
802 }
803 }
804
805 /**
806 * Obtain command in undoRedo stack to "continue" when dragging
807 * @param ds The data set the command needs to be in.
808 * @return last command
809 */
810 private static Command getLastCommandInDataset(DataSet ds) {
811 LinkedList<Command> commands = Main.main.undoRedo.commands;
812 if (!commands.isEmpty()) {
813 Command lastCommand = commands.getLast();
814 if (lastCommand instanceof SequenceCommand) {
815 lastCommand = ((SequenceCommand) lastCommand).getLastCommand();
816 }
817 if (ds.equals(lastCommand.getAffectedDataSet())) {
818 return lastCommand;
819 }
820 }
821 return null;
822 }
823
824 /**
825 * Present warning in the following cases and undo unwanted movements: <ul>
826 * <li>large and possibly unwanted movements</li>
827 * <li>movement of node with attached ways that are hidden by filters</li>
828 * </ul>
829 *
830 * @param e the mouse event causing the action (mouse released)
831 */
832 private void confirmOrUndoMovement(MouseEvent e) {
833 if (movesHiddenWay()) {
834 final ExtendedDialog ed = new ConfirmMoveDialog();
835 ed.setContent(tr("Are you sure that you want to move elements with attached ways that are hidden by filters?"));
836 ed.toggleEnable("movedHiddenElements");
837 ed.showDialog();
838 if (ed.getValue() != 1) {
839 Main.main.undoRedo.undo();
840 }
841 }
842 int max = Main.pref.getInteger("warn.move.maxelements", 20), limit = max;
843 for (OsmPrimitive osm : getLayerManager().getEditDataSet().getSelected()) {
844 if (osm instanceof Way) {
845 limit -= ((Way) osm).getNodes().size();
846 }
847 if (--limit < 0) {
848 break;
849 }
850 }
851 if (limit < 0) {
852 final ExtendedDialog ed = new ConfirmMoveDialog();
853 ed.setContent(
854 /* for correct i18n of plural forms - see #9110 */
855 trn("You moved more than {0} element. " + "Moving a large number of elements is often an error.\n" + "Really move them?",
856 "You moved more than {0} elements. " + "Moving a large number of elements is often an error.\n" + "Really move them?",
857 max, max));
858 ed.toggleEnable("movedManyElements");
859 ed.showDialog();
860
861 if (ed.getValue() != 1) {
862 Main.main.undoRedo.undo();
863 }
864 } else {
865 // if small number of elements were moved,
866 updateKeyModifiers(e);
867 if (ctrl) mergePrims(e.getPoint());
868 }
869 }
870
871 static class ConfirmMoveDialog extends ExtendedDialog {
872 ConfirmMoveDialog() {
873 super(Main.parent,
874 tr("Move elements"),
875 tr("Move them"), tr("Undo move"));
876 setButtonIcons("reorder", "cancel");
877 setCancelButton(2);
878 }
879 }
880
881 private boolean movesHiddenWay() {
882 DataSet ds = getLayerManager().getEditDataSet();
883 final Collection<OsmPrimitive> elementsToTest = new HashSet<>(ds.getSelected());
884 for (Way osm : Utils.filteredCollection(ds.getSelected(), Way.class)) {
885 elementsToTest.addAll(osm.getNodes());
886 }
887 for (OsmPrimitive node : Utils.filteredCollection(elementsToTest, Node.class)) {
888 for (Way ref : Utils.filteredCollection(node.getReferrers(), Way.class)) {
889 if (ref.isDisabledAndHidden()) {
890 return true;
891 }
892 }
893 }
894 return false;
895 }
896
897 /**
898 * Merges the selected nodes to the one closest to the given mouse position if the control
899 * key is pressed. If there is no such node, no action will be done and no error will be
900 * reported. If there is, it will execute the merge and add it to the undo buffer.
901 * @param p mouse position
902 */
903 private void mergePrims(Point p) {
904 DataSet ds = getLayerManager().getEditDataSet();
905 Collection<Node> selNodes = ds.getSelectedNodes();
906 if (selNodes.isEmpty())
907 return;
908
909 Node target = findNodeToMergeTo(p);
910 if (target == null)
911 return;
912
913 if (selNodes.size() == 1) {
914 // Move all selected primitive to preserve shape #10748
915 Collection<OsmPrimitive> selection = ds.getSelectedNodesAndWays();
916 Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection);
917 Command c = getLastCommandInDataset(ds);
918 ds.beginUpdate();
919 try {
920 if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand) c).getParticipatingPrimitives())) {
921 Node selectedNode = selNodes.iterator().next();
922 EastNorth selectedEN = selectedNode.getEastNorth();
923 EastNorth targetEN = target.getEastNorth();
924 ((MoveCommand) c).moveAgain(targetEN.getX() - selectedEN.getX(),
925 targetEN.getY() - selectedEN.getY());
926 }
927 } finally {
928 ds.endUpdate();
929 }
930 }
931
932 Collection<Node> nodesToMerge = new LinkedList<>(selNodes);
933 nodesToMerge.add(target);
934 mergeNodes(Main.getLayerManager().getEditLayer(), nodesToMerge, target);
935 }
936
937 /**
938 * Merge nodes using {@code MergeNodesAction}.
939 * Can be overridden for testing purpose.
940 * @param layer layer the reference data layer. Must not be null
941 * @param nodes the collection of nodes. Ignored if null
942 * @param targetLocationNode this node's location will be used for the target node
943 */
944 public void mergeNodes(OsmDataLayer layer, Collection<Node> nodes,
945 Node targetLocationNode) {
946 MergeNodesAction.doMergeNodes(layer, nodes, targetLocationNode);
947 }
948
949 /**
950 * Tries to find a node to merge to when in move-merge mode for the current mouse
951 * position. Either returns the node or null, if no suitable one is nearby.
952 * @param p mouse position
953 * @return node to merge to, or null
954 */
955 private Node findNodeToMergeTo(Point p) {
956 Collection<Node> target = mv.getNearestNodes(p,
957 getLayerManager().getEditDataSet().getSelectedNodes(),
958 mv.isSelectablePredicate);
959 return target.isEmpty() ? null : target.iterator().next();
960 }
961
962 private void selectPrims(Collection<OsmPrimitive> prims, boolean released, boolean area) {
963 DataSet ds = getLayerManager().getEditDataSet();
964
965 // not allowed together: do not change dataset selection, return early
966 // Virtual Ways: if non-empty the cursor is above a virtual node. So don't highlight
967 // anything if about to drag the virtual node (i.e. !released) but continue if the
968 // cursor is only released above a virtual node by accident (i.e. released). See #7018
969 if (ds == null || (shift && ctrl) || (ctrl && !released) || (virtualManager.hasVirtualWaysToBeConstructed() && !released))
970 return;
971
972 if (!released) {
973 // Don't replace the selection if the user clicked on a
974 // selected object (it breaks moving of selected groups).
975 // Do it later, on mouse release.
976 shift |= ds.getSelected().containsAll(prims);
977 }
978
979 if (ctrl) {
980 // Ctrl on an item toggles its selection status,
981 // but Ctrl on an *area* just clears those items
982 // out of the selection.
983 if (area) {
984 ds.clearSelection(prims);
985 } else {
986 ds.toggleSelected(prims);
987 }
988 } else if (shift) {
989 // add prims to an existing selection
990 ds.addSelected(prims);
991 } else {
992 // clear selection, then select the prims clicked
993 ds.setSelected(prims);
994 }
995 }
996
997 /**
998 * Returns the current select mode.
999 * @return the select mode
1000 * @since 7543
1001 */
1002 public final Mode getMode() {
1003 return mode;
1004 }
1005
1006 @Override
1007 public String getModeHelpText() {
1008 if (mouseDownButton == MouseEvent.BUTTON1 && mouseReleaseTime < mouseDownTime) {
1009 if (mode == Mode.SELECT)
1010 return tr("Release the mouse button to select the objects in the rectangle.");
1011 else if (mode == Mode.MOVE && (System.currentTimeMillis() - mouseDownTime >= initialMoveDelay)) {
1012 final DataSet ds = getLayerManager().getEditDataSet();
1013 final boolean canMerge = ds != null && !ds.getSelectedNodes().isEmpty();
1014 final String mergeHelp = canMerge ? (' ' + tr("Ctrl to merge with nearest node.")) : "";
1015 return tr("Release the mouse button to stop moving.") + mergeHelp;
1016 } else if (mode == Mode.ROTATE)
1017 return tr("Release the mouse button to stop rotating.");
1018 else if (mode == Mode.SCALE)
1019 return tr("Release the mouse button to stop scaling.");
1020 }
1021 return tr("Move objects by dragging; Shift to add to selection (Ctrl to toggle); Shift-Ctrl to rotate selected; " +
1022 "Alt-Ctrl to scale selected; or change selection");
1023 }
1024
1025 @Override
1026 public boolean layerIsSupported(Layer l) {
1027 return l instanceof OsmDataLayer;
1028 }
1029
1030 /**
1031 * Enable or diable the lasso mode
1032 * @param lassoMode true to enable the lasso mode, false otherwise
1033 */
1034 public void setLassoMode(boolean lassoMode) {
1035 this.selectionManager.setLassoMode(lassoMode);
1036 this.lassoMode = lassoMode;
1037 }
1038
1039 private final transient CycleManager cycleManager = new CycleManager();
1040 private final transient VirtualManager virtualManager = new VirtualManager();
1041
1042 private class CycleManager {
1043
1044 private Collection<OsmPrimitive> cycleList = Collections.emptyList();
1045 private boolean cyclePrims;
1046 private OsmPrimitive cycleStart;
1047 private boolean waitForMouseUpParameter;
1048 private boolean multipleMatchesParameter;
1049 /**
1050 * read preferences
1051 */
1052 private void init() {
1053 waitForMouseUpParameter = Main.pref.getBoolean("mappaint.select.waits-for-mouse-up", false);
1054 multipleMatchesParameter = Main.pref.getBoolean("selectaction.cycles.multiple.matches", false);
1055 }
1056
1057 /**
1058 * Determine primitive to be selected and build cycleList
1059 * @param nearest primitive found by simple method
1060 * @param p point where user clicked
1061 * @return OsmPrimitive to be selected
1062 */
1063 private OsmPrimitive cycleSetup(OsmPrimitive nearest, Point p) {
1064 OsmPrimitive osm = null;
1065
1066 if (nearest != null) {
1067 osm = nearest;
1068
1069 if (!(alt || multipleMatchesParameter)) {
1070 // no real cycling, just one element in cycle list
1071 cycleList = asColl(osm);
1072
1073 if (waitForMouseUpParameter) {
1074 // prefer a selected nearest node or way, if possible
1075 osm = mv.getNearestNodeOrWay(p, mv.isSelectablePredicate, true);
1076 }
1077 } else {
1078 // Alt + left mouse button pressed: we need to build cycle list
1079 cycleList = mv.getAllNearest(p, mv.isSelectablePredicate);
1080
1081 if (cycleList.size() > 1) {
1082 cyclePrims = false;
1083
1084 // find first already selected element in cycle list
1085 OsmPrimitive old = osm;
1086 for (OsmPrimitive o : cycleList) {
1087 if (o.isSelected()) {
1088 cyclePrims = true;
1089 osm = o;
1090 break;
1091 }
1092 }
1093
1094 // special case: for cycle groups of 2, we can toggle to the
1095 // true nearest primitive on mousePressed right away
1096 if (cycleList.size() == 2 && !waitForMouseUpParameter) {
1097 if (!(osm.equals(old) || osm.isNew() || ctrl)) {
1098 cyclePrims = false;
1099 osm = old;
1100 } // else defer toggling to mouseRelease time in those cases:
1101 /*
1102 * osm == old -- the true nearest node is the
1103 * selected one osm is a new node -- do not break
1104 * unglue ways in ALT mode ctrl is pressed -- ctrl
1105 * generally works on mouseReleased
1106 */
1107 }
1108 }
1109 }
1110 }
1111 return osm;
1112 }
1113
1114 /**
1115 * Modifies current selection state and returns the next element in a
1116 * selection cycle given by
1117 * <code>cycleList</code> field
1118 * @return the next element of cycle list
1119 */
1120 private Collection<OsmPrimitive> cyclePrims() {
1121 if (cycleList.size() <= 1) {
1122 // no real cycling, just return one-element collection with nearest primitive in it
1123 return cycleList;
1124 }
1125 // updateKeyModifiers() already called before!
1126
1127 DataSet ds = getLayerManager().getEditDataSet();
1128 OsmPrimitive first = cycleList.iterator().next(), foundInDS = null;
1129 OsmPrimitive nxt = first;
1130
1131 if (cyclePrims && shift) {
1132 for (Iterator<OsmPrimitive> i = cycleList.iterator(); i.hasNext();) {
1133 nxt = i.next();
1134 if (!nxt.isSelected()) {
1135 break; // take first primitive in cycleList not in sel
1136 }
1137 }
1138 // if primitives 1,2,3 are under cursor, [Alt-press] [Shift-release] gives 1 -> 12 -> 123
1139 } else {
1140 for (Iterator<OsmPrimitive> i = cycleList.iterator(); i.hasNext();) {
1141 nxt = i.next();
1142 if (nxt.isSelected()) {
1143 foundInDS = nxt;
1144 // first selected primitive in cycleList is found
1145 if (cyclePrims || ctrl) {
1146 ds.clearSelection(foundInDS); // deselect it
1147 nxt = i.hasNext() ? i.next() : first;
1148 // return next one in cycle list (last->first)
1149 }
1150 break; // take next primitive in cycleList
1151 }
1152 }
1153 }
1154
1155 // if "no-alt-cycling" is enabled, Ctrl-Click arrives here.
1156 if (ctrl) {
1157 // a member of cycleList was found in the current dataset selection
1158 if (foundInDS != null) {
1159 // mouse was moved to a different selection group w/ a previous sel
1160 if (!cycleList.contains(cycleStart)) {
1161 ds.clearSelection(cycleList);
1162 cycleStart = foundInDS;
1163 } else if (cycleStart.equals(nxt)) {
1164 // loop detected, insert deselect step
1165 ds.addSelected(nxt);
1166 }
1167 } else {
1168 // setup for iterating a sel group again or a new, different one..
1169 nxt = cycleList.contains(cycleStart) ? cycleStart : first;
1170 cycleStart = nxt;
1171 }
1172 } else {
1173 cycleStart = null;
1174 }
1175 // return one-element collection with one element to be selected (or added to selection)
1176 return asColl(nxt);
1177 }
1178 }
1179
1180 private class VirtualManager {
1181
1182 private Node virtualNode;
1183 private Collection<WaySegment> virtualWays = new LinkedList<>();
1184 private int nodeVirtualSize;
1185 private int virtualSnapDistSq2;
1186 private int virtualSpace;
1187
1188 private void init() {
1189 nodeVirtualSize = Main.pref.getInteger("mappaint.node.virtual-size", 8);
1190 int virtualSnapDistSq = Main.pref.getInteger("mappaint.node.virtual-snap-distance", 8);
1191 virtualSnapDistSq2 = virtualSnapDistSq*virtualSnapDistSq;
1192 virtualSpace = Main.pref.getInteger("mappaint.node.virtual-space", 70);
1193 }
1194
1195 /**
1196 * Calculate a virtual node if there is enough visual space to draw a
1197 * crosshair node and the middle of a way segment is clicked. If the
1198 * user drags the crosshair node, it will be added to all ways in
1199 * <code>virtualWays</code>.
1200 *
1201 * @param p the point clicked
1202 * @return whether
1203 * <code>virtualNode</code> and
1204 * <code>virtualWays</code> were setup.
1205 */
1206 private boolean activateVirtualNodeNearPoint(Point p) {
1207 if (nodeVirtualSize > 0) {
1208
1209 Collection<WaySegment> selVirtualWays = new LinkedList<>();
1210 Pair<Node, Node> vnp = null, wnp = new Pair<>(null, null);
1211
1212 for (WaySegment ws : mv.getNearestWaySegments(p, mv.isSelectablePredicate)) {
1213 Way w = ws.way;
1214
1215 wnp.a = w.getNode(ws.lowerIndex);
1216 wnp.b = w.getNode(ws.lowerIndex + 1);
1217 MapViewPoint p1 = mv.getState().getPointFor(wnp.a);
1218 MapViewPoint p2 = mv.getState().getPointFor(wnp.b);
1219 if (WireframeMapRenderer.isLargeSegment(p1, p2, virtualSpace)) {
1220 Point2D pc = new Point2D.Double((p1.getInViewX() + p2.getInViewX()) / 2, (p1.getInViewY() + p2.getInViewY()) / 2);
1221 if (p.distanceSq(pc) < virtualSnapDistSq2) {
1222 // Check that only segments on top of each other get added to the
1223 // virtual ways list. Otherwise ways that coincidentally have their
1224 // virtual node at the same spot will be joined which is likely unwanted
1225 Pair.sort(wnp);
1226 if (vnp == null) {
1227 vnp = new Pair<>(wnp.a, wnp.b);
1228 virtualNode = new Node(mv.getLatLon(pc.getX(), pc.getY()));
1229 }
1230 if (vnp.equals(wnp)) {
1231 // if mutiple line segments have the same points,
1232 // add all segments to be splitted to virtualWays list
1233 // if some lines are selected, only their segments will go to virtualWays
1234 (w.isSelected() ? selVirtualWays : virtualWays).add(ws);
1235 }
1236 }
1237 }
1238 }
1239
1240 if (!selVirtualWays.isEmpty()) {
1241 virtualWays = selVirtualWays;
1242 }
1243 }
1244
1245 return !virtualWays.isEmpty();
1246 }
1247
1248 private void createMiddleNodeFromVirtual(EastNorth currentEN) {
1249 Collection<Command> virtualCmds = new LinkedList<>();
1250 virtualCmds.add(new AddCommand(virtualNode));
1251 for (WaySegment virtualWay : virtualWays) {
1252 Way w = virtualWay.way;
1253 Way wnew = new Way(w);
1254 wnew.addNode(virtualWay.lowerIndex + 1, virtualNode);
1255 virtualCmds.add(new ChangeCommand(w, wnew));
1256 }
1257 virtualCmds.add(new MoveCommand(virtualNode, startEN, currentEN));
1258 String text = trn("Add and move a virtual new node to way",
1259 "Add and move a virtual new node to {0} ways", virtualWays.size(),
1260 virtualWays.size());
1261 Main.main.undoRedo.add(new SequenceCommand(text, virtualCmds));
1262 getLayerManager().getEditDataSet().setSelected(Collections.singleton((OsmPrimitive) virtualNode));
1263 clear();
1264 }
1265
1266 private void clear() {
1267 virtualWays.clear();
1268 virtualNode = null;
1269 }
1270
1271 private boolean hasVirtualNode() {
1272 return virtualNode != null;
1273 }
1274
1275 private boolean hasVirtualWaysToBeConstructed() {
1276 return !virtualWays.isEmpty();
1277 }
1278 }
1279
1280 /**
1281 * Returns {@code o} as collection of {@code o}'s type.
1282 * @param <T> object type
1283 * @param o any object
1284 * @return {@code o} as collection of {@code o}'s type.
1285 */
1286 protected static <T> Collection<T> asColl(T o) {
1287 return o == null ? Collections.emptySet() : Collections.singleton(o);
1288 }
1289}
Note: See TracBrowser for help on using the repository browser.