Java Reference
In-Depth Information
1
S wing is good.
2
34
5
6
8
9
0
7
10 11 12 13
P
P
P
1
Figure 18.1 A text of 14 symbols. The numbering of the symbols begins with 0 and is shown
above the text. Three positions markers, P 1 , P 2 and P 3 ,are shown. P 1 has offset 0 as there
is no symbol between it and the start of the text, P 2 has offset 6 because it is immediately
before the 6th symbol and P 3 has offset 9
the first symbol has offset 1, etc. In the next section we use position markers
to specify the beginning and end of text parts that receive specific formatting.
Figure 18.1 illustrates the concept of position markers.
Let us now see what happens to position markers when the text is changed.
We begin by inserting a single symbol, an m say, between the symbols 5 and 6 of
the text in Figure 18.1. Then all symbols of the original text beginning with the
one numbered 6 are moved one place to the right and the new symbol is inserted
at place 6. Position marker P 3 is moved with the text; its offset is increased from
9to10. The new letter is inserted precisely at the position occupied by marker
P 2 . The convention is that the insertion happens before the marker. Hence the
offset of P 2 is increased to 7. The result is shown in Figure 18.2.
Let us now see what happens to position markers when text is deleted. Let us
first assume that the deleted text does not contain a position marker. In the original
text of Figure 18.1 let us delete the symbols 2 to 5 ( ing_ ). All position markers
to the right of the deleted text will move left, i.e. their offsets are decreased. The
result is shown in Figure 18.3.
Let us now delete the symbols 4 to 10 ( g_is_go )inFigure 18.1, including both
spaces. This range includes position markers P 2 and P 3 . Though the symbols are
deleted, the two markers are not. They are now at the position formerly occupied
by the deleted text. Figure 18.4 shows the result.
1
Swing mis good.
0
2
34
5
6
7
8
9
10 11 12 13
P
P
P
1
Figure 18.2 Inserting letter m at position 6 moves P 2 and P 3 to the right
1
Swis good.
0
2
3
4
5
6
7
8
9
P
P
P
1
Figure 18.3 The result of deleting symbols ing_ in Figure 18.1. P 2 and P 3 move left to
offsets 2 and 5
Search WWH ::




Custom Search