Class SystemOfMeasurement

java.lang.Object
org.openstreetmap.josm.data.SystemOfMeasurement

public class SystemOfMeasurement extends Object
A system of units used to express length and area measurements.

This class also manages one globally set system of measurement stored in the ProjectionPreference

Since:
3406 (creation), 6992 (extraction in this package)
  • Field Details

  • Constructor Details

    • SystemOfMeasurement

      public SystemOfMeasurement(String name, double aValue, String aName, double bValue, String bName, String speedName, double speedValue)
      System of measurement. Currently covers only length (and area) units. If a quantity x is given in m (x_m) and in unit a (x_a) then it translates as x_a == x_m / aValue
      Parameters:
      name - Translatable name of this system of measurement
      aValue - First value, in meters, used to translate unit according to above formula.
      aName - First unit used to format text.
      bValue - Second value, in meters, used to translate unit according to above formula.
      bName - Second unit used to format text.
      speedName - the most common speed symbol (kmh/h, mph, kn, etc.)
      speedValue - the speed value for the most common speed symbol, for 1 meter per second
      Since:
      15395
    • SystemOfMeasurement

      public SystemOfMeasurement(String name, double aValue, String aName, double bValue, String bName, String speedName, double speedValue, double areaCustomValue, String areaCustomName)
      System of measurement. Currently covers only length (and area) units. If a quantity x is given in m (x_m) and in unit a (x_a) then it translates as x_a == x_m / aValue
      Parameters:
      name - Translatable name of this system of measurement
      aValue - First value, in meters, used to translate unit according to above formula.
      aName - First unit used to format text.
      bValue - Second value, in meters, used to translate unit according to above formula.
      bName - Second unit used to format text.
      speedName - the most common speed symbol (kmh/h, mph, kn, etc.)
      speedValue - the speed value for the most common speed symbol, for 1 meter per second
      areaCustomValue - Specific optional area value, in squared meters, between aValue*aValue and bValue*bValue. Set to -1 if not used.
      areaCustomName - Specific optional area unit. Set to null if not used.
      Since:
      15395
  • Method Details

    • removeSoMChangeListener

      Removes a global SoM change listener.
      Parameters:
      listener - the listener. Ignored if null or already absent
      Since:
      8554
    • addSoMChangeListener

      Adds a SoM change listener.
      Parameters:
      listener - the listener. Ignored if null or already registered.
      Since:
      8554
    • fireSoMChanged

      protected static void fireSoMChanged(String oldSoM, String newSoM)
    • getSystemOfMeasurement

      Returns the current global system of measurement.
      Returns:
      The current system of measurement (metric system by default).
      Since:
      8554
    • setSystemOfMeasurement

      public static void setSystemOfMeasurement(SystemOfMeasurement som)
      Sets the current global system of measurement.
      Parameters:
      som - The system of measurement to set. Must be defined in ALL_SYSTEMS.
      Throws:
      IllegalArgumentException - if som is not known
      Since:
      16985 (signature)
    • getDistText

      public String getDistText(double dist)
      Returns the text describing the given distance in this system of measurement.
      Parameters:
      dist - The distance in metres
      Returns:
      The text describing the given distance in this system of measurement.
    • getDistText

      public String getDistText(double dist, NumberFormat format, double threshold)
      Returns the text describing the given distance in this system of measurement.
      Parameters:
      dist - The distance in metres
      format - A NumberFormat to format the area value
      threshold - Values lower than this threshold are displayed as "< [threshold]"
      Returns:
      The text describing the given distance in this system of measurement.
      Since:
      6422
    • getAreaText

      public String getAreaText(double area)
      Returns the text describing the given area in this system of measurement.
      Parameters:
      area - The area in square metres
      Returns:
      The text describing the given area in this system of measurement.
      Since:
      5560
    • getAreaText

      public String getAreaText(double area, NumberFormat format, double threshold)
      Returns the text describing the given area in this system of measurement.
      Parameters:
      area - The area in square metres
      format - A NumberFormat to format the area value
      threshold - Values lower than this threshold are displayed as "< [threshold]"
      Returns:
      The text describing the given area in this system of measurement.
      Since:
      6422
    • getName

      public String getName()
      Returns the translatable name of this system of measurement.
      Returns:
      the translatable name of this system of measurement
      Since:
      15395
    • toString

      public String toString()
      Returns the localized name of this system of measurement
      Overrides:
      toString in class Object
      Returns:
      the localized name
    • getDefault

      Returns the default system of measurement for the current country.
      Returns:
      the default system of measurement for the current country
      Since:
      15395
    • formatText

      private static String formatText(double v, String unit, NumberFormat format)