Changeset 12891 in josm for trunk/src/org
- Timestamp:
- 2017-09-23T23:20:03+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OpenFileAction.java
r12846 r12891 32 32 33 33 import org.openstreetmap.josm.Main; 34 import org.openstreetmap.josm.data.PreferencesUtils; 34 35 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 35 36 import org.openstreetmap.josm.gui.MainApplication; … … 336 337 fileHistory.removeAll(failedAll); 337 338 int maxsize = Math.max(0, Config.getPref().getInt("file-open.history.max-size", 15)); 338 Main.pref.putCollectionBounded("file-open.history", maxsize, fileHistory);339 PreferencesUtils.putCollectionBounded(Config.getPref(), "file-open.history", maxsize, fileHistory); 339 340 } 340 341 } -
trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java
r12846 r12891 16 16 17 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.data.PreferencesUtils; 18 19 import org.openstreetmap.josm.gui.ExtendedDialog; 19 20 import org.openstreetmap.josm.gui.io.importexport.FileExporter; … … 235 236 history.remove(filepath); 236 237 history.add(0, filepath); 237 Main.pref.putCollectionBounded("file-open.history", maxsize, history);238 PreferencesUtils.putCollectionBounded(Config.getPref(), "file-open.history", maxsize, history); 238 239 } 239 240 } -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r12885 r12891 660 660 * @param def The default value 661 661 * @return The boolean value or the default value if it could not be parsed 662 */ 662 * @deprecated use {@link PreferencesUtils#getBoolean(IPreferences, String, String, boolean)} 663 */ 664 @Deprecated 663 665 public synchronized boolean getBoolean(final String key, final String specName, final boolean def) { 664 666 boolean generic = getBoolean(key, def); … … 1076 1078 * @param def The default value 1077 1079 * @return The integer value or the default value if it could not be parsed 1078 */ 1080 * @deprecated use {@link PreferencesUtils#getInteger(IPreferences, String, String, int) 1081 */ 1082 @Deprecated 1079 1083 public synchronized int getInteger(String key, String specName, int def) { 1080 1084 String v = get(key+'.'+specName); … … 1122 1126 * @param value The value that should be removed in the collection 1123 1127 * @see #getList(String) 1124 */ 1128 * @deprecated use {@link PreferencesUtils#removeFromCollection(IPreferences, String, String)} 1129 */ 1130 @Deprecated 1125 1131 public synchronized void removeFromCollection(String key, String value) { 1126 1132 List<String> a = new ArrayList<>(getList(key, Collections.<String>emptyList())); … … 1230 1236 * @param val value 1231 1237 * @return {@code true}, if something has changed (i.e. value is different than before) 1232 */ 1238 * @deprecated use {@link PreferencesUtils#putCollectionBounded(IPreferences, String, int, Collection)} 1239 */ 1240 @Deprecated 1233 1241 public boolean putCollectionBounded(String key, int maxsize, Collection<String> val) { 1234 1242 List<String> newCollection = new ArrayList<>(Math.min(maxsize, val.size())); … … 1248 1256 * @param def default array value 1249 1257 * @return array value 1250 */ 1258 * @deprecated use {@link #getListOfLists(java.lang.String, java.util.List)} 1259 */ 1260 @Deprecated 1251 1261 @SuppressWarnings({ "unchecked", "rawtypes" }) 1252 1262 public synchronized Collection<Collection<String>> getArray(String key, Collection<Collection<String>> def) { -
trunk/src/org/openstreetmap/josm/data/PreferencesUtils.java
r12881 r12891 6 6 import java.util.ArrayList; 7 7 import java.util.Collection; 8 import java.util.Collections; 8 9 import java.util.HashMap; 9 10 import java.util.Iterator; … … 18 19 19 20 import org.openstreetmap.josm.Main; 21 import org.openstreetmap.josm.spi.preferences.IPreferences; 20 22 import org.openstreetmap.josm.spi.preferences.ListListSetting; 21 23 import org.openstreetmap.josm.spi.preferences.ListSetting; … … 476 478 engine.eval(init); 477 479 } 480 481 /** 482 * Gets an boolean that may be specialized 483 * @param prefs the preferences 484 * @param key The basic key 485 * @param specName The sub-key to append to the key 486 * @param def The default value 487 * @return The boolean value or the default value if it could not be parsed 488 * @since 12891 489 */ 490 public static boolean getBoolean(IPreferences prefs, final String key, final String specName, final boolean def) { 491 synchronized (prefs) { 492 boolean generic = prefs.getBoolean(key, def); 493 String skey = key+'.'+specName; 494 String svalue = prefs.get(skey, null); 495 if (svalue != null) 496 return Boolean.parseBoolean(svalue); 497 else 498 return generic; 499 } 500 } 501 502 /** 503 * Gets an integer that may be specialized 504 * @param prefs the preferences 505 * @param key The basic key 506 * @param specName The sub-key to append to the key 507 * @param def The default value 508 * @return The integer value or the default value if it could not be parsed 509 * @since 12891 510 */ 511 public static int getInteger(IPreferences prefs, String key, String specName, int def) { 512 synchronized (prefs) { 513 String v = prefs.get(key+'.'+specName); 514 if (v.isEmpty()) 515 v = prefs.get(key, Integer.toString(def)); 516 if (v.isEmpty()) 517 return def; 518 519 try { 520 return Integer.parseInt(v); 521 } catch (NumberFormatException e) { 522 // fall out 523 Logging.trace(e); 524 } 525 return def; 526 } 527 } 528 529 /** 530 * Removes a value from a given String collection 531 * @param prefs the preferences 532 * @param key The preference key the collection is stored with 533 * @param value The value that should be removed in the collection 534 * @see #getList(String) 535 * @since 12891 536 */ 537 public static void removeFromCollection(IPreferences prefs, String key, String value) { 538 synchronized (prefs) { 539 List<String> a = new ArrayList<>(prefs.getList(key, Collections.<String>emptyList())); 540 a.remove(value); 541 prefs.putList(key, a); 542 } 543 } 544 545 /** 546 * Saves at most {@code maxsize} items of collection {@code val}. 547 * @param prefs the preferences 548 * @param key key 549 * @param maxsize max number of items to save 550 * @param val value 551 * @return {@code true}, if something has changed (i.e. value is different than before) 552 * @since 12891 553 */ 554 public static boolean putCollectionBounded(IPreferences prefs, String key, int maxsize, Collection<String> val) { 555 List<String> newCollection = new ArrayList<>(Math.min(maxsize, val.size())); 556 for (String i : val) { 557 if (newCollection.size() >= maxsize) { 558 break; 559 } 560 newCollection.add(i); 561 } 562 return prefs.putList(key, newCollection); 563 } 564 478 565 } -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java
r12846 r12891 33 33 import javax.swing.ImageIcon; 34 34 35 import org.openstreetmap.josm.Main;36 35 import org.openstreetmap.josm.data.Bounds; 36 import org.openstreetmap.josm.data.PreferencesUtils; 37 37 import org.openstreetmap.josm.data.SystemOfMeasurement; 38 38 import org.openstreetmap.josm.data.SystemOfMeasurement.SoMChangeListener; … … 279 279 public ColorMode getColorMode(String layerName) { 280 280 try { 281 int i = Main.pref.getInteger("draw.rawgps.colors", specName(layerName), 0);281 int i = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.colors", specName(layerName), 0); 282 282 return ColorMode.fromIndex(i); 283 283 } catch (IndexOutOfBoundsException e) { … … 300 300 public void readPreferences(String layerName) { 301 301 String spec = specName(layerName); 302 forceLines = Main.pref.getBoolean("draw.rawgps.lines.force", spec, false);303 direction = Main.pref.getBoolean("draw.rawgps.direction", spec, false);304 lineWidth = Main.pref.getInteger("draw.rawgps.linewidth", spec, 0);305 alphaLines = Main.pref.getBoolean("draw.rawgps.lines.alpha-blend", spec, false);302 forceLines = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.lines.force", spec, false); 303 direction = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.direction", spec, false); 304 lineWidth = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.linewidth", spec, 0); 305 alphaLines = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.lines.alpha-blend", spec, false); 306 306 307 307 if (!data.fromServer) { 308 maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length.local", spec, -1);309 lines = Main.pref.getBoolean("draw.rawgps.lines.local", spec, true);308 maxLineLength = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.max-line-length.local", spec, -1); 309 lines = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.lines.local", spec, true); 310 310 } else { 311 maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length", spec, 200);312 lines = Main.pref.getBoolean("draw.rawgps.lines", spec, true);313 } 314 large = Main.pref.getBoolean("draw.rawgps.large", spec, false);315 largesize = Main.pref.getInteger("draw.rawgps.large.size", spec, 3);316 hdopCircle = Main.pref.getBoolean("draw.rawgps.hdopcircle", spec, false);311 maxLineLength = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.max-line-length", spec, 200); 312 lines = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.lines", spec, true); 313 } 314 large = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.large", spec, false); 315 largesize = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.large.size", spec, 3); 316 hdopCircle = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.hdopcircle", spec, false); 317 317 colored = getColorMode(layerName); 318 alternateDirection = Main.pref.getBoolean("draw.rawgps.alternatedirection", spec, false);319 delta = Main.pref.getInteger("draw.rawgps.min-arrow-distance", spec, 40);320 colorTracksTune = Main.pref.getInteger("draw.rawgps.colorTracksTune", spec, 45);321 colorModeDynamic = Main.pref.getBoolean("draw.rawgps.colors.dynamic", spec, false);318 alternateDirection = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.alternatedirection", spec, false); 319 delta = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.min-arrow-distance", spec, 40); 320 colorTracksTune = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.colorTracksTune", spec, 45); 321 colorModeDynamic = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.colors.dynamic", spec, false); 322 322 /* good HDOP's are between 1 and 3, very bad HDOP's go into 3 digit values */ 323 323 hdoprange = Config.getPref().getInt("hdop.range", 7); … … 326 326 327 327 // get heatmap parameters 328 heatMapEnabled = Main.pref.getBoolean("draw.rawgps.heatmap.enabled", spec, false);329 heatMapDrawExtraLine = Main.pref.getBoolean("draw.rawgps.heatmap.line-extra", spec, false);330 heatMapDrawColorTableIdx = Main.pref.getInteger("draw.rawgps.heatmap.colormap", spec, 0);331 heatMapDrawPointMode = Main.pref.getBoolean("draw.rawgps.heatmap.use-points", spec, false);332 heatMapDrawGain = Main.pref.getInteger("draw.rawgps.heatmap.gain", spec, 0);333 heatMapDrawLowerLimit = Main.pref.getInteger("draw.rawgps.heatmap.lower-limit", spec, 0);328 heatMapEnabled = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.heatmap.enabled", spec, false); 329 heatMapDrawExtraLine = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.heatmap.line-extra", spec, false); 330 heatMapDrawColorTableIdx = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.heatmap.colormap", spec, 0); 331 heatMapDrawPointMode = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.heatmap.use-points", spec, false); 332 heatMapDrawGain = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.heatmap.gain", spec, 0); 333 heatMapDrawLowerLimit = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.heatmap.lower-limit", spec, 0); 334 334 335 335 // shrink to range -
trunk/src/org/openstreetmap/josm/gui/preferences/display/GPXSettingsPanel.java
r12846 r12891 25 25 import org.openstreetmap.josm.Main; 26 26 import org.openstreetmap.josm.actions.ExpertToggleAction; 27 import org.openstreetmap.josm.data.PreferencesUtils; 27 28 import org.openstreetmap.josm.gui.layer.gpx.GpxDrawHelper; 28 29 import org.openstreetmap.josm.gui.layer.markerlayer.Marker; … … 392 393 drawRawGpsLinesGlobal.setSelected(true); 393 394 } else { 394 Boolean lf = Main.pref.getBoolean("draw.rawgps.lines.local", layerName, true);395 if ( Main.pref.getBoolean("draw.rawgps.lines", layerName, true)) {395 Boolean lf = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.lines.local", layerName, true); 396 if (PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.lines", layerName, true)) { 396 397 drawRawGpsLinesAll.setSelected(true); 397 398 } else if (lf) { … … 402 403 } 403 404 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)); 405 drawRawGpsMaxLineLengthLocal.setText(Integer.toString(PreferencesUtils.getInteger(Config.getPref(), 406 "draw.rawgps.max-line-length.local", layerName, -1))); 407 drawRawGpsMaxLineLength.setText(Integer.toString(PreferencesUtils.getInteger(Config.getPref(), 408 "draw.rawgps.max-line-length", layerName, 200))); 409 drawLineWidth.setText(Integer.toString(PreferencesUtils.getInteger(Config.getPref(), 410 "draw.rawgps.linewidth", layerName, 0))); 411 drawLineWithAlpha.setSelected(PreferencesUtils.getBoolean(Config.getPref(), 412 "draw.rawgps.lines.alpha-blend", layerName, false)); 413 forceRawGpsLines.setSelected(PreferencesUtils.getBoolean(Config.getPref(), 414 "draw.rawgps.lines.force", layerName, false)); 415 drawGpsArrows.setSelected(PreferencesUtils.getBoolean(Config.getPref(), 416 "draw.rawgps.direction", layerName, false)); 417 drawGpsArrowsFast.setSelected(PreferencesUtils.getBoolean(Config.getPref(), 418 "draw.rawgps.alternatedirection", layerName, false)); 419 drawGpsArrowsMinDist.setText(Integer.toString(PreferencesUtils.getInteger(Config.getPref(), 420 "draw.rawgps.min-arrow-distance", layerName, 40))); 421 hdopCircleGpsPoints.setSelected(PreferencesUtils.getBoolean(Config.getPref(), 422 "draw.rawgps.hdopcircle", layerName, false)); 423 largeGpsPoints.setSelected(PreferencesUtils.getBoolean(Config.getPref(), 424 "draw.rawgps.large", layerName, false)); 414 425 useGpsAntialiasing.setSelected(Config.getPref().getBoolean("mappaint.gpx.use-antialiasing", false)); 415 426 … … 424 435 colorTypeHeatMapLowerLimit.setValue(0); 425 436 } else { 426 int colorType = Main.pref.getInteger("draw.rawgps.colors", layerName, 0);437 int colorType = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.colors", layerName, 0); 427 438 switch (colorType) { 428 439 case 0: colorTypeNone.setSelected(true); break; … … 434 445 default: Logging.warn("Unknown color type: " + colorType); 435 446 } 436 int ccts = Main.pref.getInteger("draw.rawgps.colorTracksTune", layerName, 45);447 int ccts = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.colorTracksTune", layerName, 45); 437 448 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)); 449 colorTypeHeatMapTune.setSelectedIndex(PreferencesUtils.getInteger(Config.getPref(), 450 "draw.rawgps.heatmap.colormap", layerName, 0)); 451 colorDynamic.setSelected(PreferencesUtils.getBoolean(Config.getPref(), 452 "draw.rawgps.colors.dynamic", layerName, false)); 453 colorTypeHeatMapPoints.setSelected(PreferencesUtils.getBoolean(Config.getPref(), 454 "draw.rawgps.heatmap.use-points", layerName, false)); 455 colorTypeHeatMapGain.setValue(PreferencesUtils.getInteger(Config.getPref(), 456 "draw.rawgps.heatmap.gain", layerName, 0)); 457 colorTypeHeatMapLowerLimit.setValue(PreferencesUtils.getInteger(Config.getPref(), 458 "draw.rawgps.heatmap.lower-limit", layerName, 0)); 443 459 } 444 460 } -
trunk/src/org/openstreetmap/josm/io/UploadStrategy.java
r12846 r12891 6 6 import java.util.Locale; 7 7 8 import org.openstreetmap.josm. Main;8 import org.openstreetmap.josm.data.PreferencesUtils; 9 9 import org.openstreetmap.josm.spi.preferences.Config; 10 10 import org.openstreetmap.josm.tools.Logging; … … 85 85 v = Config.getPref().get("osm-server.atomic-upload", null); 86 86 if (v != null) { 87 Main.pref.removeFromCollection("osm-server.atomic-upload", v);87 PreferencesUtils.removeFromCollection(Config.getPref(), "osm-server.atomic-upload", v); 88 88 } else { 89 89 v = ""; -
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r12873 r12891 54 54 import org.openstreetmap.josm.Main; 55 55 import org.openstreetmap.josm.actions.RestartAction; 56 import org.openstreetmap.josm.data.PreferencesUtils; 56 57 import org.openstreetmap.josm.data.Version; 57 58 import org.openstreetmap.josm.gui.HelpAwareOptionPane; … … 348 349 if (plugins.contains(depr.name)) { 349 350 plugins.remove(depr.name); 350 Main.pref.removeFromCollection("plugins", depr.name);351 PreferencesUtils.removeFromCollection(Config.getPref(), "plugins", depr.name); 351 352 removedPlugins.add(depr); 352 353 } … … 402 403 Utils.escapeReservedCharactersHTML(unmaintained)); 403 404 if (confirmDisablePlugin(parent, msg, unmaintained)) { 404 Main.pref.removeFromCollection("plugins", unmaintained);405 PreferencesUtils.removeFromCollection(Config.getPref(), "plugins", unmaintained); 405 406 plugins.remove(unmaintained); 406 407 } … … 800 801 } 801 802 if (msg != null && confirmDisablePlugin(parent, msg, plugin.name)) { 802 Main.pref.removeFromCollection("plugins", plugin.name);803 PreferencesUtils.removeFromCollection(Config.getPref(), "plugins", plugin.name); 803 804 } 804 805 }
Note:
See TracChangeset
for help on using the changeset viewer.