Permalink
Browse files

:border option now supports i18n keywords. Creates a titled border fr…

…om resource bundle. Thanks to Bahman Movaqar for pointing out this omission. Also wrote docs for to-border.
  • Loading branch information...
1 parent daebc2f commit bc880075ccaf0842af5134670eb3e3130aed3a91 @daveray committed Dec 4, 2011
Showing with 35 additions and 6 deletions.
  1. +27 −6 src/seesaw/border.clj
  2. +6 −0 test/seesaw/test/border.clj
  3. +2 −0 test/seesaw/test/border.properties
View
@@ -12,7 +12,7 @@
:author "Dave Ray"}
seesaw.border
(:use [seesaw.color :only [to-color]]
- [seesaw.util :only [to-insets]])
+ [seesaw.util :only [to-insets resource]])
(:import [javax.swing BorderFactory]
[javax.swing.border Border]
[java.awt Color]))
@@ -124,13 +124,34 @@
(paintBorder [this c g x y w h]
(when paint (paint c g x y w h))))))
-(defn to-border
+(defn to-border
+ "Construct a border. The border returned depends on the input:
+
+ nil - returns nil
+ a Border - returns b
+ a number - returns an empty border with the given thickness
+ a vector or list - returns a compound border by applying to-border
+ to each element, inner to outer.
+ a i18n keyword - returns a titled border using the given resource
+ a string - returns a titled border using the given stirng
+
+ If given more than one argument, a compound border is created by applying
+ to-border to each argument, inner to outer.
+
+
+ Note:
+
+ to-border is used implicitly by the :border option supported by all widgets
+ to it is rarely necessary to call directly.
+ "
([b]
(cond
- (instance? Border b) b
- (integer? b) (empty-border :thickness b)
- (coll? b) (apply to-border b)
- true (BorderFactory/createTitledBorder (str b))))
+ (nil? b) nil
+ (instance? Border b) b
+ (integer? b) (empty-border :thickness b)
+ (coll? b) (apply to-border b)
+ (and (keyword? b) (namespace b)) (to-border (resource b))
+ :else (BorderFactory/createTitledBorder (str b))))
([b & args]
(apply compound-border b args)))
@@ -66,13 +66,19 @@
(expect (= in (.. b (getInsideBorder) (getInsideBorder)))))))
(describe to-border
+ (it "returns nil given nil"
+ (nil? (to-border nil)))
(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 a resource bundle if given an i18n keyword"
+ (let [b (to-border ::titled-border-test)]
+ (expect (= TitledBorder (class b)))
+ (expect (= "Test value from border.properties" (.getTitle 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)))
@@ -0,0 +1,2 @@
+# resource bundle used in border.clj tests
+titled-border-test=Test value from border.properties

0 comments on commit bc88007

Please sign in to comment.