0.1.0-SNAPSHOT Arrow_down_16x16



  • (seq-ref-combobox-model seq-ref & [selected])

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/combo_box.clj:54 top

(defn seq-ref-combobox-model [seq-ref & [selected]]
  (let [selected (or selected (atom nil))
	listeners (atom #{})
	key (gensym "seq-ref-combobox-model-watch")
	m (commbo-box-model
	   :mutable true
	   :size ([] (count @seq-ref))
	   :get-selected-item ([] (dosync (if (and @selected (some #(= @selected %) @seq-ref)) @selected (swap! selected (constantly nil)))))
	   :set-selected-item ([i] (dosync (if (and i (some #(= i %) @seq-ref)) (swap! selected (constantly i)) (swap! selected (constantly nil)))))
	   :add-listener ([l] (swap! listeners conj l))
	   :remove-listener ([l] (swap! listeners disj l))
	   :get ([i] (if (has-index? @seq-ref i) (nth @seq-ref i) nil))
	   :add ([itm] (dosync (alter seq-ref conj itm)))
	   :add-at ([itm idx] (dosync 
			       (if (vector? @seq-ref)
				 (alter seq-ref #(vec (insert-at % idx itm)))
				 (alter seq-ref insert-at idx itm))))
	   :remove ([itm] (dosync 
			       (if (vector? @seq-ref)
				 (alter seq-ref #(vec (remove (partial = itm) %)))
				 (alter seq-ref #(remove (partial = itm) %)))))
	   :remove-at ([idx] (dosync 
			       (if (vector? @seq-ref)
				 (alter seq-ref #(vec (drop-nth % idx)))
				 (alter seq-ref drop-nth idx)))))]
    (add-watch seq-ref key 
		    (fn [_ _ _ state]
		       (let [m (ListDataEvent. m (ListDataEvent/CONTENTS_CHANGED) 0 (count state))]
			(doseq [l @listeners]
			  (.contentsChanged l m))))))
Vars in clj-swing.combo-box/seq-ref-combobox-model: add-watch defn doseq fn key let
Used in 0 other vars

Comments top

No comments for seq-ref-combobox-model. Log in to add a comment.