Changeset 9860 in josm


Ignore:
Timestamp:
2016-02-23T20:39:21+01:00 (6 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.

Location:
trunk/src/org/openstreetmap/josm/gui/layer
Files:
6 edited

Legend:

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

    r8840 r9860  
    99import org.apache.commons.jcs.access.behavior.ICacheAccess;
    1010import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
     11import org.openstreetmap.gui.jmapviewer.tilesources.AbstractTMSTileSource;
    1112import org.openstreetmap.josm.Main;
    1213import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
     
    2223 *
    2324 * @author Wiktor Niesiobędzki
     25 * @param <T> Tile Source class used by this Imagery Layer
    2426 *
    2527 */
    26 public abstract class AbstractCachedTileSourceLayer extends AbstractTileSourceLayer {
     28public abstract class AbstractCachedTileSourceLayer<T extends AbstractTMSTileSource> extends AbstractTileSourceLayer<T> {
    2729    /** loader factory responsible for loading tiles for all layers */
    2830    private static Map<String, TileLoaderFactory> loaderFactories = new ConcurrentHashMap<>();
  • 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
  • trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java

    r9825 r9860  
    3333 *
    3434 */
    35 public class TMSLayer extends AbstractCachedTileSourceLayer implements NativeScaleLayer {
     35public class TMSLayer extends AbstractCachedTileSourceLayer<TMSTileSource> implements NativeScaleLayer {
    3636    private static final String CACHE_REGION_NAME = "TMS";
    3737
     
    7878     */
    7979    @Override
    80     protected AbstractTMSTileSource getTileSource(ImageryInfo info) throws IllegalArgumentException {
     80    protected TMSTileSource getTileSource(ImageryInfo info) throws IllegalArgumentException {
    8181        return getTileSourceStatic(info, new Runnable() {
    8282            @Override
     
    127127     * @throws IllegalArgumentException if url from imagery info is null or invalid
    128128     */
    129     public static AbstractTMSTileSource getTileSourceStatic(ImageryInfo info, Runnable attributionLoadedTask) throws IllegalArgumentException {
     129    public static TMSTileSource getTileSourceStatic(ImageryInfo info, Runnable attributionLoadedTask) throws IllegalArgumentException {
    130130        if (info.getImageryType() == ImageryType.TMS) {
    131131            TemplatedTMSTileSource.checkUrl(info.getUrl());
  • trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java

    r9848 r9860  
    1818import org.apache.commons.jcs.access.CacheAccess;
    1919import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
    20 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
    21 import org.openstreetmap.gui.jmapviewer.tilesources.AbstractTMSTileSource;
    2220import org.openstreetmap.josm.Main;
    2321import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
     
    3735 *
    3836 */
    39 public class WMSLayer extends AbstractCachedTileSourceLayer {
     37public class WMSLayer extends AbstractCachedTileSourceLayer<TemplatedWMSTileSource> {
    4038    private static final String PREFERENCE_PREFIX   = "imagery.wms.";
    4139
     
    7573
    7674    @Override
    77     protected AbstractTMSTileSource getTileSource(ImageryInfo info) {
     75    protected TemplatedWMSTileSource getTileSource(ImageryInfo info) {
    7876        if (info.getImageryType() == ImageryType.WMS && info.getUrl() != null) {
    7977            TemplatedWMSTileSource.checkUrl(info.getUrl());
     
    105103
    106104    @Override
    107     protected Map<String, String> getHeaders(TileSource tileSource) {
    108         if (tileSource instanceof TemplatedWMSTileSource) {
    109             return ((TemplatedWMSTileSource) tileSource).getHeaders();
    110         }
    111         return null;
     105    protected Map<String, String> getHeaders(TemplatedWMSTileSource tileSource) {
     106        return tileSource.getHeaders();
    112107    }
    113108
     
    155150        }
    156151
    157         if (!newValue.equals(oldValue) && tileSource instanceof TemplatedWMSTileSource) {
    158             ((TemplatedWMSTileSource) tileSource).initProjection(newValue);
     152        if (!newValue.equals(oldValue)) {
     153            tileSource.initProjection(newValue);
    159154        }
    160155    }
  • trunk/src/org/openstreetmap/josm/gui/layer/WMTSLayer.java

    r9825 r9860  
    77import org.apache.commons.jcs.access.CacheAccess;
    88import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
    9 import org.openstreetmap.gui.jmapviewer.tilesources.AbstractTMSTileSource;
    109import org.openstreetmap.josm.Main;
    1110import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
     
    2726 *
    2827 */
    29 public class WMTSLayer extends AbstractCachedTileSourceLayer implements NativeScaleLayer {
     28public class WMTSLayer extends AbstractCachedTileSourceLayer<WMTSTileSource> implements NativeScaleLayer {
    3029    /**
    3130     * default setting of autozoom per layer
     
    4443
    4544    @Override
    46     protected AbstractTMSTileSource getTileSource(ImageryInfo info) {
     45    protected WMTSTileSource getTileSource(ImageryInfo info) {
    4746        try {
    4847            if (info.getImageryType() == ImageryType.WMTS && info.getUrl() != null) {
     
    7877    @Override
    7978    public boolean isProjectionSupported(Projection proj) {
    80         Set<String> supportedProjections = ((WMTSTileSource) tileSource).getSupportedProjections();
     79        Set<String> supportedProjections = tileSource.getSupportedProjections();
    8180        return supportedProjections.contains(proj.toCode());
    8281    }
     
    8584    public String nameSupportedProjections() {
    8685        StringBuilder ret = new StringBuilder();
    87         for (String e: ((WMTSTileSource) tileSource).getSupportedProjections()) {
     86        for (String e: tileSource.getSupportedProjections()) {
    8887            ret.append(e).append(", ");
    8988        }
     
    9493    public void projectionChanged(Projection oldValue, Projection newValue) {
    9594        super.projectionChanged(oldValue, newValue);
    96         ((WMTSTileSource) tileSource).initProjection(newValue);
     95        tileSource.initProjection(newValue);
    9796    }
    9897
     
    116115    @Override
    117116    public ScaleList getNativeScales() {
    118         return ((WMTSTileSource) tileSource).getNativeScales();
     117        return tileSource.getNativeScales();
    119118    }
    120119}
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/DownloadWmsAlongTrackAction.java

    r9719 r9860  
    1616import javax.swing.JPanel;
    1717
     18import org.openstreetmap.gui.jmapviewer.tilesources.AbstractTMSTileSource;
    1819import org.openstreetmap.josm.Main;
    1920import org.openstreetmap.josm.actions.AbstractMergeAction.LayerListCellRenderer;
     
    2627import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    2728import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer;
    28 import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer.PrecacheTask;
    2929import org.openstreetmap.josm.gui.progress.ProgressTaskId;
    3030import org.openstreetmap.josm.gui.progress.ProgressTaskIds;
     
    5353    static class PrecacheWmsTask extends PleaseWaitRunnable {
    5454
    55         private final AbstractTileSourceLayer layer;
     55        private final AbstractTileSourceLayer<? extends AbstractTMSTileSource> layer;
    5656        private final List<LatLon> points;
    57         private PrecacheTask precacheTask;
     57        private AbstractTileSourceLayer<? extends AbstractTMSTileSource>.PrecacheTask precacheTask;
    5858
    59         protected PrecacheWmsTask(AbstractTileSourceLayer layer, List<LatLon> points) {
     59        protected PrecacheWmsTask(AbstractTileSourceLayer<? extends AbstractTMSTileSource> layer, List<LatLon> points) {
    6060            super(tr("Precaching WMS"));
    6161            this.layer = layer;
     
    6565        @Override
    6666        protected void realRun() throws SAXException, IOException, OsmTransferException {
    67             precacheTask = layer.new PrecacheTask(progressMonitor);
    68             layer.downloadAreaToCache(precacheTask, points, 0, 0);
     67            precacheTask = layer.downloadAreaToCache(progressMonitor, points, 0, 0);
    6968            while (!precacheTask.isFinished() && !progressMonitor.isCanceled()) {
    7069                synchronized (this) {
     
    106105            points.add(p.getCoor());
    107106        }
    108         AbstractTileSourceLayer layer = askedLayer();
     107        AbstractTileSourceLayer<? extends AbstractTMSTileSource> layer = askedLayer();
    109108        return layer != null ? new PrecacheWmsTask(layer, points) : null;
    110109    }
     
    118117    }
    119118
    120     protected AbstractTileSourceLayer askedLayer() {
     119    @SuppressWarnings({ "rawtypes", "unchecked" })
     120    protected AbstractTileSourceLayer<? extends AbstractTMSTileSource> askedLayer() {
    121121        if (!Main.isDisplayingMapView()) {
    122122            return null;
Note: See TracChangeset for help on using the changeset viewer.