A Brief Note on Seesaw Selectors
Just wanted to note that I finally got around to a full implementation of CSS-style selectors in Seesaw, the Clojure UI library I’ve been working on. The updated doc for the
(seesaw.core/select) function has most of the details, but here are a couple examples:
; All JLabels, no sub-classes allowed (select root [:<javax.swing.JLabel!>]) ; All JSliders that are descendants of a JPanel with id foo (select root [:JPanel#foo :JSlider]) ; All JSliders (and sub-classes) that are immediate children of a ; JPanel with id foo (select root [:JPanel#foo :> :<javax.swing.JSlider>])
To implement the selectors, I hacked up the zipper-based selector code in the very cool Enlive project. It was surprisingly straightforward:
- Modify zipper construction to create a zipper over a Swing widget hierarchy instead of an HTML doc
- Hack up the parser a little bit to allow my Java-class-matching extensions
- Update the predicate sets to work on widgets instead of DOM nodes
Hats off to Christophe Grand for writing such a well-factored piece of Clojure code that I could get this working in an evening.
I’ll write more (like what this could be useful for) when it’s not the middle of the night.
p.s. this will be in the 1.0.6 release on Clojars sometime this week after I beat on it a bit more.