source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/display/GPXSettingsPanel.java@ 10378

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

Checkstyle 6.19: enable SingleSpaceSeparator and fix violations

  • Property svn:eol-style set to native
File size: 26.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.display;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5import static org.openstreetmap.josm.tools.I18n.trc;
6
7import java.awt.Component;
8import java.awt.GridBagLayout;
9import java.awt.event.ActionEvent;
10import java.awt.event.ActionListener;
11
12import javax.swing.BorderFactory;
13import javax.swing.Box;
14import javax.swing.ButtonGroup;
15import javax.swing.JCheckBox;
16import javax.swing.JLabel;
17import javax.swing.JOptionPane;
18import javax.swing.JPanel;
19import javax.swing.JRadioButton;
20import javax.swing.event.ChangeEvent;
21import javax.swing.event.ChangeListener;
22
23import org.openstreetmap.josm.Main;
24import org.openstreetmap.josm.actions.ExpertToggleAction;
25import org.openstreetmap.josm.gui.layer.markerlayer.Marker;
26import org.openstreetmap.josm.gui.layer.markerlayer.Marker.TemplateEntryProperty;
27import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane.ValidationListener;
28import org.openstreetmap.josm.gui.widgets.JosmComboBox;
29import org.openstreetmap.josm.gui.widgets.JosmTextField;
30import org.openstreetmap.josm.tools.GBC;
31import org.openstreetmap.josm.tools.template_engine.ParseError;
32import org.openstreetmap.josm.tools.template_engine.TemplateParser;
33
34/**
35 * Panel for GPX settings.
36 */
37public class GPXSettingsPanel extends JPanel implements ValidationListener {
38
39 private static final int WAYPOINT_LABEL_CUSTOM = 6;
40 private static final String[] LABEL_PATTERN_TEMPLATE = new String[] {Marker.LABEL_PATTERN_AUTO, Marker.LABEL_PATTERN_NAME,
41 Marker.LABEL_PATTERN_DESC, "{special:everything}", "?{ '{name}' | '{desc}' | '{formattedWaypointOffset}' }", ""};
42 private static final String[] LABEL_PATTERN_DESC = new String[] {tr("Auto"), /* gpx data field name */ trc("gpx_field", "Name"),
43 /* gpx data field name */ trc("gpx_field", "Desc(ription)"), tr("Everything"), tr("Name or offset"), tr("None"), tr("Custom")};
44
45
46 private final JRadioButton drawRawGpsLinesGlobal = new JRadioButton(tr("Use global settings"));
47 private final JRadioButton drawRawGpsLinesAll = new JRadioButton(tr("All"));
48 private final JRadioButton drawRawGpsLinesLocal = new JRadioButton(tr("Local files"));
49 private final JRadioButton drawRawGpsLinesNone = new JRadioButton(tr("None"));
50 private transient ActionListener drawRawGpsLinesActionListener;
51 private final JosmTextField drawRawGpsMaxLineLength = new JosmTextField(8);
52 private final JosmTextField drawRawGpsMaxLineLengthLocal = new JosmTextField(8);
53 private final JosmTextField drawLineWidth = new JosmTextField(2);
54 private final JCheckBox forceRawGpsLines = new JCheckBox(tr("Force lines if no segments imported"));
55 private final JCheckBox largeGpsPoints = new JCheckBox(tr("Draw large GPS points"));
56 private final JCheckBox hdopCircleGpsPoints = new JCheckBox(tr("Draw a circle from HDOP value"));
57 private final JRadioButton colorTypeVelocity = new JRadioButton(tr("Velocity (red = slow, green = fast)"));
58 private final JRadioButton colorTypeDirection = new JRadioButton(tr("Direction (red = west, yellow = north, green = east, blue = south)"));
59 private final JRadioButton colorTypeDilution = new JRadioButton(tr("Dilution of Position (red = high, green = low, if available)"));
60 private final JRadioButton colorTypeTime = new JRadioButton(tr("Track date"));
61 private final JRadioButton colorTypeNone = new JRadioButton(tr("Single Color (can be customized for named layers)"));
62 private final JRadioButton colorTypeGlobal = new JRadioButton(tr("Use global settings"));
63 private final JosmComboBox<String> colorTypeVelocityTune = new JosmComboBox<>(new String[] {tr("Car"), tr("Bicycle"), tr("Foot")});
64 private final JCheckBox makeAutoMarkers = new JCheckBox(tr("Create markers when reading GPX"));
65 private final JCheckBox drawGpsArrows = new JCheckBox(tr("Draw Direction Arrows"));
66 private final JCheckBox drawGpsArrowsFast = new JCheckBox(tr("Fast drawing (looks uglier)"));
67 private final JosmTextField drawGpsArrowsMinDist = new JosmTextField(8);
68 private final JCheckBox colorDynamic = new JCheckBox(tr("Dynamic color range based on data limits"));
69 private final JosmComboBox<String> waypointLabel = new JosmComboBox<>(LABEL_PATTERN_DESC);
70 private final JosmTextField waypointLabelPattern = new JosmTextField();
71 private final JosmComboBox<String> audioWaypointLabel = new JosmComboBox<>(LABEL_PATTERN_DESC);
72 private final JosmTextField audioWaypointLabelPattern = new JosmTextField();
73 private final JCheckBox useGpsAntialiasing = new JCheckBox(tr("Smooth GPX graphics (antialiasing)"));
74
75 private String layerName;
76 private final boolean local; // flag to display LocalOnly checkbox
77 private final boolean nonlocal; // flag to display AllLines checkbox
78
79 /**
80 * Constructs a new {@code GPXSettingsPanel} for a given layer name.
81 * @param layerName The GPX layer name
82 * @param local flag to display LocalOnly checkbox
83 * @param nonlocal flag to display AllLines checkbox
84 */
85 public GPXSettingsPanel(String layerName, boolean local, boolean nonlocal) {
86 super(new GridBagLayout());
87 this.local = local;
88 this.nonlocal = nonlocal;
89 this.layerName = "layer "+layerName;
90 initComponents();
91 loadPreferences();
92 }
93
94 /**
95 * Constructs a new {@code GPXSettingsPanel}.
96 */
97 public GPXSettingsPanel() {
98 super(new GridBagLayout());
99 initComponents();
100 local = false;
101 nonlocal = false;
102 loadPreferences(); // preferences -> controls
103 }
104
105 private void initComponents() {
106 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
107
108 // makeAutoMarkers
109 makeAutoMarkers.setToolTipText(tr("Automatically make a marker layer from any waypoints when opening a GPX layer."));
110 ExpertToggleAction.addVisibilitySwitcher(makeAutoMarkers);
111 add(makeAutoMarkers, GBC.eol().insets(20, 0, 0, 5));
112
113 // drawRawGpsLines
114 ButtonGroup gpsLinesGroup = new ButtonGroup();
115 if (layerName != null) {
116 gpsLinesGroup.add(drawRawGpsLinesGlobal);
117 }
118 gpsLinesGroup.add(drawRawGpsLinesNone);
119 gpsLinesGroup.add(drawRawGpsLinesLocal);
120 gpsLinesGroup.add(drawRawGpsLinesAll);
121
122 /* ensure that default is in data base */
123
124 JLabel label = new JLabel(tr("Draw lines between raw GPS points"));
125 add(label, GBC.eol().insets(20, 0, 0, 0));
126 if (layerName != null) {
127 add(drawRawGpsLinesGlobal, GBC.eol().insets(40, 0, 0, 0));
128 }
129 add(drawRawGpsLinesNone, GBC.eol().insets(40, 0, 0, 0));
130 if (layerName == null || local) {
131 add(drawRawGpsLinesLocal, GBC.eol().insets(40, 0, 0, 0));
132 }
133 if (layerName == null || nonlocal) {
134 add(drawRawGpsLinesAll, GBC.eol().insets(40, 0, 0, 0));
135 }
136 ExpertToggleAction.addVisibilitySwitcher(label);
137 ExpertToggleAction.addVisibilitySwitcher(drawRawGpsLinesGlobal);
138 ExpertToggleAction.addVisibilitySwitcher(drawRawGpsLinesNone);
139 ExpertToggleAction.addVisibilitySwitcher(drawRawGpsLinesLocal);
140 ExpertToggleAction.addVisibilitySwitcher(drawRawGpsLinesAll);
141
142 drawRawGpsLinesActionListener = new ActionListener() {
143 @Override
144 public void actionPerformed(ActionEvent e) {
145 boolean f = drawRawGpsLinesNone.isSelected() || drawRawGpsLinesGlobal.isSelected();
146 forceRawGpsLines.setEnabled(!f);
147 drawRawGpsMaxLineLength.setEnabled(!(f || drawRawGpsLinesLocal.isSelected()));
148 drawRawGpsMaxLineLengthLocal.setEnabled(!f);
149 drawGpsArrows.setEnabled(!f);
150 drawGpsArrowsFast.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
151 drawGpsArrowsMinDist.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
152 }
153 };
154
155 drawRawGpsLinesGlobal.addActionListener(drawRawGpsLinesActionListener);
156 drawRawGpsLinesNone.addActionListener(drawRawGpsLinesActionListener);
157 drawRawGpsLinesLocal.addActionListener(drawRawGpsLinesActionListener);
158 drawRawGpsLinesAll.addActionListener(drawRawGpsLinesActionListener);
159
160 // drawRawGpsMaxLineLengthLocal
161 drawRawGpsMaxLineLengthLocal.setToolTipText(
162 tr("Maximum length (in meters) to draw lines for local files. Set to ''-1'' to draw all lines."));
163 label = new JLabel(tr("Maximum length for local files (meters)"));
164 add(label, GBC.std().insets(40, 0, 0, 0));
165 add(drawRawGpsMaxLineLengthLocal, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
166 ExpertToggleAction.addVisibilitySwitcher(label);
167 ExpertToggleAction.addVisibilitySwitcher(drawRawGpsMaxLineLengthLocal);
168
169 // drawRawGpsMaxLineLength
170 drawRawGpsMaxLineLength.setToolTipText(tr("Maximum length (in meters) to draw lines. Set to ''-1'' to draw all lines."));
171 label = new JLabel(tr("Maximum length (meters)"));
172 add(label, GBC.std().insets(40, 0, 0, 0));
173 add(drawRawGpsMaxLineLength, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
174 ExpertToggleAction.addVisibilitySwitcher(label);
175 ExpertToggleAction.addVisibilitySwitcher(drawRawGpsMaxLineLength);
176
177 // forceRawGpsLines
178 forceRawGpsLines.setToolTipText(tr("Force drawing of lines if the imported data contain no line information."));
179 add(forceRawGpsLines, GBC.eop().insets(40, 0, 0, 0));
180 ExpertToggleAction.addVisibilitySwitcher(forceRawGpsLines);
181
182 // drawGpsArrows
183 drawGpsArrows.addActionListener(new ActionListener() {
184 @Override
185 public void actionPerformed(ActionEvent e) {
186 drawGpsArrowsFast.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
187 drawGpsArrowsMinDist.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
188 }
189 });
190 drawGpsArrows.setToolTipText(tr("Draw direction arrows for lines, connecting GPS points."));
191 add(drawGpsArrows, GBC.eop().insets(40, 0, 0, 0));
192
193 // drawGpsArrowsFast
194 drawGpsArrowsFast.setToolTipText(tr("Draw the direction arrows using table lookups instead of complex math."));
195 add(drawGpsArrowsFast, GBC.eop().insets(60, 0, 0, 0));
196 ExpertToggleAction.addVisibilitySwitcher(drawGpsArrowsFast);
197
198 // drawGpsArrowsMinDist
199 drawGpsArrowsMinDist.setToolTipText(tr("Do not draw arrows if they are not at least this distance away from the last one."));
200 add(new JLabel(tr("Minimum distance (pixels)")), GBC.std().insets(60, 0, 0, 0));
201 add(drawGpsArrowsMinDist, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
202
203 // hdopCircleGpsPoints
204 hdopCircleGpsPoints.setToolTipText(tr("Draw a circle from HDOP value."));
205 add(hdopCircleGpsPoints, GBC.eop().insets(20, 0, 0, 0));
206 ExpertToggleAction.addVisibilitySwitcher(hdopCircleGpsPoints);
207
208 // largeGpsPoints
209 largeGpsPoints.setToolTipText(tr("Draw larger dots for the GPS points."));
210 add(largeGpsPoints, GBC.eop().insets(20, 0, 0, 0));
211
212 // drawLineWidth
213 drawLineWidth.setToolTipText(tr("Width of drawn GPX line (0 for default)"));
214 add(new JLabel(tr("Drawing width of GPX lines")), GBC.std().insets(20, 0, 0, 0));
215 add(drawLineWidth, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
216
217 // antialiasing
218 useGpsAntialiasing.setToolTipText(tr("Apply antialiasing to the GPX lines resulting in a smoother appearance."));
219 add(useGpsAntialiasing, GBC.eop().insets(20, 0, 0, 0));
220 ExpertToggleAction.addVisibilitySwitcher(useGpsAntialiasing);
221
222 // colorTracks
223 ButtonGroup colorGroup = new ButtonGroup();
224 if (layerName != null) {
225 colorGroup.add(colorTypeGlobal);
226 }
227 colorGroup.add(colorTypeNone);
228 colorGroup.add(colorTypeVelocity);
229 colorGroup.add(colorTypeDirection);
230 colorGroup.add(colorTypeDilution);
231 colorGroup.add(colorTypeTime);
232
233 colorTypeVelocity.addChangeListener(new ChangeListener() {
234 @Override
235 public void stateChanged(ChangeEvent e) {
236 colorTypeVelocityTune.setEnabled(colorTypeVelocity.isSelected());
237 colorDynamic.setEnabled(colorTypeVelocity.isSelected() || colorTypeDilution.isSelected());
238 }
239 });
240 colorTypeDilution.addChangeListener(new ChangeListener() {
241 @Override
242 public void stateChanged(ChangeEvent e) {
243 colorDynamic.setEnabled(colorTypeVelocity.isSelected() || colorTypeDilution.isSelected());
244 }
245 });
246
247 colorTypeNone.setToolTipText(tr("All points and track segments will have the same color. Can be customized in Layer Manager."));
248 colorTypeVelocity.setToolTipText(tr("Colors points and track segments by velocity."));
249 colorTypeDirection.setToolTipText(tr("Colors points and track segments by direction."));
250 colorTypeDilution.setToolTipText(
251 tr("Colors points and track segments by dilution of position (HDOP). Your capture device needs to log that information."));
252 colorTypeTime.setToolTipText(tr("Colors points and track segments by its timestamp."));
253
254 // color Tracks by Velocity Tune
255 colorTypeVelocityTune.setToolTipText(tr("Allows to tune the track coloring for different average speeds."));
256
257 add(Box.createVerticalGlue(), GBC.eol().insets(0, 20, 0, 0));
258
259 add(new JLabel(tr("Track and Point Coloring")), GBC.eol().insets(20, 0, 0, 0));
260 if (layerName != null) {
261 add(colorTypeGlobal, GBC.eol().insets(40, 0, 0, 0));
262 }
263 add(colorTypeNone, GBC.eol().insets(40, 0, 0, 0));
264 add(colorTypeVelocity, GBC.std().insets(40, 0, 0, 0));
265 add(colorTypeVelocityTune, GBC.eop().insets(5, 0, 0, 5));
266 add(colorTypeDirection, GBC.eol().insets(40, 0, 0, 0));
267 add(colorTypeDilution, GBC.eol().insets(40, 0, 0, 0));
268 add(colorTypeTime, GBC.eol().insets(40, 0, 0, 0));
269 ExpertToggleAction.addVisibilitySwitcher(colorTypeDirection);
270 ExpertToggleAction.addVisibilitySwitcher(colorTypeDilution);
271
272 colorDynamic.setToolTipText(tr("Colors points and track segments by data limits."));
273 add(colorDynamic, GBC.eop().insets(40, 0, 0, 0));
274 ExpertToggleAction.addVisibilitySwitcher(colorDynamic);
275
276 if (layerName == null) {
277 // Setting waypoints for gpx layer doesn't make sense - waypoints are shown in marker layer that has different name - so show
278 // this only for global config
279
280 // waypointLabel
281 label = new JLabel(tr("Waypoint labelling"));
282 add(label, GBC.std().insets(20, 0, 0, 0));
283 label.setLabelFor(waypointLabel);
284 add(waypointLabel, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
285 waypointLabel.addActionListener(new ActionListener() {
286 @Override
287 public void actionPerformed(ActionEvent e) {
288 updateWaypointPattern(waypointLabel, waypointLabelPattern);
289 }
290 });
291 updateWaypointLabelCombobox(waypointLabel, waypointLabelPattern, TemplateEntryProperty.forMarker(layerName));
292 add(waypointLabelPattern, GBC.eol().fill(GBC.HORIZONTAL).insets(20, 0, 0, 5));
293 ExpertToggleAction.addVisibilitySwitcher(label);
294 ExpertToggleAction.addVisibilitySwitcher(waypointLabel);
295 ExpertToggleAction.addVisibilitySwitcher(waypointLabelPattern);
296
297 // audioWaypointLabel
298 Component glue = Box.createVerticalGlue();
299 add(glue, GBC.eol().insets(0, 20, 0, 0));
300 ExpertToggleAction.addVisibilitySwitcher(glue);
301
302 label = new JLabel(tr("Audio waypoint labelling"));
303 add(label, GBC.std().insets(20, 0, 0, 0));
304 label.setLabelFor(audioWaypointLabel);
305 add(audioWaypointLabel, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
306 audioWaypointLabel.addActionListener(new ActionListener() {
307 @Override
308 public void actionPerformed(ActionEvent e) {
309 updateWaypointPattern(audioWaypointLabel, audioWaypointLabelPattern);
310 }
311 });
312 updateWaypointLabelCombobox(audioWaypointLabel, audioWaypointLabelPattern, TemplateEntryProperty.forAudioMarker(layerName));
313 add(audioWaypointLabelPattern, GBC.eol().fill(GBC.HORIZONTAL).insets(20, 0, 0, 5));
314 ExpertToggleAction.addVisibilitySwitcher(label);
315 ExpertToggleAction.addVisibilitySwitcher(audioWaypointLabel);
316 ExpertToggleAction.addVisibilitySwitcher(audioWaypointLabelPattern);
317 }
318
319 add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH));
320 }
321
322 /**
323 * Loads preferences to UI controls
324 */
325 public final void loadPreferences() {
326 makeAutoMarkers.setSelected(Main.pref.getBoolean("marker.makeautomarkers", true));
327 if (layerName != null && Main.pref.get("draw.rawgps.lines."+layerName).isEmpty()
328 && Main.pref.get("draw.rawgps.lines.local."+layerName).isEmpty()) {
329 // no line preferences for layer is found
330 drawRawGpsLinesGlobal.setSelected(true);
331 } else {
332 Boolean lf = Main.pref.getBoolean("draw.rawgps.lines.local", layerName, true);
333 if (Main.pref.getBoolean("draw.rawgps.lines", layerName, true)) {
334 drawRawGpsLinesAll.setSelected(true);
335 } else if (lf) {
336 drawRawGpsLinesLocal.setSelected(true);
337 } else {
338 drawRawGpsLinesNone.setSelected(true);
339 }
340 }
341
342 drawRawGpsMaxLineLengthLocal.setText(Integer.toString(Main.pref.getInteger("draw.rawgps.max-line-length.local", layerName, -1)));
343 drawRawGpsMaxLineLength.setText(Integer.toString(Main.pref.getInteger("draw.rawgps.max-line-length", layerName, 200)));
344 drawLineWidth.setText(Integer.toString(Main.pref.getInteger("draw.rawgps.linewidth", layerName, 0)));
345 forceRawGpsLines.setSelected(Main.pref.getBoolean("draw.rawgps.lines.force", layerName, false));
346 drawGpsArrows.setSelected(Main.pref.getBoolean("draw.rawgps.direction", layerName, false));
347 drawGpsArrowsFast.setSelected(Main.pref.getBoolean("draw.rawgps.alternatedirection", layerName, false));
348 drawGpsArrowsMinDist.setText(Integer.toString(Main.pref.getInteger("draw.rawgps.min-arrow-distance", layerName, 40)));
349 hdopCircleGpsPoints.setSelected(Main.pref.getBoolean("draw.rawgps.hdopcircle", layerName, false));
350 largeGpsPoints.setSelected(Main.pref.getBoolean("draw.rawgps.large", layerName, false));
351 useGpsAntialiasing.setSelected(Main.pref.getBoolean("mappaint.gpx.use-antialiasing", false));
352 drawRawGpsLinesActionListener.actionPerformed(null);
353
354 if (layerName != null && Main.pref.get("draw.rawgps.colors."+layerName).isEmpty()) {
355 colorTypeGlobal.setSelected(true);
356 colorDynamic.setSelected(false);
357 colorDynamic.setEnabled(false);
358 } else {
359 int colorType = Main.pref.getInteger("draw.rawgps.colors", layerName, 0);
360 switch (colorType) {
361 case 0: colorTypeNone.setSelected(true); break;
362 case 1: colorTypeVelocity.setSelected(true); break;
363 case 2: colorTypeDilution.setSelected(true); break;
364 case 3: colorTypeDirection.setSelected(true); break;
365 case 4: colorTypeTime.setSelected(true); break;
366 default: Main.warn("Unknown color type: " + colorType);
367 }
368 int ccts = Main.pref.getInteger("draw.rawgps.colorTracksTune", layerName, 45);
369 colorTypeVelocityTune.setSelectedIndex(ccts == 10 ? 2 : (ccts == 20 ? 1 : 0));
370 colorTypeVelocityTune.setEnabled(colorTypeVelocity.isSelected() && colorTypeVelocity.isEnabled());
371 colorDynamic.setSelected(Main.pref.getBoolean("draw.rawgps.colors.dynamic", layerName, false));
372 colorDynamic.setEnabled(colorTypeVelocity.isSelected() || colorTypeDilution.isSelected());
373 }
374 }
375
376 /**
377 * Save preferences from UI controls, globally or for a specified layer.
378 * @param layerName The GPX layer name. Can be {@code null}, in that case, global preferences are written
379 * @param locLayer {@code true} if the GPX layer is a local one. Ignored if {@code layerName} is null
380 * @return {@code true} when restart is required, {@code false} otherwise
381 */
382 public boolean savePreferences(String layerName, boolean locLayer) {
383 String layerNameDot = ".layer "+layerName;
384 if (layerName == null) {
385 layerNameDot = "";
386 }
387 Main.pref.put("marker.makeautomarkers"+layerNameDot, makeAutoMarkers.isSelected());
388 if (drawRawGpsLinesGlobal.isSelected()) {
389 Main.pref.put("draw.rawgps.lines" + layerNameDot, null);
390 Main.pref.put("draw.rawgps.max-line-length" + layerNameDot, null);
391 Main.pref.put("draw.rawgps.lines.local" + layerNameDot, null);
392 Main.pref.put("draw.rawgps.max-line-length.local" + layerNameDot, null);
393 Main.pref.put("draw.rawgps.lines.force"+layerNameDot, null);
394 Main.pref.put("draw.rawgps.direction"+layerNameDot, null);
395 Main.pref.put("draw.rawgps.alternatedirection"+layerNameDot, null);
396 Main.pref.put("draw.rawgps.min-arrow-distance"+layerNameDot, null);
397 } else {
398 if (layerName == null || !locLayer) {
399 Main.pref.put("draw.rawgps.lines" + layerNameDot, drawRawGpsLinesAll.isSelected());
400 Main.pref.put("draw.rawgps.max-line-length" + layerNameDot, drawRawGpsMaxLineLength.getText());
401 }
402 if (layerName == null || locLayer) {
403 Main.pref.put("draw.rawgps.lines.local" + layerNameDot, drawRawGpsLinesAll.isSelected() || drawRawGpsLinesLocal.isSelected());
404 Main.pref.put("draw.rawgps.max-line-length.local" + layerNameDot, drawRawGpsMaxLineLengthLocal.getText());
405 }
406 Main.pref.put("draw.rawgps.lines.force"+layerNameDot, forceRawGpsLines.isSelected());
407 Main.pref.put("draw.rawgps.direction"+layerNameDot, drawGpsArrows.isSelected());
408 Main.pref.put("draw.rawgps.alternatedirection"+layerNameDot, drawGpsArrowsFast.isSelected());
409 Main.pref.put("draw.rawgps.min-arrow-distance"+layerNameDot, drawGpsArrowsMinDist.getText());
410 }
411
412 Main.pref.put("draw.rawgps.hdopcircle"+layerNameDot, hdopCircleGpsPoints.isSelected());
413 Main.pref.put("draw.rawgps.large"+layerNameDot, largeGpsPoints.isSelected());
414 Main.pref.put("draw.rawgps.linewidth"+layerNameDot, drawLineWidth.getText());
415 Main.pref.put("mappaint.gpx.use-antialiasing", useGpsAntialiasing.isSelected());
416
417 TemplateEntryProperty.forMarker(layerName).put(waypointLabelPattern.getText());
418 TemplateEntryProperty.forAudioMarker(layerName).put(audioWaypointLabelPattern.getText());
419
420 if (colorTypeGlobal.isSelected()) {
421 Main.pref.put("draw.rawgps.colors"+layerNameDot, null);
422 Main.pref.put("draw.rawgps.colors.dynamic"+layerNameDot, null);
423 Main.pref.put("draw.rawgps.colorTracksTunec"+layerNameDot, null);
424 return false;
425 } else if (colorTypeVelocity.isSelected()) {
426 Main.pref.putInteger("draw.rawgps.colors"+layerNameDot, 1);
427 } else if (colorTypeDilution.isSelected()) {
428 Main.pref.putInteger("draw.rawgps.colors"+layerNameDot, 2);
429 } else if (colorTypeDirection.isSelected()) {
430 Main.pref.putInteger("draw.rawgps.colors"+layerNameDot, 3);
431 } else if (colorTypeTime.isSelected()) {
432 Main.pref.putInteger("draw.rawgps.colors"+layerNameDot, 4);
433 } else {
434 Main.pref.putInteger("draw.rawgps.colors"+layerNameDot, 0);
435 }
436 Main.pref.put("draw.rawgps.colors.dynamic"+layerNameDot, colorDynamic.isSelected());
437 int ccti = colorTypeVelocityTune.getSelectedIndex();
438 Main.pref.putInteger("draw.rawgps.colorTracksTune"+layerNameDot, ccti == 2 ? 10 : (ccti == 1 ? 20 : 45));
439 return false;
440 }
441
442 /**
443 * Save preferences from UI controls for initial layer or globally
444 * @return {@code true} when restart is required, {@code false} otherwise
445 */
446 public boolean savePreferences() {
447 return savePreferences(null, false);
448 }
449
450 private static void updateWaypointLabelCombobox(JosmComboBox<String> cb, JosmTextField tf, TemplateEntryProperty property) {
451 String labelPattern = property.getAsString();
452 boolean found = false;
453 for (int i = 0; i < LABEL_PATTERN_TEMPLATE.length; i++) {
454 if (LABEL_PATTERN_TEMPLATE[i].equals(labelPattern)) {
455 cb.setSelectedIndex(i);
456 found = true;
457 break;
458 }
459 }
460 if (!found) {
461 cb.setSelectedIndex(WAYPOINT_LABEL_CUSTOM);
462 tf.setEnabled(true);
463 tf.setText(labelPattern);
464 }
465 }
466
467 private static void updateWaypointPattern(JosmComboBox<String> cb, JosmTextField tf) {
468 if (cb.getSelectedIndex() == WAYPOINT_LABEL_CUSTOM) {
469 tf.setEnabled(true);
470 } else {
471 tf.setEnabled(false);
472 tf.setText(LABEL_PATTERN_TEMPLATE[cb.getSelectedIndex()]);
473 }
474 }
475
476 @Override
477 public boolean validatePreferences() {
478 TemplateParser parser = new TemplateParser(waypointLabelPattern.getText());
479 try {
480 parser.parse();
481 } catch (ParseError e) {
482 JOptionPane.showMessageDialog(Main.parent,
483 tr("Incorrect waypoint label pattern: {0}", e.getMessage()), tr("Incorrect pattern"), JOptionPane.ERROR_MESSAGE);
484 waypointLabelPattern.requestFocus();
485 return false;
486 }
487 parser = new TemplateParser(audioWaypointLabelPattern.getText());
488 try {
489 parser.parse();
490 } catch (ParseError e) {
491 JOptionPane.showMessageDialog(Main.parent,
492 tr("Incorrect audio waypoint label pattern: {0}", e.getMessage()), tr("Incorrect pattern"), JOptionPane.ERROR_MESSAGE);
493 audioWaypointLabelPattern.requestFocus();
494 return false;
495 }
496 return true;
497 }
498}
Note: See TracBrowser for help on using the repository browser.