Changeset 15395 in josm
- Timestamp:
- 2019-09-30T23:31:03+02:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/SystemOfMeasurement.java
r12846 r15395 5 5 6 6 import java.text.NumberFormat; 7 import java.util.Collections;8 import java.util.LinkedHashMap;9 7 import java.util.Locale; 10 8 import java.util.Map; 11 9 import java.util.Optional; 12 10 import java.util.concurrent.CopyOnWriteArrayList; 11 import java.util.function.Function; 12 import java.util.stream.Collectors; 13 import java.util.stream.Stream; 13 14 14 15 import org.openstreetmap.josm.data.preferences.StringProperty; … … 25 26 26 27 /** 27 * Preferences entry for system of measurement.28 * @since 12674 (moved from ProjectionPreference)29 */30 public static final StringProperty PROP_SYSTEM_OF_MEASUREMENT = new StringProperty("system_of_measurement", "Metric");31 32 /**33 28 * Interface to notify listeners of the change of the system of measurement. 34 29 * @since 8554 … … 49 44 * @since 3406 50 45 */ 51 public static final SystemOfMeasurement METRIC = new SystemOfMeasurement( 1, "m", 1000, "km", "km/h", 3.6, 10_000, "ha");46 public static final SystemOfMeasurement METRIC = new SystemOfMeasurement(marktr("Metric"), 1, "m", 1000, "km", "km/h", 3.6, 10_000, "ha"); 52 47 53 48 /** … … 57 52 * @since 3406 58 53 */ 59 public static final SystemOfMeasurement CHINESE = new SystemOfMeasurement( 1.0/3.0, "\u5e02\u5c3a" /* chi */, 500, "\u5e02\u91cc" /* li */,60 "km/h", 3.6, 666.0 + 2.0/3.0, "\u4ea9" /* mu */);54 public static final SystemOfMeasurement CHINESE = new SystemOfMeasurement(marktr("Chinese"), 55 1.0/3.0, "\u5e02\u5c3a" /* chi */, 500, "\u5e02\u91cc" /* li */, "km/h", 3.6, 666.0 + 2.0/3.0, "\u4ea9" /* mu */); 61 56 62 57 /** … … 64 59 * @since 3406 65 60 */ 66 public static final SystemOfMeasurement IMPERIAL = new SystemOfMeasurement(0.3048, "ft", 1609.344, "mi", "mph", 2.23694, 4046.86, "ac"); 61 public static final SystemOfMeasurement IMPERIAL = new SystemOfMeasurement(marktr("Imperial"), 62 0.3048, "ft", 1609.344, "mi", "mph", 2.23694, 4046.86, "ac"); 67 63 68 64 /** … … 70 66 * @since 5549 71 67 */ 72 public static final SystemOfMeasurement NAUTICAL_MILE = new SystemOfMeasurement(185.2, "kbl", 1852, "NM", "kn", 1.94384); 68 public static final SystemOfMeasurement NAUTICAL_MILE = new SystemOfMeasurement(marktr("Nautical Mile"), 69 185.2, "kbl", 1852, "NM", "kn", 1.94384); 73 70 74 71 /** … … 76 73 * @since 3406 77 74 */ 78 public static final Map<String, SystemOfMeasurement> ALL_SYSTEMS; 79 static { 80 Map<String, SystemOfMeasurement> map = new LinkedHashMap<>(); 81 map.put(marktr("Metric"), METRIC); 82 map.put(marktr("Chinese"), CHINESE); 83 map.put(marktr("Imperial"), IMPERIAL); 84 map.put(marktr("Nautical Mile"), NAUTICAL_MILE); 85 ALL_SYSTEMS = Collections.unmodifiableMap(map); 86 } 75 public static final Map<String, SystemOfMeasurement> ALL_SYSTEMS = Stream.of(METRIC, CHINESE, IMPERIAL, NAUTICAL_MILE) 76 .collect(Collectors.toMap(SystemOfMeasurement::getName, Function.identity())); 77 78 /** 79 * Preferences entry for system of measurement. 80 * @since 12674 (moved from ProjectionPreference) 81 */ 82 public static final StringProperty PROP_SYSTEM_OF_MEASUREMENT = new StringProperty("system_of_measurement", getDefault().getName()); 87 83 88 84 private static final CopyOnWriteArrayList<SoMChangeListener> somChangeListeners = new CopyOnWriteArrayList<>(); … … 142 138 } 143 139 140 /** Translated name of this system of measurement. */ 141 private final String name; 144 142 /** First value, in meters, used to translate unit according to above formula. */ 145 143 public final double aValue; … … 169 167 * x_a == x_m / aValue 170 168 * 169 * @param name Translated name of this system of measurement 171 170 * @param aValue First value, in meters, used to translate unit according to above formula. 172 171 * @param aName First unit used to format text. … … 175 174 * @param speedName the most common speed symbol (kmh/h, mph, kn, etc.) 176 175 * @param speedValue the speed value for the most common speed symbol, for 1 meter per second 177 * @since 1 0175178 */ 179 public SystemOfMeasurement( double aValue, String aName, double bValue, String bName, String speedName, double speedValue) {180 this( aValue, aName, bValue, bName, speedName, speedValue, -1, null);176 * @since 15395 177 */ 178 public SystemOfMeasurement(String name, double aValue, String aName, double bValue, String bName, String speedName, double speedValue) { 179 this(name, aValue, aName, bValue, bName, speedName, speedValue, -1, null); 181 180 } 182 181 … … 187 186 * x_a == x_m / aValue 188 187 * 188 * @param name Translated name of this system of measurement 189 189 * @param aValue First value, in meters, used to translate unit according to above formula. 190 190 * @param aName First unit used to format text. … … 197 197 * @param areaCustomName Specific optional area unit. Set to {@code null} if not used. 198 198 * 199 * @since 1 0175200 */ 201 public SystemOfMeasurement( double aValue, String aName, double bValue, String bName, String speedName, double speedValue,199 * @since 15395 200 */ 201 public SystemOfMeasurement(String name, double aValue, String aName, double bValue, String bName, String speedName, double speedValue, 202 202 double areaCustomValue, String areaCustomName) { 203 this.name = name; 203 204 this.aValue = aValue; 204 205 this.aName = aName; … … 271 272 } 272 273 274 /** 275 * Returns the translated name of this system of measurement. 276 * @return the translated name of this system of measurement 277 * @since 15395 278 */ 279 public String getName() { 280 return name; 281 } 282 283 /** 284 * Returns the default system of measurement for the current country. 285 * @return the default system of measurement for the current country 286 * @since 15395 287 */ 288 public static SystemOfMeasurement getDefault() { 289 switch (Locale.getDefault().getCountry()) { 290 case "US": 291 // https://en.wikipedia.org/wiki/Metrication_in_the_United_States#Current_use 292 // Imperial units still used in transportation and Earth sciences 293 return IMPERIAL; 294 default: 295 return METRIC; 296 } 297 } 298 273 299 private static String formatText(double v, String unit, NumberFormat format) { 274 300 if (format != null) { -
trunk/src/org/openstreetmap/josm/tools/I18n.java
r14811 r15395 392 392 /* try initial language settings, may be changed later again */ 393 393 if (!load(LanguageInfo.getJOSMLocaleCode())) { 394 Locale.setDefault( Locale.ENGLISH);394 Locale.setDefault(new Locale("en", Locale.getDefault().getCountry())); 395 395 } 396 396 } -
trunk/src/org/openstreetmap/josm/tools/LanguageInfo.java
r14706 r15395 203 203 l = new Locale(localeName.substring(0, country), localeName.substring(country + 1)); 204 204 } else { 205 l = new Locale(localeName );205 l = new Locale(localeName, Locale.getDefault().getCountry()); 206 206 } 207 207 return l;
Note:
See TracChangeset
for help on using the changeset viewer.