0.1.0-SNAPSHOT Arrow_down_16x16



  • (add-str-ref-doc-listener doc-owner str-ref)

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clj_swing/document.clj:98 top

(defn add-str-ref-doc-listener [doc-owner str-ref]
  (let [doc (.getDocument doc-owner)
	watch-key (gensym "str-ref-doc-listener-watch")
	watch-fn (fn [l]
		   (fn [a b c state]
		      (.removeDocumentListener doc l)
		      (.remove doc 0 (.getLength doc))
		      (.insertString doc 0 state nil)
		      (.addDocumentListener doc l))))
	l (proxy [DocumentListener] []
	    (insertUpdate [event]
			  (let [offset (.getOffset event)]
			     (remove-watch str-ref watch-key)
			     (dosync (alter str-ref str-insert offset (.getText doc offset (.getLength event))))
			     (add-watch str-ref watch-key (watch-fn this))))
	    (removeUpdate [event]
			   (remove-watch  str-ref watch-key)
			   (dosync (alter str-ref str-remove (.getOffset event) (.getLength event)))
			   (add-watch str-ref watch-key (watch-fn this)))
	    (changedUpdate [event]))]
    (if (< 0 (.getLength doc))
      (.remove doc 0 (.getOffset (.getEndPosition doc))))
    (prn str-ref)
    (.insertString doc 0 @str-ref nil)
    (.addDocumentListener doc l)
    (add-watch str-ref watch-key (watch-fn l))))
Vars in clj-swing.document/add-str-ref-doc-listener: < add-watch defn doc let prn deref
Used in 0 other vars

Comments top

No comments for add-str-ref-doc-listener. Log in to add a comment.