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

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

fix #14282 - add robustness to GPX settings panel (patch by kidelo)

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