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

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

fix #16796 - Rework of GPX track colors / layer preferences (patch by Bjoeni)

  • Property svn:eol-style set to native
File size: 36.2 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.Dimension;
9import java.awt.GridBagLayout;
10import java.awt.event.ActionListener;
11import java.util.Collections;
12import java.util.Enumeration;
13import java.util.HashMap;
14import java.util.List;
15import java.util.Map;
16import java.util.Optional;
17
18import javax.swing.AbstractButton;
19import javax.swing.BorderFactory;
20import javax.swing.Box;
21import javax.swing.ButtonGroup;
22import javax.swing.JCheckBox;
23import javax.swing.JLabel;
24import javax.swing.JOptionPane;
25import javax.swing.JPanel;
26import javax.swing.JRadioButton;
27import javax.swing.JSlider;
28
29import org.apache.commons.jcs.access.exception.InvalidArgumentException;
30import org.openstreetmap.josm.actions.ExpertToggleAction;
31import org.openstreetmap.josm.data.gpx.GpxData;
32import org.openstreetmap.josm.gui.MainApplication;
33import org.openstreetmap.josm.gui.layer.GpxLayer;
34import org.openstreetmap.josm.gui.layer.gpx.GpxDrawHelper;
35import org.openstreetmap.josm.gui.layer.markerlayer.Marker;
36import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane.ValidationListener;
37import org.openstreetmap.josm.gui.widgets.JosmComboBox;
38import org.openstreetmap.josm.gui.widgets.JosmTextField;
39import org.openstreetmap.josm.spi.preferences.Config;
40import org.openstreetmap.josm.tools.GBC;
41import org.openstreetmap.josm.tools.Logging;
42import org.openstreetmap.josm.tools.template_engine.ParseError;
43import org.openstreetmap.josm.tools.template_engine.TemplateParser;
44
45/**
46 * Panel for GPX settings.
47 */
48public class GPXSettingsPanel extends JPanel implements ValidationListener {
49
50 private static final int WAYPOINT_LABEL_CUSTOM = 6;
51 private static final String[] LABEL_PATTERN_TEMPLATE = new String[] {Marker.LABEL_PATTERN_AUTO, Marker.LABEL_PATTERN_NAME,
52 Marker.LABEL_PATTERN_DESC, "{special:everything}", "?{ '{name}' | '{desc}' | '{formattedWaypointOffset}' }", " "};
53 private static final String[] LABEL_PATTERN_DESC = new String[] {tr("Auto"), /* gpx data field name */ trc("gpx_field", "Name"),
54 /* gpx data field name */ trc("gpx_field", "Desc(ription)"), tr("Everything"), tr("Name or offset"), tr("None"), tr("Custom")};
55
56
57 private final JRadioButton drawRawGpsLinesGlobal = new JRadioButton(tr("Use global settings"));
58 private final JRadioButton drawRawGpsLinesAll = new JRadioButton(tr("All"));
59 private final JRadioButton drawRawGpsLinesLocal = new JRadioButton(tr("Local files"));
60 private final JRadioButton drawRawGpsLinesNone = new JRadioButton(tr("None"));
61 private transient ActionListener drawRawGpsLinesActionListener;
62 private final JosmTextField drawRawGpsMaxLineLength = new JosmTextField(8);
63 private final JosmTextField drawRawGpsMaxLineLengthLocal = new JosmTextField(8);
64 private final JosmTextField drawLineWidth = new JosmTextField(2);
65 private final JCheckBox forceRawGpsLines = new JCheckBox(tr("Force lines if no segments imported"));
66 private final JCheckBox largeGpsPoints = new JCheckBox(tr("Draw large GPS points"));
67 private final JCheckBox hdopCircleGpsPoints = new JCheckBox(tr("Draw a circle from HDOP value"));
68 private final JRadioButton colorTypeVelocity = new JRadioButton(tr("Velocity (red = slow, green = fast)"));
69 private final JRadioButton colorTypeDirection = new JRadioButton(tr("Direction (red = west, yellow = north, green = east, blue = south)"));
70 private final JRadioButton colorTypeDilution = new JRadioButton(tr("Dilution of Position (red = high, green = low, if available)"));
71 private final JRadioButton colorTypeQuality = new JRadioButton(tr("Quality (RTKLib only, if available)"));
72 private final JRadioButton colorTypeTime = new JRadioButton(tr("Track date"));
73 private final JRadioButton colorTypeHeatMap = new JRadioButton(tr("Heat Map (dark = few, bright = many)"));
74 private final JRadioButton colorTypeNone = new JRadioButton(tr("Single Color (can be customized in the layer manager)"));
75 private final JRadioButton colorTypeGlobal = new JRadioButton(tr("Use global settings"));
76 private final JosmComboBox<String> colorTypeVelocityTune = new JosmComboBox<>(new String[] {tr("Car"), tr("Bicycle"), tr("Foot")});
77 private final JosmComboBox<String> colorTypeHeatMapTune = new JosmComboBox<>(new String[] {
78 trc("Heat map", "User Normal"),
79 trc("Heat map", "User Light"),
80 trc("Heat map", "Traffic Lights"),
81 trc("Heat map", "Inferno"),
82 trc("Heat map", "Viridis"),
83 trc("Heat map", "Wood"),
84 trc("Heat map", "Heat")});
85 private final JCheckBox colorTypeHeatMapPoints = new JCheckBox(tr("Use points instead of lines for heat map"));
86 private final JSlider colorTypeHeatMapGain = new JSlider();
87 private final JSlider colorTypeHeatMapLowerLimit = new JSlider();
88 private final JCheckBox makeAutoMarkers = new JCheckBox(tr("Create markers when reading GPX"));
89 private final JCheckBox drawGpsArrows = new JCheckBox(tr("Draw Direction Arrows"));
90 private final JCheckBox drawGpsArrowsFast = new JCheckBox(tr("Fast drawing (looks uglier)"));
91 private final JosmTextField drawGpsArrowsMinDist = new JosmTextField(8);
92 private final JCheckBox colorDynamic = new JCheckBox(tr("Dynamic color range based on data limits"));
93 private final JosmComboBox<String> waypointLabel = new JosmComboBox<>(LABEL_PATTERN_DESC);
94 private final JosmTextField waypointLabelPattern = new JosmTextField();
95 private final JosmComboBox<String> audioWaypointLabel = new JosmComboBox<>(LABEL_PATTERN_DESC);
96 private final JosmTextField audioWaypointLabelPattern = new JosmTextField();
97 private final JCheckBox useGpsAntialiasing = new JCheckBox(tr("Smooth GPX graphics (antialiasing)"));
98 private final JCheckBox drawLineWithAlpha = new JCheckBox(tr("Draw with Opacity (alpha blending) "));
99
100 private final List<GpxLayer> layers;
101 private final GpxLayer firstLayer;
102 private final boolean global; // global settings vs. layer specific settings
103 private final boolean hasLocalFile; // flag to display LocalOnly checkbooks
104 private final boolean hasNonLocalFile; // flag to display AllLines checkbox
105
106 private final static Map<String, Object> DEFAULT_PREFS = getDefaultPrefs();
107
108 private static Map<String, Object> getDefaultPrefs() {
109 HashMap<String, Object> m = new HashMap<>();
110 m.put("colormode", -1);
111 m.put("colormode.dynamic-range", false);
112 m.put("colormode.heatmap.colormap", 0);
113 m.put("colormode.heatmap.gain", 0);
114 m.put("colormode.heatmap.line-extra", false); //Einstein only
115 m.put("colormode.heatmap.lower-limit", 0);
116 m.put("colormode.heatmap.use-points", false);
117 m.put("colormode.time.min-distance", 60); //Einstein only
118 m.put("colormode.velocity.tune", 45);
119 m.put("lines", -1);
120 m.put("lines.alpha-blend", false);
121 m.put("lines.arrows", false);
122 m.put("lines.arrows.fast", false);
123 m.put("lines.arrows.min-distance", 40);
124 m.put("lines.force", false);
125 m.put("lines.max-length", 200);
126 m.put("lines.max-length.local", -1);
127 m.put("lines.width", 0);
128 m.put("markers.color", "");
129 m.put("markers.show-text", true);
130 m.put("markers.pattern", Marker.LABEL_PATTERN_AUTO);
131 m.put("markers.audio.pattern", "?{ '{name}' | '{desc}' | '{" + Marker.MARKER_FORMATTED_OFFSET + "}' }");
132 m.put("points.hdopcircle", false);
133 m.put("points.large", false);
134 m.put("points.large.alpha", -1); //Einstein only
135 m.put("points.large.size", 3); //Einstein only
136 return Collections.unmodifiableMap(m);
137 }
138
139 /**
140 * Constructs a new {@code GPXSettingsPanel} for the given layers.
141 * @param layers the GPX layers
142 */
143 public GPXSettingsPanel(List<GpxLayer> layers) {
144 super(new GridBagLayout());
145 this.layers = layers;
146 if (layers == null || layers.isEmpty()) {
147 throw new InvalidArgumentException("At least one layer required");
148 }
149 firstLayer = layers.get(0);
150 global = false;
151 hasLocalFile = layers.stream().anyMatch(GpxLayer::isLocalFile);
152 hasNonLocalFile = layers.stream().anyMatch(l -> !l.isLocalFile());
153 initComponents();
154 loadPreferences();
155 }
156
157 /**
158 * Constructs a new {@code GPXSettingsPanel}.
159 */
160 public GPXSettingsPanel() {
161 super(new GridBagLayout());
162 layers = null;
163 firstLayer = null;
164 global = hasLocalFile = hasNonLocalFile = true;
165 initComponents();
166 loadPreferences(); // preferences -> controls
167 }
168
169 /**
170 * Reads the preference for the given layer or the default preference if not available
171 * @param layer the GpxLayer. Can be <code>null</code>, default preference will be returned then
172 * @param key the drawing key to be read, without "draw.rawgps."
173 * @return the value
174 */
175 public static String getLayerPref(GpxLayer layer, String key) {
176 Object d = DEFAULT_PREFS.get(key);
177 String ds;
178 if (d != null) {
179 ds = d.toString();
180 } else {
181 Logging.warn("No default value found for layer preference \"" + key + "\".");
182 ds = null;
183 }
184 return Optional.ofNullable(tryGetLayerPrefLocal(layer, key)).orElse(Config.getPref().get("draw.rawgps." + key, ds));
185 }
186
187 /**
188 * Reads the integer preference for the given layer or the default preference if not available
189 * @param layer the GpxLayer. Can be <code>null</code>, default preference will be returned then
190 * @param key the drawing key to be read, without "draw.rawgps."
191 * @return the integer value
192 */
193 public static int getLayerPrefInt(GpxLayer layer, String key) {
194 String s = getLayerPref(layer, key);
195 if (s != null) {
196 try {
197 return Integer.parseInt(s);
198 } catch (NumberFormatException ex) {
199 Object d = DEFAULT_PREFS.get(key);
200 if (d instanceof Integer) {
201 return (int) d;
202 } else {
203 Logging.warn("No valid default value found for layer preference \"" + key + "\".");
204 }
205 }
206 }
207 return 0;
208 }
209
210 /**
211 * Try to read the preference for the given layer
212 * @param layer the GpxLayer
213 * @param key the drawing key to be read, without "draw.rawgps."
214 * @return the value or <code>null</code> if not found
215 */
216 public static String tryGetLayerPrefLocal(GpxLayer layer, String key) {
217 return layer != null ? tryGetLayerPrefLocal(layer.data, key) : null;
218 }
219
220 /**
221 * Try to read the preference for the given GpxData
222 * @param data the GpxData
223 * @param key the drawing key to be read, without "draw.rawgps."
224 * @return the value or <code>null</code> if not found
225 */
226 public static String tryGetLayerPrefLocal(GpxData data, String key) {
227 return data != null ? data.getLayerPrefs().get(key) : null;
228 }
229
230 /**
231 * Puts the preference for the given layers or the default preference if layers is <code>null</code>
232 * @param layers List of <code>GpxLayer</code> to put the drawingOptions
233 * @param key the drawing key to be written, without "draw.rawgps."
234 * @param value (can be <code>null</code> to remove option)
235 */
236 public static void putLayerPref(List<GpxLayer> layers, String key, Object value) {
237 String v = value == null ? null : value.toString();
238 if (layers != null) {
239 for (GpxLayer l : layers) {
240 putLayerPrefLocal(l.data, key, v);
241 }
242 } else {
243 Config.getPref().put("draw.rawgps." + key, v);
244 }
245 }
246
247 /**
248 * Puts the preference for the given layer
249 * @param layer <code>GpxLayer</code> to put the drawingOptions
250 * @param key the drawing key to be written, without "draw.rawgps."
251 * @param value the value or <code>null</code> to remove key
252 */
253 public static void putLayerPrefLocal(GpxLayer layer, String key, String value) {
254 if (layer == null) return;
255 putLayerPrefLocal(layer.data, key, value);
256 }
257
258 /**
259 * Puts the preference for the given layer
260 * @param data <code>GpxData</code> to put the drawingOptions. Must not be <code>null</code>
261 * @param key the drawing key to be written, without "draw.rawgps."
262 * @param value the value or <code>null</code> to remove key
263 */
264 public static void putLayerPrefLocal(GpxData data, String key, String value) {
265 if (value == null || value.trim().isEmpty() || (getLayerPref(null, key).equals(value) && DEFAULT_PREFS.get(key) != null && DEFAULT_PREFS.get(key).toString().equals(value))) {
266 data.getLayerPrefs().remove(key);
267 } else {
268 data.getLayerPrefs().put(key, value);
269 }
270 }
271
272 private String pref(String key) {
273 return getLayerPref(firstLayer, key);
274 }
275
276 private boolean prefBool(String key) {
277 return Boolean.parseBoolean(pref(key));
278 }
279
280 private int prefInt(String key) {
281 return getLayerPrefInt(firstLayer, key);
282 }
283
284 private int prefIntLocal(String key) {
285 try {
286 return Integer.parseInt(tryGetLayerPrefLocal(firstLayer, key));
287 } catch (NumberFormatException ex) {
288 return -1;
289 }
290
291 }
292
293 private void putPref(String key, Object value) {
294 putLayerPref(layers, key, value);
295 }
296
297 // CHECKSTYLE.OFF: ExecutableStatementCountCheck
298 private void initComponents() {
299 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
300
301 if (global) {
302 // makeAutoMarkers
303 makeAutoMarkers.setToolTipText(tr("Automatically make a marker layer from any waypoints when opening a GPX layer."));
304 ExpertToggleAction.addVisibilitySwitcher(makeAutoMarkers);
305 add(makeAutoMarkers, GBC.eol().insets(20, 0, 0, 5));
306 }
307
308 // drawRawGpsLines
309 ButtonGroup gpsLinesGroup = new ButtonGroup();
310 if (!global) {
311 gpsLinesGroup.add(drawRawGpsLinesGlobal);
312 }
313 gpsLinesGroup.add(drawRawGpsLinesNone);
314 gpsLinesGroup.add(drawRawGpsLinesLocal);
315 gpsLinesGroup.add(drawRawGpsLinesAll);
316
317 /* ensure that default is in data base */
318
319 JLabel label = new JLabel(tr("Draw lines between raw GPS points"));
320 add(label, GBC.eol().insets(20, 0, 0, 0));
321 if (!global) {
322 add(drawRawGpsLinesGlobal, GBC.eol().insets(40, 0, 0, 0));
323 }
324 add(drawRawGpsLinesNone, GBC.eol().insets(40, 0, 0, 0));
325 if (hasLocalFile) {
326 add(drawRawGpsLinesLocal, GBC.eol().insets(40, 0, 0, 0));
327 }
328 if (hasNonLocalFile) {
329 add(drawRawGpsLinesAll, GBC.eol().insets(40, 0, 0, 0));
330 }
331 ExpertToggleAction.addVisibilitySwitcher(label);
332 ExpertToggleAction.addVisibilitySwitcher(drawRawGpsLinesGlobal);
333 ExpertToggleAction.addVisibilitySwitcher(drawRawGpsLinesNone);
334 ExpertToggleAction.addVisibilitySwitcher(drawRawGpsLinesLocal);
335 ExpertToggleAction.addVisibilitySwitcher(drawRawGpsLinesAll);
336
337 drawRawGpsLinesActionListener = e -> {
338 boolean f = drawRawGpsLinesNone.isSelected() || drawRawGpsLinesGlobal.isSelected();
339 forceRawGpsLines.setEnabled(!f);
340 drawRawGpsMaxLineLength.setEnabled(!(f || drawRawGpsLinesLocal.isSelected()));
341 drawRawGpsMaxLineLengthLocal.setEnabled(!f);
342 drawGpsArrows.setEnabled(!f);
343 drawGpsArrowsFast.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
344 drawGpsArrowsMinDist.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
345 };
346
347 drawRawGpsLinesGlobal.addActionListener(drawRawGpsLinesActionListener);
348 drawRawGpsLinesNone.addActionListener(drawRawGpsLinesActionListener);
349 drawRawGpsLinesLocal.addActionListener(drawRawGpsLinesActionListener);
350 drawRawGpsLinesAll.addActionListener(drawRawGpsLinesActionListener);
351
352 // drawRawGpsMaxLineLengthLocal
353 drawRawGpsMaxLineLengthLocal.setToolTipText(
354 tr("Maximum length (in meters) to draw lines for local files. Set to ''-1'' to draw all lines."));
355 label = new JLabel(tr("Maximum length for local files (meters)"));
356 add(label, GBC.std().insets(40, 0, 0, 0));
357 add(drawRawGpsMaxLineLengthLocal, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
358 ExpertToggleAction.addVisibilitySwitcher(label);
359 ExpertToggleAction.addVisibilitySwitcher(drawRawGpsMaxLineLengthLocal);
360
361 // drawRawGpsMaxLineLength
362 drawRawGpsMaxLineLength.setToolTipText(tr("Maximum length (in meters) to draw lines. Set to ''-1'' to draw all lines."));
363 label = new JLabel(tr("Maximum length (meters)"));
364 add(label, GBC.std().insets(40, 0, 0, 0));
365 add(drawRawGpsMaxLineLength, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
366 ExpertToggleAction.addVisibilitySwitcher(label);
367 ExpertToggleAction.addVisibilitySwitcher(drawRawGpsMaxLineLength);
368
369 // forceRawGpsLines
370 forceRawGpsLines.setToolTipText(tr("Force drawing of lines if the imported data contain no line information."));
371 add(forceRawGpsLines, GBC.eop().insets(40, 0, 0, 0));
372 ExpertToggleAction.addVisibilitySwitcher(forceRawGpsLines);
373
374 // drawGpsArrows
375 drawGpsArrows.addActionListener(e -> {
376 drawGpsArrowsFast.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
377 drawGpsArrowsMinDist.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
378 });
379 drawGpsArrows.setToolTipText(tr("Draw direction arrows for lines, connecting GPS points."));
380 add(drawGpsArrows, GBC.eop().insets(20, 0, 0, 0));
381
382 // drawGpsArrowsFast
383 drawGpsArrowsFast.setToolTipText(tr("Draw the direction arrows using table lookups instead of complex math."));
384 add(drawGpsArrowsFast, GBC.eop().insets(40, 0, 0, 0));
385 ExpertToggleAction.addVisibilitySwitcher(drawGpsArrowsFast);
386
387 // drawGpsArrowsMinDist
388 drawGpsArrowsMinDist.setToolTipText(tr("Do not draw arrows if they are not at least this distance away from the last one."));
389 add(new JLabel(tr("Minimum distance (pixels)")), GBC.std().insets(40, 0, 0, 0));
390 add(drawGpsArrowsMinDist, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
391
392 // hdopCircleGpsPoints
393 hdopCircleGpsPoints.setToolTipText(tr("Draw a circle from HDOP value"));
394 add(hdopCircleGpsPoints, GBC.eop().insets(20, 0, 0, 0));
395 ExpertToggleAction.addVisibilitySwitcher(hdopCircleGpsPoints);
396
397 // largeGpsPoints
398 largeGpsPoints.setToolTipText(tr("Draw larger dots for the GPS points."));
399 add(largeGpsPoints, GBC.eop().insets(20, 0, 0, 0));
400
401 // drawLineWidth
402 drawLineWidth.setToolTipText(tr("Width of drawn GPX line (0 for default)"));
403 add(new JLabel(tr("Drawing width of GPX lines")), GBC.std().insets(20, 0, 0, 0));
404 add(drawLineWidth, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
405
406 // antialiasing
407 useGpsAntialiasing.setToolTipText(tr("Apply antialiasing to the GPX lines resulting in a smoother appearance."));
408 add(useGpsAntialiasing, GBC.eop().insets(20, 0, 0, 0));
409 ExpertToggleAction.addVisibilitySwitcher(useGpsAntialiasing);
410
411 // alpha blending
412 drawLineWithAlpha.setToolTipText(tr("Apply dynamic alpha-blending and adjust width based on zoom level for all GPX lines."));
413 add(drawLineWithAlpha, GBC.eop().insets(20, 0, 0, 0));
414 ExpertToggleAction.addVisibilitySwitcher(drawLineWithAlpha);
415
416 // colorTracks
417 ButtonGroup colorGroup = new ButtonGroup();
418 if (!global) {
419 colorGroup.add(colorTypeGlobal);
420 }
421 colorGroup.add(colorTypeNone);
422 colorGroup.add(colorTypeVelocity);
423 colorGroup.add(colorTypeDirection);
424 colorGroup.add(colorTypeDilution);
425 colorGroup.add(colorTypeQuality);
426 colorGroup.add(colorTypeTime);
427 colorGroup.add(colorTypeHeatMap);
428
429 colorTypeNone.setToolTipText(tr("All points and track segments will have their own color. Can be customized in Layer Manager."));
430 colorTypeVelocity.setToolTipText(tr("Colors points and track segments by velocity."));
431 colorTypeDirection.setToolTipText(tr("Colors points and track segments by direction."));
432 colorTypeDilution.setToolTipText(
433 tr("Colors points and track segments by dilution of position (HDOP). Your capture device needs to log that information."));
434 colorTypeQuality.setToolTipText(
435 tr("Colors points and track segments by RTKLib quality flag (Q). Your capture device needs to log that information."));
436 colorTypeTime.setToolTipText(tr("Colors points and track segments by its timestamp."));
437 colorTypeHeatMap.setToolTipText(tr("Collected points and track segments for a position and displayed as heat map."));
438
439 // color Tracks by Velocity Tune
440 colorTypeVelocityTune.setToolTipText(tr("Allows to tune the track coloring for different average speeds."));
441
442 colorTypeHeatMapTune.setToolTipText(tr("Selects the color schema for heat map."));
443 JLabel colorTypeHeatIconLabel = new JLabel();
444
445 add(Box.createVerticalGlue(), GBC.eol().insets(0, 20, 0, 0));
446
447 add(new JLabel(tr("Track and Point Coloring")), GBC.eol().insets(20, 0, 0, 0));
448 if (!global) {
449 add(colorTypeGlobal, GBC.eol().insets(40, 0, 0, 0));
450 }
451 add(colorTypeNone, GBC.eol().insets(40, 0, 0, 0));
452 add(colorTypeVelocity, GBC.std().insets(40, 0, 0, 0));
453 add(colorTypeVelocityTune, GBC.eop().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
454 add(colorTypeDirection, GBC.eol().insets(40, 0, 0, 0));
455 add(colorTypeDilution, GBC.eol().insets(40, 0, 0, 0));
456 add(colorTypeQuality, GBC.eol().insets(40, 0, 0, 0));
457 add(colorTypeTime, GBC.eol().insets(40, 0, 0, 0));
458 add(colorTypeHeatMap, GBC.std().insets(40, 0, 0, 0));
459 add(colorTypeHeatIconLabel, GBC.std().insets(5, 0, 0, 5));
460 add(colorTypeHeatMapTune, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
461
462 JLabel colorTypeHeatMapGainLabel = new JLabel(tr("Overlay gain adjustment"));
463 JLabel colorTypeHeatMapLowerLimitLabel = new JLabel(tr("Lower limit of visibility"));
464 add(colorTypeHeatMapGainLabel, GBC.std().insets(80, 0, 0, 0));
465 add(colorTypeHeatMapGain, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
466 add(colorTypeHeatMapLowerLimitLabel, GBC.std().insets(80, 0, 0, 0));
467 add(colorTypeHeatMapLowerLimit, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
468 add(colorTypeHeatMapPoints, GBC.eol().insets(60, 0, 0, 0));
469
470 colorTypeHeatMapGain.setToolTipText(tr("Adjust the gain of overlay blending."));
471 colorTypeHeatMapGain.setOrientation(JSlider.HORIZONTAL);
472 colorTypeHeatMapGain.setPaintLabels(true);
473 colorTypeHeatMapGain.setMinimum(-10);
474 colorTypeHeatMapGain.setMaximum(+10);
475 colorTypeHeatMapGain.setMinorTickSpacing(1);
476 colorTypeHeatMapGain.setMajorTickSpacing(5);
477
478 colorTypeHeatMapLowerLimit.setToolTipText(tr("Draw all GPX traces that exceed this threshold."));
479 colorTypeHeatMapLowerLimit.setOrientation(JSlider.HORIZONTAL);
480 colorTypeHeatMapLowerLimit.setMinimum(0);
481 colorTypeHeatMapLowerLimit.setMaximum(254);
482 colorTypeHeatMapLowerLimit.setPaintLabels(true);
483 colorTypeHeatMapLowerLimit.setMinorTickSpacing(10);
484 colorTypeHeatMapLowerLimit.setMajorTickSpacing(100);
485
486 colorTypeHeatMapPoints.setToolTipText(tr("Render engine uses points with simulated position error instead of lines. "));
487
488 // iterate over the buttons, add change listener to any change event
489 for (Enumeration<AbstractButton> button = colorGroup.getElements(); button.hasMoreElements();) {
490 (button.nextElement()).addChangeListener(e -> {
491 colorTypeVelocityTune.setEnabled(colorTypeVelocity.isSelected());
492 colorTypeHeatMapTune.setEnabled(colorTypeHeatMap.isSelected());
493 colorTypeHeatMapPoints.setEnabled(colorTypeHeatMap.isSelected());
494 colorTypeHeatMapGain.setEnabled(colorTypeHeatMap.isSelected());
495 colorTypeHeatMapLowerLimit.setEnabled(colorTypeHeatMap.isSelected());
496 colorTypeHeatMapGainLabel.setEnabled(colorTypeHeatMap.isSelected());
497 colorTypeHeatMapLowerLimitLabel.setEnabled(colorTypeHeatMap.isSelected());
498 colorDynamic.setEnabled(colorTypeVelocity.isSelected() || colorTypeDilution.isSelected());
499 });
500 }
501
502 colorTypeHeatMapTune.addActionListener(e -> {
503 final Dimension dim = colorTypeHeatMapTune.getPreferredSize();
504 if (null != dim) {
505 // get image size of environment
506 final int iconSize = (int) dim.getHeight();
507 colorTypeHeatIconLabel.setIcon(GpxDrawHelper.getColorMapImageIcon(
508 GpxDrawHelper.DEFAULT_COLOR_PROPERTY.get(),
509 colorTypeHeatMapTune.getSelectedIndex(),
510 iconSize));
511 }
512 });
513
514 ExpertToggleAction.addVisibilitySwitcher(colorTypeDirection);
515 ExpertToggleAction.addVisibilitySwitcher(colorTypeDilution);
516 ExpertToggleAction.addVisibilitySwitcher(colorTypeQuality);
517 ExpertToggleAction.addVisibilitySwitcher(colorTypeHeatMapLowerLimit);
518 ExpertToggleAction.addVisibilitySwitcher(colorTypeHeatMapLowerLimitLabel);
519
520 colorDynamic.setToolTipText(tr("Colors points and track segments by data limits."));
521 add(colorDynamic, GBC.eop().insets(40, 0, 0, 0));
522 ExpertToggleAction.addVisibilitySwitcher(colorDynamic);
523
524 if (global) {
525 // Setting waypoints for gpx layer doesn't make sense - waypoints are shown in marker layer that has different name - so show
526 // this only for global config
527
528 // waypointLabel
529 label = new JLabel(tr("Waypoint labelling"));
530 add(label, GBC.std().insets(20, 0, 0, 0));
531 label.setLabelFor(waypointLabel);
532 add(waypointLabel, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
533 waypointLabel.addActionListener(e -> updateWaypointPattern(waypointLabel, waypointLabelPattern));
534 add(waypointLabelPattern, GBC.eol().fill(GBC.HORIZONTAL).insets(20, 0, 0, 5));
535 ExpertToggleAction.addVisibilitySwitcher(label);
536 ExpertToggleAction.addVisibilitySwitcher(waypointLabel);
537 ExpertToggleAction.addVisibilitySwitcher(waypointLabelPattern);
538
539 // audioWaypointLabel
540 Component glue = Box.createVerticalGlue();
541 add(glue, GBC.eol().insets(0, 20, 0, 0));
542 ExpertToggleAction.addVisibilitySwitcher(glue);
543
544 label = new JLabel(tr("Audio waypoint labelling"));
545 add(label, GBC.std().insets(20, 0, 0, 0));
546 label.setLabelFor(audioWaypointLabel);
547 add(audioWaypointLabel, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
548 audioWaypointLabel.addActionListener(e -> updateWaypointPattern(audioWaypointLabel, audioWaypointLabelPattern));
549 add(audioWaypointLabelPattern, GBC.eol().fill(GBC.HORIZONTAL).insets(20, 0, 0, 5));
550 ExpertToggleAction.addVisibilitySwitcher(label);
551 ExpertToggleAction.addVisibilitySwitcher(audioWaypointLabel);
552 ExpertToggleAction.addVisibilitySwitcher(audioWaypointLabelPattern);
553 }
554
555 add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH));
556 }
557 // CHECKSTYLE.ON: ExecutableStatementCountCheck
558
559 /**
560 * Loads preferences to UI controls
561 */
562 public final void loadPreferences() {
563 makeAutoMarkers.setSelected(Config.getPref().getBoolean("marker.makeautomarkers", true));
564 int lines = global ? prefInt("lines") : prefIntLocal("lines");
565 if (lines == 2 && hasNonLocalFile) {
566 drawRawGpsLinesAll.setSelected(true);
567 } else if ((lines == 1 && hasLocalFile) || (lines == -1 && global)) {
568 drawRawGpsLinesLocal.setSelected(true);
569 } else if (lines == 0) {
570 drawRawGpsLinesNone.setSelected(true);
571 } else if (lines == -1) {
572 drawRawGpsLinesGlobal.setSelected(true);
573 } else {
574 Logging.warn("Unknown line type: " + lines);
575 }
576 drawRawGpsMaxLineLengthLocal.setText(pref("lines.max-length.local"));
577 drawRawGpsMaxLineLength.setText(pref("lines.max-length"));
578 drawLineWidth.setText(pref("lines.width"));
579 drawLineWithAlpha.setSelected(prefBool("lines.alpha-blend"));
580 forceRawGpsLines.setSelected(prefBool("lines.force"));
581 drawGpsArrows.setSelected(prefBool("lines.arrows"));
582 drawGpsArrowsFast.setSelected(prefBool("lines.arrows.fast"));
583 drawGpsArrowsMinDist.setText(pref("lines.arrows.min-distance"));
584 hdopCircleGpsPoints.setSelected(prefBool("points.hdopcircle"));
585 largeGpsPoints.setSelected(prefBool("points.large"));
586 useGpsAntialiasing.setSelected(Config.getPref().getBoolean("mappaint.gpx.use-antialiasing", false));
587
588 drawRawGpsLinesActionListener.actionPerformed(null);
589 if (!global && prefIntLocal("colormode") == -1) {
590 colorTypeGlobal.setSelected(true);
591 colorDynamic.setSelected(false);
592 colorDynamic.setEnabled(false);
593 colorTypeHeatMapPoints.setSelected(false);
594 colorTypeHeatMapGain.setValue(0);
595 colorTypeHeatMapLowerLimit.setValue(0);
596 } else {
597 int colorType = prefInt("colormode");
598 switch (colorType) {
599 case -1: case 0: colorTypeNone.setSelected(true); break;
600 case 1: colorTypeVelocity.setSelected(true); break;
601 case 2: colorTypeDilution.setSelected(true); break;
602 case 3: colorTypeDirection.setSelected(true); break;
603 case 4: colorTypeTime.setSelected(true); break;
604 case 5: colorTypeHeatMap.setSelected(true); break;
605 case 6: colorTypeQuality.setSelected(true); break;
606 default: Logging.warn("Unknown color type: " + colorType);
607 }
608 int ccts = prefInt("colormode.velocity.tune");
609 colorTypeVelocityTune.setSelectedIndex(ccts == 10 ? 2 : (ccts == 20 ? 1 : 0));
610 colorTypeHeatMapTune.setSelectedIndex(prefInt("colormode.heatmap.colormap"));
611 colorDynamic.setSelected(prefBool("colormode.dynamic-range"));
612 colorTypeHeatMapPoints.setSelected(prefBool("colormode.heatmap.use-points"));
613 colorTypeHeatMapGain.setValue(prefInt("colormode.heatmap.gain"));
614 colorTypeHeatMapLowerLimit.setValue(prefInt("colormode.heatmap.lower-limit"));
615 }
616 updateWaypointLabelCombobox(waypointLabel, waypointLabelPattern, pref("markers.pattern"));
617 updateWaypointLabelCombobox(audioWaypointLabel, audioWaypointLabelPattern, pref("markers.audio.pattern"));
618
619 }
620
621 /**
622 * Save preferences from UI controls, globally or for the specified layers.
623 * @return {@code true} when restart is required, {@code false} otherwise
624 */
625 public boolean savePreferences() {
626 if (global) {
627 Config.getPref().putBoolean("marker.makeautomarkers", makeAutoMarkers.isSelected());
628 putPref("markers.pattern", waypointLabelPattern.getText());
629 putPref("markers.audio.pattern", audioWaypointLabelPattern.getText());
630 }
631 boolean g;
632 if (!global && ((g = drawRawGpsLinesGlobal.isSelected()) || drawRawGpsLinesNone.isSelected())) {
633 if (g) {
634 putPref("lines", null);
635 } else {
636 putPref("lines", 0);
637 }
638 putPref("lines.max-length", null);
639 putPref("lines.max-length.local", null);
640 putPref("lines.force", null);
641 putPref("lines.arrows", null);
642 putPref("lines.arrows.fast", null);
643 putPref("lines.arrows.min-distance", null);
644 } else {
645 if (drawRawGpsLinesLocal.isSelected()) {
646 putPref("lines", 1);
647 } else if (drawRawGpsLinesAll.isSelected()) {
648 putPref("lines", 2);
649 }
650 putPref("lines.max-length", drawRawGpsMaxLineLength.getText());
651 putPref("lines.max-length.local", drawRawGpsMaxLineLengthLocal.getText());
652 putPref("lines.force", forceRawGpsLines.isSelected());
653 putPref("lines.arrows", drawGpsArrows.isSelected());
654 putPref("lines.arrows.fast", drawGpsArrowsFast.isSelected());
655 putPref("lines.arrows.min-distance", drawGpsArrowsMinDist.getText());
656 }
657
658 putPref("points.hdopcircle", hdopCircleGpsPoints.isSelected());
659 putPref("points.large", largeGpsPoints.isSelected());
660 putPref("lines.width", drawLineWidth.getText());
661 putPref("lines.alpha-blend", drawLineWithAlpha.isSelected());
662
663 Config.getPref().putBoolean("mappaint.gpx.use-antialiasing", useGpsAntialiasing.isSelected());
664
665 if (colorTypeGlobal.isSelected()) {
666 putPref("colormode", null);
667 putPref("colormode.dynamic-range", null);
668 putPref("colormode.velocity.tune", null);
669 return false;
670 } else if (colorTypeVelocity.isSelected()) {
671 putPref("colormode", 1);
672 } else if (colorTypeDilution.isSelected()) {
673 putPref("colormode", 2);
674 } else if (colorTypeDirection.isSelected()) {
675 putPref("colormode", 3);
676 } else if (colorTypeTime.isSelected()) {
677 putPref("colormode", 4);
678 } else if (colorTypeHeatMap.isSelected()) {
679 putPref("colormode", 5);
680 } else if (colorTypeQuality.isSelected()) {
681 putPref("colormode", 6);
682 } else {
683 putPref("colormode", 0);
684 }
685 putPref("colormode.dynamic-range", colorDynamic.isSelected());
686 int ccti = colorTypeVelocityTune.getSelectedIndex();
687 putPref("colormode.velocity.tune", ccti == 2 ? 10 : (ccti == 1 ? 20 : 45));
688 putPref("colormode.heatmap.colormap", colorTypeHeatMapTune.getSelectedIndex());
689 putPref("colormode.heatmap.use-points", colorTypeHeatMapPoints.isSelected());
690 putPref("colormode.heatmap.gain", colorTypeHeatMapGain.getValue());
691 putPref("colormode.heatmap.lower-limit", colorTypeHeatMapLowerLimit.getValue());
692
693 if (!global && layers != null && !layers.isEmpty()) {
694 layers.forEach(l -> l.data.invalidate());
695 }
696
697 return false;
698 }
699
700 private static void updateWaypointLabelCombobox(JosmComboBox<String> cb, JosmTextField tf, String labelPattern) {
701 boolean found = false;
702 for (int i = 0; i < LABEL_PATTERN_TEMPLATE.length; i++) {
703 if (LABEL_PATTERN_TEMPLATE[i].equals(labelPattern)) {
704 cb.setSelectedIndex(i);
705 found = true;
706 break;
707 }
708 }
709 if (!found) {
710 cb.setSelectedIndex(WAYPOINT_LABEL_CUSTOM);
711 tf.setEnabled(true);
712 tf.setText(labelPattern);
713 }
714 }
715
716 private static void updateWaypointPattern(JosmComboBox<String> cb, JosmTextField tf) {
717 if (cb.getSelectedIndex() == WAYPOINT_LABEL_CUSTOM) {
718 tf.setEnabled(true);
719 } else {
720 tf.setEnabled(false);
721 tf.setText(LABEL_PATTERN_TEMPLATE[cb.getSelectedIndex()]);
722 }
723 }
724
725 @Override
726 public boolean validatePreferences() {
727 TemplateParser parser = new TemplateParser(waypointLabelPattern.getText());
728 try {
729 parser.parse();
730 } catch (ParseError e) {
731 Logging.warn(e);
732 JOptionPane.showMessageDialog(MainApplication.getMainFrame(),
733 tr("Incorrect waypoint label pattern: {0}", e.getMessage()), tr("Incorrect pattern"), JOptionPane.ERROR_MESSAGE);
734 waypointLabelPattern.requestFocus();
735 return false;
736 }
737 parser = new TemplateParser(audioWaypointLabelPattern.getText());
738 try {
739 parser.parse();
740 } catch (ParseError e) {
741 Logging.warn(e);
742 JOptionPane.showMessageDialog(MainApplication.getMainFrame(),
743 tr("Incorrect audio waypoint label pattern: {0}", e.getMessage()), tr("Incorrect pattern"), JOptionPane.ERROR_MESSAGE);
744 audioWaypointLabelPattern.requestFocus();
745 return false;
746 }
747 return true;
748 }
749}
Note: See TracBrowser for help on using the repository browser.