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
ConstructorsConstructorDescriptionCreates a new scale format with a defaultNumberFormatused to parse and format the nominator and denominator, and a default separator character (':').TLcdScaleFormat(NumberFormat aNumberFormat) Creates a new scale format whereaNumberFormatis used to parse and format the nominator and denominator.TLcdScaleFormat(NumberFormat aNumberFormat, char aSeparator) Creates a new scale format whereaNumberFormatis used to parse and format the nominator and denominator. -
Method Summary
Modifier and TypeMethodDescriptionformat(Object obj, StringBuffer toAppendTo, FieldPosition pos) Parses a givenStringand creates a newObjectwith the corresponding type/properties.parseMapScale(String aMapScale) Parses the given map scale string into aTLcdMapScaleinstance.parseObject(String aSource) parseObject(String aMapScale, ParsePosition pos) Methods inherited from class java.text.Format
clone, format, formatToCharacterIteratorMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.luciad.util.ILcdFormatter
format
-
Constructor Details
-
TLcdScaleFormat
public TLcdScaleFormat()Creates a new scale format with a defaultNumberFormatused to parse and format the nominator and denominator, and a default separator character (':'). -
TLcdScaleFormat
Creates a new scale format whereaNumberFormatis 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 whereaNumberFormatis used to parse and format the nominator and denominator.aSeparatoris 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.aNumberFormatmust 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:
formatin classFormat- Throws:
IllegalArgumentException
-
parseMapScale
Parses the given map scale string into aTLcdMapScaleinstance.- Parameters:
aMapScale- the string containing the map scale- Returns:
- the parsed map scale
- Throws:
ParseException- Since:
- 2021.0
-
parseObject
- Specified by:
parseObjectin classFormat
-
parseObject
- Overrides:
parseObjectin classFormat- Throws:
ParseException
-
parse
Description copied from interface:ILcdParserParses a givenStringand creates a newObjectwith the corresponding type/properties.- Specified by:
parsein interfaceILcdParser- Parameters:
aString- theStringto be parsed.- Returns:
- the resulting new
Object. - Throws:
IllegalArgumentException- if theStringcan't be parsed.
-