Changeset 4334 in josm


Ignore:
Timestamp:
2011-08-22T13:47:35+02:00 (13 years ago)
Author:
xeen
Message:

fix two NPEs in GpxLayer (fixes #6726) and also repaint the map when merging new GPX data

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java

    r2512 r4334  
    8181            } else {
    8282                x.mergeFrom(layer);
     83                Main.map.repaint();
    8384            }
    8485        }
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r4332 r4334  
    112112    private boolean isLocalFile;
    113113    // used by ChooseTrackVisibilityAction to determine which tracks to show/hide
    114     private boolean[] trackVisibility;
     114    private boolean[] trackVisibility = new boolean[0];
    115115
    116116    private final List<GpxTrack> lastTracks = new ArrayList<GpxTrack>(); // List of tracks at last paint
     
    126126        data = d;
    127127        computeCacheInSync = false;
    128         trackVisibility = new boolean[d.tracks.size()];
    129         for(int i=0; i < d.tracks.size(); i++) {
    130             trackVisibility[i] = true;
    131         }
     128        ensureTrackVisibilityLength();
    132129    }
    133130
     
    579576                                    int velColor =(int) Math.round(colorModeDynamic ? ((vel-minval)*255/(maxval-minval))
    580577                                            : (vel <= 0 ? 0 : vel / colorTracksTune * 255));
    581                                     trkPnt.customColoring = colors[velColor > 255 ? 255 : velColor];
     578                                    trkPnt.customColoring = colors[Math.max(0, Math.min(velColor, 255))];
    582579                                } else {
    583580                                    trkPnt.customColoring = colors[255];
     
    622619        WayPoint last = null;
    623620        int i = 0;
     621        ensureTrackVisibilityLength();
    624622        for (GpxTrack trk: data.tracks) {
    625623            // hide tracks that were de-selected in ChooseTrackVisibilityAction
     
    857855    public void setAssociatedFile(File file) {
    858856        data.storageFile = file;
     857    }
     858
     859    /** ensures the trackVisibility array has the correct length without losing data.
     860     * additional entries are initialized to true;
     861     */
     862    final private void ensureTrackVisibilityLength() {
     863        final int l = data.tracks.size();
     864        if(l == trackVisibility.length)
     865            return;
     866        final boolean[] back = trackVisibility.clone();
     867        final int m = Math.min(l, back.length);
     868        trackVisibility = new boolean[l];
     869        for(int i=0; i < m; i++) {
     870            trackVisibility[i] = back[i];
     871        }
     872        for(int i=m; i < l; i++) {
     873            trackVisibility[i] = true;
     874        }
    859875    }
    860876
Note: See TracChangeset for help on using the changeset viewer.