Skip to content

Instantly share code, notes, and snippets.

@shinmuro
Created April 1, 2014 00:48
Show Gist options
  • Save shinmuro/9905624 to your computer and use it in GitHub Desktop.
Save shinmuro/9905624 to your computer and use it in GitHub Desktop.
;; http://docs.oracle.com/javase/8/javafx/properties-binding-tutorial/binding.htm#JFXBD107
;; の Example 1-7 Using the Low-Level API のサンプルを Clojure REPL で動くように書いてみた
(import javafx.beans.binding.DoubleBinding
javafx.beans.property.SimpleDoubleProperty)
(def a (SimpleDoubleProperty. 1))
(def b (SimpleDoubleProperty. 2))
(def c (SimpleDoubleProperty. 3))
(def d (SimpleDoubleProperty. 4))
(def db
(proxy [DoubleBinding] []
(bind [] (proxy-super bind a b c d))
(computeValue []
(+ (* (.get a) (.get b)) (* (.get c) (.get d))))))
(.computeValue db)
; => 14.0
(.set b 3)
; => nil
(.computeValue db)
; => 15.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment