source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/imagery/TMSSettingsPanel.java@ 11289

Last change on this file since 11289 was 10568, checked in by Don-vip, 8 years ago

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

  • Property svn:eol-style set to native
File size: 4.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.imagery;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.GridBagLayout;
7
8import javax.swing.JCheckBox;
9import javax.swing.JLabel;
10import javax.swing.JPanel;
11import javax.swing.JSpinner;
12import javax.swing.SpinnerNumberModel;
13
14import org.openstreetmap.josm.data.imagery.TMSCachedTileLoader;
15import org.openstreetmap.josm.gui.layer.TMSLayer;
16import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings;
17import org.openstreetmap.josm.tools.GBC;
18
19/**
20 * {@code JPanel} giving access to TMS settings.
21 * @since 5465
22 */
23public class TMSSettingsPanel extends JPanel {
24
25 // TMS Settings
26 private final JCheckBox autozoomActive = new JCheckBox();
27 private final JCheckBox autoloadTiles = new JCheckBox();
28 private final JSpinner minZoomLvl;
29 private final JSpinner maxZoomLvl;
30 private final JCheckBox addToSlippyMapChosser = new JCheckBox();
31
32 private final JSpinner maxConcurrentDownloads;
33 private final JSpinner maxDownloadsPerHost;
34
35
36 /**
37 * Constructs a new {@code TMSSettingsPanel}.
38 */
39 public TMSSettingsPanel() {
40 super(new GridBagLayout());
41 minZoomLvl = new JSpinner(new SpinnerNumberModel(
42 TMSLayer.PROP_MIN_ZOOM_LVL.get().intValue(), TMSLayer.MIN_ZOOM, TMSLayer.MAX_ZOOM, 1));
43 maxZoomLvl = new JSpinner(new SpinnerNumberModel(
44 TMSLayer.PROP_MAX_ZOOM_LVL.get().intValue(), TMSLayer.MIN_ZOOM, TMSLayer.MAX_ZOOM, 1));
45 maxConcurrentDownloads = new JSpinner(new SpinnerNumberModel(
46 TMSCachedTileLoader.THREAD_LIMIT.get().intValue(), 0, Integer.MAX_VALUE, 1));
47 maxDownloadsPerHost = new JSpinner(new SpinnerNumberModel(
48 TMSCachedTileLoader.HOST_LIMIT.get().intValue(), 0, Integer.MAX_VALUE, 1));
49
50
51 add(new JLabel(tr("Auto zoom by default: ")), GBC.std());
52 add(GBC.glue(5, 0), GBC.std());
53 add(autozoomActive, GBC.eol().fill(GBC.HORIZONTAL));
54
55 add(new JLabel(tr("Autoload tiles by default: ")), GBC.std());
56 add(GBC.glue(5, 0), GBC.std());
57 add(autoloadTiles, GBC.eol().fill(GBC.HORIZONTAL));
58
59 add(new JLabel(tr("Min. zoom level: ")), GBC.std());
60 add(GBC.glue(5, 0), GBC.std());
61 add(this.minZoomLvl, GBC.eol());
62
63 add(new JLabel(tr("Max. zoom level: ")), GBC.std());
64 add(GBC.glue(5, 0), GBC.std());
65 add(this.maxZoomLvl, GBC.eol());
66
67 add(new JLabel(tr("Add to slippymap chooser: ")), GBC.std());
68 add(GBC.glue(5, 0), GBC.std());
69 add(addToSlippyMapChosser, GBC.eol().fill(GBC.HORIZONTAL));
70
71 add(new JLabel(tr("Maximum concurrent downloads: ")), GBC.std());
72 add(GBC.glue(5, 0), GBC.std());
73 add(maxConcurrentDownloads, GBC.eol());
74
75 add(new JLabel(tr("Maximum concurrent downloads per host: ")), GBC.std());
76 add(GBC.glue(5, 0), GBC.std());
77 add(maxDownloadsPerHost, GBC.eol());
78
79 }
80
81 /**
82 * Loads the TMS settings.
83 */
84 public void loadSettings() {
85 this.autozoomActive.setSelected(TileSourceDisplaySettings.PROP_AUTO_ZOOM.get());
86 this.autoloadTiles.setSelected(TileSourceDisplaySettings.PROP_AUTO_LOAD.get());
87 this.addToSlippyMapChosser.setSelected(TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.get());
88 this.maxZoomLvl.setValue(TMSLayer.getMaxZoomLvl(null));
89 this.minZoomLvl.setValue(TMSLayer.getMinZoomLvl(null));
90 this.maxConcurrentDownloads.setValue(TMSCachedTileLoader.THREAD_LIMIT.get());
91 this.maxDownloadsPerHost.setValue(TMSCachedTileLoader.HOST_LIMIT.get());
92 }
93
94 /**
95 * Saves the TMS settings.
96 * @return true when restart is required
97 */
98 public boolean saveSettings() {
99 boolean restartRequired = false;
100
101 if (!TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.get().equals(this.addToSlippyMapChosser.isSelected())) {
102 restartRequired = true;
103 }
104 TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.put(this.addToSlippyMapChosser.isSelected());
105 TileSourceDisplaySettings.PROP_AUTO_ZOOM.put(this.autozoomActive.isSelected());
106 TileSourceDisplaySettings.PROP_AUTO_LOAD.put(this.autoloadTiles.isSelected());
107 TMSLayer.setMaxZoomLvl((Integer) this.maxZoomLvl.getValue());
108 TMSLayer.setMinZoomLvl((Integer) this.minZoomLvl.getValue());
109
110 if (!TMSCachedTileLoader.THREAD_LIMIT.get().equals(this.maxConcurrentDownloads.getValue())) {
111 TMSCachedTileLoader.THREAD_LIMIT.put((Integer) this.maxConcurrentDownloads.getValue());
112 restartRequired = true;
113 }
114
115 if (!TMSCachedTileLoader.HOST_LIMIT.get().equals(this.maxDownloadsPerHost.getValue())) {
116 TMSCachedTileLoader.HOST_LIMIT.put((Integer) this.maxDownloadsPerHost.getValue());
117 restartRequired = true;
118 }
119
120 return restartRequired;
121 }
122}
Note: See TracBrowser for help on using the repository browser.