Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (require '[clojure.string :as str])
- (defn keyword->setter [kw]
- (->> (str/split (name kw) #"-")
- (map str/capitalize)
- (apply str "set")
- (symbol)))
- (defmacro bean-set! [bean props]
- `(doto ~bean
- ~@(for [[k v] props]
- `(. ~(keyword->setter k) ~v))))
- (defmacro create-bean [cls props]
- `(bean-set! (new ~cls) ~props))
- (defn dim [w h] (Dimension. w h))
- (create-bean JFrame {:title "Hello, world!"
- :size (dim 400 300)
- :visible true})
- ; -> #<JFrame javax.swing.JFrame[frame6,0,0,400x300,invalid,layout=java.awt.BorderLayout,title=Hello, world!,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,4,30,392x266,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement