Package org.openstreetmap.josm.data
Class SystemOfMeasurement
- java.lang.Object
-
- org.openstreetmap.josm.data.SystemOfMeasurement
-
public class SystemOfMeasurement extends java.lang.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)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceSystemOfMeasurement.SoMChangeListenerInterface to notify listeners of the change of the system of measurement.
-
Field Summary
Fields Modifier and Type Field Description static java.util.Map<java.lang.String,SystemOfMeasurement>ALL_SYSTEMSKnown systems of measurement.java.lang.StringaNameFirst unit used to format text.java.lang.StringareaCustomNameSpecific optional area unit.doubleareaCustomValueSpecific optional area value, in squared meters, betweenaValue*aValueandbValue*bValue.doubleaValueFirst value, in meters, used to translate unit according to above formula.java.lang.StringbNameSecond unit used to format text.doublebValueSecond value, in meters, used to translate unit according to above formula.static SystemOfMeasurementCHINESEChinese system.static SystemOfMeasurementIMPERIALImperial system (British Commonwealth and former British Empire).static SystemOfMeasurementMETRICMetric system (international standard).private java.lang.StringnameTranslatable name of this system of measurement.static SystemOfMeasurementNAUTICAL_MILENautical mile system (navigation, polar exploration).static StringPropertyPROP_SYSTEM_OF_MEASUREMENTPreferences entry for system of measurement.private static java.util.concurrent.CopyOnWriteArrayList<SystemOfMeasurement.SoMChangeListener>somChangeListenersjava.lang.StringspeedNameMost common speed symbol (kmh/h, mph, kn, etc.)doublespeedValueSpeed value for the most common speed symbol, in meters per second
-
Constructor Summary
Constructors Constructor Description SystemOfMeasurement(java.lang.String name, double aValue, java.lang.String aName, double bValue, java.lang.String bName, java.lang.String speedName, double speedValue)System of measurement.SystemOfMeasurement(java.lang.String name, double aValue, java.lang.String aName, double bValue, java.lang.String bName, java.lang.String speedName, double speedValue, double areaCustomValue, java.lang.String areaCustomName)System of measurement.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidaddSoMChangeListener(SystemOfMeasurement.SoMChangeListener listener)Adds a SoM change listener.protected static voidfireSoMChanged(java.lang.String oldSoM, java.lang.String newSoM)private static java.lang.StringformatText(double v, java.lang.String unit, java.text.NumberFormat format)java.lang.StringgetAreaText(double area)Returns the text describing the given area in this system of measurement.java.lang.StringgetAreaText(double area, java.text.NumberFormat format, double threshold)Returns the text describing the given area in this system of measurement.static SystemOfMeasurementgetDefault()Returns the default system of measurement for the current country.java.lang.StringgetDistText(double dist)Returns the text describing the given distance in this system of measurement.java.lang.StringgetDistText(double dist, java.text.NumberFormat format, double threshold)Returns the text describing the given distance in this system of measurement.java.lang.StringgetName()Returns the translatable name of this system of measurement.static SystemOfMeasurementgetSystemOfMeasurement()Returns the current global system of measurement.static voidremoveSoMChangeListener(SystemOfMeasurement.SoMChangeListener listener)Removes a global SoM change listener.static voidsetSystemOfMeasurement(SystemOfMeasurement som)Sets the current global system of measurement.java.lang.StringtoString()Returns the localized name of this system of measurement
-
-
-
Field Detail
-
METRIC
public static final SystemOfMeasurement METRIC
Metric system (international standard).- Since:
- 3406
-
CHINESE
public static final SystemOfMeasurement CHINESE
Chinese system. See length units, area units- Since:
- 3406
-
IMPERIAL
public static final SystemOfMeasurement IMPERIAL
Imperial system (British Commonwealth and former British Empire).- Since:
- 3406
-
NAUTICAL_MILE
public static final SystemOfMeasurement NAUTICAL_MILE
Nautical mile system (navigation, polar exploration).- Since:
- 5549
-
ALL_SYSTEMS
public static final java.util.Map<java.lang.String,SystemOfMeasurement> ALL_SYSTEMS
Known systems of measurement.- Since:
- 3406
-
PROP_SYSTEM_OF_MEASUREMENT
public static final StringProperty PROP_SYSTEM_OF_MEASUREMENT
Preferences entry for system of measurement.- Since:
- 12674 (moved from ProjectionPreference)
-
somChangeListeners
private static final java.util.concurrent.CopyOnWriteArrayList<SystemOfMeasurement.SoMChangeListener> somChangeListeners
-
name
private final java.lang.String name
Translatable name of this system of measurement.
-
aValue
public final double aValue
First value, in meters, used to translate unit according to above formula.
-
bValue
public final double bValue
Second value, in meters, used to translate unit according to above formula.
-
aName
public final java.lang.String aName
First unit used to format text.
-
bName
public final java.lang.String bName
Second unit used to format text.
-
speedValue
public final double speedValue
Speed value for the most common speed symbol, in meters per second- Since:
- 10175
-
speedName
public final java.lang.String speedName
Most common speed symbol (kmh/h, mph, kn, etc.)- Since:
- 10175
-
areaCustomValue
public final double areaCustomValue
Specific optional area value, in squared meters, betweenaValue*aValueandbValue*bValue. Set to-1if not used.- Since:
- 5870
-
areaCustomName
public final java.lang.String areaCustomName
Specific optional area unit. Set tonullif not used.- Since:
- 5870
-
-
Constructor Detail
-
SystemOfMeasurement
public SystemOfMeasurement(java.lang.String name, double aValue, java.lang.String aName, double bValue, java.lang.String bName, java.lang.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 measurementaValue- 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(java.lang.String name, double aValue, java.lang.String aName, double bValue, java.lang.String bName, java.lang.String speedName, double speedValue, double areaCustomValue, java.lang.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 measurementaValue- 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 secondareaCustomValue- Specific optional area value, in squared meters, betweenaValue*aValueandbValue*bValue. Set to-1if not used.areaCustomName- Specific optional area unit. Set tonullif not used.- Since:
- 15395
-
-
Method Detail
-
removeSoMChangeListener
public static void removeSoMChangeListener(SystemOfMeasurement.SoMChangeListener listener)
Removes a global SoM change listener.- Parameters:
listener- the listener. Ignored if null or already absent- Since:
- 8554
-
addSoMChangeListener
public static void addSoMChangeListener(SystemOfMeasurement.SoMChangeListener listener)
Adds a SoM change listener.- Parameters:
listener- the listener. Ignored if null or already registered.- Since:
- 8554
-
fireSoMChanged
protected static void fireSoMChanged(java.lang.String oldSoM, java.lang.String newSoM)
-
getSystemOfMeasurement
public static SystemOfMeasurement 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 inALL_SYSTEMS.- Throws:
java.lang.IllegalArgumentException- ifsomis not known- Since:
- 16985 (signature)
-
getDistText
public java.lang.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 java.lang.String getDistText(double dist, java.text.NumberFormat format, double threshold)
Returns the text describing the given distance in this system of measurement.- Parameters:
dist- The distance in metresformat- ANumberFormatto format the area valuethreshold- Values lower than thisthresholdare displayed as"< [threshold]"- Returns:
- The text describing the given distance in this system of measurement.
- Since:
- 6422
-
getAreaText
public java.lang.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 java.lang.String getAreaText(double area, java.text.NumberFormat format, double threshold)
Returns the text describing the given area in this system of measurement.- Parameters:
area- The area in square metresformat- ANumberFormatto format the area valuethreshold- Values lower than thisthresholdare displayed as"< [threshold]"- Returns:
- The text describing the given area in this system of measurement.
- Since:
- 6422
-
getName
public java.lang.String getName()
Returns the translatable name of this system of measurement.- Returns:
- the translatable name of this system of measurement
- Since:
- 15395
-
toString
public java.lang.String toString()
Returns the localized name of this system of measurement- Overrides:
toStringin classjava.lang.Object- Returns:
- the localized name
-
getDefault
public static SystemOfMeasurement 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 java.lang.String formatText(double v, java.lang.String unit, java.text.NumberFormat format)
-
-