/
messages.clj
64 lines (50 loc) · 2.72 KB
/
messages.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
(ns lib.sfd.swing.messages
(:import [javax.swing JOptionPane JFileChooser]))
(def *parent-frame* nil)
(defn messenger-factory
[message-type]
(fn [m t] (JOptionPane/showMessageDialog parnet-frame m t message-type nil)))
(defn plain-message
"Creates a dialog that shows a plain message. Will block the thread it is in. Returns nil."
([message] (plain-message message nil))
([message title] ((messenger-factory JOptionPane/PLAIN_MESSAGE) message title)))
(defn info-message
"Creates a dialog that shows an informational message. Will block the thread it is in. Returns nil."
([message] (info-message message nil))
([message title] ((messenger-factory JOptionPane/INFORMATION_MESSAGE) message title)))
(defn warning-message
"Creates a dialog that shows a warning message. Will block the thread it is in. Returns nil."
([message] (warning-message message nil))
([message title] ((messenger-factory JOptionPane/WARNING_MESSAGE) message title)))
(defn error-message
"Creates a dialog that shows an error message. Will block the thread it is in. Returns nil."
([message] (error-message message nil))
([message title] ((messenger-factory JOptionPane/ERROR_MESSAGE) message title)))
(defn question-message
"Creates a dialog that shows a question message. Will block the thread it is in. Returns nil."
([message] (question-message message nil))
([message title] ((messenger-factory JOptionPane/QUESTION_MESSAGE) message title)))
;A map to turn integers into keywords
(def yes-no-decoder {JOptionPane/YES_OPTION :yes
JOptionPane/NO_OPTION :no})
(defn yes-no-dialog
"Creates an yes/no dialog. Will block the thread it is in. Returns :yes or :no"
([message] (yes-no-dialog message nil))
([message title] (yes-no-decoder
(JOptionPane/showConfirmDialog nil message title JOptionPane/YES_NO_OPTION))))
(defn yes-no-cancel-dialog
"Creates an yes/no/cancel dialog. Will block the thread it is in. Returns :yes or :no, or nil if cancelled"
([message] (yes-no-cancel-dialog message nil))
([message title] (yes-no-decoder
(JOptionPane/showConfirmDialog nil message title JOptionPane/YES_NO_CANCEL_OPTION))))
(defn input-dialog
"Creates an input dialog. Will block the thread it is in. Returns the value entered as a String, nil if cancelled."
[message] (JOptionPane/showInputDialog message))
(defn dropdown-dialog
"Creates a dropdown dialog. Will block the thread it is in. Returns the value selected, or nil if cancelled."
([message title coll] (dropdown-dialog message title coll nil))
([message title coll default] (JOptionPane/showInputDialog nil message title JOptionPane/QUESTION_MESSAGE nil (into-array coll) default)))
;(defn file-open-dialog
; ([]))
;(defn file-save-dialog
; ([]))