Changeset 36057 in osm for applications/editors/josm/plugins
- Timestamp:
- 2023-02-23T22:30:59+01:00 (19 months ago)
- Location:
- applications/editors/josm/plugins/FastDraw
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FDSettings.java
r34510 r36057 9 9 import org.openstreetmap.josm.spi.preferences.Config; 10 10 11 /** 12 * A holder for plugin settings 13 */ 11 14 public class FDSettings { 12 15 public NamedColorProperty COLOR_FIXED = new NamedColorProperty("fastdraw.color.delete", Color.red); -
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawConfigDialog.java
r35860 r36057 27 27 import org.openstreetmap.josm.tools.TextTagParser; 28 28 29 /** 30 * A configuration dialog 31 */ 29 32 public class FastDrawConfigDialog extends ExtendedDialog { 30 33 31 private final JLabel label1 = new JLabel(tr("Epsilon multiplier")); 32 private final JLabel label2 = new JLabel(tr("Starting Epsilon")); 33 private final JLabel label3 = new JLabel(tr("Max points count per 1 km")); 34 private final JLabel label4 = new JLabel(/* I18n: Combobox to select what a press to return key does */ tr("Enter key mode")); 35 private final JLabel label5 = new JLabel(tr("Auto add tags")); 34 private static final long serialVersionUID = -4894608522010226092L; 36 35 private final JFormattedTextField text1 = new JFormattedTextField(NumberFormat.getInstance()); 37 36 private final JFormattedTextField text2 = new JFormattedTextField(NumberFormat.getInstance()); … … 47 46 private final FDSettings settings; 48 47 48 /** 49 * Create anew configuration dialog 50 * @param settings The settings to use 51 */ 49 52 public FastDrawConfigDialog(FDSettings settings) { 50 super(MainApplication.getMainFrame(), tr("FastDraw configuration"), new String[] {tr("Ok"), tr("Cancel")});53 super(MainApplication.getMainFrame(), tr("FastDraw configuration"), tr("Ok"), tr("Cancel")); 51 54 this.settings = settings; 52 55 … … 55 58 all.setLayout(layout); 56 59 JButton pasteButton = new JButton(new AbstractAction(tr("Paste"), ImageProvider.get("apply")) { 60 private static final long serialVersionUID = -8597276971260620654L; 61 57 62 @Override 58 63 public void actionPerformed(ActionEvent e) { 59 64 String s = ClipboardUtils.getClipboardStringContent(); 60 if (s != null) { 61 if (TextTagParser.getValidatedTagsFromText(s, TextTagPaster::warning) != null) { 62 addTags.setText(s); 63 } 65 if (s != null && TextTagParser.getValidatedTagsFromText(s, TextTagPaster::warning) != null) { 66 addTags.setText(s); 64 67 } 65 68 } … … 68 71 69 72 addTags.getModel().prefs().load("fastdraw.tags-history"); 70 while (addTags.getModel().find("") != null) 73 while (addTags.getModel().find("") != null) { 71 74 addTags.getModel().removeElement(""); 75 } 72 76 77 JLabel label1 = new JLabel(tr("Epsilon multiplier")); 73 78 all.add(label1, GBC.std().insets(10, 0, 0, 0)); 74 79 all.add(text1, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5)); 80 JLabel label2 = new JLabel(tr("Starting Epsilon")); 75 81 all.add(label2, GBC.std().insets(10, 0, 0, 0)); 76 82 all.add(text2, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5)); 83 JLabel label3 = new JLabel(tr("Max points count per 1 km")); 77 84 all.add(label3, GBC.std().insets(10, 0, 0, 0)); 78 85 all.add(text3, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5)); 86 JLabel label4 = new JLabel(/* I18n: Combobox to select what a press to return key does */ tr("Enter key mode")); 79 87 all.add(label4, GBC.std().insets(10, 0, 0, 0)); 80 88 all.add(combo1, GBC.eop().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5)); 81 89 90 JLabel label5 = new JLabel(tr("Auto add tags")); 82 91 all.add(label5, GBC.std().insets(10, 0, 0, 0)); 83 92 all.add(pasteButton, GBC.eop().insets(0, 0, 0, 5)); … … 105 114 106 115 setContent(all, false); 107 setButtonIcons(new String[] {"ok", "cancel"}); 108 setToolTipTexts(new String[] { 109 tr("Save settings"), 110 tr("Cancel") 111 }); 116 setButtonIcons("ok", "cancel"); 117 setToolTipTexts(tr("Save settings"), 118 tr("Cancel")); 112 119 setDefaultButton(1); 113 //configureContextsensitiveHelp("/Action/DownloadObject", true /* show help button */);114 120 } 115 121 -
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawingMode.java
r35978 r36057 50 50 */ 51 51 class FastDrawingMode extends MapMode implements MapViewPaintable, KeyPressReleaseListener, ModifierExListener { 52 private static final long serialVersionUID = -3395918050593965929L; 52 53 // CHECKSTYLE.OFF: LineLength 53 private static final String SIMPLIFY MODE_MESSAGE =54 private static final String SIMPLIFY_MODE_MESSAGE = 54 55 tr("Q=Options, Enter=save, Ctrl-Enter=save with tags, Up/Down=tune"); 55 private static final String DRAWING MODE_MESSAGE =56 private static final String DRAWING_MODE_MESSAGE = 56 57 tr("Click or Click&drag to continue, Ctrl-Click to add fixed node, Shift-Click to delete, Enter to simplify or save, Ctrl-Shift-Click to start new line"); 57 58 // CHECKSTYLE.ON: LineLength … … 68 69 private final Cursor cursorShift; 69 70 private final Cursor cursorReady; 70 //private final Cursor cursorNode;71 71 private final Cursor cursorDrawing; 72 72 private boolean nearSomeNode; … … 80 80 private Way oldWay; 81 81 82 FastDrawingMode( MapFrame mapFrame) {83 super(tr("FastDrawing"), "turbopen .png", tr("Fast drawing mode"),82 FastDrawingMode() { 83 super(tr("FastDrawing"), "turbopen", tr("Fast drawing mode"), 84 84 Shortcut.registerShortcut("mapmode:fastdraw", tr("Mode: {0}", tr("Fast drawing mode")), KeyEvent.VK_F, Shortcut.SHIFT), 85 85 Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); … … 89 89 cursorShift = ImageProvider.getCursor("crosshair", "new"); 90 90 cursorReady = ImageProvider.getCursor("crosshair", "ready"); 91 //cursorNode = ImageProvider.getCursor("crosshair", "joinnode");92 91 cursorDrawing = ImageProvider.getCursor("crosshair", "mode"); 93 //loadPrefs();94 92 } 95 93 … … 98 96 @Override 99 97 public void enterMode() { 98 this.updateEnabledState(); 100 99 if (!isEnabled()) 101 100 return; … … 150 149 } 151 150 152 private final ArrayList<Point> fixedPoints = new ArrayList<>(3000); // temporary stora te for paint151 private final ArrayList<Point> fixedPoints = new ArrayList<>(3000); // temporary storage for paint 153 152 154 153 ////////// Event listener methods … … 201 200 g.fillRect(p2.x - rp, p2.y - rp, dp, dp); 202 201 } 203 if (!drawing) { 204 if (!line.wasSimplified() && nearestPointIndex == i+1) { 205 if (shift) { 206 // highlight node to delete 207 g.setStroke(settings.deleteStroke); 208 g.setColor(settings.COLOR_DELETE.get()); 209 g.drawLine(p2.x - 5, p2.y - 5, p2.x + 5, p2.y + 5); 210 g.drawLine(p2.x - 5, p2.y + 5, p2.x + 5, p2.y - 5); 211 g.setStroke(settings.normalStroke); 212 } else if (ctrl) { 213 // highlight node to toggle fixation 214 g.setStroke(settings.deleteStroke); 215 g.setColor(line.isFixed(pp2) ? settings.COLOR_NORMAL.get() : settings.COLOR_FIXED.get()); 216 g.fillOval(p2.x - bigDotSize/2-2, p2.y - bigDotSize/2-2, bigDotSize+4, bigDotSize+4); 217 g.setStroke(settings.normalStroke); 218 } 202 if (!drawing && !line.wasSimplified() && nearestPointIndex == i+1) { 203 if (shift) { 204 // highlight node to delete 205 g.setStroke(settings.deleteStroke); 206 g.setColor(settings.COLOR_DELETE.get()); 207 g.drawLine(p2.x - 5, p2.y - 5, p2.x + 5, p2.y + 5); 208 g.drawLine(p2.x - 5, p2.y + 5, p2.x + 5, p2.y - 5); 209 g.setStroke(settings.normalStroke); 210 } else if (ctrl) { 211 // highlight node to toggle fixation 212 g.setStroke(settings.deleteStroke); 213 g.setColor(line.isFixed(pp2) ? settings.COLOR_NORMAL.get() : settings.COLOR_FIXED.get()); 214 g.fillOval(p2.x - bigDotSize/2-2, p2.y - bigDotSize/2-2, bigDotSize+4, bigDotSize+4); 215 g.setStroke(settings.normalStroke); 219 216 } 220 217 } … … 286 283 287 284 private void startDrawing(Point point, boolean fixFlag) { 288 //if (line.isClosed()) { setStatusLine(tr(SIMPLIFYMODE_MESSAGE));return; }289 285 drawing = true; 290 286 if (line.wasSimplified()) { … … 293 289 saveAsWay(false); 294 290 newDrawing(); 295 //line.clearSimplifiedVersion();296 291 } 297 292 … … 301 296 if (nd1 != null) { 302 297 // found node, make it fixed point of the line 303 //System.out.println("node "+nd1);304 298 p = nd1.getCoor(); 305 299 line.fixPoint(p); … … 325 319 drawing = false; 326 320 highlightedFragmentStart = null; 327 if (!line.isClosed()) setStatusLine(DRAWING MODE_MESSAGE);321 if (!line.isClosed()) setStatusLine(DRAWING_MODE_MESSAGE); 328 322 updateCursor(); 329 323 repaint(); … … 380 374 return; 381 375 } 382 if (line.isClosed()) setStatusLine(SIMPLIFY MODE_MESSAGE);376 if (line.isClosed()) setStatusLine(SIMPLIFY_MODE_MESSAGE); 383 377 384 378 // do not draw points close to existing points - we do not want self-intersections … … 391 385 // free mouse-drawing 392 386 if (nearSomeNode) { 393 if (settings.snapNodes && lastP != null && Math.hypot(e.getX() - lastP.x, e.getY() - lastP.y) > 1e-2) { 387 if (nd1 != null && settings.snapNodes && lastP != null 388 && Math.hypot((double) e.getX() - lastP.x, (double) e.getY() - lastP.y) > 1e-2) { 394 389 line.addFixed(nd1.getCoor()); // snap to node coords 395 390 repaint(); … … 397 392 } 398 393 } else { 399 if (lastP != null && Math.hypot( e.getX() - lastP.x,e.getY() - lastP.y) > settings.minPixelsBetweenPoints) {394 if (lastP != null && Math.hypot((double) e.getX() - lastP.x, (double) e.getY() - lastP.y) > settings.minPixelsBetweenPoints) { 400 395 line.addLast(getLatLon(e)); // add new point 401 396 repaint(); … … 426 421 // first Enter = simplify, second = save the way 427 422 if (!line.wasSimplified()) { 428 //line.simplify(eps);429 423 switch(settings.simplifyMode) { 430 424 case 0: //case 1: … … 456 450 case KeyEvent.VK_UP: 457 451 if (ctrl || shift || alt) return; 458 // lessdetails452 // fewer details 459 453 e.consume(); 460 454 if (line.wasSimplified()) changeEpsilon(1/settings.epsilonMult); … … 483 477 tr("{0} m - length of the line\n{1} nodes\n{2} points per km (maximum)\n{3} points per km (average)", 484 478 line.getLength(), line.getPoints().size(), line.getNodesPerKm(settings.pkmBlockSize), 485 line.getNodesPerKm(1 000000)),479 line.getNodesPerKm(1_000_000)), 486 480 tr("Line information"), JOptionPane.INFORMATION_MESSAGE); 487 481 break; 488 482 case KeyEvent.VK_Q: 489 // lessdetails483 // fewer details 490 484 e.consume(); 491 485 new FastDrawConfigDialog(settings).showDialog(); … … 508 502 @Override 509 503 public void doKeyReleased(KeyEvent keyEvent) { 510 //System.out.println("released "+keyEvent);511 504 if (keyEvent.getKeyCode() == KeyEvent.VK_SPACE) stopDrawing(); 512 505 updateCursor(); … … 550 543 } else { 551 544 w = new Way(oldWay); 552 w.setNodes(new ArrayList< Node>()); // nodes will be created frosm scratch545 w.setNodes(new ArrayList<>()); // nodes will be created from scratch 553 546 } 554 547 … … 586 579 if (!settings.autoTags.isEmpty()) { 587 580 Map<String, String> tags = TextTagParser.readTagsFromText(settings.autoTags); 588 for ( String k: tags.keySet()) {589 w.put( k, tags.get(k));581 for (Map.Entry<String, String> entry : tags.entrySet()) { 582 w.put(entry.getKey(), entry.getValue()); 590 583 } 591 584 } … … 620 613 621 614 void changeEpsilon(double k) { 622 //System.out.println(tr("Eps={0}", eps));623 615 eps *= k; 624 616 line.simplify(eps); … … 636 628 repaint(); 637 629 } 638 639 /*private Node findClosestNode(LatLon p, double d) {640 Node nn=null;641 double dist,minD=1e10,x,y;642 Point pscreen=getPoint(p); x=pscreen.x; y=pscreen.y;643 BBox b=new BBox(new LatLon(p.lat()-deltaLatLon,p.lon()-deltaLatLon),644 new LatLon(p.lat()+deltaLatLon,p.lon()+deltaLatLon));645 List<Node> nodes = getCurrentDataSet().searchNodes(b);646 for (Node n: nodes) {647 dist = Math.sqrt(getPoint(n.getCoor()).distanceSq(x,y));648 if (dist<d && dist<minD) {649 nn=n;650 minD=dist;651 };652 }653 return nn;654 }*/655 630 656 631 private void loadFromWay(Way w) { … … 681 656 setStatusLine(tr("Eps={0}, {1} points, {2} p/km", 682 657 eps, line.getSimplePointsCount(), line.getNodesPerKm(settings.pkmBlockSize))+" " 683 + SIMPLIFYMODE_MESSAGE);658 + SIMPLIFY_MODE_MESSAGE); 684 659 } 685 660 … … 687 662 MapView mapView = MainApplication.getMap().mapView; 688 663 if (shift) mapView.setCursor(cursorShift); else 689 if (line.isClosed() || (nearestPointIndex == 0)) mapView.setCursor(cursorReady); else690 if (ctrl) mapView.setCursor(cursorCtrl); else691 if (nearSomeNode && settings.snapNodes) mapView.setCursor(cursorCtrl); else692 if (drawing) mapView.setCursor(cursorDrawing); else693 694 } 695 696 private void repaint() {664 if (line.isClosed() || (nearestPointIndex == 0)) mapView.setCursor(cursorReady); 665 else if (ctrl) mapView.setCursor(cursorCtrl); 666 else if (nearSomeNode && settings.snapNodes) mapView.setCursor(cursorCtrl); 667 else if (drawing) mapView.setCursor(cursorDrawing); 668 else mapView.setCursor(cursorDraw); 669 } 670 671 private static void repaint() { 697 672 MainApplication.getMap().mapView.repaint(); 698 673 } … … 703 678 if (selectedWays != null // if there is a selection 704 679 && selectedWays.size() == 1 // and one way is selected 705 && line.getPoints(). size() == 0) /* and theris no already drawn line */ {680 && line.getPoints().isEmpty()) /* and there is no already drawn line */ { 706 681 // we can start drawing new way starting from old one 707 682 Way w = selectedWays.iterator().next(); -
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawingPlugin.java
r33583 r36057 8 8 import org.openstreetmap.josm.plugins.PluginInformation; 9 9 10 /** 11 * The plugin entry point 12 */ 10 13 public class FastDrawingPlugin extends Plugin { 11 14 … … 17 20 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 18 21 if (oldFrame == null && newFrame != null) { 19 MainApplication.getMap().addMapMode(new IconToggleButton(new FastDrawingMode( MainApplication.getMap())));22 MainApplication.getMap().addMapMode(new IconToggleButton(new FastDrawingMode())); 20 23 } 21 24 } -
applications/editors/josm/plugins/FastDraw/test/unit/org/openstreetmap/josm/plugins/fastdraw/DrawnPolyLineTest.java
r36056 r36057 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.fastdraw; 2 3
Note:
See TracChangeset
for help on using the changeset viewer.