Created
November 24, 2010 05:05
-
-
Save harto/713148 to your computer and use it in GitHub Desktop.
ideas for clojure-swing interop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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]> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment