- Timestamp:
- 2010-03-13T10:23:39+01:00 (15 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
r3119 r3127 87 87 private final List<GpxTrack> lastTracks = new ArrayList<GpxTrack>(); // List of tracks at last paint 88 88 private int lastUpdateCount; 89 private PaintSettings lastPaintSettings; 89 90 90 91 private static class Markers { … … 463 464 @Override 464 465 public boolean isChanged() { 465 if (data.tracks.equals(lastTracks) )466 if (data.tracks.equals(lastTracks) && new PaintSettings(isLocalFile).equals(lastPaintSettings)) 466 467 return sumUpdateCount() != lastUpdateCount; 467 468 else … … 496 497 } 497 498 499 private class PaintSettings { 500 final Color neutralColor; 501 final boolean forceLines; 502 final boolean direction; 503 final int lineWidth; 504 final int maxLineLength; 505 final boolean lines; 506 final boolean large; 507 final boolean hdopcircle; 508 final colorModes colored; 509 final boolean alternatedirection; 510 final int delta; 511 final int colorTracksTune; 512 513 public PaintSettings(boolean isLocalFile) { 514 neutralColor = getColor(getName()); 515 // also draw lines between points belonging to different segments 516 forceLines = Main.pref.getBoolean("draw.rawgps.lines.force"); 517 // draw direction arrows on the lines 518 direction = Main.pref.getBoolean("draw.rawgps.direction"); 519 // don't draw lines if longer than x meters 520 lineWidth = Main.pref.getInteger("draw.rawgps.linewidth",0); 521 522 if (isLocalFile) { 523 maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length.local", -1); 524 } else { 525 maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length", 200); 526 } 527 528 // draw line between points, global setting 529 boolean lines = (Main.pref.getBoolean("draw.rawgps.lines", true) || (Main.pref 530 .getBoolean("draw.rawgps.lines.localfiles") && isLocalFile)); 531 String linesKey = "draw.rawgps.lines.layer " + getName(); 532 // draw lines, per-layer setting 533 if (Main.pref.hasKey(linesKey)) { 534 lines = Main.pref.getBoolean(linesKey); 535 } 536 this.lines = lines; 537 538 // paint large dots for points 539 large = Main.pref.getBoolean("draw.rawgps.large"); 540 hdopcircle = Main.pref.getBoolean("draw.rawgps.hdopcircle", true); 541 // color the lines 542 int colorIndex = Main.pref.getInteger("draw.rawgps.colors", 0); 543 colored = colorIndex >= 0 && colorIndex < colorModes.values().length?colorModes.values()[colorIndex]:colorModes.none; 544 // paint direction arrow with alternate math. may be faster 545 alternatedirection = Main.pref.getBoolean("draw.rawgps.alternatedirection"); 546 // don't draw arrows nearer to each other than this 547 delta = Main.pref.getInteger("draw.rawgps.min-arrow-distance", 0); 548 // allows to tweak line coloring for different speed levels. 549 colorTracksTune = Main.pref.getInteger("draw.rawgps.colorTracksTune", 45); 550 } 551 552 @Override 553 public int hashCode() { 554 final int prime = 31; 555 int result = 1; 556 result = prime * result + getOuterType().hashCode(); 557 result = prime * result + (alternatedirection ? 1231 : 1237); 558 result = prime * result + colorTracksTune; 559 result = prime * result + ((colored == null) ? 0 : colored.hashCode()); 560 result = prime * result + delta; 561 result = prime * result + (direction ? 1231 : 1237); 562 result = prime * result + (forceLines ? 1231 : 1237); 563 result = prime * result + (hdopcircle ? 1231 : 1237); 564 result = prime * result + (large ? 1231 : 1237); 565 result = prime * result + lineWidth; 566 result = prime * result + (lines ? 1231 : 1237); 567 result = prime * result + maxLineLength; 568 result = prime * result + ((neutralColor == null) ? 0 : neutralColor.hashCode()); 569 return result; 570 } 571 572 @Override 573 public boolean equals(Object obj) { 574 if (this == obj) 575 return true; 576 if (obj == null) 577 return false; 578 if (getClass() != obj.getClass()) 579 return false; 580 PaintSettings other = (PaintSettings) obj; 581 if (!getOuterType().equals(other.getOuterType())) 582 return false; 583 if (alternatedirection != other.alternatedirection) 584 return false; 585 if (colorTracksTune != other.colorTracksTune) 586 return false; 587 if (colored == null) { 588 if (other.colored != null) 589 return false; 590 } else if (!colored.equals(other.colored)) 591 return false; 592 if (delta != other.delta) 593 return false; 594 if (direction != other.direction) 595 return false; 596 if (forceLines != other.forceLines) 597 return false; 598 if (hdopcircle != other.hdopcircle) 599 return false; 600 if (large != other.large) 601 return false; 602 if (lineWidth != other.lineWidth) 603 return false; 604 if (lines != other.lines) 605 return false; 606 if (maxLineLength != other.maxLineLength) 607 return false; 608 if (neutralColor == null) { 609 if (other.neutralColor != null) 610 return false; 611 } else if (!neutralColor.equals(other.neutralColor)) 612 return false; 613 return true; 614 } 615 616 private GpxLayer getOuterType() { 617 return GpxLayer.this; 618 } 619 } 620 498 621 @Override 499 622 public void paint(Graphics2D g, MapView mv, Bounds box) { … … 501 624 lastTracks.clear(); 502 625 lastTracks.addAll(data.tracks); 626 lastPaintSettings = new PaintSettings(isLocalFile); 627 503 628 504 629 /**************************************************************** 505 630 ********** STEP 1 - GET CONFIG VALUES ************************** 506 631 ****************************************************************/ 507 // Long startTime = System.currentTimeMillis(); 508 Color neutralColor = getColor(getName()); 509 // also draw lines between points belonging to different segments 510 boolean forceLines = Main.pref.getBoolean("draw.rawgps.lines.force"); 511 // draw direction arrows on the lines 512 boolean direction = Main.pref.getBoolean("draw.rawgps.direction"); 513 // don't draw lines if longer than x meters 514 int lineWidth = Main.pref.getInteger("draw.rawgps.linewidth",0); 515 516 int maxLineLength; 517 if (this.isLocalFile) { 518 maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length.local", -1); 519 } else { 520 maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length", 200); 521 } 522 // draw line between points, global setting 523 boolean lines = (Main.pref.getBoolean("draw.rawgps.lines", true) || (Main.pref 524 .getBoolean("draw.rawgps.lines.localfiles") && this.isLocalFile)); 525 String linesKey = "draw.rawgps.lines.layer " + getName(); 526 // draw lines, per-layer setting 527 if (Main.pref.hasKey(linesKey)) { 528 lines = Main.pref.getBoolean(linesKey); 529 } 530 // paint large dots for points 531 boolean large = Main.pref.getBoolean("draw.rawgps.large"); 532 boolean hdopcircle = Main.pref.getBoolean("draw.rawgps.hdopcircle", true); 533 // color the lines 534 colorModes colored = colorModes.none; 535 try { 536 colored = colorModes.values()[Main.pref.getInteger("draw.rawgps.colors", 0)]; 537 } catch (Exception e) { 538 } 539 // paint direction arrow with alternate math. may be faster 540 boolean alternatedirection = Main.pref.getBoolean("draw.rawgps.alternatedirection"); 541 // don't draw arrows nearer to each other than this 542 int delta = Main.pref.getInteger("draw.rawgps.min-arrow-distance", 0); 543 // allows to tweak line coloring for different speed levels. 544 int colorTracksTune = Main.pref.getInteger("draw.rawgps.colorTracksTune", 45); 545 546 if(lineWidth != 0) 632 PaintSettings ps =lastPaintSettings; 633 634 if(ps.lineWidth != 0) 547 635 { 548 g.setStroke(new BasicStroke( lineWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));636 g.setStroke(new BasicStroke(ps.lineWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND)); 549 637 } 550 638 … … 552 640 ********** STEP 2a - CHECK CACHE VALIDITY ********************** 553 641 ****************************************************************/ 554 if ((computeCacheMaxLineLengthUsed != maxLineLength) || (!neutralColor.equals(computeCacheColorUsed))555 || (computeCacheColored != colored) || (computeCacheColorTracksTune !=colorTracksTune)) {642 if ((computeCacheMaxLineLengthUsed != ps.maxLineLength) || (!ps.neutralColor.equals(computeCacheColorUsed)) 643 || (computeCacheColored != ps.colored) || (computeCacheColorTracksTune != ps.colorTracksTune)) { 556 644 // System.out.println("(re-)computing gpx line styles, reason: CCIS=" + 557 645 // computeCacheInSync + " CCMLLU=" + (computeCacheMaxLineLengthUsed != maxLineLength) + 558 646 // " CCCU=" + (!neutralColor.equals(computeCacheColorUsed)) + " CCC=" + 559 647 // (computeCacheColored != colored)); 560 computeCacheMaxLineLengthUsed = maxLineLength;648 computeCacheMaxLineLengthUsed = ps.maxLineLength; 561 649 computeCacheInSync = false; 562 computeCacheColorUsed = neutralColor;563 computeCacheColored = colored;564 computeCacheColorTracksTune = colorTracksTune;650 computeCacheColorUsed = ps.neutralColor; 651 computeCacheColored = ps.colored; 652 computeCacheColorTracksTune = ps.colorTracksTune; 565 653 } 566 654 … … 572 660 for (GpxTrack trk : data.tracks) { 573 661 for (GpxTrackSegment segment : trk.getSegments()) { 574 if (! forceLines) { // don't draw lines between segments, unless forced to662 if (!ps.forceLines) { // don't draw lines between segments, unless forced to 575 663 oldWp = null; 576 664 } … … 580 668 continue; 581 669 } 582 trkPnt.customColoring = neutralColor;670 trkPnt.customColoring = ps.neutralColor; 583 671 if (oldWp != null) { 584 672 double dist = c.greatCircleDistance(oldWp.getCoor()); 585 673 586 switch ( colored) {674 switch (ps.colored) { 587 675 case velocity: 588 676 double dtime = trkPnt.time - oldWp.time; 589 677 double vel = dist / dtime; 590 double velColor = vel / colorTracksTune * 255;678 double velColor = vel / ps.colorTracksTune * 255; 591 679 // Bad case first 592 680 if (dtime <= 0 || vel < 0 || velColor > 255) { … … 612 700 } 613 701 614 if ( maxLineLength == -1 || dist <=maxLineLength) {702 if (ps.maxLineLength == -1 || dist <= ps.maxLineLength) { 615 703 trkPnt.drawLine = true; 616 704 trkPnt.dir = (int) oldWp.getCoor().heading(trkPnt.getCoor()); … … 640 728 ********** STEP 3a - DRAW LINES ******************************** 641 729 ****************************************************************/ 642 if ( lines) {730 if (ps.lines) { 643 731 Point old = null; 644 732 for (Collection<WayPoint> segment : visibleSegments) { … … 664 752 ********** STEP 3b - DRAW NICE ARROWS ************************** 665 753 ****************************************************************/ 666 if ( lines && direction && !alternatedirection) {754 if (ps.lines && ps.direction && !ps.alternatedirection) { 667 755 Point old = null; 668 756 Point oldA = null; // last arrow painted … … 677 765 // skip points that are on the same screenposition 678 766 if (old != null 679 && (oldA == null || screen.x < oldA.x - delta || screen.x > oldA.x +delta680 || screen.y < oldA.y - delta || screen.y > oldA.y +delta)) {767 && (oldA == null || screen.x < oldA.x - ps.delta || screen.x > oldA.x + ps.delta 768 || screen.y < oldA.y - ps.delta || screen.y > oldA.y + ps.delta)) { 681 769 g.setColor(trkPnt.customColoring); 682 770 double t = Math.atan2(screen.y - old.y, screen.x - old.x) + Math.PI; … … 696 784 ********** STEP 3c - DRAW FAST ARROWS ************************** 697 785 ****************************************************************/ 698 if ( lines && direction &&alternatedirection) {786 if (ps.lines && ps.direction && ps.alternatedirection) { 699 787 Point old = null; 700 788 Point oldA = null; // last arrow painted … … 709 797 // skip points that are on the same screenposition 710 798 if (old != null 711 && (oldA == null || screen.x < oldA.x - delta || screen.x > oldA.x +delta712 || screen.y < oldA.y - delta || screen.y > oldA.y +delta)) {799 && (oldA == null || screen.x < oldA.x - ps.delta || screen.x > oldA.x + ps.delta 800 || screen.y < oldA.y - ps.delta || screen.y > oldA.y + ps.delta)) { 713 801 g.setColor(trkPnt.customColoring); 714 802 g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][0], screen.y … … 727 815 ********** STEP 3d - DRAW LARGE POINTS AND HDOP CIRCLE ********* 728 816 ****************************************************************/ 729 if ( large ||hdopcircle) {730 g.setColor( neutralColor);817 if (ps.large || ps.hdopcircle) { 818 g.setColor(ps.neutralColor); 731 819 for (Collection<WayPoint> segment : visibleSegments) { 732 820 for (WayPoint trkPnt : segment) { … … 737 825 Point screen = mv.getPoint(trkPnt.getEastNorth()); 738 826 g.setColor(trkPnt.customColoring); 739 if ( hdopcircle && trkPnt.attr.get("hdop") != null) {827 if (ps.hdopcircle && trkPnt.attr.get("hdop") != null) { 740 828 // hdop value 741 829 float hdop = ((Float)trkPnt.attr.get("hdop")).floatValue(); … … 747 835 g.drawArc(screen.x-hdopp/2, screen.y-hdopp/2, hdopp, hdopp, 0, 360); 748 836 } 749 if ( large) {837 if (ps.large) { 750 838 g.fillRect(screen.x-1, screen.y-1, 3, 3); 751 839 } … … 757 845 ********** STEP 3e - DRAW SMALL POINTS FOR LINES *************** 758 846 ****************************************************************/ 759 if (! large &&lines) {760 g.setColor( neutralColor);847 if (!ps.large && ps.lines) { 848 g.setColor(ps.neutralColor); 761 849 for (Collection<WayPoint> segment : visibleSegments) { 762 850 for (WayPoint trkPnt : segment) { … … 776 864 ********** STEP 3f - DRAW SMALL POINTS INSTEAD OF LINES ******** 777 865 ****************************************************************/ 778 if (! large && !lines) {779 g.setColor( neutralColor);866 if (!ps.large && !ps.lines) { 867 g.setColor(ps.neutralColor); 780 868 for (Collection<WayPoint> segment : visibleSegments) { 781 869 for (WayPoint trkPnt : segment) { -
trunk/src/org/openstreetmap/josm/gui/preferences/ProjectionPreference.java
r2990 r3127 109 109 String projname = proj.getClass().getName(); 110 110 Collection<String> prefs = null; 111 if(proj HasPrefs(proj)) {111 if(proj instanceof ProjectionSubPrefs) { 112 112 prefs = ((ProjectionSubPrefs) proj).getPreferences(projSubPrefPanel); 113 113 } … … 121 121 } 122 122 123 return false;124 }125 126 /**127 * Finds out if the given projection implements the ProjectionPreference128 * interface129 * @param proj130 * @return131 */132 @SuppressWarnings("unchecked")133 static private boolean projHasPrefs(Projection proj) {134 Class[] ifaces = proj.getClass().getInterfaces();135 for(int i = 0; i < ifaces.length; i++) {136 if(ifaces[i].getSimpleName().equals("ProjectionSubPrefs"))137 return true;138 }139 123 return false; 140 124 } … … 167 151 String sname = name.substring(name.lastIndexOf(".")+1); 168 152 Main.pref.putCollection("projection.sub."+sname, coll); 169 if( projHasPrefs(Main.proj)) {153 if(Main.proj instanceof ProjectionSubPrefs) { 170 154 ((ProjectionSubPrefs) Main.proj).setPreferences(coll); 171 155 } … … 200 184 */ 201 185 private void selectedProjectionChanged(Projection proj) { 202 if(! projHasPrefs(proj)) {186 if(!(proj instanceof ProjectionSubPrefs)) { 203 187 projSubPrefPanel = new JPanel(); 204 188 } else { … … 229 213 String name = proj.getClass().getName(); 230 214 String sname = name.substring(name.lastIndexOf(".")+1); 231 if(proj HasPrefs(proj)) {215 if(proj instanceof ProjectionSubPrefs) { 232 216 ((ProjectionSubPrefs) proj).setPreferences(Main.pref.getCollection("projection.sub."+sname, null)); 233 217 }
Note:
See TracChangeset
for help on using the changeset viewer.