Changeset 9277 in josm for trunk/src/org


Ignore:
Timestamp:
2016-01-03T14:37:56+01:00 (4 years ago)
Author:
simon04
Message:

see #12255 - Add ImageEntry#loadThumbnail (based on patch by holgermappt)

Location:
trunk/src/org/openstreetmap/josm/gui/layer/geoimage
Files:
2 edited

Legend:

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

    r9270 r9277  
    77import java.text.ParseException;
    88import java.util.Calendar;
     9import java.util.Collections;
    910import java.util.Date;
    1011import java.util.GregorianCalendar;
     
    220221    public void setThumbnail(Image thumbnail) {
    221222        this.thumbnail = thumbnail;
     223    }
     224
     225    /**
     226     * Loads the thumbnail if it was not loaded yet.
     227     * @see ThumbsLoader
     228     */
     229    public void loadThumbnail() {
     230        if (thumbnail == null) {
     231            new ThumbsLoader(Collections.singleton(this)).run();
     232        }
    222233    }
    223234
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ThumbsLoader.java

    r9270 r9277  
    1313import java.io.IOException;
    1414import java.util.ArrayList;
    15 import java.util.List;
     15import java.util.Collection;
    1616
    1717import javax.imageio.ImageIO;
     
    2727    public static final int minSize = 22;
    2828    public volatile boolean stop;
    29     private final List<ImageEntry> data;
     29    private final Collection<ImageEntry> data;
    3030    private final GeoImageLayer layer;
    3131    private MediaTracker tracker;
    3232    private ICacheAccess<String, BufferedImageCacheEntry> cache;
    3333    private final boolean cacheOff = Main.pref.getBoolean("geoimage.noThumbnailCache", false);
     34
     35    private ThumbsLoader(Collection<ImageEntry> data, GeoImageLayer layer) {
     36        this.data = data;
     37        this.layer = layer;
     38        initCache();
     39    }
    3440
    3541    /**
     
    3844     */
    3945    public ThumbsLoader(GeoImageLayer layer) {
    40         this.layer = layer;
    41         this.data = new ArrayList<>(layer.data);
    42         initCache();
     46        this(new ArrayList<>(layer.data), layer);
     47    }
     48
     49    /**
     50     * Constructs a new thumbnail loader that operates on the image entries
     51     * @param entries image entries
     52     */
     53    public ThumbsLoader(Collection<ImageEntry> entries) {
     54        this(entries, null);
    4355    }
    4456
     
    6981                entry.setThumbnail(loadThumb(entry));
    7082
    71                 if (Main.isDisplayingMapView()) {
     83                if (layer != null && Main.isDisplayingMapView()) {
    7284                    layer.updateOffscreenBuffer = true;
    7385                    Main.map.mapView.repaint();
     
    7587            }
    7688        }
    77         layer.thumbsLoaded();
    78         layer.updateOffscreenBuffer = true;
    79         Main.map.mapView.repaint();
     89        if (layer != null) {
     90            layer.thumbsLoaded();
     91            layer.updateOffscreenBuffer = true;
     92            Main.map.mapView.repaint();
     93        }
    8094    }
    8195
Note: See TracChangeset for help on using the changeset viewer.