001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.preferences.display; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005import static org.openstreetmap.josm.tools.I18n.trc; 006 007import java.awt.Component; 008import java.awt.GridBagLayout; 009import java.awt.event.ActionEvent; 010import java.awt.event.ActionListener; 011 012import javax.swing.BorderFactory; 013import javax.swing.Box; 014import javax.swing.ButtonGroup; 015import javax.swing.JCheckBox; 016import javax.swing.JLabel; 017import javax.swing.JOptionPane; 018import javax.swing.JPanel; 019import javax.swing.JRadioButton; 020import javax.swing.event.ChangeEvent; 021import javax.swing.event.ChangeListener; 022 023import org.openstreetmap.josm.Main; 024import org.openstreetmap.josm.actions.ExpertToggleAction; 025import org.openstreetmap.josm.gui.layer.markerlayer.Marker; 026import org.openstreetmap.josm.gui.layer.markerlayer.Marker.TemplateEntryProperty; 027import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane.ValidationListener; 028import org.openstreetmap.josm.gui.widgets.JosmComboBox; 029import org.openstreetmap.josm.gui.widgets.JosmTextField; 030import org.openstreetmap.josm.tools.GBC; 031import org.openstreetmap.josm.tools.template_engine.ParseError; 032import org.openstreetmap.josm.tools.template_engine.TemplateParser; 033 034/** 035 * Panel for GPX settings. 036 */ 037public class GPXSettingsPanel extends JPanel implements ValidationListener { 038 039 private static final int WAYPOINT_LABEL_CUSTOM = 6; 040 private static final String[] LABEL_PATTERN_TEMPLATE = new String[] {Marker.LABEL_PATTERN_AUTO, Marker.LABEL_PATTERN_NAME, 041 Marker.LABEL_PATTERN_DESC, "{special:everything}", "?{ '{name}' | '{desc}' | '{formattedWaypointOffset}' }", ""}; 042 private static final String[] LABEL_PATTERN_DESC = new String[] {tr("Auto"), /* gpx data field name */ trc("gpx_field", "Name"), 043 /* gpx data field name */ trc("gpx_field", "Desc(ription)"), tr("Everything"), tr("Name or offset"), tr("None"), tr("Custom")}; 044 045 046 private JRadioButton drawRawGpsLinesGlobal = new JRadioButton(tr("Use global settings")); 047 private JRadioButton drawRawGpsLinesAll = new JRadioButton(tr("All")); 048 private JRadioButton drawRawGpsLinesLocal = new JRadioButton(tr("Local files")); 049 private JRadioButton drawRawGpsLinesNone = new JRadioButton(tr("None")); 050 private ActionListener drawRawGpsLinesActionListener; 051 private JosmTextField drawRawGpsMaxLineLength = new JosmTextField(8); 052 private JosmTextField drawRawGpsMaxLineLengthLocal = new JosmTextField(8); 053 private JosmTextField drawLineWidth = new JosmTextField(2); 054 private JCheckBox forceRawGpsLines = new JCheckBox(tr("Force lines if no segments imported")); 055 private JCheckBox largeGpsPoints = new JCheckBox(tr("Draw large GPS points")); 056 private JCheckBox hdopCircleGpsPoints = new JCheckBox(tr("Draw a circle from HDOP value")); 057 private JRadioButton colorTypeVelocity = new JRadioButton(tr("Velocity (red = slow, green = fast)")); 058 private JRadioButton colorTypeDirection = new JRadioButton(tr("Direction (red = west, yellow = north, green = east, blue = south)")); 059 private JRadioButton colorTypeDilution = new JRadioButton(tr("Dilution of Position (red = high, green = low, if available)")); 060 private JRadioButton colorTypeTime = new JRadioButton(tr("Track date")); 061 private JRadioButton colorTypeNone = new JRadioButton(tr("Single Color (can be customized for named layers)")); 062 private JRadioButton colorTypeGlobal = new JRadioButton(tr("Use global settings")); 063 private JosmComboBox<String> colorTypeVelocityTune = new JosmComboBox<>(new String[] {tr("Car"), tr("Bicycle"), tr("Foot")}); 064 private JCheckBox makeAutoMarkers = new JCheckBox(tr("Create markers when reading GPX")); 065 private JCheckBox drawGpsArrows = new JCheckBox(tr("Draw Direction Arrows")); 066 private JCheckBox drawGpsArrowsFast = new JCheckBox(tr("Fast drawing (looks uglier)")); 067 private JosmTextField drawGpsArrowsMinDist = new JosmTextField(8); 068 private JCheckBox colorDynamic = new JCheckBox(tr("Dynamic color range based on data limits")); 069 private JosmComboBox<String> waypointLabel = new JosmComboBox<>(LABEL_PATTERN_DESC); 070 private JosmTextField waypointLabelPattern = new JosmTextField(); 071 private JosmComboBox<String> audioWaypointLabel = new JosmComboBox<>(LABEL_PATTERN_DESC); 072 private JosmTextField audioWaypointLabelPattern = new JosmTextField(); 073 private JCheckBox useGpsAntialiasing = new JCheckBox(tr("Smooth GPX graphics (antialiasing)")); 074 075 private String layerName; 076 private final boolean local; // flag to display LocalOnly checkbox 077 private final boolean nonlocal; // flag to display AllLines checkbox 078 079 /** 080 * Constructs a new {@code GPXSettingsPanel} for a given layer name. 081 * @param layerName The GPX layer name 082 * @param local flag to display LocalOnly checkbox 083 * @param nonlocal flag to display AllLines checkbox 084 */ 085 public GPXSettingsPanel(String layerName, boolean local, boolean nonlocal) { 086 super(new GridBagLayout()); 087 this.local=local; 088 this.nonlocal=nonlocal; 089 this.layerName = "layer "+layerName; 090 initComponents(); 091 loadPreferences(); 092 } 093 094 /** 095 * Constructs a new {@code GPXSettingsPanel}. 096 */ 097 public GPXSettingsPanel() { 098 super(new GridBagLayout()); 099 initComponents(); 100 local=false; 101 nonlocal=false; 102 loadPreferences(); // preferences -> controls 103 } 104 105 private void initComponents() { 106 setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 107 108 // makeAutoMarkers 109 makeAutoMarkers.setToolTipText(tr("Automatically make a marker layer from any waypoints when opening a GPX layer.")); 110 ExpertToggleAction.addVisibilitySwitcher(makeAutoMarkers); 111 add(makeAutoMarkers, GBC.eol().insets(20,0,0,5)); 112 113 // drawRawGpsLines 114 ButtonGroup gpsLinesGroup = new ButtonGroup(); 115 if (layerName!=null) { 116 gpsLinesGroup.add(drawRawGpsLinesGlobal); 117 } 118 gpsLinesGroup.add(drawRawGpsLinesNone); 119 gpsLinesGroup.add(drawRawGpsLinesLocal); 120 gpsLinesGroup.add(drawRawGpsLinesAll); 121 122 /* ensure that default is in data base */ 123 124 JLabel label = new JLabel(tr("Draw lines between raw GPS points")); 125 add(label, GBC.eol().insets(20,0,0,0)); 126 if (layerName!=null) { 127 add(drawRawGpsLinesGlobal, GBC.eol().insets(40,0,0,0)); 128 } 129 add(drawRawGpsLinesNone, GBC.eol().insets(40,0,0,0)); 130 if (layerName==null || local) { 131 add(drawRawGpsLinesLocal, GBC.eol().insets(40,0,0,0)); 132 } 133 if (layerName==null || nonlocal) { 134 add(drawRawGpsLinesAll, GBC.eol().insets(40,0,0,0)); 135 } 136 ExpertToggleAction.addVisibilitySwitcher(label); 137 ExpertToggleAction.addVisibilitySwitcher(drawRawGpsLinesGlobal); 138 ExpertToggleAction.addVisibilitySwitcher(drawRawGpsLinesNone); 139 ExpertToggleAction.addVisibilitySwitcher(drawRawGpsLinesLocal); 140 ExpertToggleAction.addVisibilitySwitcher(drawRawGpsLinesAll); 141 142 drawRawGpsLinesActionListener = new ActionListener(){ 143 @Override 144 public void actionPerformed(ActionEvent e) { 145 boolean f=drawRawGpsLinesNone.isSelected()||drawRawGpsLinesGlobal.isSelected(); 146 forceRawGpsLines.setEnabled(!f); 147 drawRawGpsMaxLineLength.setEnabled(!(f || drawRawGpsLinesLocal.isSelected())); 148 drawRawGpsMaxLineLengthLocal.setEnabled(!f); 149 drawGpsArrows.setEnabled(!f); 150 drawGpsArrowsFast.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled()); 151 drawGpsArrowsMinDist.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled()); 152 } 153 }; 154 155 drawRawGpsLinesGlobal.addActionListener(drawRawGpsLinesActionListener); 156 drawRawGpsLinesNone.addActionListener(drawRawGpsLinesActionListener); 157 drawRawGpsLinesLocal.addActionListener(drawRawGpsLinesActionListener); 158 drawRawGpsLinesAll.addActionListener(drawRawGpsLinesActionListener); 159 160 // drawRawGpsMaxLineLengthLocal 161 drawRawGpsMaxLineLengthLocal.setToolTipText(tr("Maximum length (in meters) to draw lines for local files. Set to ''-1'' to draw all lines.")); 162 label = new JLabel(tr("Maximum length for local files (meters)")); 163 add(label, GBC.std().insets(40,0,0,0)); 164 add(drawRawGpsMaxLineLengthLocal, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5)); 165 ExpertToggleAction.addVisibilitySwitcher(label); 166 ExpertToggleAction.addVisibilitySwitcher(drawRawGpsMaxLineLengthLocal); 167 168 // drawRawGpsMaxLineLength 169 drawRawGpsMaxLineLength.setToolTipText(tr("Maximum length (in meters) to draw lines. Set to ''-1'' to draw all lines.")); 170 label = new JLabel(tr("Maximum length (meters)")); 171 add(label, GBC.std().insets(40,0,0,0)); 172 add(drawRawGpsMaxLineLength, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5)); 173 ExpertToggleAction.addVisibilitySwitcher(label); 174 ExpertToggleAction.addVisibilitySwitcher(drawRawGpsMaxLineLength); 175 176 // forceRawGpsLines 177 forceRawGpsLines.setToolTipText(tr("Force drawing of lines if the imported data contain no line information.")); 178 add(forceRawGpsLines, GBC.eop().insets(40,0,0,0)); 179 ExpertToggleAction.addVisibilitySwitcher(forceRawGpsLines); 180 181 // drawGpsArrows 182 drawGpsArrows.addActionListener(new ActionListener(){ 183 @Override 184 public void actionPerformed(ActionEvent e) { 185 drawGpsArrowsFast.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled()); 186 drawGpsArrowsMinDist.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled()); 187 } 188 }); 189 drawGpsArrows.setToolTipText(tr("Draw direction arrows for lines, connecting GPS points.")); 190 add(drawGpsArrows, GBC.eop().insets(40,0,0,0)); 191 192 // drawGpsArrowsFast 193 drawGpsArrowsFast.setToolTipText(tr("Draw the direction arrows using table lookups instead of complex math.")); 194 add(drawGpsArrowsFast, GBC.eop().insets(60,0,0,0)); 195 ExpertToggleAction.addVisibilitySwitcher(drawGpsArrowsFast); 196 197 // drawGpsArrowsMinDist 198 drawGpsArrowsMinDist.setToolTipText(tr("Do not draw arrows if they are not at least this distance away from the last one.")); 199 add(new JLabel(tr("Minimum distance (pixels)")), GBC.std().insets(60,0,0,0)); 200 add(drawGpsArrowsMinDist, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5)); 201 202 // hdopCircleGpsPoints 203 hdopCircleGpsPoints.setToolTipText(tr("Draw a circle from HDOP value.")); 204 add(hdopCircleGpsPoints, GBC.eop().insets(20,0,0,0)); 205 ExpertToggleAction.addVisibilitySwitcher(hdopCircleGpsPoints); 206 207 // largeGpsPoints 208 largeGpsPoints.setToolTipText(tr("Draw larger dots for the GPS points.")); 209 add(largeGpsPoints, GBC.eop().insets(20,0,0,0)); 210 211 // drawLineWidth 212 drawLineWidth.setToolTipText(tr("Width of drawn GPX line (0 for default)")); 213 add(new JLabel(tr("Drawing width of GPX lines")), GBC.std().insets(20,0,0,0)); 214 add(drawLineWidth, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5)); 215 216 // antialiasing 217 useGpsAntialiasing.setToolTipText(tr("Apply antialiasing to the GPX lines resulting in a smoother appearance.")); 218 add(useGpsAntialiasing, GBC.eop().insets(20, 0, 0, 0)); 219 ExpertToggleAction.addVisibilitySwitcher(useGpsAntialiasing); 220 221 // colorTracks 222 ButtonGroup colorGroup = new ButtonGroup(); 223 if (layerName!=null) { 224 colorGroup.add(colorTypeGlobal); 225 } 226 colorGroup.add(colorTypeNone); 227 colorGroup.add(colorTypeVelocity); 228 colorGroup.add(colorTypeDirection); 229 colorGroup.add(colorTypeDilution); 230 colorGroup.add(colorTypeTime); 231 232 colorTypeVelocity.addChangeListener(new ChangeListener(){ 233 @Override 234 public void stateChanged(ChangeEvent e) { 235 colorTypeVelocityTune.setEnabled(colorTypeVelocity.isSelected()); 236 colorDynamic.setEnabled(colorTypeVelocity.isSelected() || colorTypeDilution.isSelected()); 237 } 238 }); 239 colorTypeDilution.addChangeListener(new ChangeListener(){ 240 @Override 241 public void stateChanged(ChangeEvent e) { 242 colorDynamic.setEnabled(colorTypeVelocity.isSelected() || colorTypeDilution.isSelected()); 243 } 244 }); 245 246 colorTypeNone.setToolTipText(tr("All points and track segments will have the same color. Can be customized in Layer Manager.")); 247 colorTypeVelocity.setToolTipText(tr("Colors points and track segments by velocity.")); 248 colorTypeDirection.setToolTipText(tr("Colors points and track segments by direction.")); 249 colorTypeDilution.setToolTipText(tr("Colors points and track segments by dilution of position (HDOP). Your capture device needs to log that information.")); 250 colorTypeTime.setToolTipText(tr("Colors points and track segments by its timestamp.")); 251 252 // color Tracks by Velocity Tune 253 colorTypeVelocityTune.setToolTipText(tr("Allows to tune the track coloring for different average speeds.")); 254 255 add(Box.createVerticalGlue(), GBC.eol().insets(0, 20, 0, 0)); 256 257 add(new JLabel(tr("Track and Point Coloring")), GBC.eol().insets(20,0,0,0)); 258 if (layerName!=null) { 259 add(colorTypeGlobal, GBC.eol().insets(40,0,0,0)); 260 } 261 add(colorTypeNone, GBC.eol().insets(40,0,0,0)); 262 add(colorTypeVelocity, GBC.std().insets(40,0,0,0)); 263 add(colorTypeVelocityTune, GBC.eop().insets(5,0,0,5)); 264 add(colorTypeDirection, GBC.eol().insets(40,0,0,0)); 265 add(colorTypeDilution, GBC.eol().insets(40,0,0,0)); 266 add(colorTypeTime, GBC.eol().insets(40,0,0,0)); 267 ExpertToggleAction.addVisibilitySwitcher(colorTypeDirection); 268 ExpertToggleAction.addVisibilitySwitcher(colorTypeDilution); 269 270 colorDynamic.setToolTipText(tr("Colors points and track segments by data limits.")); 271 add(colorDynamic, GBC.eop().insets(40,0,0,0)); 272 ExpertToggleAction.addVisibilitySwitcher(colorDynamic); 273 274 if (layerName == null) { 275 // Setting waypoints for gpx layer doesn't make sense - waypoints are shown in marker layer that has different name - so show 276 // this only for global config 277 278 // waypointLabel 279 label = new JLabel(tr("Waypoint labelling")); 280 add(label, GBC.std().insets(20,0,0,0)); 281 add(waypointLabel, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5)); 282 waypointLabel.addActionListener(new ActionListener() { 283 @Override 284 public void actionPerformed(ActionEvent e) { 285 updateWaypointPattern(waypointLabel, waypointLabelPattern); 286 } 287 }); 288 updateWaypointLabelCombobox(waypointLabel, waypointLabelPattern, TemplateEntryProperty.forMarker(layerName)); 289 add(waypointLabelPattern, GBC.eol().fill(GBC.HORIZONTAL).insets(20,0,0,5)); 290 ExpertToggleAction.addVisibilitySwitcher(label); 291 ExpertToggleAction.addVisibilitySwitcher(waypointLabel); 292 ExpertToggleAction.addVisibilitySwitcher(waypointLabelPattern); 293 294 // audioWaypointLabel 295 Component glue = Box.createVerticalGlue(); 296 add(glue, GBC.eol().insets(0, 20, 0, 0)); 297 ExpertToggleAction.addVisibilitySwitcher(glue); 298 299 label = new JLabel(tr("Audio waypoint labelling")); 300 add(label, GBC.std().insets(20,0,0,0)); 301 add(audioWaypointLabel, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5)); 302 audioWaypointLabel.addActionListener(new ActionListener() { 303 @Override 304 public void actionPerformed(ActionEvent e) { 305 updateWaypointPattern(audioWaypointLabel, audioWaypointLabelPattern); 306 } 307 }); 308 updateWaypointLabelCombobox(audioWaypointLabel, audioWaypointLabelPattern, TemplateEntryProperty.forAudioMarker(layerName)); 309 add(audioWaypointLabelPattern, GBC.eol().fill(GBC.HORIZONTAL).insets(20,0,0,5)); 310 ExpertToggleAction.addVisibilitySwitcher(label); 311 ExpertToggleAction.addVisibilitySwitcher(audioWaypointLabel); 312 ExpertToggleAction.addVisibilitySwitcher(audioWaypointLabelPattern); 313 } 314 315 add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH)); 316 } 317 318 /** 319 * Loads preferences to UI controls 320 */ 321 public final void loadPreferences () { 322 makeAutoMarkers.setSelected(Main.pref.getBoolean("marker.makeautomarkers", true)); 323 if(layerName!=null && Main.pref.get("draw.rawgps.lines."+layerName).isEmpty() 324 && Main.pref.get("draw.rawgps.lines.local."+layerName).isEmpty()){ 325 // no line preferences for layer is found 326 drawRawGpsLinesGlobal.setSelected(true); 327 } else { 328 Boolean lf = Main.pref.getBoolean("draw.rawgps.lines.local",layerName, true); 329 if(Main.pref.getBoolean("draw.rawgps.lines",layerName, true)) { 330 drawRawGpsLinesAll.setSelected(true); 331 } else if (lf) { 332 drawRawGpsLinesLocal.setSelected(true); 333 } else { 334 drawRawGpsLinesNone.setSelected(true); 335 } 336 } 337 338 drawRawGpsMaxLineLengthLocal.setText(Integer.toString(Main.pref.getInteger("draw.rawgps.max-line-length.local",layerName, -1))); 339 drawRawGpsMaxLineLength.setText(Integer.toString(Main.pref.getInteger("draw.rawgps.max-line-length",layerName, 200))); 340 drawLineWidth.setText(Integer.toString(Main.pref.getInteger("draw.rawgps.linewidth",layerName, 0))); 341 forceRawGpsLines.setSelected(Main.pref.getBoolean("draw.rawgps.lines.force",layerName, false)); 342 drawGpsArrows.setSelected(Main.pref.getBoolean("draw.rawgps.direction",layerName, false)); 343 drawGpsArrowsFast.setSelected(Main.pref.getBoolean("draw.rawgps.alternatedirection",layerName, false)); 344 drawGpsArrowsMinDist.setText(Integer.toString(Main.pref.getInteger("draw.rawgps.min-arrow-distance",layerName, 40))); 345 hdopCircleGpsPoints.setSelected(Main.pref.getBoolean("draw.rawgps.hdopcircle",layerName, false)); 346 largeGpsPoints.setSelected(Main.pref.getBoolean("draw.rawgps.large",layerName, false)); 347 useGpsAntialiasing.setSelected(Main.pref.getBoolean("mappaint.gpx.use-antialiasing", false)); 348 drawRawGpsLinesActionListener.actionPerformed(null); 349 350 if(layerName!=null && Main.pref.get("draw.rawgps.colors."+layerName).isEmpty()) { 351 colorTypeGlobal.setSelected(true); 352 colorDynamic.setSelected(false); 353 colorDynamic.setEnabled(false); 354 } else { 355 switch(Main.pref.getInteger("draw.rawgps.colors",layerName, 0)) { 356 case 0: colorTypeNone.setSelected(true); break; 357 case 1: colorTypeVelocity.setSelected(true); break; 358 case 2: colorTypeDilution.setSelected(true); break; 359 case 3: colorTypeDirection.setSelected(true); break; 360 case 4: colorTypeTime.setSelected(true); break; 361 } 362 int ccts = Main.pref.getInteger("draw.rawgps.colorTracksTune",layerName, 45); 363 colorTypeVelocityTune.setSelectedIndex(ccts==10 ? 2 : (ccts==20 ? 1 : 0)); 364 colorTypeVelocityTune.setEnabled(colorTypeVelocity.isSelected() && colorTypeVelocity.isEnabled()); 365 colorDynamic.setSelected(Main.pref.getBoolean("draw.rawgps.colors.dynamic",layerName, false)); 366 colorDynamic.setEnabled(colorTypeVelocity.isSelected() || colorTypeDilution.isSelected()); 367 } 368 } 369 370 /** 371 * Save preferences from UI controls, globally or for a specified layer. 372 * @param layerName The GPX layer name. Can be {@code null}, in that case, global preferences are written 373 * @param locLayer {@code true} if the GPX layer is a local one. Ignored if {@code layerName} is null 374 * @return {@code true} when restart is required, {@code false} otherwise 375 */ 376 public boolean savePreferences(String layerName, boolean locLayer) { 377 String layerNameDot = ".layer "+layerName; 378 if (layerName==null) { 379 layerNameDot=""; 380 } 381 Main.pref.put("marker.makeautomarkers"+layerNameDot, makeAutoMarkers.isSelected()); 382 if (drawRawGpsLinesGlobal.isSelected()) { 383 Main.pref.put("draw.rawgps.lines" + layerNameDot, null); 384 Main.pref.put("draw.rawgps.max-line-length" + layerNameDot, null); 385 Main.pref.put("draw.rawgps.lines.local" + layerNameDot, null); 386 Main.pref.put("draw.rawgps.max-line-length.local" + layerNameDot, null); 387 Main.pref.put("draw.rawgps.lines.force"+layerNameDot, null); 388 Main.pref.put("draw.rawgps.direction"+layerNameDot, null); 389 Main.pref.put("draw.rawgps.alternatedirection"+layerNameDot, null); 390 Main.pref.put("draw.rawgps.min-arrow-distance"+layerNameDot, null); 391 } else { 392 if (layerName==null || !locLayer) { 393 Main.pref.put("draw.rawgps.lines" + layerNameDot, drawRawGpsLinesAll.isSelected()); 394 Main.pref.put("draw.rawgps.max-line-length" + layerNameDot, drawRawGpsMaxLineLength.getText()); 395 } 396 if (layerName==null || locLayer) { 397 Main.pref.put("draw.rawgps.lines.local" + layerNameDot, drawRawGpsLinesAll.isSelected() || drawRawGpsLinesLocal.isSelected()); 398 Main.pref.put("draw.rawgps.max-line-length.local" + layerNameDot, drawRawGpsMaxLineLengthLocal.getText()); 399 } 400 Main.pref.put("draw.rawgps.lines.force"+layerNameDot, forceRawGpsLines.isSelected()); 401 Main.pref.put("draw.rawgps.direction"+layerNameDot, drawGpsArrows.isSelected()); 402 Main.pref.put("draw.rawgps.alternatedirection"+layerNameDot, drawGpsArrowsFast.isSelected()); 403 Main.pref.put("draw.rawgps.min-arrow-distance"+layerNameDot, drawGpsArrowsMinDist.getText()); 404 } 405 406 Main.pref.put("draw.rawgps.hdopcircle"+layerNameDot, hdopCircleGpsPoints.isSelected()); 407 Main.pref.put("draw.rawgps.large"+layerNameDot, largeGpsPoints.isSelected()); 408 Main.pref.put("draw.rawgps.linewidth"+layerNameDot, drawLineWidth.getText()); 409 Main.pref.put("mappaint.gpx.use-antialiasing", useGpsAntialiasing.isSelected()); 410 411 TemplateEntryProperty.forMarker(layerName).put(waypointLabelPattern.getText()); 412 TemplateEntryProperty.forAudioMarker(layerName).put(audioWaypointLabelPattern.getText()); 413 414 if(colorTypeGlobal.isSelected()) { 415 Main.pref.put("draw.rawgps.colors"+layerNameDot, null); 416 Main.pref.put("draw.rawgps.colors.dynamic"+layerNameDot, null); 417 Main.pref.put("draw.rawgps.colorTracksTunec"+layerNameDot, null); 418 return false; 419 } else if(colorTypeVelocity.isSelected()) { 420 Main.pref.putInteger("draw.rawgps.colors"+layerNameDot, 1); 421 } else if(colorTypeDilution.isSelected()) { 422 Main.pref.putInteger("draw.rawgps.colors"+layerNameDot, 2); 423 } else if(colorTypeDirection.isSelected()) { 424 Main.pref.putInteger("draw.rawgps.colors"+layerNameDot, 3); 425 } else if(colorTypeTime.isSelected()) { 426 Main.pref.putInteger("draw.rawgps.colors"+layerNameDot, 4); 427 } else { 428 Main.pref.putInteger("draw.rawgps.colors"+layerNameDot, 0); 429 } 430 Main.pref.put("draw.rawgps.colors.dynamic"+layerNameDot, colorDynamic.isSelected()); 431 int ccti=colorTypeVelocityTune.getSelectedIndex(); 432 Main.pref.putInteger("draw.rawgps.colorTracksTune"+layerNameDot, ccti==2 ? 10 : (ccti==1 ? 20 : 45)); 433 return false; 434 } 435 436 /** 437 * Save preferences from UI controls for initial layer or globally 438 * @return {@code true} when restart is required, {@code false} otherwise 439 */ 440 public boolean savePreferences() { 441 return savePreferences(null, false); 442 } 443 444 private void updateWaypointLabelCombobox(JosmComboBox<String> cb, JosmTextField tf, TemplateEntryProperty property) { 445 String labelPattern = property.getAsString(); 446 boolean found = false; 447 for (int i=0; i<LABEL_PATTERN_TEMPLATE.length; i++) { 448 if (LABEL_PATTERN_TEMPLATE[i].equals(labelPattern)) { 449 cb.setSelectedIndex(i); 450 found = true; 451 break; 452 } 453 } 454 if (!found) { 455 cb.setSelectedIndex(WAYPOINT_LABEL_CUSTOM); 456 tf.setEnabled(true); 457 tf.setText(labelPattern); 458 } 459 } 460 461 private void updateWaypointPattern(JosmComboBox<String> cb, JosmTextField tf) { 462 if (cb.getSelectedIndex() == WAYPOINT_LABEL_CUSTOM) { 463 tf.setEnabled(true); 464 } else { 465 tf.setEnabled(false); 466 tf.setText(LABEL_PATTERN_TEMPLATE[cb.getSelectedIndex()]); 467 } 468 } 469 470 @Override 471 public boolean validatePreferences() { 472 TemplateParser parser = new TemplateParser(waypointLabelPattern.getText()); 473 try { 474 parser.parse(); 475 } catch (ParseError e) { 476 JOptionPane.showMessageDialog(Main.parent, tr("Incorrect waypoint label pattern: {0}", e.getMessage()), tr("Incorrect pattern"), JOptionPane.ERROR_MESSAGE); 477 waypointLabelPattern.requestFocus(); 478 return false; 479 } 480 parser = new TemplateParser(audioWaypointLabelPattern.getText()); 481 try { 482 parser.parse(); 483 } catch (ParseError e) { 484 JOptionPane.showMessageDialog(Main.parent, tr("Incorrect audio waypoint label pattern: {0}", e.getMessage()), tr("Incorrect pattern"), JOptionPane.ERROR_MESSAGE); 485 audioWaypointLabelPattern.requestFocus(); 486 return false; 487 } 488 return true; 489 } 490}