Ignore:
Timestamp:
13.03.2010 10:23:39 (2 years ago)
Author:
jttt
Message:

Fix #4728 display of gps-tracks (points, lines) does not refresh, cosmetics

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r3119 r3127  
    8787    private final List<GpxTrack> lastTracks = new ArrayList<GpxTrack>(); // List of tracks at last paint 
    8888    private int lastUpdateCount; 
     89    private PaintSettings lastPaintSettings; 
    8990 
    9091    private static class Markers { 
     
    463464    @Override 
    464465    public boolean isChanged() { 
    465         if (data.tracks.equals(lastTracks)) 
     466        if (data.tracks.equals(lastTracks) && new PaintSettings(isLocalFile).equals(lastPaintSettings)) 
    466467            return sumUpdateCount() != lastUpdateCount; 
    467468        else 
     
    496497    } 
    497498 
     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 
    498621    @Override 
    499622    public void paint(Graphics2D g, MapView mv, Bounds box) { 
     
    501624        lastTracks.clear(); 
    502625        lastTracks.addAll(data.tracks); 
     626        lastPaintSettings = new PaintSettings(isLocalFile); 
     627 
    503628 
    504629        /**************************************************************** 
    505630         ********** STEP 1 - GET CONFIG VALUES ************************** 
    506631         ****************************************************************/ 
    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) 
    547635        { 
    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)); 
    549637        } 
    550638 
     
    552640         ********** STEP 2a - CHECK CACHE VALIDITY ********************** 
    553641         ****************************************************************/ 
    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)) { 
    556644            // System.out.println("(re-)computing gpx line styles, reason: CCIS=" + 
    557645            // computeCacheInSync + " CCMLLU=" + (computeCacheMaxLineLengthUsed != maxLineLength) + 
    558646            // " CCCU=" + (!neutralColor.equals(computeCacheColorUsed)) + " CCC=" + 
    559647            // (computeCacheColored != colored)); 
    560             computeCacheMaxLineLengthUsed = maxLineLength; 
     648            computeCacheMaxLineLengthUsed = ps.maxLineLength; 
    561649            computeCacheInSync = false; 
    562             computeCacheColorUsed = neutralColor; 
    563             computeCacheColored = colored; 
    564             computeCacheColorTracksTune = colorTracksTune; 
     650            computeCacheColorUsed = ps.neutralColor; 
     651            computeCacheColored = ps.colored; 
     652            computeCacheColorTracksTune = ps.colorTracksTune; 
    565653        } 
    566654 
     
    572660            for (GpxTrack trk : data.tracks) { 
    573661                for (GpxTrackSegment segment : trk.getSegments()) { 
    574                     if (!forceLines) { // don't draw lines between segments, unless forced to 
     662                    if (!ps.forceLines) { // don't draw lines between segments, unless forced to 
    575663                        oldWp = null; 
    576664                    } 
     
    580668                            continue; 
    581669                        } 
    582                         trkPnt.customColoring = neutralColor; 
     670                        trkPnt.customColoring = ps.neutralColor; 
    583671                        if (oldWp != null) { 
    584672                            double dist = c.greatCircleDistance(oldWp.getCoor()); 
    585673 
    586                             switch (colored) { 
     674                            switch (ps.colored) { 
    587675                            case velocity: 
    588676                                double dtime = trkPnt.time - oldWp.time; 
    589677                                double vel = dist / dtime; 
    590                                 double velColor = vel / colorTracksTune * 255; 
     678                                double velColor = vel / ps.colorTracksTune * 255; 
    591679                                // Bad case first 
    592680                                if (dtime <= 0 || vel < 0 || velColor > 255) { 
     
    612700                            } 
    613701 
    614                             if (maxLineLength == -1 || dist <= maxLineLength) { 
     702                            if (ps.maxLineLength == -1 || dist <= ps.maxLineLength) { 
    615703                                trkPnt.drawLine = true; 
    616704                                trkPnt.dir = (int) oldWp.getCoor().heading(trkPnt.getCoor()); 
     
    640728         ********** STEP 3a - DRAW LINES ******************************** 
    641729         ****************************************************************/ 
    642         if (lines) { 
     730        if (ps.lines) { 
    643731            Point old = null; 
    644732            for (Collection<WayPoint> segment : visibleSegments) { 
     
    664752         ********** STEP 3b - DRAW NICE ARROWS ************************** 
    665753         ****************************************************************/ 
    666         if (lines && direction && !alternatedirection) { 
     754        if (ps.lines && ps.direction && !ps.alternatedirection) { 
    667755            Point old = null; 
    668756            Point oldA = null; // last arrow painted 
     
    677765                        // skip points that are on the same screenposition 
    678766                        if (old != null 
    679                                 && (oldA == null || screen.x < oldA.x - delta || screen.x > oldA.x + delta 
    680                                         || 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)) { 
    681769                            g.setColor(trkPnt.customColoring); 
    682770                            double t = Math.atan2(screen.y - old.y, screen.x - old.x) + Math.PI; 
     
    696784         ********** STEP 3c - DRAW FAST ARROWS ************************** 
    697785         ****************************************************************/ 
    698         if (lines && direction && alternatedirection) { 
     786        if (ps.lines && ps.direction && ps.alternatedirection) { 
    699787            Point old = null; 
    700788            Point oldA = null; // last arrow painted 
     
    709797                        // skip points that are on the same screenposition 
    710798                        if (old != null 
    711                                 && (oldA == null || screen.x < oldA.x - delta || screen.x > oldA.x + delta 
    712                                         || 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)) { 
    713801                            g.setColor(trkPnt.customColoring); 
    714802                            g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][0], screen.y 
     
    727815         ********** STEP 3d - DRAW LARGE POINTS AND HDOP CIRCLE ********* 
    728816         ****************************************************************/ 
    729         if (large || hdopcircle) { 
    730             g.setColor(neutralColor); 
     817        if (ps.large || ps.hdopcircle) { 
     818            g.setColor(ps.neutralColor); 
    731819            for (Collection<WayPoint> segment : visibleSegments) { 
    732820                for (WayPoint trkPnt : segment) { 
     
    737825                    Point screen = mv.getPoint(trkPnt.getEastNorth()); 
    738826                    g.setColor(trkPnt.customColoring); 
    739                     if (hdopcircle && trkPnt.attr.get("hdop") != null) { 
     827                    if (ps.hdopcircle && trkPnt.attr.get("hdop") != null) { 
    740828                        // hdop value 
    741829                        float hdop = ((Float)trkPnt.attr.get("hdop")).floatValue(); 
     
    747835                        g.drawArc(screen.x-hdopp/2, screen.y-hdopp/2, hdopp, hdopp, 0, 360); 
    748836                    } 
    749                     if (large) { 
     837                    if (ps.large) { 
    750838                        g.fillRect(screen.x-1, screen.y-1, 3, 3); 
    751839                    } 
     
    757845         ********** STEP 3e - DRAW SMALL POINTS FOR LINES *************** 
    758846         ****************************************************************/ 
    759         if (!large && lines) { 
    760             g.setColor(neutralColor); 
     847        if (!ps.large && ps.lines) { 
     848            g.setColor(ps.neutralColor); 
    761849            for (Collection<WayPoint> segment : visibleSegments) { 
    762850                for (WayPoint trkPnt : segment) { 
     
    776864         ********** STEP 3f - DRAW SMALL POINTS INSTEAD OF LINES ******** 
    777865         ****************************************************************/ 
    778         if (!large && !lines) { 
    779             g.setColor(neutralColor); 
     866        if (!ps.large && !ps.lines) { 
     867            g.setColor(ps.neutralColor); 
    780868            for (Collection<WayPoint> segment : visibleSegments) { 
    781869                for (WayPoint trkPnt : segment) { 
Note: See TracChangeset for help on using the changeset viewer.