Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Seesaw Ad Hoc StyleSheet
(ns pi.core
(:use seesaw.core))
(native!)
(def gap [:fill-h 5])
; Set up the structure of the ui, giving widgets classes and ids as needed.
(defn make-frame []
(frame
:on-close :exit
:size [300 :by 300]
:content (border-panel :class :container
:north (toolbar :items ["Steps" gap (text :id :steps) gap
"Step size" gap (text :id :step-size) gap
(button :id :go)])
:center (label :id :result)
:south (toolbar :items [(progress-bar :id :progress :min 0 :max 10000) gap
(button :id :cancel)]))))
; This is the "stylesheet", a map from Seesaw selector to property map.
(def stylesheet {
[:JFrame] {
:title "Let's Calculate \u03C0!!" }
[:.container] {
:background "#ffefd5"
:vgap 5
:hgap 5 }
[:JToolBar] {
:border 5
:floatable? false
:opaque? false }
[:#steps] { :text 10000 }
[:#step-size] { :text 10000 }
[:JButton] {
:foreground "#0022DD"
:background "#ffefd5" }
[:#go] { :text "Go!" }
[:#cancel] { :text "Cancel" }
[:#progress] {
:border 10 }
[:#result] {
:text (format "\u03C0 = %.20f" 0.0)
:border 5
:halign :center
:font "MONOSPACE-BOLD-24"
:foreground "#0022DD" }})
; Apply a style sheet to a frame
(defn apply-stylesheet [root stylesheet]
(doseq [[sel style] stylesheet]
(apply config! (select root sel) (reduce concat style)))
root)
; now bring everything together and display it.
(defn -main [& args]
(invoke-later
(-> (make-frame)
(apply-stylesheet stylesheet)
pack!
show!)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment