source: osm/applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/TileController.java@ 31540

Last change on this file since 31540 was 31540, checked in by wiktorn, 9 years ago

Remove org.openstreetmap.gui.jmapviewer.JobDispatcher as it is not use anymore. Addresses: #josm11840

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/plain
File size: 2.5 KB
Line 
1// License: GPL. For details, see Readme.txt file.
2package org.openstreetmap.gui.jmapviewer;
3
4import org.openstreetmap.gui.jmapviewer.interfaces.TileCache;
5import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
6import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener;
7import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
8
9public class TileController {
10 protected TileLoader tileLoader;
11 protected TileCache tileCache;
12 protected TileSource tileSource;
13
14 public TileController(TileSource source, TileCache tileCache, TileLoaderListener listener) {
15 this.tileSource = source;
16 this.tileLoader = new OsmTileLoader(listener);
17 this.tileCache = tileCache;
18 }
19
20 /**
21 * retrieves a tile from the cache. If the tile is not present in the cache
22 * a load job is added to the working queue of {@link JobThread}.
23 *
24 * @param tilex the X position of the tile
25 * @param tiley the Y position of the tile
26 * @param zoom the zoom level of the tile
27 * @return specified tile from the cache or <code>null</code> if the tile
28 * was not found in the cache.
29 */
30 public Tile getTile(int tilex, int tiley, int zoom) {
31 int max = 1 << zoom;
32 if (tilex < 0 || tilex >= max || tiley < 0 || tiley >= max)
33 return null;
34 Tile tile = tileCache.getTile(tileSource, tilex, tiley, zoom);
35 if (tile == null) {
36 tile = new Tile(tileSource, tilex, tiley, zoom);
37 tileCache.addTile(tile);
38 tile.loadPlaceholderFromCache(tileCache);
39 }
40 if (tile.error) {
41 tile.loadPlaceholderFromCache(tileCache);
42 }
43 if (!tile.isLoaded()) {
44 tileLoader.createTileLoaderJob(tile).submit();
45 }
46 return tile;
47 }
48
49 public TileCache getTileCache() {
50 return tileCache;
51 }
52
53 public void setTileCache(TileCache tileCache) {
54 this.tileCache = tileCache;
55 }
56
57 public TileLoader getTileLoader() {
58 return tileLoader;
59 }
60
61 public void setTileLoader(TileLoader tileLoader) {
62 this.tileLoader = tileLoader;
63 }
64
65 public TileSource getTileLayerSource() {
66 return tileSource;
67 }
68
69 public TileSource getTileSource() {
70 return tileSource;
71 }
72
73 public void setTileSource(TileSource tileSource) {
74 this.tileSource = tileSource;
75 }
76
77 /**
78 * Removes all jobs from the queue that are currently not being processed.
79 *
80 */
81 public void cancelOutstandingJobs() {
82 tileLoader.cancelOutstandingTasks();
83 }
84}
Note: See TracBrowser for help on using the repository browser.