source: josm/trunk/src/org/openstreetmap/josm/gui/layer/gpx/DownloadAlongPanel.java@ 7937

Last change on this file since 7937 was 7937, checked in by bastiK, 9 years ago

add subversion property svn:eol=native

  • Property svn:eol-style set to native
File size: 6.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.layer.gpx;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Dimension;
7import java.awt.GridBagLayout;
8
9import javax.swing.JCheckBox;
10import javax.swing.JLabel;
11import javax.swing.JList;
12import javax.swing.JOptionPane;
13import javax.swing.JPanel;
14import javax.swing.JSpinner;
15import javax.swing.SpinnerNumberModel;
16import javax.swing.event.ChangeEvent;
17import javax.swing.event.ChangeListener;
18
19import org.openstreetmap.josm.Main;
20import org.openstreetmap.josm.gui.HelpAwareOptionPane;
21import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
22import org.openstreetmap.josm.tools.GBC;
23import org.openstreetmap.josm.tools.ImageProvider;
24
25/**
26 * Panel displayed in "Download along..." dialogs
27 * @since 6054
28 */
29public class DownloadAlongPanel extends JPanel {
30
31 // Preferences keys
32 private final String prefOsm;
33 private final String prefGps;
34 private final String prefDist;
35 private final String prefArea;
36 private final String prefNear;
37
38 // Data types to download
39 private final JCheckBox cbDownloadOsmData;
40 private final JCheckBox cbDownloadGpxData;
41
42 private final JSpinner buffer;
43 private final JSpinner maxRect;
44 private final JList<String> downloadNear;
45
46 /**
47 * Constructs a new {@code DownloadPanel}.
48 * @param prefOsm Preference key determining if OSM data should be downloaded
49 * @param prefGps Preference key determining if GPS data should be downloaded
50 * @param prefDist Preference key determining maximum distance
51 * @param prefArea Preference key determining maximum area
52 * @param prefNear Preference key determining "near" parameter. Can be {@code null}
53 */
54 public DownloadAlongPanel(String prefOsm, String prefGps, String prefDist, String prefArea, String prefNear) {
55 super(new GridBagLayout());
56
57 this.prefOsm = prefOsm;
58 this.prefGps = prefGps;
59 this.prefDist = prefDist;
60 this.prefArea = prefArea;
61 this.prefNear = prefNear;
62
63 cbDownloadOsmData = new JCheckBox(tr("OpenStreetMap data"), Main.pref.getBoolean(prefOsm, true));
64 cbDownloadOsmData.setToolTipText(tr("Select to download OSM data."));
65 add(cbDownloadOsmData, GBC.std().insets(1,5,1,5));
66 cbDownloadGpxData = new JCheckBox(tr("Raw GPS data"), Main.pref.getBoolean(prefGps, false));
67 cbDownloadGpxData.setToolTipText(tr("Select to download GPS traces."));
68 add(cbDownloadGpxData, GBC.eol().insets(5,5,1,5));
69
70 add(new JLabel(tr("Download everything within:")), GBC.std());
71 buffer = new JSpinner(new SpinnerNumberModel(50.0, 10.0, 5000.0, 1.0));
72 add(buffer, GBC.std().insets(5,5,5,5));
73 add(new JLabel(tr("meters")), GBC.eol());
74
75 add(new JLabel(tr("Maximum area per request:")), GBC.std());
76 maxRect = new JSpinner(new SpinnerNumberModel(20.0, 1.0, 25.0, 1.0)) {
77 @Override
78 public Dimension getPreferredSize() {
79 return buffer.getPreferredSize();
80 }
81 };
82 add(maxRect, GBC.std().insets(5,5,5,5));
83 add(new JLabel(tr("sq km")), GBC.eol());
84
85 if (prefNear != null) {
86 add(new JLabel(tr("Download near:")), GBC.eol());
87 downloadNear = new JList<>(new String[]{tr("track only"), tr("waypoints only"), tr("track and waypoints")});
88 downloadNear.setSelectedIndex(Main.pref.getInteger(prefNear, 0));
89 add(downloadNear, GBC.eol());
90 } else {
91 downloadNear = null;
92 }
93 }
94
95 /**
96 * Gets the maximum distance in meters
97 * @return The maximum distance, in meters
98 */
99 public final double getDistance() {
100 return (double) buffer.getValue();
101 }
102
103 /**
104 * Gets the maximum area in squared kilometers
105 * @return The maximum distance, in squared kilometers
106 */
107 public final double getArea() {
108 return (double) maxRect.getValue();
109 }
110
111 /**
112 * Gets the "download near" choosen value
113 * @return the "download near" choosen value (0: track only, 1: waypoints only, 2: both)
114 */
115 public final int getNear() {
116 return downloadNear.getSelectedIndex();
117 }
118
119 /**
120 * Replies true if the user selected to download OSM data
121 *
122 * @return true if the user selected to download OSM data
123 */
124 public boolean isDownloadOsmData() {
125 return cbDownloadOsmData.isSelected();
126 }
127
128 /**
129 * Replies true if the user selected to download GPX data
130 *
131 * @return true if the user selected to download GPX data
132 */
133 public boolean isDownloadGpxData() {
134 return cbDownloadGpxData.isSelected();
135 }
136
137 /**
138 * Remembers the current settings in the download panel
139 */
140 protected final void rememberSettings() {
141 Main.pref.put(prefOsm, isDownloadOsmData());
142 Main.pref.put(prefGps, isDownloadGpxData());
143 Main.pref.putDouble(prefDist, getDistance());
144 Main.pref.putDouble(prefArea, getArea());
145 if (prefNear != null) {
146 Main.pref.putInteger(prefNear, getNear());
147 }
148 }
149
150 /**
151 * Adds a change listener to comboboxes
152 * @param listener The listener that will be notified of each combobox change
153 */
154 protected final void addChangeListener(ChangeListener listener) {
155 cbDownloadGpxData.addChangeListener(listener);
156 cbDownloadOsmData.addChangeListener(listener);
157 }
158
159 /**
160 * Show this panel in a new "Download along" help-aware dialog
161 * @param title The dialog title
162 * @param helpTopic The dialog help topic
163 * @return The selected button index (0 for download, 1 for cancel, 2 for dialog closure)
164 */
165 public int showInDownloadDialog(String title, String helpTopic) {
166 final ButtonSpec[] options = new ButtonSpec[] {
167 new ButtonSpec(
168 tr("Download"),
169 ImageProvider.get("download"),
170 tr("Click to download"),
171 null // no specific help text
172 ),
173 new ButtonSpec(
174 tr("Cancel"),
175 ImageProvider.get("cancel"),
176 tr("Click to cancel"),
177 null // no specific help text
178 )
179 };
180
181 addChangeListener(new ChangeListener() {
182 @Override public void stateChanged(ChangeEvent e) {
183 options[0].setEnabled(isDownloadOsmData() || isDownloadGpxData());
184 }
185 });
186
187 int ret = HelpAwareOptionPane.showOptionDialog(Main.parent, this, title,
188 JOptionPane.QUESTION_MESSAGE, null, options, options[0], helpTopic);
189 if (0 == ret) {
190 rememberSettings();
191 }
192
193 return ret;
194 }
195}
Note: See TracBrowser for help on using the repository browser.