- Timestamp:
- 2016-07-20T00:15:30+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java
r10547 r10568 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; … … 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; … … 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 */ … … 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); … … 130 132 private final AttributionSupport attribution = new AttributionSupport(); 131 133 private final TileHolder clickedTileHolder = new TileHolder(); 132 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 134 141 135 /** … … 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 … … 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 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; 179 195 } 180 196 … … 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 … … 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 } … … 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 … … 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 } … … 462 473 @Override 463 474 public void actionPerformed(ActionEvent ae) { 464 showErrors = !showErrors; 465 redraw(); 475 getDisplaySettings().setShowErrors(!getDisplaySettings().isShowErrors()); 466 476 } 467 477 … … 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 } … … 519 529 ZoomToBestAction() { 520 530 super(tr("Change resolution")); 521 setEnabled(! autoZoom&& getBestZoom() != currentZoomLevel);531 setEnabled(!getDisplaySettings().isAutoZoom() && getBestZoom() != currentZoomLevel); 522 532 } 523 533 … … 532 542 IncreaseZoomAction() { 533 543 super(tr("Increase zoom")); 534 setEnabled(! autoZoom&& zoomIncreaseAllowed());544 setEnabled(!getDisplaySettings().isAutoZoom() && zoomIncreaseAllowed()); 535 545 } 536 546 … … 545 555 DecreaseZoomAction() { 546 556 super(tr("Decrease zoom")); 547 setEnabled(! autoZoom&& zoomDecreaseAllowed());557 setEnabled(!getDisplaySettings().isAutoZoom() && zoomDecreaseAllowed()); 548 558 } 549 559 … … 695 705 Main.info("AbstractTileSourceLayer: estimated visible tiles: {0}, estimated cache size: {1}", visibileTiles, ret); 696 706 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 } 697 730 } 698 731 … … 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; … … 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(); … … 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()) { … … 1477 1510 1478 1511 int zoom = currentZoomLevel; 1479 if ( autoZoom) {1512 if (getDisplaySettings().isAutoZoom()) { 1480 1513 zoom = getBestZoom(); 1481 1514 } … … 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); … … 1523 1556 } 1524 1557 ts = dts.getTileSet(zoom); 1525 } else if ( autoZoom) {1558 } else if (getDisplaySettings().isAutoZoom()) { 1526 1559 setZoomLevel(zoom); 1527 1560 } … … 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 } … … 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 } … … 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 { -
trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java
r10378 r10568 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 /** … … 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"; … … 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 -
trunk/src/org/openstreetmap/josm/gui/layer/WMTSLayer.java
r9992 r10568 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 /** … … 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 … … 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 -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/TMSSettingsPanel.java
r8629 r10568 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 … … 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)); … … 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()); -
trunk/src/org/openstreetmap/josm/io/session/ImagerySessionExporter.java
r9983 r10568 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())); -
trunk/src/org/openstreetmap/josm/io/session/ImagerySessionImporter.java
r9455 r10568 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")) {
Note:
See TracChangeset
for help on using the changeset viewer.