Text clients instantiate this class with an MConstText object and a format width. Text can be formatted such that all lines fit within the format length. Alternatively, text can be formatted such that lines end only at the end of paragraphs.
The format length is specified with the setLineBound() method.
Methods in the formatter which interact with the graphics system generally take as a paramter a Point object which represents the "origin" of the text display. The origin represents the location, in the graphics system used to display the text, of the top-left corner of the text.
To display the text, call draw(), passing the a rectangle in which to draw as a parameter. Only lines of text in the draw rectangle will be drawn.
When the formatter's text changes, it is important to first call stopBackgroundFormatting() to prevent the Formatter from accessing the text from a background thread. After modifications are complete, call the updateFormat() method before invoking any other methods of the formatter. updateFormat() reformats the new text, formatting no more text than is necessary.
The formatter provides services for responding to user input from the mouse and keyboard. The method pointToTextOffset() converts a screen location to an offset in the text. The method textOffsetToPoint converts an offset in the text to an array of two Point objects, which can be used to draw a verticle caret, denoting an insertion point. highlightArea accepts two offsets into the text as paramters, and returns an array of Polygon objects representing areas where visual highlighting should be applied.
Finally, for keyboard handling, the findNewInsertionOffset() method accepts an "initial" offset, a "previous" offset, as well as a direction, and returns a new offset. The direction can be up, down, left, or right. The previous offset is the insertion point location, before the arrow key is processed. The initial offset is the offset where an up or down arrow key sequence began. Using the initial offset allows for "intelligent" handling of up and down arrow keys.
Examples of using the MFormatter class are given in the AsyncFormatter class documentation.
@author John Raley @see com.ibm.richtext.styledtext.MText
|
|