Home > clojure, seesaw > Ad Hoc Stylesheets in Seesaw

Ad Hoc Stylesheets in Seesaw

June 22nd, 2011

Following up on my last post, I decided to try that distributed pi calculation in Clojure. That’s not going so great, mostly due to my own weak sauce. Luckily, it’s not the subject of this post.

While I was doing that, I kind of got sidetracked into making a little UI that shows the estimate for pi over time, using Seesaw of course. As I fiddled with the look (UIs are such a timehole), I realized I already had the building blocks for rudimentary stylesheet support. I wrote a simple function that iterates over a map (the “stylesheet”), looks up widgets with selectors, and then applies styling using the seeseaw.core/config! function:

(defn apply-stylesheet [root stylesheet]
  (doseq [[sel style] stylesheet]
    (apply config! (select root sel) (reduce concat style)))
  root)

The end result was a nice separation of style from structure with only four lines of code.

Yes, it’s still ugly, but I never claimed to be a designer :)

Here’s the full code which uses Seesaw 1.0.7. Note that I can style classes of widgets (e.g. JButton) as well as individual widgets by id.

If you see no code, look here

Note that I’ve omitted my abomination of a pi calculation. The Clojure mailing list will probably hear from me shortly :)

clojure, seesaw

  1. alex.yakushev
    June 26th, 2011 at 20:00 | #1

    Very impressive! This Seesaw thing looks neat and beautiful!
    One question: why not to include apply-stylesheet into the framework itself? Isn’t it reusable across different projects?

  2. June 26th, 2011 at 23:25 | #2

    @alex.yakushev
    Thanks! This capability will indeed be included in Seesaw sometime soon. I want to do more experimentation and thinking before adding it officially. If I can think a little and avoid having to break the API in the future, it’s worth it :)

  1. No trackbacks yet.