Changeset 7935 in josm


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

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

Location:
trunk
Files:
2 added
4 edited

Legend:

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

    r7817 r7935  
    728728
    729729                    yLayer.useThumbs = cbShowThumbs.isSelected();
    730                     yLayer.loadThumbs();
     730                    yLayer.startLoadThumbs();
    731731
    732732                    // Search whether an other layer has yet defined some bounding box.
  • 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    }
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ThumbsLoader.java

    r7784 r7935  
    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;
    2020    List<ImageEntry> data;
    2121    GeoImageLayer layer;
     
    5151            }
    5252        }
     53        layer.thumbsLoaded();
    5354        layer.updateOffscreenBuffer = true;
    5455        Main.map.mapView.repaint();
  • trunk/src/org/openstreetmap/josm/gui/progress/ProgressMonitorExecutor.java

    r4718 r7935  
    88import org.openstreetmap.josm.Main;
    99
     10/**
     11 * Executor that displays the progress monitor to the user.
     12 *
     13 * Similar to Executors.newSingleThreadExecutor(), but displays the
     14 * progress monitor whenever a new task is executed.
     15 */
    1016public class ProgressMonitorExecutor extends ThreadPoolExecutor {
    1117
Note: See TracChangeset for help on using the changeset viewer.