*/
public void update(DocumentEvent event) {
int deltaLength= (event.getText() == null ? 0 : event.getText().length()) - event.getLength();
Position[] positions= getPositions(event.getDocument());
TypedPosition currentPosition= (TypedPosition) findCurrentPosition(positions, event.getOffset());
// document change outside positions
if (currentPosition == null) {
for (int i= 0; i != positions.length; i++) {
TypedPosition position= (TypedPosition) positions[i];
int offset= position.getOffset();
if (offset >= event.getOffset())
position.setOffset(offset + deltaLength);
}
// document change within a position
} else {
int length= currentPosition.getLength();
for (int i= 0; i != positions.length; i++) {
TypedPosition position= (TypedPosition) positions[i];
int offset= position.getOffset();
if (position.equals(currentPosition)) {
position.setLength(length + deltaLength);
} else if (offset > currentPosition.getOffset()) {
position.setOffset(offset + deltaLength);
}
}
}
}