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

Last change on this file since 8426 was 8403, checked in by wiktorn, 9 years ago

Rework the per host limit, so the queue will never reject the submited job. Also - sort tiles during loading in TMS, so center tiles will be loaded first. closes: #11437

  • Property svn:eol-style set to native
File size: 5.9 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.data.imagery.TMSCachedTileLoaderJob;
16import org.openstreetmap.josm.gui.layer.TMSLayer;
17import org.openstreetmap.josm.gui.widgets.JosmTextField;
18import org.openstreetmap.josm.tools.GBC;
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 private final JosmTextField tilecacheDir = new JosmTextField();
33 private final JSpinner maxElementsOnDisk;
34 private final JSpinner maxConcurrentDownloads;
35 private final JSpinner maxDownloadsPerHost;
36
37
38 /**
39 * Constructs a new {@code TMSSettingsPanel}.
40 */
41 public TMSSettingsPanel() {
42 super(new GridBagLayout());
43 minZoomLvl = new JSpinner(new SpinnerNumberModel(TMSLayer.DEFAULT_MIN_ZOOM, TMSLayer.MIN_ZOOM, TMSLayer.MAX_ZOOM, 1));
44 maxZoomLvl = new JSpinner(new SpinnerNumberModel(TMSLayer.DEFAULT_MAX_ZOOM, TMSLayer.MIN_ZOOM, TMSLayer.MAX_ZOOM, 1));
45 maxElementsOnDisk = new JSpinner(new SpinnerNumberModel(TMSCachedTileLoader.MAX_OBJECTS_ON_DISK.get().intValue(), 0, Integer.MAX_VALUE, 1));
46 maxConcurrentDownloads = new JSpinner(new SpinnerNumberModel(TMSCachedTileLoaderJob.THREAD_LIMIT.get().intValue(), 0, Integer.MAX_VALUE, 1));
47 maxDownloadsPerHost = new JSpinner(new SpinnerNumberModel(TMSCachedTileLoader.HOST_LIMIT.get().intValue(), 0, Integer.MAX_VALUE, 1));
48
49 add(new JLabel(tr("Auto zoom by default: ")), GBC.std());
50 add(GBC.glue(5, 0), GBC.std());
51 add(autozoomActive, GBC.eol().fill(GBC.HORIZONTAL));
52
53 add(new JLabel(tr("Autoload tiles by default: ")), GBC.std());
54 add(GBC.glue(5, 0), GBC.std());
55 add(autoloadTiles, GBC.eol().fill(GBC.HORIZONTAL));
56
57 add(new JLabel(tr("Min. zoom level: ")), GBC.std());
58 add(GBC.glue(5, 0), GBC.std());
59 add(this.minZoomLvl, GBC.eol());
60
61 add(new JLabel(tr("Max. zoom level: ")), GBC.std());
62 add(GBC.glue(5, 0), GBC.std());
63 add(this.maxZoomLvl, GBC.eol());
64
65 add(new JLabel(tr("Add to slippymap chooser: ")), GBC.std());
66 add(GBC.glue(5, 0), GBC.std());
67 add(addToSlippyMapChosser, GBC.eol().fill(GBC.HORIZONTAL));
68
69 add(new JLabel(tr("Tile cache directory: ")), GBC.std());
70 add(GBC.glue(5, 0), GBC.std());
71 add(tilecacheDir, GBC.eol().fill(GBC.HORIZONTAL));
72
73 add(new JLabel(tr("Maximum concurrent downloads: ")), GBC.std());
74 add(GBC.glue(5, 0), GBC.std());
75 add(maxConcurrentDownloads, GBC.eol());
76
77 add(new JLabel(tr("Maximum concurrent downloads per host: ")), GBC.std());
78 add(GBC.glue(5, 0), GBC.std());
79 add(maxDownloadsPerHost, GBC.eol());
80
81
82 add(new JLabel(tr("Maximum elements in disk cache: ")), GBC.std());
83 add(GBC.glue(5, 0), GBC.std());
84 add(this.maxElementsOnDisk, GBC.eol());
85
86 }
87
88 /**
89 * Loads the TMS settings.
90 */
91 public void loadSettings() {
92 this.autozoomActive.setSelected(TMSLayer.PROP_DEFAULT_AUTOZOOM.get());
93 this.autoloadTiles.setSelected(TMSLayer.PROP_DEFAULT_AUTOLOAD.get());
94 this.addToSlippyMapChosser.setSelected(TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.get());
95 this.maxZoomLvl.setValue(TMSLayer.getMaxZoomLvl(null));
96 this.minZoomLvl.setValue(TMSLayer.getMinZoomLvl(null));
97 this.tilecacheDir.setText(TMSLayer.PROP_TILECACHE_DIR.get());
98 this.maxElementsOnDisk.setValue(TMSCachedTileLoader.MAX_OBJECTS_ON_DISK.get());
99 this.maxConcurrentDownloads.setValue(TMSCachedTileLoaderJob.THREAD_LIMIT.get());
100 this.maxDownloadsPerHost.setValue(TMSCachedTileLoader.HOST_LIMIT.get());
101 }
102
103 /**
104 * Saves the TMS settings.
105 * @return true when restart is required
106 */
107 public boolean saveSettings() {
108 boolean restartRequired = false;
109
110 if (TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.get() != this.addToSlippyMapChosser.isSelected()) {
111 restartRequired = true;
112 }
113 TMSLayer.PROP_ADD_TO_SLIPPYMAP_CHOOSER.put(this.addToSlippyMapChosser.isSelected());
114 TMSLayer.PROP_DEFAULT_AUTOZOOM.put(this.autozoomActive.isSelected());
115 TMSLayer.PROP_DEFAULT_AUTOLOAD.put(this.autoloadTiles.isSelected());
116 TMSLayer.setMaxZoomLvl((Integer)this.maxZoomLvl.getValue());
117 TMSLayer.setMinZoomLvl((Integer)this.minZoomLvl.getValue());
118
119 if (!TMSCachedTileLoader.MAX_OBJECTS_ON_DISK.get().equals(this.maxElementsOnDisk.getValue())) {
120 TMSCachedTileLoader.MAX_OBJECTS_ON_DISK.put((Integer) this.maxElementsOnDisk.getValue());
121 restartRequired = true;
122 }
123
124 if(!TMSCachedTileLoader.THREAD_LIMIT.get().equals(this.maxConcurrentDownloads.getValue())) {
125 TMSCachedTileLoader.THREAD_LIMIT.put((Integer) this.maxConcurrentDownloads.getValue());
126 restartRequired = true;
127 }
128
129 if(!TMSCachedTileLoader.HOST_LIMIT.get().equals(this.maxDownloadsPerHost.getValue())) {
130 TMSCachedTileLoader.HOST_LIMIT.put((Integer) this.maxDownloadsPerHost.getValue());
131 restartRequired = true;
132 }
133
134 if (!TMSLayer.PROP_TILECACHE_DIR.get().equals(this.tilecacheDir.getText())) {
135 restartRequired = true;
136 TMSLayer.PROP_TILECACHE_DIR.put(this.tilecacheDir.getText());
137 }
138
139 return restartRequired;
140 }
141}
Note: See TracBrowser for help on using the repository browser.