Changeset 5152 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2012-04-01T19:11:26+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r5093 r5152 84 84 rotate("rotate", null), 85 85 merge("crosshair", null), 86 lasso("normal", "rope"), 86 87 merge_to_node("crosshair", "joinnode"), 87 88 move(Cursor.MOVE_CURSOR); … … 98 99 } 99 100 } 101 102 private boolean lassoMode = false; 100 103 101 104 // Cache previous mouse event (needed when only the modifier keys are … … 172 175 mv.addMouseListener(this); 173 176 mv.addMouseMotionListener(this); 174 mv.setVirtualNodesEnabled( 175 Main.pref.getInteger("mappaint.node.virtual-size", 8) != 0); 177 mv.setVirtualNodesEnabled(Main.pref.getInteger("mappaint.node.virtual-size", 8) != 0); 176 178 drawTargetHighlight = Main.pref.getBoolean("draw.target-highlight", true); 177 179 // This is required to update the cursors when ctrl/shift/alt is pressed … … 241 243 break; 242 244 case select: 243 c = "rect" + (shift ? "_add" : (ctrl ? "_rm" : "")); 245 if (lassoMode) { 246 c = "lasso"; 247 } else { 248 c = "rect" + (shift ? "_add" : (ctrl ? "_rm" : "")); 249 } 244 250 break; 245 251 } … … 727 733 case select: 728 734 default: 729 selectionManager.register(mv );735 selectionManager.register(mv, lassoMode); 730 736 selectionManager.mousePressed(e); 731 737 break; … … 825 831 public void selectionEnded(Rectangle r, MouseEvent e) { 826 832 updateKeyModifiers(e); 827 selectPrims(selectionManager.getObjectsInRectangle(r, alt), e, true, true); 833 mv.repaint(); 834 selectPrims(selectionManager.getSelectedObjects(alt), e, true, true); 828 835 } 829 836 … … 974 981 return l instanceof OsmDataLayer; 975 982 } 983 984 public void setLassoMode(boolean lassoMode) { 985 System.out.println(lassoMode); 986 this.selectionManager.setLassoMode(lassoMode); 987 this.lassoMode = lassoMode; 988 } 976 989 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java
r4982 r5152 60 60 @Override public void enterMode() { 61 61 super.enterMode(); 62 selectionManager.register(Main.map.mapView );62 selectionManager.register(Main.map.mapView, false); 63 63 } 64 64 -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r5092 r5152 41 41 42 42 import org.openstreetmap.josm.Main; 43 import org.openstreetmap.josm.actions.LassoModeAction; 43 44 import org.openstreetmap.josm.actions.mapmode.DeleteAction; 44 45 import org.openstreetmap.josm.actions.mapmode.DrawAction; … … 109 110 110 111 // Map modes 111 p rivate final MapModemapModeSelect;112 public final SelectAction mapModeSelect; 112 113 private final MapMode mapModeDraw; 113 114 private final MapMode mapModeZoom; … … 159 160 toolBarActions.setFloatable(false); 160 161 addMapMode(new IconToggleButton(mapModeSelect = new SelectAction(this))); 162 addMapMode(new IconToggleButton(new LassoModeAction(), true)); 161 163 addMapMode(new IconToggleButton(mapModeDraw = new DrawAction(this))); 162 164 addMapMode(new IconToggleButton(mapModeZoom = new ZoomAction(this))); -
trunk/src/org/openstreetmap/josm/gui/SelectionManager.java
r3642 r5152 6 6 import java.awt.Graphics; 7 7 import java.awt.Point; 8 import java.awt.Polygon; 8 9 import java.awt.Rectangle; 9 10 import java.awt.event.InputEvent; … … 97 98 private boolean aspectRatio; 98 99 100 private boolean lassoMode; 101 private Polygon lasso = new Polygon(); 102 99 103 /** 100 104 * Create a new SelectionManager. … … 116 120 * @param eventSource The emitter of the mouse events. 117 121 */ 118 public void register(NavigatableComponent eventSource) { 122 public void register(NavigatableComponent eventSource, boolean lassoMode) { 123 this.lassoMode = lassoMode; 119 124 eventSource.addMouseListener(this); 120 125 eventSource.addMouseMotionListener(this); … … 147 152 if (e.getButton() == MouseEvent.BUTTON1) { 148 153 mousePosStart = mousePos = e.getPoint(); 154 155 lasso.reset(); 156 lasso.addPoint(mousePosStart.x, mousePosStart.y); 149 157 } 150 158 } … … 160 168 mousePosStart = mousePos = e.getPoint(); 161 169 } 162 paintRect(); 170 if (!lassoMode) { 171 paintRect(); 172 } 163 173 } 164 174 165 175 if (buttonPressed == MouseEvent.BUTTON1_DOWN_MASK) { 166 176 mousePos = e.getPoint(); 167 paintRect(); 177 if (lassoMode) { 178 paintLasso(); 179 } else { 180 paintRect(); 181 } 168 182 } else if (buttonPressed == (MouseEvent.BUTTON1_DOWN_MASK | MouseEvent.BUTTON3_DOWN_MASK)) { 169 183 mousePosStart.x += e.getX()-mousePos.x; … … 182 196 if (mousePos == null || mousePosStart == null) 183 197 return; // injected release from outside 184 185 198 // disable the selection rect 186 paintRect(); 187 Rectangle r = getSelectionRectangle(); 199 Rectangle r; 200 if (!lassoMode) { 201 paintRect(); 202 r = getSelectionRectangle(); 203 204 lasso = rectToPolygon(r); 205 } else { 206 lasso.addPoint(mousePos.x, mousePos.y); 207 r = lasso.getBounds(); 208 } 188 209 mousePosStart = null; 189 210 mousePos = null; … … 207 228 Rectangle r = getSelectionRectangle(); 208 229 g.drawRect(r.x,r.y,r.width,r.height); 230 } 231 232 private void paintLasso() { 233 if (mousePos == null || mousePosStart == null || mousePos == mousePosStart) { 234 return; 235 } 236 237 Graphics g = nc.getGraphics(); 238 g.setColor(Color.WHITE); 239 240 int lastPosX = lasso.xpoints[lasso.npoints - 1]; 241 int lastPosY = lasso.ypoints[lasso.npoints - 1]; 242 g.drawLine(lastPosX, lastPosY, mousePos.x, mousePos.y); 243 244 lasso.addPoint(mousePos.x, mousePos.y); 209 245 } 210 246 … … 261 297 262 298 /** 263 * Return a list of all objects in the rectangle, respecting the different299 * Return a list of all objects in the selection, respecting the different 264 300 * modifier. 265 * @param alt Whether the alt key was pressed, which means select all objects 266 * that are touched, instead those which are completly covered. 267 */ 268 public Collection<OsmPrimitive> getObjectsInRectangle(Rectangle r, boolean alt) { 301 * 302 * @param alt Whether the alt key was pressed, which means select all 303 * objects that are touched, instead those which are completely covered. 304 */ 305 public Collection<OsmPrimitive> getSelectedObjects(boolean alt) { 306 269 307 Collection<OsmPrimitive> selection = new LinkedList<OsmPrimitive>(); 270 308 271 309 // whether user only clicked, not dragged. 272 boolean clicked = r.width <= 2 && r.height <= 2; 273 Point center = new Point(r.x+r.width/2, r.y+r.height/2); 310 boolean clicked = false; 311 Rectangle bounding = lasso.getBounds(); 312 if (bounding.height <= 2 && bounding.width <= 2) { 313 clicked = true; 314 } 274 315 275 316 if (clicked) { 317 Point center = new Point(lasso.xpoints[0], lasso.ypoints[0]); 276 318 OsmPrimitive osm = nc.getNearestNodeOrWay(center, OsmPrimitive.isSelectablePredicate, false); 277 319 if (osm != null) { … … 281 323 // nodes 282 324 for (Node n : nc.getCurrentDataSet().getNodes()) { 283 if (n.isSelectable() && r.contains(nc.getPoint(n))) {325 if (n.isSelectable() && lasso.contains(nc.getPoint(n))) { 284 326 selection.add(n); 285 327 } … … 293 335 if (alt) { 294 336 for (Node n : w.getNodes()) { 295 if (!n.isIncomplete() && r.contains(nc.getPoint(n))) {337 if (!n.isIncomplete() && lasso.contains(nc.getPoint(n))) { 296 338 selection.add(w); 297 339 break; … … 301 343 boolean allIn = true; 302 344 for (Node n : w.getNodes()) { 303 if (!n.isIncomplete() && ! r.contains(nc.getPoint(n))) {345 if (!n.isIncomplete() && !lasso.contains(nc.getPoint(n))) { 304 346 allIn = false; 305 347 break; … … 315 357 } 316 358 359 private Polygon rectToPolygon(Rectangle r) { 360 Polygon poly = new Polygon(); 361 362 poly.addPoint(r.x, r.y); 363 poly.addPoint(r.x, r.y + r.height); 364 poly.addPoint(r.x + r.width, r.y + r.height); 365 poly.addPoint(r.x + r.width, r.y); 366 367 return poly; 368 } 369 370 public void setLassoMode(boolean lassoMode) { 371 this.lassoMode = lassoMode; 372 } 373 317 374 public void mouseClicked(MouseEvent e) {} 318 375 public void mouseEntered(MouseEvent e) {}
Note:
See TracChangeset
for help on using the changeset viewer.