- Timestamp:
- 2019-05-30T16:37:17+02:00 (5 years ago)
- 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 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.bbox; 3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 3 6 4 import java.awt.Color; … … 13 11 import java.awt.geom.Path2D; 14 12 import java.util.ArrayList; 15 import java.util.Collections;16 import java.util.HashMap;17 13 import java.util.LinkedHashMap; 18 14 import java.util.List; 19 import java.util.Map;20 15 import java.util.concurrent.CopyOnWriteArrayList; 21 import java.util.concurrent.TimeUnit;22 16 import java.util.stream.Collectors; 23 17 24 18 import javax.swing.ButtonModel; 25 import javax.swing.JOptionPane;26 19 import javax.swing.JToggleButton; 27 20 import javax.swing.SpringLayout; … … 30 23 31 24 import org.openstreetmap.gui.jmapviewer.Coordinate; 32 import org.openstreetmap.gui.jmapviewer.JMapViewer;33 25 import org.openstreetmap.gui.jmapviewer.MapMarkerDot; 34 26 import org.openstreetmap.gui.jmapviewer.MemoryTileCache; 35 import org.openstreetmap.gui.jmapviewer.OsmTileLoader;36 27 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; 37 28 import org.openstreetmap.gui.jmapviewer.interfaces.MapMarker; 38 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;39 29 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 40 import org.openstreetmap.gui.jmapviewer.tilesources.OsmTileSource;41 30 import org.openstreetmap.josm.data.Bounds; 42 import org.openstreetmap.josm.data.Version;43 31 import 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;48 32 import org.openstreetmap.josm.data.osm.BBox; 49 33 import org.openstreetmap.josm.data.osm.DataSet; … … 51 35 import org.openstreetmap.josm.data.preferences.StringProperty; 52 36 import org.openstreetmap.josm.gui.MainApplication; 53 import org.openstreetmap.josm.gui.layer.AbstractCachedTileSourceLayer;54 37 import org.openstreetmap.josm.gui.layer.ImageryLayer; 55 38 import org.openstreetmap.josm.gui.layer.MainLayerManager; 56 import org.openstreetmap.josm.gui.layer.TMSLayer;57 39 import org.openstreetmap.josm.spi.preferences.Config; 58 40 import org.openstreetmap.josm.tools.Logging; … … 61 43 * This panel displays a map and lets the user chose a {@link BBox}. 62 44 */ 63 public class SlippyMapBBoxChooser extends J MapViewer implements BBoxChooser, ChangeListener,45 public class SlippyMapBBoxChooser extends JosmMapViewer implements BBoxChooser, ChangeListener, 64 46 MainLayerManager.ActiveLayerChangeListener, MainLayerManager.LayerChangeListener { 65 /**66 * A list of tile sources that can be used for displaying the map.67 */68 @FunctionalInterface69 public interface TileSourceProvider {70 /**71 * Gets the tile sources that can be displayed72 * @return The tile sources73 */74 List<TileSource> getTileSources();75 }76 77 /**78 * TileSource provider for the slippymap chooser.79 * @since 1430080 */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 sources85 */86 public abstract List<ImageryInfo> getImageryInfos();87 88 @Override89 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 source97 * @since 1449598 */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 @Override105 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 source117 */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 menu125 * @since 14300126 */127 public static class TMSTileSourceProvider extends AbstractImageryInfoBasedTileSourceProvider {128 @Override129 public List<ImageryInfo> getImageryInfos() {130 return ImageryLayerInfo.instance.getLayers();131 }132 }133 134 /**135 * TileSource provider for the slippymap chooser - providing sources from current layers136 * @since 14300137 */138 public static class CurrentLayersTileSourceProvider extends AbstractImageryInfoBasedTileSourceProvider {139 @Override140 public List<ImageryInfo> getImageryInfos() {141 return MainApplication.getLayerManager().getLayers().stream().filter(142 layer -> layer instanceof ImageryLayer143 ).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 }168 47 169 48 /** … … 190 69 public static final String RESIZE_PROP = SlippyMapBBoxChooser.class.getName() + ".resize"; 191 70 192 private final transient TileLoader cachedLoader;193 private final transient OsmTileLoader uncachedLoader;194 195 71 private final SizeButton iSizeButton; 196 72 private final ButtonModel showDownloadAreaButtonModel; … … 210 86 setLayout(springLayout); 211 87 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);224 88 setZoomControlsVisible(Config.getPref().getBoolean("slippy_map_chooser.zoomcontrols", false)); 225 89 setMapMarkerVisible(false); … … 350 214 PROP_SHOWDLAREA.put(this.showDownloadAreaButtonModel.isSelected()); 351 215 this.repaint(); 352 }353 354 /**355 * Enables the disk tile cache.356 * @param enabled true to enable, false to disable357 */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 memory368 * @param tiles The maximum number of tiles.369 */370 public final void setMaxTilesInMemory(int tiles) {371 ((MemoryTileCache) getTileCache()).setCacheSize(tiles);372 216 } 373 217 -
trunk/src/org/openstreetmap/josm/gui/bbox/TileSelectionBBoxChooser.java
r13426 r15145 40 40 import javax.swing.text.JTextComponent; 41 41 42 import org.openstreetmap.gui.jmapviewer.JMapViewer;43 42 import org.openstreetmap.gui.jmapviewer.MapMarkerDot; 44 import org.openstreetmap.gui.jmapviewer.OsmTileLoader;45 43 import org.openstreetmap.gui.jmapviewer.interfaces.MapMarker; 46 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;47 44 import org.openstreetmap.josm.data.Bounds; 48 import org.openstreetmap.josm.data.Version;49 45 import org.openstreetmap.josm.data.coor.LatLon; 50 46 import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator; … … 657 653 * The map view used in this bounding box chooser 658 654 */ 659 private static final class TileBoundsMapView extends J MapViewer {655 private static final class TileBoundsMapView extends JosmMapViewer { 660 656 private Point min; 661 657 private Point max; … … 663 659 private TileBoundsMapView() { 664 660 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 }669 661 } 670 662 -
trunk/src/org/openstreetmap/josm/gui/history/CoordinateInfoViewer.java
r14495 r15145 24 24 import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive; 25 25 import org.openstreetmap.josm.gui.NavigatableComponent; 26 import org.openstreetmap.josm.gui.bbox.JosmMapViewer; 26 27 import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser; 27 28 import org.openstreetmap.josm.gui.util.GuiHelper; … … 317 318 } 318 319 319 private static class MapViewer extends J MapViewer implements ChangeListener {320 private static class MapViewer extends JosmMapViewer implements ChangeListener { 320 321 321 322 private final transient Updater updater; -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryProvidersPanel.java
r15121 r15145 44 44 45 45 import org.openstreetmap.gui.jmapviewer.Coordinate; 46 import org.openstreetmap.gui.jmapviewer.JMapViewer;47 46 import org.openstreetmap.gui.jmapviewer.MapPolygonImpl; 48 47 import org.openstreetmap.gui.jmapviewer.MapRectangleImpl; … … 56 55 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 57 56 import org.openstreetmap.josm.gui.MainApplication; 57 import org.openstreetmap.josm.gui.bbox.JosmMapViewer; 58 58 import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser; 59 59 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; … … 74 74 */ 75 75 public class ImageryProvidersPanel extends JPanel { 76 // Public JTables and J MapViewer76 // Public JTables and JosmMapViewer 77 77 /** The table of active providers **/ 78 78 public final JTable activeTable; … … 84 84 private final transient DefListSelectionListener defaultTableListener; 85 85 /** The map displaying imagery bounds of selected default providers **/ 86 public final J MapViewer defaultMap;86 public final JosmMapViewer defaultMap; 87 87 88 88 // Public models … … 265 265 266 266 // Add default item map 267 defaultMap = new J MapViewer();267 defaultMap = new JosmMapViewer(); 268 268 defaultMap.setTileSource(SlippyMapBBoxChooser.DefaultOsmTileSourceProvider.get()); // for attribution 269 269 defaultMap.addMouseListener(new MouseAdapter() {
Note:
See TracChangeset
for help on using the changeset viewer.