Changeset 15145 in josm


Ignore:
Timestamp:
2019-05-30T16:37:17+02:00 (4 weeks ago)
Author:
Don-vip
Message:

see #17772 - make sure all JMapViewer instances in JOSM behave the same

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java

    r14495 r15145  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.bbox;
    3 
    4 import static org.openstreetmap.josm.tools.I18n.tr;
    53
    64import java.awt.Color;
     
    1311import java.awt.geom.Path2D;
    1412import java.util.ArrayList;
    15 import java.util.Collections;
    16 import java.util.HashMap;
    1713import java.util.LinkedHashMap;
    1814import java.util.List;
    19 import java.util.Map;
    2015import java.util.concurrent.CopyOnWriteArrayList;
    21 import java.util.concurrent.TimeUnit;
    2216import java.util.stream.Collectors;
    2317
    2418import javax.swing.ButtonModel;
    25 import javax.swing.JOptionPane;
    2619import javax.swing.JToggleButton;
    2720import javax.swing.SpringLayout;
     
    3023
    3124import org.openstreetmap.gui.jmapviewer.Coordinate;
    32 import org.openstreetmap.gui.jmapviewer.JMapViewer;
    3325import org.openstreetmap.gui.jmapviewer.MapMarkerDot;
    3426import org.openstreetmap.gui.jmapviewer.MemoryTileCache;
    35 import org.openstreetmap.gui.jmapviewer.OsmTileLoader;
    3627import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
    3728import org.openstreetmap.gui.jmapviewer.interfaces.MapMarker;
    38 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
    3929import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
    40 import org.openstreetmap.gui.jmapviewer.tilesources.OsmTileSource;
    4130import org.openstreetmap.josm.data.Bounds;
    42 import org.openstreetmap.josm.data.Version;
    4331import org.openstreetmap.josm.data.coor.LatLon;
    44 import org.openstreetmap.josm.data.imagery.ImageryInfo;
    45 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo;
    46 import org.openstreetmap.josm.data.imagery.TMSCachedTileLoader;
    47 import org.openstreetmap.josm.data.imagery.TileLoaderFactory;
    4832import org.openstreetmap.josm.data.osm.BBox;
    4933import org.openstreetmap.josm.data.osm.DataSet;
     
    5135import org.openstreetmap.josm.data.preferences.StringProperty;
    5236import org.openstreetmap.josm.gui.MainApplication;
    53 import org.openstreetmap.josm.gui.layer.AbstractCachedTileSourceLayer;
    5437import org.openstreetmap.josm.gui.layer.ImageryLayer;
    5538import org.openstreetmap.josm.gui.layer.MainLayerManager;
    56 import org.openstreetmap.josm.gui.layer.TMSLayer;
    5739import org.openstreetmap.josm.spi.preferences.Config;
    5840import org.openstreetmap.josm.tools.Logging;
     
    6143 * This panel displays a map and lets the user chose a {@link BBox}.
    6244 */
    63 public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser, ChangeListener,
     45public class SlippyMapBBoxChooser extends JosmMapViewer implements BBoxChooser, ChangeListener,
    6446    MainLayerManager.ActiveLayerChangeListener, MainLayerManager.LayerChangeListener {
    65     /**
    66      * A list of tile sources that can be used for displaying the map.
    67      */
    68     @FunctionalInterface
    69     public interface TileSourceProvider {
    70         /**
    71          * Gets the tile sources that can be displayed
    72          * @return The tile sources
    73          */
    74         List<TileSource> getTileSources();
    75     }
    76 
    77     /**
    78      * TileSource provider for the slippymap chooser.
    79      * @since 14300
    80      */
    81     public abstract static class AbstractImageryInfoBasedTileSourceProvider implements TileSourceProvider {
    82         /**
    83          * Returns the list of imagery infos backing tile sources.
    84          * @return the list of imagery infos backing tile sources
    85          */
    86         public abstract List<ImageryInfo> getImageryInfos();
    87 
    88         @Override
    89         public List<TileSource> getTileSources() {
    90             if (!TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.get()) return Collections.<TileSource>emptyList();
    91             return imageryInfosToTileSources(getImageryInfos());
    92         }
    93     }
    94 
    95     /**
    96      * TileSource provider for the slippymap chooser - providing default OSM tile source
    97      * @since 14495
    98      */
    99     public static class DefaultOsmTileSourceProvider implements TileSourceProvider {
    100 
    101         protected static final StringProperty DEFAULT_OSM_TILE_URL = new StringProperty(
    102                 "default.osm.tile.source.url", "https://{switch:a,b,c}.tile.openstreetmap.org/{zoom}/{x}/{y}.png");
    103 
    104         @Override
    105         public List<TileSource> getTileSources() {
    106             List<TileSource> result = imageryInfosToTileSources(ImageryLayerInfo.instance.getLayers().stream()
    107                    .filter(l -> l.getUrl().equals(DEFAULT_OSM_TILE_URL.get())).collect(Collectors.toList()));
    108             if (result.isEmpty()) {
    109                 result.add(new OsmTileSource.Mapnik());
    110             }
    111             return result;
    112         }
    113 
    114         /**
    115          * Returns the default OSM tile source.
    116          * @return the default OSM tile source
    117          */
    118         public static TileSource get() {
    119             return new DefaultOsmTileSourceProvider().getTileSources().get(0);
    120         }
    121     }
    122 
    123     /**
    124      * TileSource provider for the slippymap chooser - providing sources from imagery sources menu
    125      * @since 14300
    126      */
    127     public static class TMSTileSourceProvider extends AbstractImageryInfoBasedTileSourceProvider {
    128         @Override
    129         public List<ImageryInfo> getImageryInfos() {
    130             return ImageryLayerInfo.instance.getLayers();
    131         }
    132     }
    133 
    134     /**
    135      * TileSource provider for the slippymap chooser - providing sources from current layers
    136      * @since 14300
    137      */
    138     public static class CurrentLayersTileSourceProvider extends AbstractImageryInfoBasedTileSourceProvider {
    139         @Override
    140         public List<ImageryInfo> getImageryInfos() {
    141             return MainApplication.getLayerManager().getLayers().stream().filter(
    142                 layer -> layer instanceof ImageryLayer
    143             ).map(
    144                 layer -> ((ImageryLayer) layer).getInfo()
    145             ).collect(Collectors.toList());
    146         }
    147     }
    148 
    149     static List<TileSource> imageryInfosToTileSources(List<ImageryInfo> imageryInfos) {
    150         List<TileSource> sources = new ArrayList<>();
    151         for (ImageryInfo info : imageryInfos) {
    152             try {
    153                 TileSource source = TMSLayer.getTileSourceStatic(info);
    154                 if (source != null) {
    155                     sources.add(source);
    156                 }
    157             } catch (IllegalArgumentException ex) {
    158                 Logging.warn(ex);
    159                 if (ex.getMessage() != null && !ex.getMessage().isEmpty()) {
    160                     JOptionPane.showMessageDialog(MainApplication.getMainFrame(),
    161                             ex.getMessage(), tr("Warning"),
    162                             JOptionPane.WARNING_MESSAGE);
    163                 }
    164             }
    165         }
    166         return sources;
    167     }
    16847
    16948    /**
     
    19069    public static final String RESIZE_PROP = SlippyMapBBoxChooser.class.getName() + ".resize";
    19170
    192     private final transient TileLoader cachedLoader;
    193     private final transient OsmTileLoader uncachedLoader;
    194 
    19571    private final SizeButton iSizeButton;
    19672    private final ButtonModel showDownloadAreaButtonModel;
     
    21086        setLayout(springLayout);
    21187
    212         Map<String, String> headers = new HashMap<>();
    213         headers.put("User-Agent", Version.getInstance().getFullAgentString());
    214 
    215         TileLoaderFactory cachedLoaderFactory = AbstractCachedTileSourceLayer.getTileLoaderFactory("TMS", TMSCachedTileLoader.class);
    216         if (cachedLoaderFactory != null) {
    217             cachedLoader = cachedLoaderFactory.makeTileLoader(this, headers, TimeUnit.HOURS.toSeconds(1));
    218         } else {
    219             cachedLoader = null;
    220         }
    221 
    222         uncachedLoader = new OsmTileLoader(this);
    223         uncachedLoader.headers.putAll(headers);
    22488        setZoomControlsVisible(Config.getPref().getBoolean("slippy_map_chooser.zoomcontrols", false));
    22589        setMapMarkerVisible(false);
     
    350214        PROP_SHOWDLAREA.put(this.showDownloadAreaButtonModel.isSelected());
    351215        this.repaint();
    352     }
    353 
    354     /**
    355      * Enables the disk tile cache.
    356      * @param enabled true to enable, false to disable
    357      */
    358     public final void setFileCacheEnabled(boolean enabled) {
    359         if (enabled && cachedLoader != null) {
    360             setTileLoader(cachedLoader);
    361         } else {
    362             setTileLoader(uncachedLoader);
    363         }
    364     }
    365 
    366     /**
    367      * Sets the maximum number of tiles that may be held in memory
    368      * @param tiles The maximum number of tiles.
    369      */
    370     public final void setMaxTilesInMemory(int tiles) {
    371         ((MemoryTileCache) getTileCache()).setCacheSize(tiles);
    372216    }
    373217
  • trunk/src/org/openstreetmap/josm/gui/bbox/TileSelectionBBoxChooser.java

    r13426 r15145  
    4040import javax.swing.text.JTextComponent;
    4141
    42 import org.openstreetmap.gui.jmapviewer.JMapViewer;
    4342import org.openstreetmap.gui.jmapviewer.MapMarkerDot;
    44 import org.openstreetmap.gui.jmapviewer.OsmTileLoader;
    4543import org.openstreetmap.gui.jmapviewer.interfaces.MapMarker;
    46 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
    4744import org.openstreetmap.josm.data.Bounds;
    48 import org.openstreetmap.josm.data.Version;
    4945import org.openstreetmap.josm.data.coor.LatLon;
    5046import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator;
     
    657653     * The map view used in this bounding box chooser
    658654     */
    659     private static final class TileBoundsMapView extends JMapViewer {
     655    private static final class TileBoundsMapView extends JosmMapViewer {
    660656        private Point min;
    661657        private Point max;
     
    663659        private TileBoundsMapView() {
    664660            setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
    665             TileLoader loader = tileController.getTileLoader();
    666             if (loader instanceof OsmTileLoader) {
    667                 ((OsmTileLoader) loader).headers.put("User-Agent", Version.getInstance().getFullAgentString());
    668             }
    669661        }
    670662
  • trunk/src/org/openstreetmap/josm/gui/history/CoordinateInfoViewer.java

    r14495 r15145  
    2424import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
    2525import org.openstreetmap.josm.gui.NavigatableComponent;
     26import org.openstreetmap.josm.gui.bbox.JosmMapViewer;
    2627import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser;
    2728import org.openstreetmap.josm.gui.util.GuiHelper;
     
    317318    }
    318319
    319     private static class MapViewer extends JMapViewer implements ChangeListener {
     320    private static class MapViewer extends JosmMapViewer implements ChangeListener {
    320321
    321322        private final transient Updater updater;
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryProvidersPanel.java

    r15121 r15145  
    4444
    4545import org.openstreetmap.gui.jmapviewer.Coordinate;
    46 import org.openstreetmap.gui.jmapviewer.JMapViewer;
    4746import org.openstreetmap.gui.jmapviewer.MapPolygonImpl;
    4847import org.openstreetmap.gui.jmapviewer.MapRectangleImpl;
     
    5655import org.openstreetmap.josm.data.preferences.NamedColorProperty;
    5756import org.openstreetmap.josm.gui.MainApplication;
     57import org.openstreetmap.josm.gui.bbox.JosmMapViewer;
    5858import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser;
    5959import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
     
    7474 */
    7575public class ImageryProvidersPanel extends JPanel {
    76     // Public JTables and JMapViewer
     76    // Public JTables and JosmMapViewer
    7777    /** The table of active providers **/
    7878    public final JTable activeTable;
     
    8484    private final transient DefListSelectionListener defaultTableListener;
    8585    /** The map displaying imagery bounds of selected default providers **/
    86     public final JMapViewer defaultMap;
     86    public final JosmMapViewer defaultMap;
    8787
    8888    // Public models
     
    265265
    266266        // Add default item map
    267         defaultMap = new JMapViewer();
     267        defaultMap = new JosmMapViewer();
    268268        defaultMap.setTileSource(SlippyMapBBoxChooser.DefaultOsmTileSourceProvider.get()); // for attribution
    269269        defaultMap.addMouseListener(new MouseAdapter() {
Note: See TracChangeset for help on using the changeset viewer.