This commit is contained in:
Daniel Ziltener 2015-01-20 11:46:30 +00:00
parent 181d0d5156
commit ea49169b24
2 changed files with 24 additions and 10 deletions

View file

@ -39,6 +39,13 @@ nil)
" [& body] " [& body]
`(run-now* (fn [] ~@body))) `(run-now* (fn [] ~@body)))
(defn collize "
Turns the input into a collection, if it isn't already.
" [input]
(if (coll? input)
input
(list input)))
(tc-ignore (timbre/refer-timbre)) (tc-ignore (timbre/refer-timbre))
(import (javafx.scene.control Labeled Label TextField TextArea CheckBox ComboBox Menu MenuItem MenuBar (import (javafx.scene.control Labeled Label TextField TextArea CheckBox ComboBox Menu MenuItem MenuBar
@ -121,31 +128,31 @@ nil)
(extend-protocol p/FXParent (extend-protocol p/FXParent
Pane Pane
(get-subnodes [this] (.getChildren ^Pane this)) (get-subnodes [this] (.getChildren ^Pane this))
(set-subnodes! [this nodes] (.setAll ^ObservableList (.getChildren ^Pane this) ^Collection nodes) this) (set-subnodes! [this nodes] (.setAll ^ObservableList (.getChildren ^Pane this) (collize nodes)) this)
TabPane TabPane
(get-subnodes [this] (.getTabs ^TabPane this)) (get-subnodes [this] (.getTabs ^TabPane this))
(set-subnodes! [this nodes] (.setAll ^ObservableList (.getTabs ^TabPane this) ^Collection nodes) this) (set-subnodes! [this nodes] (.setAll ^ObservableList (.getTabs ^TabPane this) (collize nodes)) this)
MenuBar MenuBar
(get-subnodes [this] (.getMenus ^MenuBar this)) (get-subnodes [this] (.getMenus ^MenuBar this))
(set-subnodes! [this nodes] (.setAll ^ObservableList (.getMenus ^MenuBar this) ^Collection nodes) this) (set-subnodes! [this nodes] (.setAll ^ObservableList (.getMenus ^MenuBar this) (collize nodes)) this)
Menu Menu
(get-subnodes [this] (.getItems ^Menu this)) (get-subnodes [this] (.getItems ^Menu this))
(set-subnodes! [this nodes] (.setAll ^ObservableList (.getItems ^Menu this) ^Collection nodes) this) (set-subnodes! [this nodes] (.setAll ^ObservableList (.getItems ^Menu this) nodes) (collize this))
MenuButton MenuButton
(get-subnodes [this] (.getItems ^MenuButton this)) (get-subnodes [this] (.getItems ^MenuButton this))
(set-subnodes! [this nodes] (.setAll ^ObservableList (.getItems ^MenuButton this) ^Collection nodes) this) (set-subnodes! [this nodes] (.setAll ^ObservableList (.getItems ^MenuButton this) (collize nodes)) this)
ContextMenu ContextMenu
(get-subnodes [this] (.getItems ^ContextMenu this)) (get-subnodes [this] (.getItems ^ContextMenu this))
(set-subnodes! [this nodes] (.setAll ^ObservableList (.getItems ^ContextMenu this) ^Collection nodes) this) (set-subnodes! [this nodes] (.setAll ^ObservableList (.getItems ^ContextMenu this) (collize nodes)) this)
ToolBar ToolBar
(get-subnodes [this] (.getItems ^ToolBar this)) (get-subnodes [this] (.getItems ^ToolBar this))
(set-subnodes! [this nodes] (.setAll ^ObservableList (.getItems ^ToolBar this) ^Collection nodes) this) (set-subnodes! [this nodes] (.setAll ^ObservableList (.getItems ^ToolBar this) (collize nodes)) this)
SplitPane SplitPane
(get-subnodes [this] (.getItems ^SplitPane this)) (get-subnodes [this] (.getItems ^SplitPane this))
(set-subnodes! [this nodes] (.setAll ^ObservableList (.getItems ^SplitPane this) ^Collection nodes) this) (set-subnodes! [this nodes] (.setAll ^ObservableList (.getItems ^SplitPane this) (collize nodes)) this)
Accordion Accordion
(get-subnodes [this] (.getPanes ^Accordion this)) (get-subnodes [this] (.getPanes ^Accordion this))
(set-subnodes! [this nodes] (.setAll ^ObservableList (.getPanes ^Accordion this) ^Collection nodes) this))) (set-subnodes! [this nodes] (.setAll ^ObservableList (.getPanes ^Accordion this) (collize nodes)) this)))
(tc-ignore (tc-ignore
(extend-protocol p/FXContainer (extend-protocol p/FXContainer

View file

@ -31,6 +31,11 @@
ScrollPane {:content [Label {:id "label" ScrollPane {:content [Label {:id "label"
:text "This rocks."}]}]}]) :text "This rocks."}]}]}])
(def example-graph3
[VBox {:id "topBox"
:children [Button {:id "button"
:text "Close"}]}])
(def scene-graph (atom nil)) (def scene-graph (atom nil))
(facts "Vector compilation" (facts "Vector compilation"
@ -42,4 +47,6 @@
(type (reset! scene-graph (compile example-graph))) => javafx.scene.layout.VBox (type (reset! scene-graph (compile example-graph))) => javafx.scene.layout.VBox
(get-id @scene-graph) => "topBox") (get-id @scene-graph) => "topBox")
(fact "Partially precompiled nested structure" (fact "Partially precompiled nested structure"
(type (reset! scene-graph (compile example-graph2))) => javafx.scene.layout.VBox)) (type (reset! scene-graph (compile example-graph2))) => javafx.scene.layout.VBox)
(fact "Nested structure where FXParent only has one child"
(type (reset! scene-graph (compile example-graph3))) => javafx.scene.layout.VBox))