/
e16_cell_factories.clj
95 lines (88 loc) · 3.16 KB
/
e16_cell_factories.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
(ns e16-cell-factories
(:require [cljfx.api :as fx]))
(def list-view
{:fx/type :list-view
:cell-factory (fn [i]
(let [color (format "#%03x" i)]
{:style {:-fx-background-color color}
:text color}))
:items (range 16r1000)})
(def table-view
{:fx/type :table-view
:columns [{:fx/type :table-column
:text "pr-str"
:cell-value-factory identity
:cell-factory (fn [x]
{:text (pr-str x)})}
{:fx/type :table-column
:text "bg color"
:cell-value-factory identity
:cell-factory (fn [i]
{:style {:-fx-background-color i}})}]
:items [:red :green :blue "#ccc4" "#ccc4"]})
(def combo-box
{:fx/type :combo-box
:button-cell (fn [user] {:text (:name user)})
:cell-factory (fn [user] {:text (:name user)})
:items [{:name "Fred"}
{:name "Rick"}]})
(defn- ->tree-item [x]
(cond
(string? x) {:fx/type :tree-item :value x}
(seqable? x) {:fx/type :tree-item :value x :children (map ->tree-item x)}
:else {:fx/type :tree-item :value x}))
(def tree-table-view
{:fx/type :tree-table-view
:columns [{:fx/type :tree-table-column
:text "pr-str"
:max-width 960/2
:cell-value-factory identity
:cell-factory (fn [x]
{:text (pr-str x)})}
{:fx/type :tree-table-column
:text "str"
:max-width 960/2
:cell-value-factory identity
:cell-factory (fn [x]
{:text (str x)})}]
:root (->tree-item
{:set #{:a :b :c}
:scalars ["string" false 1 1M 1/2 1.0 'symbol :keyword]
:map {:a 1}
:vec [1 2 3]
:list '(1 2 3)
:range (range 4)})})
(def tree-view
{:fx/type :tree-view
:cell-factory (fn [x]
{:text (str x)})
:root (->tree-item table-view)})
(fx/on-fx-thread
(fx/create-component
{:fx/type :stage
:showing true
:title "Cell factory examples"
:scene {:fx/type :scene
:root {:fx/type :tab-pane
:pref-width 960
:pref-height 540
:tabs [{:fx/type :tab
:text "Table View"
:closable false
:content table-view}
{:fx/type :tab
:text "List View"
:closable false
:content list-view}
{:fx/type :tab
:text "Combo box"
:closable false
:content combo-box}
{:fx/type :tab
:text "Tree Table View"
:closable false
:content tree-table-view}
{:fx/type :tab
:text "Tree View"
:closable false
:content tree-view}]}}}))