Ignore:
Timestamp:
2016-02-23T20:39:21+01:00 (8 years ago)
Author:
wiktorn
Message:

Tile Source class as a Generic Type to AbstractTileSourceLayer

Provide tile source class as a Generic Type to AbstractTileSourceLayer to reduce
the number of necessary casts.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r9826 r9860  
    9595 * @author Upliner
    9696 * @author Wiktor Niesiobędzki
     97 * @param <T> Tile Source class used for this layer
    9798 * @since 3715
    9899 * @since 8526 (copied from TMSLayer)
    99100 */
    100 public abstract class AbstractTileSourceLayer extends ImageryLayer implements ImageObserver, TileLoaderListener, ZoomChangeListener {
     101public abstract class AbstractTileSourceLayer<T extends AbstractTMSTileSource> extends ImageryLayer implements ImageObserver, TileLoaderListener, ZoomChangeListener {
    101102    private static final String PREFERENCE_PREFIX = "imagery.generic";
    102103
     
    151152     */
    152153    protected TileCache tileCache; // initialized together with tileSource
    153     protected AbstractTMSTileSource tileSource;
     154    protected T tileSource;
    154155    protected TileLoader tileLoader;
    155156
     
    173174     * @throws IllegalArgumentException when Imagery is not supported by layer
    174175     */
    175     protected abstract AbstractTMSTileSource getTileSource(ImageryInfo info);
    176 
    177     protected Map<String, String> getHeaders(TileSource tileSource) {
     176    protected abstract T getTileSource(ImageryInfo info);
     177
     178    protected Map<String, String> getHeaders(T tileSource) {
    178179        if (tileSource instanceof TemplatedTileSource) {
    179180            return ((TemplatedTileSource) tileSource).getHeaders();
     
    182183    }
    183184
    184     protected void initTileSource(AbstractTMSTileSource tileSource) {
     185    protected void initTileSource(T tileSource) {
    185186        attribution.initialize(tileSource);
    186187
     
    11801181
    11811182    private final TileSet nullTileSet = new TileSet((LatLon) null, (LatLon) null, 0);
     1183
    11821184    private final class TileSet {
    11831185        int x0, x1, y0, y1;
     
    13491351    }
    13501352
    1351     private static TileSetInfo getTileSetInfo(TileSet ts) {
     1353    private static <S extends AbstractTMSTileSource> TileSetInfo getTileSetInfo(AbstractTileSourceLayer<S>.TileSet ts) {
    13521354        List<Tile> allTiles = ts.allExistingTiles();
    13531355        TileSetInfo result = new TileSetInfo();
     
    13741376        private final TileSet[] tileSets;
    13751377        private final TileSetInfo[] tileSetInfos;
     1378
     1379        @SuppressWarnings("unchecked")
    13761380        DeepTileSet(EastNorth topLeft, EastNorth botRight, int minZoom, int maxZoom) {
    13771381            this.topLeft = topLeft;
     
    13791383            this.minZoom = minZoom;
    13801384            this.maxZoom = maxZoom;
    1381             this.tileSets = new TileSet[maxZoom - minZoom + 1];
     1385            this.tileSets = new AbstractTileSourceLayer.TileSet[maxZoom - minZoom + 1];
    13821386            this.tileSetInfos = new TileSetInfo[maxZoom - minZoom + 1];
    13831387        }
     
    17421746     * To prevent accidental clear of the queue, new download executor is created with separate queue
    17431747     *
    1744      * @param precacheTask Task responsible for precaching imagery
     1748     * @param progressMonitor Task responsible for precaching imagery
    17451749     * @param points lat/lon coordinates to download
    17461750     * @param bufferX how many units in current Coordinate Reference System to cover in X axis in both sides
    17471751     * @param bufferY how many units in current Coordinate Reference System to cover in Y axis in both sides
    1748      */
    1749     public void downloadAreaToCache(final PrecacheTask precacheTask, List<LatLon> points, double bufferX, double bufferY) {
     1752     * @return
     1753     */
     1754    public AbstractTileSourceLayer<T>.PrecacheTask downloadAreaToCache(final ProgressMonitor progressMonitor, List<LatLon> points, double bufferX, double bufferY) {
     1755        PrecacheTask precacheTask = new PrecacheTask(progressMonitor);
    17501756        final Set<Tile> requestedTiles = new ConcurrentSkipListSet<>(new Comparator<Tile>() {
    17511757            @Override
     
    17801786            loader.createTileLoaderJob(t).submit();
    17811787        }
     1788        return precacheTask;
    17821789    }
    17831790
Note: See TracChangeset for help on using the changeset viewer.