rlm@10
|
1 ;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and
|
rlm@10
|
2 ;; distribution terms for this software are covered by the Eclipse Public
|
rlm@10
|
3 ;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can
|
rlm@10
|
4 ;; be found in the file epl-v10.html at the root of this distribution. By
|
rlm@10
|
5 ;; using this software in any fashion, you are agreeing to be bound by the
|
rlm@10
|
6 ;; terms of this license. You must not remove this notice, or any other,
|
rlm@10
|
7 ;; from this software.
|
rlm@10
|
8 ;;
|
rlm@10
|
9 ;; clojure.contrib.miglayout.test
|
rlm@10
|
10 ;;
|
rlm@10
|
11 ;; Test/example for clojure.contrib.miglayout
|
rlm@10
|
12 ;;
|
rlm@10
|
13 ;; scgilardi (gmail)
|
rlm@10
|
14 ;; Created 5 October 2008
|
rlm@10
|
15
|
rlm@10
|
16 (ns clojure.contrib.test-miglayout
|
rlm@10
|
17 (:import (javax.swing JButton JFrame JLabel JList JPanel
|
rlm@10
|
18 JScrollPane JTabbedPane JTextField JSeparator))
|
rlm@10
|
19 (:use clojure.contrib.miglayout))
|
rlm@10
|
20
|
rlm@10
|
21 (def tests)
|
rlm@10
|
22
|
rlm@10
|
23 (defn run-test
|
rlm@10
|
24 [index]
|
rlm@10
|
25 (let [panel ((tests index) (JPanel.))]
|
rlm@10
|
26 (println index (components panel))
|
rlm@10
|
27 (doto (JFrame. (format "MigLayout Test %d" index))
|
rlm@10
|
28 (.add panel)
|
rlm@10
|
29 (.pack)
|
rlm@10
|
30 (.setVisible true))))
|
rlm@10
|
31
|
rlm@10
|
32 (defn label
|
rlm@10
|
33 "Returns a swing label"
|
rlm@10
|
34 [text]
|
rlm@10
|
35 (JLabel. text))
|
rlm@10
|
36
|
rlm@10
|
37 (defn text-field
|
rlm@10
|
38 "Returns a swing text field"
|
rlm@10
|
39 ([] (text-field 10))
|
rlm@10
|
40 ([width]
|
rlm@10
|
41 (JTextField. width)))
|
rlm@10
|
42
|
rlm@10
|
43 (defn sep
|
rlm@10
|
44 "Returns a swing separator"
|
rlm@10
|
45 []
|
rlm@10
|
46 (JSeparator.))
|
rlm@10
|
47
|
rlm@10
|
48 (def tests [
|
rlm@10
|
49
|
rlm@10
|
50 (fn test0
|
rlm@10
|
51 [panel]
|
rlm@10
|
52 (miglayout panel
|
rlm@10
|
53 (label "Hello")
|
rlm@10
|
54 (label "World") {:gap :unrelated}
|
rlm@10
|
55 (text-field) :wrap
|
rlm@10
|
56 (label "Bonus!")
|
rlm@10
|
57 (JButton. "Bang it") {:wmin :button :grow :x :span 2} :center))
|
rlm@10
|
58
|
rlm@10
|
59 ;; test1 and test2 are based on code from
|
rlm@10
|
60 ;; http://www.devx.com/java/Article/38017/1954
|
rlm@10
|
61
|
rlm@10
|
62 ;; constraints as strings exclusively
|
rlm@10
|
63 (fn test1
|
rlm@10
|
64 [panel]
|
rlm@10
|
65 (miglayout panel
|
rlm@10
|
66 :column "[right]"
|
rlm@10
|
67 (label "General") "split, span"
|
rlm@10
|
68 (sep) "growx, wrap"
|
rlm@10
|
69 (label "Company") "gap 10"
|
rlm@10
|
70 (text-field "") "span, growx"
|
rlm@10
|
71 (label "Contact") "gap 10"
|
rlm@10
|
72 (text-field "") "span, growx, wrap"
|
rlm@10
|
73 (label "Propeller") "split, span, gaptop 10"
|
rlm@10
|
74 (sep) "growx, wrap, gaptop 10"
|
rlm@10
|
75 (label "PTI/kW") "gapx 10, gapy 15"
|
rlm@10
|
76 (text-field)
|
rlm@10
|
77 (label "Power/kW") "gap 10"
|
rlm@10
|
78 (text-field) "wrap"
|
rlm@10
|
79 (label "R/mm") "gap 10"
|
rlm@10
|
80 (text-field)
|
rlm@10
|
81 (label "D/mm") "gap 10"
|
rlm@10
|
82 (text-field)))
|
rlm@10
|
83
|
rlm@10
|
84 ;; the same constraints as strings, keywords, vectors, and maps
|
rlm@10
|
85 (fn test2
|
rlm@10
|
86 [panel]
|
rlm@10
|
87 (miglayout panel
|
rlm@10
|
88 :column "[right]"
|
rlm@10
|
89 (label "General") "split, span"
|
rlm@10
|
90 (sep) :growx :wrap
|
rlm@10
|
91 (label "Company") [:gap 10]
|
rlm@10
|
92 (text-field "") :span :growx
|
rlm@10
|
93 (label "Contact") [:gap 10]
|
rlm@10
|
94 (text-field "") :span :growx :wrap
|
rlm@10
|
95 (label "Propeller") :split :span [:gaptop 10]
|
rlm@10
|
96 (sep) :growx :wrap [:gaptop 10]
|
rlm@10
|
97 (label "PTI/kW") {:gapx 10 :gapy 15}
|
rlm@10
|
98 (text-field)
|
rlm@10
|
99 (label "Power/kW") [:gap 10]
|
rlm@10
|
100 (text-field) :wrap
|
rlm@10
|
101 (label "R/mm") [:gap 10]
|
rlm@10
|
102 (text-field)
|
rlm@10
|
103 (label "D/mm") [:gap 10]
|
rlm@10
|
104 (text-field)))
|
rlm@10
|
105
|
rlm@10
|
106 ;; the same constraints using symbols to name groups of constraints
|
rlm@10
|
107 (fn test3
|
rlm@10
|
108 [panel]
|
rlm@10
|
109 (let [g [:gap 10]
|
rlm@10
|
110 gt [:gaptop 10]
|
rlm@10
|
111 gxs #{:growx :span}
|
rlm@10
|
112 gxw #{:growx :wrap}
|
rlm@10
|
113 gxy {:gapx 10 :gapy 15}
|
rlm@10
|
114 right "[right]"
|
rlm@10
|
115 ss #{:split :span}
|
rlm@10
|
116 w :wrap]
|
rlm@10
|
117 (miglayout panel
|
rlm@10
|
118 :column right
|
rlm@10
|
119 (label "General") ss
|
rlm@10
|
120 (sep) gxw
|
rlm@10
|
121 (label "Company") g
|
rlm@10
|
122 (text-field "") gxs
|
rlm@10
|
123 (label "Contact") g
|
rlm@10
|
124 (text-field "") gxs
|
rlm@10
|
125 (label "Propeller") ss gt
|
rlm@10
|
126 (sep) gxw g
|
rlm@10
|
127 (label "PTI/kW") gxy
|
rlm@10
|
128 (text-field)
|
rlm@10
|
129 (label "Power/kW") g
|
rlm@10
|
130 (text-field) w
|
rlm@10
|
131 (label "R/mm") g
|
rlm@10
|
132 (text-field)
|
rlm@10
|
133 (label "D/mm") g
|
rlm@10
|
134 (text-field))))
|
rlm@10
|
135
|
rlm@10
|
136 (fn test4
|
rlm@10
|
137 [panel]
|
rlm@10
|
138 (miglayout panel
|
rlm@10
|
139 (label "First Name")
|
rlm@10
|
140 (text-field) {:id :firstname}
|
rlm@10
|
141 (label "Surname") [:gap :unrelated]
|
rlm@10
|
142 (text-field) {:id :surname} :wrap
|
rlm@10
|
143 (label "Address")
|
rlm@10
|
144 (text-field) {:id :address} :span :grow))
|
rlm@10
|
145 ])
|