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

Last change on this file since 15586 was 15586, checked in by Don-vip, 4 years ago

code cleanup

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