/
border.clj
88 lines (81 loc) · 3.87 KB
/
border.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
; Copyright (c) Dave Ray, 2011. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this
; distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
(ns seesaw.test.border
(:use seesaw.border)
(:use [lazytest.describe :only (describe it testing)]
[lazytest.expect :only (expect)])
(:import [javax.swing.border EmptyBorder LineBorder MatteBorder TitledBorder]
[java.awt Insets Color]))
(describe empty-border
(it "creates a 1 pixel border by default"
(let [b (empty-border)]
(expect (= EmptyBorder (class b)))
(expect (= (Insets. 1 1 1 1) (.getBorderInsets b)))))
(it "creates a border with same thickness on all sides"
(let [b (empty-border :thickness 11)]
(expect (= EmptyBorder (class b)))
(expect (= (Insets. 11 11 11 11) (.getBorderInsets b)))))
(it "creates a border with specified sides"
(let [b (empty-border :top 2 :left 3 :bottom 4 :right 5)]
(expect (= EmptyBorder (class b)))
(expect (= (Insets. 2 3 4 5) (.getBorderInsets b)))))
(it "creates a border with specified sides, defaulting to 0"
(let [b (empty-border :left 3 )]
(expect (= EmptyBorder (class b)))
(expect (= (Insets. 0 3 0 0) (.getBorderInsets b))))))
(describe line-border
(it "creates a black, one pixel border by default"
(let [b (line-border)]
(expect (= LineBorder (class b)))
(expect (= 1 (.getThickness b)))
(expect (= Color/BLACK (.getLineColor b)))))
(it "creates a border with desired color (using to-color) and thickness"
(let [b (line-border :thickness 12 :color "#FFFF00")]
(expect (= LineBorder (class b)))
(expect (= 12 (.getThickness b)))
(expect (= Color/YELLOW (.getLineColor b)))))
(it "creates a matte border with specified sides and color"
(let [b (line-border :top 2 :left 3 :bottom 4 :right 5 :color "#FFFF00")]
(expect (= MatteBorder (class b)))
(expect (= (Insets. 2 3 4 5) (.getBorderInsets b)))
(expect (= Color/YELLOW (.getMatteColor b)))))
(it "creates a matte border with specified sides, defaulting to 0"
(let [b (line-border :top 2)]
(expect (= MatteBorder (class b)))
(expect (= (Insets. 2 0 0 0) (.getBorderInsets b)))
(expect (= Color/BLACK (.getMatteColor b))))))
(describe compound-border
(it "creates nested compound borders inner to outer"
(let [in (line-border)
mid (line-border)
out (line-border)
b (compound-border in mid out)]
(expect (= out (.getOutsideBorder b)))
(expect (= mid (.. b (getInsideBorder) (getOutsideBorder))))
(expect (= in (.. b (getInsideBorder) (getInsideBorder)))))))
(describe to-border
(it "returns input if it's already a border"
(let [b (line-border)]
(expect (= b (to-border b)))))
(it "creates an empty border with specified thickness for a number"
(let [b (to-border 11)]
(expect (= EmptyBorder (class b)))
(expect (= (Insets. 11 11 11 11) (.getBorderInsets b)))))
(it "returns a titled border using str if it doesn't know what to do"
(let [b (to-border "Test")]
(expect (= TitledBorder (class b)))
(expect (= "Test" (.getTitle b)))))
(it "creates a compound border out of multiple args"
(let [b (to-border "Inner" "Outer")]
(expect (= "Outer" (.. b getOutsideBorder getTitle)))
(expect (= "Inner" (.. b getInsideBorder getTitle)))))
(it "creates a compound border out of a collection arg"
(let [b (to-border ["Inner" "Outer"])]
(expect (= "Outer" (.. b getOutsideBorder getTitle)))
(expect (= "Inner" (.. b getInsideBorder getTitle))))))