From 3bd58af56a19e4a33bd160a67cb7c7b6cf10bf64 Mon Sep 17 00:00:00 2001 From: "dziltener@lyrion.ch" Date: Thu, 29 Aug 2013 08:36:32 +0000 Subject: [PATCH] listener macro --- src/clojurefx/core.clj | 31 ++++++++++++------- target/repl/stale/extract-native.dependencies | 1 + 2 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 target/repl/stale/extract-native.dependencies diff --git a/src/clojurefx/core.clj b/src/clojurefx/core.clj index e2d6cd5..7d04d3d 100644 --- a/src/clojurefx/core.clj +++ b/src/clojurefx/core.clj @@ -89,25 +89,34 @@ Don't use this yourself; See the macros \"build\" and \"deffx\" below. (if (not (empty? (filter #(= % builder) (get pkgs k)))) (symbol (str k "." (camel (name builder)))))))))) -(defmacro build - "This helper macro makes it easier to use the [JavaFX builder classes](http://docs.oracle.com/javafx/2/api/javafx/util/Builder.html). You can also use a map, so it is possible to compose the arguments for the builder over time. +(defmacro build"This helper macro makes it easier to use the [JavaFX builder classes](http://docs.oracle.com/javafx/2/api/javafx/util/Builder.html). You can also use a map, so it is possible to compose the arguments for the builder over time. **Examples:** * `(build button (text \"Close me.\") (cancelButton true))` - * `(build button {:text \"Close me.\" :cancelButton true})`" - [what & args] + * `(build button {:text \"Close me.\" :cancelButton true})` +"[what & args] (if (and (= 1 (count args)) (map? (first args))) `(build ~what ~@(for [entry# (keys (first args))] `(~(symbol (name entry#)) ~((first args) entry#)))) - `(.. ~(get-qualified what) create - ~@args - build))) + `(run-now (.. ~(get-qualified what) ~(symbol "create") + ~@args + ~(symbol "build"))))) -(defmacro deffx - "Uses build and assigns the result to a symbol." - [name what & args] - `(def ~name +(defmacro deffx " +Uses build and assigns the result to a symbol. +"[name what & args] +`(def ~name (build ~what ~@args))) + +;; # Event handling +(defmacro add-listener " +Adds a listener to prop (\"Property\" gets added automatically) of obj, gets the value and passes it to fun. +"[obj prop fun] + `(.. ~obj + ~(symbol (str (name prop) "Property")) + (addListener (reify javafx.beans.value.ChangeListener + (changed [c#] + (~fun (.getValue c#))))))) diff --git a/target/repl/stale/extract-native.dependencies b/target/repl/stale/extract-native.dependencies new file mode 100644 index 0000000..73974ba --- /dev/null +++ b/target/repl/stale/extract-native.dependencies @@ -0,0 +1 @@ +([:dependencies ([org.clojure/clojure "1.5.1"] [com.oracle/javafx-runtime "2.2.0"] [org.clojure/tools.nrepl "0.2.3"] [clojure-complete/clojure-complete "0.2.3"])]) \ No newline at end of file