Package com.luciad.text
Class TLcdScaleFormat
java.lang.Object
java.text.Format
com.luciad.text.TLcdScaleFormat
- All Implemented Interfaces:
ILcdFormatter
,ILcdParser
,Serializable
,Cloneable
Formats and parses unitless map scale ratios of the format nominator separator denominator
from and to the double representation of the scale.
The parse method also accepts single values, which are interpreted as 1 separator value
.
Some examples:
TLcdScaleFormat scaleFormat = new TLcdScaleFormat(NumberFormat.getInstance(Locale.US));
String scaleAsString = "1:25,000";
Double scale = scaleFormat.parse(scaleAsString);//0.00004
TLcdMapScale scale = scaleFormat.parseMapScale(scaleAsString);//a TLcdMapScale of 1:25,000
and
TLcdScaleFormat scaleFormat = new TLcdScaleFormat(NumberFormat.getInstance(Locale.US));
Double scale = 0.00004;
String scaleAsString = scaleFormat.format(scale);//"1 : 25,000"
String scaleAsString = scaleFormat.format(new TLcdMapScale(scale));//"1 : 25,000"
The format also parses numbers with common decadic multiple suffixes (k for kilo, m for mega/million, b for billion, g for giga,
t for trillion/tera). For example:
TLcdScaleFormat scaleFormat = new TLcdScaleFormat(NumberFormat.getInstance(Locale.US));
String scaleAsString = "1:25K";
Double scale = scaleFormat.parse(scaleAsString);//0.00004
- Since:
- 2012.1
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.text.Format
Format.Field
-
Constructor Summary
ConstructorDescriptionCreates a new scale format with a defaultNumberFormat
used to parse and format the nominator and denominator, and a default separator character (':').TLcdScaleFormat
(NumberFormat aNumberFormat) Creates a new scale format whereaNumberFormat
is used to parse and format the nominator and denominator.TLcdScaleFormat
(NumberFormat aNumberFormat, char aSeparator) Creates a new scale format whereaNumberFormat
is used to parse and format the nominator and denominator. -
Method Summary
Modifier and TypeMethodDescriptionformat
(Object obj, StringBuffer toAppendTo, FieldPosition pos) Parses a givenString
and creates a newObject
with the corresponding type/properties.parseMapScale
(String aMapScale) Parses the given map scale string into aTLcdMapScale
instance.parseObject
(String aSource) parseObject
(String aMapScale, ParsePosition pos) Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.luciad.util.ILcdFormatter
format
-
Constructor Details
-
TLcdScaleFormat
public TLcdScaleFormat()Creates a new scale format with a defaultNumberFormat
used to parse and format the nominator and denominator, and a default separator character (':'). -
TLcdScaleFormat
Creates a new scale format whereaNumberFormat
is used to parse and format the nominator and denominator. A default separator character is used (':').- Parameters:
aNumberFormat
- The number format used for parsing and formatting of the nominator and denominator
-
TLcdScaleFormat
Creates a new scale format whereaNumberFormat
is used to parse and format the nominator and denominator.aSeparator
is used to separate the nominator from the denominator- Parameters:
aNumberFormat
- The number format used for parsing and formatting of the nominator and denominatoraSeparator
- The separator char between the nominator and the denominator.aNumberFormat
must not parseaSeparator
, so e.g. using a '.' as separator might not work with certain Locale settings.
-
-
Method Details
-
format
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) throws IllegalArgumentException - Specified by:
format
in classFormat
- Throws:
IllegalArgumentException
-
parseMapScale
Parses the given map scale string into aTLcdMapScale
instance.- Parameters:
aMapScale
- the string containing the map scale- Returns:
- the parsed map scale
- Throws:
ParseException
- Since:
- 2021.0
-
parseObject
- Specified by:
parseObject
in classFormat
-
parseObject
- Overrides:
parseObject
in classFormat
- Throws:
ParseException
-
parse
Description copied from interface:ILcdParser
Parses a givenString
and creates a newObject
with the corresponding type/properties.- Specified by:
parse
in interfaceILcdParser
- Parameters:
aString
- theString
to be parsed.- Returns:
- the resulting new
Object
. - Throws:
IllegalArgumentException
- if theString
can't be parsed.
-