Ticket #10920: GeoImageLayer_stopLoadThumbs.patch

File GeoImageLayer_stopLoadThumbs.patch, 3.0 KB (added by holgermappt, 9 years ago)

Patch file for this ticket

  • src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

     
    372372    public void mergeFrom(Layer from) {
    373373        GeoImageLayer l = (GeoImageLayer) from;
    374374
     375        // Stop to load thumbnails on both layers.  Thumbnail loading will continue the next time
     376        // the layer is painted.
     377        stopLoadThumbs();
     378        l.stopLoadThumbs();
     379
    375380        ImageEntry selected = null;
    376381        if (l.currentPhoto >= 0) {
    377382            selected = l.data.get(l.currentPhoto);
     
    988993            @Override
    989994            public void layerRemoved(Layer oldLayer) {
    990995                if (oldLayer == GeoImageLayer.this) {
    991                     if (thumbsloader != null) {
    992                         thumbsloader.stop = true;
    993                     }
     996                    stopLoadThumbs();
    994997                    Main.map.mapView.removeMouseListener(mouseAdapter);
    995998                    MapFrame.removeMapModeChangeListener(mapModeListener);
    996999                    currentPhoto = -1;
     
    10181021
    10191022    public void loadThumbs() {
    10201023        if (useThumbs && !thumbsLoaded) {
     1024            stopLoadThumbs();
    10211025            thumbsLoaded = true;
    10221026            thumbsloader = new ThumbsLoader(this);
    10231027            Thread t = new Thread(thumbsloader);
     
    10261030        }
    10271031    }
    10281032
     1033    /**
     1034     * Stop to load thumbnails.  Can be called at any time to make sure that the
     1035     * thumbnail loader is stopped.
     1036     * @since tbd
     1037     */
     1038    public void stopLoadThumbs() {
     1039        if (thumbsloader != null) {
     1040            thumbsloader.stop = true;
     1041            if (!thumbsloader.done) {
     1042                thumbsLoaded = false;
     1043            }
     1044        }
     1045    }
     1046
    10291047    public void updateBufferAndRepaint() {
    10301048        updateOffscreenBuffer = true;
    10311049        Main.map.mapView.repaint();
     
    10761094        this.useThumbs = useThumbs;
    10771095        if (useThumbs && !thumbsLoaded) {
    10781096            loadThumbs();
     1097        } else if (!useThumbs) {
     1098            stopLoadThumbs();
    10791099        }
    10801100    }
    10811101}
  • src/org/openstreetmap/josm/gui/layer/geoimage/ThumbsLoader.java

     
    1616public class ThumbsLoader implements Runnable {
    1717    public static final int maxSize = 120;
    1818    public static final int minSize = 22;
    19     volatile boolean stop = false;
     19    public volatile boolean stop = false;
     20    public volatile boolean done = false;
    2021    List<ImageEntry> data;
    2122    GeoImageLayer layer;
    2223    MediaTracker tracker;
     
    5051                }
    5152            }
    5253        }
     54        done = true;
    5355        layer.updateOffscreenBuffer = true;
    5456        Main.map.mapView.repaint();
    5557    }