Ticket #13169: patch-mapview-extract-tile-source-preferences.patch
| File patch-mapview-extract-tile-source-preferences.patch, 31.4 KB (added by , 10 years ago) |
|---|
-
src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java
diff --git a/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java b/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java index 2807ac4..c507839 100644
a b import org.openstreetmap.josm.data.imagery.ImageryInfo; 72 72 import org.openstreetmap.josm.data.imagery.TMSCachedTileLoader; 73 73 import org.openstreetmap.josm.data.imagery.TileLoaderFactory; 74 74 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 75 import org.openstreetmap.josm.data.preferences.BooleanProperty;76 75 import org.openstreetmap.josm.data.preferences.IntegerProperty; 77 76 import org.openstreetmap.josm.gui.ExtendedDialog; 78 77 import org.openstreetmap.josm.gui.MapFrame; … … import org.openstreetmap.josm.gui.PleaseWaitRunnable; 82 81 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 83 82 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 84 83 import org.openstreetmap.josm.gui.layer.imagery.ImageryFilterSettings.FilterChangeListener; 84 import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings; 85 import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings.DisplaySettingsChangeEvent; 86 import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings.DisplaySettingsChangeListener; 85 87 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 86 88 import org.openstreetmap.josm.gui.util.GuiHelper; 87 89 import org.openstreetmap.josm.io.WMSLayerImporter; … … import org.openstreetmap.josm.tools.GBC; 99 101 * @since 8526 (copied from TMSLayer) 100 102 */ 101 103 public abstract class AbstractTileSourceLayer<T extends AbstractTMSTileSource> extends ImageryLayer 102 implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeListener {104 implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeListener, DisplaySettingsChangeListener { 103 105 private static final String PREFERENCE_PREFIX = "imagery.generic"; 106 /** 107 * Registers all setting properties 108 */ 109 static { 110 new TileSourceDisplaySettings(); 111 } 104 112 105 113 /** maximum zoom level supported */ 106 114 public static final int MAX_ZOOM = 30; … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 108 116 public static final int MIN_ZOOM = 2; 109 117 private static final Font InfoFont = new Font("sansserif", Font.BOLD, 13); 110 118 111 /** do set autozoom when creating a new layer */112 public static final BooleanProperty PROP_DEFAULT_AUTOZOOM = new BooleanProperty(PREFERENCE_PREFIX + ".default_autozoom", true);113 /** do set autoload when creating a new layer */114 public static final BooleanProperty PROP_DEFAULT_AUTOLOAD = new BooleanProperty(PREFERENCE_PREFIX + ".default_autoload", true);115 /** do show errors per default */116 public static final BooleanProperty PROP_DEFAULT_SHOWERRORS = new BooleanProperty(PREFERENCE_PREFIX + ".default_showerrors", true);117 119 /** minimum zoom level to show to user */ 118 120 public static final IntegerProperty PROP_MIN_ZOOM_LVL = new IntegerProperty(PREFERENCE_PREFIX + ".min_zoom_lvl", 2); 119 121 /** maximum zoom level to show to user */ … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 130 132 private final AttributionSupport attribution = new AttributionSupport(); 131 133 private final TileHolder clickedTileHolder = new TileHolder(); 132 134 133 // needed public access for session exporter134 /** if layers changes automatically, when user zooms in */135 public boolean autoZoom = PROP_DEFAULT_AUTOZOOM.get();136 /** if layer automatically loads new tiles */137 public boolean autoLoad = PROP_DEFAULT_AUTOLOAD.get();138 /** if layer should show errors on tiles */139 public boolean showErrors = PROP_DEFAULT_SHOWERRORS.get();140 141 135 /** 142 136 * Offset between calculated zoom level and zoom level used to download and show tiles. Negative values will result in 143 137 * lower resolution of imagery useful in "retina" displays, positive values will result in higher resolution … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 167 161 } 168 162 } 169 163 }; 164 165 private final TileSourceDisplaySettings displaySettings = createDisplaySettings(); 166 170 167 /** 171 168 * Creates Tile Source based Imagery Layer based on Imagery Info 172 169 * @param info imagery info … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 176 173 setBackgroundLayer(true); 177 174 this.setVisible(true); 178 175 getFilterSettings().addFilterChangeListener(this); 176 getDisplaySettings().addSettingsChangeListener(this); 177 } 178 179 /** 180 * This method creates the {@link TileSourceDisplaySettings} object. Subclasses may implement it to e.g. change the prefix. 181 * @return The object. 182 * @since xxx 183 */ 184 protected TileSourceDisplaySettings createDisplaySettings() { 185 return new TileSourceDisplaySettings(); 186 } 187 188 /** 189 * Gets the {@link TileSourceDisplaySettings} instance associated with this tile source. 190 * @return The tile source display settings 191 * @since xxx 192 */ 193 public TileSourceDisplaySettings getDisplaySettings() { 194 return displaySettings; 179 195 } 180 196 181 197 @Override … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 410 426 411 427 @Override 412 428 public void actionPerformed(ActionEvent ae) { 413 autoZoom = !autoZoom; 414 if (autoZoom && getBestZoom() != currentZoomLevel) { 415 setZoomLevel(getBestZoom()); 416 redraw(); 417 } 429 getDisplaySettings().setAutoZoom(!getDisplaySettings().isAutoZoom()); 418 430 } 419 431 420 432 @Override 421 433 public Component createMenuComponent() { 422 434 JCheckBoxMenuItem item = new JCheckBoxMenuItem(this); 423 item.setSelected( autoZoom);435 item.setSelected(getDisplaySettings().isAutoZoom()); 424 436 return item; 425 437 } 426 438 … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 437 449 438 450 @Override 439 451 public void actionPerformed(ActionEvent ae) { 440 autoLoad = !autoLoad; 441 if (autoLoad) redraw(); 452 getDisplaySettings().setAutoLoad(!getDisplaySettings().isAutoLoad()); 442 453 } 443 454 444 455 @Override 445 456 public Component createMenuComponent() { 446 457 JCheckBoxMenuItem item = new JCheckBoxMenuItem(this); 447 item.setSelected( autoLoad);458 item.setSelected(getDisplaySettings().isAutoLoad()); 448 459 return item; 449 460 } 450 461 … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 461 472 462 473 @Override 463 474 public void actionPerformed(ActionEvent ae) { 464 showErrors = !showErrors; 465 redraw(); 475 getDisplaySettings().setShowErrors(!getDisplaySettings().isShowErrors()); 466 476 } 467 477 468 478 @Override 469 479 public Component createMenuComponent() { 470 480 JCheckBoxMenuItem item = new JCheckBoxMenuItem(this); 471 item.setSelected( showErrors);481 item.setSelected(getDisplaySettings().isShowErrors()); 472 482 return item; 473 483 } 474 484 … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 518 528 private class ZoomToBestAction extends AbstractAction { 519 529 ZoomToBestAction() { 520 530 super(tr("Change resolution")); 521 setEnabled(! autoZoom&& getBestZoom() != currentZoomLevel);531 setEnabled(!getDisplaySettings().isAutoZoom() && getBestZoom() != currentZoomLevel); 522 532 } 523 533 524 534 @Override … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 531 541 private class IncreaseZoomAction extends AbstractAction { 532 542 IncreaseZoomAction() { 533 543 super(tr("Increase zoom")); 534 setEnabled(! autoZoom&& zoomIncreaseAllowed());544 setEnabled(!getDisplaySettings().isAutoZoom() && zoomIncreaseAllowed()); 535 545 } 536 546 537 547 @Override … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 544 554 private class DecreaseZoomAction extends AbstractAction { 545 555 DecreaseZoomAction() { 546 556 super(tr("Decrease zoom")); 547 setEnabled(! autoZoom&& zoomDecreaseAllowed());557 setEnabled(!getDisplaySettings().isAutoZoom() && zoomDecreaseAllowed()); 548 558 } 549 559 550 560 @Override … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 696 706 return ret; 697 707 } 698 708 709 @Override 710 public void displaySettingsChanged(DisplaySettingsChangeEvent e) { 711 if (tileSource == null) { 712 return; 713 } 714 switch (e.getChangedSetting()) { 715 case TileSourceDisplaySettings.AUTO_ZOOM: 716 if (getDisplaySettings().isAutoZoom() && getBestZoom() != currentZoomLevel) { 717 setZoomLevel(getBestZoom()); 718 redraw(); 719 } 720 break; 721 case TileSourceDisplaySettings.AUTO_LOAD: 722 if (getDisplaySettings().isAutoLoad()) { 723 redraw(); 724 } 725 break; 726 default: 727 // trigger a redraw just to be sure. 728 redraw(); 729 } 730 } 731 699 732 /** 700 733 * Checks zoom level against settings 701 734 * @param maxZoomLvl zoom level to check … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 1142 1175 texty += 1 + fontHeight; 1143 1176 }*/ 1144 1177 1145 if (tile.hasError() && showErrors) {1178 if (tile.hasError() && getDisplaySettings().isShowErrors()) { 1146 1179 myDrawString(g, tr("Error") + ": " + tr(tile.getErrorMessage()), p.x + 2, texty); 1147 1180 //texty += 1 + fontHeight; 1148 1181 } … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 1368 1401 } 1369 1402 1370 1403 private void loadAllTiles(boolean force) { 1371 if (! autoLoad&& !force)1404 if (!getDisplaySettings().isAutoLoad() && !force) 1372 1405 return; 1373 1406 List<Tile> allTiles = allTilesCreate(); 1374 1407 Collections.sort(allTiles, getTileDistanceComparator()); … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 1378 1411 } 1379 1412 1380 1413 private void loadAllErrorTiles(boolean force) { 1381 if (! autoLoad&& !force)1414 if (!getDisplaySettings().isAutoLoad() && !force) 1382 1415 return; 1383 1416 for (Tile t : this.allTilesCreate()) { 1384 1417 if (t.hasError()) { … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 1476 1509 needRedraw = false; 1477 1510 1478 1511 int zoom = currentZoomLevel; 1479 if ( autoZoom) {1512 if (getDisplaySettings().isAutoZoom()) { 1480 1513 zoom = getBestZoom(); 1481 1514 } 1482 1515 … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 1486 1519 int displayZoomLevel = zoom; 1487 1520 1488 1521 boolean noTilesAtZoom = false; 1489 if ( autoZoom && autoLoad) {1522 if (getDisplaySettings().isAutoZoom() && getDisplaySettings().isAutoLoad()) { 1490 1523 // Auto-detection of tilesource maxzoom (currently fully works only for Bing) 1491 1524 TileSetInfo tsi = dts.getTileSetInfo(zoom); 1492 1525 if (!tsi.hasVisibleTiles && (!tsi.hasLoadingTiles || tsi.hasOverzoomedTiles)) { … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 1522 1555 tsi = dts.getTileSetInfo(zoom); 1523 1556 } 1524 1557 ts = dts.getTileSet(zoom); 1525 } else if ( autoZoom) {1558 } else if (getDisplaySettings().isAutoZoom()) { 1526 1559 setZoomLevel(zoom); 1527 1560 } 1528 1561 … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 1541 1574 List<Tile> missedTiles = this.paintTileImages(g, ts, displayZoomLevel, null); 1542 1575 int[] otherZooms = {-1, 1, -2, 2, -3, -4, -5}; 1543 1576 for (int zoomOffset : otherZooms) { 1544 if (! autoZoom) {1577 if (!getDisplaySettings().isAutoZoom()) { 1545 1578 break; 1546 1579 } 1547 1580 int newzoom = displayZoomLevel + zoomOffset; … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 1597 1630 myDrawString(g, tr("zoom in to load any tiles"), 120, 120); 1598 1631 } else if (ts.tooLarge()) { 1599 1632 myDrawString(g, tr("zoom in to load more tiles"), 120, 120); 1600 } else if (! autoZoom&& ts.tooSmall()) {1633 } else if (!getDisplaySettings().isAutoZoom() && ts.tooSmall()) { 1601 1634 myDrawString(g, tr("increase tiles zoom level (change resolution) to see more detail"), 120, 120); 1602 1635 } 1603 1636 … … implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 1709 1742 1710 1743 @Override 1711 1744 public String getToolTipText() { 1712 if ( autoLoad) {1745 if (getDisplaySettings().isAutoLoad()) { 1713 1746 return tr("{0} ({1}), automatically downloading in zoom {2}", this.getClass().getSimpleName(), getName(), currentZoomLevel); 1714 1747 } else { 1715 1748 return tr("{0} ({1}), downloading in zoom {2}", this.getClass().getSimpleName(), getName(), currentZoomLevel); -
src/org/openstreetmap/josm/gui/layer/WMSLayer.java
diff --git a/src/org/openstreetmap/josm/gui/layer/WMSLayer.java b/src/org/openstreetmap/josm/gui/layer/WMSLayer.java index 152e658..acf27c6 100644
a b import org.openstreetmap.josm.data.preferences.BooleanProperty; 28 28 import org.openstreetmap.josm.data.preferences.IntegerProperty; 29 29 import org.openstreetmap.josm.data.projection.Projection; 30 30 import org.openstreetmap.josm.gui.ExtendedDialog; 31 import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings; 31 32 32 33 /** 33 34 * This is a layer that grabs the current screen from an WMS server. The data … … import org.openstreetmap.josm.gui.ExtendedDialog; 35 36 * 36 37 */ 37 38 public class WMSLayer extends AbstractCachedTileSourceLayer<TemplatedWMSTileSource> { 38 private static final String PREFERENCE_PREFIX = "imagery.wms."; 39 private static final String PREFERENCE_PREFIX = "imagery.wms"; 40 /** 41 * Registers all setting properties 42 */ 43 static { 44 new TileSourceDisplaySettings(PREFERENCE_PREFIX); 45 } 39 46 40 47 /** default tile size for WMS Layer */ 41 public static final IntegerProperty PROP_IMAGE_SIZE = new IntegerProperty(PREFERENCE_PREFIX + " imageSize", 512);48 public static final IntegerProperty PROP_IMAGE_SIZE = new IntegerProperty(PREFERENCE_PREFIX + ".imageSize", 512); 42 49 43 50 /** should WMS layer autozoom in default mode */ 44 public static final BooleanProperty PROP_DEFAULT_AUTOZOOM = new BooleanProperty(PREFERENCE_PREFIX + " default_autozoom", true);51 public static final BooleanProperty PROP_DEFAULT_AUTOZOOM = new BooleanProperty(PREFERENCE_PREFIX + ".default_autozoom", true); 45 52 46 53 private static final String CACHE_REGION_NAME = "WMS"; 47 54 … … public class WMSLayer extends AbstractCachedTileSourceLayer<TemplatedWMSTileSour 54 61 public WMSLayer(ImageryInfo info) { 55 62 super(info); 56 63 this.supportedProjections = new TreeSet<>(info.getServerProjections()); 57 this.autoZoom = PROP_DEFAULT_AUTOZOOM.get(); 64 } 65 66 @Override 67 protected TileSourceDisplaySettings createDisplaySettings() { 68 return new TileSourceDisplaySettings(PREFERENCE_PREFIX); 58 69 } 59 70 60 71 @Override -
src/org/openstreetmap/josm/gui/layer/WMTSLayer.java
diff --git a/src/org/openstreetmap/josm/gui/layer/WMTSLayer.java b/src/org/openstreetmap/josm/gui/layer/WMTSLayer.java index c61ee95..f4cb70c 100644
a b import org.openstreetmap.josm.data.imagery.ImageryInfo; 12 12 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 13 13 import org.openstreetmap.josm.data.imagery.WMSCachedTileLoader; 14 14 import org.openstreetmap.josm.data.imagery.WMTSTileSource; 15 import org.openstreetmap.josm.data.preferences.BooleanProperty;16 15 import org.openstreetmap.josm.data.projection.Projection; 16 import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings; 17 17 18 18 /** 19 19 * WMTS layer based on AbstractTileSourceLayer. Overrides few methods to align WMTS to Tile based computations … … import org.openstreetmap.josm.data.projection.Projection; 26 26 * 27 27 */ 28 28 public class WMTSLayer extends AbstractCachedTileSourceLayer<WMTSTileSource> implements NativeScaleLayer { 29 private static final String PREFERENCE_PREFIX = "imagery.wmts"; 30 29 31 /** 30 * default setting of autozoom per layer32 * Registers all setting properties 31 33 */ 32 public static final BooleanProperty PROP_DEFAULT_AUTOZOOM_WMTS = new BooleanProperty("imagery.wmts.default_autozoom", true); 34 static { 35 new TileSourceDisplaySettings(PREFERENCE_PREFIX); 36 } 37 33 38 private static final String CACHE_REGION_NAME = "WMTS"; 34 39 35 40 /** … … public class WMTSLayer extends AbstractCachedTileSourceLayer<WMTSTileSource> imp 38 43 */ 39 44 public WMTSLayer(ImageryInfo info) { 40 45 super(info); 41 autoZoom = PROP_DEFAULT_AUTOZOOM_WMTS.get(); 46 } 47 48 @Override 49 protected TileSourceDisplaySettings createDisplaySettings() { 50 return new TileSourceDisplaySettings(PREFERENCE_PREFIX); 42 51 } 43 52 44 53 @Override -
new file src/org/openstreetmap/josm/gui/layer/imagery/TileSourceDisplaySettings.java
diff --git a/src/org/openstreetmap/josm/gui/layer/imagery/TileSourceDisplaySettings.java b/src/org/openstreetmap/josm/gui/layer/imagery/TileSourceDisplaySettings.java new file mode 100644 index 0000000..04ad579
- + 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui.layer.imagery; 3 4 import java.util.Map; 5 import java.util.concurrent.CopyOnWriteArrayList; 6 7 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 8 import org.openstreetmap.josm.Main; 9 import org.openstreetmap.josm.data.preferences.BooleanProperty; 10 import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer; 11 12 /** 13 * This are the preferences of how to display a {@link TileSource}. 14 * <p> 15 * They have been extracted from the {@link AbstractTileSourceLayer}. Each layer has one set of such settings. 16 * @author michael 17 * 18 */ 19 public class TileSourceDisplaySettings { 20 /** 21 * A string returned by {@link DisplaySettingsChangeEvent#getChangedSetting()} if auto load was changed. 22 * @see TileSourceDisplaySettings#isAutoLoad() 23 */ 24 public static final String AUTO_LOAD = "automatic-downloading"; 25 26 /** 27 * A string returned by {@link DisplaySettingsChangeEvent#getChangedSetting()} if auto zoom was changed. 28 * @see TileSourceDisplaySettings#isAutoZoom() 29 */ 30 public static final String AUTO_ZOOM = "automatically-change-resolution"; 31 32 /** 33 * A string returned by {@link DisplaySettingsChangeEvent#getChangedSetting()} if the sow errors property was changed. 34 * @see TileSourceDisplaySettings#isShowErrors() 35 */ 36 private static final String SHOW_ERRORS = "show-errors"; 37 38 private static final String PREFERENCE_PREFIX = "imagery.generic"; 39 40 /** 41 * The default auto load property 42 */ 43 public static final BooleanProperty PROP_AUTO_LOAD = new BooleanProperty(PREFERENCE_PREFIX + ".default_autoload", true); 44 45 /** 46 * The default auto zoom property 47 */ 48 public static final BooleanProperty PROP_AUTO_ZOOM = new BooleanProperty(PREFERENCE_PREFIX + ".default_autozoom", true); 49 50 /** if layers changes automatically, when user zooms in */ 51 private boolean autoZoom; 52 /** if layer automatically loads new tiles */ 53 private boolean autoLoad; 54 /** if layer should show errors on tiles */ 55 private boolean showErrors; 56 57 private final CopyOnWriteArrayList<DisplaySettingsChangeListener> listeners = new CopyOnWriteArrayList<>(); 58 59 /** 60 * Create a new {@link TileSourceDisplaySettings} 61 */ 62 public TileSourceDisplaySettings() { 63 this(new String[] { PREFERENCE_PREFIX }); 64 } 65 66 /** 67 * Create a new {@link TileSourceDisplaySettings} 68 * @param preferencePrefix The additional prefix to scan for preferences. 69 */ 70 public TileSourceDisplaySettings(String preferencePrefix) { 71 this(PREFERENCE_PREFIX, preferencePrefix); 72 } 73 74 private TileSourceDisplaySettings(String... prefixes) { 75 autoZoom = getProperty(prefixes, "default_autozoom"); 76 autoLoad = getProperty(prefixes, "default_autoload"); 77 showErrors = getProperty(prefixes, "default_showerrors"); 78 } 79 80 private static boolean getProperty(String[] prefixes, String name) { 81 // iterate through all values to force the preferences to receive the default value. 82 // we only support a default value of true. 83 boolean value = true; 84 for (String p : prefixes) { 85 String key = p + "." + name; 86 boolean currentValue = Main.pref.getBoolean(key, true); 87 if (!Main.pref.get(key).isEmpty()) { 88 value = currentValue; 89 } 90 } 91 return value; 92 } 93 94 /** 95 * Let the layer zoom automatically if the user zooms in 96 * @return auto zoom 97 */ 98 public boolean isAutoZoom() { 99 return autoZoom; 100 } 101 102 /** 103 * Sets the auto zoom property 104 * @param autoZoom 105 * @see #isAutoZoom() 106 * @see #AUTO_ZOOM 107 */ 108 public void setAutoZoom(boolean autoZoom) { 109 this.autoZoom = autoZoom; 110 fireSettingsChange(AUTO_ZOOM); 111 } 112 113 /** 114 * Gets if the layer should automatically load new tiles. 115 * @return <code>true</code> if it should 116 */ 117 public boolean isAutoLoad() { 118 return autoLoad; 119 } 120 121 /** 122 * Sets the auto load property 123 * @param autoLoad 124 * @see #isAutoLoad() 125 * @see #AUTO_LOAD 126 */ 127 public void setAutoLoad(boolean autoLoad) { 128 this.autoLoad = autoLoad; 129 fireSettingsChange(AUTO_LOAD); 130 } 131 132 /** 133 * If the layer should display the errors it encountered while loading the tiles. 134 * @return <code>true</code> to show errors. 135 */ 136 public boolean isShowErrors() { 137 return showErrors; 138 } 139 140 /** 141 * Sets the show errors proeprty. Fires a change event. 142 * @param showErrors 143 * @see #isShowErrors() 144 * @see #SHOW_ERRORS 145 */ 146 public void setShowErrors(boolean showErrors) { 147 this.showErrors = showErrors; 148 fireSettingsChange(SHOW_ERRORS); 149 } 150 151 /** 152 * Notifies all listeners that the paint settings have changed 153 * @param changedSetting The setting name 154 */ 155 private void fireSettingsChange(String changedSetting) { 156 DisplaySettingsChangeEvent e = new DisplaySettingsChangeEvent(changedSetting); 157 for (DisplaySettingsChangeListener l : listeners) { 158 l.displaySettingsChanged(e ); 159 } 160 } 161 162 /** 163 * Add a listener that listens to display settings changes. 164 * @param l The listener 165 */ 166 public void addSettingsChangeListener(DisplaySettingsChangeListener l) { 167 listeners.add(l); 168 } 169 170 /** 171 * Remove a listener that listens to display settings changes. 172 * @param l The listener 173 */ 174 public void removeSettingsChangeListener(DisplaySettingsChangeListener l) { 175 listeners.remove(l); 176 } 177 178 /** 179 * Stores the current settings object to the given hashmap. 180 * @param data The map to store the settings to. 181 * @see #loadFrom(Map) 182 */ 183 public void storeTo(Map<String, String> data) { 184 data.put(AUTO_LOAD, Boolean.toString(autoLoad)); 185 data.put(AUTO_ZOOM, Boolean.toString(autoZoom)); 186 data.put(SHOW_ERRORS, Boolean.toString(showErrors)); 187 } 188 189 /** 190 * Load the settings from the given data instance. 191 * @param data The data 192 * @see #storeTo(Map) 193 */ 194 public void loadFrom(Map<String, String> data) { 195 String doAutoLoad = data.get(AUTO_LOAD); 196 if (doAutoLoad != null) { 197 setAutoLoad(Boolean.parseBoolean(doAutoLoad)); 198 } 199 200 String doAutoZoom = data.get(AUTO_ZOOM); 201 if (doAutoZoom != null) { 202 setAutoZoom(Boolean.parseBoolean(doAutoZoom)); 203 } 204 205 String doShowErrors = data.get(SHOW_ERRORS); 206 if (doShowErrors != null) { 207 setShowErrors(Boolean.parseBoolean(doShowErrors)); 208 } 209 } 210 211 @Override 212 public int hashCode() { 213 final int prime = 31; 214 int result = 1; 215 result = prime * result + (autoLoad ? 1231 : 1237); 216 result = prime * result + (autoZoom ? 1231 : 1237); 217 result = prime * result + (showErrors ? 1231 : 1237); 218 return result; 219 } 220 221 @Override 222 public boolean equals(Object obj) { 223 if (this == obj) 224 return true; 225 if (obj == null) 226 return false; 227 if (getClass() != obj.getClass()) 228 return false; 229 TileSourceDisplaySettings other = (TileSourceDisplaySettings) obj; 230 if (autoLoad != other.autoLoad) 231 return false; 232 if (autoZoom != other.autoZoom) 233 return false; 234 if (showErrors != other.showErrors) 235 return false; 236 return true; 237 } 238 239 @Override 240 public String toString() { 241 return "TileSourceDisplaySettings [autoZoom=" + autoZoom + ", autoLoad=" + autoLoad + ", showErrors=" 242 + showErrors + "]"; 243 } 244 245 /** 246 * A listener that listens to changes to the {@link TileSourceDisplaySettings} object. 247 * @author Michael Zangl 248 * @since xxx 249 */ 250 public static interface DisplaySettingsChangeListener { 251 /** 252 * Called whenever the display settings have changed. 253 * @param e The change event. 254 */ 255 public void displaySettingsChanged(DisplaySettingsChangeEvent e); 256 } 257 258 /** 259 * An event that is created whenever the display settings change. 260 * @author Michael Zangl 261 * @since xxx 262 */ 263 public static final class DisplaySettingsChangeEvent { 264 private final String changedSetting; 265 266 DisplaySettingsChangeEvent(String changedSetting) { 267 super(); 268 this.changedSetting = changedSetting; 269 } 270 271 /** 272 * Gets the setting that was changed 273 * @return The name of the changed setting. 274 */ 275 public String getChangedSetting() { 276 return changedSetting; 277 } 278 279 @Override 280 public String toString() { 281 return "DispalySettingsChangeEvent [changedSetting=" + changedSetting + "]"; 282 } 283 } 284 } -
src/org/openstreetmap/josm/gui/preferences/imagery/TMSSettingsPanel.java
diff --git a/src/org/openstreetmap/josm/gui/preferences/imagery/TMSSettingsPanel.java b/src/org/openstreetmap/josm/gui/preferences/imagery/TMSSettingsPanel.java index 0e5eceb..3c61b69 100644
a b import javax.swing.SpinnerNumberModel; 13 13 14 14 import org.openstreetmap.josm.data.imagery.TMSCachedTileLoader; 15 15 import org.openstreetmap.josm.gui.layer.TMSLayer; 16 import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings; 16 17 import org.openstreetmap.josm.tools.GBC; 17 18 18 19 /** … … public class TMSSettingsPanel extends JPanel { 81 82 * Loads the TMS settings. 82 83 */ 83 84 public void loadSettings() { 84 this.autozoomActive.setSelected(T MSLayer.PROP_DEFAULT_AUTOZOOM.get());85 this.autoloadTiles.setSelected(T MSLayer.PROP_DEFAULT_AUTOLOAD.get());85 this.autozoomActive.setSelected(TileSourceDisplaySettings.PROP_AUTO_ZOOM.get()); 86 this.autoloadTiles.setSelected(TileSourceDisplaySettings.PROP_AUTO_LOAD.get()); 86 87 this.addToSlippyMapChosser.setSelected(TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.get()); 87 88 this.maxZoomLvl.setValue(TMSLayer.getMaxZoomLvl(null)); 88 89 this.minZoomLvl.setValue(TMSLayer.getMinZoomLvl(null)); … … public class TMSSettingsPanel extends JPanel { 101 102 restartRequired = true; 102 103 } 103 104 TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.put(this.addToSlippyMapChosser.isSelected()); 104 T MSLayer.PROP_DEFAULT_AUTOZOOM.put(this.autozoomActive.isSelected());105 T MSLayer.PROP_DEFAULT_AUTOLOAD.put(this.autoloadTiles.isSelected());105 TileSourceDisplaySettings.PROP_AUTO_ZOOM.put(this.autozoomActive.isSelected()); 106 TileSourceDisplaySettings.PROP_AUTO_LOAD.put(this.autoloadTiles.isSelected()); 106 107 TMSLayer.setMaxZoomLvl((Integer) this.maxZoomLvl.getValue()); 107 108 TMSLayer.setMinZoomLvl((Integer) this.minZoomLvl.getValue()); 108 109 -
src/org/openstreetmap/josm/io/session/ImagerySessionExporter.java
diff --git a/src/org/openstreetmap/josm/io/session/ImagerySessionExporter.java b/src/org/openstreetmap/josm/io/session/ImagerySessionExporter.java index 47b323c..239b837 100644
a b public class ImagerySessionExporter extends AbstractSessionExporter<ImageryLayer 81 81 ImageryPreferenceEntry e = new ImageryPreferenceEntry(layer.getInfo()); 82 82 Map<String, String> data = new LinkedHashMap<>(Preferences.serializeStruct(e, ImageryPreferenceEntry.class)); 83 83 if (layer instanceof AbstractTileSourceLayer) { 84 AbstractTileSourceLayer tsLayer = (AbstractTileSourceLayer) layer; 85 data.put("automatic-downloading", Boolean.toString(tsLayer.autoLoad)); 86 data.put("automatically-change-resolution", Boolean.toString(tsLayer.autoZoom)); 87 data.put("show-errors", Boolean.toString(tsLayer.showErrors)); 84 AbstractTileSourceLayer<?> tsLayer = (AbstractTileSourceLayer<?>) layer; 85 tsLayer.getDisplaySettings().storeTo(data); 88 86 } 89 87 data.put("dx", String.valueOf(layer.getDx())); 90 88 data.put("dy", String.valueOf(layer.getDy())); -
src/org/openstreetmap/josm/io/session/ImagerySessionImporter.java
diff --git a/src/org/openstreetmap/josm/io/session/ImagerySessionImporter.java b/src/org/openstreetmap/josm/io/session/ImagerySessionImporter.java index 262790d..2b68c71 100644
a b public class ImagerySessionImporter implements SessionLayerImporter { 50 50 ImageryInfo i = new ImageryInfo(prefEntry); 51 51 ImageryLayer layer = ImageryLayer.create(i); 52 52 if (layer instanceof AbstractTileSourceLayer) { 53 AbstractTileSourceLayer tsLayer = (AbstractTileSourceLayer) layer; 54 if (attributes.containsKey("automatic-downloading")) { 55 tsLayer.autoLoad = Boolean.parseBoolean(attributes.get("automatic-downloading")); 56 } 57 58 if (attributes.containsKey("automatically-change-resolution")) { 59 tsLayer.autoZoom = Boolean.parseBoolean(attributes.get("automatically-change-resolution")); 60 } 61 62 if (attributes.containsKey("show-errors")) { 63 tsLayer.showErrors = Boolean.parseBoolean(attributes.get("show-errors")); 64 } 53 AbstractTileSourceLayer<?> tsLayer = (AbstractTileSourceLayer<?>) layer; 54 tsLayer.getDisplaySettings().loadFrom(attributes); 65 55 } 66 56 if (attributes.containsKey("dx") && attributes.containsKey("dy")) { 67 57 layer.setOffset(Double.parseDouble(attributes.get("dx")), Double.parseDouble(attributes.get("dy")));
