edu.northwestern.at.utils.swing
Class CustomDocumentListener

java.lang.Object
  extended by edu.northwestern.at.utils.swing.CustomDocumentListener
All Implemented Interfaces:
java.util.EventListener, javax.swing.event.DocumentListener
Direct Known Subclasses:
Notepad.MyDocumentListener

public class CustomDocumentListener
extends java.lang.Object
implements javax.swing.event.DocumentListener

Listens for changes to document being edited.


Constructor Summary
CustomDocumentListener()
           
 
Method Summary
 void changedUpdate(javax.swing.event.DocumentEvent e)
           
 void insertUpdate(javax.swing.event.DocumentEvent e)
           
protected  boolean isRealChange(javax.swing.event.DocumentEvent e)
          Check if event really does something.
 void removeUpdate(javax.swing.event.DocumentEvent e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CustomDocumentListener

public CustomDocumentListener()
Method Detail

isRealChange

protected boolean isRealChange(javax.swing.event.DocumentEvent e)
Check if event really does something.

Parameters:
e - An event to check.
Returns:
True if event actually did something to the document.

For some reason, the document listener can get events saying something changed, but in fact these events record no real change to the document. To prevent the document from being marked dirty unnecessarily, we check the "toString()" of the event. A bogus event returns "[]" as its toString(), while a real event will have a much lengthier toString() with information about the nature of the change, what was changed, etc.


insertUpdate

public void insertUpdate(javax.swing.event.DocumentEvent e)
Specified by:
insertUpdate in interface javax.swing.event.DocumentListener

removeUpdate

public void removeUpdate(javax.swing.event.DocumentEvent e)
Specified by:
removeUpdate in interface javax.swing.event.DocumentListener

changedUpdate

public void changedUpdate(javax.swing.event.DocumentEvent e)
Specified by:
changedUpdate in interface javax.swing.event.DocumentListener