Changeset 10683 in osm for applications/editors


Ignore:
Timestamp:
2008-09-14T14:45:39+02:00 (16 years ago)
Author:
petrdlouhy
Message:

added thread pool

Location:
applications/editors/josm/plugins/wmsplugin/src/wmsplugin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/Grabber.java

    r10382 r10683  
    11package wmsplugin;
    2 import java.io.IOException;
    3 import org.openstreetmap.josm.data.Bounds;
    4 import org.openstreetmap.josm.data.projection.Projection;
    5 import java.util.ArrayList;
    6 import org.openstreetmap.josm.gui.MapView;
    72
    8 public interface Grabber {
    9         public void start();
     3public interface Grabber extends Runnable {
     4       
    105}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSGrabber.java

    r10382 r10683  
    2424
    2525
    26 public class WMSGrabber extends Thread implements Grabber{
     26public class WMSGrabber implements Grabber {
    2727        protected String baseURL;
    2828
     
    4343                mv = _mv;
    4444                layer = _layer;
    45                 this.setDaemon(true);
    46                 this.setPriority(Thread.MIN_PRIORITY);
    4745        }
    4846
     
    9290
    9391        protected BufferedImage grab(URL url) throws IOException {
    94                         InputStream is = new ProgressInputStream(
    95                                 url.openConnection(), null);
    96                         BufferedImage img;
    97                 synchronized (layer){ //download only one tile in one moment
    98                         if(!image.isVisible(mv)){
    99                                 return null;
    100                         }
    101                         img = ImageIO.read(is);
    102                 }
    103                         is.close();
    104                         return img;
     92                InputStream is = new ProgressInputStream(
     93                        url.openConnection(), null);
     94                if(!image.isVisible(mv))
     95                        return null;
     96                BufferedImage img = ImageIO.read(is);
     97                is.close();
     98                return img;
    10599        }
    106100}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java

    r10646 r10683  
    3636import org.openstreetmap.josm.gui.MapView;
    3737import java.util.ArrayList;
     38import java.util.concurrent.ExecutorService;
     39import java.util.concurrent.Executors;
     40
    3841import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    3942import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
     
    6366        protected String baseURL;
    6467        protected final int serializeFormatVersion = 3;
     68       
     69        private ExecutorService executor;
    6570
    6671        public WMSLayer() {
     
    7378                initializeImages();
    7479                this.baseURL = baseURL;
     80               
     81                executor = Executors.newFixedThreadPool(3);
    7582        }
    7683
     
    147154                                                img.image = null;
    148155                                                Grabber gr = WMSPlugin.getGrabber(baseURL, XYtoBounds(x,y), Main.main.proj, pixelPerDegree, img, mv, this);
    149                                                 gr.start();
     156                                                executor.submit(gr);
    150157                                }
    151158                        }
     
    160167                for(int x = 0; x<dax; ++x)
    161168                        for(int y = 0; y<day; ++y)
    162                                         if(images[x][y]!=null){
    163                                                 v.visit(images[x][y].min);
    164                                                 v.visit(images[x][y].max);
    165                                         }
     169                                if(images[x][y]!=null){
     170                                        v.visit(images[x][y].min);
     171                                        v.visit(images[x][y].max);
     172                                }
    166173        }
    167174
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/YAHOOGrabber.java

    r10382 r10683  
    3434
    3535
    36 public class YAHOOGrabber extends Thread implements Grabber{
     36public class YAHOOGrabber implements Grabber{
    3737        protected String baseURL;
    3838        protected String browserCmd;
     
    5656                this.mv = _mv;
    5757                this.layer = _layer;
    58                 this.setDaemon(true);
    59                 this.setPriority(Thread.MIN_PRIORITY);
    6058        }
    6159
     
    7472                                image.min = proj.latlon2eastNorth(b.min);
    7573                                image.max = proj.latlon2eastNorth(b.max);
    76                                 synchronized (layer) {
    77                                         if(!image.isVisible(mv)){
    78                                                 image.downloadingStarted = false;
    79                                                 return;
    80                                         }
    81                                         Process browser = browse(url.toString());;
    82                                         image.image =  new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    83                                         img = ImageIO.read(browser.getInputStream()).getScaledInstance(width, height, Image.SCALE_FAST);
     74                                if(!image.isVisible(mv)){ //don't download, if the image isn't visible already
     75                                        image.downloadingStarted = false;
     76                                        return;
    8477                                }
     78                                Process browser = browse(url.toString());;
     79                                image.image =  new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
     80                                img = ImageIO.read(browser.getInputStream()).getScaledInstance(width, height, Image.SCALE_FAST);
    8581                                image.image.getGraphics().drawImage(img, 0 , 0, null);
    8682
Note: See TracChangeset for help on using the changeset viewer.