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