From 733dad80483c802ccf0bcd021a8172c762205beb Mon Sep 17 00:00:00 2001 From: "dziltener@lyrion.ch" Date: Fri, 28 Jul 2017 18:57:11 +0000 Subject: [PATCH] Begin of new Controller Generator. --- project.clj | 1 + src/clojurefx/clojurefx.clj | 25 +++++++++++-------------- src/clojurefx/controllergen.clj | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 14 deletions(-) create mode 100644 src/clojurefx/controllergen.clj diff --git a/project.clj b/project.clj index 4764220..23e3f2d 100644 --- a/project.clj +++ b/project.clj @@ -4,6 +4,7 @@ :url "https://www.bitbucket.org/zilti/clojurefx" :dependencies [[org.clojure/clojure "1.8.0"] [swiss-arrows "1.0.0"] + [org.controlsfx/controlsfx "8.40.13"] [com.taoensso/timbre "4.7.4" :exclusions [com.taoensso/carmine]] [clojure-jsr-223 "0.1.0"]] ;; :profiles {:uberjar {:aot :all}} diff --git a/src/clojurefx/clojurefx.clj b/src/clojurefx/clojurefx.clj index 8e03ea0..86ff6ab 100644 --- a/src/clojurefx/clojurefx.clj +++ b/src/clojurefx/clojurefx.clj @@ -35,26 +35,23 @@ ~@code)))) (defn branch? [obj] - (or (instance? javafx.scene.Parent obj) + (or (and (instance? javafx.scene.Parent obj) + (not (instance? org.controlsfx.control.StatusBar obj))) (instance? javafx.scene.control.MenuBar obj) (instance? javafx.scene.control.Menu obj))) (defn make-node [node children] nil) -(defmulti down (fn [x] (class x))) -(defmethod down javafx.scene.Parent [obj] - (.getChildren obj)) -(defmethod down javafx.scene.control.MenuBar [obj] - (.getMenus obj)) -(defmethod down javafx.scene.control.Menu [obj] - (.getItems obj)) -(defmethod down javafx.scene.control.Label [obj] - [(.getGraphic obj)]) -(defmethod down javafx.scene.control.ProgressIndicator [obj] - [(.getContextMenu obj)]) -(defmethod down :default [obj] - nil) +(defn down [x] + (cond + (instance? javafx.scene.control.Label x) (.getGraphic x) + (instance? javafx.scene.control.ProgressIndicator x) (.getContextMenu x) + (instance? javafx.scene.control.ScrollPane x) (.getContent x) + (instance? javafx.scene.control.MenuBar x) (.getMenus x) + (instance? javafx.scene.control.Menu x) (.getItems x) + (instance? javafx.scene.Parent x) (.getChildren x) + :else nil)) (defn sgzipper [root] (zip/zipper branch? down make-node root)) diff --git a/src/clojurefx/controllergen.clj b/src/clojurefx/controllergen.clj new file mode 100644 index 0000000..40525be --- /dev/null +++ b/src/clojurefx/controllergen.clj @@ -0,0 +1,16 @@ +(ns clojurefx.controllergen + (:require [clojure.xml :as xml] + [clojure.zip :as zip] + [taoensso.timbre :as timbre])) +(timbre/refer-timbre) + +(def xmlzip (zip/xml-zip (xml/parse "/Users/danielziltener/projects/lizenztool/resources/fxml/mainwindow.fxml"))) + +(defn get-fxid-elems + ([ziptree] (get-fxid-elems ziptree [])) + ([ziptree elems] + (cond + (zip/end? ziptree) (do (debug "End reached, returning.") elems) + (contains? (:attrs (zip/node ziptree)) :fx:id) (do (debug "Found a match!\n" (zip/node ziptree)) + (recur (zip/next ziptree) (conj elems (zip/node ziptree)))) + :else (do (debug "No match, continuing:" (zip/node ziptree)) (recur (zip/next ziptree) elems)))))