Navigating in rich text items in Java™ classes
Use Document.getFirstItem or Document.getItems to access an item as a rich text item. Cast the return value to RichTextItem.
For navigation, a rich text item is a collection of elements of various types accessible through RichTextNavigator. You can find (navigate to) all types of elements. You can get some types of elements as objects; others you cannot get but must access through RichTextRange. The element types are:
- RichTextItem.RTELEM_TYPE_DOCLINK (5) is a doclink, which you can get as a RichTextDocLink object.
- RichTextItem.RTELEM_TYPE_FILEATTACHMENT (8) is a file attachment, which you can get as an EmbeddedObject of type Item.EMBED_ATTACHMENT.
- RichTextItem.RTELEM_TYPE_OLE (9) is an OLE object , which you can get as an EmbeddedObject of type Item.EMBED_OBJECT or Item.EMBED_OBJECTLINK.
- RichTextItem.RTELEM_TYPE_SECTION (6) is a collapsible section, which you can get as a RichTextSection object.
- RichTextItem.RTELEM_TYPE_TABLE (1) is a table, which you can get as a RichTextTable object.
- RichTextItem.RTELEM_TYPE_TABLECELL (7) is table cell, which you must access through RichTextRange.
- RichTextItem.RTELEM_TYPE_TEXTPARAGRAPH (4) is a paragraph of text, which you must access through RichTextRange.
- RichTextItem.RTELEM_TYPE_TEXTRUN (3) is a paragraph or less of text of the same style, which you must access through RichTextRange.
Use RichTextItem.createNavigator or RichTextRange.getNavigator to create a RichTextNavigator object.
Navigation is within elements of the same type. You can find or get the first element of a type, the next element of a type, and the nth element of a type. You cannot find or get an element regardless of type.
The navigator maintains a current position. Both find and get operations change the current position in the rich text item.
RichTextNavigator has the following methods:
- findFirstElement moves the current position to the first element of a specified type in a rich text item.
- findLastElement moves the current position to the last element of a specified type in a rich text item.
- findNextElement moves the current position to the next element of a specified type in a rich text item after the current position.
- findNthElement moves the current position to the element at a specified position within elements of the same type.
- findFirstString moves the current position to the beginning of the first occurrence of a string in a rich text item.
- findNexString moves the current position to the beginning of the next occurrence of a string in a rich text item after the current position.
- getElement returns the element at the current position.
- getFirstElement returns the first element of a specified type in a rich text item.
- getLastElement returns the last element of a specified type in a rich text item.
- getNextElement returns the element of a specified type at a position in a rich text item after the current position.
- getNthElement returns the element of a specified type at a specified position in a rich text item.
- setPosition sets the current position to a specified element in a rich text item.
- setPositionAtEnd sets the current position at the end of a specified element in a rich text item.
- setCharOffset sets the current position to an offset from the current position.
- Clone creates another RichTextNavigator object with the same position as the current one.