source: josm/src/org/openstreetmap/josm/actions/mapmode/SelectionAction.java@ 22

Last change on this file since 22 was 22, checked in by imi, 18 years ago

starting restructure of dataset. Checkpoint is broken!

File size: 3.5 KB
Line 
1package org.openstreetmap.josm.actions.mapmode;
2
3import java.awt.Rectangle;
4import java.awt.event.KeyEvent;
5import java.util.Collection;
6
7import org.openstreetmap.josm.Main;
8import org.openstreetmap.josm.data.osm.OsmPrimitive;
9import org.openstreetmap.josm.gui.MapFrame;
10import org.openstreetmap.josm.gui.SelectionManager;
11import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded;
12
13/**
14 * This MapMode enables the user to easy make a selection of different objects.
15 *
16 * The selected objects are drawn in a different style.
17 *
18 * Holding and dragging the left mouse button draws an selection rectangle.
19 * When releasing the left mouse button, all objects within the rectangle get
20 * selected.
21 *
22 * When releasing the left mouse button while the right mouse button pressed,
23 * nothing happens (the selection rectangle will be cleared, however).
24 *
25 * When releasing the mouse button and one of the following keys was hold:
26 *
27 * If Alt key was hold, select all objects that are touched by the
28 * selection rectangle. If the Alt key was not hold, select only those objects
29 * completly within (e.g. for tracks mean: only if all nodes of the track are
30 * within).
31 *
32 * If Shift key was hold, the objects are added to the current selection. If
33 * Shift key wasn't hold, the current selection get replaced.
34 *
35 * If Ctrl key was hold, remove all objects under the current rectangle from
36 * the active selection (if there were any). Nothing is added to the current
37 * selection.
38 *
39 * Alt can be combined with Ctrl or Shift. Ctrl and Shift cannot be combined.
40 * If both are pressed, nothing happens when releasing the mouse button.
41 *
42 * The user can also only click on the map. All total movements of 2 or less
43 * pixel are considered "only click". If that happens, the nearest Node will
44 * be selected if there is any within 10 pixel range. If there is no Node within
45 * 10 pixel, the nearest LineSegment (or Street, if user hold down the Alt-Key)
46 * within 10 pixel range is selected. If there is no LineSegment within 10 pixel
47 * and the user clicked in or 10 pixel away from an area, this area is selected.
48 * If there is even no area, nothing is selected. Shift and Ctrl key applies to
49 * this as usual. For more, @see MapView#getNearest(Point, boolean)
50 *
51 * @author imi
52 */
53public class SelectionAction extends MapMode implements SelectionEnded {
54
55 /**
56 * The SelectionManager that manages the selection rectangle.
57 */
58 private SelectionManager selectionManager;
59
60 /**
61 * Create a new SelectionAction in the given frame.
62 * @param mapFrame The frame this action belongs to
63 */
64 public SelectionAction(MapFrame mapFrame) {
65 super("Selection", "selection", "Select objects by dragging or clicking", KeyEvent.VK_S, mapFrame);
66 this.selectionManager = new SelectionManager(this, false, mv);
67 }
68
69 @Override
70 public void registerListener() {
71 super.registerListener();
72 selectionManager.register(mv);
73 }
74
75 @Override
76 public void unregisterListener() {
77 super.unregisterListener();
78 selectionManager.unregister(mv);
79 }
80
81
82 /**
83 * Check the state of the keys and buttons and set the selection accordingly.
84 */
85 public void selectionEnded(Rectangle r, boolean alt, boolean shift, boolean ctrl) {
86 if (shift && ctrl)
87 return; // not allowed together
88
89 if (!ctrl && !shift)
90 Main.main.ds.clearSelection(); // new selection will replace the old.
91
92 Collection<OsmPrimitive> selectionList = selectionManager.getObjectsInRectangle(r,alt);
93 for (OsmPrimitive osm : selectionList)
94 osm.setSelected(!ctrl);
95 mv.repaint();
96 }
97
98 @Override
99 protected boolean isEditMode() {
100 return false;
101 }
102}
Note: See TracBrowser for help on using the repository browser.