public static final class TypedBreakInterceptor.MutableContext extends TypedBreakInterceptor.Context
Context
.Modifier and Type | Method and Description |
---|---|
void |
setText(String text,
int breakInsertPosition,
int caretPosition,
int... reindentBlocks)
Sets the insertion text and adjusted caret position.
|
getBreakInsertOffset, getCaretOffset, getComponent, getDocument
public void setText(String text, int breakInsertPosition, int caretPosition, int... reindentBlocks)
There is no restriction on the new text
set by this method, except that it must not be null
and must contain at least
one line break. It can be of any length and can even span multiple lines.
It is important to remember that the values of the position parameters are
relative to the new text. Therefore valid values for the caretPosition
parameter, for example, are <0, text.getLength()>
! The position parameters
are not document offsets.
The following rules have to be obeyed otherwise an IllegalArgumentException
will be thrown:
text
has to contain at least one line break '\n' character.
breakInsertPosition
, if specified, has to point to the most
important line break character in the text
(eg. an interceptor can actually insert
several lines, but one of them is always considered the most significant and its
line break character position is where breakInsertPosition
should point at.
caretPosition
, if specified, has to point somewhere within the text
.
reindentBlocks
, if specified, are pairs of positions within the
text
. In each pair the first number denotes the starting position of a
region that will be reindented. The ending position of that region is denoted by the
second number in the pair. Therfore the first number has to be lower or equal to the
second number.
text
- The new text that will be inserted to a document. It must contain at least
one line break '\n' character.breakInsertPosition
- The position within the text
where the most significant
line break character is. If -1
, the position of the first line break character
in the text
will be used.caretPosition
- The position within the text
where the caret will be placed
after the text is inserted in the document. If -1
, the breakInsertPosition + 1
will be used.reindentBlocks
- The list of position pairs that determine areas within the text
that will be reindented after the text
is inserted in the document. Can be null
or zero length array in which case only the line containing the caretPosition
will
be reindented. If specified, it must contain an even number of elements.IllegalArgumentException
- If the parameters passed in violate the rules specified above.