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

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

Fix #6447: Ensure that only move commands in same layer are combined.

  • 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 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 public 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 if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand) c).getParticipatingPrimitives())) {
718 ((MoveCommand) c).saveCheckpoint();
719 ((MoveCommand) c).applyVectorTo(currentEN);
720 } else {
721 c = new MoveCommand(selection, startEN, currentEN);
722 Main.main.undoRedo.add(c);
723 }
724 for (Node n : affectedNodes) {
725 LatLon ll = n.getCoor();
726 if (ll != null && ll.isOutSideWorld()) {
727 // Revert move
728 ((MoveCommand) c).resetToCheckpoint();
729 ds.endUpdate();
730 JOptionPane.showMessageDialog(
731 Main.parent,
732 tr("Cannot move objects outside of the world."),
733 tr("Warning"),
734 JOptionPane.WARNING_MESSAGE);
735 mv.setNewCursor(cursor, this);
736 return false;
737 }
738 }
739 } else {
740 startEN = currentEN; // drag can continue after scaling/rotation
741
742 if (mode != Mode.ROTATE && mode != Mode.SCALE) {
743 return false;
744 }
745
746 ds.beginUpdate();
747
748 if (mode == Mode.ROTATE) {
749 if (c instanceof RotateCommand && affectedNodes.equals(((RotateCommand) c).getTransformedNodes())) {
750 ((RotateCommand) c).handleEvent(currentEN);
751 } else {
752 Main.main.undoRedo.add(new RotateCommand(selection, currentEN));
753 }
754 } else if (mode == Mode.SCALE) {
755 if (c instanceof ScaleCommand && affectedNodes.equals(((ScaleCommand) c).getTransformedNodes())) {
756 ((ScaleCommand) c).handleEvent(currentEN);
757 } else {
758 Main.main.undoRedo.add(new ScaleCommand(selection, currentEN));
759 }
760 }
761
762 Collection<Way> ways = ds.getSelectedWays();
763 if (doesImpactStatusLine(affectedNodes, ways)) {
764 Main.map.statusLine.setDist(ways);
765 }
766 }
767 ds.endUpdate();
768 return true;
769 }
770
771 private static boolean doesImpactStatusLine(Collection<Node> affectedNodes, Collection<Way> selectedWays) {
772 for (Way w : selectedWays) {
773 for (Node n : w.getNodes()) {
774 if (affectedNodes.contains(n)) {
775 return true;
776 }
777 }
778 }
779 return false;
780 }
781
782 /**
783 * Adapt last move command (if it is suitable) to work with next drag, started at point startEN
784 */
785 private void useLastMoveCommandIfPossible() {
786 DataSet dataSet = getLayerManager().getEditDataSet();
787 Command c = getLastCommandInDataset(dataSet);
788 Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(dataSet.getSelected());
789 if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand) c).getParticipatingPrimitives())) {
790 // old command was created with different base point of movement, we need to recalculate it
791 ((MoveCommand) c).changeStartPoint(startEN);
792 }
793 }
794
795 /**
796 * Obtain command in undoRedo stack to "continue" when dragging
797 * @param ds The data set the command needs to be in.
798 * @return last command
799 */
800 private Command getLastCommandInDataset(DataSet ds) {
801 LinkedList<Command> commands = Main.main.undoRedo.commands;
802 if (!commands.isEmpty()) {
803 Command lastCommand = commands.getLast();
804 if (lastCommand instanceof SequenceCommand) {
805 lastCommand = ((SequenceCommand) lastCommand).getLastCommand();
806 }
807 if (ds.equals(lastCommand.getAffectedDataSet())) {
808 return lastCommand;
809 }
810 }
811 return null;
812 }
813
814 /**
815 * Present warning in the following cases and undo unwanted movements: <ul>
816 * <li>large and possibly unwanted movements</li>
817 * <li>movement of node with attached ways that are hidden by filters</li>
818 * </ul>
819 *
820 * @param e the mouse event causing the action (mouse released)
821 */
822 private void confirmOrUndoMovement(MouseEvent e) {
823 if (movesHiddenWay()) {
824 final ExtendedDialog ed = new ConfirmMoveDialog();
825 ed.setContent(tr("Are you sure that you want to move elements with attached ways that are hidden by filters?"));
826 ed.toggleEnable("movedHiddenElements");
827 ed.showDialog();
828 if (ed.getValue() != 1) {
829 Main.main.undoRedo.undo();
830 }
831 }
832 int max = Main.pref.getInteger("warn.move.maxelements", 20), limit = max;
833 for (OsmPrimitive osm : getLayerManager().getEditDataSet().getSelected()) {
834 if (osm instanceof Way) {
835 limit -= ((Way) osm).getNodes().size();
836 }
837 if (--limit < 0) {
838 break;
839 }
840 }
841 if (limit < 0) {
842 final ExtendedDialog ed = new ConfirmMoveDialog();
843 ed.setContent(
844 /* for correct i18n of plural forms - see #9110 */
845 trn("You moved more than {0} element. " + "Moving a large number of elements is often an error.\n" + "Really move them?",
846 "You moved more than {0} elements. " + "Moving a large number of elements is often an error.\n" + "Really move them?",
847 max, max));
848 ed.toggleEnable("movedManyElements");
849 ed.showDialog();
850
851 if (ed.getValue() != 1) {
852 Main.main.undoRedo.undo();
853 }
854 } else {
855 // if small number of elements were moved,
856 updateKeyModifiers(e);
857 if (ctrl) mergePrims(e.getPoint());
858 }
859 }
860
861 static class ConfirmMoveDialog extends ExtendedDialog {
862 ConfirmMoveDialog() {
863 super(Main.parent,
864 tr("Move elements"),
865 new String[]{tr("Move them"), tr("Undo move")});
866 setButtonIcons(new String[]{"reorder", "cancel"});
867 setCancelButton(2);
868 }
869 }
870
871 private boolean movesHiddenWay() {
872 DataSet ds = getLayerManager().getEditDataSet();
873 final Collection<OsmPrimitive> elementsToTest = new HashSet<>(ds.getSelected());
874 for (Way osm : Utils.filteredCollection(ds.getSelected(), Way.class)) {
875 elementsToTest.addAll(osm.getNodes());
876 }
877 for (OsmPrimitive node : Utils.filteredCollection(elementsToTest, Node.class)) {
878 for (Way ref : Utils.filteredCollection(node.getReferrers(), Way.class)) {
879 if (ref.isDisabledAndHidden()) {
880 return true;
881 }
882 }
883 }
884 return false;
885 }
886
887 /**
888 * Merges the selected nodes to the one closest to the given mouse position if the control
889 * key is pressed. If there is no such node, no action will be done and no error will be
890 * reported. If there is, it will execute the merge and add it to the undo buffer.
891 * @param p mouse position
892 */
893 private void mergePrims(Point p) {
894 DataSet ds = getLayerManager().getEditDataSet();
895 Collection<Node> selNodes = ds.getSelectedNodes();
896 if (selNodes.isEmpty())
897 return;
898
899 Node target = findNodeToMergeTo(p);
900 if (target == null)
901 return;
902
903 if (selNodes.size() == 1) {
904 // Move all selected primitive to preserve shape #10748
905 Collection<OsmPrimitive> selection = ds.getSelectedNodesAndWays();
906 Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection);
907 Command c = getLastCommandInDataset(ds);
908 ds.beginUpdate();
909 if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand) c).getParticipatingPrimitives())) {
910 Node selectedNode = selNodes.iterator().next();
911 EastNorth selectedEN = selectedNode.getEastNorth();
912 EastNorth targetEN = target.getEastNorth();
913 ((MoveCommand) c).moveAgain(targetEN.getX() - selectedEN.getX(),
914 targetEN.getY() - selectedEN.getY());
915 }
916 ds.endUpdate();
917 }
918
919 Collection<Node> nodesToMerge = new LinkedList<>(selNodes);
920 nodesToMerge.add(target);
921 mergeNodes(Main.getLayerManager().getEditLayer(), nodesToMerge, target);
922 }
923
924 /**
925 * Merge nodes using {@code MergeNodesAction}.
926 * Can be overridden for testing purpose.
927 * @param layer layer the reference data layer. Must not be null
928 * @param nodes the collection of nodes. Ignored if null
929 * @param targetLocationNode this node's location will be used for the target node
930 */
931 public void mergeNodes(OsmDataLayer layer, Collection<Node> nodes,
932 Node targetLocationNode) {
933 MergeNodesAction.doMergeNodes(layer, nodes, targetLocationNode);
934 }
935
936 /**
937 * Tries to find a node to merge to when in move-merge mode for the current mouse
938 * position. Either returns the node or null, if no suitable one is nearby.
939 * @param p mouse position
940 * @return node to merge to, or null
941 */
942 private Node findNodeToMergeTo(Point p) {
943 Collection<Node> target = mv.getNearestNodes(p,
944 getLayerManager().getEditDataSet().getSelectedNodes(),
945 mv.isSelectablePredicate);
946 return target.isEmpty() ? null : target.iterator().next();
947 }
948
949 private void selectPrims(Collection<OsmPrimitive> prims, boolean released, boolean area) {
950 DataSet ds = getLayerManager().getEditDataSet();
951
952 // not allowed together: do not change dataset selection, return early
953 // Virtual Ways: if non-empty the cursor is above a virtual node. So don't highlight
954 // anything if about to drag the virtual node (i.e. !released) but continue if the
955 // cursor is only released above a virtual node by accident (i.e. released). See #7018
956 if (ds == null || (shift && ctrl) || (ctrl && !released) || (virtualManager.hasVirtualWaysToBeConstructed() && !released))
957 return;
958
959 if (!released) {
960 // Don't replace the selection if the user clicked on a
961 // selected object (it breaks moving of selected groups).
962 // Do it later, on mouse release.
963 shift |= ds.getSelected().containsAll(prims);
964 }
965
966 if (ctrl) {
967 // Ctrl on an item toggles its selection status,
968 // but Ctrl on an *area* just clears those items
969 // out of the selection.
970 if (area) {
971 ds.clearSelection(prims);
972 } else {
973 ds.toggleSelected(prims);
974 }
975 } else if (shift) {
976 // add prims to an existing selection
977 ds.addSelected(prims);
978 } else {
979 // clear selection, then select the prims clicked
980 ds.setSelected(prims);
981 }
982 }
983
984 /**
985 * Returns the current select mode.
986 * @return the select mode
987 * @since 7543
988 */
989 public final Mode getMode() {
990 return mode;
991 }
992
993 @Override
994 public String getModeHelpText() {
995 if (mouseDownButton == MouseEvent.BUTTON1 && mouseReleaseTime < mouseDownTime) {
996 if (mode == Mode.SELECT)
997 return tr("Release the mouse button to select the objects in the rectangle.");
998 else if (mode == Mode.MOVE && (System.currentTimeMillis() - mouseDownTime >= initialMoveDelay)) {
999 final DataSet ds = getLayerManager().getEditDataSet();
1000 final boolean canMerge = ds != null && !ds.getSelectedNodes().isEmpty();
1001 final String mergeHelp = canMerge ? (' ' + tr("Ctrl to merge with nearest node.")) : "";
1002 return tr("Release the mouse button to stop moving.") + mergeHelp;
1003 } else if (mode == Mode.ROTATE)
1004 return tr("Release the mouse button to stop rotating.");
1005 else if (mode == Mode.SCALE)
1006 return tr("Release the mouse button to stop scaling.");
1007 }
1008 return tr("Move objects by dragging; Shift to add to selection (Ctrl to toggle); Shift-Ctrl to rotate selected; " +
1009 "Alt-Ctrl to scale selected; or change selection");
1010 }
1011
1012 @Override
1013 public boolean layerIsSupported(Layer l) {
1014 return l instanceof OsmDataLayer;
1015 }
1016
1017 /**
1018 * Enable or diable the lasso mode
1019 * @param lassoMode true to enable the lasso mode, false otherwise
1020 */
1021 public void setLassoMode(boolean lassoMode) {
1022 this.selectionManager.setLassoMode(lassoMode);
1023 this.lassoMode = lassoMode;
1024 }
1025
1026 private final transient CycleManager cycleManager = new CycleManager();
1027 private final transient VirtualManager virtualManager = new VirtualManager();
1028
1029 private class CycleManager {
1030
1031 private Collection<OsmPrimitive> cycleList = Collections.emptyList();
1032 private boolean cyclePrims;
1033 private OsmPrimitive cycleStart;
1034 private boolean waitForMouseUpParameter;
1035 private boolean multipleMatchesParameter;
1036 /**
1037 * read preferences
1038 */
1039 private void init() {
1040 waitForMouseUpParameter = Main.pref.getBoolean("mappaint.select.waits-for-mouse-up", false);
1041 multipleMatchesParameter = Main.pref.getBoolean("selectaction.cycles.multiple.matches", false);
1042 }
1043
1044 /**
1045 * Determine primitive to be selected and build cycleList
1046 * @param nearest primitive found by simple method
1047 * @param p point where user clicked
1048 * @return OsmPrimitive to be selected
1049 */
1050 private OsmPrimitive cycleSetup(OsmPrimitive nearest, Point p) {
1051 OsmPrimitive osm = null;
1052
1053 if (nearest != null) {
1054 osm = nearest;
1055
1056 if (!(alt || multipleMatchesParameter)) {
1057 // no real cycling, just one element in cycle list
1058 cycleList = asColl(osm);
1059
1060 if (waitForMouseUpParameter) {
1061 // prefer a selected nearest node or way, if possible
1062 osm = mv.getNearestNodeOrWay(p, mv.isSelectablePredicate, true);
1063 }
1064 } else {
1065 // Alt + left mouse button pressed: we need to build cycle list
1066 cycleList = mv.getAllNearest(p, mv.isSelectablePredicate);
1067
1068 if (cycleList.size() > 1) {
1069 cyclePrims = false;
1070
1071 // find first already selected element in cycle list
1072 OsmPrimitive old = osm;
1073 for (OsmPrimitive o : cycleList) {
1074 if (o.isSelected()) {
1075 cyclePrims = true;
1076 osm = o;
1077 break;
1078 }
1079 }
1080
1081 // special case: for cycle groups of 2, we can toggle to the
1082 // true nearest primitive on mousePressed right away
1083 if (cycleList.size() == 2 && !waitForMouseUpParameter) {
1084 if (!(osm.equals(old) || osm.isNew() || ctrl)) {
1085 cyclePrims = false;
1086 osm = old;
1087 } // else defer toggling to mouseRelease time in those cases:
1088 /*
1089 * osm == old -- the true nearest node is the
1090 * selected one osm is a new node -- do not break
1091 * unglue ways in ALT mode ctrl is pressed -- ctrl
1092 * generally works on mouseReleased
1093 */
1094 }
1095 }
1096 }
1097 }
1098 return osm;
1099 }
1100
1101 /**
1102 * Modifies current selection state and returns the next element in a
1103 * selection cycle given by
1104 * <code>cycleList</code> field
1105 * @return the next element of cycle list
1106 */
1107 private Collection<OsmPrimitive> cyclePrims() {
1108 if (cycleList.size() <= 1) {
1109 // no real cycling, just return one-element collection with nearest primitive in it
1110 return cycleList;
1111 }
1112 // updateKeyModifiers() already called before!
1113
1114 DataSet ds = getLayerManager().getEditDataSet();
1115 OsmPrimitive first = cycleList.iterator().next(), foundInDS = null;
1116 OsmPrimitive nxt = first;
1117
1118 if (cyclePrims && shift) {
1119 for (Iterator<OsmPrimitive> i = cycleList.iterator(); i.hasNext();) {
1120 nxt = i.next();
1121 if (!nxt.isSelected()) {
1122 break; // take first primitive in cycleList not in sel
1123 }
1124 }
1125 // if primitives 1,2,3 are under cursor, [Alt-press] [Shift-release] gives 1 -> 12 -> 123
1126 } else {
1127 for (Iterator<OsmPrimitive> i = cycleList.iterator(); i.hasNext();) {
1128 nxt = i.next();
1129 if (nxt.isSelected()) {
1130 foundInDS = nxt;
1131 // first selected primitive in cycleList is found
1132 if (cyclePrims || ctrl) {
1133 ds.clearSelection(foundInDS); // deselect it
1134 nxt = i.hasNext() ? i.next() : first;
1135 // return next one in cycle list (last->first)
1136 }
1137 break; // take next primitive in cycleList
1138 }
1139 }
1140 }
1141
1142 // if "no-alt-cycling" is enabled, Ctrl-Click arrives here.
1143 if (ctrl) {
1144 // a member of cycleList was found in the current dataset selection
1145 if (foundInDS != null) {
1146 // mouse was moved to a different selection group w/ a previous sel
1147 if (!cycleList.contains(cycleStart)) {
1148 ds.clearSelection(cycleList);
1149 cycleStart = foundInDS;
1150 } else if (cycleStart.equals(nxt)) {
1151 // loop detected, insert deselect step
1152 ds.addSelected(nxt);
1153 }
1154 } else {
1155 // setup for iterating a sel group again or a new, different one..
1156 nxt = cycleList.contains(cycleStart) ? cycleStart : first;
1157 cycleStart = nxt;
1158 }
1159 } else {
1160 cycleStart = null;
1161 }
1162 // return one-element collection with one element to be selected (or added to selection)
1163 return asColl(nxt);
1164 }
1165 }
1166
1167 private class VirtualManager {
1168
1169 private Node virtualNode;
1170 private Collection<WaySegment> virtualWays = new LinkedList<>();
1171 private int nodeVirtualSize;
1172 private int virtualSnapDistSq2;
1173 private int virtualSpace;
1174
1175 private void init() {
1176 nodeVirtualSize = Main.pref.getInteger("mappaint.node.virtual-size", 8);
1177 int virtualSnapDistSq = Main.pref.getInteger("mappaint.node.virtual-snap-distance", 8);
1178 virtualSnapDistSq2 = virtualSnapDistSq*virtualSnapDistSq;
1179 virtualSpace = Main.pref.getInteger("mappaint.node.virtual-space", 70);
1180 }
1181
1182 /**
1183 * Calculate a virtual node if there is enough visual space to draw a
1184 * crosshair node and the middle of a way segment is clicked. If the
1185 * user drags the crosshair node, it will be added to all ways in
1186 * <code>virtualWays</code>.
1187 *
1188 * @param p the point clicked
1189 * @return whether
1190 * <code>virtualNode</code> and
1191 * <code>virtualWays</code> were setup.
1192 */
1193 private boolean activateVirtualNodeNearPoint(Point p) {
1194 if (nodeVirtualSize > 0) {
1195
1196 Collection<WaySegment> selVirtualWays = new LinkedList<>();
1197 Pair<Node, Node> vnp = null, wnp = new Pair<>(null, null);
1198
1199 for (WaySegment ws : mv.getNearestWaySegments(p, mv.isSelectablePredicate)) {
1200 Way w = ws.way;
1201
1202 wnp.a = w.getNode(ws.lowerIndex);
1203 wnp.b = w.getNode(ws.lowerIndex + 1);
1204 MapViewPoint p1 = mv.getState().getPointFor(wnp.a);
1205 MapViewPoint p2 = mv.getState().getPointFor(wnp.b);
1206 if (WireframeMapRenderer.isLargeSegment(p1, p2, virtualSpace)) {
1207 Point2D pc = new Point2D.Double((p1.getInViewX() + p2.getInViewX()) / 2, (p1.getInViewY() + p2.getInViewY()) / 2);
1208 if (p.distanceSq(pc) < virtualSnapDistSq2) {
1209 // Check that only segments on top of each other get added to the
1210 // virtual ways list. Otherwise ways that coincidentally have their
1211 // virtual node at the same spot will be joined which is likely unwanted
1212 Pair.sort(wnp);
1213 if (vnp == null) {
1214 vnp = new Pair<>(wnp.a, wnp.b);
1215 virtualNode = new Node(mv.getLatLon(pc.getX(), pc.getY()));
1216 }
1217 if (vnp.equals(wnp)) {
1218 // if mutiple line segments have the same points,
1219 // add all segments to be splitted to virtualWays list
1220 // if some lines are selected, only their segments will go to virtualWays
1221 (w.isSelected() ? selVirtualWays : virtualWays).add(ws);
1222 }
1223 }
1224 }
1225 }
1226
1227 if (!selVirtualWays.isEmpty()) {
1228 virtualWays = selVirtualWays;
1229 }
1230 }
1231
1232 return !virtualWays.isEmpty();
1233 }
1234
1235 private void createMiddleNodeFromVirtual(EastNorth currentEN) {
1236 Collection<Command> virtualCmds = new LinkedList<>();
1237 virtualCmds.add(new AddCommand(virtualNode));
1238 for (WaySegment virtualWay : virtualWays) {
1239 Way w = virtualWay.way;
1240 Way wnew = new Way(w);
1241 wnew.addNode(virtualWay.lowerIndex + 1, virtualNode);
1242 virtualCmds.add(new ChangeCommand(w, wnew));
1243 }
1244 virtualCmds.add(new MoveCommand(virtualNode, startEN, currentEN));
1245 String text = trn("Add and move a virtual new node to way",
1246 "Add and move a virtual new node to {0} ways", virtualWays.size(),
1247 virtualWays.size());
1248 Main.main.undoRedo.add(new SequenceCommand(text, virtualCmds));
1249 getLayerManager().getEditDataSet().setSelected(Collections.singleton((OsmPrimitive) virtualNode));
1250 clear();
1251 }
1252
1253 private void clear() {
1254 virtualWays.clear();
1255 virtualNode = null;
1256 }
1257
1258 private boolean hasVirtualNode() {
1259 return virtualNode != null;
1260 }
1261
1262 private boolean hasVirtualWaysToBeConstructed() {
1263 return !virtualWays.isEmpty();
1264 }
1265 }
1266
1267 /**
1268 * Returns {@code o} as collection of {@code o}'s type.
1269 * @param <T> object type
1270 * @param o any object
1271 * @return {@code o} as collection of {@code o}'s type.
1272 */
1273 protected static <T> Collection<T> asColl(T o) {
1274 return o == null ? Collections.emptySet() : Collections.singleton(o);
1275 }
1276}
Note: See TracBrowser for help on using the repository browser.