forked from cljfx/cljfx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe17_dialogs.clj
86 lines (77 loc) · 3.04 KB
/
e17_dialogs.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
(ns e17-dialogs
(:require [cljfx.api :as fx])
(:import [javafx.scene.control DialogEvent Dialog ButtonType ButtonBar$ButtonData]))
(set! *warn-on-reflection* true)
(def *state
(atom :select-action))
(defn window [_]
{:fx/type :stage
:showing true
:scene {:fx/type :scene
:root {:fx/type :v-box
:padding 20
:spacing 10
:children [{:fx/type :label
:text "Launch nukes?"}
{:fx/type :button
:text "Yes"
:on-action (fn [_]
(reset! *state :confirm))}]}}})
(defn dialog [_]
{:fx/type :dialog
:showing true
:on-hidden (fn [^DialogEvent e]
(condp = (.getButtonData ^ButtonType (.getResult ^Dialog (.getSource e)))
ButtonBar$ButtonData/NO (reset! *state :select-action)
ButtonBar$ButtonData/YES (reset! *state :confirmed)))
:dialog-pane {:fx/type :dialog-pane
:header-text "Nuke launch confirmation dialog™"
:content-text "Are you sure?"
:expandable-content {:fx/type :label
:text "This action can't be undone."}
:button-types [:no :yes]}})
(defn alert [_]
{:fx/type :alert
:alert-type :warning
:showing true
:on-close-request (fn [^DialogEvent e]
(when (nil? (.getResult ^Dialog (.getSource e)))
(.consume e)))
:on-hidden (fn [_]
(reset! *state :choose-vault))
:header-text "Nuke launch inevitable"
:content-text "Please press Yes"
:button-types [:yes]})
(defn choice-dialog [_]
{:fx/type :choice-dialog
:showing true
:on-close-request (fn [^DialogEvent e]
(when (nil? (.getResult ^Dialog (.getSource e)))
(.consume e)))
:on-hidden (fn [_]
(reset! *state :final-notes))
:header-text "Please choose vault"
:items [{:id :vaults/v8}
{:id :vaults/v13}
{:id :vaults/v15}]})
(defn text-input-dialog [_]
{:fx/type :text-input-dialog
:showing true
:header-text "Final notes?"
:on-hidden (fn [^DialogEvent e]
(let [result (.getResult ^Dialog (.getSource e))]
(println (format "Bye! Your final words were \"%s\"" result))
(reset! *state :the-end)))})
(def renderer
(fx/create-renderer
:middleware (fx/wrap-map-desc
(fn [nuke-launch-stage]
{:fx/type fx/ext-many
:desc (case nuke-launch-stage
:select-action [{:fx/type window}]
:confirm [{:fx/type dialog}]
:confirmed [{:fx/type alert}]
:choose-vault [{:fx/type choice-dialog}]
:final-notes [{:fx/type text-input-dialog}]
[])}))))
(fx/mount-renderer *state renderer)