Class TLcdAngleFormat

java.lang.Object
java.text.Format
com.luciad.text.TLcdAngleFormat
All Implemented Interfaces:
Serializable, Cloneable

public final class TLcdAngleFormat extends Format

Parses and formats angles. More specifically:

Example for display unit 'TLcdAngleUnit.DEGREE' and program unit 'TLcdAngleUnit.RADIANS'

  • Parsing '360°' will result in 6.283185307179586 (rad)
  • Formatting '2' (rad) will result in '114.59°'

By using the ParsePosition, a string containing more than one angle can be parsed too. For instance, the example below parses four angles:

    String inputData = " 120\u00B0 3200mil 360 300some text";
    TLcdAngleFormat angleFormat = new TLcdAngleFormat();
    angleFormat.setProgramUnit(TLcdAngleUnit.DEGREE);
    angleFormat.setDisplayUnit(TLcdAngleUnit.DEGREE);

    ParsePosition parsePosition = new ParsePosition(0);
    Double value1 = (Double) angleFormat.parseObject(inputData, parsePosition); // 120
    Double value2 = (Double) angleFormat.parseObject(inputData, parsePosition); // 180
    Double value3 = (Double) angleFormat.parseObject(inputData, parsePosition); // 360
    Double value4 = (Double) angleFormat.parseObject(inputData, parsePosition); // 300

The resulting values will be 120, 180, 360, and 300. A subsequent parse will return null, because "some text" cannot be parsed.

For TLcdAngleUnit.DEGREE it is also possible to specify a custom display format. E.g. DDDMMSS to have angles formatted as 000°00'00" After setting the display unit to DEGREE using setDisplayUnit(TLcdAngleUnit.DEGREE) you can set setCustomDegreeDisplayPattern(TLcdAngleFormat.DDDMMSS).

    TLcdAngleFormat angleFormat = new TLcdAngleFormat(TLcdAngleUnit.DEGREE, TLcdAngleUnit.DEGREE);
    angleFormat.setCustomDegreeDisplayPattern(TLcdAngleFormat.DDDMMSS);
    String valueFormatted = angleFormat.format(123.4687); // 123°28'07"

Note that all measurements are formatted/parsed as is and won't be normalized to an interval such as [-180, 180] or [0, 360].
E.g. parsing "400°" will return 400 should the program unit be set to TLcdAngleUnit.DEGREE

Since:
2019.1
See Also: