Ignore:
Timestamp:
2015-01-07T21:01:44+01:00 (9 years ago)
Author:
bastiK
Message:

applied #10920, applied #10854 - Move 'Toggle image thumbnail preview' feature to JOSM core (patch by holgermappt, modified)

File:
1 edited

Legend:

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

    r7912 r7935  
    1818import java.awt.event.MouseEvent;
    1919import java.awt.image.BufferedImage;
    20 import java.awt.datatransfer.Clipboard;
    21 import java.awt.datatransfer.StringSelection;
    22 import java.awt.Toolkit;
    2320import java.beans.PropertyChangeEvent;
    2421import java.beans.PropertyChangeListener;
     
    3835import java.util.Set;
    3936import java.util.TimeZone;
     37import java.util.concurrent.ExecutorService;
     38import java.util.concurrent.Executors;
    4039
    4140import javax.swing.Action;
     
    7877import com.drew.metadata.exif.ExifIFD0Directory;
    7978import com.drew.metadata.exif.GpsDirectory;
     79import java.util.concurrent.ThreadFactory;
    8080
    8181/**
     
    9393
    9494    boolean useThumbs = false;
     95    ExecutorService thumbusLoaderExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
     96        @Override
     97        public Thread newThread(Runnable r) {
     98            Thread t = new Thread(r);
     99            t.setPriority(Thread.MIN_PRIORITY);
     100            return t;
     101        }
     102    });
    95103    ThumbsLoader thumbsloader;
    96     boolean thumbsLoaded = false;
     104    boolean thumbsLoaderRunning = false;
     105    volatile boolean thumbsLoaded = false;
    97106    private BufferedImage offscreenBuffer;
    98107    boolean updateOffscreenBuffer = true;
     
    331340        entries.add(SeparatorLayerAction.INSTANCE);
    332341        entries.add(new CorrelateGpxWithImages(this));
     342        entries.add(new ShowThumbnailAction(this));
    333343        if (!menuAdditions.isEmpty()) {
    334344            entries.add(SeparatorLayerAction.INSTANCE);
     
    372382    public void mergeFrom(Layer from) {
    373383        GeoImageLayer l = (GeoImageLayer) from;
     384
     385        // Stop to load thumbnails on both layers.  Thumbnail loading will continue the next time
     386        // the layer is painted.
     387        stopLoadThumbs();
     388        l.stopLoadThumbs();
    374389
    375390        ImageEntry selected = null;
     
    440455        if (useThumbs) {
    441456            if (!thumbsLoaded) {
    442                 loadThumbs();
     457                startLoadThumbs();
    443458            }
    444459
     
    9891004            public void layerRemoved(Layer oldLayer) {
    9901005                if (oldLayer == GeoImageLayer.this) {
    991                     if (thumbsloader != null) {
    992                         thumbsloader.stop = true;
    993                     }
     1006                    stopLoadThumbs();
    9941007                    Main.map.mapView.removeMouseListener(mouseAdapter);
    9951008                    MapFrame.removeMapModeChangeListener(mapModeListener);
     
    10171030    }
    10181031
    1019     public void loadThumbs() {
    1020         if (useThumbs && !thumbsLoaded) {
    1021             thumbsLoaded = true;
     1032    /**
     1033     * Start to load thumbnails.
     1034     */
     1035    public synchronized void startLoadThumbs() {
     1036        if (useThumbs && !thumbsLoaded && !thumbsLoaderRunning) {
     1037            stopLoadThumbs();
    10221038            thumbsloader = new ThumbsLoader(this);
    1023             Thread t = new Thread(thumbsloader);
    1024             t.setPriority(Thread.MIN_PRIORITY);
    1025             t.start();
    1026         }
     1039            thumbusLoaderExecutor.submit(thumbsloader);
     1040            thumbsLoaderRunning = true;
     1041        }
     1042    }
     1043
     1044    /**
     1045     * Stop to load thumbnails.
     1046     *
     1047     * Can be called at any time to make sure that the
     1048     * thumbnail loader is stopped.
     1049     */
     1050    public synchronized void stopLoadThumbs() {
     1051        if (thumbsloader != null) {
     1052            thumbsloader.stop = true;
     1053        }
     1054        thumbsLoaderRunning = false;
     1055    }
     1056
     1057    /**
     1058     * Called to signal that the loading of thumbnails has finished.
     1059     *
     1060     * Usually called from {@link ThumbsLoader} in another thread.
     1061     */
     1062    public void thumbsLoaded() {
     1063        thumbsLoaded = true;
    10271064    }
    10281065
     
    10761113        this.useThumbs = useThumbs;
    10771114        if (useThumbs && !thumbsLoaded) {
    1078             loadThumbs();
     1115            startLoadThumbs();
     1116        } else if (!useThumbs) {
     1117            stopLoadThumbs();
    10791118        }
    10801119    }
Note: See TracChangeset for help on using the changeset viewer.