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

Last change on this file since 11713 was 11713, checked in by Don-vip, 8 years ago

add Ant target to run PMD (only few rules for now), fix violations

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