Example #1
0
 public BufferedImage getTileImage(int x, int y) throws IOException {
   SRCachedTile cachedTile = cache.get(new CacheKey(x, y));
   BufferedImage image = null;
   if (cachedTile != null) {
     CachedTile tile = cachedTile.get();
     if (tile != null) {
       if (tile.loaded) log.trace(String.format("Cache hit: x=%d y=%d", x, y));
       image = tile.getImage();
       if (!tile.nextLoadJobCreated) {
         // log.debug(String.format("Preload job added : x=%d y=%d l=%d",
         // x + 1, y, layer));
         preloadTile(new CachedTile(new CacheKey(x + 1, y)));
         tile.nextLoadJobCreated = true;
       }
     }
   }
   if (image == null) {
     log.trace(String.format("Cache miss: x=%d y=%d", x, y));
     // log.debug(String.format("Preload job added : x=%d y=%d l=%d", x +
     // 1, y, layer));
     preloadTile(new CachedTile(new CacheKey(x + 1, y)));
     image = internalGetTileImage(x, y);
   }
   return image;
 }
Example #2
0
 @Override
 public void run() {
   CachedTile tile;
   try {
     while (true) {
       tile = queue.take();
       if (tile != null && !tile.loaded) {
         // log.trace("Loading image async: " + tile);
         tile.loadImage();
       }
     }
   } catch (InterruptedException e) {
     log.debug("Image pre-loader thread terminated");
   }
 }