From ea49169b240df1ecdcaf5138282e5e8c6e865ee9 Mon Sep 17 00:00:00 2001 From: "dziltener@lyrion.ch" Date: Tue, 20 Jan 2015 11:46:30 +0000 Subject: [PATCH] Fixed #2 --- src/clojurefx/clojurefx.clj | 25 ++++++++++++++++--------- test/clojurefx/factory_test.clj | 9 ++++++++- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/clojurefx/clojurefx.clj b/src/clojurefx/clojurefx.clj index 6757bea..af0916f 100644 --- a/src/clojurefx/clojurefx.clj +++ b/src/clojurefx/clojurefx.clj @@ -39,6 +39,13 @@ nil) " [& 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)) (import (javafx.scene.control Labeled Label TextField TextArea CheckBox ComboBox Menu MenuItem MenuBar @@ -121,31 +128,31 @@ nil) (extend-protocol p/FXParent Pane (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 (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 (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 (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 (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 (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 (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 (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 (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 (extend-protocol p/FXContainer diff --git a/test/clojurefx/factory_test.clj b/test/clojurefx/factory_test.clj index ce9b0bf..ca663a7 100644 --- a/test/clojurefx/factory_test.clj +++ b/test/clojurefx/factory_test.clj @@ -31,6 +31,11 @@ ScrollPane {:content [Label {:id "label" :text "This rocks."}]}]}]) +(def example-graph3 + [VBox {:id "topBox" + :children [Button {:id "button" + :text "Close"}]}]) + (def scene-graph (atom nil)) (facts "Vector compilation" @@ -42,4 +47,6 @@ (type (reset! scene-graph (compile example-graph))) => javafx.scene.layout.VBox (get-id @scene-graph) => "topBox") (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))