1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.preferences.imagery;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.FlowLayout;
|
---|
7 | import java.awt.GridBagLayout;
|
---|
8 |
|
---|
9 | import javax.swing.Box;
|
---|
10 | import javax.swing.JCheckBox;
|
---|
11 | import javax.swing.JLabel;
|
---|
12 | import javax.swing.JPanel;
|
---|
13 | import javax.swing.JSpinner;
|
---|
14 | import javax.swing.SpinnerNumberModel;
|
---|
15 |
|
---|
16 | import org.openstreetmap.josm.gui.layer.WMSLayer;
|
---|
17 | import org.openstreetmap.josm.gui.widgets.JosmComboBox;
|
---|
18 | import org.openstreetmap.josm.io.imagery.HTMLGrabber;
|
---|
19 | import org.openstreetmap.josm.tools.GBC;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * {@code JPanel} giving access to WMS settings.
|
---|
23 | * @since 5465
|
---|
24 | */
|
---|
25 | public class WMSSettingsPanel extends JPanel {
|
---|
26 |
|
---|
27 | // WMS Settings
|
---|
28 | private final JCheckBox autozoomActive;
|
---|
29 | private final JosmComboBox<String> browser;
|
---|
30 | private final JCheckBox overlapCheckBox;
|
---|
31 | private final JSpinner spinEast;
|
---|
32 | private final JSpinner spinNorth;
|
---|
33 | private final JSpinner spinSimConn;
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Constructs a new {@code WMSSettingsPanel}.
|
---|
37 | */
|
---|
38 | public WMSSettingsPanel() {
|
---|
39 | super(new GridBagLayout());
|
---|
40 |
|
---|
41 | // Auto zoom
|
---|
42 | autozoomActive = new JCheckBox();
|
---|
43 | add(new JLabel(tr("Auto zoom by default: ")), GBC.std());
|
---|
44 | add(GBC.glue(5, 0), GBC.std());
|
---|
45 | add(autozoomActive, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
46 |
|
---|
47 | // Downloader
|
---|
48 | browser = new JosmComboBox<>(new String[] {
|
---|
49 | "webkit-image {0}",
|
---|
50 | "gnome-web-photo --mode=photo --format=png {0} /dev/stdout",
|
---|
51 | "gnome-web-photo-fixed {0}",
|
---|
52 | "webkit-image-gtk {0}"});
|
---|
53 | browser.setEditable(true);
|
---|
54 | add(new JLabel(tr("Downloader:")), GBC.std());
|
---|
55 | add(GBC.glue(5, 0), GBC.std());
|
---|
56 | add(browser, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
57 |
|
---|
58 | // Simultaneous connections
|
---|
59 | add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL));
|
---|
60 | JLabel labelSimConn = new JLabel(tr("Simultaneous connections:"));
|
---|
61 | spinSimConn = new JSpinner(new SpinnerNumberModel(WMSLayer.PROP_SIMULTANEOUS_CONNECTIONS.get().intValue(), 1, 30, 1));
|
---|
62 | add(labelSimConn, GBC.std());
|
---|
63 | add(GBC.glue(5, 0), GBC.std());
|
---|
64 | add(spinSimConn, GBC.eol());
|
---|
65 |
|
---|
66 | // Overlap
|
---|
67 | add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL));
|
---|
68 |
|
---|
69 | overlapCheckBox = new JCheckBox(tr("Overlap tiles"));
|
---|
70 | JLabel labelEast = new JLabel(tr("% of east:"));
|
---|
71 | JLabel labelNorth = new JLabel(tr("% of north:"));
|
---|
72 | spinEast = new JSpinner(new SpinnerNumberModel(WMSLayer.PROP_OVERLAP_EAST.get().intValue(), 1, 50, 1));
|
---|
73 | spinNorth = new JSpinner(new SpinnerNumberModel(WMSLayer.PROP_OVERLAP_NORTH.get().intValue(), 1, 50, 1));
|
---|
74 |
|
---|
75 | JPanel overlapPanel = new JPanel(new FlowLayout());
|
---|
76 | overlapPanel.add(overlapCheckBox);
|
---|
77 | overlapPanel.add(labelEast);
|
---|
78 | overlapPanel.add(spinEast);
|
---|
79 | overlapPanel.add(labelNorth);
|
---|
80 | overlapPanel.add(spinNorth);
|
---|
81 |
|
---|
82 | add(overlapPanel, GBC.eop());
|
---|
83 | }
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Loads the WMS settings.
|
---|
87 | */
|
---|
88 | public void loadSettings() {
|
---|
89 | this.autozoomActive.setSelected(WMSLayer.PROP_DEFAULT_AUTOZOOM.get());
|
---|
90 | this.browser.setSelectedItem(HTMLGrabber.PROP_BROWSER.get());
|
---|
91 | this.overlapCheckBox.setSelected(WMSLayer.PROP_OVERLAP.get());
|
---|
92 | this.spinEast.setValue(WMSLayer.PROP_OVERLAP_EAST.get());
|
---|
93 | this.spinNorth.setValue(WMSLayer.PROP_OVERLAP_NORTH.get());
|
---|
94 | this.spinSimConn.setValue(WMSLayer.PROP_SIMULTANEOUS_CONNECTIONS.get());
|
---|
95 | }
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * Saves the WMS settings.
|
---|
99 | * @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 | }
|
---|