Ticket #2613: WMS Plugin use CacheFiles.patch

File WMS Plugin use CacheFiles.patch, 7.3 KB (added by xeen, 17 years ago)
  • wmsplugin/src/wmsplugin/Grabber.java

     
    22
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
     5import java.awt.image.BufferedImage;
     6import java.awt.Graphics;
     7import java.awt.Color;
     8import java.awt.Font;
     9
    510import org.openstreetmap.josm.data.Bounds;
    611import org.openstreetmap.josm.data.projection.Projection;
    712import org.openstreetmap.josm.gui.MapView;
    813import org.openstreetmap.josm.Main;
    9 import java.awt.image.BufferedImage;
    10 import java.awt.Graphics;
    11 import java.awt.Color;
    12 import java.awt.Font;
    13 import javax.swing.JOptionPane;
    1414import org.openstreetmap.josm.data.coor.LatLon;
     15import org.openstreetmap.josm.io.CacheFiles;
    1516
    1617abstract public class Grabber implements Runnable {
    1718    protected Bounds b;
     
    2021    protected MapView mv;
    2122    protected WMSLayer layer;
    2223    protected GeorefImage image;
     24    protected CacheFiles cache;
    2325
    2426    Grabber(Bounds b, Projection proj, double pixelPerDegree, GeorefImage image,
    25     MapView mv, WMSLayer layer)
     27    MapView mv, WMSLayer layer, CacheFiles cache)
    2628    {
    2729        if (b.min != null && b.max != null && WMSPlugin.doOverlap)
    2830        {
     
    4850        this.image = image;
    4951        this.mv = mv;
    5052        this.layer = layer;
     53        this.cache = cache;
    5154    }
    5255
    5356    abstract void fetch() throws Exception; // the image fetch code
  • wmsplugin/src/wmsplugin/WMSGrabber.java

     
    2727import org.openstreetmap.josm.data.Bounds;
    2828import org.openstreetmap.josm.data.projection.Projection;
    2929import org.openstreetmap.josm.gui.MapView;
     30import org.openstreetmap.josm.io.CacheFiles;
    3031import org.openstreetmap.josm.io.ProgressInputStream;
    3132
    3233
    3334public class WMSGrabber extends Grabber {
    3435    protected String baseURL;
    35     protected Cache cache = new wmsplugin.Cache();
    3636    private static Boolean shownWarning = false;
    3737    private boolean urlWithPatterns;
    3838
    3939    WMSGrabber(String baseURL, Bounds b, Projection proj,
    40             double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer) {
    41         super(b, proj, pixelPerDegree, image, mv, layer);
     40            double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) {
     41        super(b, proj, pixelPerDegree, image, mv, layer, cache);
    4242        this.baseURL = baseURL;
    4343        /* URL containing placeholders? */
    4444        urlWithPatterns = baseURL != null && baseURL.contains("{1}");
     
    146146        BufferedImage img = ImageIO.read(is);
    147147        is.close();
    148148       
    149         return cache.saveImg(url.toString(), img, true);
     149        cache.saveImg(url.toString(), img);
     150        return img;
    150151    }
    151152
    152153    protected String readException(URLConnection conn) throws IOException {
  • wmsplugin/src/wmsplugin/WMSLayer.java

     
    254254        public void actionPerformed(ActionEvent ev) {
    255255            // Delete small files, because they're probably blank tiles.
    256256            // See https://josm.openstreetmap.de/ticket/2307
    257             new wmsplugin.Cache().deleteSmallFiles(2048);
     257            WMSPlugin.cache.customCleanUp(WMSPlugin.cache.CLEAN_SMALL_FILES, 2048);
    258258
    259259            for (int x = 0; x < dax; ++x) {
    260260                for (int y = 0; y < day; ++y) {
  • wmsplugin/src/wmsplugin/WMSPlugin.java

     
    2323import org.openstreetmap.josm.gui.MapFrame;
    2424import org.openstreetmap.josm.gui.IconToggleButton;
    2525import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
     26import org.openstreetmap.josm.io.CacheFiles;
    2627import org.openstreetmap.josm.io.MirroredInputStream;
    2728import org.openstreetmap.josm.actions.JosmAction;
    2829import org.openstreetmap.josm.data.Bounds;
     
    3031import org.openstreetmap.josm.gui.MapView;
    3132
    3233public class WMSPlugin extends Plugin {
     34    static CacheFiles cache = new CacheFiles("wmsplugin");
    3335
    3436    WMSLayer wmsLayer;
    3537    static JMenu wmsJMenu;
     
    5355            e.printStackTrace();
    5456        }
    5557        refreshMenu();
     58        cache.setExpire(cache.EXPIRE_MONTHLY, false);
     59        cache.setMaxSize(70, false);
    5660    }
    5761
    5862    // this parses the preferences settings. preferences for the wms plugin have to
     
    198202    public static Grabber getGrabber(String _baseURL, Bounds _b, Projection _proj,
    199203                     double _pixelPerDegree, GeorefImage _image, MapView _mv, WMSLayer _layer){
    200204        if(_baseURL.startsWith("yahoo://"))
    201             return new YAHOOGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer);
     205            return new YAHOOGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer, cache);
    202206        else
    203             return new WMSGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer);
     207            return new WMSGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer, cache);
    204208        // OSBGrabber should be rewrite for thread support first
    205209        //if (wmsurl.matches("(?i).*layers=npeoocmap.*") || wmsurl.matches("(?i).*layers=npe.*") ){
    206210        //  return new OSGBGrabber(_b, _proj, _pixelPerDegree,  _images, _mv, _layer);
  • wmsplugin/src/wmsplugin/YAHOOGrabber.java

     
    1515import org.openstreetmap.josm.Main;
    1616import org.openstreetmap.josm.data.Bounds;
    1717import org.openstreetmap.josm.data.projection.Projection;
     18import org.openstreetmap.josm.io.CacheFiles;
    1819import org.openstreetmap.josm.gui.MapView;
    1920
    2021
    21 public class YAHOOGrabber extends WMSGrabber{
     22public class YAHOOGrabber extends WMSGrabber {
    2223    protected String browserCmd;
    23     protected Cache cache = new wmsplugin.Cache();
    2424
    2525    YAHOOGrabber(String baseURL, Bounds b, Projection proj,
    26             double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer) {
     26            double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) {
    2727        super("file:///" + WMSPlugin.getPrefsPath() + "ymap.html?"
    28         , b, proj, pixelPerDegree, image, mv, layer);
     28        , b, proj, pixelPerDegree, image, mv, layer, cache);
    2929        this.browserCmd = baseURL.replaceFirst("yahoo://", "");
    3030    }
    3131
     
    5252        } catch(IOException ioe) {
    5353            throw new IOException( "Could not start browser. Please check that the executable path is correct.\n" + ioe.getMessage() );
    5454        }
    55 
    56         return cache.saveImg(urlstring, ImageIO.read(browser.getInputStream()), true);
     55       
     56        BufferedImage img = ImageIO.read(browser.getInputStream());
     57        cache.saveImg(urlstring, img);
     58        return img;
    5759    }
    5860}