Skip to content
Browse files

Split to-widget and make-widget into separate namespaces for consistency

  • Loading branch information...
1 parent 42ced87 commit 86226b68c31748e0d27c13ab5498be0841f8daec @daveray committed
View
2 src/seesaw/core.clj
@@ -15,7 +15,7 @@
capability or makes them easier to use."
:author "Dave Ray"}
seesaw.core
- (:use [seesaw util meta to-widget])
+ (:use [seesaw util meta to-widget make-widget])
(:require [seesaw color font border invoke timer selection
event selector icon action cells table graphics cursor])
(:import [javax.swing
View
7 src/seesaw/examples/to_widget.clj → src/seesaw/examples/make_widget.clj
@@ -8,10 +8,10 @@
; the terms of this license.
; You must not remove this notice, or any other, from this software.
-(ns seesaw.examples.to-widget
- (:use [seesaw core border to-widget mig]))
+(ns seesaw.examples.make-widget
+ (:use [seesaw core border make-widget mig]))
-; This example shows how to implement the ToWidget protocol for a new type.
+; This example shows how to implement the MakeWidget protocol for a new type.
; Is this cute? Yes. Useful? Hell if I know.
; First, let's make a type
@@ -19,6 +19,7 @@
(defn name-field [person field]
(text :columns 15 :text (field person)))
+
; Now implement MakeWidget to create an editor for that type
(extend-type Person
MakeWidget
View
52 src/seesaw/make_widget.clj
@@ -0,0 +1,52 @@
+; 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.make-widget
+ (:use [seesaw util icon])
+ (:import [java.awt Dimension]
+ [javax.swing Box JLabel JButton]))
+
+(defprotocol MakeWidget
+ (make-widget* [v]))
+
+(defmacro ^{:private true} def-make-widget [t b & forms]
+ `(extend-type
+ ~t
+ MakeWidget
+ (~'make-widget* ~b ~@forms)))
+
+(def-make-widget java.awt.Component [c] c)
+
+(def-make-widget java.awt.Dimension [v] (Box/createRigidArea v))
+
+(def-make-widget javax.swing.Action [v] (JButton. v))
+
+(def-make-widget clojure.lang.Keyword
+ [v]
+ (condp = v
+ :separator (javax.swing.JSeparator.)
+ :fill-h (Box/createHorizontalGlue)
+ :fill-v (Box/createVerticalGlue)))
+
+(def-make-widget clojure.lang.IPersistentVector
+ [[v0 v1 v2]]
+ (cond
+ (= :fill-h v0) (Box/createHorizontalStrut v1)
+ (= :fill-v v0) (Box/createVerticalStrut v1)
+ (= :by v1) (Box/createRigidArea (Dimension. v0 v2))))
+
+(def-make-widget String
+ [v]
+ (JLabel. v))
+
+(def-make-widget java.net.URL
+ [v]
+ (JLabel. (icon v)))
+
View
40 src/seesaw/to_widget.clj
@@ -16,24 +16,12 @@
(defprotocol ToWidget
(to-widget* [v]))
-(defprotocol MakeWidget
- (make-widget* [v]))
-
-; A couple macros to make definining the ToWidget protocol a little less
-; tedious. Mostly just for fun...
-
(defmacro ^{:private true} def-to-widget [t b & forms]
`(extend-type
~t
ToWidget
(~'to-widget* ~b ~@forms)))
-(defmacro ^{:private true} def-make-widget [t b & forms]
- `(extend-type
- ~t
- MakeWidget
- (~'make-widget* ~b ~@forms)))
-
(def-to-widget Object [c] nil)
(def-to-widget java.awt.Component [c] c)
@@ -42,31 +30,3 @@
[v]
(try-cast java.awt.Component (.getSource v)))
-(def-make-widget java.awt.Component [c] c)
-
-(def-make-widget java.awt.Dimension [v] (Box/createRigidArea v))
-
-(def-make-widget javax.swing.Action [v] (JButton. v))
-
-(def-make-widget clojure.lang.Keyword
- [v]
- (condp = v
- :separator (javax.swing.JSeparator.)
- :fill-h (Box/createHorizontalGlue)
- :fill-v (Box/createVerticalGlue)))
-
-(def-make-widget clojure.lang.IPersistentVector
- [[v0 v1 v2]]
- (cond
- (= :fill-h v0) (Box/createHorizontalStrut v1)
- (= :fill-v v0) (Box/createVerticalStrut v1)
- (= :by v1) (Box/createRigidArea (Dimension. v0 v2))))
-
-(def-make-widget String
- [v]
- (JLabel. v))
-
-(def-make-widget java.net.URL
- [v]
- (JLabel. (icon v)))
-
View
15 test/seesaw/test/make_widget.clj
@@ -0,0 +1,15 @@
+; 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.make-widget
+ (:use seesaw.make-widget)
+ (:use [lazytest.describe :only (describe it testing)]
+ [lazytest.expect :only (expect)]))
+

0 comments on commit 86226b6

Please sign in to comment.
Something went wrong with that request. Please try again.