Replacements that are used to update an
org.fxmisc.richtext.model.EditableStyledDocument in one call via commit().Note
this builder cannot be reused and a new one must be created for each multi-change.
Let's say that a document has the text |(|t|e|x|t||)| where each | represents a position
in-between the characters of the text . If one wants to remove the opening
and closing parenthesis in two update calls, they would write:
// Text: |(|t|e|x|t|)|
// Position: 0 1 2 3 4 5 6
area.deleteText(0, 1); // delete the first parenthesis
// now the second parenthesis is positioned in a different spot than before
// Text: |t|e|x|t|)|
// Position: 0 1 2 3 4 5
area.deleteText(4, 5); // delete the second parenthesis
MultiChangeBuilder can do the same thing in one call and works by applying earlier changes before
later ones. However, this creates a problem. Later changes' start and end positions must be updated to still
point to the correct spot in the text. Wouldn't it be easier to be able to define both changes in the original
coordinate system of the document before any changes were applied? Returning to the previous example,
wouldn't it be better if one could write:
// Text: |(|t|e|x|t|)|
// Position: 0 1 2 3 4 5 6
// start multi change
area.deleteText(0, 1); // delete the 1st parenthesis
area.deleteText(5, 6); // delete the 2nd parenthesis
// end multi change
Fortunately, that is already handled for you. Such changes are known as "relative" changes: their start and end positions are updated to point to where they should point once all the earlier changes before them have been applied. To execute the same code as before, we would write:
area.createMultiChange()
// deletes the 1st parenthesis
.deleteText(0, 1)
// internally updates this to delete(4, 5), so that it deletes the 2nd parenthesis
.deleteText(5, 6)
// executes the call and updates the document
.commit();
However, a developer may sometimes want an "absolute" change: their start and end positions are exactly what the developer specifies regardless of how changes before them modify the underlying document. For example, the following code would still delete both parenthesis:
area.createMultiChange()
.deleteText(0, 1) // deletes the 1st parenthesis
.deleteTextAbsolutely(4, 5) // deletes the 2nd parenthesis
.commit();
Thus, absolute changes (e.g. replaceAbsolutely(int, int, StyledDocument)) are all the methods
which have "absolute" as a suffix and relative changes (e.g. replace(int, int, StyledDocument))
do not. To make things easier for the developer, the methods declared here are similar to those declared
in EditActions, minus a few (e.g. EditActions#append(StyledDocument)).
GenericStyledArea#replace(int, int, StyledDocument) call.
// This code...
area.createMultiChange(4)
.replaceText(0, 1, "a")
.replaceTextAbsolutely(0, 1, "b")
.replaceTextAbsolutely(0, 1, "c")
.replaceTextAbsolutely(0, 1, "d")
.commit();
// ...could be optimized to...
area.createMultiChange(2)
.replaceText(0, 1, "a")
// .replaceTextAbsolutely(0, 1, "b") // superseded by next change
// .replaceTextAbsolutely(0, 1, "c") // superseded by next change
.replaceTextAbsolutely(0, 1, "d")
.commit();
// ...as it would reduce the number of updates by two and not create all the other objects
// associated with an update (e.g. RichTextChange, PlainTextChange, etc.).
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private final GenericStyledArea | |
| private final List |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| private MultiChangeBuilder | |
| public final void | |
| public MultiChangeBuilder | deleteText(IndexRange
The range of text to delete. It must not be null. Its start and end values specify the start
and end positions within the area. range)Removes a range of text. |
| public MultiChangeBuilder | deleteText(int
Start position of the range to remove start, int End position of the range to remove end)Removes a range of text. |
| public MultiChangeBuilder | deleteText(int startParagraph, int startColumn, int endParagraph, int endColumn)
Removes a range of text. |
| public MultiChangeBuilder | deleteTextAbsolutely(IndexRange
The range of text to delete. It must not be null. Its start and end values specify the start
and end positions within the area. range)Removes a range of text. |
| public MultiChangeBuilder | deleteTextAbsolutely(int
Start position of the range to remove start, int End position of the range to remove end)Removes a range of text. |
| public MultiChangeBuilder | deleteTextAbsolutely(int startParagraph, int startColumn, int endParagraph, int endColumn)
Removes a range of text. |
| private void | |
| private void | |
| public boolean | |
| public MultiChangeBuilder | insert(int
The position to insert the text. position, StyledDocument<PS, SEG, S> The rich-text content to insert. document)Inserts the given rich-text content at the given position. |
| public MultiChangeBuilder | insert(int paragraphIndex, int columnPosition, StyledDocument<PS, SEG, S>
The rich-text content to insert. document)Inserts the given rich-text content at the position returned from
|
| public MultiChangeBuilder | insertAbsolutely(int
The position to insert the text. position, StyledDocument<PS, SEG, S> The rich-text content to insert. document)Inserts the given rich-text content at the given position. |
| public MultiChangeBuilder | insertAbsolutely(int paragraphIndex, int columnPosition, StyledDocument<PS, SEG, S>
The rich-text content to insert. document)Inserts the given rich-text content at the position returned from
|
| public MultiChangeBuilder | insertText(int
The position to insert the text. position, String The text to insert. text)Inserts the given text at the given position. |
| public MultiChangeBuilder | insertText(int paragraphIndex, int columnPosition, String
The text to insert text)Inserts the given text at the position returned from
|
| public MultiChangeBuilder | insertTextAbsolutely(int
The position to insert the text. position, String The text to insert. text)Inserts the given text at the given position. |
| public MultiChangeBuilder | insertTextAbsolutely(int paragraphIndex, int columnPosition, String
The text to insert text)Inserts the given text at the position returned from
|
| private MultiChangeBuilder | |
| public MultiChangeBuilder | replace(int start, int end, StyledDocument<PS, SEG, S> replacement)
Replaces a range of characters with the given rich-text document. |
| public MultiChangeBuilder | replaceAbsolutely(int start, int end, StyledDocument<PS, SEG, S> replacement)
Replaces a range of characters with the given rich-text document. |
| public MultiChangeBuilder | replaceText(int
Start index of the range to replace, inclusive. start, int End index of the range to replace, exclusive. end, String The text to put in place of the deleted range.
It must not be null. text)Replaces a range of characters with the given text. |
| public MultiChangeBuilder | replaceTextAbsolutely(int
Start index of the range to replace, inclusive. start, int End index of the range to replace, exclusive. end, String The text to put in place of the deleted range.
It must not be null. text)Replaces a range of characters with the given text. |
| alreadyCreated | back to summary |
|---|---|
| private boolean alreadyCreated | |
| area | back to summary |
|---|---|
| private final GenericStyledArea<PS, SEG, S> area | |
| list | back to summary |
|---|---|
| private final List<Replacement<PS, SEG, S>> list | |
| MultiChangeBuilder | back to summary |
|---|---|
| pack-priv MultiChangeBuilder(GenericStyledArea<PS, SEG, S> area) | |
| MultiChangeBuilder | back to summary |
|---|---|
| pack-priv MultiChangeBuilder(GenericStyledArea<PS, SEG, S> area, int initialListSize) | |
| MultiChangeBuilder | back to summary |
|---|---|
| private MultiChangeBuilder(GenericStyledArea<PS, SEG, S> area, List<Replacement<PS, SEG, S>> list) | |
| absoluteReplace | back to summary |
|---|---|
| private MultiChangeBuilder | |
| commit | back to summary |
|---|---|
| public final void commit() Applies all the changes stored in this object to the underlying document of the area. Note this builder cannot be reused and a new one must be created for each multi-change. | |
| deleteText | back to summary |
|---|---|
| public MultiChangeBuilder Removes a range of text.
| |
| deleteText | back to summary |
|---|---|
| public MultiChangeBuilder Removes a range of text.
It must hold
| |
| deleteText | back to summary |
|---|---|
| public MultiChangeBuilder Removes a range of text.
It must hold Caution see | |
| deleteTextAbsolutely | back to summary |
|---|---|
| public MultiChangeBuilder Removes a range of text.
| |
| deleteTextAbsolutely | back to summary |
|---|---|
| public MultiChangeBuilder Removes a range of text.
It must hold
| |
| deleteTextAbsolutely | back to summary |
|---|---|
| public MultiChangeBuilder Removes a range of text.
It must hold Caution see | |
| ensureHasChanges | back to summary |
|---|---|
| private void ensureHasChanges() | |
| ensureNotYetCreated | back to summary |
|---|---|
| private void ensureNotYetCreated() | |
| hasChanges | back to summary |
|---|---|
| public boolean hasChanges() | |
| insert | back to summary |
|---|---|
| public MultiChangeBuilder Inserts the given rich-text content at the given position.
| |
| insert | back to summary |
|---|---|
| public MultiChangeBuilder Inserts the given rich-text content at the position returned from
Caution see
| |
| insertAbsolutely | back to summary |
|---|---|
| public MultiChangeBuilder Inserts the given rich-text content at the given position.
| |
| insertAbsolutely | back to summary |
|---|---|
| public MultiChangeBuilder Inserts the given rich-text content at the position returned from
Caution see
| |
| insertText | back to summary |
|---|---|
| public MultiChangeBuilder Inserts the given text at the given position.
| |
| insertText | back to summary |
|---|---|
| public MultiChangeBuilder Inserts the given text at the position returned from
Caution see
| |
| insertTextAbsolutely | back to summary |
|---|---|
| public MultiChangeBuilder Inserts the given text at the given position.
| |
| insertTextAbsolutely | back to summary |
|---|---|
| public MultiChangeBuilder Inserts the given text at the position returned from
Caution see
| |
| relativeReplace | back to summary |
|---|---|
| private MultiChangeBuilder | |
| replace | back to summary |
|---|---|
| public MultiChangeBuilder Replaces a range of characters with the given rich-text document. | |
| replaceAbsolutely | back to summary |
|---|---|
| public MultiChangeBuilder Replaces a range of characters with the given rich-text document. | |
| replaceText | back to summary |
|---|---|
| public MultiChangeBuilder Replaces a range of characters with the given text.
It must hold
| |
| replaceTextAbsolutely | back to summary |
|---|---|
| public MultiChangeBuilder Replaces a range of characters with the given text.
It must hold
| |