public class SystemOfMeasurement extends 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 Map<String,SystemOfMeasurement> |
ALL_SYSTEMS
Known systems of measurement.
|
String |
aName
First unit used to format text.
|
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.
|
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).
|
private static CopyOnWriteArrayList<SystemOfMeasurement.SoMChangeListener> |
somChangeListeners |
Constructor and Description |
---|
SystemOfMeasurement(double aValue,
String aName,
double bValue,
String bName)
System of measurement.
|
SystemOfMeasurement(double aValue,
String aName,
double bValue,
String bName,
double areaCustomValue,
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(String oldSoM,
String newSoM) |
private static String |
formatText(double v,
String unit,
NumberFormat format) |
String |
getAreaText(double area)
Returns the text describing the given area in this system of measurement.
|
String |
getAreaText(double area,
NumberFormat format,
double threshold)
Returns the text describing the given area in this system of measurement.
|
String |
getDistText(double dist)
Returns the text describing the given distance in this system of measurement.
|
String |
getDistText(double dist,
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(String somKey)
Sets the current global 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 Map<String,SystemOfMeasurement> ALL_SYSTEMS
private static final CopyOnWriteArrayList<SystemOfMeasurement.SoMChangeListener> somChangeListeners
public final double aValue
public final double bValue
public final double areaCustomValue
aValue*aValue
and bValue*bValue
. Set to -1
if not used.public final String areaCustomName
null
if not used.public SystemOfMeasurement(double aValue, String aName, double bValue, String bName)
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.public SystemOfMeasurement(double aValue, String aName, double bValue, String bName, double areaCustomValue, 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.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.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(String oldSoM, String newSoM)
public static SystemOfMeasurement getSystemOfMeasurement()
public static void setSystemOfMeasurement(String somKey)
somKey
- The system of measurement key. Must be defined in ALL_SYSTEMS
.IllegalArgumentException
- if somKey
is not knownpublic String getDistText(double dist)
dist
- The distance in metrespublic String getDistText(double dist, 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 String getAreaText(double area)
area
- The area in square metrespublic String getAreaText(double area, 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 String formatText(double v, String unit, NumberFormat format)