Ticket #2613: WMS Plugin use CacheFiles.patch
| File WMS Plugin use CacheFiles.patch, 7.3 KB (added by , 17 years ago) |
|---|
-
wmsplugin/src/wmsplugin/Grabber.java
2 2 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.image.BufferedImage; 6 import java.awt.Graphics; 7 import java.awt.Color; 8 import java.awt.Font; 9 5 10 import org.openstreetmap.josm.data.Bounds; 6 11 import org.openstreetmap.josm.data.projection.Projection; 7 12 import org.openstreetmap.josm.gui.MapView; 8 13 import 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;14 14 import org.openstreetmap.josm.data.coor.LatLon; 15 import org.openstreetmap.josm.io.CacheFiles; 15 16 16 17 abstract public class Grabber implements Runnable { 17 18 protected Bounds b; … … 20 21 protected MapView mv; 21 22 protected WMSLayer layer; 22 23 protected GeorefImage image; 24 protected CacheFiles cache; 23 25 24 26 Grabber(Bounds b, Projection proj, double pixelPerDegree, GeorefImage image, 25 MapView mv, WMSLayer layer )27 MapView mv, WMSLayer layer, CacheFiles cache) 26 28 { 27 29 if (b.min != null && b.max != null && WMSPlugin.doOverlap) 28 30 { … … 48 50 this.image = image; 49 51 this.mv = mv; 50 52 this.layer = layer; 53 this.cache = cache; 51 54 } 52 55 53 56 abstract void fetch() throws Exception; // the image fetch code -
wmsplugin/src/wmsplugin/WMSGrabber.java
27 27 import org.openstreetmap.josm.data.Bounds; 28 28 import org.openstreetmap.josm.data.projection.Projection; 29 29 import org.openstreetmap.josm.gui.MapView; 30 import org.openstreetmap.josm.io.CacheFiles; 30 31 import org.openstreetmap.josm.io.ProgressInputStream; 31 32 32 33 33 34 public class WMSGrabber extends Grabber { 34 35 protected String baseURL; 35 protected Cache cache = new wmsplugin.Cache();36 36 private static Boolean shownWarning = false; 37 37 private boolean urlWithPatterns; 38 38 39 39 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); 42 42 this.baseURL = baseURL; 43 43 /* URL containing placeholders? */ 44 44 urlWithPatterns = baseURL != null && baseURL.contains("{1}"); … … 146 146 BufferedImage img = ImageIO.read(is); 147 147 is.close(); 148 148 149 return cache.saveImg(url.toString(), img, true); 149 cache.saveImg(url.toString(), img); 150 return img; 150 151 } 151 152 152 153 protected String readException(URLConnection conn) throws IOException { -
wmsplugin/src/wmsplugin/WMSLayer.java
254 254 public void actionPerformed(ActionEvent ev) { 255 255 // Delete small files, because they're probably blank tiles. 256 256 // See https://josm.openstreetmap.de/ticket/2307 257 new wmsplugin.Cache().deleteSmallFiles(2048);257 WMSPlugin.cache.customCleanUp(WMSPlugin.cache.CLEAN_SMALL_FILES, 2048); 258 258 259 259 for (int x = 0; x < dax; ++x) { 260 260 for (int y = 0; y < day; ++y) { -
wmsplugin/src/wmsplugin/WMSPlugin.java
23 23 import org.openstreetmap.josm.gui.MapFrame; 24 24 import org.openstreetmap.josm.gui.IconToggleButton; 25 25 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 26 import org.openstreetmap.josm.io.CacheFiles; 26 27 import org.openstreetmap.josm.io.MirroredInputStream; 27 28 import org.openstreetmap.josm.actions.JosmAction; 28 29 import org.openstreetmap.josm.data.Bounds; … … 30 31 import org.openstreetmap.josm.gui.MapView; 31 32 32 33 public class WMSPlugin extends Plugin { 34 static CacheFiles cache = new CacheFiles("wmsplugin"); 33 35 34 36 WMSLayer wmsLayer; 35 37 static JMenu wmsJMenu; … … 53 55 e.printStackTrace(); 54 56 } 55 57 refreshMenu(); 58 cache.setExpire(cache.EXPIRE_MONTHLY, false); 59 cache.setMaxSize(70, false); 56 60 } 57 61 58 62 // this parses the preferences settings. preferences for the wms plugin have to … … 198 202 public static Grabber getGrabber(String _baseURL, Bounds _b, Projection _proj, 199 203 double _pixelPerDegree, GeorefImage _image, MapView _mv, WMSLayer _layer){ 200 204 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); 202 206 else 203 return new WMSGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer );207 return new WMSGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer, cache); 204 208 // OSBGrabber should be rewrite for thread support first 205 209 //if (wmsurl.matches("(?i).*layers=npeoocmap.*") || wmsurl.matches("(?i).*layers=npe.*") ){ 206 210 // return new OSGBGrabber(_b, _proj, _pixelPerDegree, _images, _mv, _layer); -
wmsplugin/src/wmsplugin/YAHOOGrabber.java
15 15 import org.openstreetmap.josm.Main; 16 16 import org.openstreetmap.josm.data.Bounds; 17 17 import org.openstreetmap.josm.data.projection.Projection; 18 import org.openstreetmap.josm.io.CacheFiles; 18 19 import org.openstreetmap.josm.gui.MapView; 19 20 20 21 21 public class YAHOOGrabber extends WMSGrabber {22 public class YAHOOGrabber extends WMSGrabber { 22 23 protected String browserCmd; 23 protected Cache cache = new wmsplugin.Cache();24 24 25 25 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) { 27 27 super("file:///" + WMSPlugin.getPrefsPath() + "ymap.html?" 28 , b, proj, pixelPerDegree, image, mv, layer );28 , b, proj, pixelPerDegree, image, mv, layer, cache); 29 29 this.browserCmd = baseURL.replaceFirst("yahoo://", ""); 30 30 } 31 31 … … 52 52 } catch(IOException ioe) { 53 53 throw new IOException( "Could not start browser. Please check that the executable path is correct.\n" + ioe.getMessage() ); 54 54 } 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; 57 59 } 58 60 }
