Alex Grönholm avatar Alex Grönholm committed ee1f828

Added DocumentListener wrapper

Comments (0)

Files changed (2)

 v1.0b3
 ======
 
+* ADDED: DocumentListener shortcuts in swingutils.events
 * CHANGED: @inlineCallbacks now always returns an AsyncToken for consistency
 * CHANGED: @inlineCallbacks now uses @swingRun instead of @swingCall to avoid
   certain undesirable side effects (the calling thread would get stuck waiting

swingutils/events.py

                             *args, **kwargs)
 
 
-def addListSelectionListener(target, listener, *args, **kwargs):
+def addDocumentListener(target, listener, *args, **kwargs):
     """
-    Shortcut for addEventListener(target, ListSelectionListener,
-    'valueChanged', listener).
-
+    Shortcut for adding event listeners for all document events (insert,
+    remove, update). The unlisten() method in the return value will unlisten
+    all three listeners.
     """
-    from javax.swing.event import ListSelectionListener
-    return addEventListener(target, ListSelectionListener, 'valueChanged',
-                            listener, *args, **kwargs)
-
-
-def addRowSorterListener(target, listener, *args, **kwargs):
-    """
-    Shortcut for addEventListener(target, addTreeSelectionListener,
-    'sorterChanged', listener).
-
-    """
-    from javax.swing.event import RowSorterListener
-    return addEventListener(target, RowSorterListener, 'sorterChanged',
-                            listener, *args, **kwargs)
-
-
-def addTableModelListener(target, listener, *args, **kwargs):
-    """
-    Shortcut for addEventListener(target, TableModelListener,
-    'tableChanged', listener).
-
-    """
-    from javax.swing.event import TableModelListener
-    return addEventListener(target, TableModelListener, 'tableChanged',
-                            listener, *args, **kwargs)
+    from javax.swing.event import DocumentListener
+    listener1 = addEventListener(target, DocumentListener, 'insertUpdate',
+                                 listener, *args, **kwargs)
+    listener2 = addEventListener(target, DocumentListener, 'removeUpdate',
+                                 listener, *args, **kwargs)
+    listener3 = addEventListener(target, DocumentListener, 'changedUpdate',
+                                 listener, *args, **kwargs)
+    return MultiListenerWrapper(listener1, listener2, listener3)
 
 
 def addListDataListener(target, listener, *args, **kwargs):
     return MultiListenerWrapper(listener1, listener2, listener3)
 
 
+def addListSelectionListener(target, listener, *args, **kwargs):
+    """
+    Shortcut for addEventListener(target, ListSelectionListener,
+    'valueChanged', listener).
+
+    """
+    from javax.swing.event import ListSelectionListener
+    return addEventListener(target, ListSelectionListener, 'valueChanged',
+                            listener, *args, **kwargs)
+
+
+def addRowSorterListener(target, listener, *args, **kwargs):
+    """
+    Shortcut for addEventListener(target, addTreeSelectionListener,
+    'sorterChanged', listener).
+
+    """
+    from javax.swing.event import RowSorterListener
+    return addEventListener(target, RowSorterListener, 'sorterChanged',
+                            listener, *args, **kwargs)
+
+
+def addTableModelListener(target, listener, *args, **kwargs):
+    """
+    Shortcut for addEventListener(target, TableModelListener,
+    'tableChanged', listener).
+
+    """
+    from javax.swing.event import TableModelListener
+    return addEventListener(target, TableModelListener, 'tableChanged',
+                            listener, *args, **kwargs)
+
+
 def addTreeSelectionListener(target, listener, *args, **kwargs):
     """
     Shortcut for addEventListener(target, TreeSelectionListener,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.