Changeset 23764 in osm for applications/editors
- Timestamp:
- 2010-10-23T16:26:48+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ElevationProfileBase.java
r23754 r23764 63 63 private int gain; 64 64 private int lastEle; 65 private WayPoint lastWayPoint;66 67 65 private static boolean ignoreZeroHeight = true; 68 66 … … 495 493 lastEle = ele; 496 494 } 497 498 /*499 if (lastWayPoint != null) {500 double d = wp.getCoor().greatCircleDistance(lastWayPoint.getCoor());501 dist += d;502 }*/503 lastWayPoint = wp;504 495 } 505 496 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ElevationWayPointKind.java
r23756 r23764 28 28 ElevationGain, // Elevation gain 29 29 ElevationLoss, // Elevation loss 30 ElevationLevel, // Elevation level (e. g. crossed 300m) 30 ElevationLevelGain, // Elevation level gain (e. g. crossed 300m from lower elevation) 31 ElevationLevelLoss, // Elevation level (e. g. crossed 300m from higher elevation) 31 32 FullHour // Full Hour 32 33 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/DefaultElevationProfileRenderer.java
r23757 r23764 54 54 private static final int REGULAR_WPT_RADIUS = BASIC_WPT_RADIUS * 4; 55 55 private static final int BIG_WPT_RADIUS = BASIC_WPT_RADIUS * 10; 56 56 57 57 // predefined colors 58 58 private static final Color HIGH_COLOR = ElevationColors.EPMidBlue; … … 65 65 // private static final double RAD_270 = Math.PI * 1.5; 66 66 private static final double RAD_90 = Math.PI * 0.5; 67 67 68 68 private List<Rectangle> forbiddenRects = new ArrayList<Rectangle>(); 69 69 … … 91 91 switch (kind) { 92 92 case Plain: 93 case ElevationLevel: 93 case ElevationLevelLoss: 94 case ElevationLevelGain: 94 95 if (z > profile.getAverageHeight()) { 95 96 return HIGH_COLOR; … … 109 110 case MinElevation: 110 111 return LOW_COLOR; 111 112 112 113 case StartPoint: 113 114 return START_COLOR; … … 179 180 180 181 Point pnt = mv.getPoint(wpt.getEastNorth()); 181 182 int ele = ((int) Math.rint(WayPointHelper.getElevation(wpt) / 100.0)) * 100; 183 182 184 int rad = REGULAR_WPT_RADIUS; 183 185 g.setColor(c); 184 // g.drawOval(pnt.x - rad, pnt.y - rad, r2, r2);186 // g.drawOval(pnt.x - rad, pnt.y - rad, r2, r2); 185 187 drawSphere(g, Color.WHITE, c, pnt.x, pnt.y, rad); 188 189 if (kind == ElevationWayPointKind.FullHour) { 190 int hour = WayPointHelper.getHourOfWayPoint(wpt); 191 drawLabel(String.format("%02d:00", hour), pnt.x, pnt.y 192 + g.getFontMetrics().getHeight(), g); 193 } 194 195 if (kind == ElevationWayPointKind.ElevationLevelGain) { 196 drawLabelWithTriangle(String.format("%dm", ele), pnt.x, pnt.y 197 + g.getFontMetrics().getHeight(), g, c, 8, 198 getColorForWaypoint(profile, wpt, ElevationWayPointKind.ElevationGain), 199 TriangleDir.Up); 200 } 186 201 187 if (kind == ElevationWayPointKind.FullHour) { 188 int hour = WayPointHelper.getHourOfWayPoint(wpt); 189 drawLabel(String.format("%02d:00", hour), pnt.x, pnt.y + g.getFontMetrics().getHeight(), g); 190 } 191 192 if (kind == ElevationWayPointKind.ElevationLevel) { 193 int ele = ((int)Math.rint(WayPointHelper.getElevation(wpt) / 100.0)) * 100; 194 drawLabel(String.format("%dm", ele), pnt.x, pnt.y + g.getFontMetrics().getHeight(), g, c); 195 } 196 202 if (kind == ElevationWayPointKind.ElevationLevelLoss) { 203 drawLabelWithTriangle(String.format("%dm", ele), pnt.x, pnt.y 204 + g.getFontMetrics().getHeight(), g, c, 8, 205 getColorForWaypoint(profile, wpt, ElevationWayPointKind.ElevationLoss), 206 TriangleDir.Down); 207 } 208 197 209 if (kind == ElevationWayPointKind.Highlighted) { 198 210 int eleH = (int) WayPointHelper.getElevation(wpt); 199 int hour = WayPointHelper.getHourOfWayPoint(wpt); 211 int hour = WayPointHelper.getHourOfWayPoint(wpt); 200 212 int min = WayPointHelper.getMinuteOfWayPoint(wpt); 201 213 drawSphere(g, Color.WHITE, c, pnt.x, pnt.y, BIG_WPT_RADIUS); 202 drawLabel(String.format("%02d:%02d", hour, min), pnt.x, pnt.y - g.getFontMetrics().getHeight() - 5, g); 203 drawLabel(String.format("%dm", eleH), pnt.x, pnt.y + g.getFontMetrics().getHeight() + 5, g); 214 drawLabel(String.format("%02d:%02d", hour, min), pnt.x, pnt.y 215 - g.getFontMetrics().getHeight() - 5, g); 216 drawLabel(String.format("%dm", eleH), pnt.x, pnt.y 217 + g.getFontMetrics().getHeight() + 5, g); 204 218 } 205 219 } … … 245 259 } 246 260 247 paintRegularTriangle(g, c, td, pnt.x, pnt.y,261 drawRegularTriangle(g, c, td, pnt.x, pnt.y, 248 262 DefaultElevationProfileRenderer.TRIANGLE_BASESIZE); 249 263 250 drawLabel(String.format("%dm", eleH), pnt.x, pnt.y + g.getFontMetrics().getHeight(), g, c); 251 } 252 253 /** 254 * Draw a regular triangle. 264 drawLabel(String.format("%dm", eleH), pnt.x, pnt.y 265 + g.getFontMetrics().getHeight(), g, c); 266 } 267 268 /** 269 * Draws a regular triangle. 255 270 * 256 271 * @param g … … 267 282 * The side length in pixel of the triangle. 268 283 */ 269 private void paintRegularTriangle(Graphics g, Color c, TriangleDir dir,284 private void drawRegularTriangle(Graphics g, Color c, TriangleDir dir, 270 285 int x, int y, int baseLength) { 271 286 if (baseLength < 2) … … 387 402 /** 388 403 * Draws a label. 389 * @param s The text to draw. 390 * @param x The x coordinate of the label. 391 * @param y The y coordinate of the label. 392 * @param g The graphics context. 404 * 405 * @param s 406 * The text to draw. 407 * @param x 408 * The x coordinate of the label. 409 * @param y 410 * The y coordinate of the label. 411 * @param g 412 * The graphics context. 393 413 */ 394 414 private void drawLabel(String s, int x, int y, Graphics g) { 395 drawLabel(s, x, y, g, Color.BLACK); 396 } 415 drawLabel(s, x, y, g, Color.GRAY); 416 } 417 397 418 /** 398 419 * Draws a label. 399 * @param s The text to draw. 400 * @param x The x coordinate of the label. 401 * @param y The y coordinate of the label. 402 * @param g The graphics context. 403 * @param secondGradColor The second color of the gradient. 404 */ 405 private void drawLabel(String s, int x, int y, Graphics g, Color secondGradColor) { 420 * 421 * @param s 422 * The text to draw. 423 * @param x 424 * The x coordinate of the label. 425 * @param y 426 * The y coordinate of the label. 427 * @param g 428 * The graphics context. 429 * @param secondGradColor 430 * The second color of the gradient. 431 */ 432 private void drawLabel(String s, int x, int y, Graphics g, 433 Color secondGradColor) { 406 434 Graphics2D g2d = (Graphics2D) g; 407 435 408 436 int width = g.getFontMetrics(g.getFont()).stringWidth(s) + 10; 437 int height = g.getFont().getSize() + g.getFontMetrics().getLeading() 438 + 5; 439 440 Rectangle r = new Rectangle(x - (width / 2), y - (height / 2), width, 441 height); 442 443 if (isForbiddenArea(r)) { 444 return; // no space left, skip this label 445 } 446 447 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 448 RenderingHints.VALUE_ANTIALIAS_ON); 449 GradientPaint gradient = new GradientPaint(x, y, Color.WHITE, x, y 450 + (height / 2), secondGradColor, false); 451 g2d.setPaint(gradient); 452 453 g2d.fillRoundRect(r.x, r.y, r.width, r.height, ROUND_RECT_RADIUS, 454 ROUND_RECT_RADIUS); 455 456 g2d.setColor(Color.BLACK); 457 458 g2d.drawRoundRect(r.x, r.y, r.width, r.height, ROUND_RECT_RADIUS, 459 ROUND_RECT_RADIUS); 460 g2d.drawString(s, x - (width / 2) + 5, y + (height / 2) - 3); 461 462 forbiddenRects.add(r); 463 } 464 465 /** 466 * Draws a label with an additional triangle on the left side. 467 * 468 * @param s 469 * The text to draw. 470 * @param x 471 * The x coordinate of the label. 472 * @param y 473 * The y coordinate of the label. 474 * @param g 475 * The graphics context. 476 * @param secondGradColor 477 * The second color of the gradient. 478 * @param baseLength 479 * The base length of the triangle in pixels. 480 * @param triangleColor 481 * The color of the triangle. 482 * @param triangleDir 483 * The direction of the triangle. 484 */ 485 private void drawLabelWithTriangle(String s, int x, int y, Graphics g, 486 Color secondGradColor, int baseLength, Color triangleColor, 487 TriangleDir triangleDir) { 488 Graphics2D g2d = (Graphics2D) g; 489 490 int width = g.getFontMetrics(g.getFont()).stringWidth(s) + 10 + baseLength + 5; 409 491 int height = g.getFont().getSize() + g.getFontMetrics().getLeading() + 5; 410 492 411 493 Rectangle r = new Rectangle(x - (width / 2), y - (height / 2), width, height); 412 413 if (isForbiddenArea(r)) { 494 495 if (isForbiddenArea(r)) { 414 496 return; // no space left, skip this label 415 497 } 416 498 417 499 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 418 RenderingHints.VALUE_ANTIALIAS_ON); 500 RenderingHints.VALUE_ANTIALIAS_ON); 419 501 GradientPaint gradient = new GradientPaint(x, y, Color.WHITE, x, y 420 + (height /2), secondGradColor, false);421 g2d.setPaint(gradient); 422 423 424 g2d.fillRoundRect(r.x, r.y, r.width, r.height, ROUND_RECT_RADIUS,ROUND_RECT_RADIUS);425 502 + (height / 2), secondGradColor, false); 503 g2d.setPaint(gradient); 504 505 g2d.fillRoundRect(r.x, r.y, r.width, r.height, ROUND_RECT_RADIUS, 506 ROUND_RECT_RADIUS); 507 426 508 g2d.setColor(Color.BLACK); 427 428 g2d.drawRoundRect(r.x, r.y, r.width, r.height, ROUND_RECT_RADIUS, ROUND_RECT_RADIUS); 429 g2d.drawString(s, x - (width / 2) + 5, y + (height / 2) - 3); 430 509 510 g2d.drawRoundRect(r.x, r.y, r.width, r.height, ROUND_RECT_RADIUS, 511 ROUND_RECT_RADIUS); 512 g2d.drawString(s, x - (width / 2) + 8 + baseLength, y + (height / 2) - 3); 513 drawRegularTriangle(g2d, triangleColor, triangleDir, r.x + baseLength, 514 r.y + baseLength, baseLength); 515 431 516 forbiddenRects.add(r); 432 517 } 433 518 434 519 /** 435 520 * Checks, if the rectangle has been 'reserved' by a previous draw action. 436 * @param r The area to check for. 521 * 522 * @param r 523 * The area to check for. 437 524 * @return true; if area is already occupied by another rectangle. 438 525 */ 439 526 private boolean isForbiddenArea(Rectangle r) { 440 527 441 528 for (Rectangle rTest : forbiddenRects) { 442 if (r.intersects(rTest)) return true; 529 if (r.intersects(rTest)) 530 return true; 443 531 } 444 532 return false; … … 452 540 @Override 453 541 public void finishRendering() { 454 // nothing to do currently 542 // nothing to do currently 455 543 } 456 544 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileLayer.java
r23759 r23764 170 170 int ele1 = (int)(ele / 100.0); 171 171 int ele2 = (int)(lastEle / 100.0); 172 if (ele1 != ele2) { // hour changed? 173 renderer.renderWayPoint(g, profile, mv, wpt, 174 ElevationWayPointKind.ElevationLevel); 175 } else { // check for elevation gain 176 if (ele > lastEle) { 172 173 // Check, if we passed an elevation level 174 if (ele1 != ele2 && Math.abs(ele1 - ele2) == 1) { 175 if (ele1 > ele2) { // we went down? 176 renderer.renderWayPoint(g, profile, mv, wpt, 177 ElevationWayPointKind.ElevationLevelGain); 178 } else { 179 renderer.renderWayPoint(g, profile, mv, wpt, 180 ElevationWayPointKind.ElevationLevelLoss); 181 } 182 } else { // check for elevation gain or loss 183 if (ele > lastEle) { // we went down? 177 184 renderer.renderWayPoint(g, profile, mv, wpt, 178 185 ElevationWayPointKind.ElevationGain); -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfilePanel.java
r23752 r23764 5 5 import java.awt.Color; 6 6 import java.awt.Dimension; 7 import java.awt.Event;8 7 import java.awt.Font; 9 8 import java.awt.FontMetrics; … … 13 12 import java.awt.event.ComponentListener; 14 13 import java.awt.event.MouseEvent; 15 import java.awt.event.MouseListener;16 14 import java.awt.event.MouseMotionListener; 17 15 import java.text.Format;
Note:
See TracChangeset
for help on using the changeset viewer.