Changeset 3128 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2010-03-13T10:45:19+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/MapView.java
r3125 r3128 39 39 import org.openstreetmap.josm.data.Bounds; 40 40 import org.openstreetmap.josm.data.SelectionChangedListener; 41 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 42 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 41 43 import org.openstreetmap.josm.data.coor.LatLon; 42 44 import org.openstreetmap.josm.data.osm.DataSet; … … 65 67 * @author imi 66 68 */ 67 public class MapView extends NavigatableComponent implements PropertyChangeListener { 69 public class MapView extends NavigatableComponent implements PropertyChangeListener, PreferenceChangedListener { 68 70 69 71 /** … … 183 185 private final List<Layer> nonChangedLayers = new ArrayList<Layer>(); 184 186 private int lastViewID; 187 private boolean paintPreferencesChanged = true; 185 188 186 189 public MapView() { 190 Main.pref.addPreferenceChangeListener(this); 187 191 addComponentListener(new ComponentAdapter(){ 188 192 @Override public void componentResized(ComponentEvent e) { … … 472 476 } 473 477 474 boolean canUseBuffer = nonChangedLayers.size() <= nonChangedLayersCount && lastViewID == getViewID(); 478 boolean canUseBuffer = !paintPreferencesChanged && nonChangedLayers.size() <= nonChangedLayersCount && lastViewID == getViewID(); 475 479 if (canUseBuffer) { 476 480 for (int i=0; i<nonChangedLayers.size(); i++) { … … 513 517 } 514 518 lastViewID = getViewID(); 519 paintPreferencesChanged = false; 515 520 516 521 tempG.drawImage(offscreenBuffer, 0, 0, null); … … 799 804 } 800 805 806 public void preferenceChanged(PreferenceChangeEvent e) { 807 paintPreferencesChanged = true; 808 } 809 801 810 } -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r3127 r3128 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;90 89 91 90 private static class Markers { … … 464 463 @Override 465 464 public boolean isChanged() { 466 if (data.tracks.equals(lastTracks) && new PaintSettings(isLocalFile).equals(lastPaintSettings))465 if (data.tracks.equals(lastTracks)) 467 466 return sumUpdateCount() != lastUpdateCount; 468 467 else … … 497 496 } 498 497 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 segments516 forceLines = Main.pref.getBoolean("draw.rawgps.lines.force");517 // draw direction arrows on the lines518 direction = Main.pref.getBoolean("draw.rawgps.direction");519 // don't draw lines if longer than x meters520 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 setting529 boolean lines = (Main.pref.getBoolean("draw.rawgps.lines", true) || (Main.pref530 .getBoolean("draw.rawgps.lines.localfiles") && isLocalFile));531 String linesKey = "draw.rawgps.lines.layer " + getName();532 // draw lines, per-layer setting533 if (Main.pref.hasKey(linesKey)) {534 lines = Main.pref.getBoolean(linesKey);535 }536 this.lines = lines;537 538 // paint large dots for points539 large = Main.pref.getBoolean("draw.rawgps.large");540 hdopcircle = Main.pref.getBoolean("draw.rawgps.hdopcircle", true);541 // color the lines542 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 faster545 alternatedirection = Main.pref.getBoolean("draw.rawgps.alternatedirection");546 // don't draw arrows nearer to each other than this547 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 @Override553 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 @Override573 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 621 498 @Override 622 499 public void paint(Graphics2D g, MapView mv, Bounds box) { … … 624 501 lastTracks.clear(); 625 502 lastTracks.addAll(data.tracks); 626 lastPaintSettings = new PaintSettings(isLocalFile);627 628 503 629 504 /**************************************************************** 630 505 ********** STEP 1 - GET CONFIG VALUES ************************** 631 506 ****************************************************************/ 632 PaintSettings ps =lastPaintSettings; 633 634 if(ps.lineWidth != 0) 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) 635 547 { 636 g.setStroke(new BasicStroke( ps.lineWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));548 g.setStroke(new BasicStroke(lineWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND)); 637 549 } 638 550 … … 640 552 ********** STEP 2a - CHECK CACHE VALIDITY ********************** 641 553 ****************************************************************/ 642 if ((computeCacheMaxLineLengthUsed != ps.maxLineLength) || (!ps.neutralColor.equals(computeCacheColorUsed))643 || (computeCacheColored != ps.colored) || (computeCacheColorTracksTune !=ps.colorTracksTune)) {554 if ((computeCacheMaxLineLengthUsed != maxLineLength) || (!neutralColor.equals(computeCacheColorUsed)) 555 || (computeCacheColored != colored) || (computeCacheColorTracksTune != colorTracksTune)) { 644 556 // System.out.println("(re-)computing gpx line styles, reason: CCIS=" + 645 557 // computeCacheInSync + " CCMLLU=" + (computeCacheMaxLineLengthUsed != maxLineLength) + 646 558 // " CCCU=" + (!neutralColor.equals(computeCacheColorUsed)) + " CCC=" + 647 559 // (computeCacheColored != colored)); 648 computeCacheMaxLineLengthUsed = ps.maxLineLength;560 computeCacheMaxLineLengthUsed = maxLineLength; 649 561 computeCacheInSync = false; 650 computeCacheColorUsed = ps.neutralColor;651 computeCacheColored = ps.colored;652 computeCacheColorTracksTune = ps.colorTracksTune;562 computeCacheColorUsed = neutralColor; 563 computeCacheColored = colored; 564 computeCacheColorTracksTune = colorTracksTune; 653 565 } 654 566 … … 660 572 for (GpxTrack trk : data.tracks) { 661 573 for (GpxTrackSegment segment : trk.getSegments()) { 662 if (! ps.forceLines) { // don't draw lines between segments, unless forced to574 if (!forceLines) { // don't draw lines between segments, unless forced to 663 575 oldWp = null; 664 576 } … … 668 580 continue; 669 581 } 670 trkPnt.customColoring = ps.neutralColor;582 trkPnt.customColoring = neutralColor; 671 583 if (oldWp != null) { 672 584 double dist = c.greatCircleDistance(oldWp.getCoor()); 673 585 674 switch ( ps.colored) {586 switch (colored) { 675 587 case velocity: 676 588 double dtime = trkPnt.time - oldWp.time; 677 589 double vel = dist / dtime; 678 double velColor = vel / ps.colorTracksTune * 255;590 double velColor = vel / colorTracksTune * 255; 679 591 // Bad case first 680 592 if (dtime <= 0 || vel < 0 || velColor > 255) { … … 700 612 } 701 613 702 if ( ps.maxLineLength == -1 || dist <=ps.maxLineLength) {614 if (maxLineLength == -1 || dist <= maxLineLength) { 703 615 trkPnt.drawLine = true; 704 616 trkPnt.dir = (int) oldWp.getCoor().heading(trkPnt.getCoor()); … … 728 640 ********** STEP 3a - DRAW LINES ******************************** 729 641 ****************************************************************/ 730 if ( ps.lines) {642 if (lines) { 731 643 Point old = null; 732 644 for (Collection<WayPoint> segment : visibleSegments) { … … 752 664 ********** STEP 3b - DRAW NICE ARROWS ************************** 753 665 ****************************************************************/ 754 if ( ps.lines &&ps.direction && !ps.alternatedirection) {666 if (lines && direction && !alternatedirection) { 755 667 Point old = null; 756 668 Point oldA = null; // last arrow painted … … 765 677 // skip points that are on the same screenposition 766 678 if (old != null 767 && (oldA == null || screen.x < oldA.x - ps.delta || screen.x > oldA.x +ps.delta768 || screen.y < oldA.y - ps.delta || screen.y > oldA.y +ps.delta)) {679 && (oldA == null || screen.x < oldA.x - delta || screen.x > oldA.x + delta 680 || screen.y < oldA.y - delta || screen.y > oldA.y + delta)) { 769 681 g.setColor(trkPnt.customColoring); 770 682 double t = Math.atan2(screen.y - old.y, screen.x - old.x) + Math.PI; … … 784 696 ********** STEP 3c - DRAW FAST ARROWS ************************** 785 697 ****************************************************************/ 786 if ( ps.lines &&ps.direction &&ps.alternatedirection) {698 if (lines && direction && alternatedirection) { 787 699 Point old = null; 788 700 Point oldA = null; // last arrow painted … … 797 709 // skip points that are on the same screenposition 798 710 if (old != null 799 && (oldA == null || screen.x < oldA.x - ps.delta || screen.x > oldA.x +ps.delta800 || screen.y < oldA.y - ps.delta || screen.y > oldA.y +ps.delta)) {711 && (oldA == null || screen.x < oldA.x - delta || screen.x > oldA.x + delta 712 || screen.y < oldA.y - delta || screen.y > oldA.y + delta)) { 801 713 g.setColor(trkPnt.customColoring); 802 714 g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][0], screen.y … … 815 727 ********** STEP 3d - DRAW LARGE POINTS AND HDOP CIRCLE ********* 816 728 ****************************************************************/ 817 if ( ps.large ||ps.hdopcircle) {818 g.setColor( ps.neutralColor);729 if (large || hdopcircle) { 730 g.setColor(neutralColor); 819 731 for (Collection<WayPoint> segment : visibleSegments) { 820 732 for (WayPoint trkPnt : segment) { … … 825 737 Point screen = mv.getPoint(trkPnt.getEastNorth()); 826 738 g.setColor(trkPnt.customColoring); 827 if ( ps.hdopcircle && trkPnt.attr.get("hdop") != null) {739 if (hdopcircle && trkPnt.attr.get("hdop") != null) { 828 740 // hdop value 829 741 float hdop = ((Float)trkPnt.attr.get("hdop")).floatValue(); … … 835 747 g.drawArc(screen.x-hdopp/2, screen.y-hdopp/2, hdopp, hdopp, 0, 360); 836 748 } 837 if ( ps.large) {749 if (large) { 838 750 g.fillRect(screen.x-1, screen.y-1, 3, 3); 839 751 } … … 845 757 ********** STEP 3e - DRAW SMALL POINTS FOR LINES *************** 846 758 ****************************************************************/ 847 if (! ps.large &&ps.lines) {848 g.setColor( ps.neutralColor);759 if (!large && lines) { 760 g.setColor(neutralColor); 849 761 for (Collection<WayPoint> segment : visibleSegments) { 850 762 for (WayPoint trkPnt : segment) { … … 864 776 ********** STEP 3f - DRAW SMALL POINTS INSTEAD OF LINES ******** 865 777 ****************************************************************/ 866 if (! ps.large && !ps.lines) {867 g.setColor( ps.neutralColor);778 if (!large && !lines) { 779 g.setColor(neutralColor); 868 780 for (Collection<WayPoint> segment : visibleSegments) { 869 781 for (WayPoint trkPnt : segment) {
Note:
See TracChangeset
for help on using the changeset viewer.