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.FlowLayout; 007import java.awt.GridBagLayout; 008 009import javax.swing.Box; 010import javax.swing.JCheckBox; 011import javax.swing.JLabel; 012import javax.swing.JPanel; 013import javax.swing.JSpinner; 014import javax.swing.SpinnerNumberModel; 015 016import org.openstreetmap.josm.gui.layer.WMSLayer; 017import org.openstreetmap.josm.gui.widgets.JosmComboBox; 018import org.openstreetmap.josm.io.imagery.HTMLGrabber; 019import org.openstreetmap.josm.tools.GBC; 020 021/** 022 * {@code JPanel} giving access to WMS settings. 023 * @since 5465 024 */ 025public class WMSSettingsPanel extends JPanel { 026 027 // WMS Settings 028 private final JCheckBox autozoomActive; 029 private final JosmComboBox<String> browser; 030 private final JCheckBox overlapCheckBox; 031 private final JSpinner spinEast; 032 private final JSpinner spinNorth; 033 private final JSpinner spinSimConn; 034 035 /** 036 * Constructs a new {@code WMSSettingsPanel}. 037 */ 038 public WMSSettingsPanel() { 039 super(new GridBagLayout()); 040 041 // Auto zoom 042 autozoomActive = new JCheckBox(); 043 add(new JLabel(tr("Auto zoom by default: ")), GBC.std()); 044 add(GBC.glue(5, 0), GBC.std()); 045 add(autozoomActive, GBC.eol().fill(GBC.HORIZONTAL)); 046 047 // Downloader 048 browser = new JosmComboBox<>(new String[] { 049 "webkit-image {0}", 050 "gnome-web-photo --mode=photo --format=png {0} /dev/stdout", 051 "gnome-web-photo-fixed {0}", 052 "webkit-image-gtk {0}"}); 053 browser.setEditable(true); 054 add(new JLabel(tr("Downloader:")), GBC.std()); 055 add(GBC.glue(5, 0), GBC.std()); 056 add(browser, GBC.eol().fill(GBC.HORIZONTAL)); 057 058 // Simultaneous connections 059 add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL)); 060 JLabel labelSimConn = new JLabel(tr("Simultaneous connections:")); 061 spinSimConn = new JSpinner(new SpinnerNumberModel(WMSLayer.PROP_SIMULTANEOUS_CONNECTIONS.get().intValue(), 1, 30, 1)); 062 add(labelSimConn, GBC.std()); 063 add(GBC.glue(5, 0), GBC.std()); 064 add(spinSimConn, GBC.eol()); 065 066 // Overlap 067 add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL)); 068 069 overlapCheckBox = new JCheckBox(tr("Overlap tiles")); 070 JLabel labelEast = new JLabel(tr("% of east:")); 071 JLabel labelNorth = new JLabel(tr("% of north:")); 072 spinEast = new JSpinner(new SpinnerNumberModel(WMSLayer.PROP_OVERLAP_EAST.get().intValue(), 1, 50, 1)); 073 spinNorth = new JSpinner(new SpinnerNumberModel(WMSLayer.PROP_OVERLAP_NORTH.get().intValue(), 1, 50, 1)); 074 075 JPanel overlapPanel = new JPanel(new FlowLayout()); 076 overlapPanel.add(overlapCheckBox); 077 overlapPanel.add(labelEast); 078 overlapPanel.add(spinEast); 079 overlapPanel.add(labelNorth); 080 overlapPanel.add(spinNorth); 081 082 add(overlapPanel, GBC.eop()); 083 } 084 085 /** 086 * Loads the WMS settings. 087 */ 088 public void loadSettings() { 089 this.autozoomActive.setSelected(WMSLayer.PROP_DEFAULT_AUTOZOOM.get()); 090 this.browser.setSelectedItem(HTMLGrabber.PROP_BROWSER.get()); 091 this.overlapCheckBox.setSelected(WMSLayer.PROP_OVERLAP.get()); 092 this.spinEast.setValue(WMSLayer.PROP_OVERLAP_EAST.get()); 093 this.spinNorth.setValue(WMSLayer.PROP_OVERLAP_NORTH.get()); 094 this.spinSimConn.setValue(WMSLayer.PROP_SIMULTANEOUS_CONNECTIONS.get()); 095 } 096 097 /** 098 * Saves the WMS settings. 099 * @return true when restart is required 100 */ 101 public boolean saveSettings() { 102 WMSLayer.PROP_DEFAULT_AUTOZOOM.put(this.autozoomActive.isSelected()); 103 WMSLayer.PROP_OVERLAP.put(overlapCheckBox.getModel().isSelected()); 104 WMSLayer.PROP_OVERLAP_EAST.put((Integer) spinEast.getModel().getValue()); 105 WMSLayer.PROP_OVERLAP_NORTH.put((Integer) spinNorth.getModel().getValue()); 106 WMSLayer.PROP_SIMULTANEOUS_CONNECTIONS.put((Integer) spinSimConn.getModel().getValue()); 107 108 HTMLGrabber.PROP_BROWSER.put(browser.getEditor().getItem().toString()); 109 110 return false; 111 } 112}