Ticket #11317: fix_flickering.patch

File fix_flickering.patch, 9.4 KB (added by wiktorn, 8 years ago)

Patch for flicking

  • new file .gitignore

    diff --git .gitignore .gitignore
    new file mode 100644
    index 0000000..2384283
    - +  
     1/bin/
     2/build/
     3/dist/
  • src/org/openstreetmap/josm/data/cache/ICachedLoaderListener.java

    diff --git src/org/openstreetmap/josm/data/cache/ICachedLoaderListener.java src/org/openstreetmap/josm/data/cache/ICachedLoaderListener.java
    index 32fa35a..fe26c09 100644
     
    22package org.openstreetmap.josm.data.cache;
    33
    44public interface ICachedLoaderListener {
     5
     6    /**
     7     * Result of download
     8     *
     9     */
     10    enum LoadResult {
     11        SUCCESS,
     12        FAILURE,
     13        REJECTED
     14    }
    515    /**
    6      * Will be called when K object was successfully downloaded
    7      *
     16     * Will be called when K object processed. The result might be:
     17     * LoadResult.SUCCESS when object was fetched
     18     * LoadResult.FAILURE when there was a failure during download
     19     * LoadResult.REJECTED when job was rejected because of full queue
     20     *
    821     * @param data
    9      * @param success
     22     * @param result
    1023     */
    11     public void loadingFinished(CacheEntry data, boolean success);
     24    public void loadingFinished(CacheEntry data, LoadResult result);
    1225
    1326}
  • src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java

    diff --git src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java
    index d636de4..478004b 100644
    import java.util.logging.Logger; 
    2626import org.apache.commons.jcs.access.behavior.ICacheAccess;
    2727import org.apache.commons.jcs.engine.behavior.ICacheElement;
    2828import org.openstreetmap.gui.jmapviewer.FeatureAdapter;
     29import org.openstreetmap.josm.data.cache.ICachedLoaderListener.LoadResult;
    2930import org.openstreetmap.josm.data.preferences.IntegerProperty;
    3031
    3132/**
    public abstract class JCSCachedTileLoaderJob<K, V extends CacheEntry> implements 
    151152            if (cacheElement != null && isCacheElementValid() && (isObjectLoadable())) {
    152153                // we got something in cache, and it's valid, so lets return it
    153154                log.log(Level.FINE, "JCS - Returning object from cache: {0}", getCacheKey());
    154                 finishLoading(true);
     155                finishLoading(LoadResult.SUCCESS);
    155156                return;
    156157            }
    157158            // object not in cache, so submit work to separate thread
    public abstract class JCSCachedTileLoaderJob<K, V extends CacheEntry> implements 
    161162            } catch (RejectedExecutionException e) {
    162163                // queue was full, try again later
    163164                log.log(Level.FINE, "JCS - rejected job for: {0}", getCacheKey());
    164                 finishLoading(false);
     165                finishLoading(LoadResult.REJECTED);
    165166            }
    166167        }
    167168    }
    public abstract class JCSCachedTileLoaderJob<K, V extends CacheEntry> implements 
    205206        try {
    206207            // try to load object from remote resource
    207208            if (loadObject()) {
    208                 finishLoading(true);
     209                finishLoading(LoadResult.SUCCESS);
    209210            } else {
    210211                // if loading failed - check if we can return stale entry
    211212                if (isObjectLoadable()) {
    212213                    // try to get stale entry in cache
    213                     finishLoading(true);
     214                    finishLoading(LoadResult.SUCCESS);
    214215                    log.log(Level.FINE, "JCS - found stale object in cache: {0}", getUrl());
    215216                } else {
    216217                    // failed completely
    217                     finishLoading(false);
     218                    finishLoading(LoadResult.FAILURE);
    218219                }
    219220            }
    220221        } finally {
    public abstract class JCSCachedTileLoaderJob<K, V extends CacheEntry> implements 
    223224    }
    224225
    225226
    226     private void finishLoading(boolean success) {
     227    private void finishLoading(LoadResult result) {
    227228        Set<ICachedLoaderListener> listeners = null;
    228229        synchronized (inProgress) {
    229230            listeners = inProgress.remove(getUrl().toString());
    public abstract class JCSCachedTileLoaderJob<K, V extends CacheEntry> implements 
    234235        }
    235236        try {
    236237            for (ICachedLoaderListener l: listeners) {
    237                 l.loadingFinished(cacheData, success);
     238                l.loadingFinished(cacheData, result);
    238239            }
    239240        } catch (Exception e) {
    240241            log.log(Level.WARNING, "JCS - Error while loading object from cache: {0}; {1}", new Object[]{e.getMessage(), getUrl()});
    241242            log.log(Level.FINE, "Stacktrace", e);
    242243            for (ICachedLoaderListener l: listeners) {
    243                 l.loadingFinished(cacheData, false);
     244                l.loadingFinished(cacheData, LoadResult.FAILURE);
    244245            }
    245246
    246247        }
  • src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java

    diff --git src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java
    index cb7754f..44e8467 100644
    public class TMSCachedTileLoaderJob extends JCSCachedTileLoaderJob<String, Buffe 
    132132        return false;
    133133    }
    134134
     135    private boolean isNoTileAtZoom() {
     136        return attributes != null && attributes.isNoTileAtZoom();
     137    }
     138
    135139    @Override
    136140    protected boolean cacheAsEmpty() {
    137         if (attributes != null && attributes.isNoTileAtZoom()) {
    138             // do not remove file - keep the information, that there is no tile, for further requests
    139             // the code above will check, if this information is still valid
     141        return isNoTileAtZoom();
     142    }
     143
     144    private boolean handleNoTileAtZoom() {
     145        if (isNoTileAtZoom()) {
    140146            log.log(Level.FINE, "JCS TMS - Tile valid, but no file, as no tiles at this level {0}", tile);
    141147            tile.setError("No tile at this zoom level");
    142148            tile.putValue("tile-info", "no-tile");
    143149            return true;
    144150        }
    145         return false; // as there is no other cache to cache the Tile, also cache other empty requests
     151        return false;
    146152    }
    147153
    148154    @Override
    public class TMSCachedTileLoaderJob extends JCSCachedTileLoaderJob<String, Buffe 
    156162    }
    157163
    158164    @Override
    159     public void loadingFinished(CacheEntry object, boolean success) {
     165    public void loadingFinished(CacheEntry object, LoadResult result) {
    160166        try {
    161             loadTile(object, success);
     167            tile.finishLoading(); // whatever happened set that loading has finished
     168            switch(result){
     169            case FAILURE:
     170                tile.setError("Problem loading tile");
     171            case SUCCESS:
     172                handleNoTileAtZoom();
     173                if (object != null) {
     174                    byte[] content = object.getContent();
     175                    if (content != null && content.length > 0) {
     176                        tile.loadImage(new ByteArrayInputStream(content));
     177                    }
     178                }
     179            case REJECTED:
     180                // do not set anything here, leave waiting sign
     181            }
    162182            if (listener != null) {
    163                 listener.tileLoadingFinished(tile, success);
     183                listener.tileLoadingFinished(tile, result.equals(LoadResult.SUCCESS));
    164184            }
    165185        } catch (IOException e) {
    166186            log.log(Level.WARNING, "JCS TMS - error loading object for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()});
    public class TMSCachedTileLoaderJob extends JCSCachedTileLoaderJob<String, Buffe 
    180200        BufferedImageCacheEntry data = get();
    181201        if (isObjectLoadable()) {
    182202            try {
    183                 loadTile(data);
     203                if (data != null && data.getImage() != null) {
     204                    tile.setImage(data.getImage());
     205                    tile.finishLoading();
     206                }
     207                if (isNoTileAtZoom()) {
     208                    handleNoTileAtZoom();
     209                    tile.finishLoading();
     210                }
    184211                return tile;
    185212            } catch (IOException e) {
    186213                log.log(Level.WARNING, "JCS TMS - error loading object for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()});
    public class TMSCachedTileLoaderJob extends JCSCachedTileLoaderJob<String, Buffe 
    188215            }
    189216
    190217        } else {
    191             return null;
    192         }
    193     }
    194 
    195     // loads tile when calling back from cache
    196     private void loadTile(CacheEntry object, boolean success) throws IOException {
    197         tile.finishLoading();
    198         if (object != null) {
    199             byte[] content = object.getContent();
    200             if (content != null && content.length > 0) {
    201                 tile.loadImage(new ByteArrayInputStream(content));
    202             }
    203         }
    204         if (!success) {
    205             tile.setError("Problem loading tile");
    206         }
    207     }
    208 
    209     // loads tile when geting stright from cache
    210     private void loadTile(BufferedImageCacheEntry object) throws IOException {
    211         tile.finishLoading();
    212         if (cacheAsEmpty() || object != null) { // if cache as empty object, do not try to load image
    213             if (object.getImage() != null) {
    214                 tile.setImage(object.getImage());
    215             }
     218            return tile;
    216219        }
    217220    }
    218221