下面列出了javax.swing.event.DocumentListener#removeUpdate() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** Gives notification that a portion of the document has been removed.
* @param ev event describing the action
*/
@Override public void removeUpdate(DocumentEvent ev) {
final DocumentListener l = docGet(ev);
if (l != null) {
l.removeUpdate(ev);
}
}
void firePreRemoveUpdate(DefaultDocumentEvent chng) {
// Notify the remove update listeners - before the actual remove happens
// so that it adheres to removeUpdate() logic; also the listeners can check
// positions' offsets before the actual removal happens.
for (DocumentListener listener: updateDocumentListenerList.getListeners()) {
listener.removeUpdate(chng);
}
}
@Override
public void removeUpdate(DocumentEvent e) {
DocumentListener l = getDelegate();
if (l != null) {
l.removeUpdate(e);
}
}
/**
* Implementation of DocumentListener's method fires all the added
* listeners according to their priority.
*/
public void removeUpdate(DocumentEvent evt) {
logEvent(evt, "removeUpdate");
// Fire the prioritized listeners
EventListener[][] listenersArray = getListenersArray();
// Attempt to fire to all listeners catching possible exception(s) and report first fired then
RuntimeException runtimeException = null;
for (int priority = listenersArray.length - 1; priority >= 0; priority--) {
logPriority(priority);
EventListener[] listeners = listenersArray[priority];
for (int i = listeners.length - 1; i >= 0; i--) {
DocumentListener l = (DocumentListener) listeners[i];
logListener(l);
try {
l.removeUpdate(evt);
} catch (RuntimeException ex) {
if (runtimeException == null) { // Only record first thrown
runtimeException = ex;
}
}
}
}
if (runtimeException != null) {
throw runtimeException; // Re-throw remembered exception
}
logEventEnd("removeUpdate");
}
protected void fireRemoveEvent( final DocumentEvent event ) {
final DocumentListener[] listeners = listenerList.getListeners( DocumentListener.class );
for ( int i = 0; i < listeners.length; i++ ) {
final DocumentListener documentListener = listeners[ i ];
documentListener.removeUpdate( event );
}
}
void handleRemove(int offset, int length) throws BadLocationException {
if (length == 0) {
return;
}
if (length < 0) {
throw new IllegalArgumentException("len=" + length + " < 0"); // NOI18N
}
if (offset < 0) {
throw new BadLocationException("Wrong remove position " + offset + " < 0", offset); // NOI18N
}
if (offset + length > getLength()) {
throw new BadLocationException("Wrong (offset+length)=" + (offset+length) +
" > getLength()=" + getLength(), offset + length); // NOI18N
}
incrementDocVersion();
int docLen = getLength();
if (offset < 0 || offset > docLen) {
throw new BadLocationException("Wrong remove position " + offset, offset); // NOI18N
}
if (offset + length > docLen) {
throw new BadLocationException("End offset of removed text " // NOI18N
+ (offset + length) + " > getLength()=" + docLen, // NOI18N
offset + length); // NOI18N
}
preRemoveCheck(offset, length);
BaseDocumentEvent evt = getDocumentEvent(offset, length, DocumentEvent.EventType.REMOVE, null);
// Store modification text as an event's property
org.netbeans.lib.editor.util.swing.DocumentUtilities.addEventPropertyStorage(evt);
String removedText = getText(offset, length);
org.netbeans.lib.editor.util.swing.DocumentUtilities.putEventProperty(evt, String.class, removedText);
if (postModificationDepth > 0) {
DocumentPostModificationUtils.markPostModification(evt);
}
removeUpdate(evt);
UndoableEdit edit = ((EditorDocumentContent) getContent()).remove(offset, removedText);
if (edit != null) {
evt.addEdit(edit);
lastModifyUndoEdit = edit; // #8692 check last modify undo edit
}
if (LOG.isLoggable(Level.FINE)) {
StringBuilder sb = new StringBuilder(200);
sb.append("remove(): doc="); // NOI18N
appendInfoTerse(sb);
sb.append(",origDocLen=").append(docLen); // NOI18N
sb.append(", offset=").append(Utilities.offsetToLineColumnString(this, offset)); // NOI18N
sb.append(",len=").append(length); // NOI18N
if (!debugNoText) {
sb.append(" \"");
appendContext(sb, offset);
sb.append("\" - \""); // NOI18N
CharSequenceUtilities.debugText(sb, ((ContentEdit) edit).getText());
sb.append("\""); // NOI18N
}
if (debugStack) {
LOG.log(Level.FINE, sb.toString(), new Throwable("Remove text")); // NOI18N
} else {
LOG.log(Level.FINE, sb.toString());
}
}
if (atomicDepth > 0) { // add edits as soon as possible
ensureAtomicEditsInited();
atomicEdits.addEdit(evt); // will be added
}
postRemoveUpdate(evt);
evt.end();
fireRemoveUpdate(evt);
postModificationDepth++;
try {
if (postModificationDocumentListener != null) {
postModificationDocumentListener.removeUpdate(evt);
}
if (postModificationDocumentListenerList.getListenerCount() > 0) {
for (DocumentListener listener : postModificationDocumentListenerList.getListeners()) {
listener.removeUpdate(evt);
}
}
} finally {
postModificationDepth--;
}
if (atomicDepth == 0 && !composedText) {
fireUndoableEditUpdate(new UndoableEditEvent(this, evt));
}
}