|
19 | 19 | * Let's say that a document has the text {@code |(|t|e|x|t||)|} where each {@code |} represents a position |
20 | 20 | * in-between the characters of the text . If one wants to remove the opening |
21 | 21 | * and closing parenthesis in two update calls, they would write: |
| 22 | + * </p> |
22 | 23 | * <pre><code> |
23 | 24 | * // Text: |(|t|e|x|t|)| |
24 | 25 | * // Position: 0 1 2 3 4 5 6 |
|
29 | 30 | * // Position: 0 1 2 3 4 5 |
30 | 31 | * area.deleteText(4, 5); // delete the second parenthesis |
31 | 32 | * </code></pre> |
32 | | - * </p> |
33 | 33 | * <p> |
34 | 34 | * {@code MultiChangeBuilder} can do the same thing in one call and works by applying earlier changes before |
35 | 35 | * later ones. However, this creates a problem. Later changes' start and end positions must be updated to still |
36 | 36 | * point to the correct spot in the text. Wouldn't it be easier to be able to define both changes in the original |
37 | 37 | * coordinate system of the document before any changes were applied? Returning to the previous example, |
38 | 38 | * wouldn't it be better if one could write: |
39 | | - * <pre><code> |
| 39 | + * </p> |
| 40 | + * <pre><code> |
40 | 41 | * // Text: |(|t|e|x|t|)| |
41 | 42 | * // Position: 0 1 2 3 4 5 6 |
42 | 43 | * |
|
45 | 46 | * area.deleteText(5, 6); // delete the 2nd parenthesis |
46 | 47 | * // end multi change |
47 | 48 | * </code></pre> |
48 | | - * </p> |
49 | 49 | * <p> |
50 | 50 | * Fortunately, that is already handled for you. Such changes are known as "relative" changes: their |
51 | 51 | * start and end positions are updated to point to where they should point once all the earlier changes before |
52 | 52 | * them have been applied. To execute the same code as before, we would write: |
| 53 | + * </p> |
53 | 54 | * <pre><code> |
54 | 55 | * area.createMultiChange() |
55 | 56 | * // deletes the 1st parenthesis |
|
61 | 62 | * // executes the call and updates the document |
62 | 63 | * .commit(); |
63 | 64 | * </code></pre> |
64 | | - * </p> |
65 | 65 | * <p> |
66 | 66 | * However, a developer may sometimes want an "absolute" change: their start and end positions |
67 | 67 | * are exactly what the developer specifies regardless of how changes before them modify the underlying document. |
68 | 68 | * For example, the following code would still delete both parenthesis: |
| 69 | + * </p> |
69 | 70 | * <pre><code> |
70 | 71 | * area.createMultiChange() |
71 | 72 | * .deleteText(0, 1) // deletes the 1st parenthesis |
72 | 73 | * .deleteTextAbsolutely(4, 5) // deletes the 2nd parenthesis |
73 | 74 | * .commit(); |
74 | 75 | * </code></pre> |
75 | | - * </p> |
76 | 76 | * <p> |
77 | 77 | * Thus, absolute changes (e.g. {@link #replaceAbsolutely(int, int, StyledDocument)}) are all the methods |
78 | 78 | * which have "absolute" as a suffix and relative changes (e.g. {@link #replace(int, int, StyledDocument)}) |
|
0 commit comments