You could also hide the vector inside your list model code, and require modification through an api. This would let you know what updates to send to the Swing object without having to walk the list.
On Fri, Feb 20, 2009 at 11:11 AM, Rowdy Rednose <rowdy.redn...@gmx.net>wrote: > > Thanks pmf and Jeffrey, > > so I guess the idea is to have the TableModel hold on to the > (dereferenced) vector and when the agent fires, the model would > dereference the ref again and compare that value with the old one. It > would then have to do a diff on those 2. > > That is one of the unelegant ideas I had - unelegant, because I have > to iterate through both collections and do a (much more complicated > than the "map =") diff on potentially large vectors, just because 1 > entry has been added. At the time we add that entry, we know what we > are doing, so if we could keep that information instead of losing it > and having to diff 2 complete collections later... But I don't have an > idea on how to do this in Clojure. > > On Feb 20, 11:15 pm, Jeffrey Straszheim <straszheimjeff...@gmail.com> > wrote: > > It would be pretty easy to wrap an agent (as pmf suggests) to notify your > > model class if a Vector changes. You could then do something like > > (map = old_vec new_vec) > > > > And then look for false results in the array and send a notification to > > Swing. > > > > On Fri, Feb 20, 2009 at 5:40 AM, Rowdy Rednose <rowdy.redn...@gmx.net > >wrote: > > > > > > > > > All the clojure swing examples I've seen so far use JTables in a > > > static way, i.e. the data is not programmatically modified once the > > > table got created. > > > > > Has anyone actually tried to implement a TableModel that is backed by > > > a clojure Vector/Map and fires events to TableModelListeners when the > > > underlying data changes? > > > > > I've got a few ideas on how to implement this, but none of them seems > > > to be very elegant (which is why I am interested in clojure in the > > > first place). > > > > > For those of you who don't know the events that a TableModel fires, > > > they are: > > > > > * Table has changed ( => redraw the whole thing) > > > * Rows x through y have changed (=> redraw only those) > > > * Rows x through y have been inserted > > > * Rows x through y have been deleted > > > > > (Full details: > > >http://java.sun.com/javase/6/docs/api/javax/swing/event/TableModelEve. > .. > > > ) > > > > > Any elegant ideas or examples on how to do this when the underlying > > > data structure is (a ref to) one of clojure's (immutable) collections, > > > so that a change to that structure will fire the appropriate event? > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---