Changeset 12186 in osm for applications
- Timestamp:
- 2008-12-02T16:58:23+01:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerAction.java
r11974 r12186 9 9 import java.awt.event.MouseEvent; 10 10 import java.awt.event.MouseListener; 11 import java.io.BufferedReader;12 11 import java.io.File; 13 import java.io.InputStreamReader;14 12 import java.util.ArrayList; 13 import java.util.Arrays; 15 14 import java.util.Collection; 15 import java.util.Comparator; 16 16 import java.util.LinkedList; 17 17 import java.util.List; 18 import java.util.Vector;19 18 20 19 import javax.swing.JOptionPane; … … 22 21 import org.openstreetmap.josm.Main; 23 22 import org.openstreetmap.josm.actions.JosmAction; 23 import org.openstreetmap.josm.command.AddCommand; 24 import org.openstreetmap.josm.command.Command; 25 import org.openstreetmap.josm.command.SequenceCommand; 24 26 import org.openstreetmap.josm.data.coor.LatLon; 25 27 import org.openstreetmap.josm.data.osm.Node; 26 28 import org.openstreetmap.josm.data.osm.OsmPrimitive; 29 import org.openstreetmap.josm.data.osm.Way; 27 30 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 28 31 import org.openstreetmap.josm.tools.ImageProvider; 29 import org.openstreetmap.josm.data.coor.LatLon;30 import org.openstreetmap.josm.data.osm.Node;31 import org.openstreetmap.josm.data.osm.Way;32 import org.openstreetmap.josm.command.AddCommand;33 import org.openstreetmap.josm.command.Command;34 import org.openstreetmap.josm.command.SequenceCommand;35 32 import org.openstreetmap.josm.tools.Shortcut; 36 37 33 import org.xml.sax.SAXException; 38 34 … … 53 49 protected Collection<Command> commands = new LinkedList<Command>(); 54 50 protected Collection<Way> ways = new ArrayList<Way>(); 51 52 /** maximum size in bytes for the sum of all tiles in a WMS-layer cache directory. */ 53 private static final long MAXCACHESIZE = 20*1024*1024*1024; 54 55 /** maximum age in ms since epoch for tiles in a WMS-layer cache directory. */ 56 private static final long MAXCACHEAGE = 3650*24*60*60*1000; 55 57 56 58 public LakewalkerAction(String name) { … … 91 93 } 92 94 95 96 97 /** 98 * check for presence of cache folder and trim cache to specified size. 99 * size/age limit is on a per folder basis. 100 */ 101 private void cleanupCache() { 102 103 for (String wmsFolder : LakewalkerPreferences.WMSLAYERS) { 104 String wmsCacheDirName = Main.pref.getPreferencesDir()+"plugins/Lakewalker/"+wmsFolder; 105 File wmsCacheDir = new File(wmsCacheDirName); 106 107 if (wmsCacheDir.exists() && wmsCacheDir.isDirectory()) { 108 File wmsCache[] = wmsCacheDir.listFiles(); 109 110 // sort files by date (most recent first) 111 Arrays.sort(wmsCache, new Comparator<File>() { 112 public int compare(File f1, File f2) { 113 return (int)(f2.lastModified()-f1.lastModified()); 114 } 115 }); 116 117 // delete aged or oversized, keep newest. Once size/age limit was reached delete all older files 118 long folderSize = 0; 119 long timeDefiningOverage = System.currentTimeMillis()-MAXCACHEAGE; 120 boolean quickdelete = false; 121 for (File cacheEntry : wmsCache) { 122 if (!cacheEntry.isFile()) continue; 123 if (!quickdelete) { 124 folderSize += cacheEntry.length(); 125 if (folderSize > MAXCACHESIZE) { 126 quickdelete = true; 127 } else if (cacheEntry.lastModified() < timeDefiningOverage) { 128 quickdelete = true; 129 } 130 } 131 132 if (quickdelete) { 133 cacheEntry.delete(); 134 } 135 } 136 137 } else { 138 // create cache directory 139 if (!wmsCacheDir.mkdirs()) { 140 JOptionPane.showMessageDialog(Main.parent, tr("Error creating cache directory: {0}", wmsCacheDirName)); 141 } 142 } 143 } 144 } 145 93 146 protected void lakewalk(Point clickPoint){ 94 147 /** … … 120 173 PleaseWaitRunnable lakewalkerTask = new PleaseWaitRunnable(tr("Tracing")){ 121 174 @Override protected void realRun() throws SAXException { 175 setStatus(tr("checking cache...")); 176 cleanupCache(); 122 177 processnodelist(pos, topLeft, botRight, waylen,maxnode,threshold,epsilon,resolution,tilesize,startdir,wmslayer,working_dir); 123 178 } … … 192 247 Way way = new Way(); 193 248 Node n = null; 194 Node tn = null;195 249 Node fn = null; 196 250 197 251 double eastOffset = Main.pref.getDouble(LakewalkerPreferences.PREF_EAST_OFFSET, 0.0); 198 252 double northOffset = Main.pref.getDouble(LakewalkerPreferences.PREF_NORTH_OFFSET, 0.0); 199 char option = ' ';200 253 201 254 int nodesinway = 0;
Note:
See TracChangeset
for help on using the changeset viewer.