Ignore:
Timestamp:
2016-07-20T00:15:30+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #13169 - Extract imagery layer settings to new class (patch by michael2402, modified) - gsoc-core

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

Legend:

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

    r10547 r10568  
    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;
     
    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;
     
    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 */
     
    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);
     
    130132    private final AttributionSupport attribution = new AttributionSupport();
    131133    private final TileHolder clickedTileHolder = new TileHolder();
    132 
    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();
    140134
    141135    /**
     
    168162        }
    169163    };
     164
     165    private final TileSourceDisplaySettings displaySettings = createDisplaySettings();
     166
    170167    /**
    171168     * Creates Tile Source based Imagery Layer based on Imagery Info
     
    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 10568
     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 10568
     192     */
     193    public TileSourceDisplaySettings getDisplaySettings() {
     194        return displaySettings;
    179195    }
    180196
     
    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
     
    421433        public Component createMenuComponent() {
    422434            JCheckBoxMenuItem item = new JCheckBoxMenuItem(this);
    423             item.setSelected(autoZoom);
     435            item.setSelected(getDisplaySettings().isAutoZoom());
    424436            return item;
    425437        }
     
    438450        @Override
    439451        public void actionPerformed(ActionEvent ae) {
    440             autoLoad = !autoLoad;
    441             if (autoLoad) redraw();
     452            getDisplaySettings().setAutoLoad(!getDisplaySettings().isAutoLoad());
    442453        }
    443454
     
    445456        public Component createMenuComponent() {
    446457            JCheckBoxMenuItem item = new JCheckBoxMenuItem(this);
    447             item.setSelected(autoLoad);
     458            item.setSelected(getDisplaySettings().isAutoLoad());
    448459            return item;
    449460        }
     
    462473        @Override
    463474        public void actionPerformed(ActionEvent ae) {
    464             showErrors = !showErrors;
    465             redraw();
     475            getDisplaySettings().setShowErrors(!getDisplaySettings().isShowErrors());
    466476        }
    467477
     
    469479        public Component createMenuComponent() {
    470480            JCheckBoxMenuItem item = new JCheckBoxMenuItem(this);
    471             item.setSelected(showErrors);
     481            item.setSelected(getDisplaySettings().isShowErrors());
    472482            return item;
    473483        }
     
    519529        ZoomToBestAction() {
    520530            super(tr("Change resolution"));
    521             setEnabled(!autoZoom && getBestZoom() != currentZoomLevel);
     531            setEnabled(!getDisplaySettings().isAutoZoom() && getBestZoom() != currentZoomLevel);
    522532        }
    523533
     
    532542        IncreaseZoomAction() {
    533543            super(tr("Increase zoom"));
    534             setEnabled(!autoZoom && zoomIncreaseAllowed());
     544            setEnabled(!getDisplaySettings().isAutoZoom() && zoomIncreaseAllowed());
    535545        }
    536546
     
    545555        DecreaseZoomAction() {
    546556            super(tr("Decrease zoom"));
    547             setEnabled(!autoZoom && zoomDecreaseAllowed());
     557            setEnabled(!getDisplaySettings().isAutoZoom() && zoomDecreaseAllowed());
    548558        }
    549559
     
    695705        Main.info("AbstractTileSourceLayer: estimated visible tiles: {0}, estimated cache size: {1}", visibileTiles, ret);
    696706        return ret;
     707    }
     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        }
    697730    }
    698731
     
    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;
     
    13691402
    13701403        private void loadAllTiles(boolean force) {
    1371             if (!autoLoad && !force)
     1404            if (!getDisplaySettings().isAutoLoad() && !force)
    13721405                return;
    13731406            List<Tile> allTiles = allTilesCreate();
     
    13791412
    13801413        private void loadAllErrorTiles(boolean force) {
    1381             if (!autoLoad && !force)
     1414            if (!getDisplaySettings().isAutoLoad() && !force)
    13821415                return;
    13831416            for (Tile t : this.allTilesCreate()) {
     
    14771510
    14781511        int zoom = currentZoomLevel;
    1479         if (autoZoom) {
     1512        if (getDisplaySettings().isAutoZoom()) {
    14801513            zoom = getBestZoom();
    14811514        }
     
    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);
     
    15231556            }
    15241557            ts = dts.getTileSet(zoom);
    1525         } else if (autoZoom) {
     1558        } else if (getDisplaySettings().isAutoZoom()) {
    15261559            setZoomLevel(zoom);
    15271560        }
     
    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            }
     
    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        }
     
    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 {
  • trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java

    r10378 r10568  
    2929import org.openstreetmap.josm.data.projection.Projection;
    3030import org.openstreetmap.josm.gui.ExtendedDialog;
     31import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings;
    3132
    3233/**
     
    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";
     
    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
  • trunk/src/org/openstreetmap/josm/gui/layer/WMTSLayer.java

    r9992 r10568  
    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/**
     
    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
     
    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
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/TMSSettingsPanel.java

    r8629 r10568  
    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
     
    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));
     
    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());
Note: See TracChangeset for help on using the changeset viewer.