NumberFormatCollection Class
A collection of number formats for measurement values of a path annotation.
Declaration
public class NumberFormatCollection extends TrackedObjectCollection<NumberFormat>
Remarks
Call the following RectilinearMeasure methods to specify number formats of measurement values:
- RectilinearMeasure.setXAxisNumberFormats(value)
- RectilinearMeasure.setYAxisNumberFormats(value)
- RectilinearMeasure.setDistanceNumberFormats(value)
- RectilinearMeasure.setAreaNumberFormats(value)
- RectilinearMeasure.setAngleNumberFormats(value)
- RectilinearMeasure.setLineSlopeNumberFormats(value)
The collection implements the java.util.List interface and does not accept null items. If you add or insert a null item or replace an item with null, the API throws an ArgumentNullException. If you pass an index outside the collection bounds, the API throws an ArgumentOutOfRangeException.
Example: Specify Measurement Units for a Polygon Annotation
The following code snippet adds a polygon annotation that displays distances in feet and areas in square feet:
import java.io.*;
import java.nio.file.*;
import java.util.List;
import com.devexpress.docs.pdf.*;
import com.devexpress.system.drawing.*;
public class Main {
public static void main(String[] args) throws Exception {
try (PdfDocument document = new PdfDocument()) {
Page page = document.getPages().add(595, 842);
NumberFormat feet = new NumberFormat();
feet.setLabel("ft");
feet.setConversionFactor(1);
feet.setDisplayFormat(NumberDisplayFormat.SHOW_AS_DECIMAL);
NumberFormat squareFeet = new NumberFormat();
squareFeet.setLabel("sq ft");
squareFeet.setConversionFactor(1);
squareFeet.setDisplayFormat(NumberDisplayFormat.SHOW_AS_DECIMAL);
RectilinearMeasure measure = new RectilinearMeasure();
measure.setScaleRatio("1 pt = 1 ft");
measure.setXAxisNumberFormats(new NumberFormatCollection(List.of(feet)));
measure.setDistanceNumberFormats(new NumberFormatCollection(List.of(feet)));
measure.setAreaNumberFormats(new NumberFormatCollection(List.of(squareFeet)));
PolygonAnnotation polygon = new PolygonAnnotation(List.of(
new PointF(100, 600), new PointF(300, 600), new PointF(300, 700), new PointF(100, 700)));
polygon.setMeasure(measure);
page.getAnnotations().add(polygon);
Files.createDirectories(Path.of("output"));
try (OutputStream stream = Files.newOutputStream(Path.of("output", "Document.pdf"))) {
document.save(stream);
}
}
}
}
Inherited Members
Inheritance
Constructors
NumberFormatCollection() Constructor
Initializes a new instance of the NumberFormatCollection class.
Declaration
public NumberFormatCollection()
NumberFormatCollection(Iterable<NumberFormat> formats) Constructor
Initializes a new instance of the NumberFormatCollection class with the specified number formats.
Declaration
public NumberFormatCollection(Iterable<NumberFormat> formats)
Parameters
| Name | Type | Description |
|---|---|---|
| formats | java.lang.Iterable<NumberFormat> | Number formats to add to the collection. |
Exceptions
| Type | Description |
|---|---|
| ArgumentNullException | Thrown if the |
Methods
getSource() Method
Returns the internal collection that stores collection items.
Declaration
public NumberFormatCollection getSource()
Returns
| Type | Description |
|---|---|
| com.devexpress.docs.pdf.internal.NumberFormatCollection | The internal collection. |
Remarks
The getSource() method supports the internal infrastructure of the PDF Document API. Do not call the getSource() method in your code.