39 |
package javax.swing.text; |
package javax.swing.text; |
40 |
|
|
41 |
import java.io.Serializable; |
import java.io.Serializable; |
42 |
|
import java.util.ArrayList; |
43 |
import java.util.Collections; |
import java.util.Collections; |
|
import java.util.LinkedList; |
|
44 |
import java.util.ListIterator; |
import java.util.ListIterator; |
45 |
|
|
46 |
import javax.swing.undo.UndoableEdit; |
import javax.swing.undo.UndoableEdit; |
59 |
public class GapContent |
public class GapContent |
60 |
implements AbstractDocument.Content, Serializable |
implements AbstractDocument.Content, Serializable |
61 |
{ |
{ |
|
|
|
62 |
/** |
/** |
63 |
* A {@link Position} implementation for <code>GapContent</code>. |
* A {@link Position} implementation for <code>GapContent</code>. |
64 |
*/ |
*/ |
113 |
*/ |
*/ |
114 |
public int getOffset() |
public int getOffset() |
115 |
{ |
{ |
116 |
if (mark <= gapEnd) |
// Check precondition. |
117 |
|
assert(mark <= gapStart || mark > gapEnd); |
118 |
|
|
119 |
|
if (mark <= gapStart) |
120 |
return mark; |
return mark; |
121 |
else |
else |
122 |
return mark - (gapEnd - gapStart); |
return mark - (gapEnd - gapStart); |
123 |
} |
} |
124 |
} |
} |
125 |
|
|
126 |
private static final long serialVersionUID = 8374645204155842629L; |
/** The serialization UID (compatible with JDK1.5). */ |
127 |
|
private static final long serialVersionUID = -6226052713477823730L; |
128 |
|
|
129 |
/** |
/** |
130 |
* This is the default buffer size and the amount of bytes that a buffer is |
* This is the default buffer size and the amount of bytes that a buffer is |
151 |
* The positions generated by this GapContent. They are kept in an ordered |
* The positions generated by this GapContent. They are kept in an ordered |
152 |
* fashion, so they can be looked up easily. |
* fashion, so they can be looked up easily. |
153 |
*/ |
*/ |
154 |
LinkedList positions; |
ArrayList positions; |
155 |
|
|
156 |
/** |
/** |
157 |
* Creates a new GapContent object. |
* Creates a new GapContent object. |
172 |
gapStart = 0; |
gapStart = 0; |
173 |
gapEnd = size - 1; |
gapEnd = size - 1; |
174 |
buffer[size - 1] = '\n'; |
buffer[size - 1] = '\n'; |
175 |
positions = new LinkedList(); |
positions = new ArrayList(); |
176 |
} |
} |
177 |
|
|
178 |
/** |
/** |
418 |
*/ |
*/ |
419 |
protected void shiftGap(int newGapStart) |
protected void shiftGap(int newGapStart) |
420 |
{ |
{ |
421 |
|
if (newGapStart == gapStart) |
422 |
|
return; |
423 |
|
|
424 |
int newGapEnd = newGapStart + (gapEnd - gapStart); |
int newGapEnd = newGapStart + (gapEnd - gapStart); |
425 |
|
|
426 |
// Update the positions between newGapEnd and (old) gapEnd. The marks |
// Update the positions between newGapEnd and (old) gapEnd. The marks |
443 |
} |
} |
444 |
} |
} |
445 |
|
|
446 |
if (newGapStart == gapStart) |
if (newGapStart < gapStart) |
|
return; |
|
|
else if (newGapStart < gapStart) |
|
447 |
{ |
{ |
448 |
System.arraycopy(buffer, newGapStart, buffer, newGapEnd, gapStart |
System.arraycopy(buffer, newGapStart, buffer, newGapEnd, gapStart |
449 |
- newGapStart); |
- newGapStart); |