Listbox (JList) Nie będzie aktualizowany dynamicznie z niestandardowego ListModel
Pracuję nad aplikacją GUI w Clojure za pomocą Seesaw i mam problem z uzyskaniem listbox (JList w Javie) do aktualizacji, gdy mój niestandardowy ListModel zostanie zaktualizowany.
Oto część mojego kodu:
(deftype ActionHistoryListModel
[^{:unsynchronized-mutable true} listeners
^{:unsynchronized-mutable true} listening-to]
ListModel
(addListDataListener [this listener]
(set! listeners (conj listeners listener)))
(removeListDataListener [this listener]
(set! listeners (remove #(= % listener) listeners)))
(getSize [this]
(get-in (deref listening-to) [:count]))
(getElementAt [this index]
(get-in (deref listening-to) [:actions index]))
ActionHistoryListModelProtocol
(listen-to [this r]
(do
(set! listening-to r)
(add-watch r this (fn [_ _ _ new-state] (.notify this new-state)))))
(notify [this new-state]
(let [action ((meta new-state) :last-action)
const (cond
(= action :create) INTERVAL_ADDED
(= action :update) CONTENTS_CHANGED)
index (last ((meta new-state) :action-target))
event (ListDataEvent. this const index index)
notification (cond
(= action :create) #(.intervalAdded % event)
(= action :update) #(.contentsChanged % event))
]
(. (.. System out) print (str "Index: " index "\n" "Event: " event "\n"))
(map #(invoke-later (notification %)) listeners)))
)
(defn make-action-history-list-model []
(ActionHistoryListModel. #{} nil))
(def ahlm (make-action-history-list-model))
(.listen-to ahlm action-history)
(def undo-list (listbox :model ahlm))
; then put list in frame...
gdzieaction-history
jestref
.
Przechodzi do punktu, w którym lista powinna zostać zaktualizowana, ponieważSystem.out.print
się dzieje, ale listbox nie chce się aktualizować
Jakieś pomysły na to, co może pójść źle? Czy to coś z mieszanką korzystania z EDT i oddzwaniania?
Daj mi znać, jeśli potrzebujesz więcej kodu.