Changeset 26448 in osm for applications/editors/josm/plugins/FastDraw
- Timestamp:
- 2011-08-04T21:13:30+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/FastDraw
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/FastDraw/build.xml
r26442 r26448 30 30 <project name="FastDraw" default="dist" basedir="."> 31 31 <!-- enter the SVN commit message --> 32 <property name="commit.message" value="FastDraw: can hold spacebar instead of LKM, can edit existing lines"/>32 <property name="commit.message" value="FastDraw: better linux compatibility"/> 33 33 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 34 34 <property name="plugin.main.version" value="4201"/> -
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawingMode.java
r26440 r26448 25 25 import java.awt.event.AWTEventListener; 26 26 import java.awt.event.ActionEvent; 27 import java.awt.event.ActionListener; 27 28 import java.awt.event.InputEvent; 28 29 import java.awt.event.KeyEvent; 29 import java.io.IOException;30 import java.lang.annotation.Target;31 30 import java.util.*; 32 31 import javax.swing.JOptionPane; 32 import javax.swing.Timer; 33 33 34 34 import org.openstreetmap.josm.Main; … … 36 36 import org.openstreetmap.josm.actions.mapmode.MapMode; 37 37 import org.openstreetmap.josm.command.AddCommand; 38 import org.openstreetmap.josm.command.ChangeCommand;39 import org.openstreetmap.josm.command.ChangeNodesCommand;40 38 import org.openstreetmap.josm.command.Command; 41 39 import org.openstreetmap.josm.command.DeleteCommand; … … 84 82 private SequenceCommand delCmd; 85 83 private List<Node> oldNodes; 86 84 85 private final TreeSet set = new TreeSet(); 86 private Timer timer; 87 88 private KeyEvent releaseEvent; 87 89 88 90 FastDrawingMode(MapFrame mapFrame) { … … 135 137 if (w.isNew()) loadFromWay(w); 136 138 } 137 139 timer = new Timer(0, new ActionListener() { 140 @Override 141 public void actionPerformed(ActionEvent ae) { 142 timer.stop(); 143 if (set.remove(releaseEvent.getKeyCode())) { 144 doKeyReleaseEvent(releaseEvent); 145 } 146 } 147 }); 148 138 149 try { 139 150 Toolkit.getDefaultToolkit().addAWTEventListener(this, … … 213 224 } 214 225 if (!drawing) { 215 if (shift && !line.wasSimplified() && nearestIdx==i+1 ) { 226 if (!line.wasSimplified() && nearestIdx==i+1 ) { 227 if (shift) { 216 228 // highlight node to delete 217 229 g.setStroke(strokeForDelete); … … 220 232 g.drawLine(p2.x - 5, p2.y + 5,p2.x + 5, p2.y - 5); 221 233 g.setStroke(strokeForOriginal); 222 } 223 if (ctrl && !line.wasSimplified() && nearestIdx==i+1 ) { 234 } else if (ctrl) { 224 235 // highlight node to toggle fixation 225 236 g.setStroke(strokeForDelete); … … 227 238 g.drawOval(p2.x - 5, p2.y - 5, 11, 11); 228 239 g.setStroke(strokeForOriginal); 240 } 229 241 } 230 242 } … … 240 252 } 241 253 updateKeyModifiers((InputEvent) event); 254 if (event instanceof KeyEvent) { 255 KeyEvent e=(KeyEvent) event; 256 242 257 if (event.getID() == KeyEvent.KEY_PRESSED) { 258 if (timer.isRunning()) { 259 timer.stop(); 260 } else { 261 set.add((e.getKeyCode())); 262 } 243 263 doKeyEvent((KeyEvent) event); 244 264 } 245 265 if (event.getID() == KeyEvent.KEY_RELEASED) { 246 doKeyReleaseEvent((KeyEvent) event); 247 } 248 updateCursor(); 249 // updateStatusLine(); 250 repaint(); 266 if (timer.isRunning()) { 267 timer.stop(); 268 if (set.remove(e.getKeyCode())) { 269 doKeyReleaseEvent(e); 270 } 271 } else { 272 releaseEvent = e; 273 timer.restart(); 274 } 275 } 276 } 251 277 } 252 278 … … 332 358 Node nd1 = getNearestNode(e.getPoint(), settings.maxDist); 333 359 boolean nearpoint2=nd1!=null; 334 if (nearpoint!=nearpoint2) {nearpoint=nearpoint2;updateCursor();} 335 336 nearestIdx=line.findClosestPoint(e.getPoint(),settings.maxDist); 360 boolean needRepaint=false; 361 if (nearpoint!=nearpoint2) {nearpoint=nearpoint2;updateCursor();needRepaint=true;} 362 363 int nearestIdx2=line.findClosestPoint(e.getPoint(),settings.maxDist); 364 if (nearestIdx != nearestIdx2) {nearestIdx=nearestIdx2; updateCursor();needRepaint=true;} 337 365 338 366 if (!drawing) { … … 350 378 repaint(); 351 379 } 380 } else if (needRepaint) { 381 repaint(); 352 382 } 353 383 return; 354 384 } 355 updateCursor();356 385 if (line.isClosed()) setStatusLine(SIMPLIFYMODE_MESSAGE); 357 386 … … 361 390 Point lastP = line.getLastPoint(); // last point of line fragment being edited 362 391 363 392 if (nearpoint){ 364 393 if ( Math.hypot(e.getX() - lastP.x, e.getY() - lastP.y) > 1e-2) { 365 394 line.addFixed(nd1.getCoor()); // snap to node coords 366 395 repaint(); 396 return; 367 397 } 368 398 } else { 369 399 if (Math.hypot(e.getX() - lastP.x, e.getY() - lastP.y) > settings.minPixelsBetweenPoints) { 370 400 line.addLast(getLatLon(e)); // free mouse-drawing 371 401 repaint(); 372 } 373 } 402 return; 403 } 404 } 405 if (nearpoint!=nearpoint2) {nearpoint=nearpoint2;updateCursor();} 406 374 407 375 408 //statusText = getLatLon(e).toString(); updateStatusLine(); … … 377 410 378 411 private void doKeyEvent(KeyEvent e) { 379 ///System.out.println(e);412 // System.out.println(e); 380 413 switch(e.getKeyCode()) { 381 414 case KeyEvent.VK_BACK_SPACE: … … 435 468 436 469 private void doKeyReleaseEvent(KeyEvent keyEvent) { 470 //System.out.println("released "+keyEvent); 437 471 if (keyEvent.getKeyCode()==KeyEvent.VK_SPACE) stopDrawing(); 472 updateCursor(); 438 473 } 439 474 /** … … 443 478 ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 444 479 shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 480 updateCursor(); 445 481 } 446 482
Note:
See TracChangeset
for help on using the changeset viewer.