Changeset 24989 in osm
- Timestamp:
- 2011-01-07T15:29:33+01:00 (14 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Demo.java
r18772 r24989 8 8 import java.awt.event.ItemEvent; 9 9 import java.awt.event.ItemListener; 10 import java.io.IOException; 10 11 11 12 import javax.swing.JButton; … … 61 62 } 62 63 }); 63 JComboBox tileLoaderSelector = new JComboBox(new TileLoader[] { new OsmFileCacheTileLoader(map), 64 new OsmTileLoader(map) }); 64 JComboBox tileLoaderSelector; 65 try { 66 tileLoaderSelector = new JComboBox(new TileLoader[] { new OsmFileCacheTileLoader(map), 67 new OsmTileLoader(map) }); 68 } catch (IOException e) { 69 tileLoaderSelector = new JComboBox(new TileLoader[] { new OsmTileLoader(map) }); 70 } 65 71 tileLoaderSelector.addItemListener(new ItemListener() { 66 72 public void itemStateChanged(ItemEvent e) { -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java
r24985 r24989 54 54 protected long recheckAfter = FILE_AGE_ONE_DAY; 55 55 56 /** 57 * Create a OSMFileCacheTileLoader with given cache directory. 58 * If cacheDir is <code>null</code> the system property temp dir 59 * is used. If not set an IOException will be thrown. 60 * @param map 61 * @param cacheDir 62 */ 63 public OsmFileCacheTileLoader(TileLoaderListener map, File cacheDir) throws SecurityException { 64 super(map); 56 public static File getDefaultCacheDir() throws SecurityException { 65 57 String tempDir = null; 66 58 String userName = System.getProperty("user.name"); … … 74 66 } 75 67 try { 76 if (cacheDir == null) { 77 if (tempDir == null) 78 throw new IOException("No temp directory set"); 79 String subDirName = "JMapViewerTiles"; 80 // On Linux/Unix systems we do not have a per user tmp directory. 81 // Therefore we add the user name for getting a unique dir name. 82 if (userName != null && userName.length() > 0) { 83 subDirName += "_" + userName; 84 } 85 cacheDir = new File(tempDir, subDirName); 86 } 87 log.finest("Tile cache directory: " + cacheDir); 88 if (!cacheDir.exists() && !cacheDir.mkdirs()) 89 throw new IOException(); 90 cacheDirBase = cacheDir.getAbsolutePath(); 68 if (tempDir == null) 69 throw new IOException("No temp directory set"); 70 String subDirName = "JMapViewerTiles"; 71 // On Linux/Unix systems we do not have a per user tmp directory. 72 // Therefore we add the user name for getting a unique dir name. 73 if (userName != null && userName.length() > 0) { 74 subDirName += "_" + userName; 75 } 76 File cacheDir = new File(tempDir, subDirName); 77 return cacheDir; 91 78 } catch (Exception e) { 92 cacheDirBase = "tiles"; 93 } 79 } 80 return null; 81 } 82 83 /** 84 * Create a OSMFileCacheTileLoader with given cache directory. 85 * If cacheDir is not set or invalid, IOException will be thrown. 86 * @param map 87 * @param cacheDir 88 */ 89 public OsmFileCacheTileLoader(TileLoaderListener map, File cacheDir) throws IOException { 90 super(map); 91 if (cacheDir == null || (!cacheDir.exists() && !cacheDir.mkdirs())) 92 throw new IOException("Cannot access cache directory"); 93 94 log.finest("Tile cache directory: " + cacheDir); 95 cacheDirBase = cacheDir.getAbsolutePath(); 94 96 } 95 97 … … 99 101 * @param map 100 102 */ 101 public OsmFileCacheTileLoader(TileLoaderListener map) throws SecurityException {102 this(map, null);103 public OsmFileCacheTileLoader(TileLoaderListener map) throws SecurityException, IOException { 104 this(map, getDefaultCacheDir()); 103 105 } 104 106
Note:
See TracChangeset
for help on using the changeset viewer.