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

Last change on this file since 12846 was 12846, checked in by bastiK, 7 years ago

see #15229 - use Config.getPref() wherever possible

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