Ticket #2310: wms.patch
File wms.patch, 4.5 KB (added by , 16 years ago) |
---|
-
wmsplugin/src/wmsplugin/Cache.java
7 7 import java.security.MessageDigest; 8 8 import java.util.Date; 9 9 import java.util.Iterator; 10 import java.util.Random; 10 11 import java.util.Set; 11 12 import java.util.TreeMap; 12 13 import javax.imageio.*; … … 23 24 private boolean disabled = false; 24 25 // If the cache is full, we don't want to delete just one file 25 26 private final int cleanUpThreshold = 20; 27 // After how many file-writes do we want to check if the cache needs emptying? 28 private final int cleanUpInterval = 5; 26 29 27 30 Cache() { 28 31 this(Main.pref.get("wmsplugin.cache.path", WMSPlugin.getPrefsPath() + "cache")); … … 72 75 System.out.println(e.getMessage()); 73 76 } 74 77 75 // Clean up must be called manually78 checkCleanUp(); 76 79 } 77 80 78 81 public BufferedImage saveImg(String ident, BufferedImage image, boolean passThrough) { … … 80 83 return image; 81 84 } 82 85 86 public void checkCleanUp() { 87 // The Cache class isn't persistent in its current implementation, 88 // therefore clean up on random intervals, but not every write 89 if(new Random().nextInt(cleanUpInterval) == 0) 90 cleanUp(); 91 } 92 83 93 public void cleanUp() { 84 94 if(disabled) return; 85 95 … … 111 121 } 112 122 } 113 123 124 public void deleteSmallFiles(int size) { 125 if(disabled) return; 126 for(File f : getFiles()) { 127 if(f.length() < size) 128 f.delete(); 129 } 130 } 131 114 132 private long getDirSize() { 133 if(disabled) return -1; 115 134 long dirsize = 0; 116 135 117 136 for(File f : getFiles()) … … 120 139 } 121 140 122 141 private File[] getFiles() { 142 if(disabled) return null; 123 143 return dir.listFiles( 124 144 new FileFilter() { 125 145 public boolean accept(File file) { -
wmsplugin/src/wmsplugin/WMSLayer.java
79 79 WMSGrabber.getProjection(baseURL, true); 80 80 mv = Main.map.mapView; 81 81 getPPD(); 82 82 83 83 executor = Executors.newFixedThreadPool(3); 84 84 } 85 85 86 86 public void destroy() { 87 try { 88 executor.shutdown(); 87 try { 88 executor.shutdown(); 89 89 // Might not be initalized, so catch NullPointer as well 90 90 } catch(Exception x) {} 91 91 } … … 171 171 JOptionPane.showMessageDialog(Main.parent, tr("The requested area is too big. Please zoom in a little, or change resolution")); 172 172 return; 173 173 } 174 174 175 175 for(int x = bminx; x<bmaxx; ++x) 176 176 for(int y = bminy; y<bmaxy; ++y){ 177 177 GeorefImage img = images[modulo(x,dax)][modulo(y,day)]; … … 183 183 executor.submit(gr); 184 184 } 185 185 } 186 187 new wmsplugin.Cache().cleanUp();188 186 } 189 187 190 188 @Override public void visitBoundingBox(BoundingXYVisitor v) { … … 247 245 mv.repaint(); 248 246 } 249 247 } 250 248 251 249 public class reloadErrorTilesAction extends AbstractAction { 252 250 public reloadErrorTilesAction() { 253 251 super(tr("Reload erroneous tiles")); 254 252 } 255 253 public void actionPerformed(ActionEvent ev) { 254 // Delete small files, because they're probably blank tiles. 255 // See https://josm.openstreetmap.de/ticket/2307 256 new wmsplugin.Cache().deleteSmallFiles(2048); 257 256 258 for (int x = 0; x < dax; ++x) { 257 259 for (int y = 0; y < day; ++y) { 258 260 GeorefImage img = images[modulo(x,dax)][modulo(y,day)]; … … 265 267 } 266 268 } 267 269 } 268 270 269 271 public class ToggleAlphaAction extends AbstractAction { 270 272 public ToggleAlphaAction() { 271 273 super(tr("Alpha channel")); … … 274 276 JCheckBoxMenuItem checkbox = (JCheckBoxMenuItem) ev.getSource(); 275 277 boolean alphaChannel = checkbox.isSelected(); 276 278 Main.pref.put("wmsplugin.alpha_channel", alphaChannel); 277 279 278 280 // clear all resized cached instances and repaint the layer 279 281 for (int x = 0; x < dax; ++x) { 280 282 for (int y = 0; y < day; ++y) {