Changeset 6422 in josm for trunk/src/org
- Timestamp:
- 2013-11-29T00:10:15+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r6317 r6422 11 11 import java.awt.geom.AffineTransform; 12 12 import java.awt.geom.Point2D; 13 import java.text.NumberFormat; 13 14 import java.util.ArrayList; 14 15 import java.util.Collection; … … 1462 1463 */ 1463 1464 public String getDistText(double dist) { 1465 return getDistText(dist, null, 0.01); 1466 } 1467 1468 /** 1469 * Returns the text describing the given distance in this system of measurement. 1470 * @param dist The distance in metres 1471 * @param format A {@link NumberFormat} to format the area value 1472 * @param threshold Values lower than this {@code threshold} are displayed as {@code "< [threshold]"} 1473 * @return The text describing the given distance in this system of measurement. 1474 * @since 6422 1475 */ 1476 public String getDistText(final double dist, final NumberFormat format, final double threshold) { 1464 1477 double a = dist / aValue; 1465 1478 if (!Main.pref.getBoolean("system_of_measurement.use_only_lower_unit", false) && a > bValue / aValue) 1466 return formatText(dist / bValue, bName );1467 else if (a < 0.01)1468 return "< 0.01 " + aName;1479 return formatText(dist / bValue, bName, format); 1480 else if (a < threshold) 1481 return "< " + formatText(threshold, aName, format); 1469 1482 else 1470 return formatText(a, aName );1483 return formatText(a, aName, format); 1471 1484 } 1472 1485 … … 1478 1491 */ 1479 1492 public String getAreaText(double area) { 1493 return getAreaText(area, null, 0.01); 1494 } 1495 1496 /** 1497 * Returns the text describing the given area in this system of measurement. 1498 * @param area The area in square metres 1499 * @param format A {@link NumberFormat} to format the area value 1500 * @param threshold Values lower than this {@code threshold} are displayed as {@code "< [threshold]"} 1501 * @return The text describing the given area in this system of measurement. 1502 * @since 6422 1503 */ 1504 public String getAreaText(final double area, final NumberFormat format, final double threshold) { 1480 1505 double a = area / (aValue*aValue); 1481 1506 boolean lowerOnly = Main.pref.getBoolean("system_of_measurement.use_only_lower_unit", false); 1482 1507 boolean customAreaOnly = Main.pref.getBoolean("system_of_measurement.use_only_custom_area_unit", false); 1483 1508 if ((!lowerOnly && areaCustomValue > 0 && a > areaCustomValue / (aValue*aValue) && a < (bValue*bValue) / (aValue*aValue)) || customAreaOnly) 1484 return formatText(area / areaCustomValue, areaCustomName );1509 return formatText(area / areaCustomValue, areaCustomName, format); 1485 1510 else if (!lowerOnly && a >= (bValue*bValue) / (aValue*aValue)) 1486 return formatText(area / (bValue *bValue), bName+"\u00b2");1487 else if (a < 0.01)1488 return "< 0.01 " + aName+"\u00b2";1511 return formatText(area / (bValue * bValue), bName + "\u00b2", format); 1512 else if (a < threshold) 1513 return "< " + formatText(threshold, aName + "\u00b2", format); 1489 1514 else 1490 return formatText(a, aName+"\u00b2"); 1491 } 1492 1493 private static String formatText(double v, String unit) { 1515 return formatText(a, aName + "\u00b2", format); 1516 } 1517 1518 private static String formatText(double v, String unit, NumberFormat format) { 1519 if (format != null) { 1520 return format.format(v) + " " + unit; 1521 } 1494 1522 return String.format(Locale.US, "%." + (v<9.999999 ? 2 : 1) + "f %s", v, unit); 1495 1523 }
Note:
See TracChangeset
for help on using the changeset viewer.