Ticket #13169: patch-mapview-extract-tile-source-preferences.patch

File patch-mapview-extract-tile-source-preferences.patch, 31.4 KB (added by michael2402, 6 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; 
    7272import org.openstreetmap.josm.data.imagery.TMSCachedTileLoader;
    7373import org.openstreetmap.josm.data.imagery.TileLoaderFactory;
    7474import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    75 import org.openstreetmap.josm.data.preferences.BooleanProperty;
    7675import org.openstreetmap.josm.data.preferences.IntegerProperty;
    7776import org.openstreetmap.josm.gui.ExtendedDialog;
    7877import org.openstreetmap.josm.gui.MapFrame;
    import org.openstreetmap.josm.gui.PleaseWaitRunnable; 
    8281import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    8382import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
    8483import org.openstreetmap.josm.gui.layer.imagery.ImageryFilterSettings.FilterChangeListener;
     84import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings;
     85import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings.DisplaySettingsChangeEvent;
     86import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings.DisplaySettingsChangeListener;
    8587import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    8688import org.openstreetmap.josm.gui.util.GuiHelper;
    8789import org.openstreetmap.josm.io.WMSLayerImporter;
    import org.openstreetmap.josm.tools.GBC; 
    99101 * @since 8526 (copied from TMSLayer)
    100102 */
    101103public abstract class AbstractTileSourceLayer<T extends AbstractTMSTileSource> extends ImageryLayer
    102 implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeListener {
     104implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeListener, DisplaySettingsChangeListener {
    103105    private static final String PREFERENCE_PREFIX = "imagery.generic";
     106    /**
     107     * Registers all setting properties
     108     */
     109    static {
     110        new TileSourceDisplaySettings();
     111    }
    104112
    105113    /** maximum zoom level supported */
    106114    public static final int MAX_ZOOM = 30;
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    108116    public static final int MIN_ZOOM = 2;
    109117    private static final Font InfoFont = new Font("sansserif", Font.BOLD, 13);
    110118
    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);
    117119    /** minimum zoom level to show to user */
    118120    public static final IntegerProperty PROP_MIN_ZOOM_LVL = new IntegerProperty(PREFERENCE_PREFIX + ".min_zoom_lvl", 2);
    119121    /** maximum zoom level to show to user */
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    130132    private final AttributionSupport attribution = new AttributionSupport();
    131133    private final TileHolder clickedTileHolder = new TileHolder();
    132134
    133     // needed public access for session exporter
    134     /** 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 
    141135    /**
    142136     * Offset between calculated zoom level and zoom level used to download and show tiles. Negative values will result in
    143137     * lower resolution of imagery useful in "retina" displays, positive values will result in higher resolution
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    167161            }
    168162        }
    169163    };
     164
     165    private final TileSourceDisplaySettings displaySettings = createDisplaySettings();
     166
    170167    /**
    171168     * Creates Tile Source based Imagery Layer based on Imagery Info
    172169     * @param info imagery info
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    176173        setBackgroundLayer(true);
    177174        this.setVisible(true);
    178175        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;
    179195    }
    180196
    181197    @Override
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    410426
    411427        @Override
    412428        public void actionPerformed(ActionEvent ae) {
    413             autoZoom = !autoZoom;
    414             if (autoZoom && getBestZoom() != currentZoomLevel) {
    415                 setZoomLevel(getBestZoom());
    416                 redraw();
    417             }
     429            getDisplaySettings().setAutoZoom(!getDisplaySettings().isAutoZoom());
    418430        }
    419431
    420432        @Override
    421433        public Component createMenuComponent() {
    422434            JCheckBoxMenuItem item = new JCheckBoxMenuItem(this);
    423             item.setSelected(autoZoom);
     435            item.setSelected(getDisplaySettings().isAutoZoom());
    424436            return item;
    425437        }
    426438
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    437449
    438450        @Override
    439451        public void actionPerformed(ActionEvent ae) {
    440             autoLoad = !autoLoad;
    441             if (autoLoad) redraw();
     452            getDisplaySettings().setAutoLoad(!getDisplaySettings().isAutoLoad());
    442453        }
    443454
    444455        @Override
    445456        public Component createMenuComponent() {
    446457            JCheckBoxMenuItem item = new JCheckBoxMenuItem(this);
    447             item.setSelected(autoLoad);
     458            item.setSelected(getDisplaySettings().isAutoLoad());
    448459            return item;
    449460        }
    450461
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    461472
    462473        @Override
    463474        public void actionPerformed(ActionEvent ae) {
    464             showErrors = !showErrors;
    465             redraw();
     475            getDisplaySettings().setShowErrors(!getDisplaySettings().isShowErrors());
    466476        }
    467477
    468478        @Override
    469479        public Component createMenuComponent() {
    470480            JCheckBoxMenuItem item = new JCheckBoxMenuItem(this);
    471             item.setSelected(showErrors);
     481            item.setSelected(getDisplaySettings().isShowErrors());
    472482            return item;
    473483        }
    474484
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    518528    private class ZoomToBestAction extends AbstractAction {
    519529        ZoomToBestAction() {
    520530            super(tr("Change resolution"));
    521             setEnabled(!autoZoom && getBestZoom() != currentZoomLevel);
     531            setEnabled(!getDisplaySettings().isAutoZoom() && getBestZoom() != currentZoomLevel);
    522532        }
    523533
    524534        @Override
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    531541    private class IncreaseZoomAction extends AbstractAction {
    532542        IncreaseZoomAction() {
    533543            super(tr("Increase zoom"));
    534             setEnabled(!autoZoom && zoomIncreaseAllowed());
     544            setEnabled(!getDisplaySettings().isAutoZoom() && zoomIncreaseAllowed());
    535545        }
    536546
    537547        @Override
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    544554    private class DecreaseZoomAction extends AbstractAction {
    545555        DecreaseZoomAction() {
    546556            super(tr("Decrease zoom"));
    547             setEnabled(!autoZoom && zoomDecreaseAllowed());
     557            setEnabled(!getDisplaySettings().isAutoZoom() && zoomDecreaseAllowed());
    548558        }
    549559
    550560        @Override
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    696706        return ret;
    697707    }
    698708
     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
    699732    /**
    700733     * Checks zoom level against settings
    701734     * @param maxZoomLvl zoom level to check
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    11421175            texty += 1 + fontHeight;
    11431176        }*/
    11441177
    1145         if (tile.hasError() && showErrors) {
     1178        if (tile.hasError() && getDisplaySettings().isShowErrors()) {
    11461179            myDrawString(g, tr("Error") + ": " + tr(tile.getErrorMessage()), p.x + 2, texty);
    11471180            //texty += 1 + fontHeight;
    11481181        }
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    13681401        }
    13691402
    13701403        private void loadAllTiles(boolean force) {
    1371             if (!autoLoad && !force)
     1404            if (!getDisplaySettings().isAutoLoad() && !force)
    13721405                return;
    13731406            List<Tile> allTiles = allTilesCreate();
    13741407            Collections.sort(allTiles, getTileDistanceComparator());
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    13781411        }
    13791412
    13801413        private void loadAllErrorTiles(boolean force) {
    1381             if (!autoLoad && !force)
     1414            if (!getDisplaySettings().isAutoLoad() && !force)
    13821415                return;
    13831416            for (Tile t : this.allTilesCreate()) {
    13841417                if (t.hasError()) {
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    14761509        needRedraw = false;
    14771510
    14781511        int zoom = currentZoomLevel;
    1479         if (autoZoom) {
     1512        if (getDisplaySettings().isAutoZoom()) {
    14801513            zoom = getBestZoom();
    14811514        }
    14821515
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    14861519        int displayZoomLevel = zoom;
    14871520
    14881521        boolean noTilesAtZoom = false;
    1489         if (autoZoom && autoLoad) {
     1522        if (getDisplaySettings().isAutoZoom() && getDisplaySettings().isAutoLoad()) {
    14901523            // Auto-detection of tilesource maxzoom (currently fully works only for Bing)
    14911524            TileSetInfo tsi = dts.getTileSetInfo(zoom);
    14921525            if (!tsi.hasVisibleTiles && (!tsi.hasLoadingTiles || tsi.hasOverzoomedTiles)) {
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    15221555                tsi = dts.getTileSetInfo(zoom);
    15231556            }
    15241557            ts = dts.getTileSet(zoom);
    1525         } else if (autoZoom) {
     1558        } else if (getDisplaySettings().isAutoZoom()) {
    15261559            setZoomLevel(zoom);
    15271560        }
    15281561
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    15411574        List<Tile> missedTiles = this.paintTileImages(g, ts, displayZoomLevel, null);
    15421575        int[] otherZooms = {-1, 1, -2, 2, -3, -4, -5};
    15431576        for (int zoomOffset : otherZooms) {
    1544             if (!autoZoom) {
     1577            if (!getDisplaySettings().isAutoZoom()) {
    15451578                break;
    15461579            }
    15471580            int newzoom = displayZoomLevel + zoomOffset;
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    15971630            myDrawString(g, tr("zoom in to load any tiles"), 120, 120);
    15981631        } else if (ts.tooLarge()) {
    15991632            myDrawString(g, tr("zoom in to load more tiles"), 120, 120);
    1600         } else if (!autoZoom && ts.tooSmall()) {
     1633        } else if (!getDisplaySettings().isAutoZoom() && ts.tooSmall()) {
    16011634            myDrawString(g, tr("increase tiles zoom level (change resolution) to see more detail"), 120, 120);
    16021635        }
    16031636
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi 
    17091742
    17101743    @Override
    17111744    public String getToolTipText() {
    1712         if (autoLoad) {
     1745        if (getDisplaySettings().isAutoLoad()) {
    17131746            return tr("{0} ({1}), automatically downloading in zoom {2}", this.getClass().getSimpleName(), getName(), currentZoomLevel);
    17141747        } else {
    17151748            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; 
    2828import org.openstreetmap.josm.data.preferences.IntegerProperty;
    2929import org.openstreetmap.josm.data.projection.Projection;
    3030import org.openstreetmap.josm.gui.ExtendedDialog;
     31import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings;
    3132
    3233/**
    3334 * This is a layer that grabs the current screen from an WMS server. The data
    import org.openstreetmap.josm.gui.ExtendedDialog; 
    3536 *
    3637 */
    3738public 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    }
    3946
    4047    /** 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);
    4249
    4350    /** 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);
    4552
    4653    private static final String CACHE_REGION_NAME = "WMS";
    4754
    public class WMSLayer extends AbstractCachedTileSourceLayer<TemplatedWMSTileSour 
    5461    public WMSLayer(ImageryInfo info) {
    5562        super(info);
    5663        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);
    5869    }
    5970
    6071    @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; 
    1212import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
    1313import org.openstreetmap.josm.data.imagery.WMSCachedTileLoader;
    1414import org.openstreetmap.josm.data.imagery.WMTSTileSource;
    15 import org.openstreetmap.josm.data.preferences.BooleanProperty;
    1615import org.openstreetmap.josm.data.projection.Projection;
     16import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings;
    1717
    1818/**
    1919 * WMTS layer based on AbstractTileSourceLayer. Overrides few methods to align WMTS to Tile based computations
    import org.openstreetmap.josm.data.projection.Projection; 
    2626 *
    2727 */
    2828public class WMTSLayer extends AbstractCachedTileSourceLayer<WMTSTileSource> implements NativeScaleLayer {
     29    private static final String PREFERENCE_PREFIX = "imagery.wmts";
     30
    2931    /**
    30      * default setting of autozoom per layer
     32     * Registers all setting properties
    3133     */
    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
    3338    private static final String CACHE_REGION_NAME = "WMTS";
    3439
    3540    /**
    public class WMTSLayer extends AbstractCachedTileSourceLayer<WMTSTileSource> imp 
    3843     */
    3944    public WMTSLayer(ImageryInfo info) {
    4045        super(info);
    41         autoZoom = PROP_DEFAULT_AUTOZOOM_WMTS.get();
     46    }
     47
     48    @Override
     49    protected TileSourceDisplaySettings createDisplaySettings() {
     50        return new TileSourceDisplaySettings(PREFERENCE_PREFIX);
    4251    }
    4352
    4453    @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.
     2package org.openstreetmap.josm.gui.layer.imagery;
     3
     4import java.util.Map;
     5import java.util.concurrent.CopyOnWriteArrayList;
     6
     7import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
     8import org.openstreetmap.josm.Main;
     9import org.openstreetmap.josm.data.preferences.BooleanProperty;
     10import 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 */
     19public 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; 
    1313
    1414import org.openstreetmap.josm.data.imagery.TMSCachedTileLoader;
    1515import org.openstreetmap.josm.gui.layer.TMSLayer;
     16import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings;
    1617import org.openstreetmap.josm.tools.GBC;
    1718
    1819/**
    public class TMSSettingsPanel extends JPanel { 
    8182     * Loads the TMS settings.
    8283     */
    8384    public void loadSettings() {
    84         this.autozoomActive.setSelected(TMSLayer.PROP_DEFAULT_AUTOZOOM.get());
    85         this.autoloadTiles.setSelected(TMSLayer.PROP_DEFAULT_AUTOLOAD.get());
     85        this.autozoomActive.setSelected(TileSourceDisplaySettings.PROP_AUTO_ZOOM.get());
     86        this.autoloadTiles.setSelected(TileSourceDisplaySettings.PROP_AUTO_LOAD.get());
    8687        this.addToSlippyMapChosser.setSelected(TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.get());
    8788        this.maxZoomLvl.setValue(TMSLayer.getMaxZoomLvl(null));
    8889        this.minZoomLvl.setValue(TMSLayer.getMinZoomLvl(null));
    public class TMSSettingsPanel extends JPanel { 
    101102            restartRequired = true;
    102103        }
    103104        TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.put(this.addToSlippyMapChosser.isSelected());
    104         TMSLayer.PROP_DEFAULT_AUTOZOOM.put(this.autozoomActive.isSelected());
    105         TMSLayer.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());
    106107        TMSLayer.setMaxZoomLvl((Integer) this.maxZoomLvl.getValue());
    107108        TMSLayer.setMinZoomLvl((Integer) this.minZoomLvl.getValue());
    108109
  • 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 
    8181        ImageryPreferenceEntry e = new ImageryPreferenceEntry(layer.getInfo());
    8282        Map<String, String> data = new LinkedHashMap<>(Preferences.serializeStruct(e, ImageryPreferenceEntry.class));
    8383        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);
    8886        }
    8987        data.put("dx", String.valueOf(layer.getDx()));
    9088        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 { 
    5050        ImageryInfo i = new ImageryInfo(prefEntry);
    5151        ImageryLayer layer = ImageryLayer.create(i);
    5252        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);
    6555        }
    6656        if (attributes.containsKey("dx") && attributes.containsKey("dy")) {
    6757            layer.setOffset(Double.parseDouble(attributes.get("dx")), Double.parseDouble(attributes.get("dy")));