- Timestamp:
- 2012-09-04T00:13:37+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r5311 r5500 4 4 import static org.openstreetmap.josm.tools.I18n.marktr; 5 5 6 import java.awt.Color; 6 7 import java.awt.Cursor; 8 import java.awt.Graphics; 7 9 import java.awt.Point; 10 import java.awt.Polygon; 8 11 import java.awt.Rectangle; 9 12 import java.awt.geom.AffineTransform; … … 108 111 protected EastNorth center = calculateDefaultCenter(); 109 112 113 private static final Object paintRequestLock = new Object(); 114 private Rectangle paintRect = null; 115 private Polygon paintPoly = null; 116 110 117 public NavigatableComponent() { 111 118 setLayout(null); … … 1266 1273 Cursors = c; 1267 1274 } 1275 1276 @Override 1277 public void paint(Graphics g) { 1278 synchronized (paintRequestLock) { 1279 if (paintRect != null) { 1280 Graphics g2 = g.create(); 1281 g2.setColor(Color.BLACK); 1282 g2.setXORMode(Color.WHITE); 1283 g2.drawRect(paintRect.x, paintRect.y, paintRect.width, paintRect.height); 1284 } 1285 if (paintPoly != null) { 1286 Graphics g2 = g.create(); 1287 g2.setColor(Color.WHITE); 1288 g2.drawPolyline(paintPoly.xpoints, paintPoly.ypoints, paintPoly.npoints); 1289 } 1290 } 1291 super.paint(g); 1292 } 1293 1294 /** 1295 * Requests to paint the given {@code Rectangle}. 1296 * @param r The Rectangle to draw 1297 * @see #requestClearRect 1298 * @since 5500 1299 */ 1300 public void requestPaintRect(Rectangle r) { 1301 if (r != null) { 1302 synchronized (paintRequestLock) { 1303 paintRect = r; 1304 } 1305 repaint(); 1306 } 1307 } 1308 1309 /** 1310 * Requests to paint the given {@code Polygon} as a polyline (unclosed polygon). 1311 * @param p The Polygon to draw 1312 * @see #requestClearPoly 1313 * @since 5500 1314 */ 1315 public void requestPaintPoly(Polygon p) { 1316 if (p != null) { 1317 synchronized (paintRequestLock) { 1318 paintPoly = p; 1319 } 1320 repaint(); 1321 } 1322 } 1323 1324 /** 1325 * Requests to clear the rectangled previously drawn. 1326 * @see #requestPaintRect 1327 * @since 5500 1328 */ 1329 public void requestClearRect() { 1330 synchronized (paintRequestLock) { 1331 paintRect = null; 1332 } 1333 repaint(); 1334 } 1335 1336 /** 1337 * Requests to clear the polyline previously drawn. 1338 * @see #requestPaintPoly 1339 * @since 5500 1340 */ 1341 public void requestClearPoly() { 1342 synchronized (paintRequestLock) { 1343 paintPoly = null; 1344 } 1345 repaint(); 1346 } 1268 1347 } -
trunk/src/org/openstreetmap/josm/gui/SelectionManager.java
r5152 r5500 2 2 package org.openstreetmap.josm.gui; 3 3 4 import java.awt.Color;5 4 import java.awt.Component; 6 import java.awt.Graphics;7 5 import java.awt.Point; 8 6 import java.awt.Polygon; … … 57 55 * Called, when the left mouse button was released. 58 56 * @param r The rectangle that is currently the selection. 59 * @param alt Whether the alt key was pressed 60 * @param shift Whether the shift key was pressed 61 * @param ctrl Whether the ctrl key was pressed 57 * @param e The mouse event. 62 58 * @see InputEvent#getModifiersEx() 63 59 */ … … 119 115 * Register itself at the given event source. 120 116 * @param eventSource The emitter of the mouse events. 117 * @param lassoMode {@code true} to enable lasso mode, {@code false} to disable it. 121 118 */ 122 119 public void register(NavigatableComponent eventSource, boolean lassoMode) { … … 199 196 Rectangle r; 200 197 if (!lassoMode) { 201 paintRect();198 nc.requestClearRect(); 202 199 r = getSelectionRectangle(); 203 200 204 201 lasso = rectToPolygon(r); 205 202 } else { 203 nc.requestClearPoly(); 206 204 lasso.addPoint(mousePos.x, mousePos.y); 207 205 r = lasso.getBounds(); … … 216 214 217 215 /** 218 * Draw a selection rectangle on screen. If already a rectangle is drawn, 219 * it is removed instead. 216 * Draws a selection rectangle on screen. 220 217 */ 221 218 private void paintRect() { 222 219 if (mousePos == null || mousePosStart == null || mousePos == mousePosStart) 223 220 return; 224 Graphics g = nc.getGraphics(); 225 g.setColor(Color.BLACK); 226 g.setXORMode(Color.WHITE); 227 228 Rectangle r = getSelectionRectangle(); 229 g.drawRect(r.x,r.y,r.width,r.height); 230 } 231 221 nc.requestPaintRect(getSelectionRectangle()); 222 } 223 232 224 private void paintLasso() { 233 225 if (mousePos == null || mousePosStart == null || mousePos == mousePosStart) { 234 226 return; 235 227 } 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 228 lasso.addPoint(mousePos.x, mousePos.y); 229 nc.requestPaintPoly(lasso); 245 230 } 246 231 … … 302 287 * @param alt Whether the alt key was pressed, which means select all 303 288 * objects that are touched, instead those which are completely covered. 289 * @return The collection of selected objects. 304 290 */ 305 291 public Collection<OsmPrimitive> getSelectedObjects(boolean alt) { … … 368 354 } 369 355 356 /** 357 * Enables or disables the lasso mode. 358 * @param lassoMode {@code true} to enable lasso mode, {@code false} to disable it. 359 */ 370 360 public void setLassoMode(boolean lassoMode) { 371 361 this.lassoMode = lassoMode;
Note:
See TracChangeset
for help on using the changeset viewer.