source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/imagery/WMSSettingsPanel.java@ 8426

Last change on this file since 8426 was 8426, checked in by Don-vip, 9 years ago

Accessibility - global use of JLabel.setLabelFor() + various fixes (javadoc, code style)

  • Property svn:eol-style set to native
File size: 4.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.imagery;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.FlowLayout;
7import java.awt.GridBagLayout;
8
9import javax.swing.Box;
10import javax.swing.JCheckBox;
11import javax.swing.JLabel;
12import javax.swing.JPanel;
13import javax.swing.JSpinner;
14import javax.swing.SpinnerNumberModel;
15
16import org.openstreetmap.josm.gui.layer.WMSLayer;
17import org.openstreetmap.josm.gui.widgets.JosmComboBox;
18import org.openstreetmap.josm.io.imagery.HTMLGrabber;
19import org.openstreetmap.josm.tools.GBC;
20
21/**
22 * {@code JPanel} giving access to WMS settings.
23 * @since 5465
24 */
25public 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 labelSimConn.setLabelFor(spinSimConn);
63 add(labelSimConn, GBC.std());
64 add(GBC.glue(5, 0), GBC.std());
65 add(spinSimConn, GBC.eol());
66
67 // Overlap
68 add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL));
69
70 overlapCheckBox = new JCheckBox(tr("Overlap tiles"));
71 JLabel labelEast = new JLabel(tr("% of east:"));
72 JLabel labelNorth = new JLabel(tr("% of north:"));
73 spinEast = new JSpinner(new SpinnerNumberModel(WMSLayer.PROP_OVERLAP_EAST.get().intValue(), 1, 50, 1));
74 spinNorth = new JSpinner(new SpinnerNumberModel(WMSLayer.PROP_OVERLAP_NORTH.get().intValue(), 1, 50, 1));
75 labelEast.setLabelFor(spinEast);
76 labelNorth.setLabelFor(spinNorth);
77
78 JPanel overlapPanel = new JPanel(new FlowLayout());
79 overlapPanel.add(overlapCheckBox);
80 overlapPanel.add(labelEast);
81 overlapPanel.add(spinEast);
82 overlapPanel.add(labelNorth);
83 overlapPanel.add(spinNorth);
84
85 add(overlapPanel, GBC.eop());
86 }
87
88 /**
89 * Loads the WMS settings.
90 */
91 public void loadSettings() {
92 this.autozoomActive.setSelected(WMSLayer.PROP_DEFAULT_AUTOZOOM.get());
93 this.browser.setSelectedItem(HTMLGrabber.PROP_BROWSER.get());
94 this.overlapCheckBox.setSelected(WMSLayer.PROP_OVERLAP.get());
95 this.spinEast.setValue(WMSLayer.PROP_OVERLAP_EAST.get());
96 this.spinNorth.setValue(WMSLayer.PROP_OVERLAP_NORTH.get());
97 this.spinSimConn.setValue(WMSLayer.PROP_SIMULTANEOUS_CONNECTIONS.get());
98 }
99
100 /**
101 * Saves the WMS settings.
102 * @return true when restart is required
103 */
104 public boolean saveSettings() {
105 WMSLayer.PROP_DEFAULT_AUTOZOOM.put(this.autozoomActive.isSelected());
106 WMSLayer.PROP_OVERLAP.put(overlapCheckBox.getModel().isSelected());
107 WMSLayer.PROP_OVERLAP_EAST.put((Integer) spinEast.getModel().getValue());
108 WMSLayer.PROP_OVERLAP_NORTH.put((Integer) spinNorth.getModel().getValue());
109 WMSLayer.PROP_SIMULTANEOUS_CONNECTIONS.put((Integer) spinSimConn.getModel().getValue());
110
111 HTMLGrabber.PROP_BROWSER.put(browser.getEditor().getItem().toString());
112
113 return false;
114 }
115}
Note: See TracBrowser for help on using the repository browser.