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.WMSCachedTileLoaderJob; 016import org.openstreetmap.josm.gui.layer.WMSLayer; 017import org.openstreetmap.josm.tools.GBC; 018 019/** 020 * {@code JPanel} giving access to WMS settings. 021 * @since 5465 022 */ 023public class WMSSettingsPanel extends JPanel { 024 025 // WMS Settings 026 private final JCheckBox autozoomActive; 027 private final JSpinner spinSimConn; 028 private final JSpinner tileSize; 029 030 /** 031 * Constructs a new {@code WMSSettingsPanel}. 032 */ 033 public WMSSettingsPanel() { 034 super(new GridBagLayout()); 035 036 // Auto zoom 037 autozoomActive = new JCheckBox(); 038 add(new JLabel(tr("Auto zoom by default: ")), GBC.std()); 039 add(GBC.glue(5, 0), GBC.std()); 040 add(autozoomActive, GBC.eol().fill(GBC.HORIZONTAL)); 041 042 // Simultaneous connections 043 add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL)); 044 JLabel labelSimConn = new JLabel(tr("Simultaneous connections:")); 045 spinSimConn = new JSpinner(new SpinnerNumberModel(WMSCachedTileLoaderJob.THREAD_LIMIT.get().intValue(), 1, 30, 1)); 046 labelSimConn.setLabelFor(spinSimConn); 047 add(labelSimConn, GBC.std()); 048 add(GBC.glue(5, 0), GBC.std()); 049 add(spinSimConn, GBC.eol()); 050 051 // Tile size 052 JLabel labelTileSize = new JLabel(tr("Tile size:")); 053 tileSize = new JSpinner(new SpinnerNumberModel(WMSLayer.PROP_IMAGE_SIZE.get().intValue(), 1, 4096, 128)); 054 labelTileSize.setLabelFor(tileSize); 055 add(labelTileSize, GBC.std()); 056 add(GBC.glue(5, 0), GBC.std()); 057 add(tileSize, GBC.eol()); 058 } 059 060 /** 061 * Loads the WMS settings. 062 */ 063 public void loadSettings() { 064 this.autozoomActive.setSelected(WMSLayer.PROP_DEFAULT_AUTOZOOM.get()); 065 this.spinSimConn.setValue(WMSCachedTileLoaderJob.THREAD_LIMIT.get()); 066 this.tileSize.setValue(WMSLayer.PROP_IMAGE_SIZE.get()); 067 } 068 069 /** 070 * Saves the WMS settings. 071 * @return true when restart is required 072 */ 073 public boolean saveSettings() { 074 WMSLayer.PROP_DEFAULT_AUTOZOOM.put(this.autozoomActive.isSelected()); 075 WMSCachedTileLoaderJob.THREAD_LIMIT.put((Integer) spinSimConn.getModel().getValue()); 076 WMSLayer.PROP_IMAGE_SIZE.put((Integer) this.tileSize.getModel().getValue()); 077 078 return false; 079 } 080}