public
Description: A 3D Graphing Calculator
Homepage:
Clone URL: git://github.com/curran/LiquidMath.git
LiquidMath / controller.clj
100644 24 lines (19 sloc) 0.825 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(defn update-text-field []
  (when (not (= (.getText text-field) @function-str))
    (.setText text-field @function-str)))
 
(defn update-display-list []
  (dosync (ref-set display-list-needs-updating true)))
 
(defn link
  "Expects a sequence of refs and a sequence of functions. Adds a watch (via add-watch) to the refs which calls the functions in the order given."
  [refs functions]
  (let [f (fn [k r o n] (doseq [f functions] (f)))]
    (doseq [r refs] (add-watch r (str (gensym)) f))))
 
(link [function-str] [generate-compiled-function update-text-field update-display-list])
 
(.addActionListener
 text-field
 (proxy [ActionListener] []
   (actionPerformed [e] (set-function-str (.getActionCommand e)))))
 
(.addWindowListener
 frame
 (proxy [WindowAdapter] []
   (windowClosing [e] (.stop animator) (.dispose frame))))