public class SystemOfMeasurement extends java.lang.Object
This class also manages one globally set system of measurement stored in the ProjectionPreference
Modifier and Type | Class and Description |
---|---|
static interface |
SystemOfMeasurement.SoMChangeListener
Interface to notify listeners of the change of the system of measurement.
|
Modifier and Type | Field and Description |
---|---|
static java.util.Map<java.lang.String,SystemOfMeasurement> |
ALL_SYSTEMS
Known systems of measurement.
|
java.lang.String |
aName
First unit used to format text.
|
java.lang.String |
areaCustomName
Specific optional area unit.
|
double |
areaCustomValue
Specific optional area value, in squared meters, between
aValue*aValue and bValue*bValue . |
double |
aValue
First value, in meters, used to translate unit according to above formula.
|
java.lang.String |
bName
Second unit used to format text.
|
double |
bValue
Second value, in meters, used to translate unit according to above formula.
|
static SystemOfMeasurement |
CHINESE
Chinese system.
|
static SystemOfMeasurement |
IMPERIAL
Imperial system (British Commonwealth and former British Empire).
|
static SystemOfMeasurement |
METRIC
Metric system (international standard).
|
static SystemOfMeasurement |
NAUTICAL_MILE
Nautical mile system (navigation, polar exploration).
|
static StringProperty |
PROP_SYSTEM_OF_MEASUREMENT
Preferences entry for system of measurement.
|
private static java.util.concurrent.CopyOnWriteArrayList<SystemOfMeasurement.SoMChangeListener> |
somChangeListeners |
java.lang.String |
speedName
Most common speed symbol (kmh/h, mph, kn, etc.)
|
double |
speedValue
Speed value for the most common speed symbol, in meters per second
|
Constructor and Description |
---|
SystemOfMeasurement(double aValue,
java.lang.String aName,
double bValue,
java.lang.String bName,
java.lang.String speedName,
double speedValue)
System of measurement.
|
SystemOfMeasurement(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.
|
Modifier and Type | Method and Description |
---|---|
static void |
addSoMChangeListener(SystemOfMeasurement.SoMChangeListener listener)
Adds a SoM change listener.
|
protected static void |
fireSoMChanged(java.lang.String oldSoM,
java.lang.String newSoM) |
private static java.lang.String |
formatText(double v,
java.lang.String unit,
java.text.NumberFormat format) |
java.lang.String |
getAreaText(double area)
Returns the text describing the given area in this system of measurement.
|
java.lang.String |
getAreaText(double area,
java.text.NumberFormat format,
double threshold)
Returns the text describing the given area in this system of measurement.
|
java.lang.String |
getDistText(double dist)
Returns the text describing the given distance in this system of measurement.
|
java.lang.String |
getDistText(double dist,
java.text.NumberFormat format,
double threshold)
Returns the text describing the given distance in this system of measurement.
|
static SystemOfMeasurement |
getSystemOfMeasurement()
Returns the current global system of measurement.
|
static void |
removeSoMChangeListener(SystemOfMeasurement.SoMChangeListener listener)
Removes a global SoM change listener.
|
static void |
setSystemOfMeasurement(java.lang.String somKey)
Sets the current global system of measurement.
|
public static final StringProperty PROP_SYSTEM_OF_MEASUREMENT
public static final SystemOfMeasurement METRIC
public static final SystemOfMeasurement CHINESE
public static final SystemOfMeasurement IMPERIAL
public static final SystemOfMeasurement NAUTICAL_MILE
public static final java.util.Map<java.lang.String,SystemOfMeasurement> ALL_SYSTEMS
private static final java.util.concurrent.CopyOnWriteArrayList<SystemOfMeasurement.SoMChangeListener> somChangeListeners
public final double aValue
public final double bValue
public final java.lang.String aName
public final java.lang.String bName
public final double speedValue
public final java.lang.String speedName
public final double areaCustomValue
aValue*aValue
and bValue*bValue
. Set to -1
if not used.public final java.lang.String areaCustomName
null
if not used.public SystemOfMeasurement(double aValue, java.lang.String aName, double bValue, java.lang.String bName, java.lang.String speedName, double speedValue)
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 secondpublic SystemOfMeasurement(double aValue, java.lang.String aName, double bValue, java.lang.String bName, java.lang.String speedName, double speedValue, double areaCustomValue, java.lang.String areaCustomName)
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 secondareaCustomValue
- 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.public static void removeSoMChangeListener(SystemOfMeasurement.SoMChangeListener listener)
listener
- the listener. Ignored if null or already absentpublic static void addSoMChangeListener(SystemOfMeasurement.SoMChangeListener listener)
listener
- the listener. Ignored if null or already registered.protected static void fireSoMChanged(java.lang.String oldSoM, java.lang.String newSoM)
public static SystemOfMeasurement getSystemOfMeasurement()
public static void setSystemOfMeasurement(java.lang.String somKey)
somKey
- The system of measurement key. Must be defined in ALL_SYSTEMS
.java.lang.IllegalArgumentException
- if somKey
is not knownpublic java.lang.String getDistText(double dist)
dist
- The distance in metrespublic java.lang.String getDistText(double dist, java.text.NumberFormat format, double threshold)
dist
- The distance in metresformat
- A NumberFormat
to format the area valuethreshold
- Values lower than this threshold
are displayed as "< [threshold]"
public java.lang.String getAreaText(double area)
area
- The area in square metrespublic java.lang.String getAreaText(double area, java.text.NumberFormat format, double threshold)
area
- The area in square metresformat
- A NumberFormat
to format the area valuethreshold
- Values lower than this threshold
are displayed as "< [threshold]"
private static java.lang.String formatText(double v, java.lang.String unit, java.text.NumberFormat format)