Index: BaseDocument.java =================================================================== RCS file: /cvs/editor/libsrc/org/netbeans/editor/BaseDocument.java,v retrieving revision 1.123 diff -u -r1.123 BaseDocument.java --- BaseDocument.java 25 Apr 2005 15:29:39 -0000 1.123 +++ BaseDocument.java 5 Aug 2005 11:00:44 -0000 @@ -36,9 +36,10 @@ import javax.swing.text.AttributeSet; import javax.swing.text.AbstractDocument; import javax.swing.text.StyleConstants; -import javax.swing.event.EventListenerList; import javax.swing.event.DocumentEvent; import javax.swing.event.UndoableEditEvent; +import javax.swing.text.Document; +import javax.swing.text.DocumentFilter; import javax.swing.text.Segment; import javax.swing.undo.AbstractUndoableEdit; import javax.swing.undo.UndoableEdit; @@ -564,12 +565,30 @@ // possible CR-LF conversion text = Analyzer.convertLSToLF(text); + DocumentFilter filter = getDocumentFilter(); // Perform the insert boolean notifyMod = notifyModifyCheckStart(offset, "insertString() vetoed"); // NOI18N boolean modFinished = false; // Whether modification succeeded extWriteLock(); try { - + if (filter != null) { + filter.insertString(getFilterBypass(), offset, text, a); + } + else { + handleInsertString(offset, text, a); + } + modFinished = true; + } finally { + extWriteUnlock(); + // Notify no mod done if notified mod but mod did not succeeded + if (notifyMod) { + notifyModifyCheckEnd(modFinished); + } + } + } + + void handleInsertString(int offset, String text, AttributeSet a) + throws BadLocationException { preInsertCheck(offset, text, a); // Do the real insert into the content @@ -622,14 +641,6 @@ if (atomicDepth == 0 && !isComposedText) { // !!! check fireUndoableEditUpdate(new UndoableEditEvent(this, evt)); } - modFinished = true; - } finally { - extWriteUnlock(); - // Notify no mod done if notified mod but mod did not succeeded - if (notifyMod) { - notifyModifyCheckEnd(modFinished); - } - } } /** Removes portion of a document */ @@ -638,10 +649,29 @@ if (offset < 0) { throw new BadLocationException("Wrong remove position " + offset, offset); // NOI18N } + DocumentFilter filter = getDocumentFilter(); boolean notifyMod = notifyModifyCheckStart(offset, "remove() vetoed"); // NOI18N boolean modFinished = false; // Whether modification succeeded extWriteLock(); try { + if (filter != null) { + filter.remove(getFilterBypass(), offset, len); + } + else { + handleRemove(offset, len); + } + modFinished = true; + } finally { + extWriteUnlock(); + // Notify no mod done if notified mod but mod did not succeeded + if (notifyMod) { + notifyModifyCheckEnd(modFinished); + } + } + } + } + + void handleRemove(int offset, int len) throws BadLocationException { int docLen = getLength(); if (offset < 0 || offset > docLen) { throw new BadLocationException("Wrong remove position " + offset, offset); // NOI18N @@ -694,17 +724,8 @@ fireUndoableEditUpdate(new UndoableEditEvent(this, evt)); } - modFinished = true; - } finally { - extWriteUnlock(); - // Notify no mod done if notified mod but mod did not succeeded - if (notifyMod) { - notifyModifyCheckEnd(modFinished); - } - } - } } - + /** * Check notify modify status and initialize it if necessary * before the actual modification is going to be done. @@ -1742,4 +1763,39 @@ return beforeModificationListener; } } + + // DocumentFilter stuff + + private transient DocumentFilter.FilterBypass filterBypass; + + private DocumentFilter.FilterBypass getFilterBypass() { + if (filterBypass == null) { + filterBypass = new DefaultFilterBypass(); + } + return filterBypass; + } + + private class DefaultFilterBypass extends DocumentFilter.FilterBypass { + public Document getDocument() { + return BaseDocument.this; + } + + public void remove(int offset, int length) throws + BadLocationException { + handleRemove(offset, length); + } + + public void insertString(int offset, String string, + AttributeSet attr) throws + BadLocationException { + handleInsertString(offset, string, attr); + } + + public void replace(int offset, int length, String text, + AttributeSet attrs) throws BadLocationException { + handleRemove(offset, length); + handleInsertString(offset, text, attrs); + } + } + }