From c26d449f66d8889929a451d3eebbde0b9a43fefc Mon Sep 17 00:00:00 2001 From: "dziltener@lyrion.ch" Date: Sat, 7 Jan 2017 17:48:17 +0000 Subject: [PATCH] no message --- src/clojurefx/AppWrap.java | 2 +- src/clojurefx/clojurefx.clj | 68 +++++++++++++------------------ src/clojurefx/factory.clj | 12 ------ test/clojurefx/clojurefx_test.clj | 45 -------------------- test/clojurefx/exampleWindow.fxml | 13 ++++++ test/clojurefx/factory_test.clj | 52 ----------------------- test/resources/test.fxml | 15 ------- 7 files changed, 42 insertions(+), 165 deletions(-) delete mode 100644 test/clojurefx/clojurefx_test.clj create mode 100644 test/clojurefx/exampleWindow.fxml delete mode 100644 test/clojurefx/factory_test.clj delete mode 100644 test/resources/test.fxml diff --git a/src/clojurefx/AppWrap.java b/src/clojurefx/AppWrap.java index fcd0cc5..f6ecdca 100644 --- a/src/clojurefx/AppWrap.java +++ b/src/clojurefx/AppWrap.java @@ -10,7 +10,7 @@ import javafx.stage.Stage; */ public class AppWrap extends Application { - String ns, fn; + private String ns, fn; public AppWrap(String ns, String fn) { super(); diff --git a/src/clojurefx/clojurefx.clj b/src/clojurefx/clojurefx.clj index 8ef2bc0..47111cb 100644 --- a/src/clojurefx/clojurefx.clj +++ b/src/clojurefx/clojurefx.clj @@ -2,40 +2,41 @@ (:require [taoensso.timbre :as timbre] [clojure.java.io :as io] [clojure.zip :as zip] - [clojurefx.protocols :as p] - [clojure.java.io :refer :all]) - (:import (clojurefx AppWrap))) + [clojurefx.protocols :as p])) + +;; Fuck you, whoever made that API design. +(defonce force-toolkit-init (javafx.embed.swing.JFXPanel.)) + +(timbre/refer-timbre) + +(import '(clojurefx AppWrap) + '(javafx.scene.control Labeled Label TextField TextArea CheckBox ComboBox Menu MenuItem MenuBar + MenuButton ContextMenu ToolBar SplitPane ScrollPane Accordion + TitledPane TabPane Tab TableColumnBase Labeled ButtonBase) + '(javafx.scene Node Scene Parent) + '(javafx.scene.layout Pane VBox) + '(javafx.stage Stage) + '(javafx.collections FXCollections ObservableList) + '(javafx.css Styleable) + '(javafx.event Event ActionEvent EventTarget) + '(java.util Collection)) (defn gen-stage! [nspc fun] (let [appwrap (AppWrap. nspc fun)] - (.launch appwrap))) + (.launch appwrap nil))) ;; ## Threading helpers -(defn run-later*" - Simple wrapper for Platform/runLater. You should use run-later. - " [f] - (assert (instance? Runnable f)) - (javafx.application.Platform/runLater f) - nil) +(defmacro run-later "Simple wrapper for Platform/runLater." [& body] + `(javafx.application.Platform/runLater (fn [] ~@body))) -(defmacro run-later [& body] - `(run-later* (fn [] ~@body))) - -(defn run-now* " - A modification of run-later waiting for the running method to return. You should use run-now. - " [f] - (if (javafx.application.Platform/isFxApplicationThread) - (apply f []) - (let [result (promise)] - (run-later - (deliver result (try (f) (catch Throwable e e)))) - @result))) - -(defmacro run-now " - Runs the code on the FX application thread and waits until the return value is delivered. - " [& body] - `(run-now* (fn [] ~@body))) +(defmacro run-now "Runs the code on the FX application thread and waits until the return value is delivered." + [& body] + `(if (javafx.application.Platform/isFxApplicationThread) + (apply (fn [] ~@body) []) + (let [result (promise)] + (run-later (deliver result (try (fn [] ~@body) (catch Throwable e e)))) + @result))) (defn collize " Turns the input into a collection, if it isn't already. @@ -44,19 +45,6 @@ input (list input))) -(timbre/refer-timbre) - -(import (javafx.scene.control Labeled Label TextField TextArea CheckBox ComboBox Menu MenuItem MenuBar - MenuButton ContextMenu ToolBar SplitPane ScrollPane Accordion - TitledPane TabPane Tab TableColumnBase Labeled ButtonBase) - (javafx.scene Node Scene Parent) - (javafx.scene.layout Pane VBox) - (javafx.stage Stage) - (javafx.collections FXCollections ObservableList) - (javafx.css Styleable) - (javafx.event Event ActionEvent EventTarget) - (java.util Collection)) - (defn pred-protocol [proto check] (let [impls (keys (proto :impls)) check (type check)] diff --git a/src/clojurefx/factory.clj b/src/clojurefx/factory.clj index b4dd6b0..4d4c160 100644 --- a/src/clojurefx/factory.clj +++ b/src/clojurefx/factory.clj @@ -53,10 +53,6 @@ (trace "Key:" k " " (type k) "Value:" v " " (type v)) (when (nil? translation) (throw (Exception. (str "Property" k "not available in translation map.")))) - ;; (when-not ((pred-substitute argument) v) - ;; (throw (Exception. (str "Input type" v "is not compatible with expected type for" k)))) - ;; (when-not ((pred-substitute parent) node) - ;; (throw (Exception. (str "Property" k "not available for class" (class node))))) ((setter translation) node v))) node) @@ -73,14 +69,6 @@ eval) (apply dissoc props mandatory)))) -;; (ann resolv-o-matic [(U String Keyword Symbol Class) -> Class]) -;; (defn resolv-o-matic [thing] -;; (cond -;; (symbol? thing) (ns-resolve (the-ns 'clojurefx.clojurefx) thing) -;; (keyword? thing) (recur (name thing)) -;; (string? thing) (recur (symbol thing)) -;; :else thing)) - (defn compile ([args] (compile args [])) ([[obj & other] accu] diff --git a/test/clojurefx/clojurefx_test.clj b/test/clojurefx/clojurefx_test.clj deleted file mode 100644 index cce9269..0000000 --- a/test/clojurefx/clojurefx_test.clj +++ /dev/null @@ -1,45 +0,0 @@ -(ns clojurefx.clojurefx-test - (:refer-clojure :exclude [compile meta with-meta]) - (:require [clojurefx.factory :as factory] - [clojurefx.protocols :refer :all]) - (:use midje.sweet - clojurefx.clojurefx)) - -(import (javafx.scene.layout VBox) - (javafx.scene.control ScrollPane Button Label)) - -;;## Element testing - -;;## Event testing -;;(def button (new Button)) -(def button (atom nil)) -(def fired? (atom false)) -(facts "Events" - (fact "Creating button with event handler" - (class (reset! button (factory/compile [Button {:action (fn [_] (reset! fired? true))}]))) => javafx.scene.control.Button) - (fact "Firing the event and checking the result" - (do (fire! @button) - @fired?) => true)) - -;;## IdMapper -(def example-graph - (factory/compile - [VBox {:id "topBox" - :children [Button {:id "button" - :text "Close"} - ScrollPane {:content [Label {:id "label" - :text "This rocks."}]}]}])) - -(facts "Id mapper" - (fact "Getting a top-level entry" - (type (get-node-by-id example-graph "topBox")) => javafx.scene.layout.VBox) - (fact "Getting an entry in an FXParent" - (type (get-node-by-id example-graph "button")) => javafx.scene.control.Button) - (fact "Getting an entry in an FXParent and an FXContainer" - (type (get-node-by-id example-graph "label")) => javafx.scene.control.Label) - (fact "Fetching the whole id map." - (map? (get-id-map example-graph)) => true) - (fact "Fetching label text from id-map." - (-> (get-id-map example-graph) - :label - get-value) => "This rocks.")) diff --git a/test/clojurefx/exampleWindow.fxml b/test/clojurefx/exampleWindow.fxml new file mode 100644 index 0000000..47ff9de --- /dev/null +++ b/test/clojurefx/exampleWindow.fxml @@ -0,0 +1,13 @@ + + + + + + + + + + +