Changeset 5870 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2013-04-15T21:41:07+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r5670 r5870 1236 1236 */ 1237 1237 public static class SystemOfMeasurement { 1238 1239 /** First value, in meters, used to translate unit according to above formula. */ 1238 1240 public final double aValue; 1241 /** Second value, in meters, used to translate unit according to above formula. */ 1239 1242 public final double bValue; 1243 /** First unit used to format text. */ 1240 1244 public final String aName; 1245 /** Second unit used to format text. */ 1241 1246 public final String bName; 1247 /** Specific optional area value, in squared meters, between {@code aValue*aValue} and {@code bValue*bValue}. Set to {@code -1} if not used. 1248 * @since 5870 */ 1249 public final double areaCustomValue; 1250 /** Specific optional area unit. Set to {@code null} if not used. 1251 * @since 5870 */ 1252 public final String areaCustomName; 1242 1253 1243 1254 /** … … 1246 1257 * If a quantity x is given in m (x_m) and in unit a (x_a) then it translates as 1247 1258 * x_a == x_m / aValue 1259 * 1260 * @param aValue First value, in meters, used to translate unit according to above formula. 1261 * @param aName First unit used to format text. 1262 * @param bValue Second value, in meters, used to translate unit according to above formula. 1263 * @param bName Second unit used to format text. 1248 1264 */ 1249 1265 public SystemOfMeasurement(double aValue, String aName, double bValue, String bName) { 1266 this(aValue, aName, bValue, bName, -1, null); 1267 } 1268 1269 /** 1270 * System of measurement. Currently covers only length (and area) units. 1271 * 1272 * If a quantity x is given in m (x_m) and in unit a (x_a) then it translates as 1273 * x_a == x_m / aValue 1274 * 1275 * @param aValue First value, in meters, used to translate unit according to above formula. 1276 * @param aName First unit used to format text. 1277 * @param bValue Second value, in meters, used to translate unit according to above formula. 1278 * @param bName Second unit used to format text. 1279 * @param areaCustomValue Specific optional area value, in squared meters, between {@code aValue*aValue} and {@code bValue*bValue}. 1280 * Set to {@code -1} if not used. 1281 * @param areaCustomName Specific optional area unit. Set to {@code null} if not used. 1282 * 1283 * @since 5870 1284 */ 1285 public SystemOfMeasurement(double aValue, String aName, double bValue, String bName, double areaCustomValue, String areaCustomName) { 1250 1286 this.aValue = aValue; 1251 1287 this.aName = aName; 1252 1288 this.bValue = bValue; 1253 1289 this.bName = bName; 1290 this.areaCustomValue = areaCustomValue; 1291 this.areaCustomName = areaCustomName; 1254 1292 } 1255 1293 … … 1261 1299 public String getDistText(double dist) { 1262 1300 double a = dist / aValue; 1263 if (!Main.pref.getBoolean("system_of_measurement.use_only_lower_unit", false) && a > bValue / aValue) { 1264 double b = dist / bValue; 1265 return String.format(Locale.US, "%." + (b<10 ? 2 : 1) + "f %s", b, bName); 1266 } else if (a < 0.01) 1301 if (!Main.pref.getBoolean("system_of_measurement.use_only_lower_unit", false) && a > bValue / aValue) 1302 return formatText(dist / bValue, bName); 1303 else if (a < 0.01) 1267 1304 return "< 0.01 " + aName; 1268 1305 else 1269 return String.format(Locale.US, "%." + (a<10 ? 2 : 1) + "f %s",a, aName);1306 return formatText(a, aName); 1270 1307 } 1271 1308 … … 1278 1315 public String getAreaText(double area) { 1279 1316 double a = area / (aValue*aValue); 1280 if (!Main.pref.getBoolean("system_of_measurement.use_only_lower_unit", false) && a > bValue / aValue) { 1281 double b = area / (bValue*bValue); 1282 return String.format(Locale.US, "%." + (b<10 ? 2 : 1) + "f %s", b, bName+"\u00b2"); 1283 } else if (a < 0.01) 1284 return "< 0.01 " + aName; 1317 boolean lowerOnly = Main.pref.getBoolean("system_of_measurement.use_only_lower_unit", false); 1318 if (!lowerOnly && areaCustomValue > 0 && a > areaCustomValue / aValue*aValue && a < bValue*bValue / aValue*aValue) 1319 return formatText(area / areaCustomValue, areaCustomName); 1320 else if (!lowerOnly && a >= bValue*bValue / aValue*aValue) 1321 return formatText(area / (bValue*bValue), bName+"\u00b2"); 1322 else if (a < 0.01) 1323 return "< 0.01 " + aName+"\u00b2"; 1285 1324 else 1286 return String.format(Locale.US, "%." + (a<10 ? 2 : 1) + "f %s", a, aName+"\u00b2"); 1325 return formatText(a, aName+"\u00b2"); 1326 } 1327 1328 private static String formatText(double v, String unit) { 1329 return String.format(Locale.US, "%." + (v<9.999999 ? 2 : 1) + "f %s", v, unit); 1287 1330 } 1288 1331 } … … 1292 1335 * @since 3406 1293 1336 */ 1294 public static final SystemOfMeasurement METRIC_SOM = new SystemOfMeasurement(1, "m", 1000, "km" );1337 public static final SystemOfMeasurement METRIC_SOM = new SystemOfMeasurement(1, "m", 1000, "km", 10000, "ha"); 1295 1338 1296 1339 /**
Note:
See TracChangeset
for help on using the changeset viewer.