Advertisement
Guest User

Untitled

a guest
Mar 26th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. (require '[clojure.string :as str])
  2.  
  3. (defn keyword->setter [kw]
  4. (->> (str/split (name kw) #"-")
  5. (map str/capitalize)
  6. (apply str "set")
  7. (symbol)))
  8.  
  9. (defmacro bean-set! [bean props]
  10. `(doto ~bean
  11. ~@(for [[k v] props]
  12. `(. ~(keyword->setter k) ~v))))
  13.  
  14. (defmacro create-bean [cls props]
  15. `(bean-set! (new ~cls) ~props))
  16.  
  17. (defn dim [w h] (Dimension. w h))
  18.  
  19. (create-bean JFrame {:title "Hello, world!"
  20. :size (dim 400 300)
  21. :visible true})
  22. ; -> #<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