116 |
public int getOffset() |
public int getOffset() |
117 |
{ |
{ |
118 |
// Check precondition. |
// Check precondition. |
119 |
assert mark <= gapStart || mark > gapEnd : "mark: " + mark |
assert mark <= gapStart || mark >= gapEnd : "mark: " + mark |
120 |
+ ", gapStart: " + gapStart |
+ ", gapStart: " + gapStart |
121 |
+ ", gapEnd: " + gapEnd; |
+ ", gapEnd: " + gapEnd; |
122 |
|
|
379 |
if (index < 0) |
if (index < 0) |
380 |
index = -(index + 1); |
index = -(index + 1); |
381 |
positions.add(index, pos); |
positions.add(index, pos); |
382 |
|
|
383 |
return pos; |
return pos; |
384 |
} |
} |
385 |
|
|
426 |
return; |
return; |
427 |
|
|
428 |
int newGapEnd = newGapStart + gapEnd - gapStart; |
int newGapEnd = newGapStart + gapEnd - gapStart; |
|
|
|
429 |
if (newGapStart < gapStart) |
if (newGapStart < gapStart) |
430 |
{ |
{ |
431 |
// Update the positions between newGapStart and (old) gapStart. The marks |
// Update the positions between newGapStart and (old) gapStart. The marks |
432 |
// must be shifted by (gapEnd - gapStart). |
// must be shifted by (gapEnd - gapStart). |
433 |
Vector v = getPositionsInRange(null, newGapStart + 1, |
Vector v = getPositionsInRange(null, newGapStart, |
434 |
gapStart - newGapStart + 1); |
gapStart - newGapStart); |
435 |
for (Iterator i = v.iterator(); i.hasNext();) |
for (Iterator i = v.iterator(); i.hasNext();) |
436 |
{ |
{ |
437 |
GapContentPosition p = (GapContentPosition) i.next(); |
GapContentPosition p = (GapContentPosition) i.next(); |
458 |
gapStart = newGapStart; |
gapStart = newGapStart; |
459 |
gapEnd = newGapEnd; |
gapEnd = newGapEnd; |
460 |
} |
} |
461 |
|
if (gapStart == 0) |
462 |
|
resetMarksAtZero(); |
463 |
} |
} |
464 |
|
|
465 |
/** |
/** |
531 |
protected void replace(int position, int rmSize, Object addItems, |
protected void replace(int position, int rmSize, Object addItems, |
532 |
int addSize) |
int addSize) |
533 |
{ |
{ |
534 |
|
if (gapStart != position) |
535 |
|
shiftGap(position); |
536 |
// Remove content |
// Remove content |
537 |
shiftGap(position); |
if (rmSize > 0) |
538 |
shiftGapEndUp(gapEnd + rmSize); |
shiftGapEndUp(gapEnd + rmSize); |
539 |
|
|
540 |
// If gap is too small, enlarge the gap. |
// If gap is too small, enlarge the gap. |
541 |
if ((gapEnd - gapStart) <= addSize) |
if ((gapEnd - gapStart) <= addSize) |
608 |
} |
} |
609 |
return res; |
return res; |
610 |
} |
} |
611 |
|
|
612 |
|
/** |
613 |
|
* Resets all <code>Position</code> that have an offset of <code>0</code>, |
614 |
|
* to also have an array index of <code>0</code>. This might be necessary |
615 |
|
* after a call to <code>shiftGap(0)</code>, since then the marks at offset |
616 |
|
* <code>0</code> get shifted to <code>gapEnd</code>. |
617 |
|
*/ |
618 |
|
protected void resetMarksAtZero() |
619 |
|
{ |
620 |
|
if (gapStart != 0) |
621 |
|
return; |
622 |
|
|
623 |
|
Vector zeroMarks = getPositionsInRange(null, gapEnd, 0); |
624 |
|
for (Iterator i = zeroMarks.iterator(); i.hasNext();) |
625 |
|
{ |
626 |
|
GapContentPosition pos = (GapContentPosition) i.next(); |
627 |
|
pos.mark = 0; |
628 |
|
} |
629 |
|
} |
630 |
} |
} |