Changeset 721 in josm for trunk/src/org/openstreetmap/josm
- Timestamp:
- 2008-07-14T22:21:09+02:00 (17 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r650 r721 77 77 protected static final double PHI = Math.toRadians(15); 78 78 private boolean computeCacheInSync; 79 private int computeCacheMaxLineLingthUsed; 79 private int computeCacheMaxLineLengthUsed; 80 private Color computeCacheColorUsed; 81 private boolean computeCacheColored; 80 82 81 83 public GpxLayer(GpxData d) { … … 352 354 353 355 @Override public void paint(Graphics g, MapView mv) { 356 357 /**************************************************************** 358 ********** STEP 1 - GET CONFIG VALUES ************************** 359 ****************************************************************/ 360 Long startTime = System.currentTimeMillis(); 354 361 String gpsCol = Main.pref.get("color.gps point"); 355 362 String gpsColSpecial = Main.pref.get("color.layer "+name); … … 362 369 neutralColor = Color.GRAY; 363 370 } 364 g.setColor(neutralColor);365 366 371 boolean forceLines = Main.pref.getBoolean("draw.rawgps.lines.force"); // also draw lines between points belonging to different segments 367 372 boolean direction = Main.pref.getBoolean("draw.rawgps.direction"); // draw direction arrows on the lines 368 int maxLineLength = Integer.parseInt(Main.pref.get("draw.rawgps.max-line-length", "-1")); // don't draw lines if longer than x meters 373 int maxLineLength = -1; 374 try { 375 maxLineLength = Integer.parseInt(Main.pref.get("draw.rawgps.max-line-length", "-1")); // don't draw lines if longer than x meters 376 } catch (java.lang.NumberFormatException e) { 377 Main.pref.put("draw.rawgps.max-line-length", "-1"); 378 } 369 379 boolean lines = Main.pref.getBoolean("draw.rawgps.lines"); // draw line between points, global setting 370 380 String linesKey = "draw.rawgps.lines.layer "+name; … … 374 384 boolean colored = Main.pref.getBoolean("draw.rawgps.colors"); // color the lines 375 385 boolean alternatedirection = Main.pref.getBoolean("draw.rawgps.alternatedirection"); // paint direction arrow with alternate math. may be faster 376 boolean trianglelines = Main.pref.getBoolean("draw.rawgps.trianglelines"); // paint lines as 2 lines 377 378 if (computeCacheInSync && computeCacheMaxLineLingthUsed != maxLineLength) { 386 387 /**************************************************************** 388 ********** STEP 2a - CHECK CACHE VALIDITY ********************** 389 ****************************************************************/ 390 if (computeCacheInSync && ((computeCacheMaxLineLengthUsed != maxLineLength) || 391 (!neutralColor.equals(computeCacheColorUsed)) || 392 (computeCacheColored != colored))) { 393 System.out.println("(re-)computing gpx line styles, reason: CCIS=" + computeCacheInSync + " CCMLLU=" + (computeCacheMaxLineLengthUsed != maxLineLength) + " CCCU=" + (!neutralColor.equals(computeCacheColorUsed)) + " CCC=" + (computeCacheColored != colored)); 394 computeCacheMaxLineLengthUsed = maxLineLength; 379 395 computeCacheInSync = false; 380 } 381 382 if (!computeCacheInSync && lines) { // don't compute if the cache is good or if there are no lines to draw at all 383 //System.out.println("(re-)computing gpx line styles, reason: CCIS=" + computeCacheInSync + " L=" + lines); 396 computeCacheColorUsed = neutralColor; 397 computeCacheColored = colored; 398 } 399 400 /**************************************************************** 401 ********** STEP 2b - RE-COMPUTE CACHE DATA ********************* 402 ****************************************************************/ 403 if (!computeCacheInSync) { // don't compute if the cache is good 384 404 WayPoint oldWp = null; 385 405 for (GpxTrack trk : data.tracks) { … … 397 417 double vel = dist/dtime; 398 418 399 if (dtime <= 0 || vel < 0 || vel > 36) { // attn: bad case first 419 if (!colored) { 420 trkPnt.speedLineColor = neutralColor; 421 } else if (dtime <= 0 || vel < 0 || vel > 36) { // attn: bad case first 400 422 trkPnt.speedLineColor = colors[255]; 401 423 } else { … … 417 439 } 418 440 computeCacheInSync = true; 419 computeCacheMaxLineLingthUsed = maxLineLength;420 441 } 421 442 443 /**************************************************************** 444 ********** STEP 3a - DRAW LINES ******************************** 445 ****************************************************************/ 446 if (lines) { 422 447 Point old = null; 423 448 for (GpxTrack trk : data.tracks) { … … 427 452 continue; 428 453 Point screen = mv.getPoint(trkPnt.eastNorth); 429 if (lines && trkPnt.drawLine) { 430 if ((old.x != screen.x) || (old.y != screen.y)) { // skip points that are on the same screenposition 431 if (colored) { 454 if (trkPnt.drawLine) { 455 if (old != null && ((old.x != screen.x) || (old.y != screen.y))) { // skip points that are on the same screenposition 432 456 g.setColor(trkPnt.speedLineColor); 433 }434 if (trianglelines) { // fast435 g.drawLine(screen.x, screen.y, old.x + dir[trkPnt.dir][0], old.y + dir[trkPnt.dir][1]);436 g.drawLine(screen.x, screen.y, old.x + dir[trkPnt.dir][2], old.y + dir[trkPnt.dir][3]);437 } else { // slow438 457 g.drawLine(old.x, old.y, screen.x, screen.y); 439 458 } 440 if (direction) { 441 if (alternatedirection) { // a little bit faster 442 g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][0], screen.y + dir[trkPnt.dir][1]); 443 g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][2], screen.y + dir[trkPnt.dir][3]); 444 } else { // a tiny bit slower, may not make a difference at all 459 } 460 old = screen; 461 } // end for trkpnt 462 } // end for segment 463 } // end for trk 464 } // end if lines 465 466 /**************************************************************** 467 ********** STEP 3b - DRAW NICE ARROWS ************************** 468 ****************************************************************/ 469 if (lines && direction && !alternatedirection) { 470 Point old = null; 471 for (GpxTrack trk : data.tracks) { 472 for (Collection<WayPoint> segment : trk.trackSegs) { 473 for (WayPoint trkPnt : segment) { 474 if (Double.isNaN(trkPnt.latlon.lat()) || Double.isNaN(trkPnt.latlon.lon())) 475 continue; 476 if (trkPnt.drawLine) { 477 Point screen = mv.getPoint(trkPnt.eastNorth); 478 if (old != null && ((old.x != screen.x) || (old.y != screen.y))) { // skip points that are on the same screenposition 479 g.setColor(trkPnt.speedLineColor); 445 480 double t = Math.atan2(screen.y-old.y, screen.x-old.x) + Math.PI; 446 481 g.drawLine(screen.x,screen.y, (int)(screen.x + 10*Math.cos(t-PHI)), (int)(screen.y + 10*Math.sin(t-PHI))); 447 482 g.drawLine(screen.x,screen.y, (int)(screen.x + 10*Math.cos(t+PHI)), (int)(screen.y + 10*Math.sin(t+PHI))); 448 483 } 484 old = screen; 449 485 } 486 } // end for trkpnt 487 } // end for segment 488 } // end for trk 489 } // end if lines 490 491 /**************************************************************** 492 ********** STEP 3c - DRAW FAST ARROWS ************************** 493 ****************************************************************/ 494 if (lines && direction && alternatedirection) { 495 Point old = null; 496 for (GpxTrack trk : data.tracks) { 497 for (Collection<WayPoint> segment : trk.trackSegs) { 498 for (WayPoint trkPnt : segment) { 499 if (Double.isNaN(trkPnt.latlon.lat()) || Double.isNaN(trkPnt.latlon.lon())) 500 continue; 501 if (trkPnt.drawLine) { 502 Point screen = mv.getPoint(trkPnt.eastNorth); 503 if (old != null && ((old.x != screen.x) || (old.y != screen.y))) { // skip points that are on the same screenposition 504 g.setColor(trkPnt.speedLineColor); 505 g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][0], screen.y + dir[trkPnt.dir][1]); 506 g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][2], screen.y + dir[trkPnt.dir][3]); 450 507 } 451 }else{ 452 if (colored) { // reset color for non-line drawing if lines are variable colored 453 g.setColor(neutralColor); 508 old = screen; 454 509 } 510 } // end for trkpnt 511 } // end for segment 512 } // end for trk 513 } // end if lines 514 515 /**************************************************************** 516 ********** STEP 3d - DRAW LARGE POINTS ************************* 517 ****************************************************************/ 455 518 if (large) { 519 g.setColor(neutralColor); 520 for (GpxTrack trk : data.tracks) { 521 for (Collection<WayPoint> segment : trk.trackSegs) { 522 for (WayPoint trkPnt : segment) { 523 if (Double.isNaN(trkPnt.latlon.lat()) || Double.isNaN(trkPnt.latlon.lon())) 524 continue; 525 Point screen = mv.getPoint(trkPnt.eastNorth); 456 526 g.fillRect(screen.x-1, screen.y-1, 3, 3); 457 } else { 527 } // end for trkpnt 528 } // end for segment 529 } // end for trk 530 } // end if large 531 532 /**************************************************************** 533 ********** STEP 3e - DRAW SMALL POINTS FOR LINES *************** 534 ****************************************************************/ 535 if (!large && lines){ 536 g.setColor(neutralColor); 537 for (GpxTrack trk : data.tracks) { 538 for (Collection<WayPoint> segment : trk.trackSegs) { 539 for (WayPoint trkPnt : segment) { 540 if (Double.isNaN(trkPnt.latlon.lat()) || Double.isNaN(trkPnt.latlon.lon())) 541 continue; 542 if (!trkPnt.drawLine) { 543 Point screen = mv.getPoint(trkPnt.eastNorth); 458 544 g.drawRect(screen.x, screen.y, 0, 0); 459 545 } 460 } 461 old = screen; 462 } 463 } 464 } 465 } 546 } // end for trkpnt 547 } // end for segment 548 } // end for trk 549 } // end if large 550 551 /**************************************************************** 552 ********** STEP 3f - DRAW SMALL POINTS INSTEAD OF LINES ******** 553 ****************************************************************/ 554 if (!large && !lines){ 555 g.setColor(neutralColor); 556 for (GpxTrack trk : data.tracks) { 557 for (Collection<WayPoint> segment : trk.trackSegs) { 558 for (WayPoint trkPnt : segment) { 559 if (Double.isNaN(trkPnt.latlon.lat()) || Double.isNaN(trkPnt.latlon.lon())) 560 continue; 561 Point screen = mv.getPoint(trkPnt.eastNorth); 562 g.drawRect(screen.x, screen.y, 0, 0); 563 } // end for trkpnt 564 } // end for segment 565 } // end for trk 566 } // end if large 567 568 Long duration = System.currentTimeMillis() - startTime; 569 //System.out.println(duration); 570 571 } // end paint 466 572 467 573 @Override public void visitBoundingBox(BoundingXYVisitor v) { -
trunk/src/org/openstreetmap/josm/gui/preferences/DrawingPreference.java
r627 r721 8 8 9 9 import javax.swing.JCheckBox; 10 import javax.swing.JLabel; 11 import javax.swing.JTextField; 10 12 11 13 import org.openstreetmap.josm.Main; … … 15 17 16 18 private JCheckBox drawRawGpsLines = new JCheckBox(tr("Draw lines between raw gps points.")); 19 private JTextField drawRawGpsMaxLineLength = new JTextField(8); 17 20 private JCheckBox forceRawGpsLines = new JCheckBox(tr("Force lines if no segments imported.")); 18 21 private JCheckBox largeGpsPoints = new JCheckBox(tr("Draw large GPS points.")); … … 20 23 private JCheckBox directionHint = new JCheckBox(tr("Draw Direction Arrows")); 21 24 private JCheckBox drawGpsArrows = new JCheckBox(tr("Draw Direction Arrows")); 25 private JCheckBox drawGpsArrowsFast = new JCheckBox(tr("Fast drawing (looks uglier)")); 22 26 private JCheckBox interestingDirections = new JCheckBox(tr("Only interesting direction hints (e.g. with oneway tag).")); 23 27 private JCheckBox segmentOrderNumber = new JCheckBox(tr("Draw segment order numbers")); … … 29 33 drawRawGpsLines.addActionListener(new ActionListener(){ 30 34 public void actionPerformed(ActionEvent e) { 31 if (!drawRawGpsLines.isSelected()){32 forceRawGpsLines.setSelected(false);33 drawGpsArrows.setSelected(false);34 }35 35 forceRawGpsLines.setEnabled(drawRawGpsLines.isSelected()); 36 drawRawGpsMaxLineLength.setEnabled(drawRawGpsLines.isSelected()); 36 37 drawGpsArrows.setEnabled(drawRawGpsLines.isSelected()); 38 drawGpsArrowsFast.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled()); 37 39 colorTracks.setEnabled(drawRawGpsLines.isSelected()); 38 40 } … … 41 43 drawRawGpsLines.setToolTipText(tr("If your gps device draw too few lines, select this to draw lines along your way.")); 42 44 gui.display.add(drawRawGpsLines, GBC.eol().insets(20,0,0,0)); 45 46 // drawRawGpsMaxLineLength 47 drawRawGpsMaxLineLength.setText(Main.pref.get("draw.rawgps.max-line-length", "-1")); 48 drawRawGpsMaxLineLength.setToolTipText(tr("Maximum length (in meters) to draw lines. Set to '-1' to draw all lines.")); 49 drawRawGpsMaxLineLength.setEnabled(drawRawGpsLines.isSelected()); 50 gui.display.add(new JLabel(tr("Maximum length (meters)")), GBC.std().insets(40,0,0,0)); 51 gui.display.add(drawRawGpsMaxLineLength, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5)); 43 52 44 53 // forceRawGpsLines … … 49 58 50 59 // drawGpsArrows 60 drawGpsArrows.addActionListener(new ActionListener(){ 61 public void actionPerformed(ActionEvent e) { 62 drawGpsArrowsFast.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled()); 63 } 64 }); 51 65 drawGpsArrows.setToolTipText(tr("Draw direction arrows for lines, connecting GPS points.")); 52 66 drawGpsArrows.setSelected(Main.pref.getBoolean("draw.rawgps.direction")); 53 67 drawGpsArrows.setEnabled(drawRawGpsLines.isSelected()); 54 68 gui.display.add(drawGpsArrows, GBC.eop().insets(40,0,0,0)); 69 70 // drawGpsArrowsFast 71 drawGpsArrowsFast.setToolTipText(tr("Draw the direction arrows using table lookups instead of complex math.")); 72 drawGpsArrowsFast.setSelected(Main.pref.getBoolean("draw.rawgps.alternatedirection")); 73 drawGpsArrowsFast.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled()); 74 gui.display.add(drawGpsArrowsFast, GBC.eop().insets(60,0,0,0)); 55 75 56 76 // colorTracks … … 76 96 } 77 97 }); 78 directionHint.setToolTipText(tr("Draw direction hints for segments.")); 98 directionHint.setToolTipText(tr("Draw direction hints for way segments.")); 79 99 directionHint.setSelected(Main.pref.getBoolean("draw.segment.direction")); 80 100 gui.display.add(directionHint, GBC.eop().insets(20,0,0,0)); … … 104 124 public void ok() { 105 125 Main.pref.put("draw.rawgps.lines", drawRawGpsLines.isSelected()); 126 Main.pref.put("draw.rawgps.max-line-length", drawRawGpsMaxLineLength.getText()); 106 127 Main.pref.put("draw.rawgps.lines.force", forceRawGpsLines.isSelected()); 107 128 Main.pref.put("draw.rawgps.direction", drawGpsArrows.isSelected()); 129 Main.pref.put("draw.rawgps.alternatedirection", drawGpsArrowsFast.isSelected()); 108 130 Main.pref.put("draw.rawgps.colors", colorTracks.isSelected()); 109 131 Main.pref.put("draw.rawgps.large", largeGpsPoints.isSelected());
Note:
See TracChangeset
for help on using the changeset viewer.