for( int i = 0; i < collDocListeners.size(); i++ ) {
oldDoc.removeDocumentListener( (DocumentListener) collDocListeners.get( i ));
//System.out.println( "remove " + collDocListeners.get( i ));
}
if( oldDoc instanceof AbstractDocument ) {
final AbstractDocument adoc = (AbstractDocument) oldDoc;
final DocumentEvent de =
adoc.new DefaultDocumentEvent( oldDoc.getStartPosition().getOffset(),
oldDoc.getLength(),
DocumentEvent.EventType.REMOVE );
// simulate clear
for( int i = 0; i < collDocListeners.size(); i++ ) {
final DocumentListener l = (DocumentListener) collDocListeners.get( i );
l.removeUpdate( de );
}
}
}
// re-register new
final Document newDoc = (Document) pce.getNewValue();
if( newDoc != null ) {
newDoc.addUndoableEditListener( TextView.this );
for( int i = 0; i < collDocListeners.size(); i++ ) {
newDoc.addDocumentListener( (DocumentListener) collDocListeners.get( i ));
//System.out.println( "add " + collDocListeners.get( i ));
}
if( newDoc instanceof AbstractDocument ) {
final AbstractDocument adoc = (AbstractDocument) newDoc;
final DocumentEvent de =
adoc.new DefaultDocumentEvent( newDoc.getStartPosition().getOffset(),
newDoc.getLength(),
DocumentEvent.EventType.INSERT );
// simulate clear