public class GeneralFormat
extends java.lang.Object
Examples:
Shows how to format field results.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a field that displays a result with no format applied.
Field field = builder.insertField("= 2 + 3");
Assert.assertEquals("= 2 + 3", field.getFieldCode());
Assert.assertEquals("5", field.getResult());
// We can apply a format to a field's result using the field's properties.
// Below are three types of formats that we can apply to a field's result.
// 1 - Numeric format:
FieldFormat format = field.getFormat();
format.setNumericFormat("$###.00");
field.update();
Assert.assertEquals("= 2 + 3 \\# $###.00", field.getFieldCode());
Assert.assertEquals("$ 5.00", field.getResult());
// 2 - Date/time format:
field = builder.insertField("DATE");
format = field.getFormat();
format.setDateTimeFormat("dddd, MMMM dd, yyyy");
field.update();
Assert.assertEquals("DATE \\@ \"dddd, MMMM dd, yyyy\"", field.getFieldCode());
System.out.println("Today's date, in {format.DateTimeFormat} format:\n\t{field.Result}");
// 3 - General format:
field = builder.insertField("= 25 + 33");
format = field.getFormat();
format.getGeneralFormats().add(GeneralFormat.LOWERCASE_ROMAN);
format.getGeneralFormats().add(GeneralFormat.UPPER);
field.update();
int index = 0;
Iterator<Integer> generalFormatEnumerator = format.getGeneralFormats().iterator();
while (generalFormatEnumerator.hasNext()) {
int value = generalFormatEnumerator.next();
System.out.println(MessageFormat.format("General format index {0}: {1}", index++, value));
}
Assert.assertEquals("= 25 + 33 \\* roman \\* Upper", field.getFieldCode());
Assert.assertEquals("LVIII", field.getResult());
Assert.assertEquals(2, format.getGeneralFormats().getCount());
Assert.assertEquals(GeneralFormat.LOWERCASE_ROMAN, format.getGeneralFormats().get(0));
// We can remove our formats to revert the field's result to its original form.
format.getGeneralFormats().remove(GeneralFormat.LOWERCASE_ROMAN);
format.getGeneralFormats().removeAt(0);
Assert.assertEquals(0, format.getGeneralFormats().getCount());
field.update();
Assert.assertEquals("= 25 + 33 ", field.getFieldCode());
Assert.assertEquals("58", field.getResult());
Assert.assertEquals(0, format.getGeneralFormats().getCount());
| Modifier and Type | Field and Description |
|---|---|
static int |
AIUEO
Numeric formatting.
|
static int |
ARABIC
Numeric formatting.
|
static int |
ARABIC_ABJAD
Numeric formatting.
|
static int |
ARABIC_ALPHA
Numeric formatting.
|
static int |
ARABIC_DASH
Numeric formatting.
|
static int |
BAHT_TEXT
Numeric formatting.
|
static int |
CAPS
Text formatting.
|
static int |
CARD_TEXT
Numeric formatting.
|
static int |
CHAR_FORMAT
Field result formatting.
|
static int |
CHINESE_NUM_1
Numeric formatting.
|
static int |
CHINESE_NUM_2
Numeric formatting.
|
static int |
CHINESE_NUM_3
Numeric formatting.
|
static int |
CHOSUNG
Numeric formatting.
|
static int |
CIRCLE_NUM
Numeric formatting.
|
static int |
DB_CHAR |
static int |
DB_NUM_1 |
static int |
DB_NUM_2 |
static int |
DB_NUM_3 |
static int |
DB_NUM_4 |
static int |
DOLLAR_TEXT
Numeric formatting.
|
static int |
FIRST_CAP
Text formatting.
|
static int |
GANADA
Numeric formatting.
|
static int |
GB_1
Numeric formatting.
|
static int |
GB_2
Numeric formatting.
|
static int |
GB_3
Numeric formatting.
|
static int |
GB_4
Numeric formatting.
|
static int |
HEBREW_1
Numeric formatting.
|
static int |
HEBREW_2
Numeric formatting.
|
static int |
HEX
Numeric formatting.
|
static int |
HINDI_ARABIC
Numeric formatting.
|
static int |
HINDI_CARD_TEXT
Numeric formatting.
|
static int |
HINDI_LETTER_1
Numeric formatting.
|
static int |
HINDI_LETTER_2
Numeric formatting.
|
static int |
IROHA
Numeric formatting.
|
static int |
KANJI_NUM_1
Numeric formatting.
|
static int |
KANJI_NUM_2
Numeric formatting.
|
static int |
KANJI_NUM_3
Numeric formatting.
|
static int |
length |
static int |
LOWER
Text formatting.
|
static int |
LOWERCASE_ALPHABETIC
Numeric formatting.
|
static int |
LOWERCASE_ROMAN
Numeric formatting.
|
static int |
MERGE_FORMAT
Field result formatting.
|
static int |
MERGE_FORMAT_INET
Field result formatting.
|
static int |
NONE
Used to specify a missing general format.
|
static int |
ORD_TEXT
Numeric formatting.
|
static int |
ORDINAL
Numeric formatting.
|
static int |
SB_CHAR |
static int |
THAI_ARABIC
Numeric formatting.
|
static int |
THAI_CARD_TEXT
Numeric formatting.
|
static int |
THAI_LETTER
Numeric formatting.
|
static int |
UPPER
Text formatting.
|
static int |
UPPERCASE_ALPHABETIC
Numeric formatting.
|
static int |
UPPERCASE_ROMAN
Numeric formatting.
|
static int |
VIET_CARD_TEXT
Numeric formatting.
|
static int |
ZODIAC_1
Numeric formatting.
|
static int |
ZODIAC_2
Numeric formatting.
|
static int |
ZODIAC_3
Numeric formatting.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
fromName(java.lang.String generalFormatName) |
static java.lang.String |
getName(int generalFormat) |
static int[] |
getValues() |
static java.lang.String |
toString(int generalFormat) |
public static int NONE
public static int AIUEO
public static int UPPERCASE_ALPHABETIC
public static int LOWERCASE_ALPHABETIC
public static int ARABIC
public static int ARABIC_ABJAD
public static int ARABIC_ALPHA
public static int ARABIC_DASH
public static int BAHT_TEXT
public static int CARD_TEXT
public static int CHINESE_NUM_1
public static int CHINESE_NUM_2
public static int CHINESE_NUM_3
public static int CHOSUNG
public static int CIRCLE_NUM
public static int DB_CHAR
public static int DB_NUM_1
public static int DB_NUM_2
public static int DB_NUM_3
public static int DB_NUM_4
public static int DOLLAR_TEXT
public static int GANADA
public static int GB_1
public static int GB_2
public static int GB_3
public static int GB_4
public static int HEBREW_1
public static int HEBREW_2
public static int HEX
public static int HINDI_ARABIC
public static int HINDI_CARD_TEXT
public static int HINDI_LETTER_1
public static int HINDI_LETTER_2
public static int IROHA
public static int KANJI_NUM_1
public static int KANJI_NUM_2
public static int KANJI_NUM_3
public static int ORDINAL
public static int ORD_TEXT
public static int UPPERCASE_ROMAN
public static int LOWERCASE_ROMAN
public static int SB_CHAR
public static int THAI_ARABIC
public static int THAI_CARD_TEXT
public static int THAI_LETTER
public static int VIET_CARD_TEXT
public static int ZODIAC_1
public static int ZODIAC_2
public static int ZODIAC_3
public static int CAPS
public static int FIRST_CAP
public static int LOWER
public static int UPPER
public static int CHAR_FORMAT
public static int MERGE_FORMAT
public static int MERGE_FORMAT_INET
public static int length