From 0bb0b5498538126d6ac2fa4ea8def640ef17f67a Mon Sep 17 00:00:00 2001 From: scgilardi Date: Wed, 3 Jun 2009 00:43:38 +0000 Subject: swing-utils: return the newly created listeners, patch from Roland Sadowski --- src/clojure/contrib/swing_utils.clj | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/clojure/contrib/swing_utils.clj b/src/clojure/contrib/swing_utils.clj index 2feadf1d..edcec999 100644 --- a/src/clojure/contrib/swing_utils.clj +++ b/src/clojure/contrib/swing_utils.clj @@ -18,15 +18,20 @@ (defn add-action-listener "Adds an ActionLister to component. When the action fires, f will be - invoked with the event as its first argument followed by args" + invoked with the event as its first argument followed by args. + Returns the listener." [component f & args] - (.addActionListener component (proxy [ActionListener] [] - (actionPerformed [event] (apply f event args))))) + (let [listener (proxy [ActionListener] [] + (actionPerformed [event] (apply f event args)))] + (.addActionListener component listener) + listener)) (defn add-key-typed-listener "Adds a KeyListener to component that only responds to KeyTyped events. When a key is typed, f is invoked with the KeyEvent as its first argument - followed by args" + followed by args. Returns the listener." [component f & args] - (.addKeyListener component (proxy [KeyAdapter] [] - (keyTyped [event] (apply f event args))))) + (let [listener (proxy [KeyAdapter] [] + (keyTyped [event] (apply f event args)))] + (.addKeyListener component listener) + listener)) -- cgit v1.2.3-18-g5258