001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.preferences.imagery; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.awt.GridBagLayout; 007 008import javax.swing.Box; 009import javax.swing.JCheckBox; 010import javax.swing.JLabel; 011import javax.swing.JPanel; 012import javax.swing.JSpinner; 013import javax.swing.SpinnerNumberModel; 014 015import org.openstreetmap.josm.data.imagery.WMSCachedTileLoader; 016import org.openstreetmap.josm.gui.layer.WMSLayer; 017import org.openstreetmap.josm.tools.GBC; 018import org.openstreetmap.josm.tools.Utils; 019 020/** 021 * {@code JPanel} giving access to WMS settings. 022 * @since 5465 023 */ 024public class WMSSettingsPanel extends JPanel { 025 026 private static final int IMAGE_SIZE_MIN = 1; 027 private static final int IMAGE_SIZE_MAX = 4096; 028 private static final int THREADS_MIN = 1; 029 private static final int THREADS_MAX = 30; 030 031 // WMS Settings 032 private final JCheckBox autozoomActive; 033 private final JSpinner spinSimConn; 034 private final JSpinner tileSize; 035 036 /** 037 * Constructs a new {@code WMSSettingsPanel}. 038 */ 039 public WMSSettingsPanel() { 040 super(new GridBagLayout()); 041 042 // Auto zoom 043 autozoomActive = new JCheckBox(); 044 add(new JLabel(tr("Auto zoom by default: ")), GBC.std()); 045 add(GBC.glue(5, 0), GBC.std()); 046 add(autozoomActive, GBC.eol().fill(GBC.HORIZONTAL)); 047 048 // Simultaneous connections 049 add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL)); 050 JLabel labelSimConn = new JLabel(tr("Simultaneous connections:")); 051 int threadLimitValue = Utils.clamp(WMSCachedTileLoader.THREAD_LIMIT.get(), THREADS_MIN, THREADS_MAX); 052 spinSimConn = new JSpinner(new SpinnerNumberModel(threadLimitValue, THREADS_MIN, THREADS_MAX, 1)); 053 labelSimConn.setLabelFor(spinSimConn); 054 add(labelSimConn, GBC.std()); 055 add(GBC.glue(5, 0), GBC.std()); 056 add(spinSimConn, GBC.eol()); 057 058 // Tile size 059 JLabel labelTileSize = new JLabel(tr("Tile size:")); 060 int tileSizeValue = Utils.clamp(WMSLayer.PROP_IMAGE_SIZE.get(), IMAGE_SIZE_MIN, IMAGE_SIZE_MAX); 061 tileSize = new JSpinner(new SpinnerNumberModel(tileSizeValue, IMAGE_SIZE_MIN, IMAGE_SIZE_MAX, 128)); 062 labelTileSize.setLabelFor(tileSize); 063 add(labelTileSize, GBC.std()); 064 add(GBC.glue(5, 0), GBC.std()); 065 add(tileSize, GBC.eol()); 066 } 067 068 /** 069 * Loads the WMS settings. 070 */ 071 public void loadSettings() { 072 this.autozoomActive.setSelected(WMSLayer.PROP_DEFAULT_AUTOZOOM.get()); 073 this.spinSimConn.setValue(WMSCachedTileLoader.THREAD_LIMIT.get()); 074 this.tileSize.setValue(WMSLayer.PROP_IMAGE_SIZE.get()); 075 } 076 077 /** 078 * Saves the WMS settings. 079 * @return true when restart is required 080 */ 081 public boolean saveSettings() { 082 WMSLayer.PROP_DEFAULT_AUTOZOOM.put(this.autozoomActive.isSelected()); 083 WMSCachedTileLoader.THREAD_LIMIT.put((Integer) spinSimConn.getModel().getValue()); 084 WMSLayer.PROP_IMAGE_SIZE.put((Integer) this.tileSize.getModel().getValue()); 085 086 return false; 087 } 088}