Changeset 26468 in osm for applications
- Timestamp:
- 2011-08-07T08:25:31+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/FastDraw
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/FastDraw/build.xml
r26460 r26468 30 30 <project name="FastDraw" default="dist" basedir="."> 31 31 <!-- enter the SVN commit message --> 32 <property name="commit.message" value="FastDraw: fix NPE and relation bugs after editing"/>32 <property name="commit.message" value="FastDraw: more settings, autosave"/> 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/DrawnPolyLine.java
r26309 r26468 342 342 //p1 = getPoint(pp1); 343 343 pp2 = it2.next(); 344 //p2 = getPoint(pp2);344 //p2 =sa getPoint(pp2); 345 345 lens[i]=pp1.greatCircleDistance(pp2); 346 346 } -
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FDSettings.java
r26455 r26468 24 24 public int pkmBlockSize; 25 25 public boolean drawLastSegment; 26 // snap to nodes 27 public boolean snapNodes; 28 // add fixed foints on mouse click 29 public boolean fixedClick; 30 // add fixed foints on spacebar 31 public boolean fixedSpacebar; 32 // option for simplifiction: 0="Autosimplify and wait", 33 //1="Simplify and wait", 2="Save as is" 34 public int simplifyMode; 26 35 27 36 public void loadPrefs() { … … 39 48 pkmBlockSize = Main.pref.getInteger("fastdraw.pkmblocksize", 10); 40 49 drawLastSegment = Main.pref.getBoolean("fastdraw.drawlastsegment", true); 50 snapNodes = Main.pref.getBoolean("fastdraw.snapnodes", true); 51 fixedClick = Main.pref.getBoolean("fastdraw.fixedclick", false); 52 fixedSpacebar = Main.pref.getBoolean("fastdraw.fixedspacebar", false); 53 simplifyMode = Main.pref.getInteger("fastdraw.simplifymode", 0); 41 54 } 42 55 … … 55 68 Main.pref.putInteger("fastdraw.pkmblocksize",pkmBlockSize); 56 69 Main.pref.put("fastdraw.drawlastsegment",drawLastSegment); 70 Main.pref.put("fastdraw.snapnodes", snapNodes); 71 Main.pref.put("fastdraw.fixedclick", fixedClick); 72 Main.pref.put("fastdraw.fixedspacebar", fixedSpacebar); 73 Main.pref.putInteger("fastdraw.simplifymode", simplifyMode); 57 74 try {Main.pref.save();} catch (IOException e) { 58 75 System.err.println(tr("Can not save preferences")); 59 76 } 60 61 77 } 62 78 } -
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawConfigDialog.java
r26303 r26468 5 5 package org.openstreetmap.josm.plugins.fastdraw; 6 6 7 import org.openstreetmap.josm.tools.GBC; 8 import java.awt.GridBagLayout; 7 9 import javax.swing.JOptionPane; 8 10 import java.text.NumberFormat; … … 10 12 import org.openstreetmap.josm.Main; 11 13 import org.openstreetmap.josm.gui.ExtendedDialog; 12 import javax.swing.GroupLayout; 14 import javax.swing.JCheckBox; 15 import javax.swing.JComboBox; 13 16 import javax.swing.JFormattedTextField; 14 17 import javax.swing.JPanel; 15 18 import javax.swing.JLabel; 16 import javax.swing.JTextField;17 19 import static org.openstreetmap.josm.tools.I18n.tr; 18 20 … … 22 24 super(Main.parent,tr("FastDraw configuration"),new String[] {tr("Ok"), tr("Cancel")}); 23 25 JPanel all = new JPanel(); 24 Gr oupLayout layout = new GroupLayout(all);26 GridBagLayout layout = new GridBagLayout(); 25 27 all.setLayout(layout); 26 layout.setAutoCreateGaps(true);27 layout.setAutoCreateContainerGaps(true);28 28 29 29 JLabel label1=new JLabel(tr("Epsilon multiplier")); 30 30 JLabel label2=new JLabel(tr("Starting Epsilon")); 31 31 JLabel label3=new JLabel(tr("Max points count per 1 km")); 32 JLabel label4=new JLabel(tr("Enter key mode")); 32 33 JFormattedTextField text1=new JFormattedTextField(NumberFormat.getInstance()); 33 34 JFormattedTextField text2=new JFormattedTextField(NumberFormat.getInstance()); 34 35 JFormattedTextField text3=new JFormattedTextField(NumberFormat.getInstance()); 35 layout.setHorizontalGroup( 36 layout.createSequentialGroup() 37 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) 38 .addComponent(label1) 39 .addComponent(label2) 40 .addComponent(label3)) 41 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) 42 .addComponent(text1) 43 .addComponent(text2) 44 .addComponent(text3) 45 ) 46 ); 47 layout.setVerticalGroup( 48 layout.createSequentialGroup() 49 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) 50 .addComponent(label1) 51 .addComponent(text1)) 52 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) 53 .addComponent(label2) 54 .addComponent(text2)) 55 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) 56 .addComponent(label3) 57 .addComponent(text3)) 58 ); 36 // JComboBox combo1=new JComboBox(new String[]{tr("Autosimplify and wait"), 37 // tr("Autosimplify and save"),tr("Simplify and wait"),tr("Simplify and save"), 38 // tr("Save as is")}); 39 JComboBox combo1=new JComboBox(new String[]{tr("Autosimplify"), 40 tr("Simplify with initial epsilon"),tr("Save as is")}); 41 JCheckBox snapCb=new JCheckBox(tr("Snap to nodes")); 42 JCheckBox fixedClickCb = new JCheckBox(tr("Add fixed points on click")); 43 JCheckBox fixedSpaceCb = new JCheckBox(tr("Add fixed points on spacebar")); 44 all.add(label1,GBC.std().insets(10,0,0,0)); 45 all.add(text1, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5)); 46 all.add(label2,GBC.std().insets(10,0,0,0)); 47 all.add(text2, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5)); 48 all.add(label3,GBC.std().insets(10,0,0,0)); 49 all.add(text3, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5)); 50 all.add(label4,GBC.std().insets(10,0,0,0)); 51 all.add(combo1, GBC.eop().fill(GBC.HORIZONTAL).insets(5,0,0,5)); 52 53 all.add(snapCb,GBC.eop().insets(20,0,0,0)); 54 all.add(fixedClickCb,GBC.eop().insets(20,0,0,0)); 55 all.add(fixedSpaceCb,GBC.eop().insets(20,0,0,0)); 59 56 60 57 text1.setValue(settings.epsilonMult); 61 58 text2.setValue(settings.startingEps); 62 59 text3.setValue(settings.maxPointsPerKm); 63 60 snapCb.setSelected(settings.snapNodes); 61 fixedClickCb.setSelected(settings.fixedClick); 62 fixedSpaceCb.setSelected(settings.fixedSpacebar); 63 combo1.setSelectedIndex(settings.simplifyMode); 64 64 65 ExtendedDialog dialog = new ExtendedDialog(Main.parent, 65 66 tr("FastDraw settings"), … … 80 81 settings.startingEps=NumberFormat.getInstance().parse(text2.getText()).doubleValue(); 81 82 settings.maxPointsPerKm=NumberFormat.getInstance().parse(text3.getText()).doubleValue(); 83 settings.snapNodes=snapCb.isSelected(); 84 settings.fixedClick=fixedClickCb.isSelected(); 85 settings.fixedSpacebar=fixedSpaceCb.isSelected(); 86 settings.simplifyMode=combo1.getSelectedIndex(); 82 87 settings.savePrefs(); 83 88 } catch (ParseException e) { -
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawingMode.java
r26460 r26468 87 87 88 88 private KeyEvent releaseEvent; 89 private boolean lineWasSaved; 90 private boolean deltaChanged; 89 91 90 92 FastDrawingMode(MapFrame mapFrame) { … … 113 115 if (!isEnabled()) return; 114 116 super.enterMode(); 117 lineWasSaved=false; 115 118 settings=new FDSettings(); 116 119 settings.loadPrefs(); … … 157 160 public void exitMode() { 158 161 super.exitMode(); 162 if (line.wasSimplified() && !lineWasSaved) saveAsWay(false); 159 163 160 164 Main.map.mapView.removeMouseListener(this); … … 242 246 } 243 247 } 244 if (settings.drawLastSegment && !drawing && !shift && !line.wasSimplified()) {248 if (settings.drawLastSegment && !drawing && !shift && nearestIdx<0 && !line.wasSimplified()) { 245 249 // draw line to current point 246 250 g.setColor(lineColor); … … 248 252 Point mp=Main.map.mapView.getMousePosition(); 249 253 if (lp!=null && mp!=null) g.drawLine(lp.x,lp.y,mp.x,mp.y); 254 } 255 if (deltaChanged) { 256 g.setColor(lineColor); 257 Point lp=line.getLastPoint(); 258 int r=(int) settings.minPixelsBetweenPoints; 259 if (lp!=null) g.drawOval(lp.x-r,lp.y-r,2*r,2*r); 250 260 } 251 261 } … … 315 325 return; 316 326 } 317 startDrawing(e.getPoint() );318 } 319 320 private void startDrawing(Point point ) {327 startDrawing(e.getPoint(),settings.fixedClick); 328 } 329 330 private void startDrawing(Point point, boolean fixFlag) { 321 331 //if (line.isClosed()) { setStatusLine(tr(SIMPLIFYMODE_MESSAGE));return; } 322 332 drawing = true; 333 if (line.wasSimplified()) { 334 // new line started after simplification 335 // we need to save old line 336 saveAsWay(false); 337 newDrawing(); 338 //line.clearSimplifiedVersion(); 339 } 340 323 341 324 342 LatLon p = mv.getLatLon(point.x, point.y); 325 Node nd1 = getNearestNode(point, settings.maxDist); 326 if (nd1!=null) { 327 // found node, make it fixed point of the line 328 //System.out.println("node "+nd1); 329 p=nd1.getCoor(); 330 line.fixPoint(p); 343 if (settings.snapNodes) { // find existing node near point and use it 344 Node nd1 = getNearestNode(point, settings.maxDist); 345 if (nd1!=null) { 346 // found node, make it fixed point of the line 347 //System.out.println("node "+nd1); 348 p=nd1.getCoor(); 349 line.fixPoint(p); 350 } 331 351 } 332 352 333 353 line.addLast(p); 334 if (ctrl) line.fixPoint(p); 335 line.clearSimplifiedVersion(); 336 354 if (ctrl || fixFlag) line.fixPoint(p); 355 337 356 setStatusLine(tr("Please move the mouse to draw new way")); 338 357 repaint(); … … 363 382 public void mouseMoved(MouseEvent e) { 364 383 if (!isEnabled()) return; 384 deltaChanged=false; 365 385 Node nd1 = getNearestNode(e.getPoint(), settings.maxDist); 366 386 boolean nearpoint2=nd1!=null; … … 422 442 case KeyEvent.VK_BACK_SPACE: 423 443 if (line.wasSimplified()) { 444 // return to line editing 424 445 line.clearSimplifiedVersion(); 425 446 repaint(); … … 429 450 break; 430 451 case KeyEvent.VK_ENTER: 452 e.consume(); 431 453 // first Enter = simplify, second = save the way 432 454 if (!line.wasSimplified()) { 433 455 //line.simplify(eps); 434 eps = line.autoSimplify(settings.startingEps, settings.epsilonMult, 456 switch(settings.simplifyMode) { 457 case 0: //case 1: 458 eps = line.autoSimplify(settings.startingEps, settings.epsilonMult, 435 459 settings.pkmBlockSize, settings.maxPointsPerKm); 436 repaint(); 437 showSimplifyHint(); 438 } else saveAsWay(); 460 break; 461 case 1: //case 2: case 3: 462 line.simplify(eps); 463 break; 464 } 465 if (settings.simplifyMode==2) { 466 // autosave 467 saveAsWay(true); 468 } else { 469 repaint(); 470 showSimplifyHint(); 471 } 472 } else {saveAsWay(true);} 439 473 break; 440 474 case KeyEvent.VK_DOWN: … … 461 495 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 462 496 new FastDrawConfigDialog(settings); 497 if (line.wasSimplified()) { 463 498 eps = line.autoSimplify(settings.startingEps, settings.epsilonMult, settings.pkmBlockSize,settings.maxPointsPerKm); 499 showSimplifyHint(); 500 } 464 501 //System.out.println("final eps="+eps); 465 502 Toolkit.getDefaultToolkit().addAWTEventListener(this, … … 471 508 if (!drawing) { 472 509 Point p = Main.map.mapView.getMousePosition(); 473 if (p!=null) startDrawing(p );510 if (p!=null) startDrawing(p,settings.fixedSpacebar); 474 511 } 475 512 break; … … 504 541 line.clear(); 505 542 } 506 private void saveAsWay( ) {543 private void saveAsWay(boolean autoExit) { 507 544 List<LatLon> pts=line.getPoints(); 508 545 int n = pts.size(); … … 561 598 Command c = new SequenceCommand(tr("Draw the way by mouse"), cmds); 562 599 Main.main.undoRedo.add(c); 600 lineWasSaved = true; 563 601 newDrawing(); // stop drawing 564 // Select this way and switch drawing mode off 565 exitMode(); 566 getCurrentDataSet().setSelected(w); 567 Main.map.selectSelectTool(false); 568 } 602 if (autoExit) { 603 // Select this way and switch drawing mode off 604 exitMode(); 605 getCurrentDataSet().setSelected(w); 606 Main.map.selectSelectTool(false); 607 } 608 } 609 610 569 611 570 612 private void repaint() { … … 588 630 void changeDelta(double k) { 589 631 settings.minPixelsBetweenPoints*=k; 632 deltaChanged=true; 590 633 setStatusLine(tr("min distance={0} pixes",(int)settings.minPixelsBetweenPoints)); 591 634 repaint(); 592 635 } 593 636
Note:
See TracChangeset
for help on using the changeset viewer.